GEOS  3.12.0
NodingIntersectionFinder.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 #pragma once
16 
17 #include <geos/noding/SegmentIntersector.h> // for inheritance
18 #include <geos/geom/Coordinate.h> // for composition
19 #include <geos/noding/SegmentString.h>
20 
21 #include <vector>
22 
23 // Forward declarations
24 namespace geos {
25 namespace algorithm {
26 class LineIntersector;
27 }
28 namespace noding {
29 class SegmentString;
30 }
31 }
32 
33 namespace geos {
34 namespace noding { // geos.noding
35 
48 
49 public:
50 
58  :
59  li(newLi),
60  interiorIntersection(geom::Coordinate::getNull()),
61  intersectionCount(0),
62  isCheckEndSegmentsOnly(false),
63  findAllIntersections(false)
64  {
65  }
66 
72  bool
74  {
75  return !interiorIntersection.isNull();
76  }
77 
84  const geom::Coordinate&
86  {
87  return interiorIntersection;
88  }
89 
95  size_t
96  count() const
97  {
98  return intersectionCount;
99  }
100 
111  void
113  {
114  isCheckEndSegmentsOnly = isCESO;
115  }
116 
117 
128  void
130  {
131  findAllIntersections = fAI;
132  }
133 
139  const std::vector<geom::Coordinate>&
141  {
142  return intSegments;
143  }
144 
155  SegmentString* e0, std::size_t segIndex0,
156  SegmentString* e1, std::size_t segIndex1) override;
157 
158  bool
159  isDone() const override
160  {
161  return !interiorIntersection.isNull();
162  }
163 
164 private:
166  geom::Coordinate interiorIntersection;
167  std::size_t intersectionCount;
168  bool isCheckEndSegmentsOnly;
169  bool findAllIntersections;
170  std::vector<geom::Coordinate> intSegments;
171 
172  // Declare type as noncopyable
173  NodingIntersectionFinder(const NodingIntersectionFinder& other) = delete;
174  NodingIntersectionFinder& operator=(const NodingIntersectionFinder& rhs) = delete;
175 
186  static bool isInteriorVertexIntersection(
187  const geom::Coordinate& p0, const geom::Coordinate& p1,
188  bool isEnd0, bool isEnd1)
189  {
190  // Intersections between endpoints are valid nodes, so not reported
191  if (isEnd0 && isEnd1) {
192  return false;
193  }
194 
195  if (p0.equals2D(p1)) {
196  return true;
197  }
198 
199  return false;
200  };
201 
218  static bool isInteriorVertexIntersection(
219  const geom::Coordinate& p00, const geom::Coordinate& p01,
220  const geom::Coordinate& p10, const geom::Coordinate& p11,
221  bool isEnd00, bool isEnd01, bool isEnd10, bool isEnd11)
222  {
223  if (isInteriorVertexIntersection(p00, p10, isEnd00, isEnd10)) {
224  return true;
225  }
226  if (isInteriorVertexIntersection(p00, p11, isEnd00, isEnd11)) {
227  return true;
228  }
229  if (isInteriorVertexIntersection(p01, p10, isEnd01, isEnd10)) {
230  return true;
231  }
232  if (isInteriorVertexIntersection(p01, p11, isEnd01, isEnd11)) {
233  return true;
234  }
235  return false;
236  };
237 
246  static bool isEndSegment(const SegmentString* segStr, std::size_t index)
247  {
248  if (index == 0) {
249  return true;
250  }
251  if (index >= segStr->size() - 2) {
252  return true;
253  }
254  return false;
255  };
256 
257 };
258 
259 } // namespace geos.noding
260 } // namespace geos
261 
262 
geos::noding::NodingIntersectionFinder::processIntersections
void processIntersections(SegmentString *e0, std::size_t segIndex0, SegmentString *e1, std::size_t segIndex1) override
This method is called by clients of the SegmentIntersector class to process intersections for two seg...
geos::noding::NodingIntersectionFinder::setCheckEndSegmentsOnly
void setCheckEndSegmentsOnly(bool isCESO)
Sets whether only end segments should be tested for interior intersection.
Definition: NodingIntersectionFinder.h:112
geos::noding::SegmentString
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:47
geos
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
geos::algorithm::LineIntersector
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:53
geos::noding::NodingIntersectionFinder::hasIntersection
bool hasIntersection() const
Tests whether an intersection was found.
Definition: NodingIntersectionFinder.h:73
geos::noding::NodingIntersectionFinder::isDone
bool isDone() const override
Reports whether the client of this class needs to continue testing all intersections in an arrangemen...
Definition: NodingIntersectionFinder.h:159
geos::noding::NodingIntersectionFinder::setFindAllIntersections
void setFindAllIntersections(bool fAI)
Sets whether all intersections should be computed.
Definition: NodingIntersectionFinder.h:129
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
geos::noding::SegmentIntersector
Processes possible intersections detected by a Noder.
Definition: noding/SegmentIntersector.h:45
geos::noding::NodingIntersectionFinder::getIntersectionSegments
const std::vector< geom::Coordinate > & getIntersectionSegments() const
Gets the endpoints of the intersecting segments.
Definition: NodingIntersectionFinder.h:140
geos::noding::NodingIntersectionFinder::getInteriorIntersection
const geom::Coordinate & getInteriorIntersection() const
Gets the computed location of the intersection. Due to round-off, the location may not be exact.
Definition: NodingIntersectionFinder.h:85
geos::noding::NodingIntersectionFinder::NodingIntersectionFinder
NodingIntersectionFinder(algorithm::LineIntersector &newLi)
Creates an intersection finder which finds an interior intersection if one exists.
Definition: NodingIntersectionFinder.h:57
geos::noding::NodingIntersectionFinder::count
size_t count() const
Gets the count of intersections found.
Definition: NodingIntersectionFinder.h:96
geos::noding::NodingIntersectionFinder
Finds non-noded intersections in a set of SegmentStrings, if any exist.
Definition: NodingIntersectionFinder.h:47