Packagestarling.utils
Classpublic class RectangleUtil
InheritanceRectangleUtil Inheritance Object

A utility class containing methods related to the Rectangle class.



Public Methods
 MethodDefined By
  
fit(rectangle:Rectangle, into:Rectangle, scaleMode:String = showAll, pixelPerfect:Boolean = false, resultRect:Rectangle = null):Rectangle
[static] Calculates a rectangle with the same aspect ratio as the given 'rectangle', centered within 'into'.
RectangleUtil
  
getBounds(rectangle:Rectangle, transformationMatrix:Matrix, resultRect:Rectangle = null):Rectangle
[static] Calculates the bounds of a rectangle after transforming it by a matrix.
RectangleUtil
  
intersect(rect1:Rectangle, rect2:Rectangle, resultRect:Rectangle = null):Rectangle
[static] Calculates the intersection between two Rectangles.
RectangleUtil
  
normalize(rect:Rectangle):void
[static] If the rectangle contains negative values for width or height, all coordinates are adjusted so that the rectangle describes the same region with positive values.
RectangleUtil
Method Detail
fit()method
public static function fit(rectangle:Rectangle, into:Rectangle, scaleMode:String = showAll, pixelPerfect:Boolean = false, resultRect:Rectangle = null):Rectangle

Calculates a rectangle with the same aspect ratio as the given 'rectangle', centered within 'into'.

This method is useful for calculating the optimal viewPort for a certain display size. You can use different scale modes to specify how the result should be calculated; furthermore, you can avoid pixel alignment errors by only allowing whole-number multipliers/divisors (e.g. 3, 2, 1, 1/2, 1/3).

Parameters

rectangle:Rectangle
 
into:Rectangle
 
scaleMode:String (default = showAll)
 
pixelPerfect:Boolean (default = false)
 
resultRect:Rectangle (default = null)

Returns
Rectangle

See also

getBounds()method 
public static function getBounds(rectangle:Rectangle, transformationMatrix:Matrix, resultRect:Rectangle = null):Rectangle

Calculates the bounds of a rectangle after transforming it by a matrix. If you pass a 'resultRect', the result will be stored in this rectangle instead of creating a new object.

Parameters

rectangle:Rectangle
 
transformationMatrix:Matrix
 
resultRect:Rectangle (default = null)

Returns
Rectangle
intersect()method 
public static function intersect(rect1:Rectangle, rect2:Rectangle, resultRect:Rectangle = null):Rectangle

Calculates the intersection between two Rectangles. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.

Parameters

rect1:Rectangle
 
rect2:Rectangle
 
resultRect:Rectangle (default = null)

Returns
Rectangle
normalize()method 
public static function normalize(rect:Rectangle):void

If the rectangle contains negative values for width or height, all coordinates are adjusted so that the rectangle describes the same region with positive values.

Parameters

rect:Rectangle