Point4 Class Reference

#include <point4.h>

Class Description

See also
Class Point3.

Description:
This class describes a point using float x, y, z and w coordinates. Methods are provided to add and subtract points, multiply and divide by scalars, and element by element multiply and divide two points.
Data Members:
float x, y, z, w;

The x, y, z and w components of the point.

static const Point4 Origin;

This is equivalent to Point4(0.0f, 0.0f, 0.0f, 0.0f);

static const Point4 XAxis;

This is equivalent to Point4(1.0f, 0.0f, 0.0f, 0.0f);

static const Point4 YAxis;

This is equivalent to Point4(0.0f,1.0f, 0.0f, 0.0f);

static const Point4 ZAxis;

This is equivalent to Point4(0.0f, 0.0f,1.0f, 0.0f);

static const Point4 WAxis;

This is equivalent to Point4(0.0f, 0.0f, 0.0f,1.0f);
+ Inheritance diagram for Point4:

Public Member Functions

 Point4 ()
 Initializes vector components to zero. More...
 
 Point4 (float X, float Y, float Z, float W)
 
 Point4 (double X, double Y, double Z, double W)
 
 Point4 (int X, int Y, int Z, int W)
 
 Point4 (const Point3 &a, float W=0.0f)
 
 Point4 (const Point4 &)=default
 
 Point4 (const float af[4])
 
float & operator[] (int i)
 
const float & operator[] (int i) const
 
 operator float * ()
 
Point4 operator- () const
 
Point4 operator+ () const
 
float Length () const
 
float FLength () const
 
float LengthSquared () const
 
int MaxComponent () const
 
int MinComponent () const
 
Point4 Normalize () const
 
Point4 FNormalize () const
 
Point4operator-= (const Point4 &)
 
Point4operator+= (const Point4 &)
 
Point4operator*= (float)
 
Point4operator/= (float)
 
Point4operator*= (const Point4 &)
 
Point4Set (float X, float Y, float Z, float W)
 
int operator== (const Point4 &p) const
 
int operator!= (const Point4 &p) const
 
int Equals (const Point4 &p, float epsilon=1E-6f)
 
Point4Unify ()
 
float LengthUnify ()
 
Point4 operator- (const Point4 &) const
 
Point4 operator+ (const Point4 &) const
 
Point4 operator/ (const Point4 &) const
 
Point4 operator* (const Point4 &) const
 
float operator% (const Point4 &) const
 

Public Attributes

float x
 
float y
 
float z
 
float w
 

Static Public Attributes

static const Point4 Origin
 
static const Point4 XAxis
 
static const Point4 YAxis
 
static const Point4 ZAxis
 
static const Point4 WAxis
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Constructor & Destructor Documentation

Point4 ( )
inline

Initializes vector components to zero.

