1
4
5 import org.aswing.geom.Point;
6 import org.aswing.geom.Rectangle;
7
8
12 class org.aswing.geom.Dimension{
13 public var width:Number;
14 public var height:Number;
15
16
21 public function Dimension(width, height:Number){
22 setSize(width, height);
23 }
24
25
30 public function setSize(width, height:Number):Void{
31 if(width instanceof Dimension){
32 this.width = width.width;
33 this.height = width.height;
34 }else{
35 if(width == undefined) width = 0;
36 if(height == undefined) height = 0;
37 this.width = width;
38 this.height = height;
39 }
40 }
41
42
46 public function increaseSize(s:Dimension):Dimension{
47 width += s.width;
48 height += s.height;
49 return this;
50 }
51
52
56 public function decreaseSize(s:Dimension):Dimension{
57 width -= s.width;
58 height -= s.height;
59 return this;
60 }
61
62
68 public function change(d:Number, h:Number):Dimension{
69 width += d;
70 h = (h==undefined ? d:h);
71 height += h;
72 return this;
73 }
74
75
81 public function changedSize(d:Number, h:Number):Dimension{
82 var s:Dimension = new Dimension(width, height);
83 return s.change(d, h);
84 }
85
86
93 public function getBounds(x, y:Number):Rectangle{
94 var p:Point = new Point(x, y);
95 var r:Rectangle = new Rectangle();
96 r.setLocation(p);
97 r.setSize(width, height);
98 return r;
99 }
100
101 public function equals(o:Object):Boolean{
102 var d:Dimension = Dimension(o);
103 return width===d.width && height===d.height;
104 }
105
106 public function toString():String{
107 return "Dimension("+width+","+height+")";
108 }
109 }
110