amath  1.8.5
Simple command line calculator
Grid Class Reference

#include <fgrid.h>

Collaboration diagram for Grid:

Public Member Functions

 Grid (UserFunction *function)
 
 ~Grid ()
 
void SetFunctionBounderies (double minX, double maxX)
 
void SetScreenBounderues (int minX, int maxX, int minY, int maxY)
 
void GetScreenCoordinates (double value, int *x, int *y) const
 
void GetScreenCoordinates (double xval, int *x, double yval, int *y) const
 
double GetHorizontalResolution () const
 
void GetXAxis (int *xstart, int *xend, int *ystart, int *yend) const
 
void GetYAxis (int *xstart, int *xend, int *ystart, int *yend) const
 

Private Member Functions

double FunctionValue (double parameter) const
 

Private Attributes

UserFunctionfunction
 
RealNumberparameter
 
double minX
 
double maxX
 
double minY
 
double maxY
 
int pad
 
int screenMinX
 
int screenMaxX
 
int screenMinY
 
int screenMaxY
 
int originX
 
int originY
 
double zoom
 
double scaleX
 
double scaleY
 

Detailed Description

Definition at line 42 of file fgrid.h.

Constructor & Destructor Documentation

◆ Grid()

Grid::Grid ( UserFunction function)
explicit

Definition at line 33 of file fgrid.cpp.

References function, pad, parameter, RealNumber::RealNumber(), and zoom.

Referenced by PlotStatement::Execute().

33  :
34  function(function)
35 {
36  parameter = new RealNumber();
37  zoom = 1.0;
38  pad = 8;
39 }
double zoom
Definition: fgrid.h:75
RealNumber * parameter
Definition: fgrid.h:60
Represent a real number with 15 significant digits.
Definition: real.h:45
int pad
Definition: fgrid.h:67
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Grid()

Grid::~Grid ( )

Definition at line 41 of file fgrid.cpp.

References parameter.

42 {
43  delete parameter;
44 }
RealNumber * parameter
Definition: fgrid.h:60

Member Function Documentation

◆ FunctionValue()

double Grid::FunctionValue ( double  parameter) const
private

Definition at line 83 of file fgrid.cpp.

References Variable::AssignValue(), ExpressionNode::Evaluate(), function, UserFunction::GetExpression(), Number::GetRealValue(), UserFunction::GetVariable(), parameter, and RealNumber::SetRealValue().

Referenced by GetScreenCoordinates(), and SetFunctionBounderies().

84 {
86  function->GetVariable()->AssignValue(this->parameter);
87  Number* res = function->GetExpression()->Evaluate();
88  double value = res->GetRealValue();
89  return value;
90 }
Definition: numb.h:66
RealNumber * parameter
Definition: fgrid.h:60
virtual double GetRealValue()=0
void SetRealValue(double value)
Definition: real.cpp:100
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetHorizontalResolution()

double Grid::GetHorizontalResolution ( ) const

Definition at line 46 of file fgrid.cpp.

References maxX, minX, screenMaxX, and screenMinX.

Referenced by PlotStatement::Execute().

47 {
48  return (maxX - minX) / (screenMaxX - screenMinX);
49 }
int screenMinX
Definition: fgrid.h:68
double minX
Definition: fgrid.h:62
double maxX
Definition: fgrid.h:63
int screenMaxX
Definition: fgrid.h:69
Here is the caller graph for this function:

◆ GetScreenCoordinates() [1/2]

void Grid::GetScreenCoordinates ( double  value,
int *  x,
int *  y 
) const

Definition at line 92 of file fgrid.cpp.

References FunctionValue(), originX, originY, scaleX, scaleY, screenMaxX, screenMaxY, screenMinX, screenMinY, and zoom.

Referenced by PlotStatement::Execute().

