-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls_point.h
142 lines (113 loc) · 3.49 KB
/
ls_point.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// Created by lurker on 2/10/17.
//
#ifndef POINT_H
#define POINT_H
#include "utils.h"
class ls_basePoint {
public:
scalar_t data[DIM];
ls_basePoint() {memset(data, 0, DIM * sizeof(scalar_t));}
ls_basePoint(scalar_t _x, scalar_t _y, scalar_t _z) {
data[0] = _x;
data[1] = _y;
data[2] = _z;
}
virtual ~ls_basePoint() {}
bool operator>=(const ls_basePoint &a) {
return (data[0] >= a.data[0] - EPS) && (data[1] >= a.data[1] - EPS) && (data[2] >= a.data[2] - EPS);
}
bool operator<=(const ls_basePoint &a) {
return (data[0] <= a.data[0] + EPS) && (data[1] <= a.data[1] + EPS) && (data[2] <= a.data[2] + EPS);
}
bool operator==(const ls_basePoint &a) {
return fabs(data[0] - a.data[0]) < EPS && fabs(data[1] - a.data[1]) < EPS && fabs(data[2] - a.data[2]) < EPS;
}
};
class ls_point : public ls_basePoint {
public:
ls_point() : ls_basePoint() {
}
ls_point(scalar_t _x, scalar_t _y, scalar_t _z) : ls_basePoint(_x, _y, _z) {
}
ls_point(const ls_point& p) {
cblas_dcopy(DIM, p.data, 1, this->data, 1);
}
ls_point(ls_point&& p) {
cblas_dcopy(DIM, p.data, 1, this->data, 1);
}
~ls_point() {}
/*
* linear algebra for vec3.
*/
ls_point operator+ (const ls_point& p) {
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_daxpy(DIM, 1.0, p.data, 1, ret.data, 1);
return ret;
}
ls_point operator+(const scalar_t val) {
ls_point p; std::fill_n(p.data, DIM, val);
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_daxpy(DIM, 1.0, p.data, 1, ret.data, 1);
return ret;
}
ls_point operator-(const ls_point& p) {
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_daxpy(DIM, -1.0, p.data, 1, ret.data, 1);
return ret;
}
ls_point operator+ (ls_point&& p) {
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_daxpy(DIM, 1.0, p.data, 1, ret.data, 1);
return ret;
}
ls_point operator-(const scalar_t val) {
ls_point p; std::fill_n(p.data, DIM, val);
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_daxpy(DIM, -1.0, p.data, 1, ret.data, 1);
return ret;
}
ls_point operator-(ls_point&& p) {
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_daxpy(DIM, -1.0, p.data, 1, ret.data, 1);
return ret;
}
ls_point operator*(scalar_t val) {
ls_point ret;
cblas_dcopy(DIM, this->data, 1, ret.data, 1);
cblas_dscal(DIM, val, ret.data, 1);
return ret;
}
void operator=(const ls_point& p) {
cblas_dcopy(DIM, p.data, 1, this->data, 1);
}
void operator=(ls_point&& p) {
cblas_dcopy(DIM, p.data, 1, this->data, 1);
}
};
inline std::ostream &operator<<(std::ostream &os, ls_point &p) {
for (int i = 0; i < DIM - 1; ++i) {
os << p.data[i] << ", ";
}
os << p.data[DIM - 1];
return os;
}
inline scalar_t norm(const ls_point& a) {
return sqrt(cblas_ddot(DIM, a.data, 1, a.data, 1));
}
inline scalar_t nrm2(const ls_point& a) {
return cblas_ddot(DIM, a.data, 1, a.data, 1);
}
inline scalar_t norm(ls_point&& a) {
return sqrt(cblas_ddot(DIM, a.data, 1, a.data, 1));
}
inline scalar_t nrm2(ls_point&& a) {
return cblas_ddot(DIM, a.data, 1, a.data, 1);
}
#endif //POINT_H