Skip to content

Commit

Permalink
Rename OverlayNGRobust
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
  • Loading branch information
dr-jts committed Sep 15, 2020
1 parent 22cee2d commit c1277b0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.operation.overlayng.OverlayNG;
import org.locationtech.jts.operation.overlayng.OverlayNGSnapIfNeeded;
import org.locationtech.jts.operation.overlayng.OverlayNGRobust;
import org.locationtech.jtstest.geomfunction.Metadata;

/**
Expand Down Expand Up @@ -105,14 +105,14 @@ public static Geometry intersectionPrep(Geometry a, Geometry b) {
PreparedGeometry pg = cacheFetch(a);
if (! pg.intersects(b)) return null;
if (pg.covers(b)) return b.copy();
return OverlayNGSnapIfNeeded.intersection(a, b);
return OverlayNGRobust.intersection(a, b);
}

public static Geometry intersectionPrepNoCache(Geometry a, Geometry b) {
PreparedGeometry pg = (new PreparedGeometryFactory()).create(a);
if (! pg.intersects(b)) return null;
if (pg.covers(b)) return b.copy();
return OverlayNGSnapIfNeeded.intersection(a, b);
return OverlayNGRobust.intersection(a, b);
}

private static Geometry cacheKey = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import static org.locationtech.jts.operation.overlayng.OverlayNG.SYMDIFFERENCE;

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.operation.overlayng.OverlayNGSnapIfNeeded;
import org.locationtech.jts.operation.overlayng.OverlayNGRobust;
import org.locationtech.jts.operation.union.UnaryUnionOp;
import org.locationtech.jts.operation.union.UnionStrategy;

public class OverlayNGSnapIfNeededFunctions {
public class OverlayNGRobustFunctions {

private static Geometry overlay(Geometry a, Geometry b, int opcode) {
return OverlayNGSnapIfNeeded.overlay(a, b, opcode );
return OverlayNGRobust.overlay(a, b, opcode );
}

public static Geometry difference(Geometry a, Geometry b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.locationtech.jtstest.function.OrientationFunctions;
import org.locationtech.jtstest.function.OverlayFunctions;
import org.locationtech.jtstest.function.OverlayNGFunctions;
import org.locationtech.jtstest.function.OverlayNGSnapIfNeededFunctions;
import org.locationtech.jtstest.function.OverlayNGRobustFunctions;
import org.locationtech.jtstest.function.OverlayNoSnapFunctions;
import org.locationtech.jtstest.function.OverlayNGSRFunctions;
import org.locationtech.jtstest.function.OverlayNGOptFunctions;
Expand Down Expand Up @@ -109,7 +109,7 @@ public static GeometryFunctionRegistry createTestBuilderRegistry()

funcRegistry.add(OverlayNGSRFunctions.class);
funcRegistry.add(OverlayNGFunctions.class);
funcRegistry.add(OverlayNGSnapIfNeededFunctions.class);
funcRegistry.add(OverlayNGRobustFunctions.class);
funcRegistry.add(OverlayNGSnappingFunctions.class);

funcRegistry.add(OverlayNGTestFunctions.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* For floating precision an {@link MCIndexNoder} is used.
* This is not fully robust, so can sometimes result in
* {@link TopologyException}s being thrown.
* For robust full-precision overlay see {@link OverlayNGSnapIfNeeded}.
* For robust full-precision overlay see {@link OverlayNGRobust}.
* <p>
* A custom {@link Noder} can be supplied.
* This allows using a more performant noding strategy in specific cases,
Expand All @@ -72,7 +72,7 @@
*
* @author mdavis
*
* @see OverlayNGSnapIfNeeded
* @see OverlayNGRobust
*
*/
public class OverlayNG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,22 @@


/**
* Performs an overlay operation, increasing robustness by using a series of
* increasingly aggressive (and slower) noding strategies.
* Performs an overlay operation using {@link OverlayNG},
* increasing robustness by using a series of
* increasingly robust (but slower) noding strategies.
* <p>
* The noding strategies used are:
* <ol>
* <li>A simple, fast noder using FLOATING precision.
* <li>A {@link SnappingNoder} using an automatically-determined snap tolerance
* <li>First snapping each geometry to itself,
* and then overlaying them using a SnappingNoder.
* and then overlaying them using a <code>SnappingNoder</code>.
* <li>The above two strategies are repeated with increasing snap tolerance, up to a limit.
* <li>Finally a {@link SnapRoundngNoder} is used with a automatically-determined scale factor.
* </ol>
* If the above heuristics still fail to compute a valid overlay,
* If all of the above heuristics fail to compute a valid overlay,
* the original {@link TopologyException} is thrown.
* In practice this should be extremely unlikely to occur.
* <p>
* This algorithm relies on each overlay operation execution
* throwing a {@link TopologyException} if it is unable
Expand All @@ -48,7 +51,7 @@
*
* @author Martin Davis
*/
public class OverlayNGSnapIfNeeded
public class OverlayNGRobust
{

public static Geometry intersection(Geometry g0, Geometry g1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
* @author mdavis
*
*/
public class OverlayNGSnapIfNeededTest extends GeometryTestCase {
public class OverlayNGRobustTest extends GeometryTestCase {

public static void main(String args[]) {
TestRunner.run(OverlayNGSnapIfNeededTest.class);
TestRunner.run(OverlayNGRobustTest.class);
}

public OverlayNGSnapIfNeededTest(String name) { super(name); }
public OverlayNGRobustTest(String name) { super(name); }

/**
* Try a failure case to exercise all overlay heuristics
Expand All @@ -53,7 +53,7 @@ public void testSnappingUnion() {

public static boolean isUnionSuccess(Geometry a, Geometry b) {
try {
OverlayNGSnapIfNeeded.union(a, b );
OverlayNGRobust.union(a, b );
return true;
}
catch (TopologyException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.locationtech.jts.noding.snap.SnappingNoder;
import org.locationtech.jts.operation.overlay.OverlayOp;
import org.locationtech.jts.operation.overlayng.OverlayNG;
import org.locationtech.jts.operation.overlayng.OverlayNGSnapIfNeeded;
import org.locationtech.jts.operation.overlayng.OverlayNGRobust;

/**
* Runs overlay operations on pairs of random polygonal geometries
Expand All @@ -44,7 +44,7 @@ private void overlay(Geometry poly1, Geometry poly2) {
//overlayOrig(poly1, poly2);
//overlayOrigNoSnap(poly1, poly2);
//overlayNGFloat(poly1, poly2);
overlayNGSnapIfNeeded(poly1, poly2);
overlayNGRobust(poly1, poly2);
//overlayNG(poly1, poly2);
//overlayNGSnapping(poly1, poly2);
}
Expand Down Expand Up @@ -168,8 +168,8 @@ private void overlayNGFloat(Geometry poly1, Geometry poly2) {
//Geometry union = inter.union(diff1).union(diff2);
}

private void overlayNGSnapIfNeeded(Geometry poly1, Geometry poly2) {
OverlayNGSnapIfNeeded.intersection(poly1, poly2);
private void overlayNGRobust(Geometry poly1, Geometry poly2) {
OverlayNGRobust.intersection(poly1, poly2);
poly1.intersection(poly2);
//Geometry diff1 = poly1.difference(poly2);
//Geometry diff2 = poly2.difference(poly1);
Expand Down

0 comments on commit c1277b0

Please sign in to comment.