GEOS 3.14.0dev
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
39class GEOS_DLL PolygonIntersectionAnalyzer : public noding::SegmentIntersector {
40 using CoordinateXY = geos::geom::CoordinateXY;
41 using SegmentString = geos::noding::SegmentString;
42
43private:
44
45 algorithm::LineIntersector li;
46 bool m_hasDoubleTouch = false;
47 bool isInvertedRingValid = false;
48 int invalidCode = TopologyValidationError::oNoInvalidIntersection;
49 CoordinateXY invalidLocation;
50 CoordinateXY doubleTouchLocation;
51
52 int findInvalidIntersection(
53 const SegmentString* ss0, std::size_t segIndex0,
54 const SegmentString* ss1, std::size_t segIndex1);
55
56 bool addDoubleTouch(
57 const SegmentString* ss0, const SegmentString* ss1,
58 const CoordinateXY& intPt);
59
60 void addSelfTouch(
61 const SegmentString* ss, const CoordinateXY& intPt,
62 const CoordinateXY* e00, const CoordinateXY* e01,
63 const CoordinateXY* e10, const CoordinateXY* e11);
64
65 const CoordinateXY& prevCoordinateInRing(
66 const SegmentString* ringSS, std::size_t segIndex) const;
67
68 bool isAdjacentInRing(const SegmentString* ringSS,
69 std::size_t segIndex0, std::size_t segIndex1) const;
70
71
72public:
73
79 PolygonIntersectionAnalyzer(bool p_isInvertedRingValid)
80 : isInvertedRingValid(p_isInvertedRingValid)
81 , invalidLocation(CoordinateXY::getNull())
82 , doubleTouchLocation(CoordinateXY::getNull())
83 {}
84
85 void processIntersections(
86 SegmentString* ss0, std::size_t segIndex0,
87 SegmentString* ss1, std::size_t segIndex1) override;
88
89 bool isDone() const override {
90 return isInvalid() || m_hasDoubleTouch;
91 };
92
93 bool isInvalid() const
94 {
95 return invalidCode >= 0;
96 };
97
98 int getInvalidCode() const
99 {
100 return invalidCode;
101 };
102
103 const CoordinateXY& getInvalidLocation() const
104 {
105 return invalidLocation;
106 };
107
108 bool hasDoubleTouch() const
109 {
110 return m_hasDoubleTouch;
111 };
112
113 const CoordinateXY& getDoubleTouchLocation() const
114 {
115 return doubleTouchLocation;
116 };
117
118};
119
120
121} // namespace geos.operation.valid
122} // namespace geos.operation
123} // namespace geos
124
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