sfof
point_class.hpp
Go to the documentation of this file.
1 
2 #ifndef CLASS_POINT
3 #define CLASS_POINT
4 
5 //#include "astro.hpp"
6 
7 #define DIMENSIONS 2
8 
9 extern int PERIODIC[DIMENSIONS];
11 
12 #define SETPERIODIC( D, L) {PERIODIC[(D)] = 1; BoxSize[(D)] = (L); BoxHalf[(D)] = (L)/2.0;}
13 #define PDISTANCE( mydist, D) ((!PERIODIC[D])? (mydist) : (((mydist) > BoxHalf[D])?( (mydist) - BoxSize[D] ) : ( ((mydist) < -BoxHalf[D])? ((mydist) + BoxSize[D]) : (mydist) ) ))
14 #define NOPERIODIC {for(int i = 0; i < DIMENSIONS; i++) PERIODIC[i] = 0;};
15 
16 
17 
18 class Point {
19 public:
20  double P[DIMENSIONS];
21 
22  double sqdistance(const Point& S)
23  {
24  if (this == &S)
25  return 0;
26  double sqdist = 0;
27  for(int i = 0; i < DIMENSIONS; i++)
28  sqdist += (P[i] - S.P[i]) * (P[i] - S.P[i]);
29  return sqdist;
30  }
31 
32  double distance(const Point& S, int D)
33  {
34  if (this == &S)
35  return 0;
36  double dist = 0;
37  dist = P[D] - S.P[D];
38  return dist;
39  }
40 
41  double psqdistance(const Point& S)
42  {
43  if (this == &S)
44  return 0;
45  double dist, sqdist = 0;
46  for(int i = 0; i < DIMENSIONS; i++) {
47  dist = PDISTANCE((P[i] - S.P[i]), i);
48  sqdist += dist * dist;
49  }
50  return sqdist;
51  }
52 
53  Point();
54  Point(double, double);
55  Point(double *);
56  Point(const Point& );
57  Point& operator=(const Point& );
58  Point& operator-(const Point& );
59  Point& operator+(const Point& );
60 
61 };
62 
63 inline Point::Point() {};
64 
65 inline Point::Point(double S0, double S1) {
66  P[0] = S0;
67  P[1] = S1;
68 }
69 
70 inline Point::Point(double *S) {
71  for(int i = 0; i < DIMENSIONS; i++)
72  P[i] = *(S+i);
73 }
74 
75 inline Point::Point(const Point& S) {
76  for(int i = 0; i < DIMENSIONS; i++)
77  P[i] = S.P[i];
78 }
79 
80 inline Point& Point::operator=(const Point& S) {
81  if (this != &S)
82  for(int i = 0; i < DIMENSIONS; i++)
83  P[i] = S.P[i];
84  return *this;
85 }
86 
87 inline Point& Point::operator+(const Point& S) {
88  if (this != &S)
89  for(int i = 0; i < DIMENSIONS; i++)
90  P[i] += S.P[i];
91  return *this;
92 }
93 
94 inline Point& Point::operator-(const Point& S) {
95  if (this != &S)
96  for(int i = 0; i < DIMENSIONS; i++)
97  P[i] -= S.P[i];
98  return *this;
99 }
100 
101 
102 #endif
Point::operator=
Point & operator=(const Point &)
Definition: point_class.hpp:80
Point::operator-
Point & operator-(const Point &)
Definition: point_class.hpp:94
Point
Definition: point_class.hpp:18
BoxHalf
double BoxHalf[DIMENSIONS]
Definition: point_class.hpp:10
Point::distance
double distance(const Point &S, int D)
Definition: point_class.hpp:32
BoxSize
double BoxSize[DIMENSIONS]
Definition: point_class.cpp:6
PERIODIC
int PERIODIC[DIMENSIONS]
Definition: point_class.cpp:5
Point::operator+
Point & operator+(const Point &)
Definition: point_class.hpp:87
Point::psqdistance
double psqdistance(const Point &S)
Definition: point_class.hpp:41
DIMENSIONS
#define DIMENSIONS
Definition: point_class.hpp:7
Point::P
double P[DIMENSIONS]
Definition: point_class.hpp:20
Point::Point
Point()
Definition: point_class.hpp:63
Point::sqdistance
double sqdistance(const Point &S)
Definition: point_class.hpp:22
PDISTANCE
#define PDISTANCE(mydist, D)
Definition: point_class.hpp:13