GEOS 3.16.0dev
CurveBuilder.h
1/**********************************************************************
2*
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2026 ISciences LLC
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundations.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/export.h>
18
19#include <memory>
20#include <vector>
21
22namespace geos::geom {
23class CoordinateSequence;
24class Curve;
25class GeometryFactory;
26class SimpleCurve;
27}
28
29namespace geos::geom::util {
30
33class GEOS_DLL CurveBuilder {
34public:
35 CurveBuilder(const GeometryFactory& gfact, bool hasZ, bool hasM);
36
37 // Add all coordinates in the provided geometry
38 void add(const Curve& geom);
39
40 // Add all coordinates in the provided sequence
41 void add(const CoordinateSequence& seq, bool isCurved);
42
43 // Add all coordinates in the provided sequence (optionally reversed)
44 void add(const CoordinateSequence& seq, bool isCurved, bool isForward);
45
46 // Add coordinates between the specified indices (inclusive)
47 void add(const CoordinateSequence& seq, std::size_t from, std::size_t to, bool isCurved);
48
49 // Close the ring, if necessary, using a linear segment
50 void closeRing();
51
52 // Get the result geometry
53 std::unique_ptr<Curve> getGeometry();
54
55 // Get a reference to the CoordinateSequence to which
56 // coordinates are currently being added.
57 CoordinateSequence& getSeq(bool isCurved);
58
59 bool hasZ() const {
60 return m_hasZ;
61 }
62
63 bool hasM() const {
64 return m_hasM;
65 }
66
67 bool hasActiveSequence() const {
68 return !m_pts.empty();
69 }
70
71 bool isCurved() const {
72 return hasActiveSequence() && m_pts.back().second;
73 }
74
75 void setOutputLinearRing(bool outputLinearRing) {
76 m_outputLinearRing = outputLinearRing;
77 }
78
79 void matchRingZM();
80
81 // Declare type as noncopyable
82 CurveBuilder(const CurveBuilder& other) = delete;
83 CurveBuilder& operator=(const CurveBuilder& rhs) = delete;
84
85private:
86 std::vector<std::pair<std::unique_ptr<CoordinateSequence>, bool>> m_pts;
87 const GeometryFactory& m_gfact;
88 const bool m_hasZ;
89 const bool m_hasM;
90 bool m_outputLinearRing{true};
91};
92
93}
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:72
Definition CurveBuilder.h:33
Provides classes that parse and modify Geometry objects.
Definition ComponentCoordinateExtracter.h:28
Definition Angle.h:26