Packagecom.rubenswieringa.geom
Classpublic class Geom

All-static class providing functionality for making basic geometric calculations.



Public Methods
 MethodDefined by
  
degrees(radians:Number):Number
[static] Takes a value and transforms it from degrees into radians.
Geom
  
getAngle(point1:Point, point2:Point):Number
[static] Calculates angle (in radians) between two Points.
Geom
  
getNearest(area:Array, point:Point):int
[static] Returns the Array index of the Point that is the nearest to a given coordinate.
Geom
  
getPointFromAngle(point:Point, angle:Number, radius:Number):Point
[static] Calculates the position of Point #2, which is positioned on a certain amount of pixels (radius parameter) from Point #1 (point parameter) at a certain angle (angle parameter).
Geom
  
getRectIntersections(line:Line, rect:Rectangle, includeNull:Boolean = false):Array
[static] Returns an Array of Points indicating where a Line intersects with a Rectangle.
Geom
  
isPointInCorner(rect:Rectangle, point:Point, corner:String, triangular:Boolean = true):Boolean
[static] Indicates whether or not a Point is in a certain corner of a Rectangle.
Geom
  
radians(degrees:Number):Number
[static] Takes a value and transforms it from radians into degrees.
Geom
  
star(radius:Number, center:Point, rotation:Number = 0, points:uint = 5):Array
[static] Returns the coordinates of a star shape.
Geom
Public Constants
 ConstantDefined by
  BL : String = "bottomleft"
[static] String representation for bottom-left.
Geom
  BOTTOM : String = "bottom"
[static] String representation for bottom.
Geom
  BR : String = "bottomright"
[static] String representation for bottom-right.
Geom
  LEFT : String = "left"
[static] String representation for left.
Geom
  RIGHT : String = "right"
[static] String representation for right.
Geom
  TL : String = "topleft"
[static] String representation for top-left.
Geom
  TOP : String = "top"
[static] String representation for top.
Geom
  TR : String = "topright"
[static] String representation for top-right.
Geom
Method detail
degrees()method
public static function degrees(radians:Number):Number

Takes a value and transforms it from degrees into radians.

Parameters
radians:Number — An angle in radians.

Returns
Number — The angle in degrees.

See also

getAngle()method 
public static function getAngle(point1:Point, point2:Point):Number

Calculates angle (in radians) between two Points.

Parameters
point1:Point — Point
 
point2:Point — Point

Returns
Number — Number
getNearest()method 
public static function getNearest(area:Array, point:Point):int

Returns the Array index of the Point that is the nearest to a given coordinate.

Parameters
area:Array — An Array consisting of Points.
 
point:Point — Point for which to look up the nearest coordinate.

Returns
int — Index of the nearest Point. Returns -1 if no Point instance was found in the provided Array.
getPointFromAngle()method 
public static function getPointFromAngle(point:Point, angle:Number, radius:Number):Point

Calculates the position of Point #2, which is positioned on a certain amount of pixels (radius parameter) from Point #1 (point parameter) at a certain angle (angle parameter).

Parameters
point:Point — Point #1.
 
angle:Number — The angle (in radians) that Point #2 makes with Point #1.
 
radius:Number — The distances between Point #1 and Point #2.

Returns
Point — Point #2.
getRectIntersections()method 
public static function getRectIntersections(line:Line, rect:Rectangle, includeNull:Boolean = false):Array

Returns an Array of Points indicating where a Line intersects with a Rectangle. This method loops through all sides (Lines) of a Rectangle and stores intersections in the returned Array. Note that instead of looking up (for instance) the bottom intersection by using 2 as an index value om the returned Array, you can also use the BOTTOM constant of the SuperRectangle class. Needless to say, the same goes for the TOP, RIGHT, and LEFT constants of the SuperRectangle class.

Parameters
line:Line — A Line instance.
 
rect:Rectangle — A Rectangle instance.
 
includeNull:Boolean (default = false) — When set to true non-intersections values (when the getHVLineIntersection method returns null) are also inserted into the returned Array. This might come in handy when you want to find out where an intersection from the Array occured, the first value in the Array (0) is actually the returned intersection with the top side of the Rectangle, the second (1) is the intersection with the right side of the Rectangle, and so forth. This parameter defaults to false.

Returns
Array — Array

See also

isPointInCorner()method 
public static function isPointInCorner(rect:Rectangle, point:Point, corner:String, triangular:Boolean = true):Boolean

Indicates whether or not a Point is in a certain corner of a Rectangle.

Parameters
rect:Rectangle — Rectangle who's area to inspect.
 
point:Point — Point of which to find out whether or not it is in the specified corner of rect.
 
corner:String — Either Geom.TL, Geom.TR, Geom.BR, or Geom.BL.
 
triangular:Boolean (default = true) — If true, the Rectangle is imaginary split in half diagonally before the calculations are conducted. If false, the method will use Rectangle corners instead of triangular ones.

Returns
Boolean — true if point is in the specified corner of rect.

See also

radians()method 
public static function radians(degrees:Number):Number

Takes a value and transforms it from radians into degrees.

Parameters
degrees:Number — An angle in degrees.

Returns
Number — The angle in radians.

See also

star()method 
public static function star(radius:Number, center:Point, rotation:Number = 0, points:uint = 5):Array

Returns the coordinates of a star shape.

Parameters
radius:Number — The radius of the outer corners of the star.
 
center:Point — Center of the star.
 
rotation:Number (default = 0) — Rotation (radians) of the star.
 
points:uint (default = 5) — Amount of points (outer corners) that the star has. Defaults to 5.

Returns
Array
Constant detail
BLconstant
public static const BL:String = "bottomleft"

String representation for bottom-left.

BOTTOMconstant 
public static const BOTTOM:String = "bottom"

String representation for bottom.

BRconstant 
public static const BR:String = "bottomright"

String representation for bottom-right.

LEFTconstant 
public static const LEFT:String = "left"

String representation for left.

RIGHTconstant 
public static const RIGHT:String = "right"

String representation for right.

TLconstant 
public static const TL:String = "topleft"

String representation for top-left.

TOPconstant 
public static const TOP:String = "top"

String representation for top.

TRconstant 
public static const TR:String = "topright"

String representation for top-right.