use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class LineStringGraph method splitEdge.
@Override
public <V extends Point> List<Edge<LineSegment>> splitEdge(final Edge<LineSegment> edge, final Collection<V> nodes) {
final List<Edge<LineSegment>> newEdges = new ArrayList<>();
if (!edge.isRemoved()) {
final Node<LineSegment> fromNode = edge.getFromNode();
final Node<LineSegment> toNode = edge.getToNode();
final CoordinatesDistanceComparator comparator = new CoordinatesDistanceComparator(fromNode.getX(), toNode.getY());
final Set<Point> newPoints = new TreeSet<>(comparator);
for (final Point point : nodes) {
newPoints.add(point);
}
newPoints.add(toNode);
final List<Integer> index = edge.getProperty(INDEX);
int i = 0;
Point previousPoint = fromNode;
for (final Point point : newPoints) {
final LineSegment lineSegment = new LineSegmentDoubleGF(previousPoint, point);
final Edge<LineSegment> newEdge = addEdge(lineSegment, previousPoint, point);
final List<Integer> newIndecies = new ArrayList<>(index);
newIndecies.add(i++);
newEdge.setProperty(INDEX, newIndecies);
newEdges.add(newEdge);
previousPoint = point;
}
remove(edge);
}
return newEdges;
}
use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class LineMatchGraph method add.
private Edge<LineSegmentMatch> add(final LineSegmentMatch lineSegmentMatch, final Node<LineSegmentMatch> from, final Node<LineSegmentMatch> to) {
final Edge<LineSegmentMatch> newEdge = add(from, to);
final LineSegmentMatch newLineSegmentMatch = newEdge.getObject();
for (int i = 0; i < lineSegmentMatch.getSegmentCount(); i++) {
if (lineSegmentMatch.hasSegment(i)) {
final LineSegment realSegment = lineSegmentMatch.getSegment(i);
final Point coordinate0 = realSegment.project(from);
final Point coordinate1 = realSegment.project(to);
final LineSegment newSegment = new LineSegmentDoubleGF(this.geometryFactory, coordinate0, coordinate1);
newLineSegmentMatch.addSegment(newSegment, i);
}
}
return newEdge;
}
use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class LineMatchGraph method add.
private void add(final LineString line, final int index) {
if (line.getLength() > 0) {
final LineString coords = line;
final Point coordinate0 = coords.getPoint(0);
final Node<LineSegmentMatch> node = getNode(coordinate0);
final Set<Node<LineSegmentMatch>> indexStartNodes = getStartNodes(index);
indexStartNodes.add(node);
Point previousCoordinate = coordinate0;
for (int i = 1; i < coords.getVertexCount(); i++) {
final Point coordinate = coords.getPoint(i);
final LineSegment segment = new LineSegmentDoubleGF(this.geometryFactory, previousCoordinate, coordinate);
if (segment.getLength() > 0) {
add(previousCoordinate, coordinate, segment, index);
}
previousCoordinate = coordinate;
}
}
}
use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class LineMatchGraph method splitEdge.
@Override
public List<Edge<LineSegmentMatch>> splitEdge(final Edge<LineSegmentMatch> edge, final Point point) {
final LineSegmentMatch lineSegmentMatch = edge.getObject();
final LineSegment segment = lineSegmentMatch.getSegment();
final Edge<LineSegmentMatch> edge1 = add(segment.getPoint(0), point);
final LineSegmentMatch lineSegmentMatch1 = edge1.getObject();
final Edge<LineSegmentMatch> edge2 = add(point, segment.getPoint(1));
final LineSegmentMatch lineSegmentMatch2 = edge2.getObject();
for (int i = 0; i < lineSegmentMatch.getSegmentCount(); i++) {
if (lineSegmentMatch.hasSegment(i)) {
final LineSegment realSegment = lineSegmentMatch.getSegment(i);
final Point projectedCoordinate = realSegment.project(point);
final Point startCoordinate = realSegment.getPoint(0);
final LineSegment segment1 = new LineSegmentDoubleGF(this.geometryFactory, startCoordinate, projectedCoordinate);
lineSegmentMatch1.addSegment(segment1, i);
final Point endCoordinate = realSegment.getPoint(1);
final LineSegment segment2 = new LineSegmentDoubleGF(this.geometryFactory, projectedCoordinate, endCoordinate);
lineSegmentMatch2.addSegment(segment2, i);
}
}
remove(edge);
return Arrays.asList(edge1, edge2);
}
use of com.revolsys.geometry.model.segment.LineSegmentDoubleGF in project com.revolsys.open by revolsys.
the class LineSegmentTest method assertIntersection3d.
public void assertIntersection3d(final Point line1Start, final Point line1End, final Point line2Start, final Point line2End, final Geometry expectedIntersection) {
final LineSegment line1 = new LineSegmentDoubleGF(GEOMETRY_FACTORY_3D, line1Start, line1End);
final LineSegment line2 = new LineSegmentDoubleGF(GEOMETRY_FACTORY_3D, line2Start, line2End);
final Geometry intersection = line1.getIntersection(line2);
if (!TestUtil.equalsExact(3, intersection, expectedIntersection)) {
TestUtil.failNotEquals("Equals Exact", expectedIntersection, intersection);
}
}
Aggregations