GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2009 2011 Sandro Santilli <strk@keybit.net> 00007 * Copyright (C) 2005-2006 Refractions Research Inc. 00008 * Copyright (C) 2001-2002 Vivid Solutions Inc. 00009 * 00010 * This is free software; you can redistribute and/or modify it under 00011 * the terms of the GNU Lesser General Public Licence as published 00012 * by the Free Software Foundation. 00013 * See the COPYING file for more information. 00014 * 00015 ********************************************************************** 00016 * 00017 * Last port: geom/LineSegment.java r18 (JTS-1.11) 00018 * 00019 **********************************************************************/ 00020 00021 #ifndef GEOS_GEOM_LINESEGMENT_H 00022 #define GEOS_GEOM_LINESEGMENT_H 00023 00024 #include <geos/export.h> 00025 #include <geos/geom/Coordinate.h> // for composition 00026 00027 #include <geos/inline.h> 00028 00029 #include <iostream> // for ostream 00030 #include <memory> // for auto_ptr 00031 00032 // Forward declarations 00033 namespace geos { 00034 namespace geom { 00035 class CoordinateSequence; 00036 class GeometryFactory; 00037 class LineString; 00038 } 00039 } 00040 00041 namespace geos { 00042 namespace geom { // geos::geom 00043 00057 class GEOS_DLL LineSegment { 00058 public: 00059 00060 friend std::ostream& operator<< (std::ostream& o, const LineSegment& l); 00061 00062 Coordinate p0; 00063 00064 Coordinate p1; 00065 00066 LineSegment(); 00067 00068 LineSegment(const LineSegment &ls); 00069 00071 LineSegment(const Coordinate& c0, const Coordinate& c1); 00072 00073 LineSegment(double x0, double y0, double x1, double y1); 00074 00075 virtual ~LineSegment(); 00076 00077 void setCoordinates(const Coordinate& c0, const Coordinate& c1); 00078 00079 // obsoleted, use operator[] instead 00080 //const Coordinate& getCoordinate(std::size_t i) const; 00081 00082 const Coordinate& operator[](std::size_t i) const; 00083 Coordinate& operator[](std::size_t i); 00084 00085 void setCoordinates(const LineSegment& ls); 00086 00088 double getLength() const; 00089 00091 // 00094 bool isHorizontal() const; 00095 00097 // 00100 bool isVertical() const; 00101 00123 int orientationIndex(const LineSegment& seg) const; 00124 00125 // TODO: deprecate this 00126 int orientationIndex(const LineSegment* seg) const; 00127 00144 int orientationIndex(const Coordinate& p) const; 00145 00147 void reverse(); 00148 00150 // 00154 void normalize(); 00155 00157 double angle() const; 00158 00160 // 00163 void midPoint(Coordinate& ret) const; 00164 00166 double distance(const LineSegment& ls) const; 00167 00169 double distance(const Coordinate& p) const; 00170 00175 double distancePerpendicular(const Coordinate& p) const; 00176 00191 void pointAlong(double segmentLengthFraction, Coordinate& ret) const; 00192 00217 void pointAlongOffset(double segmentLengthFraction, 00218 double offsetDistance, 00219 Coordinate& ret) const; 00220 00238 double projectionFactor(const Coordinate& p) const; 00239 00255 double segmentFraction(const Coordinate& inputPt) const; 00256 00265 void project(const Coordinate& p, Coordinate& ret) const; 00266 00282 bool project(const LineSegment& seg, LineSegment& ret) const; 00283 00285 // 00290 void closestPoint(const Coordinate& p, Coordinate& ret) const; 00291 00303 int compareTo(const LineSegment& other) const; 00304 00314 bool equalsTopo(const LineSegment& other) const; 00315 00323 CoordinateSequence* closestPoints(const LineSegment& line); 00324 00325 CoordinateSequence* closestPoints(const LineSegment* line); 00326 00340 bool intersection(const LineSegment& line, Coordinate& coord) const; 00341 00359 bool lineIntersection(const LineSegment& line, Coordinate& ret) const; 00360 00367 std::auto_ptr<LineString> toGeometry(const GeometryFactory& gf) const; 00368 00369 }; 00370 00371 std::ostream& operator<< (std::ostream& o, const LineSegment& l); 00372 00374 bool operator==(const LineSegment& a, const LineSegment& b); 00375 00376 00377 } // namespace geos::geom 00378 } // namespace geos 00379 00380 #ifdef GEOS_INLINE 00381 # include "geos/geom/LineSegment.inl" 00382 #endif 00383 00384 #endif // ndef GEOS_GEOM_LINESEGMENT_H