/src/geos/include/geos/coverage/CoverageEdge.h
Line | Count | Source |
1 | | |
2 | | |
3 | | |
4 | | /********************************************************************** |
5 | | * |
6 | | * GEOS - Geometry Engine Open Source |
7 | | * http://geos.osgeo.org |
8 | | * |
9 | | * Copyright (C) 2022 Paul Ramsey <pramsey@cleverelephant.ca> |
10 | | * |
11 | | * This is free software; you can redistribute and/or modify it under |
12 | | * the terms of the GNU Lesser General Public Licence as published |
13 | | * by the Free Software Foundation. |
14 | | * See the COPYING file for more information. |
15 | | * |
16 | | **********************************************************************/ |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <geos/geom/CoordinateSequence.h> |
21 | | #include <geos/geom/LineSegment.h> |
22 | | #include <geos/util.h> |
23 | | |
24 | | // Forward declarations |
25 | | namespace geos { |
26 | | namespace geom { |
27 | | class Coordinate; |
28 | | class LinearRing; |
29 | | class LineString; |
30 | | class MultiLineString; |
31 | | class GeometryFactory; |
32 | | } |
33 | | } |
34 | | |
35 | | namespace geos { // geos. |
36 | | namespace coverage { // geos.coverage |
37 | | |
38 | | /** |
39 | | * An edge of a polygonal coverage formed from all or a section of a polygon ring. |
40 | | * An edge may be a free ring, which is a ring which has not node points |
41 | | * (i.e. does not touch any other rings in the parent coverage). |
42 | | * |
43 | | * @author mdavis |
44 | | * |
45 | | */ |
46 | | class GEOS_DLL CoverageEdge { |
47 | | using Coordinate = geos::geom::Coordinate; |
48 | | using CoordinateSequence = geos::geom::CoordinateSequence; |
49 | | using GeometryFactory = geos::geom::GeometryFactory; |
50 | | using LinearRing = geos::geom::LinearRing; |
51 | | using LineString = geos::geom::LineString; |
52 | | using LineSegment = geos::geom::LineSegment; |
53 | | using MultiLineString = geos::geom::MultiLineString; |
54 | | |
55 | | |
56 | | private: |
57 | | |
58 | | // Members |
59 | | std::shared_ptr<const CoordinateSequence> m_pts; |
60 | | std::size_t m_ringCount ; |
61 | | bool m_isFreeRing = true; |
62 | | |
63 | | // Methods |
64 | | |
65 | | static std::unique_ptr<CoordinateSequence> |
66 | | extractEdgePoints(const CoordinateSequence& ring, |
67 | | std::size_t start, std::size_t end); |
68 | | |
69 | | static const Coordinate& |
70 | | findDistinctPoint( |
71 | | const CoordinateSequence& pts, |
72 | | std::size_t index, |
73 | | bool isForward, |
74 | | const Coordinate& pt); |
75 | | |
76 | | |
77 | | public: |
78 | | |
79 | | CoverageEdge(std::unique_ptr<CoordinateSequence> && pts, bool isFreeRing) |
80 | 0 | : m_pts(pts ? std::move(pts) : detail::make_unique<CoordinateSequence>()) |
81 | 0 | , m_ringCount(0) |
82 | 0 | , m_isFreeRing(isFreeRing) |
83 | 0 | {} |
84 | | |
85 | | /** |
86 | | * Computes a key segment for a ring. |
87 | | * The key is the segment starting at the lowest vertex, |
88 | | * towards the lowest adjacent distinct vertex. |
89 | | * |
90 | | * @param ring a linear ring |
91 | | * @return a LineSegment representing the key |
92 | | */ |
93 | | static LineSegment key( |
94 | | const CoordinateSequence& ring); |
95 | | |
96 | | /** |
97 | | * Computes a distinct key for a section of a linear ring. |
98 | | * |
99 | | * @param ring the linear ring |
100 | | * @param start index of the start of the section |
101 | | * @param end end index of the end of the section |
102 | | * @return a LineSegment representing the key |
103 | | */ |
104 | | static LineSegment key( |
105 | | const CoordinateSequence& ring, |
106 | | std::size_t start, |
107 | | std::size_t end); |
108 | | |
109 | | static std::unique_ptr<CoverageEdge> createEdge( |
110 | | const CoordinateSequence& ring); |
111 | | |
112 | | static std::unique_ptr<CoverageEdge> createEdge( |
113 | | const CoordinateSequence& ring, |
114 | | std::size_t start, |
115 | | std::size_t end); |
116 | | |
117 | | static std::unique_ptr<MultiLineString> createLines( |
118 | | const std::vector<CoverageEdge*>& edges, |
119 | | const GeometryFactory* geomFactory); |
120 | | |
121 | | std::unique_ptr<LineString> toLineString( |
122 | | const GeometryFactory* geomFactory) const; |
123 | | |
124 | | /* public */ |
125 | | void incRingCount() |
126 | 0 | { |
127 | 0 | m_ringCount++; |
128 | 0 | } |
129 | | |
130 | | /* public */ |
131 | | std::size_t getRingCount() const |
132 | 0 | { |
133 | 0 | return m_ringCount; |
134 | 0 | } |
135 | | |
136 | | /** |
137 | | * Returns whether this edge is a free ring; |
138 | | * i.e. one with no constrained nodes. |
139 | | * |
140 | | * @return true if this is a free ring |
141 | | */ |
142 | | bool isFreeRing() const |
143 | 0 | { |
144 | 0 | return m_isFreeRing; |
145 | 0 | } |
146 | | |
147 | | void setCoordinates(const std::shared_ptr<const CoordinateSequence>& pts) |
148 | 0 | { |
149 | 0 | m_pts = pts; |
150 | 0 | } |
151 | | |
152 | | const std::shared_ptr<const CoordinateSequence>& getCoordinates() const |
153 | 0 | { |
154 | 0 | return m_pts; |
155 | 0 | } |
156 | | |
157 | | const Coordinate& getEndCoordinate() const |
158 | 0 | { |
159 | 0 | return m_pts->getAt(m_pts->size() - 1); |
160 | 0 | } |
161 | | |
162 | | const Coordinate& getStartCoordinate() const |
163 | 0 | { |
164 | 0 | return m_pts->getAt(0); |
165 | 0 | } |
166 | | |
167 | | |
168 | | }; |
169 | | |
170 | | } // namespace geos.coverage |
171 | | } // namespace geos |