use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class EdgeRing method computePoints.
/**
* Collect all the points from the DirectedEdges of this ring into a contiguous list
*/
private void computePoints(final DirectedEdge start) {
final LineStringEditor points = new LineStringEditor(2, 10);
this.startDe = start;
DirectedEdge de = start;
boolean isFirstEdge = true;
do {
// Assert.isTrue(de != null, "found null Directed Edge");
if (de == null) {
throw new TopologyException("Found null DirectedEdge");
}
if (de.getEdgeRing() == this) {
throw new TopologyException("Directed Edge visited twice during ring-building at " + de.getCoordinate());
}
this.edges.add(de);
final Label label = de.getLabel();
if (!label.isArea()) {
throw new IllegalStateException("Label is not an area");
}
mergeLabel(label);
addPoints(points, de.getEdge(), de.isForward(), isFirstEdge);
isFirstEdge = false;
setEdgeRing(de, this);
de = getNext(de);
} while (de != this.startDe);
this.ring = points.newLinearRing();
this.isHole = this.ring.isCounterClockwise();
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class Clipper method clip.
public static LineString clip(final LineString line, final double line1x1, final double line1y1, final double line1x2, final double line1y2) {
final LineStringEditor result = new LineStringEditor(line.getGeometryFactory(), line.getVertexCount());
line.forEachSegment((line2x1, line2y1, line2x2, line2y2) -> {
if (isInside(line1x1, line1y1, line1x2, line1y2, line2x2, line2y2)) {
if (!isInside(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1)) {
addIntersection(result, line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
}
result.appendVertex(line2x2, line2y2);
} else if (isInside(line1x1, line1y1, line1x2, line1y2, line2x1, line2y1)) {
addIntersection(result, line1x1, line1y1, line1x2, line1y2, line2x1, line2y1, line2x2, line2y2);
}
});
if (!result.isClosed() && !result.isEmpty()) {
result.appendVertex(result.getX(0), result.getY(0));
}
return result;
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class SnapTransformer method snapSegments.
/**
* Snap segments of the source to nearby snap vertices.
* Source segments are "cracked" at a snap vertex.
* A single input segment may be snapped several times
* to different snap vertices.
* <p>
* For each distinct snap vertex, at most one source segment
* is snapped to. This prevents "cracking" multiple segments
* at the same point, which would likely cause
* topology collapse when being used on polygonal linework.
*
* @param newCoordinates the coordinates of the source linestring to be snapped
* @param snapPoints the target snap vertices
*/
private LineString snapSegments(LineString line) {
LineStringEditor newLine = null;
for (final Point snapPoint : this.snapPoints) {
final int index = findSegmentIndexToSnap(snapPoint, line);
/**
* If a segment to snap to was found, "crack" it at the snap pt.
* The new pt is inserted immediately into the src segment list,
* so that subsequent snapping will take place on the modified segments.
* Duplicate points are not added.
*/
if (index >= 0) {
if (newLine == null) {
if (line instanceof LineStringEditor) {
newLine = (LineStringEditor) line;
} else {
newLine = LineStringEditor.newLineStringEditor(line);
line = newLine;
}
}
newLine.insertVertex(index + 1, snapPoint, false);
}
}
if (newLine == null) {
return line;
} else {
return newLine;
}
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class LineString method newGeometryEditor.
@Override
default LineStringEditor newGeometryEditor(final int axisCount) {
final LineStringEditor geometryEditor = newGeometryEditor();
geometryEditor.setAxisCount(axisCount);
return geometryEditor;
}
use of com.revolsys.geometry.model.editor.LineStringEditor in project com.revolsys.open by revolsys.
the class LineString method editLine.
default LineString editLine(final Consumer<LineStringEditor> edit) {
final LineStringEditor editor = newGeometryEditor();
edit.accept(editor);
if (editor.isModified()) {
return editor.newGeometry();
} else {
return this;
}
}
Aggregations