93 {
94  double valueX = value * scaleX * zoom + originX;
95  double valueY = FunctionValue(value) * scaleY * zoom + originY;
96 
97  *x = valueX < screenMinX || valueX > screenMaxX ? -1 : static_cast<int>(valueX);
98  *y = valueY < screenMinY || valueY > screenMaxY ? -1 : static_cast<int>(valueY);
99 }
int originX
Definition: fgrid.h:73
double zoom
Definition: fgrid.h:75
double scaleY
Definition: fgrid.h:77
int screenMaxX
Definition: fgrid.h:69
int originY
Definition: fgrid.h:74
double scaleX
Definition: fgrid.h:76
double FunctionValue(double parameter) const
Definition: fgrid.cpp:83
int screenMaxY
Definition: fgrid.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetScreenCoordinates() [2/2]

void Grid::GetScreenCoordinates ( double  xval,
int *  x,
double  yval,
int *  y 
) const

Definition at line 101 of file fgrid.cpp.

References originX, originY, scaleX, scaleY, screenMaxX, screenMaxY, screenMinX, screenMinY, and zoom.

102 {
103  double valueX = xval * scaleX * zoom + originX;
104  double valueY = yval * scaleY * zoom + originY;
105 
106  *x = valueX < screenMinX || valueX > screenMaxX ? -1 : static_cast<int>(valueX);
107  *y = valueY < screenMinY || valueY > screenMaxY ? -1 : static_cast<int>(valueY);
108 }
int originX
Definition: fgrid.h:73
double zoom
Definition: fgrid.h:75
double scaleY
Definition: fgrid.h:77
int screenMaxX
Definition: fgrid.h:69
int originY
Definition: fgrid.h:74
double scaleX
Definition: fgrid.h:76
int screenMaxY
Definition: fgrid.h:71

◆ GetXAxis()

void Grid::GetXAxis ( int *  xstart,
int *  xend,
int *  ystart,
int *  yend 
) const

Definition at line 110 of file fgrid.cpp.

References originY, screenMaxX, and screenMinX.

111 {
112  *xstart = screenMinX;
113  *xend = screenMaxX;
114  *ystart = originY;
115  *yend = originY;
116 }
int screenMinX
Definition: fgrid.h:68
int screenMaxX
Definition: fgrid.h:69
int originY
Definition: fgrid.h:74

◆ GetYAxis()

void Grid::GetYAxis ( int *  xstart,
int *  xend,
int *  ystart,
int *  yend 
) const

Definition at line 118 of file fgrid.cpp.

References originX, screenMaxY, and screenMinY.

119 {
120  *xstart = originX;
121  *xend = originX;
122  *ystart = screenMinY;
123  *yend = screenMaxY;
124 }
int originX
Definition: fgrid.h:73
int screenMinY
Definition: fgrid.h:70
int screenMaxY
Definition: fgrid.h:71

◆ SetFunctionBounderies()

void Grid::SetFunctionBounderies ( double  minX,
double  maxX 
)

Definition at line 51 of file fgrid.cpp.

References FunctionValue(), maxX, maxY, minX, minY, scaleX, scaleY, screenMaxX, screenMaxY, screenMinX, and screenMinY.

Referenced by PlotStatement::Execute().

52 {
53  this->minX = minX;
54  this->maxX = maxX;
57 
58  scaleX = (screenMaxX - screenMinX) / (maxX - minX);
59  scaleY = (screenMaxY - screenMinY) / (maxY - minY);
60 
61  // Keep aspect ratio
62  if (scaleX < scaleY)
63  {
64  scaleX = scaleY;
65  }
66  else
67  {
68  scaleY = scaleX;
69  }
70 }
double maxY
Definition: fgrid.h:65
int screenMinX
Definition: fgrid.h:68
double scaleY
Definition: fgrid.h:77
double minX
Definition: fgrid.h:62
int screenMinY
Definition: fgrid.h:70
double minY
Definition: fgrid.h:64
double maxX
Definition: fgrid.h:63
int screenMaxX
Definition: fgrid.h:69
double scaleX
Definition: fgrid.h:76
double FunctionValue(double parameter) const
Definition: fgrid.cpp:83
int screenMaxY
Definition: fgrid.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetScreenBounderues()

