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