Point2 Class Reference

#include <point2.h>

Class Description

See also
Class IPoint2.

Description:
This class describes a 2D point using float x and y coordinates. Methods are provided to add and subtract points, multiply and divide by scalars, normalize and compute the dot product of two Point2s. All methods are implemented by the system.
Data Members:
float x,y;

The x and y components of the point.

static const Point2 Origin;

This data member is available in release 3.0 and later only.

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

static const Point2 XAxis;

This data member is available in release 3.0 and later only.

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

static const Point2 YAxis;

This data member is available in release 3.0 and later only.

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

Public Member Functions

 Point2 ()
 Initializes vector components to zero. More...
 
 Point2 (float X, float Y)
 
 Point2 (double X, double Y)
 
 Point2 (int X, int Y)
 
 Point2 (const Point2 &a)
 
 Point2 (const IPoint2 &a)
 
 Point2 (const float af[2])
 
float & operator[] (int i)
 
const float operator[] (int i) const
 
 operator float * ()
 
Point2 operator- () const
 
Point2 operator+ () const
 
float Length () const
 
int MaxComponent () const
 
int MinComponent () const
 
Point2 Normalize () const
 
Point2operator-= (const Point2 &)
 
Point2operator+= (const Point2 &)
 
Point2operator*= (const Point2 &)
 Member-wise, in-place multiplication of this vector: (x*x, y*y) More...
 
Point2operator*= (float)
 
Point2operator/= (float)
 
Point2Set (float X, float Y)
 
Point2 operator- (const Point2 &) const
 
Point2 operator+ (const Point2 &) const
 
float DotProd (const Point2 &) const
 
Point2 operator* (const Point2 &) const
 Member-wise multiplication of two vectors: (x*x, y*y) More...
 
int operator== (const Point2 &p) const
 
int operator!= (const Point2 &p) const
 
int Equals (const Point2 &p, float epsilon=1E-6f)
 
Point2Unify ()
 
float LengthUnify ()
 

Public Attributes

float x
 
float y
 

Static Public Attributes

static const Point2 Origin
 
static const Point2 XAxis
 
static const Point2 YAxis
 

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

Point2 ( )
inline

Initializes vector components to zero.

