GEOS: LineSegment.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# LineSegment.h

    00001 /**********************************************************************
    00002  * $Id: LineSegment.h 2556 2009-06-06 22:22:28Z strk $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2009  Sandro Santilli <strk@keybit.net>
    00008  * Copyright (C) 2006 Refractions Research 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 rev. 1.30 (JTS-1.9)
    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(size_t i) const;
    00081
    00082         const Coordinate& operator[](size_t i) const;
    00083         Coordinate& operator[](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
    00215         void pointAlongOffset(double segmentLengthFraction,
    00216                               double offsetDistance,
    00217                               Coordinate& ret) const;
    00218
    00236         double projectionFactor(const Coordinate& p) const;
    00237
    00253         double segmentFraction(const Coordinate& inputPt) const;
    00254
    00263         void project(const Coordinate& p, Coordinate& ret) const;
    00264
    00280         bool project(const LineSegment& seg, LineSegment& ret) const;
    00281
    00283         //
    00288         void closestPoint(const Coordinate& p, Coordinate& ret) const;
    00289
    00301         int compareTo(const LineSegment& other) const;
    00302
    00312         bool equalsTopo(const LineSegment& other) const;
    00313
    00321         CoordinateSequence* closestPoints(const LineSegment& line);
    00322
    00323         CoordinateSequence* closestPoints(const LineSegment* line);
    00324
    00338         bool intersection(const LineSegment& line, Coordinate& coord) const;
    00339
    00357         bool lineIntersection(const LineSegment& line, Coordinate& coord) const;
    00358
    00365         std::auto_ptr<LineString> toGeometry(const GeometryFactory& gf) const;
    00366
    00367 };
    00368
    00369 std::ostream& operator<< (std::ostream& o, const LineSegment& l);
    00370
    00372 bool operator==(const LineSegment& a, const LineSegment& b);
    00373
    00374
    00375 } // namespace geos::geom
    00376 } // namespace geos
    00377
    00378 #ifdef GEOS_INLINE
    00379 # include "geos/geom/LineSegment.inl"
    00380 #endif
    00381
    00382 #endif // ndef GEOS_GEOM_LINESEGMENT_H
    00383
    00384 /**********************************************************************
    00385  * $Log$
    00386  * Revision 1.8  2006/07/21 14:49:58  strk
    00387  * Fixed typo in comment
    00388  *
    00389  * Revision 1.7  2006/06/12 10:10:39  strk
    00390  * Fixed getGeometryN() to take size_t rather then int, changed unsigned int parameters to size_t.
    00391  *
    00392  * Revision 1.6  2006/04/12 17:19:56  strk
    00393  * Ported TaggedLineStringSimplifier class, made LineSegment class
    00394  * polymorphic to fix derivation of TaggedLineSegment
    00395  *
    00396  * Revision 1.5  2006/03/28 09:14:12  strk
    00397  * Headers inclusion fix.
    00398  *
    00399  * Revision 1.4  2006/03/24 09:52:41  strk
    00400  * USE_INLINE => GEOS_INLINE
    00401  *
    00402  * Revision 1.3  2006/03/16 13:28:22  strk
    00403  * obsoleted getCoordinate(), replaced by operator[]
    00404  *
    00405  * Revision 1.2  2006/03/13 22:33:09  strk
    00406  * Added missing forward declarations
    00407  *
    00408  * Revision 1.1  2006/03/09 16:46:49  strk
    00409  * geos::geom namespace definition, first pass at headers split
    00410  *
    00411  **********************************************************************/