GEOS 3.9.1
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
34namespace geos {
35namespace geomgraph { // geos.geomgraph
36
45class GEOS_DLL EdgeIntersection {
46public:
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 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
107inline bool
108operator< (const EdgeIntersection& ei1, const EdgeIntersection& ei2)
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
126struct GEOS_DLL EdgeIntersectionLessThen {
127 bool
128 operator()(const EdgeIntersection* ei1,
129 const EdgeIntersection* ei2) const
130 {
131 return *ei1 < *ei2;
132 }
133
134 bool
135 operator()(const EdgeIntersection& ei1,
136 const EdgeIntersection& ei2) const
137 {
138 return ei1 < ei2;
139 }
140};
141
143inline std::ostream&
144operator<< (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
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:60
Represents a point on an edge which intersects with another edge.
Definition EdgeIntersection.h:45
bool operator<(const EdgeIntersection &ei1, const EdgeIntersection &ei2)
Definition EdgeIntersection.h:108
Basic namespace for all GEOS functionalities.
Definition IndexedNestedRingTester.h:26