All pastes #595149 Raw Edit

Untitled

public text v1 · immutable
#595149 ·published 2007-06-29 10:35 UTC
rendered paste body
dynamic class classes.MovieClipAnimations.Point
{
	var x:Number = null;
	var y:Number = null;
	
	static function random(w:Number, h:Number):Point
	{
		return new Point(Math.round(Math.random()*w), Math.round(Math.random()*h));
	}
	
	function Point(x:Number, y:Number)
	{
		this.x = x;
		this.y = y;
	}
	
	function translate(p:Point, m:Number)
	{
		if (typeof m == "undefined") m = 1;
		this.x += m * p.x;
		this.y += m * p.y;
	}
	
	function negate():Point
	{
		return new Point(-this.x, -this.y);
	}
	
	function distance(p:Point):Number
	{
		return Math.sqrt(Math.pow(this.x - p.x, 2) + Math.pow(this.y - p.y, 2));
	}
	
	function midpoint(p:Point):Point
	{
		return new Point((this.x + p.x)/2, (this.y + p.y)/2);
	}
	
	function equals(p:Point):Boolean
	{
		return(Boolean(x == p.x && y == p.y));
	}
	
	function getPointFromSlop(degrees:Number, distance:Number):Point
	{
		var angle:Number = degrees * (Math.PI / 180);
		return(new Point(distance * Math.cos(angle) + this.x, -(distance * Math.sin(angle)) + this.y));
	}
	
	function toString()
	{
		return "Point[x=" + Math.round(this.x) + ",y=" + Math.round(this.y) + "]";
	}
}