-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.h
More file actions
47 lines (39 loc) · 1.74 KB
/
parser.h
File metadata and controls
47 lines (39 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
double evaluate(double a, double b, std::string op);
double evaluate(double a, std::string op);
std::vector<std::vector<double>> evaluate(std::vector<std::vector<double>> a, std::vector<std::vector<double>> b, std::string op);
std::vector<std::vector<double>> evaluate(std::vector<std::vector<double>> a, std::string op);
int precedence(char op);
std::string getRPN(std::string input);
double computeNumber(std::string RPN, double x, double y);
std::vector<std::vector<double>> computePlane(std::string RPN, int sizeX, int sizeY);
template <typename T>
std::vector<std::vector<T>> initVec(T a, size_t sizeX, size_t sizeY){
return std::vector<std::vector<T>>(sizeY, std::vector<T>(sizeX, a));
}
void printPlane(std::vector<std::vector<double>>& a, std::string fname="plane.txt");
template <typename T>
void printVector(std::vector<T> v, std::string fname){
std::ofstream planeFile;
planeFile.open(fname);
if(!planeFile.is_open())
std::cerr<<"file cant be opened\n";
for (auto &i : v)
{
planeFile<<i<<"\n";
//std::cout<<i;
}
planeFile.close();
}
/// @brief
/// @param expression Expression consisting of integers, arguments x, y, operators +, -, *, /, ^, brackets and functions: sin(...), cos(...).
/// @param xMin //
/// @param xMax
/// @param yMin
/// @param yMax
/// @return 2d double vector representing a plane's z coordinates, being results of expression, with x and y being coordinates starting at xMin, yMin, ending at xMax, yMax.
std::tuple<std::vector<std::vector<double>>, std::vector<double>, std::vector<double>> evaluatePlaneExpression(std::string expression, double xMin, double xMax, double yMin, double yMax);