I have an issue with simple 2d collision detection with a circle and a rectangle. All the checker does is see if the center of the circle overlaps with any point on the rectangle.
Heres the checker:
boolean overlaps(Circle circle) {
for (double i = topLeft.x; i < (topLeft.x + width); i++)
{
for (double j = topLeft.y; j < (topLeft.y + height); j++)
{
if (circle.center.x == i && circle.center.y == j)
{
return true;
}
}
}
return false;
}`
Very simple, and to the point. The error comes into play at the if statement, with my circle.center.x
, and/or circle.center.y
.
Here is the code for my Circle class:
public class Circle {
Point center;
double radius;
/**
* Constructor.
*
* @param center the center Point of the circle
* @param radius the radius of the circle
*/
public Circle(Point center, double radius) {
center = this.center;
radius = this.radius;
}
/**
* Get the current center point of the circle.
*
* @return the center point of the circle
*/
public Point getCenter() {
return center;
}
/**
* Set the center point of the circle.
*
* @param center the (new) center point of the circle
*/
public void setCenter(Point center) {
this.center = center;
}
/**
* Get the current radius.
*
* @return the current radius
*/
public double getRadius() {
return radius;
}
/**
* Set the radius.
*
* @param radius the (new) radius of the circle
*/
public void setRadius(double radius) {
this.radius = radius;
}
}`
Where am i going wrong? It certainly cannot be an issue with my Point class, as that would mean plenty of other things would've gone wrong by now. Thanks in advance.