GEOS  3.7.2
LineSegment.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2009 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: geom/LineSegment.java r18 (JTS-1.11)
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_GEOM_LINESEGMENT_H
22 #define GEOS_GEOM_LINESEGMENT_H
23 
24 #include <geos/export.h>
25 #include <geos/geom/Coordinate.h> // for composition
26 
27 #include <geos/inline.h>
28 
29 #include <iostream> // for ostream
30 #include <memory> // for unique_ptr
31 
32 // Forward declarations
33 namespace geos {
34  namespace geom {
35  class CoordinateSequence;
36  class GeometryFactory;
37  class LineString;
38  }
39 }
40 
41 namespace geos {
42 namespace geom { // geos::geom
43 
57 class GEOS_DLL LineSegment {
58 public:
59 
60  friend std::ostream& operator<< (std::ostream& o, const LineSegment& l);
61 
62  Coordinate p0;
63 
65 
67 
68  LineSegment(const LineSegment &ls);
69 
71  LineSegment(const Coordinate& c0, const Coordinate& c1);
72 
73  LineSegment(double x0, double y0, double x1, double y1);
74 
75  virtual ~LineSegment();
76 
77  void setCoordinates(const Coordinate& c0, const Coordinate& c1);
78 
79  // obsoleted, use operator[] instead
80  //const Coordinate& getCoordinate(std::size_t i) const;
81 
82  const Coordinate& operator[](std::size_t i) const;
83  Coordinate& operator[](std::size_t i);
84 
85  void setCoordinates(const LineSegment& ls);
86 
88  double getLength() const;
89 
91  //
94  bool isHorizontal() const;
95 
97  //
100  bool isVertical() const;
101 
123  int orientationIndex(const LineSegment& seg) const;
124 
125  // TODO: deprecate this
126  int orientationIndex(const LineSegment* seg) const;
127 
144  int orientationIndex(const Coordinate& p) const;
145 
147  void reverse();
148 
150  //
154  void normalize();
155 
157  double angle() const;
158 
160  //
163  void midPoint(Coordinate& ret) const;
164 
166  double distance(const LineSegment& ls) const;
167 
169  double distance(const Coordinate& p) const;
170 
175  double distancePerpendicular(const Coordinate& p) const;
176 
191  void pointAlong(double segmentLengthFraction, Coordinate& ret) const;
192 
217  void pointAlongOffset(double segmentLengthFraction,
218  double offsetDistance,
219  Coordinate& ret) const;
220 
238  double projectionFactor(const Coordinate& p) const;
239 
255  double segmentFraction(const Coordinate& inputPt) const;
256 
265  void project(const Coordinate& p, Coordinate& ret) const;
266 
282  bool project(const LineSegment& seg, LineSegment& ret) const;
283 
285  //
290  void closestPoint(const Coordinate& p, Coordinate& ret) const;
291 
303  int compareTo(const LineSegment& other) const;
304 
314  bool equalsTopo(const LineSegment& other) const;
315 
324 
325  CoordinateSequence* closestPoints(const LineSegment* line);
326 
340  bool intersection(const LineSegment& line, Coordinate& coord) const;
341 
359  bool lineIntersection(const LineSegment& line, Coordinate& ret) const;
360 
367  std::unique_ptr<LineString> toGeometry(const GeometryFactory& gf) const;
368 
369 };
370 
371 std::ostream& operator<< (std::ostream& o, const LineSegment& l);
372 
374 bool operator==(const LineSegment& a, const LineSegment& b);
375 
376 
377 } // namespace geos::geom
378 } // namespace geos
379 
380 #ifdef GEOS_INLINE
381 # include "geos/geom/LineSegment.inl"
382 #endif
383 
384 #endif // ndef GEOS_GEOM_LINESEGMENT_H
geos::geom::LineSegment::closestPoint
void closestPoint(const Coordinate &p, Coordinate &ret) const
Computes the closest point on this line segment to another point.
geos::geom::LineSegment::orientationIndex
int orientationIndex(const LineSegment &seg) const
geos::geom::LineSegment::p1
Coordinate p1
Segment start.
Definition: LineSegment.h:64
geos::geom::LineSegment::reverse
void reverse()
Reverses the direction of the line segment.
geos::geom::LineSegment::project
void project(const Coordinate &p, Coordinate &ret) const
Compute the projection of a point onto the line determined by this line segment.
geos::geom::LineSegment::closestPoints
CoordinateSequence * closestPoints(const LineSegment &line)
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::operator==
GEOS_DLL bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
geos::geom::LineSegment::pointAlongOffset
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 ...
geos::geom::LineSegment::lineIntersection
bool lineIntersection(const LineSegment &line, Coordinate &ret) const
Computes the intersection point of the lines defined by two segments, if there is one.
geos::geom::LineSegment::segmentFraction
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...
geos::geom::LineSegment::LineSegment
LineSegment()
Segment end.
geos::geom::LineSegment::compareTo
int compareTo(const LineSegment &other) const
Compares this object with the specified object for order.
geos::geom::LineSegment::angle
double angle() const
geos::geom::LineSegment::orientationIndex
int orientationIndex(const Coordinate &p) const
Determines the orientation index of a Coordinate relative to this segment.
geos::geom::LineSegment::distance
double distance(const Coordinate &p) const
Computes the distance between this line segment and a point.
geos::geom::LineSegment::equalsTopo
bool equalsTopo(const LineSegment &other) const
Returns true if other is topologically equal to this LineSegment (e.g. irrespective of orientation).
geos::geom::LineSegment::midPoint
void midPoint(Coordinate &ret) const
Computes the midpoint of the segment.
geos::geom::LineSegment::normalize
void normalize()
Puts the line segment into a normalized form.
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geos::geom::LineSegment::toGeometry
std::unique_ptr< LineString > toGeometry(const GeometryFactory &gf) const
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:59
geos::geom::LineSegment::pointAlong
void pointAlong(double segmentLengthFraction, Coordinate &ret) const
Computes the Coordinate that lies a given fraction along the line defined by this segment.
geos::geom::LineSegment::LineSegment
LineSegment(const Coordinate &c0, const Coordinate &c1)
Constructs a LineSegment with the given start and end Coordinates.
geos::geom::LineSegment
Definition: LineSegment.h:57
geos::geom::LineSegment::distancePerpendicular
double distancePerpendicular(const Coordinate &p) const
Computes the perpendicular distance between the (infinite) line defined by this line segment and a po...
geos::geom::operator<<
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
geos::geom::LineSegment::isHorizontal
bool isHorizontal() const
Tests whether the segment is horizontal.
geos::geom::LineSegment::intersection
bool intersection(const LineSegment &line, Coordinate &coord) const
geos::geom::LineSegment::getLength
double getLength() const
Computes the length of the line segment.
geos::geom::LineSegment::distance
double distance(const LineSegment &ls) const
Computes the distance between this line segment and another one.
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
geos::geom::LineSegment::project
bool project(const LineSegment &seg, LineSegment &ret) const
Project a line segment onto this line segment and return the resulting line segment.
geos::geom::LineSegment::projectionFactor
double projectionFactor(const Coordinate &p) const
Compute the projection factor for the projection of the point p onto this LineSegment.
geos::geom::LineSegment::isVertical
bool isVertical() const
Tests whether the segment is vertical.