Circle extends Geometry { @Override public boolean intersects(Geometry other) { Envelope otherEnvelope = other.getEnvelopeInternal(); if (!getEnvelopeInternal().intersects(otherEnvelope)) { return false; } if (other instanceof Point) { return covers((Point) other); } if (other instanceof LineString) { return intersects((LineString) other); } if (other instanceof Polygon) { return intersects((Polygon) other); } if (other instanceof GeometryCollection) { GeometryCollection collection = (GeometryCollection) other; for (int i = 0; i < collection.getNumGeometries(); i++) { if (intersects(collection.getGeometryN(i))) { return true; } } return false; } throw new IllegalArgumentException("Circle.intersects() doesn't support geometry type " + other.getGeometryType()); } Circle(Geometry centerGeometry, Double givenRadius); Geometry getCenterGeometry(); Coordinate getCenterPoint(); Double getRadius(); void setRadius(Double givenRadius); @Override boolean covers(Geometry other); @Override boolean intersects(Geometry other); @Override String getGeometryType(); @Override Coordinate getCoordinate(); @Override Coordinate[] getCoordinates(); @Override int getNumPoints(); @Override boolean isEmpty(); @Override int getDimension(); @Override Geometry getBoundary(); @Override int getBoundaryDimension(); @Override Geometry reverse(); @Override Object clone(); @Override boolean equalsExact(Geometry g, double tolerance); @Override void apply(CoordinateFilter filter); @Override void apply(CoordinateSequenceFilter filter); @Override void apply(GeometryFilter filter); @Override void apply(GeometryComponentFilter filter); @Override void normalize(); @Override String toString();  }
@Test public void testIntersects() throws Exception { Circle circle = new Circle(makePoint(0.0, 0.0), 0.5); assertTrue(circle.intersects(makePoint(0, 0))); assertTrue(circle.intersects(makePoint(0.1, 0.2))); assertFalse(circle.intersects(makePoint(0.4, 0.4))); assertFalse(circle.intersects(makePoint(-1, 0.4))); assertTrue(circle.intersects(parseWkt("MULTIPOINT ((0.1 0.1), (0.2 0.4))"))); assertTrue(circle.intersects(parseWkt("MULTIPOINT ((0.1 0.1), (1.2 0.4))"))); assertFalse(circle.intersects(parseWkt("MULTIPOINT ((1.1 0.1), (0.2 1.4))"))); assertTrue(circle.intersects(parseWkt("POLYGON ((-0.1 0.1, 0 0.4, 0.1 0.2, -0.1 0.1))"))); assertTrue(circle.intersects(parseWkt("POLYGON ((-0.5 0, 0 0.5, 0.5 0, -0.5 0))"))); assertTrue(circle.intersects(parseWkt("POLYGON ((0 0, 1 1, 1 0, 0 0))"))); assertTrue(circle.intersects(parseWkt("POLYGON ((-1 -1, -1 1, 1 1, 1.5 0.5, 1 -1, -1 -1))"))); assertTrue(circle.intersects(parseWkt("POLYGON ((-1 -1, -1 1, 1 1, 1 -1, -1 -1), " + "(-0.1 -0.1, 0.1 -0.1, 0.1 0.1, -0.1 0.1, -0.1 -0.1))"))); assertFalse(circle.intersects(parseWkt("POLYGON ((0.4 0.4, 0.4 0.45, 0.45 0.45, 0.45 0.4, 0.4 0.4))"))); assertFalse(circle.intersects(parseWkt("POLYGON ((-1 0, -1 1, 0 1, 0 2, -1 2, -1 0))"))); assertFalse(circle.intersects(parseWkt("POLYGON ((-1 -1, -1 1, 1 1, 1 -1, -1 -1), " + "(-0.6 -0.6, 0.6 -0.6, 0.6 0.6, -0.6 0.6, -0.6 -0.6))"))); assertTrue(circle.intersects(parseWkt("MULTIPOLYGON (((-0.1 0.1, 0 0.4, 0.1 0.2, -0.1 0.1)), " + "((-0.5 0, 0 0.5, 0.5 0, -0.5 0)))"))); assertTrue(circle.intersects(parseWkt("MULTIPOLYGON (((-0.1 0.1, 0 0.4, 0.1 0.2, -0.1 0.1)), " + "((-1 0, -1 1, 0 1, 0 2, -1 2, -1 0)))"))); assertFalse(circle.intersects(parseWkt("MULTIPOLYGON (((0.4 0.4, 0.4 0.45, 0.45 0.45, 0.45 0.4, 0.4 0.4)), " + "((-1 0, -1 1, 0 1, 0 2, -1 2, -1 0)))"))); assertTrue(circle.intersects(parseWkt("LINESTRING (-1 -1, 1 1)"))); assertTrue(circle.intersects(parseWkt("LINESTRING (-1 0.5, 1 0.5)"))); assertTrue(circle.intersects(parseWkt("LINESTRING (0 0, 0.1 0.2)"))); assertFalse(circle.intersects(parseWkt("LINESTRING (0.4 0.4, 1 1)"))); assertFalse(circle.intersects(parseWkt("LINESTRING (-0.4 -0.4, -2 -3.2)"))); assertFalse(circle.intersects(parseWkt("LINESTRING (0.1 0.5, 1 0.5)"))); assertTrue(circle.intersects(parseWkt("MULTILINESTRING ((-1 -1, 1 1), (-1 0.5, 1 0.5))"))); assertTrue(circle.intersects(parseWkt("MULTILINESTRING ((-1 -1, 1 1), (0.4 0.4, 1 1))"))); assertFalse(circle.intersects(parseWkt("MULTILINESTRING ((0.1 0.5, 1 0.5), (0.4 0.4, 1 1))"))); }