@Test @Category(UnitTest.class) public void testOutsideTouchingRight() { Point[] inputs = { GeometryFactory.createPoint(30.0, 25.0), GeometryFactory.createPoint(40.0, 20.0), GeometryFactory.createPoint(40.0, 30.0) }; Polygon input = GeometryFactory.createPolygon(inputs); Point[] clips = { GeometryFactory.createPoint(20.0, 20.0), GeometryFactory.createPoint(30.0, 20.0), GeometryFactory.createPoint(30.0, 30.0), GeometryFactory.createPoint(20.0, 30.0) }; Polygon clip = GeometryFactory.createPolygon(clips); Geometry output = input.clip(clip); Assert.assertNull(output); }
@Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof Polygon && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof Polygon) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; }
PolygonImpl extends GeometryImpl implements WritablePolygon { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof Polygon && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof Polygon) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } }
PolygonImpl extends GeometryImpl implements WritablePolygon { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof Polygon && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof Polygon) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } PolygonImpl();   PolygonImpl(Map<String, String> attributes);   PolygonImpl(Point... points);   PolygonImpl(Collection<Point> points); }
PolygonImpl extends GeometryImpl implements WritablePolygon { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof Polygon && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof Polygon) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } PolygonImpl();   PolygonImpl(Map<String, String> attributes);   PolygonImpl(Point... points);   PolygonImpl(Collection<Point> points); static Class[] getClasses(); @Override void addInteriorRing(LinearRing lr); @Override WritableGeometry createWritableClone(); @Override void filter(PointFilter pf); @Override LinearRing getExteriorRing(); @Override void setExteriorRing(LinearRing ring); @Override LinearRing getInteriorRing(int i); @Override int getNumInteriorRings(); @Override boolean isValid(); @Override void read(DataInputStream stream); @Override void write(DataOutputStream stream); @Override Type type(); @Override void fromJTS(com.vividsolutions.jts.geom.Polygon jtsPolygon); @Override com.vividsolutions.jts.geom.Polygon toJTS(); @Override Bounds getBounds(); @Override boolean isEmpty(); @Override Geometry clip(Polygon geom); }
PolygonImpl extends GeometryImpl implements WritablePolygon { @Override public Geometry clip(Polygon geom) { Geometry clipped = super.clip(geom); if (clipped instanceof Polygon && !clipped.isEmpty()) { return clipped; } else if (clipped instanceof GeometryCollection) { WritableGeometryCollection collection = (WritableGeometryCollection) clipped; Iterator<? extends Geometry> iter = collection.iterator(); while (iter.hasNext()) { Geometry g = iter.next(); if (!(g instanceof Polygon) || g.isEmpty()) { iter.remove(); } } if (collection.getNumGeometries() == 0) { return null; } else if (collection.getNumGeometries() == 1) { return collection.getGeometry(0); } return collection; } return null; } PolygonImpl();   PolygonImpl(Map<String, String> attributes);   PolygonImpl(Point... points);   PolygonImpl(Collection<Point> points); static Class[] getClasses(); @Override void addInteriorRing(LinearRing lr); @Override WritableGeometry createWritableClone(); @Override void filter(PointFilter pf); @Override LinearRing getExteriorRing(); @Override void setExteriorRing(LinearRing ring); @Override LinearRing getInteriorRing(int i); @Override int getNumInteriorRings(); @Override boolean isValid(); @Override void read(DataInputStream stream); @Override void write(DataOutputStream stream); @Override Type type(); @Override void fromJTS(com.vividsolutions.jts.geom.Polygon jtsPolygon); @Override com.vividsolutions.jts.geom.Polygon toJTS(); @Override Bounds getBounds(); @Override boolean isEmpty(); @Override Geometry clip(Polygon geom);  }