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> 34 #include <unordered_set> 39 class CoordinateSequence;
40 class GeometryFactory;
73 LineSegment(
double x0,
double y0,
double x1,
double y1)
81 void setCoordinates(
const Coordinate& c0,
const Coordinate& c1)
87 void setCoordinates(
const LineSegment& ls)
89 setCoordinates(ls.p0, ls.p1);
95 const Coordinate& operator[](std::size_t i)
const 104 Coordinate& operator[](std::size_t i)
116 return std::min(p0.x, p1.x);
122 return std::max(p0.x, p1.x);
128 return std::min(p0.y, p1.y);
134 return std::max(p0.y, p1.y);
140 return p0.distance(p1);
182 int orientationIndex(
const LineSegment& seg)
const;
188 return orientationIndex(*seg);
238 if(p1.compareTo(p0) < 0) {
246 return std::atan2(p1.y - p0.y, p1.x - p0.x);
284 return p0.distance(p);
299 double distancePerpendicularOriented(
const CoordinateXY& p)
const;
318 p0.x + segmentLengthFraction * (p1.x - p0.x),
319 p0.y + segmentLengthFraction * (p1.y - p0.y));
346 void pointAlongOffset(
double segmentLengthFraction,
347 double offsetDistance,
383 double projectionFactor(
const CoordinateXY& p)
const;
400 double segmentFraction(
const CoordinateXY& inputPt)
const;
412 CoordinateXY project(
const CoordinateXY& p)
const;
437 void closestPoint(
const CoordinateXY& p, CoordinateXY& ret)
const;
456 std::array<Coordinate, 2> closestPoints(
const LineSegment& line);
458 std::array<Coordinate, 2> closestPoints(
const LineSegment* line)
461 return closestPoints(*line);
476 Coordinate intersection(
const LineSegment& line)
const;
494 Coordinate lineIntersection(
const LineSegment& line)
const;
502 std::unique_ptr<LineString> toGeometry(
const GeometryFactory& gf)
const;
518 int comp0 = p0.compareTo(other.p0);
522 return p1.compareTo(other.
p1);
525 std::ostream& operator<< (std::ostream& o);
527 inline bool operator==(
const LineSegment& rhs)
const {
528 return compareTo(rhs) == 0;
531 inline bool operator<(
const LineSegment& rhs)
const {
532 return compareTo(rhs) < 0;
535 inline bool operator>(
const LineSegment& rhs)
const {
536 return compareTo(rhs) > 0;
540 inline std::size_t operator()(
const LineSegment & s)
const {
541 std::size_t h = std::hash<double>{}(s.p0.x);
542 h ^= (std::hash<double>{}(s.p0.y) << 1);
543 h ^= (std::hash<double>{}(s.p1.x) << 1);
544 return h ^ (std::hash<double>{}(s.p1.y) << 1);
547 inline std::size_t operator()(
const LineSegment * s)
const {
548 std::size_t h = std::hash<double>{}(s->p0.x);
549 h ^= (std::hash<double>{}(s->p0.y) << 1);
550 h ^= (std::hash<double>{}(s->p1.x) << 1);
551 return h ^ (std::hash<double>{}(s->p1.y) << 1);
556 using UnorderedSet = std::unordered_set<LineSegment, HashCode>;
560 void project(
double factor, CoordinateXY& ret)
const;
static double pointToSegment(const geom::CoordinateXY &p, const geom::CoordinateXY &A, const geom::CoordinateXY &B)
int orientationIndex(const Coordinate &p) const
Determines the orientation index of a Coordinate relative to this segment.
Definition: LineSegment.h:223
Definition: LineSegment.h:61
Coordinate p1
Segment start.
Definition: LineSegment.h:66
double distancePerpendicular(const CoordinateXY &p) const
Definition: LineSegment.h:281
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
bool isVertical() const
Definition: LineSegment.h:156
double minX() const
gets the minimum X ordinate value
Definition: LineSegment.h:114
bool operator<(const CoordinateXY &a, const CoordinateXY &b)
Strict weak ordering operator for Coordinate.
Definition: Coordinate.h:453
int compareTo(const LineSegment &other) const
Compares this object with the specified object for order.
Definition: LineSegment.h:516
bool isHorizontal() const
Definition: LineSegment.h:147
double minY() const
gets the minimum Y ordinate value
Definition: LineSegment.h:126
double maxY() const
gets the maximum Y ordinate value
Definition: LineSegment.h:132
LineSegment(const Coordinate &c0, const Coordinate &c1)
Segment end.
Definition: LineSegment.h:68
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
double getLength() const
Computes the length of the line segment.
Definition: LineSegment.h:138
double distance(const CoordinateXY &p) const
Computes the distance between this line segment and a point.
Definition: LineSegment.h:267
double distance(const LineSegment &ls) const
Computes the distance between this line segment and another one.
Definition: LineSegment.h:261
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:315
int orientationIndex(const CoordinateXY &p) const
Definition: LineSegment.h:202
void midPoint(Coordinate &ret) const
Computes the midpoint of the segment.
Definition: LineSegment.h:253
static double segmentToSegment(const geom::CoordinateXY &A, const geom::CoordinateXY &B, const geom::CoordinateXY &C, const geom::CoordinateXY &D)
double maxX() const
gets the maximum X ordinate value
Definition: LineSegment.h:120
double angle() const
Definition: LineSegment.h:244
static int index(const geom::CoordinateXY &p1, const geom::CoordinateXY &p2, const geom::CoordinateXY &q)
Returns the orientation index of the direction of the point q relative to a directed infinite line sp...
static double pointToLinePerpendicular(const geom::CoordinateXY &p, const geom::CoordinateXY &A, const geom::CoordinateXY &B)
void normalize()
Puts the line segment into a normalized form.
Definition: LineSegment.h:236