# LineSegment.h

    00001 /**********************************************************************
    00002  * $Id: LineSegment.h 1820 2006-09-06 16:54:23Z mloskot $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2006 Refractions Research Inc.
    00008  *
    00009  * This is free software; you can redistribute and/or modify it under
    00010  * the terms of the GNU Lesser General Public Licence as published
    00011  * by the Free Software Foundation.
    00012  * See the COPYING file for more information.
    00013  *
    00014  **********************************************************************/
    00015
    00016 #ifndef GEOS_GEOM_LINESEGMENT_H
    00017 #define GEOS_GEOM_LINESEGMENT_H
    00018
    00019 #include <geos/geom/Coordinate.h> // for composition
    00020
    00021 #include <geos/inline.h>
    00022
    00023 #include <iostream> // for ostream
    00024
    00025 // Forward declarations
    00026 namespace geos {
    00027         namespace geom {
    00028                 class CoordinateSequence;
    00029         }
    00030 }
    00031
    00032 namespace geos {
    00033 namespace geom { // geos::geom
    00034
    00048 class LineSegment {
    00049 public:
    00050
    00051         friend std::ostream& operator<< (std::ostream& o, const LineSegment& l);
    00052
    00053         Coordinate p0;
    00054
    00055         Coordinate p1;
    00056
    00057         LineSegment();
    00058
    00059         LineSegment(const LineSegment &ls);
    00060
    00062         LineSegment(const Coordinate& c0, const Coordinate& c1);
    00063
    00064         virtual ~LineSegment();
    00065
    00066         void setCoordinates(const Coordinate& c0, const Coordinate& c1);
    00067
    00068         // obsoleted, use operator[] instead
    00069         //const Coordinate& getCoordinate(size_t i) const;
    00070
    00071         const Coordinate& operator[](size_t i) const;
    00072         Coordinate& operator[](size_t i);
    00073
    00074         void setCoordinates(const LineSegment& ls);
    00075
    00077         double getLength() const;
    00078
    00080         //
    00083         bool isHorizontal() const;
    00084
    00086         //
    00089         bool isVertical() const;
    00090
    00112         int orientationIndex(const LineSegment& seg) const;
    00113
    00114         int orientationIndex(const LineSegment* seg) const;
    00115
    00117         void reverse();
    00118
    00120         //
    00124         void normalize();
    00125
    00127         double angle() const;
    00128
    00130         double distance(const LineSegment& ls) const;
    00131
    00133         double distance(const Coordinate& p) const;
    00134
    00139         double distancePerpendicular(const Coordinate& p) const;
    00140
    00147         double projectionFactor(const Coordinate& p) const;
    00148
    00157         void project(const Coordinate& p, Coordinate& ret) const;
    00158
    00174         bool project(const LineSegment& seg, LineSegment& ret) const;
    00175
    00177         //
    00182         void closestPoint(const Coordinate& p, Coordinate& ret) const;
    00183
    00195         int compareTo(const LineSegment& other) const;
    00196
    00206         bool equalsTopo(const LineSegment& other) const;
    00207
    00215         CoordinateSequence* closestPoints(const LineSegment& line);
    00216
    00217         CoordinateSequence* closestPoints(const LineSegment* line);
    00218
    00232         bool intersection(const LineSegment& line, Coordinate& coord) const;
    00233
    00234 };
    00235
    00236 std::ostream& operator<< (std::ostream& o, const LineSegment& l);
    00237
    00239 bool operator==(const LineSegment& a, const LineSegment& b);
    00240
    00241
    00242 } // namespace geos::geom
    00243 } // namespace geos
    00244
    00245 #ifdef GEOS_INLINE
    00246 # include "geos/geom/LineSegment.inl"
    00247 #endif
    00248
    00249 #endif // ndef GEOS_GEOM_LINESEGMENT_H
    00250
    00251 /**********************************************************************
    00252  * $Log$
    00253  * Revision 1.8  2006/07/21 14:49:58  strk
    00254  * Fixed typo in comment
    00255  *
    00256  * Revision 1.7  2006/06/12 10:10:39  strk
    00257  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
    00258  *
    00259  * Revision 1.6  2006/04/12 17:19:56  strk
    00260  * Ported TaggedLineStringSimplifier class, made LineSegment class
    00261  * polymorphic to fix derivation of TaggedLineSegment
    00262  *
    00263  * Revision 1.5  2006/03/28 09:14:12  strk
    00264  * Headers inclusion fix.
    00265  *
    00266  * Revision 1.4  2006/03/24 09:52:41  strk
    00267  * USE_INLINE => GEOS_INLINE
    00268  *
    00269  * Revision 1.3  2006/03/16 13:28:22  strk
    00270  * obsoleted getCoordinate(), replaced by operator[]
    00271  *
    00272  * Revision 1.2  2006/03/13 22:33:09  strk
    00273  * Added missing forward declarations
    00274  *
    00275  * Revision 1.1  2006/03/09 16:46:49  strk
    00276  * geos::geom namespace definition, first pass at headers split
    00277  *
    00278  **********************************************************************/