FuncSketch
Loading...
Searching...
No Matches
plot_config.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2026 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
21
22#include <fmt/format.h>
23
25
26namespace func_sketch::plotter {
27
29 if (value < 0) {
30 throw InvalidArgumentException("Left margin must be non-negative");
31 }
32 left_margin_ = value;
33 return *this;
34}
35
37 if (value < 0) {
38 throw InvalidArgumentException("Right margin must be non-negative");
39 }
40 right_margin_ = value;
41 return *this;
42}
43
45 if (value < 0) {
46 throw InvalidArgumentException("Top margin must be non-negative");
47 }
48 top_margin_ = value;
49 return *this;
50}
51
53 if (value < 0) {
54 throw InvalidArgumentException("Bottom margin must be non-negative");
55 }
56 bottom_margin_ = value;
57 return *this;
58}
59
61 if (value < 0) {
63 "Tick label font size must be non-negative");
64 }
66 return *this;
67}
68
70 if (value < 0) {
71 throw InvalidArgumentException("Axes line width must be non-negative");
72 }
73 axes_line_width_ = value;
74 return *this;
75}
76
78 if (value < 0) {
79 throw InvalidArgumentException("Grid line width must be non-negative");
80 }
81 grid_line_width_ = value;
82 return *this;
83}
84
86 if (value < 0) {
87 throw InvalidArgumentException("Zero line width must be non-negative");
88 }
89 zero_line_width_ = value;
90 return *this;
91}
92
94 if (value < 0) {
95 throw InvalidArgumentException("Curve line width must be non-negative");
96 }
97 curve_line_width_ = value;
98 return *this;
99}
100
102 background_color_ = value;
103 return *this;
104}
105
107 axes_color_ = value;
108 return *this;
109}
110
112 grid_color_ = value;
113 return *this;
114}
115
117 if (value < 2) {
119 "Number of sample points must be at least 2");
120 }
122 return *this;
123}
124
126 if (value < 2) {
128 "Number of sample points must be at least 2.");
129 }
130 if (value > max_max_num_sample_points) {
132 fmt::format("Number of sample points must be at most {}",
134 }
136 return *this;
137}
138
140 if (value <= 0.0) {
142 "Maximum coordinate change rate must be positive.");
143 }
145 return *this;
146}
147
149 if (value <= 0.0) {
151 "Slope change threshold must be positive.");
152 }
154 return *this;
155}
156
158 if (value < min_min_param_change_rate) {
160 fmt::format("Minimum parameter change rate must be at least {}",
162 }
164 return *this;
165}
166
168 if (value == 0) {
170 "Number of pixels per tick in the x-axis must be positive.");
171 }
173 return *this;
174}
175
177 if (value == 0) {
179 "Number of pixels per tick in the y-axis must be positive.");
180 }
182 return *this;
183}
184
185int PlotConfig::left_margin() const noexcept { return left_margin_; }
186
187int PlotConfig::right_margin() const noexcept { return right_margin_; }
188
189int PlotConfig::top_margin() const noexcept { return top_margin_; }
190
191int PlotConfig::bottom_margin() const noexcept { return bottom_margin_; }
192
195}
196
197int PlotConfig::axes_line_width() const noexcept { return axes_line_width_; }
198
199int PlotConfig::grid_line_width() const noexcept { return grid_line_width_; }
200
201int PlotConfig::zero_line_width() const noexcept { return zero_line_width_; }
202
203int PlotConfig::curve_line_width() const noexcept { return curve_line_width_; }
204
205const RGBColor& PlotConfig::background_color() const noexcept {
206 return background_color_;
207}
208
209const RGBColor& PlotConfig::axes_color() const noexcept { return axes_color_; }
210
211const RGBColor& PlotConfig::grid_color() const noexcept { return grid_color_; }
212
213std::size_t PlotConfig::initial_num_sample_points() const noexcept {
215}
216
217std::size_t PlotConfig::max_num_sample_points() const noexcept {
219}
220
224
225double PlotConfig::slope_change_threshold() const noexcept {
227}
228
229double PlotConfig::min_param_change_rate() const noexcept {
231}
232
233std::size_t PlotConfig::num_pixels_per_tick_in_x_axis() const noexcept {
235}
236
237std::size_t PlotConfig::num_pixels_per_tick_in_y_axis() const noexcept {
239}
240
241} // namespace func_sketch::plotter
Class of exceptions for invalid arguments.
Definition exceptions.h:37
const RGBColor & background_color() const noexcept
Get the color of background.
int left_margin_
Left margin of plots in pixels.
RGBColor grid_color_
Color of grid lines.
std::size_t num_pixels_per_tick_in_y_axis_
Number of pixels per tick in the y-axis.
int right_margin() const noexcept
Get the right margin of plots in pixels.
double min_param_change_rate() const noexcept
Get the minimum rate of parameter change in adaptive sampling.
int grid_line_width_
Line width of grid lines in pixels.
PlotConfig()=default
Constructor.
std::size_t num_pixels_per_tick_in_x_axis_
Number of pixels per tick in the x-axis.
std::size_t num_pixels_per_tick_in_y_axis() const noexcept
Get the number of pixels per tick in the y-axis.
int right_margin_
Right margin of plots in pixels.
std::size_t max_num_sample_points() const noexcept
Get the maximum number of points to sample in adaptive sampling.
int zero_line_width_
Line width of the grid line at zero in pixels.
int grid_line_width() const noexcept
Get the line width of grid lines in pixels.
std::size_t initial_num_sample_points_
Number of points to sample initially in adaptive sampling.
std::size_t num_pixels_per_tick_in_x_axis() const noexcept
Get the number of pixels per tick in the x-axis.
int bottom_margin_
Bottom margin of plots in pixels.
int axes_line_width() const noexcept
Get the line width of axes in pixels.
int zero_line_width() const noexcept
Get the line width of the grid line at zero in pixels.
std::size_t max_num_sample_points_
Maximum number of points to sample in adaptive sampling.
double max_coordinate_change_rate() const noexcept
Get the threshold of the change in coordinates of sample points relative to the plot range in adaptiv...
RGBColor axes_color_
Color of axes.
RGBColor background_color_
Color of background.
int curve_line_width() const noexcept
Get the line width of curves in pixels.
int curve_line_width_
Line width of curves in pixels.
int bottom_margin() const noexcept
Get the bottom margin of plots in pixels.
int top_margin() const noexcept
Get the top margin of plots in pixels.
int tick_label_font_size() const noexcept
Get the font size of tick labels in pixels.
int axes_line_width_
Line width of axes in pixels.
const RGBColor & grid_color() const noexcept
Get the color of grid lines.
double slope_change_threshold() const noexcept
Get the threshold of the change in slope normalized by the plot range in adaptive sampling.
std::size_t initial_num_sample_points() const noexcept
Get the number of points to sample initially in adaptive sampling.
double min_param_change_rate_
Minimum rate of parameter change in adaptive sampling.
int tick_label_font_size_
Font size of tick labels in pixels.
int left_margin() const noexcept
Get the left margin of plots in pixels.
int top_margin_
Top margin of plots in pixels.
const RGBColor & axes_color() const noexcept
Get the color of axes.
Definition of exception classes.
Definition of PlotConfig class.
constexpr double min_min_param_change_rate
Minimum value of the minimum rate of parameter change in adaptive sampling for safety limit of memory...
Definition plot_config.h:86
constexpr std::size_t max_max_num_sample_points
Maximum value of the maximum number of points to sample in adaptive sampling for safety limit of memo...
Definition plot_config.h:74
Struct of RGB color.
Definition rgb_color.h:31