3ds Max C++ API Reference
Point2 Class Reference

#include <point2.h>

+ Inheritance diagram for Point2:

Public Member Functions

 Point2 ()=default
 Initializes vector components to zero. More...
 
 Point2 (const Point2 &)=default
 
 Point2 (Point2 &&)=default
 
Point2operator= (const Point2 &)=default
 
Point2operator= (Point2 &&)=default
 
 Point2 (float X, float Y)
 
 Point2 (double X, double Y)
 
 Point2 (int X, int Y)
 
 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 = 0.f
 
float y = 0.f
 

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...
 

Detailed 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

Constructor & Destructor Documentation

◆ Point2() [1/8]

Point2 ( )
default

Initializes vector components to zero.

◆ Point2() [2/8]

Point2 ( const Point2 )
default

◆ Point2() [3/8]

Point2 ( Point2 &&  )
default

◆ Point2() [4/8]

Point2 ( float  X,
float  Y 
)
inline
Remarks
Constructor. Data members are initialized to X and Y.
61  {
62  x = X;
63  y = Y;
64  }
float y
Definition: point2.h:49
float x
Definition: point2.h:48

◆ Point2() [5/8]

Point2 ( double  X,
double  Y 
)
inline
Remarks
Constructor. Data members are initialized to X and Y cast as floats.
67  {
68  x = (float)X;
69  y = (float)Y;
70  }

◆ Point2() [6/8]

Point2 ( int  X,
int  Y 
)
inline
Remarks
Constructor. Data members are initialized to X and Y cast as floats.
73  {
74  x = (float)X;
75  y = (float)Y;
76  }

◆ Point2() [7/8]

Point2 ( const IPoint2 a)
inlineexplicit
Remarks
Constructor. Data members are initialized to a.x and a.y.
79  {
80  x = float(a.x);
81  y = float(a.y);
82  }
int y
Definition: ipoint2.h:38
int x
Definition: ipoint2.h:37

◆ Point2() [8/8]

Point2 ( const float  af[2])
inline
Remarks
Constructor. Data members are initialized as x = af[0] and y = af[1].
85  {
86  x = af[0];
87  y = af[1];
88  }

Member Function Documentation

◆ operator=() [1/2]

Point2& operator= ( const Point2 )
default

◆ operator=() [2/2]

Point2& operator= ( Point2 &&  )
default

◆ operator[]() [1/2]

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.
98  {
99  DbgAssert((i == 0) || (i == 1));
100  return (&x)[i];
101  }
#define DbgAssert(expr)
Definition: assert1.h:82

◆ operator[]() [2/2]

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.
105  {
106  DbgAssert((i == 0) || (i == 1));
107  return (&x)[i];
108  }

◆ operator float *()

operator float * ( )
inline
Remarks
Returns the address of the Point2.x
113  {
114  return (&x);
115  }

◆ operator-() [1/2]

Point2 operator- ( ) const
inline
Remarks
Unary -. Negates both x and y.
Returns
A Point2 with -x, -y.
121  {
122  return (Point2(-x, -y));
123  }
Point2()=default
Initializes vector components to zero.

◆ operator+() [1/2]

Point2 operator+ ( ) const
inline
Remarks
Unary +. Returns the point unaltered.
Returns
Returns the Point2 unaltered.
127  {
128  return *this;
129  }

◆ Length()

float Length ( ) const
inline
Remarks
Returns the length of the point. This is sqrt(v.x*v.x+v.y*v.y);
252 {
253  return (float)sqrt(x * x + y * y);
254 }

◆ MaxComponent()

int MaxComponent ( ) const
Remarks
This method returns the component with the maximum absolute value.
Returns
0 for X, 1 for Y, 2 for Z.

◆ MinComponent()

int MinComponent ( ) const
Remarks
This method returns the component with the minimum absolute value.
Returns
0 for X, 1 for Y, 2 for Z.

◆ Normalize()

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).

◆ operator-=()

Point2 & operator-= ( const Point2 a)
inline
Remarks
Subtracts a Point2 from this Point2.
Returns
A Point2 that is the difference between two Point2s.
264 {
265  x -= a.x;
266  y -= a.y;
267  return *this;
268 }

◆ operator+=()

Point2 & operator+= ( const Point2 a)
inline
Remarks
Adds a Point2 to this Point2.
Returns
A Point2 that is the sum of two Point2's.
271 {
272  x += a.x;
273  y += a.y;
274  return *this;
275 }

◆ operator*=() [1/2]

Point2 & operator*= ( const Point2 rhs)
inline

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

278 {
279  x *= rhs.x;
280  y *= rhs.y;
281  return *this;
282 }

◆ operator*=() [2/2]

Point2 & operator*= ( float  f)
inline
Remarks
Multiplies this Point2 by a floating point value.
Returns
A Point2 multiplied by a float.
285 {
286  x *= f;
287  y *= f;
288  return *this;
289 }

◆ operator/=()

Point2 & operator/= ( float  f)
inline
Remarks
Divides this Point2 by a floating point value.
Returns
A Point2 divided by a float.
292 {
293  DbgAssert(f != 0.0f);
294  float invF = 1.0f / f; // Mimic 2019 behavior
295  x *= invF;
296  y *= invF;
297  return *this;
298 }

◆ Set()

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.
301 {
302  x = X;
303  y = Y;
304  return *this;
305 }

◆ operator-() [2/2]

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.
308 {
309  return (Point2(x - b.x, y - b.y));
310 }

◆ operator+() [2/2]

Point2 operator+ ( const Point2 b) const
inline
Remarks
Adds a Point2 to a Point2.
Returns
The sum of two Point2's.
313 {
314  return (Point2(x + b.x, y + b.y));
315 }

◆ DotProd()

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.
318 {
319  return (x * b.x + y * b.y);
320 }

◆ operator*()

Point2 operator* ( const Point2 b) const
inline

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

323 {
324  return Point2(x * b.x, y * b.y);
325 }

◆ operator==()

int operator== ( const Point2 p) const
inline
Remarks
Equality operator. Compares two Point2's.
Returns
Nonzero if the Point2's are equal; otherwise 0.
188  {
189  return (x == p.x && y == p.y);
190  }

◆ operator!=()

int operator!= ( const Point2 p) const
inline
192  {
193  return ((x != p.x) || (y != p.y));
194  }

◆ Equals()

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.

◆ Unify()

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.

◆ LengthUnify()

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

◆ x

float x = 0.f

◆ y

float y = 0.f

◆ Origin

const Point2 Origin
static

◆ XAxis

const Point2 XAxis
static

◆ YAxis

const Point2 YAxis
static