-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.h
More file actions
97 lines (83 loc) · 2.04 KB
/
Point.h
File metadata and controls
97 lines (83 loc) · 2.04 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// Created by Ben Dickson on 5/9/17.
//
#ifndef LIBRARY_POINT_H
#define LIBRARY_POINT_H
#include <math.h>
#include <cstdlib>
#include <string>
struct Point
{
double x,y,r;
};
class Rotation
{
private:
double sinValue[360];
double cosValue[360];
public:
const double PI = 3.1415926535897932384626433832795f;
inline double cos(int angle) const
{
if(angle<0)
{
return cosValue[(angle%360+360)%360];
}
return cosValue[angle%360];
}
inline double sin(int angle) const
{
if(angle<0)
{
return sinValue[(angle%360+360)%360];
}
return sinValue[angle%360];
}
Rotation()
{
int i=-1;
while(++i<360)
{
sinValue[i] = sin(((double)i*PI)/180);
cosValue[i] = cos(((double)i*PI)/180);
}
cosValue[0] = 1;
cosValue[90] = 0;
cosValue[180] = -1;
cosValue[270] = 0;
sinValue[0] = 0;
sinValue[90] = 1;
sinValue[180] = 0;
sinValue[270] = -1;
}
};
// white space trimmer
// taken from http://stackoverflow.com/a/1798170
std::string trim(const std::string& str,
const std::string& whitespace = " \t")
{
const auto strBegin = str.find_first_not_of(whitespace);
if (strBegin == std::string::npos)
return ""; // no content
const auto strEnd = str.find_last_not_of(whitespace);
const auto strRange = strEnd - strBegin + 1;
return str.substr(strBegin, strRange);
}
// takes a line with an equals and splits into two strings
std::pair<std::string,std::string> getEquals(const std::string line)
{
return getEquals(line,'=');
};
std::pair<std::string,std::string> getEquals(const std::string line,char split)
{
int eq = line.find(split);
if(eq<line.length())
{
return std::pair<std::string,std::string>(line.substr(0,eq),line.substr(eq+1,std::string::npos));
}
else
{
return std::pair<std::string,std::string>(line, nullptr);
}
};
#endif //LIBRARY_POINT_H