3ds Max C++ API Reference
Point2 Class Reference

#include <point2.h>

Public Member Functions

 Point2 ()=default
 
constexpr Point2 (const Point2 &)=default
 
constexpr Point2 (Point2 &&)=default
 
Point2operator= (const Point2 &)=default
 
Point2operator= (Point2 &&)=default
 
constexpr Point2 (float X, float Y)
 
constexpr Point2 (double X, double Y)
 
constexpr Point2 (int X, int Y)
 
constexpr Point2 (const IPoint2 &a)
 
constexpr Point2 (const float af[2])
 
float & operator[] (int i)
 
const float & operator[] (int i) const
 
constexpr operator float * ()
 
constexpr operator const float * () const
 
constexpr Point2 operator- () const
 
constexpr Point2 operator+ () const
 
constexpr float LengthSquared () const
 
float Length () const
 
int MaxComponent () const
 
int MinComponent () const
 
Point2 Normalize () const
 
constexpr Point2operator+= (const Point2 &a)
 Member-wise, in-place addition of this vector (x+a.x, y+a.y) More...
 
constexpr Point2operator-= (const Point2 &a)
 Member-wise, in-place subtraction of this vector (x-a.x, y-a.y) More...
 
constexpr Point2operator*= (const Point2 &a)
 Member-wise, in-place multiplication of this vector: (x*a.x, y*a.y) More...
 
Point2operator/= (const Point2 &a)
 Member-wise, in-place division of this vector: (x/a.x, y/a.y) More...
 
constexpr Point2operator+= (float f)
 
constexpr Point2operator-= (float f)
 
constexpr Point2operator*= (float f)
 
Point2operator/= (float f)
 
constexpr Point2Set (float X, float Y)
 
constexpr Point2 operator- (const Point2 &a) const
 Member-wise subtraction of two vectors: (x-a.x, y-a.y) More...
 
constexpr Point2 operator+ (const Point2 &a) const
 Member-wise addition of two vectors: (x+a.x, y+a.y) More...
 
constexpr Point2 operator* (const Point2 &a) const
 Member-wise multiplication of two vectors: (x*a.x, y*a.y) More...
 
Point2 operator/ (const Point2 &a) const
 Member-wise division of two vectors: (x/a.x, y/a.y) More...
 
constexpr float DotProd (const Point2 &a) const
 Returns the dot product of two Point2's. More...
 
constexpr float operator% (const Point2 &a) const
 Returns the dot product of two Point2's. More...
 
constexpr bool operator== (const Point2 &p) const
 
constexpr bool operator!= (const Point2 &p) const
 
bool Equals (const Point2 &p, float epsilon=1E-6f) const
 
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
 

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 is equivalent to Point2(0.0f, 0.0f);

static const Point2 XAxis;

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

static const Point2 YAxis;

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

Constructor & Destructor Documentation

◆ Point2() [1/8]

Point2 ( )
default

◆ Point2() [2/8]

constexpr Point2 ( const Point2 )
constexprdefault

◆ Point2() [3/8]

constexpr Point2 ( Point2 &&  )
constexprdefault

◆ Point2() [4/8]

constexpr Point2 ( float  X,
float  Y 
)
inlineconstexpr
Remarks
Constructor. Data members are initialized to X and Y.
50 : x(X), y(Y) {}
float y
Definition: point2.h:41
float x
Definition: point2.h:40

◆ Point2() [5/8]

constexpr Point2 ( double  X,
double  Y 
)
inlineconstexpr
Remarks
Constructor. Data members are initialized to X and Y cast as floats.
52 : x((float)X), y((float)Y) {}

◆ Point2() [6/8]

constexpr Point2 ( int  X,
int  Y 
)
inlineconstexpr
Remarks
Constructor. Data members are initialized to X and Y cast as floats.
54 : x((float)X), y((float)Y) {}

◆ Point2() [7/8]

constexpr Point2 ( const IPoint2 a)
inlineexplicitconstexpr
Remarks
Constructor. Data members are initialized to a.x and a.y.
56 : x((float)a.x), y((float)a.y) {}
int y
Definition: ipoint2.h:33
int x
Definition: ipoint2.h:32

◆ Point2() [8/8]

constexpr Point2 ( const float  af[2])
inlineconstexpr
Remarks
Constructor. Data members are initialized as x = af[0] and y = af[1].
58 : x(af[0]), y(af[1]) {}

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.
68  {
69  assert((i == 0) || (i == 1));
70  return (i == 0) ? x : y;
71  }
#define assert(expr)
Definition: assert1.h:81

◆ operator[]() [2/2]

const float& operator[] ( int  i) const
inline
73  {
74  assert((i == 0) || (i == 1));
75  return (i == 0) ? x : y;
76  }

◆ operator float *()

constexpr operator float * ( )
inlineconstexpr
Remarks
Returns the address of the Point2.x
81  {
82  return &x;
83  }

◆ operator const float *()

constexpr operator const float * ( ) const
inlineconstexpr
85  {
86  return &x;
87  }

◆ operator-() [1/2]

constexpr Point2 operator- ( ) const
inlineconstexpr
Remarks
Unary -. Negates both x and y.
92  {
93  return Point2(-x, -y);
94  }
Point2()=default

