GEOS 3.3.1
|
00001 /********************************************************************** 00002 * $Id: LineSegment.h 3257 2011-03-02 12:46:57Z strk $ 00003 * 00004 * GEOS - Geometry Engine Open Source 00005 * http://geos.refractions.net 00006 * 00007 * Copyright (C) 2009 2011 Sandro Santilli <strk@keybit.net> 00008 * Copyright (C) 2005-2006 Refractions Research Inc. 00009 * Copyright (C) 2001-2002 Vivid Solutions Inc. 00010 * 00011 * This is free software; you can redistribute and/or modify it under 00012 * the terms of the GNU Lesser General Public Licence as published 00013 * by the Free Software Foundation. 00014 * See the COPYING file for more information. 00015 * 00016 ********************************************************************** 00017 * 00018 * Last port: geom/LineSegment.java r18 (JTS-1.11) 00019 * 00020 **********************************************************************/ 00021 00022 #ifndef GEOS_GEOM_LINESEGMENT_H 00023 #define GEOS_GEOM_LINESEGMENT_H 00024 00025 #include <geos/export.h> 00026 #include <geos/geom/Coordinate.h> // for composition 00027 00028 #include <geos/inline.h> 00029 00030 #include <iostream> // for ostream 00031 #include <memory> // for auto_ptr 00032 00033 // Forward declarations 00034 namespace geos { 00035 namespace geom { 00036 class CoordinateSequence; 00037 class GeometryFactory; 00038 class LineString; 00039 } 00040 } 00041 00042 namespace geos { 00043 namespace geom { // geos::geom 00044 00058 class GEOS_DLL LineSegment { 00059 public: 00060 00061 friend std::ostream& operator<< (std::ostream& o, const LineSegment& l); 00062 00063 Coordinate p0; 00064 00065 Coordinate p1; 00066 00067 LineSegment(); 00068 00069 LineSegment(const LineSegment &ls); 00070 00072 LineSegment(const Coordinate& c0, const Coordinate& c1); 00073 00074 LineSegment(double x0, double y0, double x1, double y1); 00075 00076 virtual ~LineSegment(); 00077 00078 void setCoordinates(const Coordinate& c0, const Coordinate& c1); 00079 00080 // obsoleted, use operator[] instead 00081 //const Coordinate& getCoordinate(std::size_t i) const; 00082 00083 const Coordinate& operator[](std::size_t i) const; 00084 Coordinate& operator[](std::size_t i); 00085 00086 void setCoordinates(const LineSegment& ls); 00087 00089 double getLength() const; 00090 00092 // 00095 bool isHorizontal() const; 00096 00098 // 00101 bool isVertical() const; 00102 00124 int orientationIndex(const LineSegment& seg) const; 00125 00126 // TODO: deprecate this 00127 int orientationIndex(const LineSegment* seg) const; 00128 00145 int orientationIndex(const Coordinate& p) const; 00146 00148 void reverse(); 00149 00151 // 00155 void normalize(); 00156 00158 double angle() const; 00159 00161 // 00164 void midPoint(Coordinate& ret) const; 00165 00167 double distance(const LineSegment& ls) const; 00168 00170 double distance(const Coordinate& p) const; 00171 00176 double distancePerpendicular(const Coordinate& p) const; 00177 00192 void pointAlong(double segmentLengthFraction, Coordinate& ret) const; 00193 00218 void pointAlongOffset(double segmentLengthFraction, 00219 double offsetDistance, 00220 Coordinate& ret) const; 00221 00239 double projectionFactor(const Coordinate& p) const; 00240 00256 double segmentFraction(const Coordinate& inputPt) const; 00257 00266 void project(const Coordinate& p, Coordinate& ret) const; 00267 00283 bool project(const LineSegment& seg, LineSegment& ret) const; 00284 00286 // 00291 void closestPoint(const Coordinate& p, Coordinate& ret) const; 00292 00304 int compareTo(const LineSegment& other) const; 00305 00315 bool equalsTopo(const LineSegment& other) const; 00316 00324 CoordinateSequence* closestPoints(const LineSegment& line); 00325 00326 CoordinateSequence* closestPoints(const LineSegment* line); 00327 00341 bool intersection(const LineSegment& line, Coordinate& coord) const; 00342 00360 bool lineIntersection(const LineSegment& line, Coordinate& coord) const; 00361 00368 std::auto_ptr<LineString> toGeometry(const GeometryFactory& gf) const; 00369 00370 }; 00371 00372 std::ostream& operator<< (std::ostream& o, const LineSegment& l); 00373 00375 bool operator==(const LineSegment& a, const LineSegment& b); 00376 00377 00378 } // namespace geos::geom 00379 } // namespace geos 00380 00381 #ifdef GEOS_INLINE 00382 # include "geos/geom/LineSegment.inl" 00383 #endif 00384 00385 #endif // ndef GEOS_GEOM_LINESEGMENT_H 00386 00387 /********************************************************************** 00388 * $Log$ 00389 * Revision 1.8 2006/07/21 14:49:58 strk 00390 * Fixed typo in comment 00391 * 00392 * Revision 1.7 2006/06/12 10:10:39 strk 00393 * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t. 00394 * 00395 * Revision 1.6 2006/04/12 17:19:56 strk 00396 * Ported TaggedLineStringSimplifier class, made LineSegment class 00397 * polymorphic to fix derivation of TaggedLineSegment 00398 * 00399 * Revision 1.5 2006/03/28 09:14:12 strk 00400 * Headers inclusion fix. 00401 * 00402 * Revision 1.4 2006/03/24 09:52:41 strk 00403 * USE_INLINE => GEOS_INLINE 00404 * 00405 * Revision 1.3 2006/03/16 13:28:22 strk 00406 * obsoleted getCoordinate(), replaced by operator[] 00407 * 00408 * Revision 1.2 2006/03/13 22:33:09 strk 00409 * Added missing forward declarations 00410 * 00411 * Revision 1.1 2006/03/09 16:46:49 strk 00412 * geos::geom namespace definition, first pass at headers split 00413 * 00414 **********************************************************************/