Rect object packs a rectangle
coordinates and some methods to manipulate them. Some of the
properties and methods of the ALPFrame external
object accept as parameters Rect objects.
Creation: Use the external.CreateMiscObject
method.
Class name: RECT
Example:
var rc = external.CreateMiscObject("RECT");
Rect objects represent the rectangles using two points - usually
called upper-left and bottom-right. In this documentation they are
often called first and second points (corners) of the
rectangle:
All the actions performed by the Rect object's methods are intended
to change its coordinates (of the both points) and usually return new
Rect object holding the result. Rect objects are accepted as
parameters by methods and properties of other objects in the ALPFrame.
Properties
left
- long integer. X coordinate of the first corner of the rectangle
right
- long integer. X coordinate of the second corner of the rectangle
top
- long integer. Y coordinate of the first point of the rectangle
bottom
- long integer. Y coordinate of the second point of the rectangle
isEmpty
- Returns true if the rectangle is empty (with overlapping first and
second corners)
first
- Point, Sets/Gets the Point
object that represents the first corner of the rectangle
second
- Point, Sets/Gets the Point
object that represents the second corner of the rectangle
Methods
Resize
variable = object.Resize( point_object )
Resizes the rectangle to the size specified by the x and y
properties of the passed point object.
Example:
var pt = external.CreateMiscObject("POINT");
pt.x = 100; pt.y = 200;
var rc1 = rc.Resize(pt);
Makes the rectangle size 100x200.
Move
variable = object.Move( point_object )
Moves the rectangle by point_object.x and point_object.y.
point_object is a previously created Point
object.
Example:
var pt = external.CreateMiscObject("POINT");
pt.x = 100; pt.y = -100;
var rc1 = rc.Move(pt);
Moves the rectangle by +100 on X axis and -100 on Y axis.
Shrink
variable = object.Shrink( point_object )
Shrinks the rectangle by point_object.x and point_object.y.
point_object is a previously created Point
object.
Example:
var pt = external.CreateMiscObject("POINT");
pt.x = 20; pt.y = 20;
var rc1 = rc.Shrink(pt);
Reduces the rectangle size by 20 on each side.
Expand
variable = object.Expand( point_object )
Expands the rectangle by point_object.x and point_object.y.
point_object is a previously created Point
object.
Example:
var pt = external.CreateMiscObject("POINT");
pt.x = 20; pt.y = 20;
var rc1 = rc.Expands(pt);
Enlarges the rectangle size by 20 on each side.
IsPointInRect
variable = object.Expand( point_object )
Checks if the point_object is in the rectangle and returns
true/false to indicate the result. point_object is a previously
created Point
object.
Example:
var pt = external.CreateMiscObject("POINT");
var rc = external.CreateMiscObject("RECT");
rc.left = 5; rc.top = 5; rc.right = 100; rc.bottom = 200;
pt.x = 20; pt.y = 20;
var boolResult = rc.IsPointInRect(pt);
The result is true - the point (20,20) is in the rectangle
(5,5,100,200).
IsEqual
variable = object.IsEqual( rect_object )
Compares the both rectangles and returns true if they are equal and
false if not.
rect_object is another Rect object.
Example:
var rc1 = external.CreateMiscObject("RECT");
var rc2 = external.CreateMiscObject("RECT");
rc1.left = 5; rc1.top = 5; rc1.right = 100; rc1.bottom = 200;
rc2.left = 10; rc2.top = 5; rc2.right = 100; rc2.bottom = 200;
var boolResult = rc1.IsEqual(rc2);
The result is false.
Intersect
variable = object.Intersect( rect_object )
Returns the new rectangle holding the intersection of the both
recangles.
rect_object is another Rect object.
Empty
object.Empty();
Empties the rectangle - makes all the coordinates 0.
Subtract
variable = object.Subtract( rect_object )
Returns the new rectangle holding the subtraction of the both
recangles.
rect_object is another Rect object.
Union
variable = object.Union( rect_object )
Returns the new rectangle holding the union of the both recangles.
rect_object is another Rect object.
|