Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip redundant calculation in the DistanceOp point-linesegment #930

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -504,17 +504,32 @@ public Coordinate reflect(Coordinate p) {
* @return a Coordinate which is the closest point on the line segment to the point p
*/
public Coordinate closestPoint(Coordinate p)
{
return closestPoint(p, false);
}

/**
* Computes the closest point on this line segment to another point.
* @param p the point to find the closest point to
* @param skip0 If true, do not check p0. Client will have determined this is redundant.
* @return a Coordinate which is the closest point on the line segment to the point p
*/
public Coordinate closestPoint(Coordinate p, boolean skip0)
{
double factor = projectionFactor(p);
if (factor > 0 && factor < 1) {
return project(p, factor);
}
if (skip0) {
return p1;
}
double dist0 = p0.distance(p);
double dist1 = p1.distance(p);
if (dist0 < dist1)
return p0;
return p1;
}

/**
* Computes the closest points on two line segments.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void computeMinDistance(LineString line, Point pt,
if (dist < minDistance) {
minDistance = dist;
LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]);
Coordinate segClosestPoint = seg.closestPoint(coord);
Coordinate segClosestPoint = seg.closestPoint(coord, i > 0);
locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
locGeom[1] = new GeometryLocation(pt, 0, coord);
}
Expand Down