TORCS  1.3.9
The Open Racing Car Simulator
Point.h
Go to the documentation of this file.
1 /*
2  3D - C++ Class Library for 3D Transformations
3  Copyright (C) 1996-1998 Gino van den Bergen
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 
19  Please send remarks, questions and bug reports to gino@win.tue.nl,
20  or write to:
21  Gino van den Bergen
22  Department of Mathematics and Computing Science
23  Eindhoven University of Technology
24  P.O. Box 513, 5600 MB Eindhoven, The Netherlands
25 */
26 
27 #ifndef _POINT_H_
28 #define _POINT_H_
29 
30 #include <algorithm>
31 
32 #include "Vector.h"
33 
34 class Point : public Vector {
35 public:
36  Point() {}
37  Point(const float p[3]) : Vector(p) {}
38  Point(const double p[3]) : Vector(p) {}
39  Point(Scalar x, Scalar y, Scalar z) : Vector(x, y, z) {}
40 
41  Point& operator+=(const Vector& v);
42  Point& operator-=(const Vector& v);
43  Point& operator=(const Vector& v);
44 
45  void setInf(const Point& p);
46  void setSup(const Point& p);
47 };
48 
49 Point operator+(const Point& p, const Vector& v);
50 Point operator-(const Point& p, const Vector& v);
51 
52 Vector operator-(const Point& p1, const Point& p2);
53 
54 bool operator<(const Point& p1, const Point& p2);
55 
56 Point inf(const Point& p1, const Point& p2);
57 Point sup(const Point& p1, const Point& p2);
58 
59 Point affine(const Point& p1, const Point& p2, Scalar t);
60 
61 Scalar distance(const Point& p1, const Point& p2);
62 Scalar distance2(const Point& p1, const Point& p2);
63 
64 
65 inline Point& Point::operator+=(const Vector& v) {
66  comp[X] += v[X]; comp[Y] += v[Y]; comp[Z] += v[Z];
67  return *this;
68 }
69 
70 inline Point& Point::operator-=(const Vector& v) {
71  comp[X] -= v[X]; comp[Y] -= v[Y]; comp[Z] -= v[Z];
72  return *this;
73 }
74 
75 inline Point& Point::operator=(const Vector& v) {
76  comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z];
77  return *this;
78 }
79 
80 inline void Point::setInf(const Point& p) {
81  set_min(comp[X], p[X]); set_min(comp[Y], p[Y]); set_min(comp[Z], p[Z]);
82 }
83 
84 inline void Point::setSup(const Point& p) {
85  set_max(comp[X], p[X]); set_max(comp[Y], p[Y]); set_max(comp[Z], p[Z]);
86 }
87 
88 inline Point operator+(const Point& p, const Vector& v) {
89  return Point(p[X] + v[X], p[Y] + v[Y], p[Z] + v[Z]);
90 }
91 
92 inline Point operator-(const Point& p, const Vector& v) {
93  return Point(p[X] - v[X], p[Y] - v[Y], p[Z] - v[Z]);
94 }
95 
96 inline Vector operator-(const Point& p1, const Point& p2) {
97  return Vector(p1[X] - p2[X], p1[Y] - p2[Y], p1[Z] - p2[Z]);
98 }
99 
100 inline bool operator<(const Point& p1, const Point& p2) {
101  return p1[X] < p2[X] && p1[Y] < p2[Y] && p1[Z] < p2[Z];
102 }
103 
104 inline Point inf(const Point& p1, const Point& p2) {
105  return Point(min(p1[X], p2[X]), min(p1[Y], p2[Y]), min(p1[Z], p2[Z]));
106 }
107 
108 inline Point sup(const Point& p1, const Point& p2) {
109  return Point(max(p1[X], p2[X]), max(p1[Y], p2[Y]), max(p1[Z], p2[Z]));
110 }
111 
112 inline Point affine(const Point& p1, const Point& p2, Scalar t) {
113  return Point(p1[X] + (p2[X] - p1[X]) * t,
114  p1[Y] + (p2[Y] - p1[Y]) * t,
115  p1[Z] + (p2[Z] - p1[Z]) * t);
116 }
117 
118 inline Scalar distance(const Point& p1, const Point& p2) {
119  return length(p1 - p2);
120 }
121 
122 inline Scalar distance2(const Point& p1, const Point& p2) {
123  return length2(p1 - p2);
124 }
125 
126 #endif
Scalar distance2(const Point &p1, const Point &p2)
Definition: Point.h:122
void set_min(Scalar &x, Scalar y)
Definition: Basic.h:52
Scalar max(Scalar x, Scalar y)
Definition: Basic.h:50
Point & operator+=(const Vector &v)
Definition: Point.h:65
Point operator-(const Point &p, const Vector &v)
Definition: Point.h:92
Point(const double p[3])
Definition: Point.h:38
Point(const float p[3])
Definition: Point.h:37
Point(Scalar x, Scalar y, Scalar z)
Definition: Point.h:39
Definition: Basic.h:58
bool operator<(const Point &p1, const Point &p2)
Definition: Point.h:100
Definition: Basic.h:58
Point & operator-=(const Vector &v)
Definition: Point.h:70
Scalar length(const Quaternion &q)
Definition: Quaternion.h:193
static Point p[4]
Definition: Convex.cpp:54
Definition: Basic.h:58
Scalar comp[3]
Definition: Tuple3.h:63
void set_max(Scalar &x, Scalar y)
Definition: Basic.h:53
Point sup(const Point &p1, const Point &p2)
Definition: Point.h:108
Scalar min(Scalar x, Scalar y)
Definition: Basic.h:49
Point inf(const Point &p1, const Point &p2)
Definition: Point.h:104
static Vector y[4]
Definition: Convex.cpp:56
Point affine(const Point &p1, const Point &p2, Scalar t)
Definition: Point.h:112
void setSup(const Point &p)
Definition: Point.h:84
Point operator+(const Point &p, const Vector &v)
Definition: Point.h:88
Point()
Definition: Point.h:36
#define Scalar
Definition: Basic.h:34
Point & operator=(const Vector &v)
Definition: Point.h:75
Definition: Vector.h:32
Scalar length2(const Quaternion &q)
Definition: Quaternion.h:192
void setInf(const Point &p)
Definition: Point.h:80
Scalar distance(const Point &p1, const Point &p2)
Definition: Point.h:118
Definition: Point.h:34