#include <LineSegment.h>
Public Member Functions | |
LineSegment () | |
Segemnt end. | |
LineSegment (const LineSegment &ls) | |
LineSegment (const Coordinate &c0, const Coordinate &c1) | |
Constructs a LineSegment with the given start and end Coordinates. | |
void | setCoordinates (const Coordinate &c0, const Coordinate &c1) |
const Coordinate & | operator[] (size_t i) const |
Coordinate & | operator[] (size_t i) |
void | setCoordinates (const LineSegment &ls) |
double | getLength () const |
Computes the length of the line segment. | |
bool | isHorizontal () const |
Tests whether the segment is horizontal. | |
bool | isVertical () const |
Tests whether the segment is vertical. | |
int | orientationIndex (const LineSegment &seg) const |
int | orientationIndex (const LineSegment *seg) const |
void | reverse () |
Reverses the direction of the line segment. | |
void | normalize () |
Puts the line segment into a normalized form. | |
double | angle () const |
| |
double | distance (const LineSegment &ls) const |
Computes the distance between this line segment and another one. | |
double | distance (const Coordinate &p) const |
Computes the distance between this line segment and a point. | |
double | distancePerpendicular (const Coordinate &p) const |
Computes the perpendicular distance between the (infinite) line defined by this line segment and a point. | |
double | projectionFactor (const Coordinate &p) const |
void | project (const Coordinate &p, Coordinate &ret) const |
Compute the projection of a point onto the line determined by this line segment. | |
bool | project (const LineSegment &seg, LineSegment &ret) const |
Project a line segment onto this line segment and return the resulting line segment. | |
void | closestPoint (const Coordinate &p, Coordinate &ret) const |
Computes the closest point on this line segment to another point. | |
int | compareTo (const LineSegment &other) const |
Compares this object with the specified object for order. | |
bool | equalsTopo (const LineSegment &other) const |
Returns true if other is topologically equal to this LineSegment (e.g. irrespective of orientation). | |
CoordinateSequence * | closestPoints (const LineSegment &line) |
CoordinateSequence * | closestPoints (const LineSegment *line) |
bool | intersection (const LineSegment &line, Coordinate &coord) const |
Public Attributes | |
Coordinate | p0 |
Coordinate | p1 |
Segment start. | |
Friends | |
std::ostream & | operator<< (std::ostream &o, const LineSegment &l) |
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 Coordinates.
TODO: have this class keep pointers rather then real Coordinates ?
bool geos::geom::LineSegment::isHorizontal | ( | ) | const |
Tests whether the segment is horizontal.
true
if the segment is horizontal bool geos::geom::LineSegment::isVertical | ( | ) | const |
Tests whether the segment is vertical.
true
if the segment is vertical int geos::geom::LineSegment::orientationIndex | ( | const LineSegment & | seg | ) | const |
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, <ul A is to the left of a segment L if A lies wholly in the closed half-plane lying to the left of L A is to the right of a segment L if A lies wholly in the closed half-plane lying to the right of L otherwise, A has indeterminate orientation relative to L. This happens if A is collinear with L or if A crosses the line determined by L.
seg | the LineSegment to compare |
-1 if seg is to the right of this segment
0 if seg has indeterminate orientation relative to this segment
void geos::geom::LineSegment::normalize | ( | ) |
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.
double geos::geom::LineSegment::projectionFactor | ( | const Coordinate & | p | ) | const |
Compute the projection factor for the projection of the point p onto this LineSegment. The projection factor is the constant k by which the vector for this segment must be multiplied to equal the vector for the projection of p.
void geos::geom::LineSegment::project | ( | const Coordinate & | p, | |
Coordinate & | ret | |||
) | const |
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].
bool geos::geom::LineSegment::project | ( | const LineSegment & | seg, | |
LineSegment & | ret | |||
) | const |
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.
seg | the line segment to project | |
ret | the projected line segment |
void geos::geom::LineSegment::closestPoint | ( | const Coordinate & | p, | |
Coordinate & | ret | |||
) | const |
Computes the closest point on this line segment to another point.
p | the point to find the closest point to | |
ret | the Coordinate to which the closest point on the line segment to the point p will be written |
int geos::geom::LineSegment::compareTo | ( | const LineSegment & | other | ) | const |
Compares this object with the specified object for order.
Uses the standard lexicographic ordering for the points in the LineSegment.
o | the LineSegment with which this LineSegment is being compared |
bool geos::geom::LineSegment::equalsTopo | ( | const LineSegment & | other | ) | const |
Returns true
if other
is topologically equal to this LineSegment (e.g. irrespective of orientation).
other | a LineSegment with which to do the comparison. |
CoordinateSequence* geos::geom::LineSegment::closestPoints | ( | const LineSegment & | line | ) |
Computes the closest points on two line segments.
p | the point to find the closest point to |
bool geos::geom::LineSegment::intersection | ( | const LineSegment & | line, | |
Coordinate & | coord | |||
) | const |
Computes an intersection point between two 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, a single one is returned (chosen at the discretion of the algorithm). If more information is required about the details of the intersection, the LineIntersector class should be used.
line | ||
coord | the Coordinate to write the result into |