-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint_imp.h
More file actions
65 lines (53 loc) · 1.78 KB
/
Point_imp.h
File metadata and controls
65 lines (53 loc) · 1.78 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
//
// Created by simonepanzeri on 24/11/2021.
//
#ifndef DEV_FDAPDE_POINT_IMP_H
#define DEV_FDAPDE_POINT_IMP_H
template<>
constexpr Point<2>::Point(UInt id, UInt bcId, const Real(&coord)[2]) :
Identifier(id, bcId), coord_({coord[0],coord[1]}) {}
template<>
constexpr Point<3>::Point(UInt id, UInt bcId, const Real(&coord)[3]) :
Identifier(id, bcId), coord_({coord[0],coord[1],coord[2]}) {}
template<UInt ndim>
Point<ndim>::Point(UInt id, UInt bcId, const EigenCoords& coord) :
Identifier(id, bcId) {
for(UInt i = 0; i < ndim; ++i)
coord_[i] = coord[i];
}
template<UInt ndim>
Point<ndim>::Point(UInt id, const RNumericMatrix& points) :
Identifier(id) {
for(UInt i = 0; i < ndim; ++i)
coord_[i] = points(id, i);
}
// This function returns the squared euclidean distance between "this" point and other
template <UInt ndim>
inline Real Point<ndim>::dist2(const Point<ndim> &other) const {
return (this->eigenView() - other.eigenView()).squaredNorm();
}
// This function returns the euclidean distance between "this" point and other
template <UInt ndim>
inline Real Point<ndim>::dist(const Point<ndim> &other) const {
return std::sqrt(dist2(other));
}
// Overloaded +=/-= operators
template <UInt ndim>
inline Point<ndim>& Point<ndim>::operator+=(const Point &other) {
this->eigenView() += other.eigenView();
return *this;
}
template <UInt ndim>
inline Point<ndim>& Point<ndim>::operator-=(const Point &other) {
this->eigenView() -= other.eigenView();
return *this;
}
template <UInt NDIM>
std::ostream& operator<<(std::ostream& os, const Point<NDIM>& p) {
if(p.hasValidId())
os << p.getId() << ":";
for (const auto &c : p.coord_)
os << " " << c;
return os << std::endl;
}
#endif //DEV_FDAPDE_POINT_IMP_H