|
This is more applicable for an algorithms thread, but I couldn't find one. Some background: I have a canvas in an Adobe Flex application that has n number of equal sized square children. User can drag these around, or add a new one. If they choose to add a new one, a new one is created and added to the canvas. Problem: They are always added in the same place, which means if the user adds two or more without first moving them, they are added to the same position. What I need to do is find a a square space within the canvas that is not occupied by any other components. I can brute force this by looking at every point (x,y) in the canvas and checking to see if the rectangle defined by (x, y, width, height) intersects with any other component, but that isn't a very finessed way of doing it. Has anyone come across this problem before, and if so, did you have a better way of solving the problem?
|
# ? Mar 17, 2009 19:48 |
|
|
# ? Jun 4, 2024 04:16 |
|
digital-entropy posted:This is more applicable for an algorithms thread, but I couldn't find one. If you keep a sorted list in the X and Y directions you can binary search into the lists for where the intersecting rectangle would be, etc. It'd be O(lgn), which is faster than your O(n) solution.
|
# ? Mar 17, 2009 19:56 |
|
Ugg boots posted:If you keep a sorted list in the X and Y directions you can binary search into the lists for where the intersecting rectangle would be, etc. It'd be O(lgn), which is faster than your O(n) solution. Good point. For now I have only 5 or 6 things max that I have to check against so it works fairly well. It started getting slow around 12 or so, so I optimized it slightly by skipping over n pixels in the direction I'm searching where n is the width or height of the component that intersects. That made it work reasonably fast so while there's no inherent need to optimize further I'll probably end up working on it later.
|
# ? Mar 17, 2009 22:13 |
|
A long time ago I saw a video (I think linked from slashdot?) about a very mature visual programming language whose goal was to simplify extremely complicated conditional paths. Anyone remember the name of this language? I have a current project that I actually want to mess a bit around with it.
|
# ? Mar 18, 2009 17:03 |
|
Chuu posted:A long time ago I saw a video (I think linked from slashdot?) about a very mature visual programming language whose goal was to simplify extremely complicated conditional paths.
|
# ? Mar 18, 2009 17:39 |
|
Given the coordinates of points A and B and the distance D, what would be the best way of calculating the coordinates of point C? I figured out a retardedly convulated way of doing it but I'm sure there must be a nice elegant solution. I'm no mathematician so I don't really know what I should be putting into Google.
|
# ? Mar 18, 2009 19:32 |
|
Dicky B posted:what I should be putting into Google. Scalar multiplication of vectors? Maybe something about a unit vector?
|
# ? Mar 18, 2009 19:42 |
|
Dicky B posted:
B + D * ( normalized AB )
|
# ? Mar 18, 2009 19:48 |
|
That Turkey Story posted:B + D * ( normalized AB )
|
# ? Mar 18, 2009 20:34 |
|
Dicky B posted:Thank you this is great! Thank you also royallthefourth, this is fun to learn about. I wish they had taught us this kind of stuff in my graphics and animation classes. They (or the prerequisite classes) didn't?
|
# ? Mar 18, 2009 20:49 |
I want to parse a human readable string of time spans, not really sure how to approach this to make it clean. I'm sure I could come up with something that works, but I have a feeling it will be a sloppy mess of poo poo if I don't go in with a plan of attack. I'll be using Java for this. The basic format is: 1:00pm to 2:00pm and 3:00pm to 4:00pm It can come in other variations: 1:15-2 1-2 3-4 1-2 and 3-4 1 to 2 and 3-4 1300-1400 I also want to handle overlap: 1-2 and 2-3 turns into 1-3 Can anybody give me a nudge in the right direction? fletcher fucked around with this message at 21:07 on Mar 18, 2009 |
|
# ? Mar 18, 2009 21:03 |
|
fletcher posted:Can anybody give me a nudge in the right direction? Regular expressions?
|
# ? Mar 18, 2009 21:18 |
|
fletcher posted:I want to parse a human readable string of time spans, not really sure how to approach this to make it clean. I'm sure I could come up with something that works, but I have a feeling it will be a sloppy mess of poo poo if I don't go in with a plan of attack. I'll be using Java for this. Is it possible to write a mini-parser to take care of this? This may be overkill for what you want though.. code:
|
# ? Mar 19, 2009 00:09 |
|
fletcher posted:Can anybody give me a nudge in the right direction? You asked for a nudge instead of a solution, so I'll give you a solution in a different language using principles that may be difficult to translate over. It's a fun little trivial problem, though. chocojosh posted:Is it possible to write a mini-parser to take care of this? chocojosh posted:This may be overkill for what you want though.. code:
code:
code:
code:
code:
code:
code:
code:
code:
code:
Edit: For overlapping, we just define a sort order on timespans, then walk down a sorted list and collapse overlaps. code:
ShoulderDaemon fucked around with this message at 00:38 on Mar 19, 2009 |
# ? Mar 19, 2009 00:14 |
|
fletcher posted:I want to parse a human readable string of time spans, not really sure how to approach this to make it clean. I'm sure I could come up with something that works, but I have a feeling it will be a sloppy mess of poo poo if I don't go in with a plan of attack. I'll be using Java for this. Check out the Ruby gem Chronic, which does natural date/time parsing. Might make life easier if it works with the format you've got.
|
# ? Mar 19, 2009 00:24 |
|
ShoulderDaemon posted:stuff Christ, he asked for a nudge and you pushed him off the cliff... good show!
|
# ? Mar 19, 2009 00:48 |
|
Can anyone recommend an 8085 Assembler IDE? I need a memory editor and labels, that's about it. I already tried the Olshonsoft one.
|
# ? Mar 19, 2009 23:20 |
|
Can any of you tell me what CSS/HTML is required to center two images side by side? My end goal is to create a 2x2 grid of images, with each being their own html link.
|
# ? Mar 20, 2009 03:37 |
|
Brackhar posted:Can any of you tell me what CSS/HTML is required to center two images side by side? My end goal is to create a 2x2 grid of images, with each being their own html link. Sounds like you want display 4 images in a table! code:
|
# ? Mar 20, 2009 04:41 |
|
Only little girls use tables. The real solution is to set up a tapestry installation and through that deliver a custom applet layout of the images.
|
# ? Mar 20, 2009 05:33 |
|
I am in Programming I and we're using Java to learn with. I have an assignment with the following question Write a Java application to find all Pythagorean Triples for side1, side2 and the hypotenuse, each no larger than 200. Use a triple-nested for loop that tries all possibilities. SUGGESTION: Use a set of 3 nested loops, with an if construct inside the inner-most loop. I have no idea how to find a Pythagorean Triple with code. Any sort of guidance on that would be nice but I would prefer to obviously write the code myself
|
# ? Mar 21, 2009 05:01 |
|
ayb posted:I am in Programming I and we're using Java to learn with. I have an assignment with the following question here's a hint a * a + b * b == c * c
|
# ? Mar 21, 2009 05:13 |
|
ayb posted:I am in Programming I and we're using Java to learn with. I have an assignment with the following question code:
code:
code:
|
# ? Mar 21, 2009 05:20 |
|
ShoulderDaemon posted:ooh ooh ooh e: might as well... code:
Scaevolus fucked around with this message at 09:32 on Mar 21, 2009 |
# ? Mar 21, 2009 05:30 |
|
Scaevolus posted:Sure, do the guy's homework for him. He still has to translate from moon to Java.
|
# ? Mar 21, 2009 05:51 |
|
Scaevolus posted:Sure, do the guy's homework for him. People love doing this because they get to show off their amazing ability to solve freshmen-level assignments thanks to completing a degree in CS. Bravo, folks. Bravo.
|
# ? Mar 21, 2009 06:48 |
|
quadreb posted:He still has to translate from moon to Java. You're right, I made that way too simple. code:
|
# ? Mar 21, 2009 07:02 |
|
What the christ is that?
|
# ? Mar 21, 2009 08:06 |
|
Mithaldu posted:What the christ is that? Befunge, although I'm fairly certain I could've folded it better and my use of storage instead of pure stack manipulation is lame. If it's not obvious, I'm kind of bored. Edit: And that version also has an extra control structure that I left in because I must've missed it as I revised my code. Oops.
|
# ? Mar 21, 2009 08:16 |
|
Hopping on the pythagorean train:code:
tef fucked around with this message at 09:50 on Mar 21, 2009 |
# ? Mar 21, 2009 09:45 |
|
Okay guys but can you write fizz buzz?
|
# ? Mar 21, 2009 11:06 |
|
drat, I'm not cool enough to solve Pythagorean triples in some esoteric language.
|
# ? Mar 21, 2009 16:23 |
|
Haskell is the best language for solving trivial problems.
|
# ? Mar 21, 2009 16:30 |
|
Ensign Expendable posted:drat, I'm not cool enough to solve Pythagorean triples in some esoteric language. code:
|
# ? Mar 21, 2009 16:33 |
|
While working on my Java school project I had to debug some NullPointerExceptions. This made me wonder: How can Java have Null Pointer Exceptions if Java only has references?
|
# ? Mar 21, 2009 17:28 |
|
chocojosh posted:How can Java have Null Pointer Exceptions if Java only has references? Well gee, don't read the documentation. http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NullPointerException.html
|
# ? Mar 21, 2009 17:55 |
|
shrughes posted:Well gee, don't read the documentation. I meant it as a tongue-in-cheek joke because of people who say that "Java doesn't have pointers". If Java doesn't have pointers, it should be a NullReferenceException
|
# ? Mar 21, 2009 19:13 |
|
chocojosh posted:If Java doesn't have pointers, it should be a NullReferenceException No it shouldn't -- Java was targeting C++ programmers.
|
# ? Mar 21, 2009 19:43 |
|
shrughes posted:No it shouldn't -- Java was targeting C++ programmers. They are called references in Java, so why would they call their exceptions null pointer exceptions? If you follow your logic of Java being targeted at C++ programmers, then Java reference types shouldn't be called reference types, they should be called pointer types. The point is, Java is needlessly inconsistent, not to mention the fact that the language is gay as hell to begin with.
|
# ? Mar 21, 2009 20:26 |
|
|
# ? Jun 4, 2024 04:16 |
|
I'm new to vbulletin, but cannot figure out why this 20 pixel boarder shows up around my forums. Any help is greatly appreciated. Click here for the full 1280x600 image. wait, I think I can handle it after all. Lee Bow fucked around with this message at 00:01 on Mar 22, 2009 |
# ? Mar 21, 2009 23:37 |