Point

Edit on GitHub
#include <Point.h>
SReturnNameParameters
Point (int32 value = 0)
Point (int32 x, int32 y)
bool IsZero (void) const
Size ToSize (void) const
Point& operator += (const Point& point)
Point& operator -= (const Point& point)
Point operator + (const Point& point) const
Point operator - (const Point& point) const
bool operator == (const Point& point) const
bool operator != (const Point& point) const
Point operator - (void) const
int32 X
int32 Y

Description

Represents a two-dimensional point defined by X and Y with integer precision. Each component can be manipulated directly through the exposed property values. The IsZero function returns true if both X and Y are equal to zero and the ToSize function converts the point into a Size. Addition, Subtraction, and negation are performed on each component separately.

Constructors

 Point (int32 value = 0) Point (int32 x, int32 y)

Constructs a point with both components set to value or x and y.

Functions

 bool IsZero (void) const

Returns true if both components are equal to zero.

 Size ToSize (void) const

Returns a Size with Width and Height set to X and Y.

Operators

 Point& operator += (const Point& point) Point& operator -= (const Point& point)

Adds or subtracts point to or from this point and returns a reference to this point.

Point p1 ( 3, 7);
Point p2 (-1, 4);

p1 += p2; // p1 becomes (2, 11)
p1 -= p2; // p1 becomes (4,  3)

 Point operator + (const Point& point) const Point operator - (const Point& point) const

Adds or subtracts point to or from this point and returns the result in a new point.

 bool operator == (const Point& point) const bool operator != (const Point& point) const

Performs equality comparison on each component.

 Point operator - (void) const

Negates both components of this point and returns the result in a new point.

Properties

 int32 X int32 Y

Provides direct access to the X and Y components of this point.

Examples

// C++
#include <Robot.h>
ROBOT_NS_USE_ALL;

int main (void)
{
Point p1, p2 (4, 6);

p1.IsZero(); // True
p2.IsZero(); // False

// s1 becomes (4, 6)
Size s1 = p2.ToSize();

// p1 becomes (1, 2)
p1.X = 1; p1.Y = 2;

p1 += p2; // p1 becomes (5, 8)
p1 -= p2; // p1 becomes (1, 2)

// p3 becomes (3, 4)
Point p3 = p2 - p1;

p1 == p3; // False
p1 != p3; // True

// p2 becomes (-1, -2)
p2 = -p1;
return 0;
}
// Node
var robot = require ("robot-js");

var p1 = robot.Point ();
var p2 = robot.Point (4, 6);

p1.isZero(); // True
p2.isZero(); // False

// s1 becomes (4, 6)
var s1 = p2.toSize();

// p1 becomes (1, 2)
p1.x = 1; p1.y = 2;

p1 = p1.add (p2); // p1 becomes (5, 8)
p1 = p1.sub (p2); // p1 becomes (1, 2)

// p3 becomes (3, 4)
var p3 = p2.sub (p1);

p1.eq (p3); // False
p1.ne (p3); // True

// p2 becomes (-1, -2)
p2 = p1.neg();

// Point construction
p1 = robot.Point (p2);
p1 = robot.Point
({
x: 100,
y: 200
});