FuncSketch
Loading...
Searching...
No Matches
function_sampler.h
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 */
20#pragma once
21
22#include <vector>
23
29
30namespace func_sketch::plotter {
31
36public:
44
51 FunctionSampler& range(const PlotRange& value);
52
59 FunctionSampler& config(const PlotConfig& value);
60
67 [[nodiscard]] std::vector<Point> operator()(
68 const expressions::Expression& function) const;
69
70private:
77 [[nodiscard]] std::vector<Point> sample_initial_points(
78 const expressions::Expression& function) const;
79
87 [[nodiscard]] std::vector<Point> sample_adaptive_points(
88 const expressions::Expression& function,
89 const std::vector<Point>& initial_samples) const;
90
100 [[nodiscard]] bool divide_segment_according_to_y_change(
101 const expressions::Expression& function, std::vector<Point>& samples,
102 std::size_t left_index) const;
103
114 const expressions::Expression& function, std::vector<Point>& samples,
115 std::size_t left_index) const;
116
127 const expressions::Expression& function, std::vector<Point>& samples,
128 std::size_t left_index) const;
129
142 [[nodiscard]] bool divide_segment(const expressions::Expression& function,
143 std::vector<Point>& samples, std::size_t left_index) const;
144
153 [[nodiscard]] Point sample_additional_point(
154 const expressions::Expression& function, const Point& left_point,
155 const Point& right_point) const;
156
166 [[nodiscard]] bool is_sampling_should_be_skipped(
167 const Point& left_point, const Point& right_point) const;
168
171
174
177};
178
179} // namespace func_sketch::plotter
bool divide_segment_according_to_y_change(const expressions::Expression &function, std::vector< Point > &samples, std::size_t left_index) const
Divide if the change of y is large.
bool divide_segment(const expressions::Expression &function, std::vector< Point > &samples, std::size_t left_index) const
Divide a segment into two segments in sample points if applicable.
std::vector< Point > sample_adaptive_points(const expressions::Expression &function, const std::vector< Point > &initial_samples) const
Sample additional points adaptively.
FunctionSampler & config(const PlotConfig &value)
Set the configuration of plots.
bool divide_segment_when_one_end_is_not_finite(const expressions::Expression &function, std::vector< Point > &samples, std::size_t left_index) const
Divide if one end of the segment is not finite.
std::vector< Point > operator()(const expressions::Expression &function) const
Sample a function for plotting.
FunctionSampler(const PlotRange &range, const PlotConfig &config)
Constructor.
bool divide_segment_according_to_slope_change(const expressions::Expression &function, std::vector< Point > &samples, std::size_t left_index) const
Divide if the change of slope of y is large.
expressions::ExpressionEvaluator evaluator_
Evaluator of expressions.
std::vector< Point > sample_initial_points(const expressions::Expression &function) const
Sample initial points.
PlotConfig config_
Configuration of plots.
bool is_sampling_should_be_skipped(const Point &left_point, const Point &right_point) const
Check the condition to skip sampling of a point between two points.
Point sample_additional_point(const expressions::Expression &function, const Point &left_point, const Point &right_point) const
Sample an additional point between two points.
FunctionSampler & range(const PlotRange &value)
Set the range of plots.
Class of configurations of a plot.
Definition plot_config.h:97
Class of a range of a plot.
Definition plot_range.h:35
Definition of Expression class.
Definition of ExpressionEvaluator class.
Definition of PlotConfig class.
Definition of PlotRange class.
Definition of Point struct.
Struct of a point.
Definition point.h:29