50 : x(0.0f), y(0.0f) {}
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 ( float  X,
float  Y 
)
inline
Remarks
Constructor. Data members are initialized to X and Y.
52  {
53  x = X; y = Y;
54  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 ( double  X,
double  Y 
)
inline
Remarks
Constructor. Data members are initialized to X and Y cast as floats.
56  {
57  x = (float)X; y = (float)Y;
58  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 ( int  X,
int  Y 
)
inline
Remarks
Constructor. Data members are initialized to X and Y cast as floats.
60  {
61  x = (float)X; y = (float)Y;
62  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 ( const Point2 a)
inline
Remarks
Constructor. Data members are initialized to a.x and a.y.
64  {
65  x = a.x; y = a.y;
66  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 ( const IPoint2 a)
inlineexplicit
Remarks
Constructor. Data members are initialized to a.x and a.y.
68  {
69  x = float(a.x); y = float(a.y);
70  }
int y
Definition: ipoint2.h:36
float x
Definition: point2.h:47
float y
Definition: point2.h:47
int x
Definition: ipoint2.h:36
Point2 ( const float  af[2])
inline
Remarks
Constructor. Data members are initialized as x = af[0] and y = af[1].
72  {
73  x = af[0]; y = af[1];
74  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47

Member Function Documentation

float& operator[] ( int  i)
inline
Remarks
Allows access to x, y using the subscript operator.
Returns
A value for i of 0 will return x, 1 will return y.
83  {
84  DbgAssert((i == 0) || (i == 1));
85  return (&x)[i];
86  }
float x
Definition: point2.h:47
#define DbgAssert(expr)
Definition: assert1.h:72
const float operator[] ( int  i) const
inline
Remarks
Allows access to x, y using the subscript operator.
Returns
A value for i of 0 will return x, 1 will return y.
89  {
90  DbgAssert((i == 0) || (i == 1));
91  return (&x)[i];
92  }
float x
Definition: point2.h:47
#define DbgAssert(expr)
Definition: assert1.h:72
operator float * ( )
inline
Remarks
Returns the address of the Point2.x
96  {
97  return(&x);
98  }
float x
Definition: point2.h:47
Point2 operator- ( ) const
inline
Remarks
Unary -. Negates both x and y.
Returns
A Point2 with -x, -y.
103  {
104  return(Point2(-x,-y));
105  }
float x
Definition: point2.h:47
Point2()
Initializes vector components to zero.
Definition: point2.h:50
float y
Definition: point2.h:47
Point2 operator+ ( ) const
inline
Remarks
Unary +. Returns the point unaltered.
Returns
Returns the Point2 unaltered.
108  {
109  return *this;
110  }
float Length ( ) const
inline
Remarks
Returns the length of the point. This is sqrt(v.x*v.x+v.y*v.y);
224  {
225  return (float)sqrt(x*x+y*y);
226  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
int MaxComponent ( ) const
Remarks
This method returns the component with the maximum absolute value.
Returns
0 for X, 1 for Y, 2 for Z.
int MinComponent ( ) const
Remarks
This method returns the component with the minimum absolute value.
Returns
0 for X, 1 for Y, 2 for Z.
Point2 Normalize ( ) const
Remarks
This method returns a normalized version of this Point2. This method is more accurate than *this/Length() (internal computations are done in double precision).
Point2 & operator-= ( const Point2 a)
inline
Remarks
Subtracts a Point2 from this Point2.
Returns
A Point2 that is the difference between two Point2s.
234  {
235  x -= a.x; y -= a.y;
236  return *this;
237  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 & operator+= ( const Point2 a)
inline
Remarks
Adds a Point2 to this Point2.
Returns
A Point2 that is the sum of two Point2's.
239  {
240  x += a.x; y += a.y;
241  return *this;
242  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 & operator*= ( const Point2 rhs)
inline

Member-wise, in-place multiplication of this vector: (x*x, y*y)

245 {
246  x *= rhs.x;
247  y *= rhs.y;
248  return *this;
249 }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 & operator*= ( float  f)
inline
Remarks
Multiplies this Point2 by a floating point value.
Returns
A Point2 multiplied by a float.
251  {
252  x *= f; y *= f;
253  return *this;
254  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 & operator/= ( float  f)
inline
Remarks
Divides this Point2 by a floating point value.
Returns
A Point2 divided by a float.
256  {
257  DbgAssert(f != 0.0f);
258  float invF = 1.0f / f; // Mimic 2019 behavior
259  x *= invF; y *= invF;
260  return *this;
261  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
#define DbgAssert(expr)
Definition: assert1.h:72
Point2 & Set ( float  X,
float  Y 
)
inline
Remarks
Sets the x and y coordinate to the values passed and returns a reference to this Point2.
Parameters:
float X

The new x value.

float Y

The new y value.
Returns
A reference to this Point2.
263  {
264  x = X; y = Y;
265  return *this;
266  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 operator- ( const Point2 b) const
inline
Remarks
Subtracts a Point2 from a Point2.
Returns
A Point2 that is the difference between two Point2's.
268  {
269  return(Point2(x-b.x,y-b.y));
270  }
float x
Definition: point2.h:47
Point2()
Initializes vector components to zero.
Definition: point2.h:50
float y
Definition: point2.h:47
Point2 operator+ ( const Point2 b) const
inline
Remarks
Adds a Point2 to a Point2.
Returns
The sum of two Point2's.
272  {
273  return(Point2(x+b.x,y+b.y));
274  }
float x
Definition: point2.h:47
Point2()
Initializes vector components to zero.
Definition: point2.h:50
float y
Definition: point2.h:47
float DotProd ( const Point2 b) const
inline
Remarks
Returns the dot product of two Point2's. This is the sum of both x values multiplied together and both y values multiplied together.
276  {
277  return(x*b.x+y*b.y);
278  }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
Point2 operator* ( const Point2 b) const
inline

Member-wise multiplication of two vectors: (x*x, y*y)

280  {
281  return Point2(x * b.x, y * b.y);
282  }
float x
Definition: point2.h:47
Point2()
Initializes vector components to zero.
Definition: point2.h:50
float y
Definition: point2.h:47
int operator== ( const Point2 p) const
inline
Remarks
Equality operator. Compares two Point2's.
Returns
Nonzero if the Point2's are equal; otherwise 0.
168 { return (x == p.x && y == p.y); }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
int operator!= ( const Point2 p) const
inline
169 { return ( (x != p.x) || (y != p.y) ); }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
int Equals ( const Point2 p,
float  epsilon = 1E-6f 
)
Remarks
Compares this Point2 and the specified one to see if the x and y values are within plus or minus the specified tolerance.
Parameters:
const Point2& 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.
Point2& Unify ( )
Remarks
This method is used to unify (or normalize) this Point2 (in place) and return the result. Internal computations are done in double precision.
float LengthUnify ( )
Remarks
This method is used to unify (or normalize) this Point2 (in place) and return the previous length. Internal computations are done in double precision.

Member Data Documentation

float x
float y
const Point2 Origin
static
const Point2 XAxis
static
const Point2 YAxis
static