gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
SPoint2.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 SPOINT2_H
7 #define SPOINT2_H
8 
9 #include <cmath>
10 
11 // A point in 2-space
12 class SPoint2 {
13 protected:
14  double P[2];
15 
16 public:
17  SPoint2(double x = 0.0, double y = 0.0)
18  {
19  P[0] = x;
20  P[1] = y;
21  }
22  SPoint2(double *p)
23  {
24  P[0] = p[0];
25  P[1] = p[1];
26  }
27  SPoint2(const SPoint2 &pt)
28  {
29  P[0] = pt.P[0];
30  P[1] = pt.P[1];
31  }
32  virtual ~SPoint2() {}
33  void setPosition(double xx, double yy);
34  void getPosition(double *xx, double *yy) const;
35  void position(double *) const;
36  inline double x(void) const;
37  inline double y(void) const;
38  double &operator[](int);
39  double operator[](int) const;
40  double distance(const SPoint2 &p) const;
41  SPoint2 &operator=(const SPoint2 &p);
42  void operator+=(const SPoint2 &p);
43  void operator-=(const SPoint2 &p);
44  void operator*=(double mult);
45  SPoint2 operator*(double mult) const;
46  operator double *() { return P; }
47  bool operator<(const SPoint2 &other) const
48  {
49  if(other.P[0] < P[0]) return true;
50  if(other.P[0] > P[0]) return false;
51  if(other.P[1] < P[1]) return true;
52  return false;
53  }
54  const double *data() const { return P; }
55  double *data() { return P; }
56 };
57 
58 inline SPoint2 operator+(const SPoint2 &a, const SPoint2 &b)
59 {
60  return SPoint2(a.x() + b.x(), a.y() + b.y());
61 }
62 
63 inline SPoint2 operator-(const SPoint2 &a, const SPoint2 &b)
64 {
65  return SPoint2(a.x() - b.x(), a.y() - b.y());
66 }
67 
68 inline void SPoint2::setPosition(double xx, double yy)
69 {
70  P[0] = xx;
71  P[1] = yy;
72 }
73 
74 inline void SPoint2::getPosition(double *xx, double *yy) const
75 {
76  *xx = P[0];
77  *yy = P[1];
78 }
79 
80 inline void SPoint2::position(double *p) const
81 {
82  p[0] = P[0];
83  p[1] = P[1];
84 }
85 
86 inline double SPoint2::x(void) const { return P[0]; }
87 
88 inline double SPoint2::y(void) const { return P[1]; }
89 
91 {
92  P[0] = p.P[0];
93  P[1] = p.P[1];
94  return *this;
95 }
96 
97 inline double &SPoint2::operator[](int i) { return P[i]; }
98 
99 inline double SPoint2::operator[](int i) const { return P[i]; }
100 
101 inline void SPoint2::operator+=(const SPoint2 &p)
102 {
103  P[0] += p.P[0];
104  P[1] += p.P[1];
105 }
106 
107 inline void SPoint2::operator-=(const SPoint2 &p)
108 {
109  P[0] -= p.P[0];
110  P[1] -= p.P[1];
111 }
112 
113 inline void SPoint2::operator*=(double mult)
114 {
115  P[0] *= mult;
116  P[1] *= mult;
117 }
118 
119 inline SPoint2 SPoint2::operator*(double mult) const
120 {
121  return SPoint2(P[0] * mult, P[1] * mult);
122 }
123 
124 inline double SPoint2::distance(const SPoint2 &p) const
125 {
126  double x = P[0] - p.P[0], y = P[1] - p.P[1];
127  return std::sqrt(x * x + y * y);
128 }
129 
130 #endif
operator+
SPoint2 operator+(const SPoint2 &a, const SPoint2 &b)
Definition: SPoint2.h:58
SPoint2
Definition: SPoint2.h:12
SPoint2::operator+=
void operator+=(const SPoint2 &p)
Definition: SPoint2.h:101
SPoint2::data
double * data()
Definition: SPoint2.h:55
SPoint2::operator[]
double & operator[](int)
Definition: SPoint2.h:97
SPoint2::data
const double * data() const
Definition: SPoint2.h:54
operator-
SPoint2 operator-(const SPoint2 &a, const SPoint2 &b)
Definition: SPoint2.h:63
SPoint2::SPoint2
SPoint2(double x=0.0, double y=0.0)
Definition: SPoint2.h:17
SPoint2::operator-=
void operator-=(const SPoint2 &p)
Definition: SPoint2.h:107
SPoint2::~SPoint2
virtual ~SPoint2()
Definition: SPoint2.h:32
SPoint2::operator*
SPoint2 operator*(double mult) const
Definition: SPoint2.h:119
SPoint2::position
void position(double *) const
Definition: SPoint2.h:80
SPoint2::operator=
SPoint2 & operator=(const SPoint2 &p)
Definition: SPoint2.h:90
SPoint2::getPosition
void getPosition(double *xx, double *yy) const
Definition: SPoint2.h:74
SPoint2::operator<
bool operator<(const SPoint2 &other) const
Definition: SPoint2.h:47
mult
Quaternion mult(const Quaternion &A, const Quaternion &B)
Definition: Camera.cpp:459
SPoint2::SPoint2
SPoint2(double *p)
Definition: SPoint2.h:22
SPoint2::setPosition
void setPosition(double xx, double yy)
Definition: SPoint2.h:68
SPoint2::P
double P[2]
Definition: SPoint2.h:14
SPoint2::x
double x(void) const
Definition: SPoint2.h:86
SPoint2::SPoint2
SPoint2(const SPoint2 &pt)
Definition: SPoint2.h:27
SPoint2::distance
double distance(const SPoint2 &p) const
Definition: SPoint2.h:124
SPoint2::operator*=
void operator*=(double mult)
Definition: SPoint2.h:113
SPoint2::y
double y(void) const
Definition: SPoint2.h:88