LineSegment class
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 ). 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.
@version 1.7
- Implemented types
- Implementers
Constructors
- LineSegment(double x0, double y0, double x1, double y1)
- LineSegment.empty()
- LineSegment.fromCoordinates(Coordinate p0, Coordinate p1)
- LineSegment.fromSegment(LineSegment ls)
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- p0 ↔ Coordinate
-
getter/setter pair
- p1 ↔ Coordinate
-
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
angle(
) → double -
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. -
closestPoint(
Coordinate p) → Coordinate - Computes the closest point on this line segment to another point. @param p the point to find the closest point to @return a Coordinate which is the closest point on the line segment to the point p
-
closestPoints(
LineSegment line) → List< Coordinate> - Computes the closest points on two line segments.
-
compareTo(
dynamic o) → int -
Compares this object with the specified object for order.
Uses the standard lexicographic ordering for the points in the LineSegment.
override
-
distance(
LineSegment ls) → double - Computes the distance between this line segment and another segment.
-
distanceCoord(
Coordinate p) → double - Computes the distance between this line segment and a given point.
-
distancePerpendicular(
Coordinate p) → double - Computes the perpendicular distance between the (infinite) line defined by this line segment and a point.
-
equals(
Object o) → bool -
Returns
true
ifother
has the same values for its points. -
equalsTopo(
LineSegment other) → bool -
Returns
true
ifother
is topologically equal to this LineSegment (e.g. irrespective of orientation). -
getCoordinate(
int i) → Coordinate -
getLength(
) → double - Computes the length of the line segment. @return the length of the line segment
-
intersection(
LineSegment line) → 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.
-
isHorizontal(
) → bool - Tests whether the segment is horizontal.
-
isVertical(
) → bool - Tests whether the segment is vertical.
-
lineIntersection(
LineSegment line) → Coordinate? - 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.
-
maxX(
) → double - Gets the maximum X ordinate. @return the maximum X ordinate
-
maxY(
) → double - Gets the maximum Y ordinate. @return the maximum Y ordinate
-
midPoint(
) → Coordinate - Computes the midpoint of the segment
-
minX(
) → double - Gets the minimum X ordinate. @return the minimum X ordinate
-
minY(
) → double - Gets the minimum Y ordinate. @return the minimum Y ordinate
-
normalize(
) → 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}).
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
orientationIndex(
LineSegment seg) → int - 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,
-
orientationIndexCoord(
Coordinate p) → int - Determines the orientation index of a {@link Coordinate} relative to this segment. The orientation index is as defined in {@link Orientation#computeOrientation}.
-
pointAlong(
double segmentLengthFraction) → Coordinate -
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 of1.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. -
pointAlongOffset(
double segmentLengthFraction, double offsetDistance) → 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 of1.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. -
project(
LineSegment seg) → LineSegment? - 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.
-
projectCoord(
Coordinate p) → Coordinate - Compute the projection of a point onto the line determined by this line segment.
-
projectionFactor(
Coordinate p) → double - 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 on the line defined by this segment.
-
reverse(
) → void - Reverses the direction of the line segment.
-
segmentFraction(
Coordinate inputPt) → double -
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. -
setCoordinates(
Coordinate p0, Coordinate p1) → void -
setCoordinatesFromLinesegment(
LineSegment ls) → void -
toGeometry(
GeometryFactory geomFactory) → LineString - Creates a LineString with the same coordinates as this segment
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
midPointCoords(
Coordinate p0, Coordinate p1) → Coordinate - Computes the midpoint of a segment