23#include <geos/export.h>
24#include <geos/geom/Coordinate.h>
25#include <geos/geom/LineSegment.h>
26#include <geos/algorithm/Distance.h>
27#include <geos/algorithm/Orientation.h>
38class CoordinateSequence;
66 friend std::ostream& operator<< (std::ostream& o,
const LineSegment& l);
71 return a.p0 == b.p0 && a.
p1 == b.
p1;
79 LineSegment(
double x0,
double y0,
double x1,
double y1)
87 void setCoordinates(
const Coordinate& c0,
const Coordinate& c1)
93 void setCoordinates(
const LineSegment& ls)
95 setCoordinates(ls.p0, ls.p1);
101 const Coordinate& operator[](std::size_t i)
const
110 Coordinate& operator[](std::size_t i)
122 return std::min(p0.
x, p1.
x);
128 return std::max(p0.
x, p1.
x);
134 return std::min(p0.
y, p1.
y);
140 return std::max(p0.
y, p1.
y);
194 return orientationIndex(*seg);
238 return std::atan2(p1.
y - p0.
y, p1.
x - p0.
x);
290 p0.
x + segmentLengthFraction * (p1.
x - p0.
x),
291 p0.
y + segmentLengthFraction * (p1.
y - p0.
y));
319 double offsetDistance,
441 std::array<Coordinate, 2> closestPoints(
const LineSegment* line)
444 return closestPoints(*line);
488 std::size_t operator()(
const LineSegment & s)
const {
489 std::size_t h = std::hash<double>{}(s.p0.
x);
490 h ^= (std::hash<double>{}(s.p0.
y) << 1);
491 h ^= (std::hash<double>{}(s.
p1.
x) << 1);
492 return h ^ (std::hash<double>{}(s.
p1.
y) << 1);
497 void project(
double factor, Coordinate& ret)
const;
static double pointToLinePerpendicular(const geom::Coordinate &p, const geom::Coordinate &A, const geom::Coordinate &B)
static double segmentToSegment(const geom::Coordinate &A, const geom::Coordinate &B, const geom::Coordinate &C, const geom::Coordinate &D)
static double pointToSegment(const geom::Coordinate &p, const geom::Coordinate &A, const geom::Coordinate &B)
static int index(const geom::Coordinate &p1, const geom::Coordinate &p2, const geom::Coordinate &q)
Returns the orientation index of the direction of the point q relative to a directed infinite line sp...
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
double distance(const Coordinate &p) const
Definition: Coordinate.h:191
double y
y-coordinate
Definition: Coordinate.h:81
double x
x-coordinate
Definition: Coordinate.h:78
int compareTo(const Coordinate &other) const
TODO: deprecate this, move logic to CoordinateLessThen instead.
Definition: Coordinate.h:161
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Definition: LineSegment.h:60
void closestPoint(const Coordinate &p, Coordinate &ret) const
Computes the closest point on this line segment to another point.
bool isVertical() const
Definition: LineSegment.h:162
double distancePerpendicular(const Coordinate &p) const
Computes the perpendicular distance between the (infinite) line defined by this line segment and a po...
Definition: LineSegment.h:268
void midPoint(Coordinate &ret) const
Computes the midpoint of the segment.
Definition: LineSegment.h:245
double minX() const
gets the minimum X ordinate value
Definition: LineSegment.h:120
int compareTo(const LineSegment &other) const
Compares this object with the specified object for order.
void pointAlongOffset(double segmentLengthFraction, double offsetDistance, Coordinate &ret) const
Computes the Coordinate that lies a given fraction along the line defined by this segment and offset ...
bool project(const LineSegment &seg, LineSegment &ret) const
Project a line segment onto this line segment and return the resulting line segment.
double minY() const
gets the minimum Y ordinate value
Definition: LineSegment.h:132
double projectionFactor(const Coordinate &p) const
Compute the projection factor for the projection of the point p onto this LineSegment.
void pointAlong(double segmentLengthFraction, Coordinate &ret) const
Computes the Coordinate that lies a given fraction along the line defined by this segment.
Definition: LineSegment.h:287
void project(const Coordinate &p, Coordinate &ret) const
Compute the projection of a point onto the line determined by this line segment.
double maxX() const
gets the maximum X ordinate value
Definition: LineSegment.h:126
bool equalsTopo(const LineSegment &other) const
Returns true if other is topologically equal to this LineSegment (e.g. irrespective of orientation).
void reverse()
Reverses the direction of the line segment.
double distance(const Coordinate &p) const
Computes the distance between this line segment and a point.
Definition: LineSegment.h:259
double distance(const LineSegment &ls) const
Computes the distance between this line segment and another one.
Definition: LineSegment.h:253
int orientationIndex(const LineSegment &seg) const
std::unique_ptr< LineString > toGeometry(const GeometryFactory &gf) const
void normalize()
Puts the line segment into a normalized form.
Definition: LineSegment.h:228
std::array< Coordinate, 2 > closestPoints(const LineSegment &line)
bool isHorizontal() const
Definition: LineSegment.h:153
double getLength() const
Computes the length of the line segment.
Definition: LineSegment.h:144
Coordinate p1
Segment start.
Definition: LineSegment.h:64
Coordinate lineIntersection(const LineSegment &line) const
Computes the intersection point of the lines defined by two segments, if there is one.
LineSegment offset(double offsetDistance)
friend bool operator==(const LineSegment &a, const LineSegment &b)
Checks if two LineSegment are equal (2D only check)
Definition: LineSegment.h:69
int orientationIndex(const Coordinate &p) const
Determines the orientation index of a Coordinate relative to this segment.
Definition: LineSegment.h:215
double angle() const
Definition: LineSegment.h:236
Coordinate intersection(const LineSegment &line) const
double maxY() const
gets the maximum Y ordinate value
Definition: LineSegment.h:138
double segmentFraction(const Coordinate &inputPt) const
Computes the fraction of distance (in [0.0, 1.0]) that the projection of a point occurs along this li...
Basic namespace for all GEOS functionalities.
Definition: geos.h:39