GEOS 3.11.2
SegmentNode.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: noding/SegmentNode.java 4667170ea (JTS-1.17)
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22#include <geos/geom/Coordinate.h>
23#include <geos/noding/SegmentPointComparator.h>
24
25#include <vector>
26#include <iostream>
27
28// Forward declarations
29namespace geos {
30namespace noding {
31class NodedSegmentString;
32}
33}
34
35namespace geos {
36namespace noding { // geos.noding
37
44class GEOS_DLL SegmentNode {
45private:
46 // const NodedSegmentString* segString;
47
48 int segmentOctant;
49
50 bool isInteriorVar;
51
52public:
53 friend std::ostream& operator<< (std::ostream& os, const SegmentNode& n);
54
57
59 std::size_t segmentIndex;
60
74 const geom::Coordinate& nCoord,
75 std::size_t nSegmentIndex, int nSegmentOctant);
76
77 ~SegmentNode() {}
78
84 bool
85 isInterior() const
86 {
87 return isInteriorVar;
88 }
89
90 bool isEndPoint(unsigned int maxSegmentIndex) const
91 {
92 if(segmentIndex == 0 && ! isInteriorVar) {
93 return true;
94 }
95 if(segmentIndex == maxSegmentIndex) {
96 return true;
97 }
98 return false;
99 };
100
108 int compareTo(const SegmentNode& other) const
109 {
110 if (segmentIndex < other.segmentIndex) {
111 return -1;
112 }
113 if (segmentIndex > other.segmentIndex) {
114 return 1;
115 }
116
117 if (coord.equals2D(other.coord)) {
118
119 return 0;
120 }
121
122 // an exterior node is the segment start point,
123 // so always sorts first
124 // this guards against a robustness problem
125 // where the octants are not reliable
126 if (!isInteriorVar) return -1;
127 if (!other.isInteriorVar) return 1;
128
129 return SegmentPointComparator::compare(
130 segmentOctant, coord,
131 other.coord);
132 };
133
134};
135
136// std::ostream& operator<< (std::ostream& os, const SegmentNode& n);
137
138struct GEOS_DLL SegmentNodeLT {
139 bool
140 operator()(SegmentNode* s1, SegmentNode* s2) const
141 {
142 return s1->compareTo(*s2) < 0;
143 }
144
145 bool
146 operator()(const SegmentNode& s1, const SegmentNode& s2) const
147 {
148 return s1.compareTo(s2) < 0;
149 }
150};
151
152
153} // namespace geos.noding
154} // namespace geos
155
156
157
158
159
160
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:58
Represents a list of contiguous line segments, and supports noding the segments.
Definition NodedSegmentString.h:59
Represents an intersection point between two NodedSegmentString.
Definition SegmentNode.h:44
int compareTo(const SegmentNode &other) const
Definition SegmentNode.h:108
std::size_t segmentIndex
the index of the containing line segment in the parent edge
Definition SegmentNode.h:59
geom::Coordinate coord
the point of intersection (own copy)
Definition SegmentNode.h:56
bool isInterior() const
Return true if this Node is internal (not on the boundary) of the corresponding segment....
Definition SegmentNode.h:85
SegmentNode(const NodedSegmentString &ss, const geom::Coordinate &nCoord, std::size_t nSegmentIndex, int nSegmentOctant)
Basic namespace for all GEOS functionalities.
Definition geos.h:39