GEOS  3.8.0dev
EdgeIntersection.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2009-2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
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.
14  *
15  **********************************************************************
16  *
17  * Last port: geomgraph/EdgeIntersection.java rev. 1.5 (JTS-1.10)
18  *
19  **********************************************************************/
20 
21 
22 #ifndef GEOS_GEOMGRAPH_EDGEINTERSECTION_H
23 #define GEOS_GEOMGRAPH_EDGEINTERSECTION_H
24 
25 #include <geos/export.h>
26 
27 #include <geos/geom/Coordinate.h> // for composition and inlines
28 
29 #include <geos/inline.h>
30 
31 #include <ostream>
32 
33 
34 namespace geos {
35 namespace geomgraph { // geos.geomgraph
36 
45 class GEOS_DLL EdgeIntersection {
46 public:
47 
48  // the point of intersection
49  geom::Coordinate coord;
50 
51  // the edge distance of this point along the containing line segment
52  double dist;
53 
54  // the index of the containing line segment in the parent edge
55  size_t segmentIndex;
56 
57  EdgeIntersection(const geom::Coordinate& newCoord,
58  size_t newSegmentIndex, double newDist)
59  :
60  coord(newCoord),
61  dist(newDist),
62  segmentIndex(newSegmentIndex)
63  {}
64 
65  bool
66  isEndPoint(size_t maxSegmentIndex) const
67  {
68  if(segmentIndex == 0 && dist == 0.0) {
69  return true;
70  }
71  if(segmentIndex == maxSegmentIndex) {
72  return true;
73  }
74  return false;
75  }
76 
77  const geom::Coordinate&
78  getCoordinate() const
79  {
80  return coord;
81  }
82 
83  size_t
84  getSegmentIndex() const
85  {
86  return segmentIndex;
87  }
88 
89  double
90  getDistance() const
91  {
92  return dist;
93  }
94 
95 };
96 
98 //
100 inline bool
102 {
103  if(ei1.segmentIndex < ei2.segmentIndex) {
104  return true;
105  }
106  if(ei1.segmentIndex == ei2.segmentIndex) {
107  if(ei1.dist < ei2.dist) {
108  return true;
109  }
110 
111  // TODO: check if the Coordinate matches, or this will
112  // be a robustness issue in computin distance
113  // See http://trac.osgeo.org/geos/ticket/350
114  }
115  return false;
116 }
117 
118 // @deprecated, use strict weak ordering operator
119 struct GEOS_DLL EdgeIntersectionLessThen {
120  bool
121  operator()(const EdgeIntersection* ei1,
122  const EdgeIntersection* ei2) const
123  {
124  return *ei1 < *ei2;
125  }
126 };
127 
129 inline std::ostream&
130 operator<< (std::ostream& os, const EdgeIntersection& e)
131 {
132  os << e.coord << " seg # = " << e.segmentIndex << " dist = " << e.dist;
133  return os;
134 }
135 
136 } // namespace geos.geomgraph
137 } // namespace geos
138 
139 #endif // ifndef GEOS_GEOMGRAPH_EDGEINTERSECTION_H
140 
141 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Definition: EdgeIntersection.h:45
bool operator<(const EdgeIntersection &ei1, const EdgeIntersection &ei2)
Strict weak ordering operator for EdgeIntersection.
Definition: EdgeIntersection.h:101
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25