API Docs for: 1.4.0
Show:

Kiwi.Geom.Rectangle Class

Module: Geom
Parent Module: Kiwi

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]
)
Kiwi.Geom.Rectangle

Parameters:

  • [x=0] Number optional

    The x coordinate of the top-left corner of the rectangle.

  • [y=0] Number optional

    The y coordinate of the top-left corner of the rectangle.

  • [width=0] Number optional

    width The width of the rectangle in pixels.

  • [height=0] Number optional

    height The height of the rectangle in pixels.

Returns:

Kiwi.Geom.Rectangle:

This rectangle object

Methods

clone

(
  • [output]
)
Kiwi.Geom.Rectangle public

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 optional

    Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.

contains

(
  • x
  • y
)
Boolean public

Determines whether the specified coordinates are contained within the region defined by this Rectangle object.

Parameters:

  • x Number

    The x coordinate of the point to test.

  • y Number

    The y coordinate of the point to test.

Returns:

Boolean:

A value of true if the Rectangle object contains the specified point; otherwise false.

containsPoint

(
  • point
)
Boolean public

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.Point

    The point object being checked. Can be Kiwi.Geom.Point or any object with .x and .y values.

Returns:

Boolean:

A value of true if the Rectangle object contains the specified point; otherwise false.

containsRect

(
  • rect
)
Boolean public

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:

Returns:

Boolean:

A value of true if the Rectangle object contains the specified point; otherwise false.

copyFrom

(
  • source
)
Kiwi.Geom.Rectangle public

Copies all of rectangle data from the source Rectangle object into the calling Rectangle object.

Parameters:

Returns:

Kiwi.Geom.Rectangle:

This rectangle object

copyTo

(
  • [target]
)
Kiwi.Geom.Rectangle public

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 optional

    The destination rectangle object to copy in to. Creates a new rectangle if one is not passed.

Returns:

Kiwi.Geom.Rectangle:

The destination rectangle object

equals

(
  • toCompare
)
Boolean public

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:

Returns:

Boolean:

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
)
Kiwi.Geom.Rectangle public

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 Number

    dx The amount to be added to the left side of this Rectangle.

  • dy Number

    dy The amount to be added to the bottom side of this Rectangle.

Returns:

Kiwi.Geom.Rectangle:

This Rectangle object.

inflatePoint

(
  • point
)
Kiwi.Geom.Rectangle public

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.Point

    The 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:

Kiwi.Geom.Rectangle:

This Rectangle object.

intersection

(
  • toIntersect
  • [output]
)
Kiwi.Geom.Rectangle public

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.Rectangle

    The Rectangle object to compare against to see if it intersects with this Rectangle object.

  • [output] Kiwi.Geom.Rectangle optional

    Optional 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:

Kiwi.Geom.Rectangle:

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
)
Boolean public

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.Rectangle

    The Rectangle object to compare against to see if it intersects with this Rectangle object.

Returns:

Boolean:

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:

Boolean:

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:

String:

"Rectangle"

offset

(
  • dx
  • dy
)
Kiwi.Geom.Rectangle public

Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.

Parameters:

  • dx Number

    Moves the x value of the Rectangle object by this amount.

  • dy Number

    Moves the y value of the Rectangle object by this amount.

Returns:

Kiwi.Geom.Rectangle:

This Rectangle object.

offsetPoint

(
  • point
)
Kiwi.Geom.Rectangle public

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.Point

    A Point object to use to offset this Rectangle object.

Returns:

Kiwi.Geom.Rectangle:

This Rectangle object.

overlap

(
  • rect
)
Object public

Checks for overlaps between this Rectangle and the given Rectangle. Returns an object with boolean values for each check.

Parameters:

Returns:

Object:

An object containing the overlapping details between the two Rectangles

scale

(
  • x
  • y
  • translation
)
Kiwi.Geom.Rectangle public

Scales this Rectangle by values passed.

Parameters:

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:

Kiwi.Geom.Rectangle:

This rectangle object

setTo

(
  • x
  • y
  • width
  • height
)
Kiwi.Geom.Rectangle public

Sets the properties of Rectangle to the specified values.

Parameters:

  • x Number

    x The x coordinate of the top-left corner of the rectangle.

  • y Number

    y The y coordinate of the top-left corner of the rectangle.

  • width Number

    width The width of the rectangle in pixels.

  • height Number

    height The height of the rectangle in pixels.

Returns:

Kiwi.Geom.Rectangle:

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:

Number:

toString

() String

Returns a string representation of this object.

Returns:

String:

a string representation of the instance.

union

(
  • toUnion
  • [output]
)
Kiwi.Geom.Rectangle public

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.Rectangle

    toUnion A Rectangle object to add to this Rectangle object.

  • [output] Kiwi.Geom.Rectangle optional

    output Optional Rectangle object. If given the new values will be set into this object, otherwise a new Rectangle object will be created.

Returns:

Kiwi.Geom.Rectangle:

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