15 #ifndef OSMANIP_GRAPHICS_PLOT2DCANVAS_HPP
16 #define OSMANIP_GRAPHICS_PLOT2DCANVAS_HPP
55 void setScale(
float xScale,
float yScale);
75 template <
typename Y,
typename X>
76 inline void draw(std::function<Y(X)>
function,
char c, std::string_view
feat =
"") {
79 uint32_t x_min = std::max(0,
static_cast<int>(std::floor((0 - offset_x_) / scale_x_)));
80 uint32_t x_max = std::min(
width_,
static_cast<uint32_t
>(std::ceil((
width_ - offset_x_) / scale_x_)));
83 for (uint32_t x = x_min; x < x_max; x++) {
84 float real_x = offset_x_ + x * scale_x_;
85 Y real_y =
function(real_x);
86 uint32_t y =
static_cast<uint32_t
>((real_y - offset_y_) / scale_y_);
94 float offset_x_, offset_y_, scale_x_, scale_y_;
Instances of this class are used to draw in a limited 2D space. All the functions that modify the can...
Definition: canvas.hpp:52
uint32_t width_
Definition: canvas.hpp:100
uint32_t height_
Definition: canvas.hpp:100
void put(uint32_t x, uint32_t y, char c, std::string_view feat="")
Put a character in the canvas, given its coordinates and an optional feat. An out-of-bounds exception...
Definition: canvas.cpp:201
This class is used to plot mathematical functions R -> R. In addition to all the properties of a basi...
Definition: plot_2D.hpp:47
float getOffsetX() const
Get the offset_x of the canvas.
Definition: plot_2D.cpp:78
void setOffset(float xOff, float yOff)
Set the offset_x and offset_y of the canvas.
Definition: plot_2D.cpp:51
float getOffsetY() const
Get the offset_y of the canvas.
Definition: plot_2D.cpp:86
float getScaleY() const
Get the scale_y of the canvas.
Definition: plot_2D.cpp:102
void setScale(float xScale, float yScale)
Set the scale_x and scale_y of the canvas.
Definition: plot_2D.cpp:63
Plot2DCanvas(uint32_t w, uint32_t h)
Construct a new Plot2D:: Plot2D object. The same as its parent, the constructor requires the dimensio...
Definition: plot_2D.cpp:37
float getScaleX() const
Get the scale_x of the canvas.
Definition: plot_2D.cpp:94
void draw(std::function< Y(X)> function, char c, std::string_view feat="")
Plot a function that receives an argument of a numeric type X and returns a numeric value of type Y....
Definition: plot_2D.hpp:76
Definition: canvas.cpp:30
const std::string & feat(const std::unordered_map< std::string, std::string > &generic_map, const std::string &feat_string)
It takes an std::map object as the first argument and an std::string object (map key) as the second a...
Definition: common.cpp:41