gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
SPoint3.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef SPOINT3_H
7 #define SPOINT3_H
8 
9 #include <cmath>
10 #include <vector>
11 #include <array>
12 
13 // A point in 3-space
14 class SPoint3 {
15 protected:
16  double P[3];
17 
18 public:
19  SPoint3() { P[0] = P[1] = P[2] = 0.; }
20  SPoint3(double x, double y, double z)
21  {
22  P[0] = x;
23  P[1] = y;
24  P[2] = z;
25  }
26  SPoint3(const double *p)
27  {
28  P[0] = p[0];
29  P[1] = p[1];
30  P[2] = p[2];
31  }
32  SPoint3(const SPoint3 &pt)
33  {
34  P[0] = pt.P[0];
35  P[1] = pt.P[1];
36  P[2] = pt.P[2];
37  }
38  virtual ~SPoint3() {}
39  void setPosition(double xx, double yy, double zz);
40  void setPosition(const SPoint3 &pt, const SPoint3 &dir, const double dist_)
41  {
42  P[0] = pt.P[0];
43  P[1] = pt.P[1];
44  P[2] = pt.P[2];
45  SPoint3 a(dir);
46  a *= dist_;
47  P[0] += a[0];
48  P[1] += a[1];
49  P[2] += a[2];
50  }
51  void getPosition(double *xx, double *yy, double *zz) const;
52  void position(double *) const;
53  inline double x(void) const;
54  inline double y(void) const;
55  inline double z(void) const;
56  double &operator[](int);
57  double operator[](int) const;
58  SPoint3 &operator=(const SPoint3 &p);
59  void operator+=(const SPoint3 &p);
60  void operator-=(const SPoint3 &p);
61  void operator*=(double mult);
62  void operator/=(double mult);
63  SPoint3 operator*(double mult);
64  operator double *() { return P; }
65  double distance(const SPoint3 &p) const;
66  // lexicographic
67  bool operator<(const SPoint3 &p) const
68  {
69  if(P[0] < p.P[0]) return true;
70  if(P[0] > p.P[0]) return false;
71  if(P[1] < p.P[1]) return true;
72  if(P[1] > p.P[1]) return false;
73  if(P[2] < p.P[2]) return true;
74  return false;
75  }
76  const double *data() const { return P; }
77  double *data() { return P; }
78  bool transform(const std::vector<double> &tfo)
79  {
80  if(tfo.size() < 12) return false;
81  double old[3] = {P[0], P[1], P[2]};
82  P[0] = P[1] = P[2] = 0.;
83  int idx = 0;
84  for(int i = 0; i < 3; i++) {
85  for(int j = 0; j < 3; j++) P[i] += old[j] * tfo[idx++];
86  P[i] += tfo[idx++];
87  }
88  return true;
89  }
90  // implicit conversion to std::array<double, 3>
91  operator std::array<double, 3>() const { return {{P[0], P[1], P[2]}}; }
92 };
93 
94 inline SPoint3 operator+(const SPoint3 &a, const SPoint3 &b)
95 {
96  return SPoint3(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
97 }
98 
99 inline SPoint3 operator-(const SPoint3 &a, const SPoint3 &b)
100 {
101  return SPoint3(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
102 }
103 
104 inline void SPoint3::setPosition(double xx, double yy, double zz)
105 {
106  P[0] = xx;
107  P[1] = yy;
108  P[2] = zz;
109 }
110 
111 inline void SPoint3::getPosition(double *xx, double *yy, double *zz) const
112 {
113  *xx = P[0];
114  *yy = P[1];
115  *zz = P[2];
116 }
117 
118 inline void SPoint3::position(double *p) const
119 {
120  p[0] = P[0];
121  p[1] = P[1];
122  p[2] = P[2];
123 }
124 
125 inline double SPoint3::x(void) const { return P[0]; }
126 
127 inline double SPoint3::y(void) const { return P[1]; }
128 
129 inline double SPoint3::z(void) const { return P[2]; }
130 
132 {
133  P[0] = p.P[0];
134  P[1] = p.P[1];
135  P[2] = p.P[2];
136  return *this;
137 }
138 
139 inline void SPoint3::operator+=(const SPoint3 &p)
140 {
141  P[0] += p.P[0];
142  P[1] += p.P[1];
143  P[2] += p.P[2];
144 }
145 
146 inline void SPoint3::operator-=(const SPoint3 &p)
147 {
148  P[0] -= p.P[0];
149  P[1] -= p.P[1];
150  P[2] -= p.P[2];
151 }
152 
153 inline void SPoint3::operator*=(double mult)
154 {
155  P[0] *= mult;
156  P[1] *= mult;
157  P[2] *= mult;
158 }
159 
160 inline void SPoint3::operator/=(double div)
161 {
162  P[0] /= div;
163  P[1] /= div;
164  P[2] /= div;
165 }
166 
168 {
169  return SPoint3(P[0] * mult, P[1] * mult, P[2] * mult);
170 }
171 
172 inline double &SPoint3::operator[](int i) { return P[i]; }
173 
174 inline double SPoint3::operator[](int i) const { return P[i]; }
175 
176 inline double SPoint3::distance(const SPoint3 &p) const
177 {
178  double x = P[0] - p.P[0], y = P[1] - p.P[1], z = P[2] - p.P[2];
179  return std::sqrt(x * x + y * y + z * z);
180 }
181 
182 #endif
SPoint3::operator-=
void operator-=(const SPoint3 &p)
Definition: SPoint3.h:146
operator+
SPoint3 operator+(const SPoint3 &a, const SPoint3 &b)
Definition: SPoint3.h:94
SPoint3::operator*=
void operator*=(double mult)
Definition: SPoint3.h:153
SPoint3::operator=
SPoint3 & operator=(const SPoint3 &p)
Definition: SPoint3.h:131
operator-
SPoint3 operator-(const SPoint3 &a, const SPoint3 &b)
Definition: SPoint3.h:99
SPoint3::operator[]
double & operator[](int)
Definition: SPoint3.h:172
SPoint3::data
double * data()
Definition: SPoint3.h:77
SPoint3
Definition: SPoint3.h:14
SPoint3::~SPoint3
virtual ~SPoint3()
Definition: SPoint3.h:38
SPoint3::getPosition
void getPosition(double *xx, double *yy, double *zz) const
Definition: SPoint3.h:111
SPoint3::setPosition
void setPosition(double xx, double yy, double zz)
Definition: SPoint3.h:104
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
SPoint3::data
const double * data() const
Definition: SPoint3.h:76
SPoint3::SPoint3
SPoint3(double x, double y, double z)
Definition: SPoint3.h:20
SPoint3::SPoint3
SPoint3(const double *p)
Definition: SPoint3.h:26
SPoint3::P
double P[3]
Definition: SPoint3.h:16
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
SPoint3::operator<
bool operator<(const SPoint3 &p) const
Definition: SPoint3.h:67
mult
Quaternion mult(const Quaternion &A, const Quaternion &B)
Definition: Camera.cpp:459
SPoint3::SPoint3
SPoint3(const SPoint3 &pt)
Definition: SPoint3.h:32
SPoint3::SPoint3
SPoint3()
Definition: SPoint3.h:19
SPoint3::setPosition
void setPosition(const SPoint3 &pt, const SPoint3 &dir, const double dist_)
Definition: SPoint3.h:40
SPoint3::operator+=
void operator+=(const SPoint3 &p)
Definition: SPoint3.h:139
SPoint3::distance
double distance(const SPoint3 &p) const
Definition: SPoint3.h:176
SPoint3::position
void position(double *) const
Definition: SPoint3.h:118
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
SPoint3::operator*
SPoint3 operator*(double mult)
Definition: SPoint3.h:167
SPoint3::operator/=
void operator/=(double mult)
Definition: SPoint3.h:160
SPoint3::transform
bool transform(const std::vector< double > &tfo)
Definition: SPoint3.h:78