Kiwi.Geom.Rectangle Class
An area defined by its position, as indicated by its top-left corner (x,y) and width and height
Constructor
Kiwi.Geom.Rectangle
-
[x=0]
-
[y=0]
-
[width=0]
-
[height=0]
Parameters:
-
[x=0]
Number optionalThe x coordinate of the top-left corner of the rectangle.
-
[y=0]
Number optionalThe y coordinate of the top-left corner of the rectangle.
-
[width=0]
Number optionalwidth The width of the rectangle in pixels.
-
[height=0]
Number optionalheight The height of the rectangle in pixels.
Returns:
This rectangle object
Item Index
Methods
Methods
clone
-
[output]
Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
Parameters:
-
[output]
Kiwi.Geom.Rectangle optionalOptional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
Returns:
contains
-
x
-
y
Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
Parameters:
-
x
NumberThe x coordinate of the point to test.
-
y
NumberThe y coordinate of the point to test.
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
containsPoint
-
point
Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter.
Parameters:
-
point
Kiwi.Geom.PointThe point object being checked. Can be Kiwi.Geom.Point or any object with .x and .y values.
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
containsRect
-
rect
Determines whether the Rectangle object specified by the rect parameter is contained within this Rectangle object. A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
Parameters:
-
rect
Kiwi.Geom.RectangleThe rectangle object being checked.
Returns:
A value of true if the Rectangle object contains the specified point; otherwise false.
copyFrom
-
source
Copies all of rectangle data from the source Rectangle object into the calling Rectangle object.
Parameters:
-
source
Kiwi.Geom.RectangleThe source rectangle object to copy from
Returns:
This rectangle object
copyTo
-
[target]
Copies all the rectangle data from this Rectangle object into the destination Rectangle object. Creates a new rectangle if one was not passed.
Parameters:
-
[target]
Kiwi.Geom.Rectangle optionalThe destination rectangle object to copy in to. Creates a new rectangle if one is not passed.
Returns:
The destination rectangle object
equals
-
toCompare
Determines whether the object specified in the toCompare parameter is equal to this Rectangle object. This method compares the x, y, width, and height properties of an object against the same properties of this Rectangle object.
Parameters:
-
toCompare
Kiwi.Geom.RectangletoCompare The rectangle to compare to this Rectangle object.
Returns:
A value of true if the object has exactly the same values for the x, y, width, and height properties as this Rectangle object; otherwise false.
inflate
-
dx
-
dy
Increases the size of the Rectangle object by the specified amounts, in pixels.
The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
Parameters:
-
dx
Numberdx The amount to be added to the left side of this Rectangle.
-
dy
Numberdy The amount to be added to the bottom side of this Rectangle.
Returns:
This Rectangle object.
inflatePoint
-
point
Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter.
Parameters:
-
point
Kiwi.Geom.PointThe x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object.
Returns:
This Rectangle object.
intersection
-
toIntersect
-
[output]
If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.
Parameters:
-
toIntersect
Kiwi.Geom.RectangleThe Rectangle object to compare against to see if it intersects with this Rectangle object.
-
[output]
Kiwi.Geom.Rectangle optionalOptional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned.
Returns:
A Rectangle object that equals the area of intersection. If the rectangles do not intersect, this method returns an empty Rectangle object; that is, a rectangle with its x, y, width, and height properties set to 0.
intersects
-
toIntersect
Determines whether the object specified in the toIntersect parameter intersects with this Rectangle object. This method checks the x, y, width, and height properties of the specified Rectangle object to see if it intersects with this Rectangle object.
Parameters:
-
toIntersect
Kiwi.Geom.RectangleThe Rectangle object to compare against to see if it intersects with this Rectangle object.
Returns:
A value of true if the specified object intersects with this Rectangle object; otherwise false.
isEmpty
()
Boolean
public
Determines whether or not this Rectangle object is empty.
Returns:
A value of true if the Rectangle object's width or height is less than or equal to 0; otherwise false.
objType
()
String
public
The type of this object.
Returns:
"Rectangle"
offset
-
dx
-
dy
Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
Parameters:
-
dx
NumberMoves the x value of the Rectangle object by this amount.
-
dy
NumberMoves the y value of the Rectangle object by this amount.
Returns:
This Rectangle object.
offsetPoint
-
point
Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
Parameters:
-
point
Kiwi.Geom.PointA Point object to use to offset this Rectangle object.
Returns:
This Rectangle object.
overlap
-
rect
Checks for overlaps between this Rectangle and the given Rectangle. Returns an object with boolean values for each check.
Parameters:
-
rect
Kiwi.Geom.Rectangle
Returns:
An object containing the overlapping details between the two Rectangles
scale
-
x
-
y
-
translation
Scales this Rectangle by values passed.
Parameters:
-
x
Number -
y
Number -
translation
Kiwi.Geom.Point
Returns:
setEmpty
()
Kiwi.Geom.Rectangle
public
Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
Returns:
This rectangle object
setTo
-
x
-
y
-
width
-
height
Sets the properties of Rectangle to the specified values.
Parameters:
-
x
Numberx The x coordinate of the top-left corner of the rectangle.
-
y
Numbery The y coordinate of the top-left corner of the rectangle.
-
width
Numberwidth The width of the rectangle in pixels.
-
height
Numberheight The height of the rectangle in pixels.
Returns:
This rectangle object
top
()
Number
public
The y coordinate of the top-left corner of the rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. However it does affect the height property, whereas changing the y value does not affect the height property.
Returns:
toString
()
String
Returns a string representation of this object.
Returns:
a string representation of the instance.
union
-
toUnion
-
[output]
Adds two rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two rectangles.
Parameters:
-
toUnion
Kiwi.Geom.RectangletoUnion A Rectangle object to add to this Rectangle object.
-
[output]
Kiwi.Geom.Rectangle optionaloutput Optional Rectangle object. If given the new values will be set into this object, otherwise a new Rectangle object will be created.
Returns:
A Rectangle object that is the union of the two rectangles.
Properties
bottom
Number
public
The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
bottomRight
Kiwi.Geom.Point
public
Returns a Point containing the location of the Rectangle's bottom-right corner, determined by the values of the right and bottom properties.
center
Kiwi.Geom.Point
public
Returns a Point containing the location of the center of the Rectangle, relative to the top left edge
height
Number
public
The height of the rectangle in pixels
Default: 0
left
Number
public
The x coordinate of the top-left corner of the rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
perimeter
Number
public
The perimeter size of the Rectangle object in pixels. This is the sum of all 4 sides.
right
Number
public
The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties. However it does affect the width property.
size
Kiwi.Geom.Point
public
The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
topLeft
Kiwi.Geom.Point
public
The location of the Rectangle object's top-left corner, determined by the x and y coordinates of the point.
volume
Number
The volume of the Rectangle object in pixels, derived from width * height
width
Number
public
The width of the rectangle in pixels
Default: 0
x
Number
public
The x coordinate of the top-left corner of the rectangle
Default: 0
y
Number
public
The y coordinate of the top-left corner of the rectangle
Default: 0