RatioUtil

Kind of class:public class
Package:org.casalib.util
Inherits from:none
Version:04/03/09
Author:Aaron Clinger
Classpath:org.casalib.util.RatioUtil
File last modified:Friday, 03 April 2009, 11:59:28
Provides utility functions for ratio scaling.

Summary


Class methods
  • widthToHeight (size:Rectangle) : Number
    • Determines the ratio of width to height.
  • heightToWidth (size:Rectangle) : Number
    • Determines the ratio of height to width.
  • scale (size:Rectangle, amount:Percent, snapToPixel:Boolean = true) : Rectangle
    • Scales an area's width and height while preserving aspect ratio.
  • scaleWidth (size:Rectangle, height:Number, snapToPixel:Boolean = true) : Rectangle
    • Scales the width of an area while preserving aspect ratio.
  • scaleHeight (size:Rectangle, width:Number, snapToPixel:Boolean = true) : Rectangle
    • Scales the height of an area while preserving aspect ratio.
  • scaleToFill (size:Rectangle, bounds:Rectangle, snapToPixel:Boolean = true) : Rectangle
    • Resizes an area to fill the bounding area while preserving aspect ratio.
  • scaleToFit (size:Rectangle, bounds:Rectangle, snapToPixel:Boolean = true) : Rectangle
    • Resizes an area to the maximum size of a bounding area without exceeding while preserving aspect ratio.

Class methods

heightToWidth

public static function heightToWidth (
size:Rectangle) : Number

Determines the ratio of height to width.
Parameters:
size:
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.

scale

public static function scale (
size:Rectangle, amount:Percent, snapToPixel:Boolean = true) : Rectangle

Scales an area's width and height while preserving aspect ratio.
Parameters:
size :
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.
amount :
The amount you wish to scale by.
snapToPixel:
Force the scale to whole pixels true, or allow sub-pixels false.

scaleHeight

public static function scaleHeight (
size:Rectangle, width:Number, snapToPixel:Boolean = true) : Rectangle

Scales the height of an area while preserving aspect ratio.
Parameters:
size :
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.
width :
The new width of the area.
snapToPixel:
Force the scale to whole pixels true, or allow sub-pixels false.

scaleToFill

public static function scaleToFill (
size:Rectangle, bounds:Rectangle, snapToPixel:Boolean = true) : Rectangle

Resizes an area to fill the bounding area while preserving aspect ratio.
Parameters:
size :
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.
bounds :
The area to fill. The Rectangle's x and y values are ignored.
snapToPixel:
Force the scale to whole pixels true, or allow sub-pixels false.

scaleToFit

public static function scaleToFit (
size:Rectangle, bounds:Rectangle, snapToPixel:Boolean = true) : Rectangle

Resizes an area to the maximum size of a bounding area without exceeding while preserving aspect ratio.
Parameters:
size :
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.
bounds :
The area the rectangle needs to fit within. The Rectangle's x and y values are ignored.
snapToPixel:
Force the scale to whole pixels true, or allow sub-pixels false.

scaleWidth

public static function scaleWidth (
size:Rectangle, height:Number, snapToPixel:Boolean = true) : Rectangle

Scales the width of an area while preserving aspect ratio.
Parameters:
size :
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.
height :
The new height of the area.
snapToPixel:
Force the scale to whole pixels true, or allow sub-pixels false.

widthToHeight

public static function widthToHeight (
size:Rectangle) : Number

Determines the ratio of width to height.
Parameters:
size:
The area's width and height expressed as a Rectangle. The Rectangle's x and y values are ignored.