Coverage Report

Created: 2025-11-24 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/geomgraph/EdgeRing.h
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7
 * Copyright (C) 2005-2006 Refractions Research Inc.
8
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9
 *
10
 * This is free software; you can redistribute and/or modify it under
11
 * the terms of the GNU Lesser General Public Licence as published
12
 * by the Free Software Foundation.
13
 * See the COPYING file for more information.
14
 *
15
 **********************************************************************
16
 *
17
 * Last port: geomgraph/EdgeRing.java r428 (JTS-1.12+)
18
 *
19
 **********************************************************************/
20
21
22
#pragma once
23
24
#include <geos/export.h>
25
#include <geos/geomgraph/Label.h> // for composition
26
#include <geos/geom/CoordinateSequence.h>
27
#include <geos/geom/LinearRing.h>
28
29
#include <cassert> // for testInvariant
30
#include <iosfwd> // for operator<<
31
#include <memory>
32
#include <vector>
33
34
#ifdef _MSC_VER
35
#pragma warning(push)
36
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37
#endif
38
39
// Forward declarations
40
namespace geos {
41
namespace geom {
42
class GeometryFactory;
43
class Polygon;
44
class Coordinate;
45
}
46
namespace geomgraph {
47
class DirectedEdge;
48
//class Label;
49
class Edge;
50
}
51
}
52
53
namespace geos {
54
namespace geomgraph { // geos.geomgraph
55
56
/** EdgeRing */
57
class GEOS_DLL EdgeRing /* non-final */ {
58
59
public:
60
    friend std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
61
62
    EdgeRing(DirectedEdge* newStart,
63
             const geom::GeometryFactory* newGeometryFactory);
64
65
0
    virtual ~EdgeRing() = default;
66
67
    bool isIsolated();
68
69
    bool isHole();
70
71
    /**
72
     * Return a pointer to the LinearRing owned by
73
     * this object. Make a copy if you need it beyond
74
     * this objects's lifetime.
75
     */
76
    geom::LinearRing* getLinearRing();
77
78
    Label& getLabel();
79
80
    bool isShell();
81
82
    EdgeRing* getShell();
83
84
    void setShell(EdgeRing* newShell);
85
86
    void addHole(EdgeRing* edgeRing);
87
88
    /**
89
     * Return a Polygon copying coordinates from this
90
     * EdgeRing and its holes.
91
     */
92
    std::unique_ptr<geom::Polygon> toPolygon(const geom::GeometryFactory* geometryFactory);
93
94
    /**
95
     * Compute a LinearRing from the point list previously collected.
96
     * Test if the ring is a hole (i.e. if it is CCW) and set the hole
97
     * flag accordingly.
98
     */
99
    void computeRing();
100
101
    virtual DirectedEdge* getNext(DirectedEdge* de) = 0;
102
103
    virtual void setEdgeRing(DirectedEdge* de, EdgeRing* er) = 0;
104
105
    /**
106
     * Returns the list of DirectedEdges that make up this EdgeRing
107
     */
108
    std::vector<DirectedEdge*>& getEdges();
109
110
    int getMaxNodeDegree();
111
112
    void setInResult();
113
114
    /**
115
     * This method will use the computed ring.
116
     * It will also check any holes, if they have been assigned.
117
     */
118
    bool containsPoint(const geom::Coordinate& p);
119
120
    void
121
    testInvariant() const
122
0
    {
123
        // pts are never NULL
124
        // assert(pts);
125
126
#ifndef NDEBUG
127
        // If this is not an hole, check that
128
        // each hole is not null and
129
        // has 'this' as it's shell
130
        if(! shell) {
131
            for(const auto& hole : holes) {
132
                assert(hole);
133
                assert(hole->getShell() == this);
134
            }
135
        }
136
#endif // ndef NDEBUG
137
0
    }
138
139
protected:
140
141
    DirectedEdge* startDe; // the directed edge which starts the list of edges for this EdgeRing
142
143
    const geom::GeometryFactory* geometryFactory;
144
145
    /// @throws util::TopologyException
146
    void computePoints(DirectedEdge* newStart);
147
148
    void mergeLabel(const Label& deLabel);
149
150
    /** \brief
151
     * Merge the RHS label from a DirectedEdge into the label for
152
     * this EdgeRing.
153
     *
154
     * The DirectedEdge label may be null.
155
     * This is acceptable - it results from a node which is NOT
156
     * an intersection node between the Geometries
157
     * (e.g. the end node of a LinearRing).
158
     * In this case the DirectedEdge label does not contribute any
159
     * information to the overall labelling, and is
160
     * simply skipped.
161
     */
162
    void mergeLabel(const Label& deLabel, uint8_t geomIndex);
163
164
    void addPoints(Edge* edge, bool isForward, bool isFirstEdge);
165
166
    /// a list of EdgeRings which are holes in this EdgeRing
167
    std::vector<std::unique_ptr<EdgeRing>> holes;
168
169
private:
170
171
    int maxNodeDegree;
172
173
    /// the DirectedEdges making up this EdgeRing
174
    std::vector<DirectedEdge*> edges;
175
176
    geom::CoordinateSequence pts;
177
178
    // label stores the locations of each geometry on the
179
    // face surrounded by this ring
180
    Label label;
181
182
    std::unique_ptr<geom::LinearRing> ring;  // the ring created for this EdgeRing
183
184
    bool isHoleVar;
185
186
    /// if non-null, the ring is a hole and this EdgeRing is its containing shell
187
    EdgeRing* shell;
188
189
    void computeMaxNodeDegree();
190
191
};
192
193
std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
194
195
} // namespace geos.geomgraph
196
} // namespace geos
197
198
#ifdef _MSC_VER
199
#pragma warning(pop)
200
#endif
201