48 : x(0.0f), y(0.0f), z(0.0f), w(0.0f) { }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 ( float  X,
float  Y,
float  Z,
float  W 
)
inline
Remarks
Constructor. x, y, z and w are initialized to the values specified.
50  {
51  x = X; y = Y; z = Z; w = W;
52  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 ( double  X,
double  Y,
double  Z,
double  W 
)
inline
Remarks
Constructor. x, y, z and w are initialized to the specified values (cast as floats).
54  {
55  x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
56  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 ( int  X,
int  Y,
int  Z,
int  W 
)
inline
Remarks
Constructor. x, y, z and w are initialized to the specified values (cast as floats).
58  {
59  x = (float)X; y = (float)Y; z = (float)Z; w = (float)W;
60  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 ( const Point3 a,
float  W = 0.0f 
)
inline
Remarks
Constructor. x, y, z and w are initialized to the specified Point3 and W.
62  {
63  x = a.x; y = a.y; z = a.z; w = W;
64  }
float y
Definition: point3.h:60
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point3.h:61
float x
Definition: point3.h:59
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 ( const Point4 )
default
Point4 ( const float  af[4])
inline
Remarks
Constructor. x, y, z and w are initialized to af[0], af[1], af[2] and af[3] respectively.
69  {
70  x = af[0]; y = af[1]; z = af[2]; w = af[3];
71  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45

Member Function Documentation

float& operator[] ( int  i)
inline
Remarks
Allows access to x, y, z and w using the subscript operator.
Returns
An value for i of 0 will return x, 1 will return y, 2 will return z and 3 will return w.
83  {
84  DbgAssert((i >= 0) && (i <= 3));
85  return (&x)[i];
86  }
float x
Definition: point4.h:45
#define DbgAssert(expr)
Definition: assert1.h:72
const float& operator[] ( int  i) const
inline
Remarks
Allows access to x, y, z and w using the subscript operator.
Returns
An value for i of 0 will return x, 1 will return y, 2 will return z and 3 will return w.
90  {
91  DbgAssert((i >= 0) && (i <= 3));
92  return (&x)[i];
93  }
float x
Definition: point4.h:45
#define DbgAssert(expr)
Definition: assert1.h:72
operator float * ( )
inline
Remarks
Conversion function. Returns the address of the Point4.x
97  {
98  return(&x);
99  }
float x
Definition: point4.h:45
Point4 operator- ( ) const
inline
Remarks
Unary - operator. Negates x, y, z and w.
103  {
104  return(Point4(-x,-y,-z, -w));
105  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
Point4()
Initializes vector components to zero.
Definition: point4.h:48
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 operator+ ( ) const
inline
Remarks
Unary +. Returns the Point4.
107  {
108  return *this;
109  }
float Length ( ) const
inline
208  {
209  return (float)sqrt(x*x+y*y+z*z+w*w);
210 }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
float FLength ( ) const
inline
212  {
213  return Sqrt(x*x+y*y+z*z+w*w);
214 }
float Sqrt(float arg)
Definition: gfloat.h:76
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
float LengthSquared ( ) const
inline
216  {
217  return (x*x+y*y+z*z+w*w);
218 }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
int MaxComponent ( ) const
int MinComponent ( ) const
Point4 Normalize ( ) const
Point4 FNormalize ( ) const
Point4 & operator-= ( const Point4 a)
inline
Remarks
Subtracts a Point4 from this Point4.
Returns
A Point4 that is the difference between two Point4s.
232  {
233  x -= a.x; y -= a.y; z -= a.z; w -= a.w;
234 
235  return *this;
236  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 & operator+= ( const Point4 a)
inline
Remarks
Adds a Point4 to this Point4.
Returns
A Point4 that is the sum of two Point4s.
238  {
239  x += a.x; y += a.y; z += a.z; w += a.w;
240  return *this;
241  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 & operator*= ( float  f)
inline
Remarks
Multiplies this Point4 by a floating point value.
Returns
A Point4 multiplied by a float.
243  {
244  x *= f; y *= f; z *= f; w *= f;
245 
246  return *this;
247  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 & operator/= ( float  f)
inline
Remarks
Divides this Point4 by a floating point value.
Returns
A Point4 divided by a float.
249  {
250  DbgAssert(f != 0.0f);
251  if (f==0.0f) f = .000001f;
252  float invF = 1.0f / f; // Mimic 2019 behavior
253  x *= invF; y *= invF; z *= invF; w *= invF;
254 
255  return *this;
256  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
#define DbgAssert(expr)
Definition: assert1.h:72
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 & operator*= ( const Point4 a)
inline
Remarks
Element-by-element multiplication of two Point4s:

(x*x, y*y, z*z, w*w).
Returns
A Point4 element-by-element multiplied by another Point4.
258  {
259  x *= a.x; y *= a.y; z *= a.z; w *= a.w;
260 
261  return *this;
262  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 & Set ( float  X,
float  Y,
float  Z,
float  W 
)
inline
Remarks
Sets the x, y, z and w coordinate to the values passed and returns a reference to this Point4.
Parameters:
float X

The new x value.

float Y

The new y value.

float Z

The new z value.

float W

The new w value.
Returns
A reference to this Point4.
264  {
265  x = X;
266  y = Y;
267  z = Z;
268  w = W;
269 
270  return *this;
271  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
int operator== ( const Point4 p) const
inline
Remarks
Equality operator. Test for equality between two Point4's.
Returns
Nonzero if the Point4's are equal; otherwise 0.
154  {
155  return ((p.x==x)&&(p.y==y)&&(p.z==z)&&(p.w==w));
156  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
int operator!= ( const Point4 p) const
inline
157  {
158  return ((p.x!=x)||(p.y!=y)||(p.z!=z)||(p.w!=w));
159  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
int Equals ( const Point4 p,
float  epsilon = 1E-6f 
)
inline
Remarks
Compares this Point4 and the specified one to see if the x, y, z and w values are within plus or minus the specified tolerance.
Parameters:
const Point4& p

The point to compare.

float epsilon = 1E-6f

The tolerance to use in the comparison.
Returns
Nonzero if the points are 'equal'; otherwise zero.
Operators:
320  {
321  return (fabs(p.x - x) <= epsilon && fabs(p.y - y) <= epsilon
322  && fabs(p.z - z) <= epsilon && fabs(p.w - w) <= epsilon);
323  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4& Unify ( )
float LengthUnify ( )
Point4 operator- ( const Point4 b) const
inline
Remarks
Subtracts a Point4 from a Point4.
Returns
A Point4 that is the difference between two Point4s.
273  {
274  return(Point4(x-b.x,y-b.y,z-b.z, w-b.w));
275  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
Point4()
Initializes vector components to zero.
Definition: point4.h:48
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 operator+ ( const Point4 b) const
inline
Remarks
Adds a Point4 to a Point4.
Returns
A Point4 that is the sum of two Point4s.
277  {
278  return(Point4(x+b.x,y+b.y,z+b.z, w+b.w));
279  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
Point4()
Initializes vector components to zero.
Definition: point4.h:48
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 operator/ ( const Point4 b) const
inline
Remarks
Divides a Point4 by a Point4 element by element.
Returns
A Point4 resulting from dividing a Point4 by a Point4 element by element.
281  {
282  assert(b.x != 0.0f && b.y != 0.0f && b.z != 0.0f && b.w != 0.0f);
283  return Point4(x/b.x,y/b.y,z/b.z,w/b.w);
284  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
Point4()
Initializes vector components to zero.
Definition: point4.h:48
#define assert(expr)
Definition: assert1.h:71
float z
Definition: point4.h:45
float w
Definition: point4.h:45
Point4 operator* ( const Point4 b) const
inline
Remarks
Multiplies a Point4 by a Point4 element by element.

(x*x, y*y, z*z, w*w).
Returns
A Point4 resulting from the multiplication of a Point4 and a Point4.
286  {
287  return Point4(x*b.x, y*b.y, z*b.z,w*b.w);
288  }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
Point4()
Initializes vector components to zero.
Definition: point4.h:48
float z
Definition: point4.h:45
float w
Definition: point4.h:45
float operator% ( const Point4 b) const
inline
316  {
317  return (x*b.x + y*b.y + z*b.z + w*b.w);
318 }
float y
Definition: point4.h:45
float x
Definition: point4.h:45
float z
Definition: point4.h:45
float w
Definition: point4.h:45

Member Data Documentation

float x
float y
float z
float w
const Point4 Origin
static
const Point4 XAxis
static
const Point4 YAxis
static
const Point4 ZAxis
static
const Point4 WAxis
static