Minkowski { public static IGeometry substractionOfMinkowskiFromCenter(IGeometry polygon1, IGeometry polygon2){ IGeometry box = polygon1.buffer(10).mbRegion(); IGeometry parcelle = box.difference(polygon1); IGeometry batiment = (IGeometry) polygon2.clone(); IGeometry temp = Minkowski.inverseSumOfMinkowskiFromCenter(parcelle, batiment); if (((IPolygon)temp).getInterior().size() == 0){return null;} IGeometry tempclear = (IGeometry) temp.clone(); ((IPolygon)tempclear).getInterior().clear(); IGeometry output = tempclear.difference(temp); return output; }  static IGeometry convexSumOfMinkowski(IGeometry polygon1, IGeometry polygon2); static IGeometry convexSumOfMinkowski(IGeometry polygon, IGeometry structure, IDirectPosition ref); static boolean isConvex(IGeometry polygone); static IGeometry sumOfMinkowski(IGeometry polygon1, IGeometry polygon2); @SuppressWarnings("rawtypes") static IGeometry sumOfMinkowski(IGeometry polygon1, IGeometry polygon2, IDirectPosition ref); static IGeometry sumOfMinkowskiFromCenter(IGeometry polygon1, IGeometry polygon2); static IGeometry inverseSumOfMinkowskiFromCenter(IGeometry polygon1, IGeometry polygon2); static IGeometry substractionOfMinkowskiFromCenter(IGeometry polygon1, IGeometry polygon2);  }
@Test public void testSoustraction1(){ DirectPositionList controlPts = new DirectPositionList(); controlPts.add(new DirectPosition(11.166666666666666,13.166666666666666)); controlPts.add(new DirectPosition(12.166666666666666,13.166666666666666)); controlPts.add(new DirectPosition(12.166666666666666,12.166666666666666)); controlPts.add(new DirectPosition(13.166666666666666,11.166666666666666)); controlPts.add(new DirectPosition(11.166666666666666,11.166666666666666)); controlPts.add(new DirectPosition(11.166666666666666,13.166666666666666)); GM_LineString linesControl = new GM_LineString(controlPts); GM_Polygon control = new GM_Polygon(linesControl); DirectPositionList points = new DirectPositionList(); points.add(new DirectPosition(10,10)); points.add(new DirectPosition(15,10)); points.add(new DirectPosition(17,12)); points.add(new DirectPosition(13,13)); points.add(new DirectPosition(15,15)); points.add(new DirectPosition(10,15)); points.add(new DirectPosition(10,10)); GM_LineString lines = new GM_LineString(points); GM_Polygon p1 = new GM_Polygon(lines); DirectPositionList points2 = new DirectPositionList(); points2.add(new DirectPosition(5,5)); points2.add(new DirectPosition(7,5)); points2.add(new DirectPosition(7,7)); points2.add(new DirectPosition(6,8)); points2.add(new DirectPosition(5,5)); GM_LineString lines2 = new GM_LineString(points2); GM_Polygon p2 = new GM_Polygon(lines2); GM_Polygon innerfit = (GM_Polygon) Minkowski.substractionOfMinkowskiFromCenter(p1, p2); double ratio = innerfit.intersection(control).area()/innerfit.union(control).area(); Assert.assertEquals(ratio, 1.0, Math.pow(10, -6)); }
@Test public void testSoustraction2(){ DirectPositionList points = new DirectPositionList(); DirectPositionList points2 = new DirectPositionList(); points.add(new DirectPosition(10,10)); points.add(new DirectPosition(15,10)); points.add(new DirectPosition(18,10)); points.add(new DirectPosition(19,13)); points.add(new DirectPosition(17,15)); points.add(new DirectPosition(14,12)); points.add(new DirectPosition(15,15)); points.add(new DirectPosition(10,15)); points.add(new DirectPosition(10,10)); points2.add(new DirectPosition(5,11)); points2.add(new DirectPosition(8,11)); points2.add(new DirectPosition(6,14)); points2.add(new DirectPosition(5,11)); GM_LineString lines = new GM_LineString(points); GM_Polygon p1 = new GM_Polygon(lines); GM_LineString lines2 = new GM_LineString(points2); GM_Polygon p2 = new GM_Polygon(lines2); @SuppressWarnings("unused") DirectPosition center = (DirectPosition) p2.centroid(); @SuppressWarnings({ "rawtypes", "unused" }) GM_MultiSurface innerfit = (GM_MultiSurface) Minkowski.substractionOfMinkowskiFromCenter(p1, p2); Assert.assertTrue(true); }
@Test public void testSoustraction3(){ DirectPositionList points = new DirectPositionList(); DirectPositionList points2 = new DirectPositionList(); points.add(new DirectPosition(10,10)); points.add(new DirectPosition(15,10)); points.add(new DirectPosition(17,12)); points.add(new DirectPosition(13,12)); points.add(new DirectPosition(13,15)); points.add(new DirectPosition(10,15)); points.add(new DirectPosition(10,10)); points2.add(new DirectPosition(5,11)); points2.add(new DirectPosition(9,11)); points2.add(new DirectPosition(9,11.3)); points2.add(new DirectPosition(5.3,11.3)); points2.add(new DirectPosition(5.3,14)); points2.add(new DirectPosition(5,14)); points2.add(new DirectPosition(5,11)); GM_LineString lines = new GM_LineString(points); GM_Polygon p1 = new GM_Polygon(lines); GM_LineString lines2 = new GM_LineString(points2); GM_Polygon p2 = new GM_Polygon(lines2); @SuppressWarnings("unused") DirectPosition center = (DirectPosition) p2.centroid(); @SuppressWarnings("unused") GM_Polygon innerfit = (GM_Polygon) Minkowski.substractionOfMinkowskiFromCenter(p1, p2); Assert.assertTrue(true); }
@Test public void testSoustraction4(){ DirectPositionList points = new DirectPositionList(); DirectPositionList points2 = new DirectPositionList(); points.add(new DirectPosition(10,10)); points.add(new DirectPosition(15,10)); points.add(new DirectPosition(17,12)); points.add(new DirectPosition(14,12)); points.add(new DirectPosition(15,15)); points.add(new DirectPosition(10,15)); points.add(new DirectPosition(10,10)); points2.add(new DirectPosition(5,11)); points2.add(new DirectPosition(8,11)); points2.add(new DirectPosition(6,14)); points2.add(new DirectPosition(5,11)); GM_LineString lines = new GM_LineString(points); GM_Polygon p1 = new GM_Polygon(lines); GM_LineString lines2 = new GM_LineString(points2); GM_Polygon p2 = new GM_Polygon(lines2); @SuppressWarnings("unused") DirectPosition center = (DirectPosition) p2.centroid(); @SuppressWarnings("unused") GM_Polygon innerfit = (GM_Polygon) Minkowski.substractionOfMinkowskiFromCenter(p1, p2); Assert.assertTrue(true); }