GEOS 3.15.0dev
SurfaceImpl.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2024 ISciences, LLC
7 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
8 * Copyright (C) 2005 2006 Refractions Research Inc.
9 * Copyright (C) 2001-2002 Vivid Solutions Inc.
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/CoordinateSequenceFilter.h>
21#include <geos/geom/Curve.h>
22#include <geos/geom/GeometryComponentFilter.h>
23#include <geos/geom/GeometryFilter.h>
24#include <geos/geom/LinearRing.h>
25#include <geos/geom/Surface.h>
26#include <geos/util/IllegalArgumentException.h>
27
28namespace geos {
29namespace geom {
30
31template<typename RingType>
32class SurfaceImpl : public Surface {
33
34protected:
35
36 SurfaceImpl(const SurfaceImpl& p)
37 :
38 Surface(p),
39 shell(static_cast<RingType*>(p.shell->clone().release())),
40 holes(p.holes.size())
41 {
42 for (std::size_t i = 0; i < holes.size(); ++i) {
43 holes[i].reset(static_cast<RingType*>(p.holes[i]->clone().release()));
44 }
45 }
46
65 SurfaceImpl(std::unique_ptr<RingType>&& newShell,
66 const GeometryFactory& newFactory) :
67 Surface(&newFactory),
68 shell(std::move(newShell))
69 {
70 if (shell == nullptr) {
71 shell.reset(static_cast<RingType*>(createEmptyRing(newFactory).release()));
72 }
73
74 validateConstruction();
75 }
76
77 SurfaceImpl(std::unique_ptr<RingType>&& newShell,
78 std::vector<std::unique_ptr<RingType>>&& newHoles,
79 const GeometryFactory& newFactory) :
80 Surface(&newFactory),
81 shell(std::move(newShell)),
82 holes(std::move(newHoles))
83 {
84 if (shell == nullptr) {
85 shell.reset(static_cast<RingType*>(createEmptyRing(newFactory).release()));
86 }
87
88 validateConstruction();
89 }
90
91public:
92
93 const RingType*
94 getExteriorRing() const override
95 {
96 return shell.get();
97 }
98
99 RingType*
100 getExteriorRing() override
101 {
102 return shell.get();
103 }
104
105 const RingType*
106 getInteriorRingN(std::size_t n) const override
107 {
108 return holes[n].get();
109 }
110
111 RingType*
112 getInteriorRingN(std::size_t n) override
113 {
114 return holes[n].get();
115 }
116
117 size_t getNumInteriorRing() const override
118 {
119 return holes.size();
120 }
121
130 std::unique_ptr<RingType>
131 releaseExteriorRing()
132 {
133 return std::move(shell);
134 }
135
144 std::vector<std::unique_ptr<RingType>> releaseInteriorRings()
145 {
146 return std::move(holes);
147 }
148
149protected:
150 std::unique_ptr<RingType> shell;
151 std::vector<std::unique_ptr<RingType>> holes;
152
153};
154
155}
156}
std::unique_ptr< Geometry > clone() const
Make a deep-copy of this Geometry.
Definition Geometry.h:212
Basic namespace for all GEOS functionalities.
Definition geos.h:38