GEOS  3.9.1dev
EdgeIntersection.h
Go to the documentation of this file.
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 
46 public:
47 
48  // the point of intersection
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 
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
85  {
86  return segmentIndex;
87  }
88 
89  double
90  getDistance() const
91  {
92  return dist;
93  }
94 
95  bool operator==(const EdgeIntersection& other) const {
96  return segmentIndex == other.segmentIndex &&
97  dist == other.dist;
98 
99  // We don't check the coordinate, consistent with operator<
100  }
101 
102 };
103 
107 inline bool
109 {
110  if(ei1.segmentIndex < ei2.segmentIndex) {
111  return true;
112  }
113  if(ei1.segmentIndex == ei2.segmentIndex) {
114  if(ei1.dist < ei2.dist) {
115  return true;
116  }
117 
118  // TODO: check if the Coordinate matches, or this will
119  // be a robustness issue in computin distance
120  // See http://trac.osgeo.org/geos/ticket/350
121  }
122  return false;
123 }
124 
125 // @deprecated, use strict weak ordering operator
127  bool
129  const EdgeIntersection* ei2) const
130  {
131  return *ei1 < *ei2;
132  }
133 
134  bool
136  const EdgeIntersection& ei2) const
137  {
138  return ei1 < ei2;
139  }
140 };
141 
143 inline std::ostream&
144 operator<< (std::ostream& os, const EdgeIntersection& e)
145 {
146  os << e.coord << " seg # = " << e.segmentIndex << " dist = " << e.dist;
147  return os;
148 }
149 
150 } // namespace geos.geomgraph
151 } // namespace geos
152 
153 #endif // ifndef GEOS_GEOMGRAPH_EDGEINTERSECTION_H
154 
155 
#define GEOS_DLL
Definition: export.h:28
EdgeIntersection(const geom::Coordinate &newCoord, size_t newSegmentIndex, double newDist)
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
bool operator()(const EdgeIntersection *ei1, const EdgeIntersection *ei2) const
bool operator()(const EdgeIntersection &ei1, const EdgeIntersection &ei2) const
Represents a point on an edge which intersects with another edge.
bool operator==(const EdgeIntersection &other) const
bool operator<(const EdgeIntersection &ei1, const EdgeIntersection &ei2)
std::ostream & operator<<(std::ostream &os, const Edge &el)
Basic namespace for all GEOS functionalities.
const geom::Coordinate & getCoordinate() const
bool isEndPoint(size_t maxSegmentIndex) const