◆ operator+() [1/2]

constexpr Point2 operator+ ( ) const
inlineconstexpr
Remarks
Unary +. Returns the point unaltered.
97  {
98  return *this;
99  }

◆ LengthSquared()

constexpr float LengthSquared ( ) const
inlineconstexpr
Remarks
The 'Length' squared of the point. This is v.x*v.x+v.y*v.y.
104  {
105  return x * x + y * y;
106  }

◆ Length()

float Length ( ) const
inline
Remarks
Returns the length of the point. This is sqrt(v.x*v.x+v.y*v.y);
109  {
110  return sqrtf(LengthSquared());
111  }
constexpr float LengthSquared() const
Definition: point2.h:103

◆ MaxComponent()

int MaxComponent ( ) const
Remarks
Returns the component with the maximum abs value. 0=x, 1=y.

◆ MinComponent()

int MinComponent ( ) const
Remarks
Returns the component with the minimum abs value. 0=x, 1=y.

◆ 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+=() [1/2]

constexpr Point2& operator+= ( const Point2 a)
inlineconstexpr

Member-wise, in-place addition of this vector (x+a.x, y+a.y)

123  {
124  x += a.x;
125  y += a.y;
126  return *this;
127  }

◆ operator-=() [1/2]

constexpr Point2& operator-= ( const Point2 a)
inlineconstexpr

Member-wise, in-place subtraction of this vector (x-a.x, y-a.y)

130  {
131  x -= a.x;
132  y -= a.y;
133  return *this;
134  }

◆ operator*=() [1/2]

constexpr Point2& operator*= ( const Point2 a)
inlineconstexpr

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

138  {
139  x *= a.x;
140  y *= a.y;
141  return *this;
142  }

◆ operator/=() [1/2]

Point2& operator/= ( const Point2 a)
inline

Member-wise, in-place division of this vector: (x/a.x, y/a.y)

146  {
147  assert(a.x != 0 && a.y != 0);
148  x /= a.x;
149  y /= a.y;
150  return *this;
151  }

◆ operator+=() [2/2]

constexpr Point2& operator+= ( float  f)
inlineconstexpr
Remarks
Adds floating point value to this Point2.
155  {
156  x += f;
157  y += f;
158  return *this;
159  }

◆ operator-=() [2/2]

constexpr Point2& operator-= ( float  f)
inlineconstexpr
Remarks
Subtracts floating point value from this Point2.
163  {
164  return *this += -f;
165  }

◆ operator*=() [2/2]

constexpr Point2& operator*= ( float  f)
inlineconstexpr
Remarks
Multiplies this Point2 by a floating point value.
169  {
170  x *= f;
171  y *= f;
172  return *this;
173  }

◆ operator/=() [2/2]

Point2& operator/= ( float  f)
inline
Remarks
Divides this Point2 by a floating point value.
176  {
177  assert(f != 0.0f);
178  return (*this) *= (1.0f / f);
179  }

◆ Set()

constexpr Point2& Set ( float  X,
float  Y 
)
inlineconstexpr
Remarks
Sets the x and y coordinate and returns a reference to this Point2.
183  {
184  x = X;
185  y = Y;
186  return *this;
187  }
@ X
Using the X axis as the slice axis.
@ Y
Using the Y axis as the slice axis.

◆ operator-() [2/2]

constexpr Point2 operator- ( const Point2 a) const
inlineconstexpr

Member-wise subtraction of two vectors: (x-a.x, y-a.y)

192  {
193  return Point2(x - a.x, y - a.y);
194  }

◆ operator+() [2/2]

constexpr Point2 operator+ ( const Point2 a) const
inlineconstexpr

Member-wise addition of two vectors: (x+a.x, y+a.y)

197  {
198  return Point2(x + a.x, y + a.y);
199  }

◆ operator*()

constexpr Point2 operator* ( const Point2 a) const
inlineconstexpr

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

202  {
203  return Point2(x * a.x, y * a.y);
204  }

◆ operator/()

Point2 operator/ ( const Point2 a) const
inline

Member-wise division of two vectors: (x/a.x, y/a.y)

207  {
208  assert(a.x != 0 && a.y != 0);
209  return Point2(x / a.x, y / a.y);
210  }

◆ DotProd()

constexpr float DotProd ( const Point2 a) const
inlineconstexpr

Returns the dot product of two Point2's.

213  {
214  return x * a.x + y * a.y;
215  }

◆ operator%()

constexpr float operator% ( const Point2 a) const
inlineconstexpr

Returns the dot product of two Point2's.

218  {
219  return DotProd(a);
220  }
constexpr float DotProd(const Point2 &a) const
Returns the dot product of two Point2's.
Definition: point2.h:212

◆ operator==()

constexpr bool operator== ( const Point2 p) const
inlineconstexpr
Remarks
Equality operator. Compares two Point2's.
225  {
226  return x == p.x && y == p.y;
227  }

◆ operator!=()

constexpr bool operator!= ( const Point2 p) const
inlineconstexpr
229  {
230  return !(*this == p);
231  }

◆ Equals()

bool Equals ( const Point2 p,
float  epsilon = 1E-6f 
) const
Remarks
Returns true if the absolute difference between point components is less or equal to the given epsilon for each component

◆ 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