torcs - 1.2.2

src/modules/simu/simuv2/SOLID-2.0/include/3D/Point.h

Go to the documentation of this file.
00001 /*
00002   3D - C++ Class Library for 3D Transformations
00003   Copyright (C) 1996-1998  Gino van den Bergen
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public
00016   License along with this library; if not, write to the Free
00017   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019   Please send remarks, questions and bug reports to gino@win.tue.nl,
00020   or write to:
00021                   Gino van den Bergen
00022                   Department of Mathematics and Computing Science
00023                   Eindhoven University of Technology
00024                   P.O. Box 513, 5600 MB Eindhoven, The Netherlands
00025 */
00026 
00027 #ifndef _POINT_H_
00028 #define _POINT_H_
00029 
00030 #include <algorithm>
00031 
00032 #include "Vector.h"
00033 
00034 class Point : public Vector {
00035 public:
00036   Point() {}
00037   Point(const float p[3]) : Vector(p) {} 
00038   Point(const double p[3]) : Vector(p) {}
00039   Point(Scalar x, Scalar y, Scalar z) : Vector(x, y, z) {}
00040 
00041   Point& operator+=(const Vector& v);
00042   Point& operator-=(const Vector& v);
00043   Point& operator=(const Vector& v);
00044 
00045   void setInf(const Point& p);
00046   void setSup(const Point& p);
00047 };
00048 
00049 Point operator+(const Point& p, const Vector& v);
00050 Point operator-(const Point& p, const Vector& v);
00051 
00052 Vector operator-(const Point& p1, const Point& p2);
00053 
00054 bool operator<(const Point& p1, const Point& p2);
00055 
00056 Point inf(const Point& p1, const Point& p2);
00057 Point sup(const Point& p1, const Point& p2);
00058 
00059 Point affine(const Point& p1, const Point& p2, Scalar t);
00060 
00061 Scalar distance(const Point& p1, const Point& p2);
00062 Scalar distance2(const Point& p1, const Point& p2);
00063 
00064 
00065 inline Point& Point::operator+=(const Vector& v) {
00066   comp[X] += v[X]; comp[Y] += v[Y]; comp[Z] += v[Z];
00067   return *this;
00068 }
00069 
00070 inline Point& Point::operator-=(const Vector& v) {
00071   comp[X] -= v[X]; comp[Y] -= v[Y]; comp[Z] -= v[Z];
00072   return *this;
00073 }
00074 
00075 inline Point& Point::operator=(const Vector& v) {
00076   comp[X] = v[X]; comp[Y] = v[Y]; comp[Z] = v[Z];
00077   return *this;
00078 }
00079 
00080 inline void Point::setInf(const Point& p) {
00081   set_min(comp[X], p[X]); set_min(comp[Y], p[Y]); set_min(comp[Z], p[Z]);
00082 }
00083 
00084 inline void Point::setSup(const Point& p) {
00085   set_max(comp[X], p[X]); set_max(comp[Y], p[Y]); set_max(comp[Z], p[Z]);
00086 }
00087 
00088 inline Point operator+(const Point& p, const Vector& v) {
00089   return Point(p[X] + v[X], p[Y] + v[Y], p[Z] + v[Z]);
00090 }
00091 
00092 inline Point operator-(const Point& p, const Vector& v) {
00093   return Point(p[X] - v[X], p[Y] - v[Y], p[Z] - v[Z]);
00094 }
00095 
00096 inline Vector operator-(const Point& p1, const Point& p2) {
00097   return Vector(p1[X] - p2[X], p1[Y] - p2[Y], p1[Z] - p2[Z]);
00098 }
00099 
00100 inline bool operator<(const Point& p1, const Point& p2) {
00101   return p1[X] < p2[X] && p1[Y] < p2[Y] && p1[Z] < p2[Z];
00102 }
00103 
00104 inline Point inf(const Point& p1, const Point& p2) { 
00105   return Point(min(p1[X], p2[X]), min(p1[Y], p2[Y]), min(p1[Z], p2[Z]));
00106 }
00107 
00108 inline Point sup(const Point& p1, const Point& p2) { 
00109   return Point(max(p1[X], p2[X]), max(p1[Y], p2[Y]), max(p1[Z], p2[Z]));
00110 }
00111 
00112 inline Point affine(const Point& p1, const Point& p2, Scalar t) {
00113   return Point(p1[X] + (p2[X] - p1[X]) * t,
00114                p1[Y] + (p2[Y] - p1[Y]) * t,
00115                p1[Z] + (p2[Z] - p1[Z]) * t);
00116 }
00117 
00118 inline Scalar distance(const Point& p1, const Point& p2) { 
00119   return length(p1 - p2); 
00120 }
00121 
00122 inline Scalar distance2(const Point& p1, const Point& p2) { 
00123   return length2(p1 - p2); 
00124 }
00125 
00126 #endif

Generated at Thu Feb 26 21:52:30 2004 for torcs by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-1999
TORCS © Eric Espié 1999, 2002.