8000 Add Variable buffer class by dr-jts · Pull Request #495 · locationtech/jts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Variable buffer class #495

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

Merged
merged 3 commits into from
Nov 20, 2019
Merged
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 @@ -27,6 +27,7 @@
import org.locationtech.jts.operation.buffer.BufferParameters;
import org.locationtech.jts.operation.buffer.OffsetCurveBuilder;
import org.locationtech.jts.operation.buffer.OffsetCurveSetBuilder;
import org.locationtech.jts.operation.buffer.VariableBuffer;
import org.locationtech.jts.operation.buffer.validate.BufferResultValidator;
import org.locationtech.jtstest.geomfunction.Metadata;

Expand Down Expand Up @@ -190,4 +191,13 @@ public Geometry map(Geometry g)
public static Geometry bufferAndInverse(Geometry g, double distance) {
return g.buffer(distance).buffer(-distance);
}

@Metadata(description="Buffer a line by a distance varying along the line")
public static Geometry variableBuffer(Geometry line,
@Metadata(title="Start distance")
double startDist,
@Metadata(title="End distance")
double endDist) {
return VariableBuffer.buffer(line, startDist, endDist);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ public static Geometry lineIntersectionDD(Geometry g1, Geometry g2)
return g1.getFactory().createPoint(intPt);
}

public static Geometry reflectPoint(Geometry g1, Geometry g2)
{
Coordinate[] line = g1.getCoordinates();
Coordinate pt = g2.getCoordinate();

LineSegment seg = new LineSegment(line[0], line[1]);
Coordinate reflectPt = seg.reflect(pt);

return g1.getFactory().createPoint(reflectPt);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,32 @@ public LineSegment project(LineSegment seg)

return new LineSegment(newp0, newp1);
}

/**
* Computes the reflection of a point in the line defined
* by this line segment.
*
* @param p the point to reflect
* @return the reflected point
*/
public Coordinate reflect(Coordinate p) {
// general line equation
double A = p1.getY() - p0.getY();
double B = p0.getX() - p1.getX();
double C = p0.getY() * (p1.getX() - p0.getX()) - p0.getX()*( p1.getY() - p0.getY() );

// compute reflected point
double A2plusB2 = A*A + B*B;
double A2subB2 = A*A - B*B;

double x = p.getX();
double y = p.getY();
double rx = ( -A2subB2*x - 2*A*B*y - 2*A*C ) / A2plusB2;
double ry = ( A2subB2*y - 2*A*B*x - 2*B*C ) / A2plusB2;

return new Coordinate(rx, ry);
}

/**
* Computes the closest point on this line segment to another point.
* @param p the point to find the closest point to
Expand Down
Loading
0