DPoint2 Class Reference

#include <dpoint2.h>

Class Description

Description: This class describes a 2D point using double precision x and y coordinates.

Methods are provided to add and subtract points, multiply and divide by scalars, and element by element multiply and divide two points. All methods are implemented by the system.

+ Inheritance diagram for DPoint2:

Public Member Functions

 DPoint2 ()
 Constructor. More...
 
 DPoint2 (double X, double Y)
 Constructor. More...
 
 DPoint2 (const DPoint2 &a)
 Constructor. More...
 
 DPoint2 (const Point2 &a)
 Constructor. More...
 
 DPoint2 (const double af[2])
 Constructor. More...
 
double & operator[] (int i)
 Allows access to x and y using the subscript operator. More...
 
const double & operator[] (int i) const
 Allows access to x and y using the subscript operator. More...
 
 operator double * ()
 Conversion function. More...
 
 operator Point2 ()
 Convert DPoint2 to Point2. More...
 
DPoint2 operator- () const
 Unary - operator. More...
 
DPoint2 operator+ () const
 Unary +. More...
 
DPoint2operator= (const Point2 &a)
 Assignment operator. More...
 
DPoint2operator-= (const DPoint2 &a)
 Subtracts a DPoint2 from this DPoint2. More...
 
DPoint2operator+= (const DPoint2 &a)
 Adds a DPoint2 to this DPoint2. More...
 
DPoint2operator*= (const DPoint2 &a)
 Member-wise multiplication of two vectors: (x*x, y*y) More...
 
DPoint2operator*= (double a)
 Each element of this DPoint2 is multiplied by the specified double. More...
 
DPoint2operator/= (double a)
 Each element of this DPoint2 is divided by the specified double. More...
 
DPoint2 operator- (const DPoint2 &a) const
 Subtracts a DPoint2 from a DPoint2. More...
 
DPoint2 operator+ (const DPoint2 &a) const
 Adds a DPoint2 to a DPoint2. More...
 
DPoint2 operator* (const DPoint2 &a) const
 Member-wise multiplication of two vectors: (x*x, y*y) More...
 
double Length () const
 Returns the 'Length' of this point (vector). More...
 
double LengthSquared () const
 The 'Length' squared of this point. More...
 
DPoint2Unify ()
 In place normalize. More...
 
int MaxComponent () const
 The largest axis. More...
 
int MinComponent () const
 The smallest axis. More...
 
int operator== (const DPoint2 &p) const
 Equality operator. More...
 
int operator!= (const DPoint2 &p) const
 Equality operator. More...
 

Public Attributes

double x
 
double y
 

Static Public Attributes

static const DPoint2 Origin
 const for (0,0) More...
 
static const DPoint2 XAxis
 const for (1,0) More...
 
static const DPoint2 YAxis
 const for (0,1) More...
 

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

DPoint2 ( )
inline

Constructor.

Initializes all vector components to zero.

29 : x(0.0), y(0.0) {}
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 ( double  X,
double  Y 
)
inline

Constructor.

x and y are initialized to the values specified.

33 { x = X; y = Y; }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 ( const DPoint2 a)
inline

Constructor.

x and y are initialized to the DPoint2 specified.

Parameters
avalue used to initialize x and y components
38 { x = a.x; y = a.y; }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 ( const Point2 a)
inline

Constructor.

x and y are initialized to the Point2 specified.

Parameters
avalue used to initialize x and y components
43 { x = a.x; y = a.y; }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 ( const double  af[2])
inline

Constructor.

x and y are initialized to. af[0] and af[1] respectively.

Parameters
aftwo-element array to initialize x and y components
48 { x = af[0]; y = af[1]; }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25

Member Function Documentation

double& operator[] ( int  i)
inline

Allows access to x and y using the subscript operator.

Parameters
iindex of component to return (0 or 1)
Returns
An index of 0 will return x, 1 will return y.
55 { DbgAssert((i >= 0) && (i <= 1)); return (i == 0) ? x : y; }
#define DbgAssert(expr)
Definition: assert1.h:72
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
const double& operator[] ( int  i) const
inline

Allows access to x and y using the subscript operator.

Parameters
iindex of component to return (0 or 1)
Returns
An index of 0 will return x, 1 will return y.
60 { DbgAssert((i >= 0) && (i <= 1)); return (i == 0) ? x : y; }
#define DbgAssert(expr)
Definition: assert1.h:72
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
operator double * ( )
inline

Conversion function.

Returns the address of the DPoint2.x

Returns
a pointer to the x component.
66 { return(&x); }
double x
Definition: dpoint2.h:25
operator Point2 ( )
inline

