diff --git a/modules/core/src/main/java/org/locationtech/jts/operation/relateng/BasicPredicate.java b/modules/core/src/main/java/org/locationtech/jts/operation/relateng/BasicPredicate.java index edb63ef10a..41b4c1fafe 100644 --- a/modules/core/src/main/java/org/locationtech/jts/operation/relateng/BasicPredicate.java +++ b/modules/core/src/main/java/org/locationtech/jts/operation/relateng/BasicPredicate.java @@ -41,6 +41,16 @@ protected void updateValue(boolean val) { updateValue(TopologyPredicateValue.toValue(val)); } + protected void setRequire(boolean cond) { + if (! cond) + updateValue(false); + } + + protected void setValueIf(boolean value, boolean cond) { + if (cond) + updateValue(value); + } + protected void updateValue(int val) { //-- don't change already-known value if (isKnown()) diff --git a/modules/core/src/main/java/org/locationtech/jts/operation/relateng/IMPredicate.java b/modules/core/src/main/java/org/locationtech/jts/operation/relateng/IMPredicate.java index 9ba4496f9c..b9d3075942 100644 --- a/modules/core/src/main/java/org/locationtech/jts/operation/relateng/IMPredicate.java +++ b/modules/core/src/main/java/org/locationtech/jts/operation/relateng/IMPredicate.java @@ -12,6 +12,7 @@ package org.locationtech.jts.operation.relateng; import org.locationtech.jts.geom.Dimension; +import org.locationtech.jts.geom.Envelope; import org.locationtech.jts.geom.IntersectionMatrix; import org.locationtech.jts.geom.Location; @@ -62,6 +63,10 @@ protected int valuePartial() { return TopologyPredicateValue.UNKNOWN; } + protected void requireCovers(Envelope a, Envelope b) { + setRequire(a.covers(b)); + } + protected boolean intersectsExteriorOf(boolean isA) { if (isA) { return isIntersects(Location.EXTERIOR, Location.INTERIOR) diff --git a/modules/core/src/main/java/org/locationtech/jts/operation/relateng/TopologyPredicateFactory.java b/modules/core/src/main/java/org/locationtech/jts/operation/relateng/TopologyPredicateFactory.java index 9533a1bcf8..05cd84d0fd 100644 --- a/modules/core/src/main/java/org/locationtech/jts/operation/relateng/TopologyPredicateFactory.java +++ b/modules/core/src/main/java/org/locationtech/jts/operation/relateng/TopologyPredicateFactory.java @@ -24,18 +24,17 @@ public static TopologyPredicate intersects() { @Override public void init(Envelope envA, Envelope envB) { - updateValue(requireIntersects(envA, envB)); + setRequire(envA.intersects(envB)); } @Override public void updateDim(int locA, int locB, int dimension) { - if (isIntersection(locA, locB)) { - updateValue(true); - } + setValueIf(true, isIntersection(locA, locB)); } @Override public void finish() { + //-- if no intersecting locations were found updateValue(false); } @@ -49,19 +48,17 @@ public static TopologyPredicate disjoint() { @Override public void init(Envelope envA, Envelope envB) { - updateValue(valueIf(true, envA.disjoint(envB))); + setValueIf(true, envA.disjoint(envB)); } @Override public void updateDim(int locA, int locB, int dimension) { - if (isIntersection(locA, locB)) { - updateValue(false); - } + setValueIf(false, isIntersection(locA, locB)); } @Override public void finish() { - //-- no intersecting locations have been found + //-- if no intersecting locations were found updateValue(true); } @@ -76,12 +73,12 @@ public static TopologyPredicate contains() { @Override public void init(int dimA, int dimB) { super.init(dimA, dimB); - updateValue( require( isDimsCompatibleWithCovers(dimA, dimB) )); + setRequire( isDimsCompatibleWithCovers(dimA, dimB) ); } @Override public void init(Envelope envA, Envelope envB) { - updateValue(requireCovers(envA, envB)); + requireCovers(envA, envB); } @Override @@ -104,12 +101,12 @@ public static TopologyPredicate covers() { @Override public void init(int dimA, int dimB) { super.init(dimA, dimB); - updateValue( require( isDimsCompatibleWithCovers(dimA, dimB) )); + setRequire( isDimsCompatibleWithCovers(dimA, dimB) ); } @Override public void init(Envelope envA, Envelope envB) { - updateValue(requireCovers(envA, envB)); + requireCovers(envA, envB); } @Override @@ -132,12 +129,12 @@ public static TopologyPredicate within() { @Override public void init(int dimA, int dimB) { super.init(dimA, dimB); - updateValue( require( isDimsCompatibleWithCovers(dimB, dimA) )); + setRequire( isDimsCompatibleWithCovers(dimB, dimA) ); } @Override public void init(Envelope envA, Envelope envB) { - updateValue(requireCovers(envB, envA)); + requireCovers(envB, envA); } @Override @@ -158,12 +155,12 @@ public static TopologyPredicate coveredBy() { @Override public void init(int dimA, int dimB) { super.init(dimA, dimB); - updateValue( require( isDimsCompatibleWithCovers(dimB, dimA) )); + setRequire( isDimsCompatibleWithCovers(dimB, dimA) ); } @Override public void init(Envelope envA, Envelope envB) { - updateValue(requireCovers(envB, envA)); + requireCovers(envB, envA); } @Override @@ -187,7 +184,7 @@ public void init(int dimA, int dimB) { super.init(dimA, dimB); boolean isBothPointsOrAreas = (dimA == Dimension.P && dimB == Dimension.P) || (dimA == Dimension.A && dimB == Dimension.A); - updateValue( require(! isBothPointsOrAreas)); + setRequire(! isBothPointsOrAreas); } @Override @@ -226,12 +223,12 @@ public static TopologyPredicate equalsTopo() { @Override public void init(int dimA, int dimB) { super.init(dimA, dimB); - updateValue( require(dimA == dimB)); + setRequire(dimA == dimB); } @Override public void init(Envelope envA, Envelope envB) { - updateValue( requireEquals(envA, envB)); + setRequire(envA.equals(envB)); } @Override @@ -259,7 +256,7 @@ public static TopologyPredicate overlaps() { @Override public void init(int dimA, int dimB) { super.init(dimA, dimB); - updateValue( require(dimA == dimB)); + setRequire(dimA == dimB); } @Override @@ -295,7 +292,7 @@ public void init(int dimA, int dimB) { super.init(dimA, dimB); //-- Points have only interiors, so cannot touch boolean isBothPoints = dimA == 0 && dimB == 0; - updateValue( require(! isBothPoints)); + setRequire(! isBothPoints); } @Override @@ -312,33 +309,6 @@ public boolean valueIM() { }; } - public static int requireEquals(Envelope envA, Envelope envB) { - return require(envA.equals(envB)); - } - - public static int requireCovers(Envelope envA, Envelope envB) { - return require(envA.covers(envB)); - } - - public static int requireIntersects(Envelope envA, Envelope envB) { - return require(envA.intersects(envB)); - } - - /** - * Returns FALSE if the condition is not met, - * or UNKNOWN if it is. - * Equivalent to "valueFalseIfNot". - * - * @param cond the required condition - * @return FALSE or UNKNOWN - */ - public static int require(boolean cond) { - if (! cond) { - return TopologyPredicateValue.FALSE; - } - return TopologyPredicateValue.UNKNOWN; - } - /** * Returns a known predicate value if the condition holds. * Otherwise returns UNKNOWN.