GEOS 3.13.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/geom/Coordinate.h>
19#include <geos/noding/SegmentIntersector.h>
20#include <geos/algorithm/LineIntersector.h>
21#include <geos/operation/valid/TopologyValidationError.h>
22
23
24#include <geos/export.h>
25
26#include <memory>
27
28// Forward declarations
29namespace geos {
30namespace noding {
31class SegmentString;
32}
33}
34
35namespace geos { // geos.
36namespace operation { // geos.operation
37namespace valid { // geos.operation.valid
38
39using geos::geom::CoordinateXY;
41
42class GEOS_DLL PolygonIntersectionAnalyzer : public noding::SegmentIntersector {
43
44private:
45
46 algorithm::LineIntersector li;
47 bool m_hasDoubleTouch = false;
48 bool isInvertedRingValid = false;
49 int invalidCode = TopologyValidationError::oNoInvalidIntersection;
50 CoordinateXY invalidLocation;
51 CoordinateXY doubleTouchLocation;
52
53 int findInvalidIntersection(
54 const SegmentString* ss0, std::size_t segIndex0,
55 const SegmentString* ss1, std::size_t segIndex1);
56
57 bool addDoubleTouch(
58 const SegmentString* ss0, const SegmentString* ss1,
59 const CoordinateXY& intPt);
60
61 void addSelfTouch(
62 const SegmentString* ss, const CoordinateXY& intPt,
63 const CoordinateXY* e00, const CoordinateXY* e01,
64 const CoordinateXY* e10, const CoordinateXY* e11);
65
66 const CoordinateXY& prevCoordinateInRing(
67 const SegmentString* ringSS, std::size_t segIndex) const;
68
69 bool isAdjacentInRing(const SegmentString* ringSS,
70 std::size_t segIndex0, std::size_t segIndex1) const;
71
72
73public:
74
80 PolygonIntersectionAnalyzer(bool p_isInvertedRingValid)
81 : isInvertedRingValid(p_isInvertedRingValid)
82 , invalidLocation(CoordinateXY::getNull())
83 , doubleTouchLocation(CoordinateXY::getNull())
84 {}
85
86 void processIntersections(
87 SegmentString* ss0, std::size_t segIndex0,
88 SegmentString* ss1, std::size_t segIndex1) override;
89
90 bool isDone() const override {
91 return isInvalid() || m_hasDoubleTouch;
92 };
93
94 bool isInvalid() const
95 {
96 return invalidCode >= 0;
97 };
98
99 int getInvalidCode() const
100 {
101 return invalidCode;
102 };
103
104 const CoordinateXY& getInvalidLocation() const
105 {
106 return invalidLocation;
107 };
108
109 bool hasDoubleTouch() const
110 {
111 return m_hasDoubleTouch;
112 };
113
114 const CoordinateXY& getDoubleTouchLocation() const
115 {
116 return doubleTouchLocation;
117 };
118
119};
120
121
122} // namespace geos.operation.valid
123} // namespace geos.operation
124} // namespace geos
125
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
Basic namespace for all GEOS functionalities.
Definition geos.h:39