GEOS  3.14.0dev
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 #include <geos/noding/SegmentString.h>
25 
26 #include <vector>
27 #include <iostream>
28 
29 namespace geos {
30 namespace noding { // geos.noding
31 
38 class GEOS_DLL SegmentNode {
39 private:
40  int segmentOctant;
41 
42  bool isInteriorVar;
43 
44 public:
45  friend std::ostream& operator<< (std::ostream& os, const SegmentNode& n);
46 
48  geom::CoordinateXYZM coord;
49 
51  std::size_t segmentIndex;
52 
65  template<typename CoordType>
67  const CoordType& nCoord,
68  std::size_t nSegmentIndex, int nSegmentOctant)
69  : segmentOctant(nSegmentOctant)
70  , coord(nCoord)
71  , segmentIndex(nSegmentIndex)
72  {
73  // Number of points in NodedSegmentString is one-more number of segments
74  assert(segmentIndex < ss.size());
75  isInteriorVar = !coord.equals2D(ss.getCoordinate(segmentIndex));
76  }
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 
139 struct 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 
Represents an intersection point between two NodedSegmentString.
Definition: SegmentNode.h:38
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:51
geom::CoordinateXYZM coord
the point of intersection (own copy)
Definition: SegmentNode.h:48
bool isInterior() const
Return true if this Node is internal (not on the boundary) of the corresponding segment....
Definition: SegmentNode.h:86
SegmentNode(const SegmentString &ss, const CoordType &nCoord, std::size_t nSegmentIndex, int nSegmentOctant)
Definition: SegmentNode.h:66
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
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:47
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25