drmcnellis / collisiondetectionkit

Automatically exported from code.google.com/p/collisiondetectionkit
0 stars 0 forks source link

Need way to determine target in checkCollisions #8

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When calling checkCollisions, you are giving an untyped argument with two 
properties:

object1
object2

There is currently no way to know which object was the target passed to 
CollisionList. In fact, it 
seems to be random, and can sometimes be object1 or object2.

I suggest that we rename these to something like:

target
collisionItem

and ensure that target always contains the target.

This will make it clearer and easier to use, as well as improve performance 
(since the developer 
will not have to check which one is the target).

Original issue reported on code.google.com by mikechambers on 21 Jun 2009 at 10:59

GoogleCodeExporter commented 9 years ago
I'll mull this one over.  The main reason I have it as object1/object2 is so 
that 
you could swap out CollisionGroup and CollisionList without having to rewrite 
any of 
the code handling the collision.  If I specify target for CollisionList, but 
still 
have object1/object2 for CollisionGroup, then implementation changes between 
the 
two.  

However, I agree that specifying the target in CollisionList would improve 
performance by eliminating checks, so I'll think it over.

I should note that you get a wee bit of help in discerning between object1 and 
object2 in that object1 is always the smallest of the two involved in the 
collision.  So in situations where your target is always smaller or larger than 
your 
other items in the list, you always know if it's object1 or object2.

Original comment by lessthan...@gmail.com on 22 Jun 2009 at 7:36

GoogleCodeExporter commented 9 years ago
How about this:

In the case of CollisionGroup, object1 will always be the smaller of the two 
objects 
(as it is now)

In the case of CollisionList, object1 will always be the target.

This way we can have a Collision object being returned (re: your issue for 
typed 
objects from checkCollision()) that is the same structure for both 
CollisionGroup 
and CollisionList, making it painless to swap between the two.

Shoot, I can have a "target" property in the class anyways and just use it in 
the 
case of CollisionList if you think it's worth it.

Original comment by lessthan...@gmail.com on 22 Jun 2009 at 8:14

GoogleCodeExporter commented 9 years ago
I can live with the option you described in comment #2. However I do much 
prefer the
target/collisionItem option Mike described. I do not see a scenario where I 
would
first choose to use CollisionGroup and later swap it for CollisionList. When 
you have
a clear goal on what you're building you choose either one and never swap. Often
clear and easy code outweighs flexibility.

Original comment by e.verd...@gmail.com on 24 Jun 2009 at 5:23