Convert DPoint2 to Point2.

Returns
the value as a Point2
70 { return Point2(x, y); }
Definition: point2.h:43
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 operator- ( ) const
inline

Unary - operator.

Negates both x and y

Returns
the resulting DPoint2
76 { return(DPoint2(-x, -y)); }
DPoint2()
Constructor.
Definition: dpoint2.h:29
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 operator+ ( ) const
inline

Unary +.

Returns the point unaltered.

Returns
the resulting DPoint2
80 { return *this; }
DPoint2& operator= ( const Point2 a)
inline

Assignment operator.

Parameters
athe Point2 to assign to this DPoint2
Returns
the resulting DPoint2
85 { x = a.x; y = a.y; return *this; }
float x
Definition: point2.h:47
float y
Definition: point2.h:47
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 & operator-= ( const DPoint2 a)
inline

Subtracts a DPoint2 from this DPoint2.

Parameters
athe value to subtract from this DPoint2
Returns
the resulting DPoint2
233  {
234  x -= a.x; y -= a.y;
235  return *this;
236 }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 & operator+= ( const DPoint2 a)
inline

Adds a DPoint2 to this DPoint2.

Parameters
athe value to add to this DPoint2
Returns
the resulting DPoint2
238  {
239  x += a.x; y += a.y;
240  return *this;
241 }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 & operator*= ( const DPoint2 a)
inline

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

Parameters
athe multiplier
Returns
the resulting DPoint2
244 {
245  x *= rhs.x;
246  y *= rhs.y;
247  return *this;
248 }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 & operator*= ( double  a)
inline

Each element of this DPoint2 is multiplied by the specified double.

Parameters
athe multiplier
Returns
the resulting DPoint2
250  {
251  x *= f; y *= f;
252  return *this;
253 }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 & operator/= ( double  a)
inline

Each element of this DPoint2 is divided by the specified double.

Parameters
athe divisor
Returns
the resulting DPoint2
255  {
256  DbgAssert(f != 0.0);
257  double invF = 1.0 / f; // Mimic 2019 behavior
258  x *= invF; y *= invF;
259  return *this;
260 }
#define DbgAssert(expr)
Definition: assert1.h:72
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 operator- ( const DPoint2 a) const
inline

Subtracts a DPoint2 from a DPoint2.

Parameters
athe value to subtract from this DPoint2
Returns
the resulting DPoint2
262  {
263  return(DPoint2(x - b.x, y - b.y));
264 }
DPoint2()
Constructor.
Definition: dpoint2.h:29
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 operator+ ( const DPoint2 a) const
inline

Adds a DPoint2 to a DPoint2.

Parameters
athe value to add to this DPoint2
Returns
the resulting DPoint2
266  {
267  return(DPoint2(x + b.x, y + b.y));
268 }
DPoint2()
Constructor.
Definition: dpoint2.h:29
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
DPoint2 operator* ( const DPoint2 a) const
inline

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

Parameters
athe multiplier
Returns
the resulting DPoint2
270  {
271  return DPoint2(x * b.x, y * b.y);
272 }
DPoint2()
Constructor.
Definition: dpoint2.h:29
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
double Length ( ) const

Returns the 'Length' of this point (vector).

This is:

sqrt(v.x*v.x+v.y*v.y).

Returns
the length value
double LengthSquared ( ) const

The 'Length' squared of this point.

This is v.x*v.x+v.y*v.y.

Returns
the length value
DPoint2& Unify ( )

In place normalize.

Returns
the normalized value
int MaxComponent ( ) const

The largest axis.

Returns
the largest axis (0 = x, 1 = y)
int MinComponent ( ) const

The smallest axis.

Returns
the smallest axis (0 = x, 1 = y)
int operator== ( const DPoint2 p) const
inline

Equality operator.

Test for equality between two DPoint2's.

Parameters
pthe value to compare
Returns
Nonzero if the DPoint2's are equal; otherwise 0.
158  {
159  return ((p.x == x) && (p.y == y));
160  }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25
int operator!= ( const DPoint2 p) const
inline

Equality operator.

Test for nonequality between two DPoint2's.

Parameters
pthe value to compare
Returns
Nonzero if the DPoint2's are not equal; otherwise 0.
165  {
166  return ((p.x != x) || (p.y != y));
167  }
double x
Definition: dpoint2.h:25
double y
Definition: dpoint2.h:25

Member Data Documentation

double x
double y
const DPoint2 Origin
static

const for (0,0)

const DPoint2 XAxis
static

const for (1,0)

const DPoint2 YAxis
static

const for (0,1)