The new method is not correct.
Proof:
Code:
System.out.println("contains? " + new Circle(53, 47, 4).contains(46, 44));
returns
Code:
contains? true
53 and 46 are already x-dist 7 from each other and the radius is 4 so...
I googled a bit and found this:
http://stackoverflow.com/questions/4811 ... e-a-circleSo the error was getX/Y instead of getCenterX/Y.
And because I dont know the operator orderings I think we may just move sqrdist to a local variable or put another pair of brackets around it
Fixed algorithm:float sqrdist = (x - getCenterX()) * (x - getCenterX()) + (y - getCenterY()) * (y - getCenterY());
return sqrdist < (getRadius() * getRadius());
Patch file for Circle.java:Code:
Index: src/org/newdawn/slick/geom/Circle.java
===================================================================
--- src/org/newdawn/slick/geom/Circle.java (revision 1556)
+++ src/org/newdawn/slick/geom/Circle.java (working copy)
@@ -118,7 +118,9 @@
*/
public boolean contains(float x, float y)
{
- return (x - getX()) * (x - getX()) + (y - getY()) * (y - getY()) < getRadius() * getRadius();
+ float sqrdist = (x - getCenterX()) * (x - getCenterX())
+ + (y - getCenterY()) * (y - getCenterY());
+ return sqrdist < (getRadius() * getRadius());
}
/**