Search in sources :

Example 1 with DirectedEdge

use of com.revolsys.geometry.geomgraph.DirectedEdge in project com.revolsys.open by revolsys.

the class Buffer method findStabbedSegments.

/**
 * Finds all non-horizontal segments intersecting the stabbing line
 * in the input dirEdge.
 * The stabbing line is the ray to the right of stabbingRayLeftPt.
 *
 * @param stabbingRayLeftPt the left-hand origin of the stabbing line
 * @param stabbedSegments the current list of {@link DepthSegments} intersecting the stabbing line
 */
private static void findStabbedSegments(final Collection<BufferSubgraph> subgraphs, final Point stabbingRayLeftPt, final DirectedEdge dirEdge, final List<DepthSegment> stabbedSegments) {
    final Edge edge = dirEdge.getEdge();
    for (int i = 0; i < edge.getVertexCount() - 1; i++) {
        final Point p1 = edge.getPoint(i);
        LineSegment seg = new LineSegmentDouble(p1, edge.getPoint(i + 1));
        double y1 = seg.getY(0);
        double y2 = seg.getY(1);
        // ensure segment always points upwards
        if (y1 > y2) {
            seg = seg.reverse();
            y1 = seg.getY(0);
            y2 = seg.getY(1);
        }
        final double x1 = seg.getX(0);
        final double x2 = seg.getX(1);
        // skip segment if it is left of the stabbing line
        final double maxx = Math.max(x1, x2);
        if (maxx < stabbingRayLeftPt.getX()) {
            continue;
        }
        // the same depth info
        if (seg.isHorizontal()) {
            continue;
        }
        // skip if segment is above or below stabbing line
        if (stabbingRayLeftPt.getY() < y1 || stabbingRayLeftPt.getY() > y2) {
            continue;
        }
        // skip if stabbing ray is right of the segment
        if (CGAlgorithmsDD.orientationIndex(seg.getP0(), seg.getP1(), stabbingRayLeftPt) == CGAlgorithms.RIGHT) {
            continue;
        }
        // stabbing line cuts this segment, so record it
        int depth = dirEdge.getDepth(Position.LEFT);
        // if segment direction was flipped, use RHS depth instead
        if (!seg.getP0().equals(p1)) {
            depth = dirEdge.getDepth(Position.RIGHT);
        }
        final DepthSegment ds = new DepthSegment(seg, depth);
        stabbedSegments.add(ds);
    }
}
Also used : LineSegmentDouble(com.revolsys.geometry.model.segment.LineSegmentDouble) Point(com.revolsys.geometry.model.Point) Edge(com.revolsys.geometry.geomgraph.Edge) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) Point(com.revolsys.geometry.model.Point) LineSegment(com.revolsys.geometry.model.segment.LineSegment)

Example 2 with DirectedEdge

use of com.revolsys.geometry.geomgraph.DirectedEdge in project com.revolsys.open by revolsys.

the class ConsistentPolygonRingChecker method testLinkResultDirectedEdges.

private void testLinkResultDirectedEdges(final DirectedEdgeStar deStar, final int opCode) {
    // make sure edges are copied to resultAreaEdges list
    final List ringEdges = getPotentialResultAreaEdges(deStar, opCode);
    // find first area edge (if any) to start linking at
    DirectedEdge firstOut = null;
    DirectedEdge incoming = null;
    int state = this.SCANNING_FOR_INCOMING;
    // link edges in CCW order
    for (int i = 0; i < ringEdges.size(); i++) {
        final DirectedEdge nextOut = (DirectedEdge) ringEdges.get(i);
        final DirectedEdge nextIn = nextOut.getSym();
        // skip de's that we're not interested in
        if (!nextOut.getLabel().isArea()) {
            continue;
        }
        // record first outgoing edge, in order to link the last incoming edge
        if (firstOut == null && isPotentialResultAreaEdge(nextOut, opCode)) {
            firstOut = nextOut;
        // assert: sym.isInResult() == false, since pairs of dirEdges should
        // have been removed already
        }
        switch(state) {
            case SCANNING_FOR_INCOMING:
                if (!isPotentialResultAreaEdge(nextIn, opCode)) {
                    continue;
                }
                incoming = nextIn;
                state = this.LINKING_TO_OUTGOING;
                break;
            case LINKING_TO_OUTGOING:
                if (!isPotentialResultAreaEdge(nextOut, opCode)) {
                    continue;
                }
                // incoming.setNext(nextOut);
                state = this.SCANNING_FOR_INCOMING;
                break;
        }
    }
    // Debug.print(this);
    if (state == this.LINKING_TO_OUTGOING) {
        // Debug.print(firstOut == null, this);
        if (firstOut == null) {
            throw new TopologyException("no outgoing dirEdge found", deStar.getCoordinate());
        }
    }
}
Also used : DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) List(java.util.List) ArrayList(java.util.ArrayList) TopologyException(com.revolsys.geometry.model.TopologyException)

