Vector2D - rescaling fix - zero issue
This commit is contained in:
parent
010cb5853a
commit
8af4e653b2
@ -86,7 +86,9 @@ public class Vector2D implements IVector2D {
|
|||||||
public void rescale() {
|
public void rescale() {
|
||||||
// calc unit vector and set it
|
// calc unit vector and set it
|
||||||
double vectorLength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2)); //using the square root of x and y
|
double vectorLength = Math.sqrt(Math.pow(getDx(), 2) + Math.pow(getDy(), 2)); //using the square root of x and y
|
||||||
setDx((1 / vectorLength) * getDx() * Constants.BALL_SPEED);
|
|
||||||
setDy((1 / vectorLength) * getDy() * Constants.BALL_SPEED);
|
// rescaling only needed, if value is not zero
|
||||||
|
if(getDx() != 0) setDx((1 / vectorLength) * getDx() * Constants.BALL_SPEED);
|
||||||
|
if(getDy() != 0) setDy((1 / vectorLength) * getDy() * Constants.BALL_SPEED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user