Class IPoint2
See Also: Class Point2.
class IPoint2
Description:
This class describes a 2D point using int 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 IPoint2s. All methods are implemented by the system.
Data Members:
public:
int x,y;
Methods:
Prototype:
IPoint2()
Remarks:
Constructor.
Prototype:
IPoint2(int X, int Y)
Remarks:
Constructor. Data members are initialized to X and Y.
Prototype:
IPoint2(const IPoint2& a)
Remarks:
Constructor. Data members are initialized to a.x and a.y.
Prototype:
IPoint2(int af[2])
Remarks:
Constructor. Data members are initialized as x = af[0] and y = af[1].
Prototype:
int DotProd(const IPoint2&) const;
Remarks:
Returns the dot product of two IPoint2's. This is the sum of both x values multiplied together and both y values multiplied together.
Operators:
Prototype:
int& operator[](int i)
const int& operator[](int i) const
Remarks:
Allows access to x, y using the subscript operator.
Return Value:
An index of 0 will return x, 1 will return y.
Prototype:
operator int*()
Remarks:
Returns the address of the IPoint2.x.
Prototype:
IPoint2 operator-() const
Remarks:
Unary -. Negates both x and y.
Prototype:
IPoint2 operator+() const
Remarks:
Unary +. Returns the Ipoint2 unaltered.
Prototype:
IPoint2& operator-=(const IPoint2&);
Remarks:
Subtracts a IPoint2 from this IPoint2.
Prototype:
IPoint2& operator+=(const IPoint2&);
Remarks:
Adds a IPoint2 to this IPoint2.
Prototype:
IPoint2& operator*=(int);
Remarks:
Multiplies this IPoint2 by an integer value.
Prototype:
IPoint2& operator/=(int);
Remarks:
Divides this IPoint2 by an integer value.
Prototype:
IPoint2 operator-(const IPoint2&) const;
Remarks:
Subtracts a IPoint2 from a IPoint2.
Prototype:
IPoint2 operator+(const IPoint2&) const;
Remarks:
Adds a IPoint2 to a IPoint2.
Prototype:
int operator*(const IPoint2&) const;
Remarks:
Returns the dot product of two IPoint2's. This is the sum of both x values multiplied together and both y values multiplied together.
Prototype:
int operator==(const IPoint2& p) const
Remarks:
Equality operator. Compare two IPoint2's.
Return Value:
Nonzero if the IPoint2's are equal; otherwise 0.
The following functions are not members of class IPoint2 but are available for use:
Function:
int Length(const IPoint2& v);
Remarks:
Returns the length of the IPoint2, ie:
sqrt(v.x*v.x+v.y*v.y);
Function:
IPoint2 Normalize(const IPoint2&);
Remarks:
Returns a unit vector. This is an IPoint2 with each component divided by the point Length().
Prototype:
IPoint2 operator*(int, const IPoint2&);
IPoint2 operator*(const IPoint2&, int);
Remarks:
Each returns an IPoint2 multiplied by a scalar.
Prototype:
IPoint2 operator/(const IPoint2&, int);
Remarks:
Returns an IPoint2 whose x and y members are divided by a scalar.
Prototype:
ostream &operator<<(ostream&, const IPoint2&);
Remarks:
Formats the IPoint2 for output as in
(x, y).
Prototype:
inline int MaxComponent(const IPoint2& p)
Remarks:
Returns the component with the minimum abs value. 0=x, 1=y.
Prototype:
inline int MinComponent(const IPoint2& p)
Remarks:
Returns the component with the minimum abs value. 0=x, 1=y.