Search in sources :

Example 1 with LineSegmentDoubleGF

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;
}
Also used : CoordinatesDistanceComparator(com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) TreeSet(java.util.TreeSet) Edge(com.revolsys.geometry.graph.Edge) LineSegment(com.revolsys.geometry.model.segment.LineSegment) PointOnLineSegment(com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)

Example 2 with LineSegmentDoubleGF

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;
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 3 with LineSegmentDoubleGF

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;
        }
    }
}
Also used : LineString(com.revolsys.geometry.model.LineString) Node(com.revolsys.geometry.graph.Node) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 4 with LineSegmentDoubleGF

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);
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 5 with LineSegmentDoubleGF

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);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineSegmentDoubleGF(com.revolsys.geometry.model.segment.LineSegmentDoubleGF) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Aggregations

LineSegment (com.revolsys.geometry.model.segment.LineSegment)13 LineSegmentDoubleGF (com.revolsys.geometry.model.segment.LineSegmentDoubleGF)13 Point (com.revolsys.geometry.model.Point)8 Geometry (com.revolsys.geometry.model.Geometry)6 Edge (com.revolsys.geometry.graph.Edge)4 LineString (com.revolsys.geometry.model.LineString)4 BoundingBox (com.revolsys.geometry.model.BoundingBox)3 PointOnLineSegment (com.revolsys.geometry.model.coordinates.filter.PointOnLineSegment)2 Shape (java.awt.Shape)2 AffineTransform (java.awt.geom.AffineTransform)2 ArrayList (java.util.ArrayList)2 Node (com.revolsys.geometry.graph.Node)1 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)1 Lineal (com.revolsys.geometry.model.Lineal)1 Punctual (com.revolsys.geometry.model.Punctual)1 Triangle (com.revolsys.geometry.model.Triangle)1 CoordinatesDistanceComparator (com.revolsys.geometry.model.coordinates.comparator.CoordinatesDistanceComparator)1 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)1 TreeSet (java.util.TreeSet)1