diff --git a/types/jsts/index.d.ts b/types/jsts/index.d.ts index 5328bf05d6..1ddc4910fb 100644 --- a/types/jsts/index.d.ts +++ b/types/jsts/index.d.ts @@ -1981,6 +1981,345 @@ declare namespace jsts { ); } } + + /** + * Represents a line segment defined by two {@link Coordinate}s. Provides + * methods to compute various geometric properties and relationships of line + * segments. + *
+ * This class is designed to be easily mutable (to the extent of having its
+ * contained points public). This supports a common pattern of reusing a single
+ * LineSegment object as a way of computing segment properties on the segments
+ * defined by arrays or lists of {@link Coordinate}s.
+ *
+ * @param {Coordinate}
+ * p0
+ * @param {Coordinate}
+ * p1
+ * @constructor
+ */
+ export class LineSegment {
+ p0: Coordinate;
+ p1: Coordinate;
+
+ constructor(p0: Coordinate, p1: Coordinate);
+ /**
+ * Computes the midpoint of a segment
+ *
+ * @param {jsts.geom.Coordinate} p0
+ * @param {jsts.geom.Coordinate} p1
+ * @return {jsts.geom.Coordinate} the midpoint of the segment
+ */
+ static midPoint(p0: Coordinate, p1: Coordinate): Coordinate;
+
+ /**
+ * @param {number} i
+ * @return {jsts.geom.Coordinate}
+ */
+ getCoordinate(): number;
+
+ /**
+ * Computes the length of the line segment.
+ *
+ * @return {number} the length of the line segment.
+ */
+ getLength(): number;
+
+ /**
+ * Tests whether the segment is horizontal.
+ *
+ * @return {boolean} true if the segment is horizontal.
+ */
+ isHorizontal(): boolean;
+
+ /**
+ * Tests whether the segment is vertical.
+ *
+ * @return {boolean} true if the segment is vertical.
+ */
+ isVertical(): boolean;
+
+ /**
+ * Determines the orientation of a LineSegment relative to this segment.
+ * The concept of orientation is specified as follows:
+ * Given two line segments A and L,
+ *
seg is to the left of this segmentseg is to the right of this segmentseg has indeterminate orientation relative to this segment
+ */
+ orientationIndex1(seg: LineSegment): 1 | -1 | 0;
+
+ /**
+ * Determines the orientation index of a {@link Coordinate} relative to this segment.
+ * The orientation index is as defined in {@link CGAlgorithms#computeOrientation}.
+ *
+ * @param {jsts.geom.Coordinate} p the coordinate to compare
+ *
+ * @return 1 (LEFT) if p is to the left of this segment
+ * @return -1 (RIGHT) if p is to the right of this segment
+ * @return 0 (COLLINEAR) if p is collinear with this segment
+ *
+ * @see CGAlgorithms#computeOrientation(Coordinate, Coordinate, Coordinate)
+ */
+ orientationIndex2(p: Coordinate): 1 | -1 | 0;
+
+ /**
+ * Reverses the direction of the line segment.
+ */
+ reverse(): void;
+
+ /**
+ * Puts the line segment into a normalized form.
+ * This is useful for using line segments in maps and indexes when
+ * topological equality rather than exact equality is desired.
+ * A segment in normalized form has the first point smaller
+ * than the second (according to the standard ordering on {@link Coordinate}).
+ */
+ normalize(): void;
+
+ /**
+ * Computes the angle that the vector defined by this segment
+ * makes with the X-axis.
+ * The angle will be in the range [ -PI, PI ] radians.
+ *
+ * @return {number} the angle this segment makes with the X-axis (in radians)
+ */
+ angle(): number;
+
+ /**
+ * Computes the midpoint of the segment
+ *
+ * @return {jsts.geom.Coordinate} the midpoint of the segment
+ */
+ midPoint(): Coordinate;
+
+ /**
+ * Computes the distance between this line segment and another segment.
+ *
+ * @param {jsts.geom.LineSegment} ls
+ * @return {number} the distance to the other segment
+ */
+ distance1(ls: LineSegment): number;
+
+ /**
+ * Computes the distance between this line segment and a given point.
+ *
+ * @param {jsts.geom.Coordinate}
+ * p the coordinate.
+ * @return {number}
+ * the distance from this segment to the given point.
+ */
+ distance2(p: Coordinate): number;
+
+ /**
+ * Computes the {@link Coordinate} that lies a given
+ * fraction along the line defined by this segment.
+ * A fraction of 0.0 returns the start point of the segment;
+ * a fraction of 1.0 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 {number} segmentLengthFraction the fraction of the segment length along the line
+ * @return {jsts.geom.Coordinate} the point at that distance
+ */
+ pointAlong(segmentLengthFraction: number): Coordinate;
+
+ /**
+ * Computes the {@link Coordinate} that lies a given
+ * fraction along the line defined by this segment and offset from
+ * the segment by a given distance.
+ * A fraction of 0.0 offsets from the start point of the segment;
+ * a fraction of 1.0 offsets from the end point of the segment.
+ * The computed point is offset to the left of the line if the offset distance is
+ * positive, to the right if negative.
+ *
+ * @param {number} segmentLengthFraction the fraction of the segment length along the line
+ * @param {number} offsetDistance the distance the point is offset from the segment
+ * (positive is to the left, negative is to the right)
+ * @return {jsts.geom.Coordinate} the point at that distance and offset
+ */
+ pointAlongOffset(
+ segmentLengthFraction: number,
+ offsetDistance: number
+ ): Coordinate;
+
+ /**
+ * Computes the Projection Factor for the projection of the point p onto this
+ * LineSegment. The Projection Factor is the constant r by which the vector for
+ * this segment must be multiplied to equal the vector for the projection of
+ * p/t> on the line
+ * defined by this segment.
+ * + * The projection factor returned will be in the range (-inf, +inf). + * + * @param {Coordinate} p the point to compute the factor for. + * @return {double} the projection factor for the point. + */ + projectionFactor(p: Coordinate): number; + + /** + * Computes the fraction of distance (in [0.0, 1.0]) + * that the projection of a point occurs along this line segment. + * If the point is beyond either ends of the line segment, + * the closest fractional value (0.0 or 1.0) is returned. + *
+ * Essentially, this is the {@link #projectionFactor} clamped to + * the range [0.0, 1.0]. + * If the segment has zero length, 1.0 is returned. + * + * @param {jsts.geom.Coordinate} inputPt the point + * @return {number} the fraction along the line segment the projection of the point occurs + */ + segmentFraction(inputPt: Coordinate): number; + + /** + * Compute the projection of a point onto the line determined + * by this line segment. + *
+ * Note that the projected point + * may lie outside the line segment. If this is the case, + * the projection factor will lie outside the range [0.0, 1.0]. + * @param {jsts.geom.Coordinate} p + * @return {jsts.geom.Coordinate} + */ + project1(p: Coordinate): Coordinate; + + /** + * Project a line segment onto this line segment and return the resulting + * line segment. The returned line segment will be a subset of + * the target line line segment. This subset may be null, if + * the segments are oriented in such a way that there is no projection. + *
+ * Note that the returned line may have zero length (i.e. the same endpoints).
+ * This can happen for instance if the lines are perpendicular to one another.
+ *
+ * @param {jsts.geom.LineSegment} seg the line segment to project
+ * @return {jsts.geom.LineSegment} the projected line segment, or null if there is no overlap
+ */
+ project2(seg: LineSegment): LineSegment;
+
+ /**
+ * Computes the closest point on this line segment to another point.
+ *
+ * @param {Coordinate}
+ * p the point to find the closest point to.
+ * @return {Coordinate} a Coordinate which is the closest point on the line
+ * segment to the point p.
+ */
+ closestPoint(p: Coordinate): Coordinate;
+
+ /**
+ * Computes the closest points on two line segments.
+ *
+ * @param {LineSegment}
+ * line the segment to find the closest point to.
+ * @return {[]} a pair of Coordinates which are the closest points on the line
+ * segments.
+ */
+ closestPoints(line: LineSegment): [Coordinate, Coordinate];
+
+ /**
+ * Computes an intersection point between two line segments, if there is one.
+ * There may be 0, 1 or many intersection points between two segments. If there
+ * are 0, null is returned. If there is 1 or more, exactly one of them is
+ * returned (chosen at the discretion of the algorithm). If more information is
+ * required about the details of the intersection, the
+ * {@link RobustLineIntersector} class should be used.
+ *
+ * @param {LineSegment}
+ * line a line segment.
+ * @return {Coordinate} an intersection point, or null if there
+ * is none.
+ *
+ * @see RobustLineIntersector
+ */
+ intersection(line: LineSegment): Coordinate | null;
+
+ setCoordinates(ls: LineSegment): void;
+
+ setCoordinates2(p0: Coordinate, p1: Coordinate): void;
+
+ /**
+ * Computes the perpendicular distance between the (infinite) line defined
+ * by this line segment and a point.
+ *
+ * @param {jsts.geom.Coordinate} p the coordinate
+ * @return {number} the perpendicular distance between the defined line and the given point
+ */
+ distancePerpendicular(p: Coordinate): number;
+
+ /**
+ * Computes the intersection point of the lines of infinite extent defined
+ * by two line segments (if there is one).
+ * There may be 0, 1 or an infinite number of intersection points
+ * between two lines.
+ * If there is a unique intersection point, it is returned.
+ * Otherwise, null is returned.
+ * If more information is required about the details of the intersection,
+ * the {@link RobustLineIntersector} class should be used.
+ *
+ * @param {jsts.geom.LineSegment} line a line segment defining an straight line with infinite extent
+ * @return {jsts.geom.Coordinate} an intersection point,
+ * or null if there is no point of intersection
+ * or an infinite number of intersection points
+ *
+ * @see RobustLineIntersector
+ */
+ lineIntersection(line: LineSegment): Coordinate | null;
+
+ /**
+ * Creates a LineString with the same coordinates as this segment
+ *
+ * @param {jsts.geom.GeometryFactory} geomFactory the geometery factory to use
+ * @return {jsts.geom.LineString} a LineString with the same geometry as this segment
+ */
+ toGeometry(geomFactory: GeometryFactory): LineString;
+
+ /**
+ * Returns true if other has the same values for
+ * its points.
+ *
+ * @param {Object} o a LineSegment with which to do the comparison.
+ * @return {boolean} true if other is a LineSegment
+ * with the same values for the x and y ordinates.
+ */
+ equals(o: LineSegment): boolean;
+
+ /**
+ * Compares this object with the specified object for order.
+ * Uses the standard lexicographic ordering for the points in the LineSegment.
+ *
+ *@param {Object} o the LineSegment with which this LineSegment
+ * is being compared
+ *@return {number} a negative integer, zero, or a positive integer as this LineSegment
+ * is less than, equal to, or greater than the specified LineSegment
+ */
+ compareTo(o: LineSegment): number;
+
+ /**
+ * Returns true if other is
+ * topologically equal to this LineSegment (e.g. irrespective
+ * of orientation).
+ *
+ * @param {jsts.geom.LineSegment} other a LineSegment with which to do the comparison.
+ * @return {boolean} true if other is a LineSegment
+ * with the same values for the x and y ordinates.
+ */
+ equalsTopo(other: LineSegment): boolean;
+
+ toString(): string;
+ }
}
namespace io {
@@ -2132,6 +2471,401 @@ declare namespace jsts {
);
}
}
+
+ namespace buffer {
+ import Geometry = jsts.geom.Geometry;
+ import PrecisionModel = jsts.geom.PrecisionModel;
+
+ export class BufferParameters {
+ /**
+ * Specifies a round line buffer end cap style.
+ *
+ * @type {int}
+ */
+ static CAP_ROUND: number;
+ /**
+ * Specifies a flat line buffer end cap style.
+ *
+ * @type {int}
+ */
+ static CAP_FLAT: number;
+ /**
+ * Specifies a square line buffer end cap style.
+ *
+ * @type {int}
+ */
+ static CAP_SQUARE: number;
+ /**
+ * Specifies a round join style.
+ *
+ * @type {int}
+ */
+ static JOIN_ROUND: number;
+ /**
+ * Specifies a mitre join style.
+ */
+ static JOIN_MITRE: number;
+ /**
+ * Specifies a bevel join style.
+ *
+ * @type {int}
+ */
+ static JOIN_BEVEL: number;
+
+ /**
+ * The default number of facets into which to divide a fillet of 90 degrees. A
+ * value of 8 gives less than 2% max error in the buffer distance. For a max
+ * error of < 1%, use QS = 12. For a max error of < 0.1%, use QS = 18.
+ *
+ * @type {int}
+ */
+ static DEFAULT_QUADRANT_SEGMENTS: number;
+ /**
+ * The default mitre limit Allows fairly pointy mitres.
+ *
+ * @type {double}
+ */
+ static DEFAULT_MITRE_LIMIT: number;
+
+ /**
+ * Contains the parameters which describe how a buffer should be constructed.
+ *
+ * @constructor
+ */
+ constructor(
+ quadrantSegments?: number,
+ endCapStyle?: number,
+ joinStyle?: number,
+ mitreLimit?: number
+ );
+
+ /**
+ * Gets the number of quadrant segments which will be used
+ *
+ * @return the number of quadrant segments.
+ */
+ getQuadrantSegments(): number;
+
+ /**
+ * Sets the number of segments used to approximate a angle fillet
+ *
+ * @param {int}
+ * quadrantSegments the number of segments in a fillet for a quadrant.
+ */
+ setQuadrantSegments(quadrantSegments: number): void;
+
+ /**
+ * Sets the number of line segments used to approximate an angle fillet.
+ *
+ * mitreLimit= | + * + * quadSegs + * + * | + *+ * + *
+ * The side used is determined by the sign of the buffer distance: + *
+ * The End Cap Style for single-sided buffers is always ignored, and forced to + * the equivalent of CAP_FLAT. + * + * @param isSingleSided + * true if a single-sided buffer should be constructed. + */ + setSingleSided(isSingleSided: boolean): void; + + /** + * Tests whether the buffer is to be generated on a single side only. + * + * @return true if the generated buffer is to be single-sided. + */ + isSingleSided(): boolean; + } + + /** + * Computes the buffer of a geometry, for both positive and negative buffer + * distances. + * + * In GIS, the positive buffer of a geometry is defined as + * the Minkowski sum or difference of the geometry + * with a circle of radius equal to the absolute value of the buffer distance. + * In the CAD/CAM world buffers are known as offset curves. + * In morphological analysis they are known as erosion and + * dilation + * + * The buffer operation always returns a polygonal result. + * The negative or zero-distance buffer of lines and points is always an empty + * {@link Polygon}. + * + * Since true buffer curves may contain circular arcs, + * computed buffer polygons can only be approximations to the true geometry. + * The user can control the accuracy of the curve approximation by specifying + * the number of linear segments used to approximate curves. + * + * The end cap style of a linear buffer may be specified. The + * following end cap styles are supported: + *
maxPrecisionDigits value.
+ *
+ * @param {Geometry}
+ * g the Geometry being buffered.
+ * @param {double}
+ * distance the buffer distance.
+ * @param {int}
+ * maxPrecisionDigits the max # of digits that should be allowed by the
+ * precision determined by the computed scale factor.
+ *
+ * @return {double} a scale factor for the buffer computation.
+ */
+ static precisionScaleFactor(
+ g: Geometry,
+ distance: number,
+ maxPrecisionDigits: number
+ ): number;
+
+ /**
+ * Computes the buffer of a geometry for a given buffer distance.
+ *
+ * @param {Geometry}
+ * g the geometry to buffer.
+ * @param {double}
+ * distance the buffer distance.
+ * @return {Geometry} the buffer of the input geometry.
+ */
+ static bufferOp(g: Geometry, distance: number): Geometry;
+
+ /**
+ * Computes the buffer for a geometry for a given buffer distance and accuracy
+ * of approximation.
+ *
+ * @param {Geometry}
+ * g the geometry to buffer.
+ * @param {double}
+ * distance the buffer distance.
+ * @param {BufferParameters}
+ * params the buffer parameters to use.
+ * @return {Geometry} the buffer of the input geometry.
+ *
+ */
+ static bufferOp2(
+ g: Geometry,
+ distance: number,
+ params: BufferParameters
+ ): Geometry;
+
+ /**
+ * Computes the buffer for a geometry for a given buffer distance and accuracy
+ * of approximation.
+ *
+ * @param {Geometry}
+ * g the geometry to buffer.
+ * @param {double}
+ * distance the buffer distance.
+ * @param {int}
+ * quadrantSegments the number of segments used to approximate a
+ * quarter circle.
+ * @return {Geometry} the buffer of the input geometry.
+ *
+ */
+ static bufferOp3(
+ g: Geometry,
+ distance: number,
+ quadrantSegments: number
+ ): Geometry;
+
+ /**
+ * Computes the buffer for a geometry for a given buffer distance and accuracy
+ * of approximation.
+ *
+ * @param {Geometry}
+ * g the geometry to buffer.
+ * @param {double}
+ * distance the buffer distance.
+ * @param {int}
+ * quadrantSegments the number of segments used to approximate a
+ * quarter circle.
+ * @param {int}
+ * endCapStyle the end cap style to use.
+ * @return {Geometry} the buffer of the input geometry.
+ *
+ */
+ static bufferOp4(
+ g: Geometry,
+ distance: number,
+ quadrantSegments: number,
+ endCapStyle: number
+ ): Geometry;
+
+ /**
+ * Specifies the end cap style of the generated buffer. The styles supported are
+ * {@link #CAP_ROUND}, {@link #CAP_BUTT}, and {@link #CAP_SQUARE}. The
+ * default is CAP_ROUND.
+ *
+ * @param {int}
+ * endCapStyle the end cap style to specify.
+ */
+ setEndCapStyle(endCapStyle: number): void;
+
+ /**
+ * Sets the number of segments used to approximate a angle fillet
+ *
+ * @param {int}
+ * quadrantSegments the number of segments in a fillet for a quadrant.
+ */
+ setQuadrantSegments(quadrantSegments: number): void;
+
+ /**
+ * Returns the buffer computed for a geometry for a given buffer distance.
+ *
+ * @param {double}
+ * dist the buffer distance.
+ * @return {Geometry} the buffer of the input geometry.
+ */
+ getResultGeometry(dist: number): Geometry;
+
+ /**
+ * @param {int}
+ * precisionDigits
+ */
+ bufferReducedPrecision2(precisionDigits: number): void;
+
+ /**
+ * @param {PrecisionModel}
+ * fixedPM
+ */
+ bufferFixedPrecision(fixedPM: PrecisionModel): void;
+ }
+ }
}
}