Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Apr 8, 2024
1 parent f0b1b54 commit 1009ab5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private void prepareSections() {
}

private static boolean hasMultiplePolygonSections(List<NodeSection> sections, int i) {
//-- if last section can only be one
if (i >= sections.size() - 1)
return false;
//-- check if there are at least two sections for same polygon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public static String name(boolean isA) {
private Geometry geom;
private int dim;
private LinearBoundary lineBoundary;
private PointOnGeometryLocator areaLocator = null;
private PointLocator lineLocator = null;
private boolean isPrepared = false;
private List<Coordinate> pts;
private Set<Coordinate> uniquePoints;
Expand Down Expand Up @@ -129,35 +127,7 @@ public boolean isZeroLength() {
return geom.getLength() <= 0;
}

/**
* Tests whether a node is significant and should be
* evaluated to see if it adds topological information.
* A node is significant if it is an actual crossing point
* of the geometry edges, and is not in the interior of another area
* (which can only happen in a mixed-type GC).
* Otherwise, the topology at the point will be determined
* by other evaluation.
*
* @param nodePt the node coordinate
* @return true if the node is significant
*/
/*
public boolean isSignificantNode(Coordinate nodePt) {
RelatePointLocator locator = new RelatePointLocator(geom);
int loc = locator.locateNodeWithDim(nodePt);
if (loc == Location.EXTERIOR)
return false;
//-- need to check this
//if (loc == RelatePointLocator.AREA_INTERIOR)
// return false;
//-- node is not in interior of a GC area
return true;
}
*/

public boolean isAreaInterior(Coordinate nodePt) {
public boolean isNodeInArea(Coordinate nodePt) {
RelatePointLocator locator = new RelatePointLocator(geom);
int loc = locator.locateNodeWithDim(nodePt);
return loc == RelatePointLocator.AREA_INTERIOR;
Expand All @@ -167,13 +137,6 @@ public int locateNode(Coordinate pt) {
RelatePointLocator locator = new RelatePointLocator(geom);
return locator.locateNode(pt);
}

public int locate(Coordinate pt) {
//TODO: provide an indexed option - or just always use indexed?
RelatePointLocator locator = new RelatePointLocator(geom);
int loc = locator.locate(pt);
return loc;
}

public int locateWithDim(Coordinate pt) {
//TODO: provide an indexed option
Expand All @@ -182,6 +145,7 @@ public int locateWithDim(Coordinate pt) {
return loc;
}

/*
public int OLDlocate(Coordinate pt) {
//TODO: to support mixed GCs all dimensions will have to be tested
switch (dim) {
Expand Down Expand Up @@ -223,7 +187,7 @@ private int locateOnArea(Coordinate pt) {
}
return areaLocator.locate(pt);
}

*/
public boolean isPointsOrPolygons() {
return geom instanceof Point
|| geom instanceof MultiPoint
Expand Down Expand Up @@ -273,7 +237,7 @@ public List<Coordinate> getCoordinates() {
return pts;
}

public List<Point> getPoints() {
public List<Point> getEffectivePoints() {
List<Point> ptListAll = PointExtracter.getPoints(geom);

if (getDimensionEffective() <= Dimension.P)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public boolean compute(TopologyPredicate predicate, Geometry inputB) {

//-- optimize P/P evaluation
if (dimA == Dimension.P && dimB == Dimension.P) {
computePointPointOpt(geomB, topoBuilder);
computePP(geomB, topoBuilder);
topoBuilder.finish();
return topoBuilder.getResult();
}
Expand Down Expand Up @@ -163,12 +163,12 @@ private boolean finishValue(TopologyPredicate predicate) {

/**
* An optimized algorithm for evaluating P/P cases.
* It only tests one point set against the other.
* It tests one point set against the other.
*
* @param geomB
* @param topoBuilder
*/
private void computePointPointOpt(RelateGeometry geomB, TopologyBuilder topoBuilder) {
private void computePP(RelateGeometry geomB, TopologyBuilder topoBuilder) {
Set<Coordinate> ptsA = geomA.getUniquePoints();
//TODO: only query points in interaction extent?
Set<Coordinate> ptsB = geomB.getUniquePoints();
Expand Down Expand Up @@ -212,13 +212,15 @@ private void computeAtPoints(RelateGeometry geomSrc, boolean isA,

private boolean computePoints(RelateGeometry geom, boolean isA, RelateGeometry geomTarget,
TopologyBuilder topoBuilder) {
List<Point> points = geom.getPoints();
List<Point> points = geom.getEffectivePoints();
for (Point pt : points) {
if (pt.isEmpty())
continue;

Coordinate p = pt.getCoordinate();
//TODO: break when all possible topo locations have been found

//TODO: break when all possible topo locations have been found?

int locDimTarget = geomTarget.locateWithDim(p);
int locTarget = RelatePointLocator.location(locDimTarget);
int dimTarget = RelatePointLocator.dimension(locDimTarget, topoBuilder.getDimension(! isA));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ public static int dimension(int dimLoc) {
return Dimension.FALSE;
}

public static int dimension(int dimLoc, int geomDim) {
public static int dimension(int dimLoc, int exteriorDim) {
if (location(dimLoc) == Location.EXTERIOR)
return geomDim;
return exteriorDim;
return dimension(dimLoc);
}

private Geometry geom;
private BoundaryNodeRule boundaryRule;

private int elementDim = Dimension.FALSE;
private int numBoundaries = 0; // the number of sub-elements whose boundaries the point lies in
private int numLineBoundaries = 0; // the number of sub-elements whose boundaries the point lies in
private int numAreaBoundaries = 0;
private int elementLocation = Location.EXTERIOR;

public RelatePointLocator(Geometry geom) {
Expand All @@ -95,18 +96,6 @@ public RelatePointLocator(Geometry geom, BoundaryNodeRule bnRule) {
this.boundaryRule = bnRule;
}

/**
* Convenience method to test a point for intersection with
* a Geometry
* @param p the coordinate to test
* @param geom the Geometry to test
* @return <code>true</code> if the point is in the interior or boundary of the Geometry
*/
public boolean intersects(Coordinate p)
{
return locate(p) != Location.EXTERIOR;
}

public int locate(Coordinate p) {
return location(locateWithDim(p));
}
Expand Down Expand Up @@ -175,7 +164,7 @@ private int locateWithDim(Coordinate p, boolean isNode)
return POINT_INTERIOR;
}
if (elementDim == Dimension.L) {
if (boundaryRule.isInBoundary(numBoundaries))
if (boundaryRule.isInBoundary(numLineBoundaries))
return LINE_BOUNDARY;
return LINE_INTERIOR;

Expand Down Expand Up @@ -246,8 +235,11 @@ private void updateLocationInfo(int loc, int dimension)
return;
}

if (dimension == Dimension.L && loc == Location.BOUNDARY) {
numBoundaries++;
if (loc == Location.BOUNDARY) {
switch (dimension) {
case Dimension.L: numLineBoundaries++;
case Dimension.A: numAreaBoundaries++;
}
}
elementLocation = loc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,18 @@ public void addPointOnGeometry(boolean isA, int locTarget, int dimTarget, Coordi
case Dimension.P:
return;
case Dimension.L:
/**
* Because zero-length lines are handled,
* a point lying in the exterior of the line target
* may imply either P or L for the Exterior interaction
*/
//TODO: determine if effective dimension of linear target is L?
//updateDim(isGeomA, Location.EXTERIOR, locTarget, Dimension.P);
return;
case Dimension.A:
/**
* If a point intersects an area, then the area interior and boundary
* must extend beyond the point.
* If a point intersects an area target, then the area interior and boundary
* must extend beyond the point and thus interact with its exterior.
*/
updateDim(isA, Location.EXTERIOR, Location.INTERIOR, Dimension.A);
updateDim(isA, Location.EXTERIOR, Location.BOUNDARY, Dimension.L);
Expand Down Expand Up @@ -377,8 +383,8 @@ public void evaluateNodes() {
if (nodeSections.hasInteractionAB()) {
RelateNode node = nodeSections.createNode();
//-- Node must have edges for geom, but may also be in interior of a overlapping GC
boolean isAreaInteriorA = geomA.isAreaInterior(p);
boolean isAreaInteriorB = geomB.isAreaInterior(p);
boolean isAreaInteriorA = geomA.isNodeInArea(p);
boolean isAreaInteriorB = geomB.isNodeInArea(p);
node.finish(isAreaInteriorA, isAreaInteriorB);
evaluateNode(node);
if (isResultKnown())
Expand Down

0 comments on commit 1009ab5

Please sign in to comment.