Skip to content

Commit

Permalink
Improve parameter locality
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Dec 4, 2023
1 parent ab28630 commit 3c4e579
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class TaggedLineStringSimplifier
private ComponentJumpChecker jumpChecker;
private TaggedLineString line;
private Coordinate[] linePts;
private double distanceTolerance = 0.0;

public TaggedLineStringSimplifier(LineSegmentIndex inputIndex,
LineSegmentIndex outputIndex,
Expand All @@ -49,35 +48,25 @@ public TaggedLineStringSimplifier(LineSegmentIndex inputIndex,
this.jumpChecker = crossChecker;
}

/**
* Sets the distance tolerance for the simplification.
* All vertices in the simplified geometry will be within this
* distance of the original geometry.
*
* @param distanceTolerance the approximation tolerance to use
*/
public void setDistanceTolerance(double distanceTolerance) {
this.distanceTolerance = distanceTolerance;
}

/**
* Simplifies the given {@link TaggedLineString}
* using the distance tolerance specified.
*
* @param line the linestring to simplify
* @param distanceTolerance the simplification distance tolerance
*/
void simplify(TaggedLineString line)
void simplify(TaggedLineString line, double distanceTolerance)
{
this.line = line;
linePts = line.getParentCoordinates();
simplifySection(0, linePts.length - 1, 0);
simplifySection(0, linePts.length - 1, 0, distanceTolerance);

if (line.isRing() && CoordinateArrays.isRing(linePts)) {
simplifyRingEndpoint();
simplifyRingEndpoint(distanceTolerance);
}
}

private void simplifySection(int i, int j, int depth)
private void simplifySection(int i, int j, int depth, double distanceTolerance)
{
depth += 1;
//-- if section has only one segment just keep the segment
Expand Down Expand Up @@ -124,16 +113,16 @@ private void simplifySection(int i, int j, int depth)
line.addToResult(newSeg);
return;
}
simplifySection(i, furthestPtIndex, depth);
simplifySection(furthestPtIndex, j, depth);
simplifySection(i, furthestPtIndex, depth, distanceTolerance);
simplifySection(furthestPtIndex, j, depth, distanceTolerance);
}

/**
* Simplifies the result segments on either side of a ring endpoint
* (which was not processed by the initial simplification).
* This ensures that simplification removes flat (collinear) endpoints.
*/
private void simplifyRingEndpoint()
private void simplifyRingEndpoint(double distanceTolerance)
{
if (line.getResultSize() > line.getMinimumSize()) {
LineSegment firstSeg = line.getResultSegment(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public void simplify(Collection taggedLines) {
for (Iterator i = taggedLines.iterator(); i.hasNext(); ) {
TaggedLineStringSimplifier tlss
= new TaggedLineStringSimplifier(inputIndex, outputIndex, jumpChecker);
tlss.setDistanceTolerance(distanceTolerance);
tlss.simplify((TaggedLineString) i.next());
tlss.simplify((TaggedLineString) i.next(), distanceTolerance);
}
}

Expand Down

0 comments on commit 3c4e579

Please sign in to comment.