GEOS  3.3.3
LineSegment.h
1 /**********************************************************************
2  * $Id: LineSegment.h 3257 2011-03-02 12:46:57Z strk $
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2009 2011 Sandro Santilli <strk@keybit.net>
8  * Copyright (C) 2005-2006 Refractions Research Inc.
9  * Copyright (C) 2001-2002 Vivid Solutions Inc.
10  *
11  * This is free software; you can redistribute and/or modify it under
12  * the terms of the GNU Lesser General Public Licence as published
13  * by the Free Software Foundation.
14  * See the COPYING file for more information.
15  *
16  **********************************************************************
17  *
18  * Last port: geom/LineSegment.java r18 (JTS-1.11)
19  *
20  **********************************************************************/
21 
22 #ifndef GEOS_GEOM_LINESEGMENT_H
23 #define GEOS_GEOM_LINESEGMENT_H
24 
25 #include <geos/export.h>
26 #include <geos/geom/Coordinate.h> // for composition
27 
28 #include <geos/inline.h>
29 
30 #include <iostream> // for ostream
31 #include <memory> // for auto_ptr
32 
33 // Forward declarations
34 namespace geos {
35  namespace geom {
36  class CoordinateSequence;
37  class GeometryFactory;
38  class LineString;
39  }
40 }
41 
42 namespace geos {
43 namespace geom { // geos::geom
44 
58 class GEOS_DLL LineSegment {
59 public:
60 
61  friend std::ostream& operator<< (std::ostream& o, const LineSegment& l);
62 
63  Coordinate p0;
64 
66 
67  LineSegment();
68 
69  LineSegment(const LineSegment &ls);
70 
72  LineSegment(const Coordinate& c0, const Coordinate& c1);
73 
74  LineSegment(double x0, double y0, double x1, double y1);
75 
76  virtual ~LineSegment();
77 
78  void setCoordinates(const Coordinate& c0, const Coordinate& c1);
79 
80  // obsoleted, use operator[] instead
81  //const Coordinate& getCoordinate(std::size_t i) const;
82 
83  const Coordinate& operator[](std::size_t i) const;
84  Coordinate& operator[](std::size_t i);
85 
86  void setCoordinates(const LineSegment& ls);
87 
89  double getLength() const;
90 
92  //
95  bool isHorizontal() const;
96 
98  //
101  bool isVertical() const;
102 
124  int orientationIndex(const LineSegment& seg) const;
125 
126  // TODO: deprecate this
127  int orientationIndex(const LineSegment* seg) const;
128 
145  int orientationIndex(const Coordinate& p) const;
146 
148  void reverse();
149 
151  //
155  void normalize();
156 
158  double angle() const;
159 
161  //
164  void midPoint(Coordinate& ret) const;
165 
167  double distance(const LineSegment& ls) const;
168 
170  double distance(const Coordinate& p) const;
171 
176  double distancePerpendicular(const Coordinate& p) const;
177 
192  void pointAlong(double segmentLengthFraction, Coordinate& ret) const;
193 
218  void pointAlongOffset(double segmentLengthFraction,
219  double offsetDistance,
220  Coordinate& ret) const;
221 
239  double projectionFactor(const Coordinate& p) const;
240 
256  double segmentFraction(const Coordinate& inputPt) const;
257 
266  void project(const Coordinate& p, Coordinate& ret) const;
267 
283  bool project(const LineSegment& seg, LineSegment& ret) const;
284 
286  //
291  void closestPoint(const Coordinate& p, Coordinate& ret) const;
292 
304  int compareTo(const LineSegment& other) const;
305 
315  bool equalsTopo(const LineSegment& other) const;
316 
324  CoordinateSequence* closestPoints(const LineSegment& line);
325 
326  CoordinateSequence* closestPoints(const LineSegment* line);
327 
341  bool intersection(const LineSegment& line, Coordinate& coord) const;
342 
360  bool lineIntersection(const LineSegment& line, Coordinate& coord) const;
361 
368  std::auto_ptr<LineString> toGeometry(const GeometryFactory& gf) const;
369 
370 };
371 
372 std::ostream& operator<< (std::ostream& o, const LineSegment& l);
373 
375 bool operator==(const LineSegment& a, const LineSegment& b);
376 
377 
378 } // namespace geos::geom
379 } // namespace geos
380 
381 #ifdef GEOS_INLINE
382 # include "geos/geom/LineSegment.inl"
383 #endif
384 
385 #endif // ndef GEOS_GEOM_LINESEGMENT_H
386 
387 /**********************************************************************
388  * $Log$
389  * Revision 1.8 2006/07/21 14:49:58 strk
390  * Fixed typo in comment
391  *
392  * Revision 1.7 2006/06/12 10:10:39 strk
393  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
394  *
395  * Revision 1.6 2006/04/12 17:19:56 strk
396  * Ported TaggedLineStringSimplifier class, made LineSegment class
397  * polymorphic to fix derivation of TaggedLineSegment
398  *
399  * Revision 1.5 2006/03/28 09:14:12 strk
400  * Headers inclusion fix.
401  *
402  * Revision 1.4 2006/03/24 09:52:41 strk
403  * USE_INLINE => GEOS_INLINE
404  *
405  * Revision 1.3 2006/03/16 13:28:22 strk
406  * obsoleted getCoordinate(), replaced by operator[]
407  *
408  * Revision 1.2 2006/03/13 22:33:09 strk
409  * Added missing forward declarations
410  *
411  * Revision 1.1 2006/03/09 16:46:49 strk
412  * geos::geom namespace definition, first pass at headers split
413  *
414  **********************************************************************/