MySQL 9.1.0
Source Code Documentation
buffer_strategies.h
Go to the documentation of this file.
1#ifndef SQL_GIS_BUFFER_STRATEGIES_H_INCLUDED
2#define SQL_GIS_BUFFER_STRATEGIES_H_INCLUDED
3
4// Copyright (c) 2021, 2024, Oracle and/or its affiliates.
5//
6// This program is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License, version 2.0,
8// as published by the Free Software Foundation.
9//
10// This program is designed to work with certain software (including
11// but not limited to OpenSSL) that is licensed under separate terms,
12// as designated in a particular file or component or in included license
13// documentation. The authors of MySQL hereby grant you an additional
14// permission to link the program and your derivative works with the
15// separately licensed software that they have either included with
16// the program or referenced in the documentation.
17//
18// This program is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License, version 2.0, for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with this program; if not, write to the Free Software
25// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
27/// @file
28///
29/// This file implements a struct that is used to hold information that
30/// decide how to compute the buffer of a geometry.
31
32#include <cstddef>
33
34namespace gis {
35
36// Used as cases in the switch in Item_func_st_buffer::parse_strategy.
37// Cannot use enum because switching on type uint.
38constexpr uint kEndRound = 1;
39constexpr uint kEndFlat = 2;
40constexpr uint kJoinRound = 3;
41constexpr uint kJoinMiter = 4;
42constexpr uint kPointCircle = 5;
43constexpr uint kPointSquare = 6;
44
46 // See Boost's documentation for information on bg::buffer's strategies.
47
48 std::size_t join_circle_value = 32;
49 std::size_t end_circle_value = 32;
50 std::size_t point_circle_value = 32;
51 double join_miter_value = 5.0;
52 double distance = 0;
53
54 bool join_is_set = false;
55 bool end_is_set = false;
56 bool point_is_set = false;
57
58 /// 8 possible combinations since 'End = round || flat', 'Join = round ||
59 /// miter', and 'Point = circle || square'. Default combo is 0, with
60 /// default values. Combo made by bitwise OR-ing.
61 /// 0 : join_round, end_round, point_circle
62 /// 1 : join_round, end_flat, point_circle
63 /// 2 : join_miter, end_round, point_circle
64 /// 3 : join_miter, end_flat, point_circle
65 /// 4 : join_round, end_round, point_square
66 /// 5 : join_round, end_flat, point_square
67 /// 6 : join_miter, end_round, point_square
68 /// 7 : join_miter, end_flat, point_square
69 int combination = 0;
70
71 bool set_end_round(double value) {
72 if (end_is_set ||
73 value >= static_cast<double>(std::numeric_limits<std::size_t>::max())) {
74 return true;
75 } else {
76 end_is_set = true;
77 end_circle_value = static_cast<std::size_t>(value);
78 return false;
79 }
80 }
81
82 bool set_end_flat() {
83 if (end_is_set) {
84 return true;
85 } else {
86 end_is_set = true;
87 combination |= 1;
88 return false;
89 }
90 }
91
92 bool set_join_round(double value) {
93 if (join_is_set ||
94 value >= static_cast<double>(std::numeric_limits<std::size_t>::max())) {
95 return true;
96 } else {
97 join_is_set = true;
98 join_circle_value = static_cast<std::size_t>(value);
99 return false;
100 }
101 }
102
103 bool set_join_miter(double value) {
104 if (join_is_set) {
105 return true;
106 } else {
107 join_is_set = true;
108 combination |= 2;
109 join_miter_value = value;
110 return false;
111 }
112 }
113
114 bool set_point_circle(double value) {
115 if (point_is_set ||
116 value >= static_cast<double>(std::numeric_limits<std::size_t>::max())) {
117 return true;
118 } else {
119 point_is_set = true;
120 point_circle_value = static_cast<std::size_t>(value);
121 return false;
122 }
123 }
124
126 if (point_is_set) {
127 return true;
128 } else {
129 point_is_set = true;
130 combination |= 4;
131 return false;
132 }
133 }
134};
135
136} // namespace gis
137
138#endif // SQL_GIS_BUFFER_H_INCLUDED
Definition: area.cc:47
constexpr uint kPointSquare
Definition: buffer_strategies.h:43
constexpr uint kJoinRound
Definition: buffer_strategies.h:40
constexpr uint kPointCircle
Definition: buffer_strategies.h:42
constexpr uint kEndFlat
Definition: buffer_strategies.h:39
constexpr uint kJoinMiter
Definition: buffer_strategies.h:41
constexpr uint kEndRound
Definition: buffer_strategies.h:38
Definition: buffer_strategies.h:45
std::size_t end_circle_value
Definition: buffer_strategies.h:49
std::size_t join_circle_value
Definition: buffer_strategies.h:48
bool set_join_miter(double value)
Definition: buffer_strategies.h:103
bool set_point_circle(double value)
Definition: buffer_strategies.h:114
bool point_is_set
Definition: buffer_strategies.h:56
int combination
8 possible combinations since 'End = round || flat', 'Join = round || miter', and 'Point = circle || ...
Definition: buffer_strategies.h:69
bool set_end_flat()
Definition: buffer_strategies.h:82
bool set_point_square()
Definition: buffer_strategies.h:125
bool set_join_round(double value)
Definition: buffer_strategies.h:92
double join_miter_value
Definition: buffer_strategies.h:51
bool join_is_set
Definition: buffer_strategies.h:54
std::size_t point_circle_value
Definition: buffer_strategies.h:50
bool set_end_round(double value)
Definition: buffer_strategies.h:71
double distance
Definition: buffer_strategies.h:52
bool end_is_set
Definition: buffer_strategies.h:55