1
4
5
9 class org.aswing.geom.Point{
10
11 public var x:Number = 0;
12 public var y:Number = 0;
13
14
21 public function Point(x, y:Number){
22 setLocation(x, y);
23 }
24
25
30 public function setLocation(x, y:Number):Void{
31 if(x instanceof Point){
32 this.x = x.x;
33 this.y = x.y;
34 }else{
35 if(x == undefined) x = 0;
36 if(y == undefined) y = 0;
37 this.x = x;
38 this.y = y;
39 }
40 }
41
42 public function move(dx:Number, dy:Number):Point{
43 x += dx;
44 y += dy;
45 return this;
46 }
47
48 public function moveRadians(angle:Number, distance:Number):Point{
49 x += Math.cos(angle)*distance;
50 y += Math.sin(angle)*distance;
51 return this;
52 }
53
54 public function nextPoint(angle:Number, distance:Number):Point{
55 return new Point(x+Math.cos(angle)*distance, y+Math.sin(angle)*distance);
56 }
57
58
65 public function distanceSq(tx, ty:Number):Number{
66 var xx:Number;
67 var yy:Number;
68 if(tx instanceof Point){
69 xx = tx.x;
70 yy = tx.y;
71 }else{
72 xx = tx;
73 yy = ty;
74 }
75 return ((x-xx)*(x-xx)+(y-yy)*(y-yy));
76 }
77
78
85 public function distance(tx, ty:Number):Number{
86 return Math.sqrt(distanceSq(tx, ty));
87 }
88
89 public function equals(o:Object):Boolean{
90 var p:Point = Point(o);
91 return x===p.x && y===p.y;
92 }
93
94 public function toString():String{
95 return "Point("+x+","+y+")";
96 }
97 }
98