void Grid::SetScreenBounderues ( int  minX,
int  maxX,
int  minY,
int  maxY 
)

Definition at line 72 of file fgrid.cpp.

References originX, originY, pad, screenMaxX, screenMaxY, screenMinX, and screenMinY.

Referenced by PlotStatement::Execute().

73 {
74  screenMinX = minX + pad;
75  screenMaxX = maxX - pad;
76  screenMinY = minY + pad;
77  screenMaxY = maxY - pad;
78 
79  originX = (screenMaxX - screenMinX) / 2;
80  originY = (screenMaxY - screenMinY) / 2;
81 }
double maxY
Definition: fgrid.h:65
int originX
Definition: fgrid.h:73
int screenMinX
Definition: fgrid.h:68
double minX
Definition: fgrid.h:62
int screenMinY
Definition: fgrid.h:70
double minY
Definition: fgrid.h:64
double maxX
Definition: fgrid.h:63
int screenMaxX
Definition: fgrid.h:69
int originY
Definition: fgrid.h:74
int pad
Definition: fgrid.h:67
int screenMaxY
Definition: fgrid.h:71
Here is the caller graph for this function:

Member Data Documentation

◆ function

UserFunction* Grid::function
private

Definition at line 59 of file fgrid.h.

Referenced by FunctionValue(), and Grid().

◆ maxX

double Grid::maxX
private

Definition at line 63 of file fgrid.h.

Referenced by GetHorizontalResolution(), and SetFunctionBounderies().

◆ maxY

double Grid::maxY
private

Definition at line 65 of file fgrid.h.

Referenced by SetFunctionBounderies().

◆ minX

double Grid::minX
private

Definition at line 62 of file fgrid.h.

Referenced by GetHorizontalResolution(), and SetFunctionBounderies().

◆ minY

double Grid::minY
private

Definition at line 64 of file fgrid.h.

Referenced by SetFunctionBounderies().

◆ originX

int Grid::originX
private

Definition at line 73 of file fgrid.h.

Referenced by GetScreenCoordinates(), GetYAxis(), and SetScreenBounderues().

◆ originY

int Grid::originY
private

Definition at line 74 of file fgrid.h.

Referenced by GetScreenCoordinates(), GetXAxis(), and SetScreenBounderues().

◆ pad

int Grid::pad
private

Definition at line 67 of file fgrid.h.

Referenced by Grid(), and SetScreenBounderues().

◆ parameter

RealNumber* Grid::parameter
private

Definition at line 60 of file fgrid.h.

Referenced by FunctionValue(), Grid(), and ~Grid().

◆ scaleX

double Grid::scaleX
private

Definition at line 76 of file fgrid.h.

Referenced by GetScreenCoordinates(), and SetFunctionBounderies().

◆ scaleY

double Grid::scaleY
private

Definition at line 77 of file fgrid.h.

Referenced by GetScreenCoordinates(), and SetFunctionBounderies().

◆ screenMaxX

int Grid::screenMaxX
private

◆ screenMaxY

int Grid::screenMaxY
private

Definition at line 71 of file fgrid.h.

Referenced by GetScreenCoordinates(), GetYAxis(), SetFunctionBounderies(), and SetScreenBounderues().

◆ screenMinX

int Grid::screenMinX
private

◆ screenMinY

int Grid::screenMinY
private

Definition at line 70 of file fgrid.h.

Referenced by GetScreenCoordinates(), GetYAxis(), SetFunctionBounderies(), and SetScreenBounderues().

◆ zoom

double Grid::zoom
private

Definition at line 75 of file fgrid.h.

Referenced by GetScreenCoordinates(), and Grid().


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