osmanip
Library with useful output stream tools like: color and style manipulators, progress bars and terminal graphics.
Public Member Functions | List of all members
osm::Plot2DCanvas Class Reference

This class is used to plot mathematical functions R -> R. In addition to all the properties of a basic Canvas, this one also has an offset and a scale for the plot. The offset is the first value in x and y to be represented in the canvas and the scale is the difference in x or y that each character represents relative to the previous one. For example: a canvas of size = (15, 10) with offset = (3,2) and scale = (7, 5) will represent the functions you draw from x=3 to x=3+15*7=108 and from y=2 to y=2+10*5=52. More...

#include <plot_2D.hpp>

Inheritance diagram for osm::Plot2DCanvas:
Inheritance graph
[legend]
Collaboration diagram for osm::Plot2DCanvas:
Collaboration graph
[legend]

Public Member Functions

 Plot2DCanvas (uint32_t w, uint32_t h)
 Construct a new Plot2D:: Plot2D object. The same as its parent, the constructor requires the dimensions of the canvas. More...
 
void setOffset (float xOff, float yOff)
 Set the offset_x and offset_y of the canvas. More...
 
void setScale (float xScale, float yScale)
 Set the scale_x and scale_y of the canvas. More...
 
float getOffsetX () const
 Get the offset_x of the canvas. More...
 
float getOffsetY () const
 Get the offset_y of the canvas. More...
 
float getScaleX () const
 Get the scale_x of the canvas. More...
 
float getScaleY () const
 Get the scale_y of the canvas. More...
 
template<typename Y , typename X >
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. Represent it with a given char c and an optional feat. More...
 
- Public Member Functions inherited from osm::Canvas
 Canvas (uint32_t width, uint32_t height)
 Construct a new Canvas:: Canvas object. The size of the canvas in characters must be specified upon construction. More...
 
void enableFrame (bool frame_enabled)
 Flag to frame or not the canvas. The frame doesn't increase the size taken by the canvas. Instead, reduces the 2D space to draw in two columns and two rows (used to print the frame itself). More...
 
void setFrame (FrameStyle, std::string_view feat="")
 Set the FrameStyle of the canvas and an optional feat. More...
 
void setBackground (char c, std::string_view feat="")
 Set the char that fills the background and an optional feat. More...
 
void setWidth (uint32_t width)
 Set the width of the canvas. More...
 
void setHeight (uint32_t height)
 Set the height of the canvas. More...
 
char getBackground () const
 Get the char that fills the background. More...
 
std::string getBackgroundFeat () const
 Get the optional feat of the background. More...
 
bool isFrameEnabled () const
 Return True if the frame is enabled. Otherwise return False. More...
 
std::string getFrameFeat () const
 Get the frame feature (if set). More...
 
FrameStyle getFrameStyle () const
 Get the frame style. More...
 
uint32_t getWidth () const
 Get the width of the canvas. More...
 
uint32_t getHeight () const
 Get the height of the canvas. More...
 
void clear ()
 Fill the canvas with the background. More...
 
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 will be thrown if the coordinates are outside the canvas. More...
 
void refresh ()
 Display the canvas in the console. More...
 

Additional Inherited Members

- Protected Attributes inherited from osm::Canvas
uint32_t width_
 
uint32_t height_
 

Detailed Description

This class is used to plot mathematical functions R -> R. In addition to all the properties of a basic Canvas, this one also has an offset and a scale for the plot. The offset is the first value in x and y to be represented in the canvas and the scale is the difference in x or y that each character represents relative to the previous one. For example: a canvas of size = (15, 10) with offset = (3,2) and scale = (7, 5) will represent the functions you draw from x=3 to x=3+15*7=108 and from y=2 to y=2+10*5=52.

Constructor & Destructor Documentation

◆ Plot2DCanvas()

osm::Plot2DCanvas::Plot2DCanvas ( uint32_t  w,
uint32_t  h 
)
explicit

Construct a new Plot2D:: Plot2D object. The same as its parent, the constructor requires the dimensions of the canvas.

Parameters
widthWidth of the canvas.
heightHeight of the canvas.

Member Function Documentation

◆ draw()

template<typename Y , typename X >
void osm::Plot2DCanvas::draw ( std::function< Y(X)>  function,
char  c,
std::string_view  feat = "" 
)
inline

Plot a function that receives an argument of a numeric type X and returns a numeric value of type Y. Represent it with a given char c and an optional feat.

Template Parameters
YType-argument of the given function.
XType-return of the given function.
Parameters
functionThe input function.
cThe char to represent a function.
featThe optional feature.

◆ getOffsetX()

float osm::Plot2DCanvas::getOffsetX ( ) const

Get the offset_x of the canvas.

Returns
The offset_x of the canvas.

◆ getOffsetY()

float osm::Plot2DCanvas::getOffsetY ( ) const

Get the offset_y of the canvas.

Returns
The offset_y of the canvas.

◆ getScaleX()

float osm::Plot2DCanvas::getScaleX ( ) const

Get the scale_x of the canvas.

Returns
The scale_x of the canvas.

◆ getScaleY()

float osm::Plot2DCanvas::getScaleY ( ) const

Get the scale_y of the canvas.

Returns
The scale_y of the canvas.

◆ setOffset()

void osm::Plot2DCanvas::setOffset ( float  xOff,
float  yOff 
)

Set the offset_x and offset_y of the canvas.

Parameters
offset_xThe offset_x of the canvas.
offset_yThe offset_y of the canvas.

◆ setScale()

void osm::Plot2DCanvas::setScale ( float  xScale,
float  yScale 
)

Set the scale_x and scale_y of the canvas.

Parameters
scale_xThe scale_x of the canvas.
scale_yThe scale_y of the canvas.

The documentation for this class was generated from the following files: