GEOS 3.11.1
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/SegmentNode.h>
24#include <geos/noding/SegmentPointComparator.h>
25
26#include <vector>
27#include <iostream>
28
29// Forward declarations
30namespace geos {
31namespace noding {
32class NodedSegmentString;
33}
34}
35
36namespace geos {
37namespace noding { // geos.noding
38
45class GEOS_DLL SegmentNode {
46private:
47 // const NodedSegmentString* segString;
48
49 int segmentOctant;
50
51 bool isInteriorVar;
52
53public:
54 friend std::ostream& operator<< (std::ostream& os, const SegmentNode& n);
55
58
60 std::size_t segmentIndex;
61
75 const geom::Coordinate& nCoord,
76 std::size_t nSegmentIndex, int nSegmentOctant);
77
78 ~SegmentNode() {}
79
85 bool
86 isInterior() const
87 {
88 return isInteriorVar;
89 }
90
91 bool isEndPoint(unsigned int maxSegmentIndex) const
92 {
93 if(segmentIndex == 0 && ! isInteriorVar) {
94 return true;
95 }
96 if(segmentIndex == maxSegmentIndex) {
97 return true;
98 }
99 return false;
100 };
101
109 int compareTo(const SegmentNode& other) const
110 {
111 if (segmentIndex < other.segmentIndex) {
112 return -1;
113 }
114 if (segmentIndex > other.segmentIndex) {
115 return 1;
116 }
117
118 if (coord.equals2D(other.coord)) {
119
120 return 0;
121 }
122
123 // an exterior node is the segment start point,
124 // so always sorts first
125 // this guards against a robustness problem
126 // where the octants are not reliable
127 if (!isInteriorVar) return -1;
128 if (!other.isInteriorVar) return 1;
129
131 segmentOctant, coord,
132 other.coord);
133 };
134
135};
136
137// std::ostream& operator<< (std::ostream& os, const SegmentNode& n);
138
139struct GEOS_DLL SegmentNodeLT {
140 bool
141 operator()(SegmentNode* s1, SegmentNode* s2) const
142 {
143 return s1->compareTo(*s2) < 0;
144 }
145
146 bool
147 operator()(const SegmentNode& s1, const SegmentNode& s2) const
148 {
149 return s1.compareTo(s2) < 0;
150 }
151};
152
153
154} // namespace geos.noding
155} // namespace geos
156
157
158
159
160
161
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:45
int compareTo(const SegmentNode &other) const
Definition: SegmentNode.h:109
std::size_t segmentIndex
the index of the containing line segment in the parent edge
Definition: SegmentNode.h:60
geom::Coordinate coord
the point of intersection (own copy)
Definition: SegmentNode.h:57
bool isInterior() const
Return true if this Node is internal (not on the boundary) of the corresponding segment....
Definition: SegmentNode.h:86
SegmentNode(const NodedSegmentString &ss, const geom::Coordinate &nCoord, std::size_t nSegmentIndex, int nSegmentOctant)
static int compare(int octant, const geom::Coordinate &p0, const geom::Coordinate &p1)
Compares two Coordinates for their relative position along a segment lying in the specified Octant.
Definition: SegmentPointComparator.h:52
Basic namespace for all GEOS functionalities.
Definition: geos.h:39