Size
Edit on GitHubS | Return | Name | Parameters |
---|---|---|---|
Size | (int32 value = 0) | ||
Size | (int32 w, int32 h) | ||
bool | IsZero | (void) const | |
bool | IsEmpty | (void) const | |
Point | ToPoint | (void) const | |
Size& | operator += | (const Size& size) | |
Size& | operator -= | (const Size& size) | |
Size | operator + | (const Size& size) const | |
Size | operator - | (const Size& size) const | |
bool | operator == | (const Size& size) const | |
bool | operator != | (const Size& size) const | |
int32 | W | ||
int32 | H |
Description
Represents the size of a two-dimensional object defined by W and H with integer precision. Each component can be manipulated directly through the exposed property values. The IsZero function returns true if both Width and Height are equal to zero while the IsEmpty function returns true if either Width or Height are equal to zero. The ToPoint function converts the size into a Point. Addition and Subtraction are performed on each component separately.
Constructors
Size | (int32 value = 0) |
Size | (int32 w, int32 h) |
Constructs a size with both components set to value or w and h.
Functions
bool | IsZero | (void) const |
Returns true if both components are equal to zero.
bool | IsEmpty | (void) const |
Returns true if either components are equal to zero.
Point | ToPoint | (void) const |
Returns a Point with X and Y set to Width and Height.
Operators
Size& | operator += | (const Size& size) |
Size& | operator -= | (const Size& size) |
Adds or subtracts size to or from this size and returns a reference to this size.
Size s1 ( 3, 7);
Size s2 (-1, 4);
s1 += s2; // s1 becomes (2, 11)
s1 -= s2; // s1 becomes (4, 3)
Size | operator + | (const Size& size) const |
Size | operator - | (const Size& size) const |
Adds or subtracts size to or from this size and returns the result in a new size.
bool | operator == | (const Size& size) const |
bool | operator != | (const Size& size) const |
Performs equality comparison on each component.
Properties
int32 | W | |
int32 | H |
Provides direct access to the Width and Height components of this size.
Examples
// C++
#include <Robot.h>
ROBOT_NS_USE_ALL;
int main (void)
{
Size s1, s2 (4, 6);
s1.IsZero (); // True
s2.IsZero (); // False
s1.IsEmpty(); // True
s2.IsEmpty(); // False
// p1 becomes (4, 6)
Point p1 = s2.ToPoint();
// s1 becomes (1, 2)
s1.W = 1; s1.H = 2;
s1 += s2; // s1 becomes (5, 8)
s1 -= s2; // s1 becomes (1, 2)
// s3 becomes (3, 4)
Size s3 = s2 - s1;
s1 == s3; // False
s1 != s3; // True
return 0;
}
// Node
var robot = require ("robot-js");
var s1 = robot.Size ();
var s2 = robot.Size (4, 6);
s1.isZero (); // True
s2.isZero (); // False
s1.isEmpty(); // True
s2.isEmpty(); // False
// p1 becomes (4, 6)
var p1 = s2.toPoint();
// s1 becomes (1, 2)
s1.w = 1; s1.h = 2;
s1 = s1.add (s2); // s1 becomes (5, 8)
s1 = s1.sub (s2); // s1 becomes (1, 2)
// s3 becomes (3, 4)
var s3 = s2.sub (s1);
s1.eq (s3); // False
s1.ne (s3); // True
// Size construction
s1 = robot.Size (s2);
s1 = robot.Size
({
w: 100,
h: 200
});