@Test public void intersectsTest() { Rectangle rectangle1 = create(1, 2, 3, 4); Rectangle rectangle2 = create(1, 2, 3, 4); Rectangle rectangle3 = create(3, 4, 3, 4); Rectangle rectangle4 = create(0, 0, 3, 4); Rectangle rectangle5 = create(0, 0, 5, 5); Rectangle rectangle6 = create(5, 5, 6, 6); Rectangle rectangle7 = create(1, 0, 3, 1); assertIntersection(rectangle1, rectangle1); assertIntersection(rectangle1, rectangle2); assertIntersection(rectangle1, rectangle3); assertIntersection(rectangle1, rectangle4); assertIntersection(rectangle1, rectangle5); assertNoIntersection(rectangle1, rectangle6); assertNoIntersection(rectangle1, rectangle7); }
public boolean intersects(Rectangle rectangle) { if (this == rectangle) { return true; } return this.left <= rectangle.right && rectangle.left <= this.right && this.top <= rectangle.bottom && rectangle.top <= this.bottom; }
Rectangle implements Serializable { public boolean intersects(Rectangle rectangle) { if (this == rectangle) { return true; } return this.left <= rectangle.right && rectangle.left <= this.right && this.top <= rectangle.bottom && rectangle.top <= this.bottom; } }
Rectangle implements Serializable { public boolean intersects(Rectangle rectangle) { if (this == rectangle) { return true; } return this.left <= rectangle.right && rectangle.left <= this.right && this.top <= rectangle.bottom && rectangle.top <= this.bottom; } Rectangle(double left, double top, double right, double bottom); }
Rectangle implements Serializable { public boolean intersects(Rectangle rectangle) { if (this == rectangle) { return true; } return this.left <= rectangle.right && rectangle.left <= this.right && this.top <= rectangle.bottom && rectangle.top <= this.bottom; } Rectangle(double left, double top, double right, double bottom); boolean contains(Point point); @Override boolean equals(Object obj); Point getCenter(); double getCenterX(); double getCenterY(); double getHeight(); double getWidth(); @Override int hashCode(); boolean intersects(Rectangle rectangle); boolean intersectsCircle(double pointX, double pointY, double radius); @Override String toString(); }
Rectangle implements Serializable { public boolean intersects(Rectangle rectangle) { if (this == rectangle) { return true; } return this.left <= rectangle.right && rectangle.left <= this.right && this.top <= rectangle.bottom && rectangle.top <= this.bottom; } Rectangle(double left, double top, double right, double bottom); boolean contains(Point point); @Override boolean equals(Object obj); Point getCenter(); double getCenterX(); double getCenterY(); double getHeight(); double getWidth(); @Override int hashCode(); boolean intersects(Rectangle rectangle); boolean intersectsCircle(double pointX, double pointY, double radius); @Override String toString(); final double bottom; final double left; final double right; final double top; }