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> 38 class CoordinateSequence;
39 class GeometryFactory;
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);
188 int orientationIndex(
const LineSegment& seg)
const;
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));
318 void pointAlongOffset(
double segmentLengthFraction,
319 double offsetDistance,
355 double projectionFactor(
const Coordinate& p)
const;
372 double segmentFraction(
const Coordinate& inputPt)
const;
439 std::array<Coordinate, 2> closestPoints(
const LineSegment& line);
441 std::array<Coordinate, 2> closestPoints(
const LineSegment* line)
444 return closestPoints(*line);
459 Coordinate intersection(
const LineSegment& line)
const;
477 Coordinate lineIntersection(
const LineSegment& line)
const;
485 std::unique_ptr<LineString> toGeometry(
const GeometryFactory& gf)
const;
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;
int orientationIndex(const Coordinate &p) const
Determines the orientation index of a Coordinate relative to this segment.
Definition: LineSegment.h:215
Definition: LineSegment.h:60
Coordinate p1
Segment start.
Definition: LineSegment.h:64
double distance(const Coordinate &p) const
Computes the distance between this line segment and a point.
Definition: LineSegment.h:259
double y
y-coordinate
Definition: Coordinate.h:81
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
bool isVertical() const
Definition: LineSegment.h:162
static double pointToSegment(const geom::Coordinate &p, const geom::Coordinate &A, const geom::Coordinate &B)
double minX() const
gets the minimum X ordinate value
Definition: LineSegment.h:120
static double pointToLinePerpendicular(const geom::Coordinate &p, const geom::Coordinate &A, const geom::Coordinate &B)
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
bool isHorizontal() const
Definition: LineSegment.h:153
static double segmentToSegment(const geom::Coordinate &A, const geom::Coordinate &B, const geom::Coordinate &C, const geom::Coordinate &D)
double minY() const
gets the minimum Y ordinate value
Definition: LineSegment.h:132
double maxY() const
gets the maximum Y ordinate value
Definition: LineSegment.h:138
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
double getLength() const
Computes the length of the line segment.
Definition: LineSegment.h:144
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...
double distance(const LineSegment &ls) const
Computes the distance between this line segment and another one.
Definition: LineSegment.h:253
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 midPoint(Coordinate &ret) const
Computes the midpoint of the segment.
Definition: LineSegment.h:245
double maxX() const
gets the maximum X ordinate value
Definition: LineSegment.h:126
double distance(const Coordinate &p) const
Definition: Coordinate.h:191
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
double angle() const
Definition: LineSegment.h:236
void normalize()
Puts the line segment into a normalized form.
Definition: LineSegment.h:228
friend bool operator==(const LineSegment &a, const LineSegment &b)
Checks if two LineSegment are equal (2D only check)
Definition: LineSegment.h:69