deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / Geometry / Point.sc
blob1d44e8a84bb951f54063dffcf42c50774f833baf
1 Point {
2         var <>x = 0, <>y = 0;
4         *new { arg x=0, y=0;
5                 ^super.newCopyArgs(x, y);
6         }
7         @ { arg aPoint;
8                 ^Rect.fromPoints(this, aPoint)
9         }
11         set { arg argX=0, argY=0; x = argX; y = argY; }
13         asPoint { ^this }
14         asComplex { ^Complex.new(x,y) }
15         asPolar { ^Polar.new(this.rho, this.theta) }
16         asSize { ^Size(x,y) }
17         asRect { ^Rect.new(0,0,x,y) }
18         asArray { ^[this.x, this.y] }
20         == { arg aPoint;
21                 ^aPoint respondsTo: #[\x, \y] and: { x == aPoint.x and: { y == aPoint.y } }
22         }
23         hash { ^ (x.hash << 1) bitXor: y.hash }
25         performBinaryOpOnSomething { |aSelector, thing, adverb|
26                 ^thing.asPoint.perform(aSelector, this, adverb)
27         }
28         + { arg delta;
29                 var deltaPoint;
30                 deltaPoint = delta.asPoint;
31                 ^(this.x + deltaPoint.x) @ (this.y + deltaPoint.y)
32         }
33         - { arg delta;
34                 var deltaPoint;
35                 deltaPoint = delta.asPoint;
36                 ^(this.x - deltaPoint.x) @ (this.y - deltaPoint.y)
37         }
39         * { arg scale;
40                 var scalePoint;
41                 scalePoint = scale.asPoint;
42                 ^(this.x * scalePoint.x) @ (this.y * scalePoint.y)
43         }
44         / { arg scale;
45                 var scalePoint;
46                 scalePoint = scale.asPoint;
47                 ^(this.x / scalePoint.x) @ (this.y / scalePoint.y)
48         }
49         div { arg scale;
50                 var scalePoint;
51                 scalePoint = scale.asPoint;
52                 ^(this.x div: scalePoint.x) @ (this.y div: scalePoint.y)
53         }
54         translate { arg delta;
55                 ^(this.x + delta.x) @ (this.y + delta.y)
56         }
57         scale { arg scale;
58                 ^(this.x * scale.x) @ (this.y * scale.y)
59         }
60         rotate { arg angle; // in radians
61                 var sinr, cosr;
62                 sinr = angle.sin;
63                 cosr = angle.cos;
64                 ^((x * cosr) - (y * sinr)) @ ((y * cosr) + (x * sinr))
65         }
67         abs { ^x.abs @ y.abs }
69         rho { ^hypot(x, y) }
70         theta { ^atan2(y, x) }
72         dist { arg aPoint;
73                 aPoint = aPoint.asPoint;
74                 ^hypot(x - aPoint.x, y - aPoint.y)
75         }
76         transpose { ^y @ x }
78         round { arg quant;
79                 quant = quant.asPoint;
80                 ^x.round(quant.x) @ y.round(quant.y)
81         }
82         trunc { arg quant;
83                 quant = quant.asPoint;
84                 ^x.trunc(quant.x) @ y.trunc(quant.y)
85         }
87         mod {|that|
88                 var thatPoint;
89                 thatPoint = that.asPoint;
90                 ^(this.x mod: thatPoint.x) @ (this.y mod: thatPoint.y)
91         }
93         printOn { arg stream;
94                 stream << this.class.name << "( " << x << ", " << y << " )";
95         }
96         storeArgs { ^[x,y] }
100 PointArray : Point
102         *new { arg n;
103                 ^super.new(Signal.new(n), Signal.new(n))
104         }
105         add { arg point;
106                 x = x.add(point.x);
107                 y = y.add(point.y);
108         }
111 //Lines : PointArray
113 //      *new { arg n;
114 //              ^super.new(2*n)
115 //      }
118 //Polygon : PointArray
122 //ZigZag : PointArray