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