Search in sources :

Example 36 with Point

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

the class LineSegment method getIntersection.

default LineSegment getIntersection(BoundingBox boundingBox) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    boundingBox = boundingBox.convert(geometryFactory);
    final Point lineStart = getPoint(0);
    final Point lineEnd = getPoint(1);
    final boolean contains1 = boundingBox.covers(lineStart);
    final boolean contains2 = boundingBox.covers(lineEnd);
    if (contains1) {
        if (contains2) {
            return this;
        } else {
            final Point c1 = lineStart;
            final Point c2 = getCrossing(lineEnd, lineStart, boundingBox);
            return new LineSegmentDoubleGF(geometryFactory, c1, c2);
        }
    } else {
        if (contains2) {
            final Point c1 = getCrossing(lineStart, lineEnd, boundingBox);
            final Point c2 = lineEnd;
            return new LineSegmentDoubleGF(geometryFactory, c1, c2);
        } else {
            final Point c1 = getCrossing(lineStart, lineEnd, boundingBox);
            final Point c2 = getCrossing(lineEnd, lineStart, boundingBox);
            return new LineSegmentDoubleGF(geometryFactory, c1, c2);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 37 with Point

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

the class LineSegment method convertGeometry.

@Override
@SuppressWarnings("unchecked")
default <V extends Geometry> V convertGeometry(final GeometryFactory geometryFactory) {
    final GeometryFactory factory = getGeometryFactory();
    if (geometryFactory == factory) {
        return (V) this;
    } else {
        final Point point1 = ProjectionFactory.convert(getPoint(0), factory, geometryFactory);
        final Point point2 = ProjectionFactory.convert(getPoint(1), factory, geometryFactory);
        return (V) new LineSegmentDoubleGF(geometryFactory, point1, point2);
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 38 with Point

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

the class LineSegment method extend.

default LineSegment extend(final double startDistance, final double endDistance) {
    final double angle = angle();
    final Point c1 = CoordinatesUtil.offset(getPoint(0), angle, -startDistance);
    final Point c2 = CoordinatesUtil.offset(getPoint(1), angle, endDistance);
    return new LineSegmentDoubleGF(getGeometryFactory(), c1, c2);
}
Also used : Point(com.revolsys.geometry.model.Point)

Example 39 with Point

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

the class LineSegment method pointAlong.

/**
 * Computes the {@link Coordinates} that lies a given
 * fraction along the line defined by this segment.
 * A fraction of <code>0.0</code> returns the start point of the segment;
 * a fraction of <code>1.0</code> returns the end point of the segment.
 * If the fraction is < 0.0 or > 1.0 the point returned
 * will lie before the start or beyond the end of the segment.
 *
 * @param projectionFactor the fraction of the segment length along the line
 * @return the point at that distance
 */
default Point pointAlong(final double projectionFactor) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    final int axisCount = getAxisCount();
    final double[] coordinates = new double[axisCount];
    for (int i = 0; i < axisCount; i++) {
        final double value1 = getCoordinate(0, i);
        final double value2 = getCoordinate(1, i);
        final double delta = value2 - value1;
        double newValue = value1 + delta * projectionFactor;
        newValue = geometryFactory.makePrecise(i, newValue);
        coordinates[i] = newValue;
    }
    return newPoint(coordinates);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point)

Example 40 with Point

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

the class BoundingBoxDoubleXY method newBoundingBox.

public static BoundingBox newBoundingBox(final Point... points) {
    double minX = Double.POSITIVE_INFINITY;
    double maxX = Double.NEGATIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY;
    double maxY = Double.NEGATIVE_INFINITY;
    for (final Point point : points) {
        final double x = point.getX();
        final double y = point.getY();
        if (x < minX) {
            minX = x;
        }
        if (y < minY) {
            minY = y;
        }
        if (x > maxX) {
            maxX = x;
        }
        if (y > maxY) {
            maxY = y;
        }
    }
    return newBoundingBoxXY(minX, minY, maxX, maxY);
}
Also used : Point(com.revolsys.geometry.model.Point)

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