GEOS 3.11.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#pragma once
23
24#include <geos/export.h>
25
26#include <geos/geom/Coordinate.h> // for composition and inlines
27
28#include <ostream>
29
30
31namespace geos {
32namespace geomgraph { // geos.geomgraph
33
42class GEOS_DLL EdgeIntersection {
43public:
44
45 // the point of intersection
46 geom::Coordinate coord;
47
48 // the edge distance of this point along the containing line segment
49 double dist;
50
51 // the index of the containing line segment in the parent edge
52 std::size_t segmentIndex;
53
54 EdgeIntersection(const geom::Coordinate& newCoord,
55 std::size_t newSegmentIndex, double newDist)
56 :
57 coord(newCoord),
58 dist(newDist),
59 segmentIndex(newSegmentIndex)
60 {}
61
62 bool
63 isEndPoint(std::size_t maxSegmentIndex) const
64 {
65 if(segmentIndex == 0 && dist == 0.0) {
66 return true;
67 }
68 if(segmentIndex == maxSegmentIndex) {
69 return true;
70 }
71 return false;
72 }
73
74 const geom::Coordinate&
75 getCoordinate() const
76 {
77 return coord;
78 }
79
80 size_t
81 getSegmentIndex() const
82 {
83 return segmentIndex;
84 }
85
86 double
87 getDistance() const
88 {
89 return dist;
90 }
91
92 bool operator==(const EdgeIntersection& other) const {
93 return segmentIndex == other.segmentIndex &&
94 dist == other.dist;
95
96 // We don't check the coordinate, consistent with operator<
97 }
98
99};
100
104inline bool
105operator< (const EdgeIntersection& ei1, const EdgeIntersection& ei2)
106{
107 if(ei1.segmentIndex < ei2.segmentIndex) {
108 return true;
109 }
110 if(ei1.segmentIndex == ei2.segmentIndex) {
111 if(ei1.dist < ei2.dist) {
112 return true;
113 }
114
115 // TODO: check if the Coordinate matches, or this will
116 // be a robustness issue in computing distance
117 // See http://trac.osgeo.org/geos/ticket/350
118 }
119 return false;
120}
121
122// @deprecated, use strict weak ordering operator
123struct GEOS_DLL EdgeIntersectionLessThen {
124 bool
125 operator()(const EdgeIntersection* ei1,
126 const EdgeIntersection* ei2) const
127 {
128 return *ei1 < *ei2;
129 }
130
131 bool
132 operator()(const EdgeIntersection& ei1,
133 const EdgeIntersection& ei2) const
134 {
135 return ei1 < ei2;
136 }
137};
138
140inline std::ostream&
141operator<< (std::ostream& os, const EdgeIntersection& e)
142{
143 os << e.coord << " seg # = " << e.segmentIndex << " dist = " << e.dist;
144 return os;
145}
146
147} // namespace geos.geomgraph
148} // namespace geos
149
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Represents a point on an edge which intersects with another edge.
Definition: EdgeIntersection.h:42
bool operator<(const EdgeIntersection &ei1, const EdgeIntersection &ei2)
Definition: EdgeIntersection.h:105
Basic namespace for all GEOS functionalities.
Definition: geos.h:39