TORCS  1.3.10
The Open Racing Car Simulator
Loading...
Searching...
No Matches
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
34class Point : public Vector {
35public:
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
49Point operator+(const Point& p, const Vector& v);
50Point operator-(const Point& p, const Vector& v);
51
52Vector operator-(const Point& p1, const Point& p2);
53
54bool operator<(const Point& p1, const Point& p2);
55
56Point inf(const Point& p1, const Point& p2);
57Point sup(const Point& p1, const Point& p2);
58
59Point affine(const Point& p1, const Point& p2, Scalar t);
60
61Scalar distance(const Point& p1, const Point& p2);
62Scalar distance2(const Point& p1, const Point& p2);
63
64
65inline Point& Point::operator+=(const Vector& v) {
66 comp[X] += v[X]; comp[Y] += v[Y]; comp[Z] += v[Z];
67 return *this;
68}
69
70inline Point& Point::operator-=(const Vector& v) {
71 comp[X] -= v[X]; comp[Y] -= v[Y]; comp[Z] -= v[Z];
72 return *this;
73}
74
75inline Point& Point::operator=(const Vector& v) {
76 comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z];
77 return *this;
78}
79
80inline 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
84inline 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
88inline 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
92inline 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
96inline 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
100inline bool operator<(const Point& p1, const Point& p2) {
101 return p1[X] < p2[X] && p1[Y] < p2[Y] && p1[Z] < p2[Z];
102}
103
104inline 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
108inline 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
112inline 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
118inline Scalar distance(const Point& p1, const Point& p2) {
119 return length(p1 - p2);
120}
121
122inline Scalar distance2(const Point& p1, const Point& p2) {
123 return length2(p1 - p2);
124}
125
126#endif
Scalar min(Scalar x, Scalar y)
Definition Basic.h:49
@ Y
Definition Basic.h:58
@ X
Definition Basic.h:58
@ Z
Definition Basic.h:58
Scalar max(Scalar x, Scalar y)
Definition Basic.h:50
#define Scalar
Definition Basic.h:34
void set_max(Scalar &x, Scalar y)
Definition Basic.h:53
void set_min(Scalar &x, Scalar y)
Definition Basic.h:52
static Point p[4]
Definition Convex.cpp:54
static Vector y[4]
Definition Convex.cpp:56
Point affine(const Point &p1, const Point &p2, Scalar t)
Definition Point.h:112
Point operator+(const Point &p, const Vector &v)
Definition Point.h:88
Scalar distance(const Point &p1, const Point &p2)
Definition Point.h:118
Point sup(const Point &p1, const Point &p2)
Definition Point.h:108
Point operator-(const Point &p, const Vector &v)
Definition Point.h:92
Point inf(const Point &p1, const Point &p2)
Definition Point.h:104
bool operator<(const Point &p1, const Point &p2)
Definition Point.h:100
Scalar distance2(const Point &p1, const Point &p2)
Definition Point.h:122
Scalar length(const Quaternion &q)
Definition Quaternion.h:193
Scalar length2(const Quaternion &q)
Definition Quaternion.h:192
Definition Point.h:34
void setInf(const Point &p)
Definition Point.h:80
Point & operator=(const Vector &v)
Definition Point.h:75
Point(const double p[3])
Definition Point.h:38
Point(Scalar x, Scalar y, Scalar z)
Definition Point.h:39
Point & operator-=(const Vector &v)
Definition Point.h:70
Point & operator+=(const Vector &v)
Definition Point.h:65
void setSup(const Point &p)
Definition Point.h:84
Point(const float p[3])
Definition Point.h:37
Point()
Definition Point.h:36
Scalar comp[3]
Definition Tuple3.h:63
Vector()
Definition Vector.h:34