Use geomgraph::Label by value (less extra-heap), cleanups and port sync.
[geos.git] / include / geos / geomgraph / EdgeEnd.h
blob444c06fffb91b5d1e8f38f7d5ebd05afde076967
1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.refractions.net
6 * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
7 * Copyright (C) 2005-2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
15 **********************************************************************
17 * Last port: geomgraph/EdgeEnd.java r428 (JTS-1.12+)
19 **********************************************************************/
22 #ifndef GEOS_GEOMGRAPH_EDGEEND_H
23 #define GEOS_GEOMGRAPH_EDGEEND_H
25 #include <geos/export.h>
26 #include <geos/geom/Coordinate.h> // for p0,p1
27 #include <geos/geomgraph/Label.h> // for composition
28 #include <geos/inline.h>
30 #include <string>
32 // Forward declarations
33 namespace geos {
34 namespace algorithm {
35 class BoundaryNodeRule;
37 namespace geomgraph {
38 class Edge;
39 class Node;
43 namespace geos {
44 namespace geomgraph { // geos.geomgraph
46 /** \brief
47 * Models the end of an edge incident on a node.
49 * EdgeEnds have a direction
50 * determined by the direction of the ray from the initial
51 * point to the next point.
52 * EdgeEnds are comparable under the ordering
53 * "a has a greater angle with the x-axis than b".
54 * This ordering is used to sort EdgeEnds around a node.
56 class GEOS_DLL EdgeEnd {
58 public:
60 friend std::ostream& operator<< (std::ostream&, const EdgeEnd&);
62 EdgeEnd();
64 virtual ~EdgeEnd() {}
66 /**
67 * NOTES:
68 * - Copies the given Label
69 * - keeps a pointer to given Edge, make sure it's
70 * not deleted before the EdgeEnd.
71 * - copies given Coordinates (maybe we should avoid that)
73 EdgeEnd(Edge* newEdge, const geom::Coordinate& newP0,
74 const geom::Coordinate& newP1,
75 const Label& newLabel);
77 /**
78 * NOTES:
79 * - keeps a pointer to given Edge, make sure it's
80 * not deleted before the EdgeEnd.
81 * - copies given Coordinates (maybe we should avoid that)
83 EdgeEnd(Edge* newEdge, const geom::Coordinate& newP0,
84 const geom::Coordinate& newP1);
86 Edge* getEdge() { return edge; }
87 //virtual Edge* getEdge() { return edge; }
89 Label& getLabel() { return label; }
91 const Label& getLabel() const { return label; }
93 virtual geom::Coordinate& getCoordinate();
95 virtual geom::Coordinate& getDirectedCoordinate();
97 virtual int getQuadrant();
99 virtual double getDx();
101 virtual double getDy();
103 virtual void setNode(Node* newNode);
105 virtual Node* getNode();
107 virtual int compareTo(const EdgeEnd *e) const;
110 * Implements the total order relation:
112 * a has a greater angle with the positive x-axis than b
114 * Using the obvious algorithm of simply computing the angle
115 * is not robust, since the angle calculation is obviously
116 * susceptible to roundoff.
117 * A robust algorithm is:
118 * - first compare the quadrant. If the quadrants
119 * are different, it it trivial to determine which vector
120 * is "greater".
121 * - if the vectors lie in the same quadrant, the
122 * computeOrientation function can be used to decide
123 * the relative orientation of the vectors.
125 virtual int compareDirection(const EdgeEnd *e) const;
127 virtual void computeLabel(const algorithm::BoundaryNodeRule& bnr);
129 virtual std::string print();
131 protected:
133 Edge* edge;// the parent edge of this edge end
135 Label label;
137 EdgeEnd(Edge* newEdge);
139 virtual void init(const geom::Coordinate& newP0,
140 const geom::Coordinate& newP1);
142 private:
144 /// the node this edge end originates at
145 Node* node;
147 /// points of initial line segment. FIXME: do we need a copy here ?
148 geom::Coordinate p0, p1;
150 /// the direction vector for this edge from its starting point
151 double dx, dy;
153 int quadrant;
156 std::ostream& operator<< (std::ostream&, const EdgeEnd&);
158 struct GEOS_DLL EdgeEndLT {
159 bool operator()(const EdgeEnd *s1, const EdgeEnd *s2) const {
160 return s1->compareTo(s2)<0;
164 } // namespace geos.geomgraph
165 } // namespace geos
167 //#ifdef GEOS_INLINE
168 //# include "geos/geomgraph/EdgeEnd.inl"
169 //#endif
171 #endif // ifndef GEOS_GEOMGRAPH_EDGEEND_H