GEOS 3.15.0beta1
CurveToLineParams.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 Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/export.h>
18#include <geos/geom/CircularArc.h>
19
20namespace geos::algorithm {
21
22class GEOS_DLL CurveToLineParams {
23
24public:
25
26 CurveToLineParams() :
27 m_maxStepDegrees(4.0),
28 m_maxDeviation(DoubleInfinity) {}
29
30 CurveToLineParams& setMaxStepDegrees(double value) {
31 if (!(value > 0)) {
32 throw util::IllegalArgumentException("Step size must be positive");
33 }
34
35 m_maxStepDegrees = value;
36
37 return *this;
38 }
39
40 CurveToLineParams& setMaxDeviation(double value) {
41 if (!(value > 0)) {
42 throw util::IllegalArgumentException("Max deviation must be positive");
43 }
44
45 m_maxDeviation = value;
46
47 return *this;
48 }
49
50 static CurveToLineParams maxDeviation(double dev) {
51 return CurveToLineParams()
52 .setMaxStepDegrees(DoubleInfinity)
53 .setMaxDeviation(dev);
54 }
55
56 static CurveToLineParams stepSizeDegrees(double stepSize) {
57 return CurveToLineParams()
58 .setMaxStepDegrees(stepSize)
59 .setMaxDeviation(DoubleInfinity);
60 }
61
62 double getStepSizeDegrees(const geom::CircularArc& arc) const {
63 const double deviationRatio = 1 - m_maxDeviation / arc.getRadius();
64 const double maxStepFromDeviation = deviationRatio < 0 ? 180 : std::acos(deviationRatio) * 360 / MATH_PI;
65
66 return std::min(m_maxStepDegrees, maxStepFromDeviation);
67 }
68
69private:
70
71 double m_maxStepDegrees;
72 double m_maxDeviation;
73
74};
75
76}
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32