protected Point randomPointIn(Rectangle r) { double x = r.getMinX() + randomDouble() * r.getWidth(); double y = r.getMinY() + randomDouble() * r.getHeight(); x = normX(x); y = normY(y); Point p = ctx.makePoint(x, y); assertEquals(CONTAINS, r.relate(p)); return p; }
protected Point randomPointIn(Shape shape) { if (!shape.hasArea()) // or try the center? throw new UnsupportedOperationException("Need area to define shape!"); Rectangle bbox = shape.getBoundingBox(); Point p; do { p = randomPointIn(bbox); } while (!bbox.relate(p).intersects()); return p; }
@Override public SpatialRelation relate(Shape other) { final SpatialRelation bboxSect = bbox.relate(other); if (bboxSect == SpatialRelation.DISJOINT || bboxSect == SpatialRelation.WITHIN) return bboxSect; final boolean containsWillShortCircuit = (other instanceof Point) || relateContainsShortCircuits(); SpatialRelation sect = null; for (Shape shape : shapes) { SpatialRelation nextSect = shape.relate(other); if (sect == null) { // first pass sect = nextSect; } else { sect = sect.combine(nextSect); } if (sect == INTERSECTS) return INTERSECTS; if (sect == CONTAINS && containsWillShortCircuit) return CONTAINS; } return sect; }