Search in sources :

Example 46 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class SimpleSnapRounder method computeVertexSnaps.

/**
 * Performs a brute-force comparison of every segment in each {@link SegmentString}.
 * This has n^2 performance.
 */
private void computeVertexSnaps(final NodedSegmentString segment1, final NodedSegmentString segment2) {
    for (int i0 = 0; i0 < segment1.size() - 1; i0++) {
        final Point point1 = segment1.getPoint(i0);
        final HotPixel hotPixel = new HotPixel(point1, this.scaleFactor, this.li);
        for (int i1 = 0; i1 < segment2.size() - 1; i1++) {
            // don't snap a vertex to itself
            if (segment1 == segment2) {
                if (i0 == i1) {
                    continue;
                }
            }
            // System.out.println("trying " + pts0[i0] + " against " + pts1[i1] +
            // pts1[i1 + 1]);
            final boolean isNodeAdded = hotPixel.addSnappedNode(segment2, i1);
            // if a node is created for a vertex, that vertex must be noded too
            if (isNodeAdded) {
                segment1.addIntersection(point1, i0);
            }
        }
    }
}
Also used : Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 47 with Point

use of com.revolsys.geometry.model.Point 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 48 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class DistanceWithPoints method computeLinePoint.

private boolean computeLinePoint(final LineString line, final Point point) {
    if (this.minDistance == Double.MAX_VALUE || line.getBoundingBox().distance(point) <= this.minDistance) {
        for (final Segment segment : line.segments()) {
            final double distance = segment.distancePoint(point);
            if (distance < this.minDistance) {
                this.minDistance = distance;
                final Point closestPoint = segment.closestPoint(point);
                this.minDistancePoint1 = closestPoint;
                this.minDistancePoint2 = point;
                if (this.minDistance <= this.terminateDistance) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Point(com.revolsys.geometry.model.Point) Segment(com.revolsys.geometry.model.segment.Segment)

Example 49 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class DistanceWithPoints method computePointsPoints.

private boolean computePointsPoints(final List<Point> points1, final List<Point> points2) {
    for (final Point point1 : points1) {
        for (final Point point2 : points2) {
            final double dist = point1.distancePoint(point2);
            if (dist < this.minDistance) {
                this.minDistance = dist;
                this.minDistancePoint1 = point1;
                this.minDistancePoint2 = point2;
                if (this.minDistance <= this.terminateDistance) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Point(com.revolsys.geometry.model.Point)

Example 50 with Point

use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.

the class DistanceWithPoints method computeContainmentDistance.

private boolean computeContainmentDistance(final List<Point> locations, final List<Polygon> polygons) {
    for (final Point point : locations) {
        final double x = point.getX();
        final double y = point.getY();
        for (final Polygon polygon : polygons) {
            if (computeContainmentDistance(polygon, x, y)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Point(com.revolsys.geometry.model.Point) Polygon(com.revolsys.geometry.model.Polygon)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14