/** * Returns a new instance which is the union of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI add(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry union = geom.union(theGeom.getGeometry()); return buildROIGeometry(union); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new instance which is the exclusive OR of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI exclusiveOr(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { return buildROIGeometry(theGeom.getGeometry().symDifference(geom)); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new instance which is the intersection of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to intersect with * @return the intersection as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry intersect = geom.intersection(theGeom.getGeometry()); return buildROIGeometry(intersect); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new instance which is the difference of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to add * @return the union as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI subtract(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry difference = theGeom.getGeometry().difference(geom); return buildROIGeometry(difference); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }
/** * Returns a new ROI created by applying the given transform to * this ROI. * * @param at the transform * * @return the new ROI */ @Override public ROI transform(AffineTransform at) { Geometry cloned = theGeom.getGeometry().copy(); cloned.apply(new AffineTransformation(at.getScaleX(), at.getShearX(), at.getTranslateX(), at.getShearY(), at.getScaleY(), at.getTranslateY())); if (useFixedPrecision){ Geometry fixed = PRECISE_FACTORY.createGeometry(cloned); Coordinate[] coords = fixed.getCoordinates(); for (Coordinate coord : coords) { Coordinate precise = coord; PRECISION.makePrecise(precise); } cloned = fixed; } return buildROIGeometry(cloned); }