/
BufferParameters.cpp
105 lines (93 loc) · 2.78 KB
/
BufferParameters.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: operation/buffer/BufferParameters.java r278 (JTS-1.12)
*
**********************************************************************/
#include <cstdlib> // for std::abs()
#include <cmath> // for cos
#include <geos/algorithm/Angle.h>
#include <geos/constants.h>
#include <geos/operation/buffer/BufferParameters.h>
namespace geos {
namespace operation { // geos.operation
namespace buffer { // geos.operation.buffer
// public static const
const double BufferParameters::DEFAULT_MITRE_LIMIT = 5.0;
// public
BufferParameters::BufferParameters()
:
quadrantSegments(DEFAULT_QUADRANT_SEGMENTS),
endCapStyle(CAP_ROUND),
joinStyle(JOIN_ROUND),
mitreLimit(DEFAULT_MITRE_LIMIT),
_isSingleSided(false)
{}
// public
BufferParameters::BufferParameters(int p_quadrantSegments)
:
quadrantSegments(DEFAULT_QUADRANT_SEGMENTS),
endCapStyle(CAP_ROUND),
joinStyle(JOIN_ROUND),
mitreLimit(DEFAULT_MITRE_LIMIT),
_isSingleSided(false)
{
setQuadrantSegments(p_quadrantSegments);
}
// public
BufferParameters::BufferParameters(int p_quadrantSegments,
EndCapStyle p_endCapStyle)
:
quadrantSegments(DEFAULT_QUADRANT_SEGMENTS),
endCapStyle(CAP_ROUND),
joinStyle(JOIN_ROUND),
mitreLimit(DEFAULT_MITRE_LIMIT),
_isSingleSided(false)
{
setQuadrantSegments(p_quadrantSegments);
setEndCapStyle(p_endCapStyle);
}
// public
BufferParameters::BufferParameters(int p_quadrantSegments,
EndCapStyle p_endCapStyle,
JoinStyle p_joinStyle,
double p_mitreLimit)
:
quadrantSegments(DEFAULT_QUADRANT_SEGMENTS),
endCapStyle(CAP_ROUND),
joinStyle(JOIN_ROUND),
mitreLimit(DEFAULT_MITRE_LIMIT),
_isSingleSided(false)
{
setQuadrantSegments(p_quadrantSegments);
setEndCapStyle(p_endCapStyle);
setJoinStyle(p_joinStyle);
setMitreLimit(p_mitreLimit);
}
// public
void
BufferParameters::setQuadrantSegments(int quadSegs)
{
quadrantSegments = quadSegs;
}
// public static
double
BufferParameters::bufferDistanceError(int quadSegs)
{
double alpha = algorithm::Angle::PI_OVER_2 / quadSegs;
return 1 - cos(alpha / 2.0);
}
} // namespace geos.operation.buffer
} // namespace geos.operation
} // namespace geos