ROIGeometry extends ROI { @Override public ROI intersect(ROI roi) { try { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry intersect = geom.intersection(theGeom.getGeometry()); return buildROIGeometry(intersect); } } catch(TopologyException e) { if(LOGGER.isLoggable(Level.FINE)) { LOGGER.log(Level.FINE, "Failed to perform operation using geometries, falling back on raster path", e); } } return super.intersect(roi); } ROIGeometry(Geometry geom);  ROIGeometry(Rectangle rect);  ROIGeometry(Geometry geom, final boolean useFixedPrecision);  ROIGeometry(Geometry geom, final boolean antiAliasing, final boolean useFixedPrecision);  ROIGeometry(Geometry geom, final RenderingHints hints);  ROIGeometry(Geometry geom, final boolean antiAliasing, 
            final boolean useFixedPrecision, final RenderingHints hints); @Override ROI add(ROI roi); @Override boolean contains(Point p); @Override boolean contains(Point2D p); @Override boolean contains(int x, int y); @Override boolean contains(double x, double y); @Override boolean contains(Rectangle rect); @Override boolean contains(Rectangle2D rect); @Override boolean contains(int x, int y, int w, int h); @Override boolean contains(double x, double y, double w, double h); @Override ROI exclusiveOr(ROI roi); @Override int[][] getAsBitmask(int x, int y, int width, int height, int[][] mask); @Override PlanarImage getAsImage(); @Override LinkedList getAsRectangleList(int x, int y, int width, int height); @Override Shape getAsShape(); Geometry getAsGeometry(); @Override Rectangle getBounds(); @Override Rectangle2D getBounds2D(); @Override int getThreshold(); @Override ROI intersect(ROI roi); @Override boolean intersects(Rectangle rect); @Override boolean intersects(Rectangle2D rect); @Override boolean intersects(int x, int y, int w, int h); @Override boolean intersects(double x, double y, double w, double h); @Override ROI performImageOp(RenderedImageFactory RIF, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints); @Override ROI performImageOp(String name, ParameterBlock paramBlock, int sourceIndex, RenderingHints renderHints); @Override void setThreshold(int threshold); @Override ROI subtract(ROI roi); @Override ROI transform(AffineTransform at, Interpolation interp); @Override ROI transform(AffineTransform at); @Override String toString(); static final boolean DEFAULT_ROIGEOMETRY_ANTIALISING; static final boolean DEFAULT_ROIGEOMETRY_USEFIXEDPRECISION; }
@Test public void testRotatedRectangleIntersection() throws Exception { if (isOSX) { System.out.println("skipping testRotatedRectangleIntersection on OSX"); } else { Polygon polygon1 = (Polygon) new WKTReader().read("POLYGON((20 0, 50 -30, 30 -50, 0 -20, 20 0))"); Polygon polygon2 = (Polygon) new WKTReader().read("POLYGON((40 -40, 60 -20, 20 20, 0 0, 40 -40))"); ROIGeometry geom1 = new ROIGeometry(polygon1); ROIShape shape1 = getEquivalentROIShape(geom1); ROIGeometry geom2 = new ROIGeometry(polygon2); ROIShape shape2 = getEquivalentROIShape(geom2); final ROI geomUnion = geom1.intersect(geom2); final ROI shapeUnion = shape1.intersect(shape2); assertROIEquivalent(geomUnion, shapeUnion, "RotatedIntersection"); } }
@Test @Ignore("not working on any platform ?") public void testIntersect() throws Exception { Point p1 = new GeometryFactory().createPoint(new Coordinate(10, 10)); Point p2 = new GeometryFactory().createPoint(new Coordinate(20, 10)); Geometry buffer1 = p1.buffer(15); Geometry buffer2 = p2.buffer(15); ROIGeometry rg1 = new ROIGeometry(buffer1); ROIGeometry rg2 = new ROIGeometry(buffer2); ROI rgIntersection = rg1.intersect(rg2); ROIShape rs1 = getEquivalentROIShape(rg1); ROIShape rs2 = getEquivalentROIShape(rg2); ROI rsIntersection = rs1.intersect(rs2); assertROIEquivalent(rgIntersection, rsIntersection, "Intersection"); }