macite / swingame

2D game library accessible from multiple languages
swingame.com
28 stars 9 forks source link

clarified VectorNormal and fixed #39 in the process #40

Closed michaelb958 closed 8 years ago

michaelb958 commented 8 years ago

Dividing by zero is bad. Also, there's a perfectly good magnitude function.

macite commented 8 years ago

Not sure this is the best solution, as a vector with no magnitude does not have a normal. A better solution would be to alter the circle collision so that it avoids asking for this when the sprite has no velocity.

michaelb958 commented 8 years ago

It doesn't feel particularly right for $PROGRAM to bomb out with a floating-point exception when all $PROGRAMMER did was pass in a vector; SwinGame is meant to be at a higher level of abstraction.

jgardner8 commented 8 years ago

I think when Andrew says "the circle collision" he doesn't mean your game code, but the CollideCircleLine function you had this issue with, and whatever other circle collision functions there are.

The problem is not that VectorNormal crashes on a vector of 0 magnitude -- that is exactly what should happen as the function has no valid result. However it doesn't make sense for the circle collision functions to crash if the sprite isn't moving, so the fix should be at that level.

macite commented 8 years ago

I've updated this so it returns a null/zero vector and raises a warning, and have also updated the collision code so that it avoids calling VectorNormal when there is no velocity.

michaelb958 commented 8 years ago

I approve of 0dc6c9c1ab55147fb9f685d141b918b6b1517607, for what it's worth.