IceHPoint.h
Go to the documentation of this file.
1 
8 
11 // Include Guard
12 #ifndef __ICEHPOINT_H__
13 #define __ICEHPOINT_H__
14 
15  class ICEMATHS_API HPoint : public Point
16  {
17  public:
18 
22  inline_ HPoint(float _x, float _y, float _z, float _w=0.0f) : Point(_x, _y, _z), w(_w) {}
24  inline_ HPoint(const float f[4]) : Point(f), w(f[3]) {}
26  inline_ HPoint(const Point& p, float _w=0.0f) : Point(p), w(_w) {}
29 
31  inline_ HPoint& Zero() { x = y = z = w = 0.0f; return *this; }
32 
34  inline_ HPoint& Set(float _x, float _y, float _z, float _w ) { x = _x; y = _y; z = _z; w = _w; return *this; }
36  inline_ HPoint& Set(const float f[4]) { x = f[_X]; y = f[_Y]; z = f[_Z]; w = f[_W]; return *this; }
38  inline_ HPoint& Set(const HPoint& src) { x = src.x; y = src.y; z = src.z; w = src.w; return *this; }
39 
41  inline_ HPoint& Add(float _x, float _y, float _z, float _w ) { x += _x; y += _y; z += _z; w += _w; return *this; }
43  inline_ HPoint& Add(const float f[4]) { x += f[_X]; y += f[_Y]; z += f[_Z]; w += f[_W]; return *this; }
44 
46  inline_ HPoint& Sub(float _x, float _y, float _z, float _w ) { x -= _x; y -= _y; z -= _z; w -= _w; return *this; }
48  inline_ HPoint& Sub(const float f[4]) { x -= f[_X]; y -= f[_Y]; z -= f[_Z]; w -= f[_W]; return *this; }
49 
51  inline_ HPoint& Mul(float s) { x *= s; y *= s; z *= s; w *= s; return *this; }
52 
54  float Min() const { return MIN(x, MIN(y, MIN(z, w))); }
56  float Max() const { return MAX(x, MAX(y, MAX(z, w))); }
58  HPoint& Min(const HPoint& p) { x = MIN(x, p.x); y = MIN(y, p.y); z = MIN(z, p.z); w = MIN(w, p.w); return *this; }
60  HPoint& Max(const HPoint& p) { x = MAX(x, p.x); y = MAX(y, p.y); z = MAX(z, p.z); w = MAX(w, p.w); return *this; }
61 
63  inline_ float SquareMagnitude() const { return x*x + y*y + z*z + w*w; }
65  inline_ float Magnitude() const { return sqrtf(x*x + y*y + z*z + w*w); }
66 
69  {
70  float M = Magnitude();
71  if(M)
72  {
73  M = 1.0f / M;
74  x *= M;
75  y *= M;
76  z *= M;
77  w *= M;
78  }
79  return *this;
80  }
81 
82  // Arithmetic operators
84  inline_ HPoint operator-() const { return HPoint(-x, -y, -z, -w); }
85 
87  inline_ HPoint operator+(const HPoint& p) const { return HPoint(x + p.x, y + p.y, z + p.z, w + p.w); }
89  inline_ HPoint operator-(const HPoint& p) const { return HPoint(x - p.x, y - p.y, z - p.z, w - p.w); }
90 
92  inline_ HPoint operator*(const HPoint& p) const { return HPoint(x * p.x, y * p.y, z * p.z, w * p.w); }
94  inline_ HPoint operator*(float s) const { return HPoint(x * s, y * s, z * s, w * s); }
96  inline_ friend HPoint operator*(float s, const HPoint& p) { return HPoint(s * p.x, s * p.y, s * p.z, s * p.w); }
97 
99  inline_ HPoint operator/(const HPoint& p) const { return HPoint(x / p.x, y / p.y, z / p.z, w / p.w); }
101  inline_ HPoint operator/(float s) const { s = 1.0f / s; return HPoint(x * s, y * s, z * s, w * s); }
103  inline_ friend HPoint operator/(float s, const HPoint& p) { return HPoint(s / p.x, s / p.y, s / p.z, s / p.w); }
104 
106  inline_ float operator|(const HPoint& p) const { return x*p.x + y*p.y + z*p.z + w*p.w; }
107  // No cross-product in 4D
108 
110  inline_ HPoint& operator+=(const HPoint& p) { x += p.x; y += p.y; z += p.z; w += p.w; return *this; }
112  inline_ HPoint& operator+=(float s) { x += s; y += s; z += s; w += s; return *this; }
113 
115  inline_ HPoint& operator-=(const HPoint& p) { x -= p.x; y -= p.y; z -= p.z; w -= p.w; return *this; }
117  inline_ HPoint& operator-=(float s) { x -= s; y -= s; z -= s; w -= s; return *this; }
118 
120  inline_ HPoint& operator*=(const HPoint& p) { x *= p.x; y *= p.y; z *= p.z; w *= p.w; return *this; }
122  inline_ HPoint& operator*=(float s) { x*=s; y*=s; z*=s; w*=s; return *this; }
123 
125  inline_ HPoint& operator/=(const HPoint& p) { x /= p.x; y /= p.y; z /= p.z; w /= p.w; return *this; }
127  inline_ HPoint& operator/=(float s) { s = 1.0f / s; x*=s; y*=s; z*=s; w*=s; return *this; }
128 
129  // Arithmetic operators
130 
132  Point operator*(const Matrix3x3& mat) const;
134  HPoint operator*(const Matrix4x4& mat) const;
135 
136  // HPoint *= Matrix3x3 doesn't exist, the matrix is first casted to a 4x4
138  HPoint& operator*=(const Matrix4x4& mat);
139 
140  // Logical operators
141 
143  inline_ bool operator==(const HPoint& p) const { return ( (x==p.x)&&(y==p.y)&&(z==p.z)&&(w==p.w)); }
145  inline_ bool operator!=(const HPoint& p) const { return ( (x!=p.x)||(y!=p.y)||(z!=p.z)||(w!=p.w)); }
146 
147  // Cast operators
148 
150 #ifdef _MSC_VER
151  inline_ operator Point() const { return Point(x, y, z); }
152  // gcc complains that conversion to a base class will never use a type conversion operator
153 #endif
154 
155  public:
156  float w;
157  };
158 
159 #endif // __ICEHPOINT_H__
160 
inline_ HPoint(const Point &p, float _w=0.0f)
Constructor from a Point.
Definition: IceHPoint.h:26
Definition: IceAxes.h:19
inline_ float Magnitude() const
Computes magnitude.
Definition: IceHPoint.h:65
#define MAX(a, b)
Returns the max value between a and b.
Definition: IceTypes.h:147
inline_ HPoint operator*(float s) const
Operator for HPoint Scale = HPoint * float;.
Definition: IceHPoint.h:94
inline_ HPoint & operator+=(float s)
Operator for HPoint += float;.
Definition: IceHPoint.h:112
float Min() const
Returns MIN(x, y, z, w);.
Definition: IceHPoint.h:54
* x
Definition: IceUtils.h:98
inline_ friend HPoint operator/(float s, const HPoint &p)
Operator for HPoint Scale = float / HPoint;.
Definition: IceHPoint.h:103
HPoint & Min(const HPoint &p)
Sets each element to be componentwise minimum.
Definition: IceHPoint.h:58
inline_ HPoint()
Empty constructor.
Definition: IceHPoint.h:20
inline_ float Magnitude() const
Computes magnitude.
Definition: IcePoint.h:219
inline_ HPoint & operator/=(const HPoint &p)
Operator for HPoint /= HPoint;.
Definition: IceHPoint.h:125
#define MIN(a, b)
Returns the min value between a and b.
Definition: IceTypes.h:146
inline_ HPoint & operator*=(const HPoint &p)
Operator for HPoint *= HPoint;.
Definition: IceHPoint.h:120
#define inline_
inline_ HPoint operator*(const HPoint &p) const
Operator for HPoint Mul = HPoint * HPoint;.
Definition: IceHPoint.h:92
float z
Definition: IcePoint.h:524
w
Definition: IcePoint.h:25
#define ICEMATHS_API
Definition: OPC_IceHook.h:51
Definition: IceAxes.h:18
inline_ bool operator!=(const HPoint &p) const
Operator for "if(HPoint!=HPoint)".
Definition: IceHPoint.h:145
inline_ float SquareMagnitude() const
Computes square magnitude.
Definition: IceHPoint.h:63
float x
Definition: IcePoint.h:524
inline_ HPoint & Sub(float _x, float _y, float _z, float _w)
Subtract a vector.
Definition: IceHPoint.h:46
inline_ HPoint & Mul(float s)
Multiplies by a scalar.
Definition: IceHPoint.h:51
inline_ Point & operator*=(const Point &p)
Operator for Point *= Point.
Definition: IcePoint.h:443
inline_ Point operator*(const Point &p) const
Operator for Point Mul = Point * Point.
Definition: IcePoint.h:408
inline_ HPoint & Sub(const float f[4])
Subtract a vector.
Definition: IceHPoint.h:48
inline_ HPoint operator+(const HPoint &p) const
Operator for HPoint Plus = HPoint + HPoint;.
Definition: IceHPoint.h:87
inline_ HPoint & Set(float _x, float _y, float _z, float _w)
Assignment from values.
Definition: IceHPoint.h:34
inline_ HPoint operator/(const HPoint &p) const
Operator for HPoint Div = HPoint / HPoint;.
Definition: IceHPoint.h:99
inline_ HPoint operator-(const HPoint &p) const
Operator for HPoint Minus = HPoint - HPoint;.
Definition: IceHPoint.h:89
HPoint & Max(const HPoint &p)
Sets each element to be componentwise maximum.
Definition: IceHPoint.h:60
inline_ HPoint & Set(const HPoint &src)
Assignment from another h-point.
Definition: IceHPoint.h:38
inline_ HPoint & Set(const float f[4])
Assignment from array.
Definition: IceHPoint.h:36
inline_ HPoint & Add(const float f[4])
Add a vector.
Definition: IceHPoint.h:43
inline_ ~HPoint()
Destructor.
Definition: IceHPoint.h:28
inline_ HPoint & operator/=(float s)
Operator for HPoint /= float;.
Definition: IceHPoint.h:127
inline_ HPoint(const float f[4])
Constructor from array.
Definition: IceHPoint.h:24
inline_ HPoint & operator*=(float s)
Operator for HPoint *= float;.
Definition: IceHPoint.h:122
float y
Definition: IcePoint.h:524
inline_ HPoint & operator-=(const HPoint &p)
Operator for HPoint -= HPoint;.
Definition: IceHPoint.h:115
float w
Cast a HPoint to a Point. w is discarded.
Definition: IceHPoint.h:156
Definition: IceAxes.h:17
inline_ HPoint operator-() const
Operator for HPoint Negate = - HPoint;.
Definition: IceHPoint.h:84
inline_ float operator|(const HPoint &p) const
Operator for float DotProd = HPoint | HPoint;.
Definition: IceHPoint.h:106
inline_ HPoint & Zero()
Clear the point.
Definition: IceHPoint.h:31
Definition: IceAxes.h:20
inline_ HPoint & Add(float _x, float _y, float _z, float _w)
Add a vector.
Definition: IceHPoint.h:41
inline_ HPoint & operator+=(const HPoint &p)
Operator for HPoint += HPoint;.
Definition: IceHPoint.h:110
float Max() const
Returns MAX(x, y, z, w);.
Definition: IceHPoint.h:56
inline_ Point()
Empty constructor.
Definition: IcePoint.h:30
inline_ bool operator==(const HPoint &p) const
Operator for "if(HPoint==HPoint)".
Definition: IceHPoint.h:143
inline_ HPoint(float _x, float _y, float _z, float _w=0.0f)
Constructor from floats.
Definition: IceHPoint.h:22
* y
Definition: IceUtils.h:97
inline_ HPoint & operator-=(float s)
Operator for HPoint -= float;.
Definition: IceHPoint.h:117
inline_ friend HPoint operator*(float s, const HPoint &p)
Operator for HPoint Scale = float * HPoint;.
Definition: IceHPoint.h:96
inline_ HPoint & Normalize()
Normalize the vector.
Definition: IceHPoint.h:68
inline_ HPoint operator/(float s) const
Operator for HPoint Scale = HPoint / float;.
Definition: IceHPoint.h:101


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:22