GEOS 3.11.1
PolygonIntersectionAnalyzer.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
7 * Copyright (C) 2021 Martin Davis
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************/
15
16#pragma once
17
18#include <geos/noding/SegmentIntersector.h>
19#include <geos/algorithm/LineIntersector.h>
20#include <geos/operation/valid/TopologyValidationError.h>
21
22
23#include <geos/export.h>
24
25#include <memory>
26
27// Forward declarations
28namespace geos {
29namespace geom {
30class Coordinate;
31}
32namespace noding {
33class SegmentString;
34}
35}
36
37namespace geos { // geos.
38namespace operation { // geos.operation
39namespace valid { // geos.operation.valid
40
43
44class GEOS_DLL PolygonIntersectionAnalyzer : public noding::SegmentIntersector {
45
46private:
47
48 algorithm::LineIntersector li;
49 bool m_hasDoubleTouch = false;
50 bool isInvertedRingValid = false;
51 int invalidCode = TopologyValidationError::oNoInvalidIntersection;
52 Coordinate invalidLocation;
53 Coordinate doubleTouchLocation;
54
55 int findInvalidIntersection(
56 const SegmentString* ss0, std::size_t segIndex0,
57 const SegmentString* ss1, std::size_t segIndex1);
58
59 bool addDoubleTouch(
60 const SegmentString* ss0, const SegmentString* ss1,
61 const Coordinate& intPt);
62
63 void addSelfTouch(
64 const SegmentString* ss, const Coordinate& intPt,
65 const Coordinate* e00, const Coordinate* e01,
66 const Coordinate* e10, const Coordinate* e11);
67
68 const Coordinate& prevCoordinateInRing(
69 const SegmentString* ringSS, std::size_t segIndex) const;
70
71 bool isAdjacentInRing(const SegmentString* ringSS,
72 std::size_t segIndex0, std::size_t segIndex1) const;
73
74
75public:
76
82 PolygonIntersectionAnalyzer(bool p_isInvertedRingValid)
83 : isInvertedRingValid(p_isInvertedRingValid)
84 , invalidLocation(Coordinate::getNull())
85 , doubleTouchLocation(Coordinate::getNull())
86 {}
87
88 void processIntersections(
89 SegmentString* ss0, std::size_t segIndex0,
90 SegmentString* ss1, std::size_t segIndex1) override;
91
92 bool isDone() const override {
93 return isInvalid() || m_hasDoubleTouch;
94 };
95
96 bool isInvalid() const
97 {
98 return invalidCode >= 0;
99 };
100
101 int getInvalidCode() const
102 {
103 return invalidCode;
104 };
105
106 const Coordinate& getInvalidLocation() const
107 {
108 return invalidLocation;
109 };
110
111 bool hasDoubleTouch() const
112 {
113 return m_hasDoubleTouch;
114 };
115
116 const Coordinate& getDoubleTouchLocation() const
117 {
118 return doubleTouchLocation;
119 };
120
121};
122
123
124} // namespace geos.operation.valid
125} // namespace geos.operation
126} // namespace geos
127
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:45
Basic namespace for all GEOS functionalities.
Definition: geos.h:39