Example 3 with DirectedEdge

use of com.revolsys.geometry.geomgraph.DirectedEdge in project com.revolsys.open by revolsys.

the class LineBuilder method collectLineEdge.

/**
 * Collect line edges which are in the result.
 * Line edges are in the result if they are not part of
 * an area boundary, if they are in the result of the overlay operation,
 * and if they are not covered by a result area.
 *
 * @param de the directed edge to test
 * @param opCode the overlap operation
 * @param edges the list of included line edges
 */
private void collectLineEdge(final DirectedEdge de, final int opCode, final List<Edge> edges) {
    final Label label = de.getLabel();
    final Edge e = de.getEdge();
    // include L edges which are in the result
    if (de.isLineEdge()) {
        if (!de.isVisited() && OverlayOp.isResultOfOp(label, opCode) && !e.isCovered()) {
            // Debug.println("de: " + de.getLabel());
            // Debug.println("edge: " + e.getLabel());
            edges.add(e);
            de.setVisitedEdge(true);
        }
    }
}
Also used : Label(com.revolsys.geometry.geomgraph.Label) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) Edge(com.revolsys.geometry.geomgraph.Edge)

Example 4 with DirectedEdge

use of com.revolsys.geometry.geomgraph.DirectedEdge in project com.revolsys.open by revolsys.

the class RightmostEdgeFinder method getRightmostSideOfSegment.

private int getRightmostSideOfSegment(final DirectedEdge de, final int i) {
    final Edge edge = de.getEdge();
    if (i < 0 || i + 1 >= edge.getVertexCount()) {
        return -1;
    }
    final Point p1 = edge.getPoint(i);
    final Point p2 = edge.getPoint(i + 1);
    if (p1.getY() == p2.getY()) {
        // indicates edge is parallel to x-axis
        return -1;
    }
    int pos = Position.LEFT;
    if (p1.getY() < p2.getY()) {
        pos = Position.RIGHT;
    }
    return pos;
}
Also used : Point(com.revolsys.geometry.model.Point) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) Edge(com.revolsys.geometry.geomgraph.Edge) Point(com.revolsys.geometry.model.Point)

Example 5 with DirectedEdge

use of com.revolsys.geometry.geomgraph.DirectedEdge in project com.revolsys.open by revolsys.

the class RightmostEdgeFinder method checkForRightmostCoordinate.

private void checkForRightmostCoordinate(final DirectedEdge de) {
    final Edge edge = de.getEdge();
    for (int i = 0; i < edge.getVertexCount() - 1; i++) {
        // only check vertices which are the start or end point of a
        // non-horizontal segment
        // <FIX> MD 19 Sep 03 - NO! we can test all vertices, since the rightmost
        // must have a non-horiz segment adjacent to it
        final int i1 = i;
        final Point point = edge.getPoint(i1);
        if (this.minCoord == null || point.getX() > this.minCoord.getX()) {
            this.minDe = de;
            this.minIndex = i;
            this.minCoord = point;
        }
    // }
    }
}
Also used : Point(com.revolsys.geometry.model.Point) DirectedEdge(com.revolsys.geometry.geomgraph.DirectedEdge) Edge(com.revolsys.geometry.geomgraph.Edge) Point(com.revolsys.geometry.model.Point)

Aggregations

DirectedEdge (com.revolsys.geometry.geomgraph.DirectedEdge)23 Point (com.revolsys.geometry.model.Point)8 Edge (com.revolsys.geometry.geomgraph.Edge)7 ArrayList (java.util.ArrayList)6 DirectedEdgeStar (com.revolsys.geometry.geomgraph.DirectedEdgeStar)5 Node (com.revolsys.geometry.geomgraph.Node)5 List (java.util.List)3 Label (com.revolsys.geometry.geomgraph.Label)2 TopologyException (com.revolsys.geometry.model.TopologyException)2 MaximalEdgeRing (com.revolsys.geometry.operation.overlay.MaximalEdgeRing)2 EdgeRing (com.revolsys.geometry.geomgraph.EdgeRing)1 LineString (com.revolsys.geometry.model.LineString)1 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)1 LineSegment (com.revolsys.geometry.model.segment.LineSegment)1 LineSegmentDouble (com.revolsys.geometry.model.segment.LineSegmentDouble)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1