File: Point.sc

package info (click to toggle)
supercollider 1%3A3.6.6~repack-2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 23,792 kB
  • ctags: 25,269
  • sloc: cpp: 177,129; lisp: 63,421; ansic: 11,297; python: 1,787; perl: 766; yacc: 311; sh: 286; lex: 181; ruby: 173; makefile: 168; xml: 13
file content (125 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download
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
125
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;
		^(this.x + deltaPoint.x) @ (this.y + deltaPoint.y)
	}
	- { arg delta;
		var deltaPoint;
		deltaPoint = delta.asPoint;
		^(this.x - deltaPoint.x) @ (this.y - deltaPoint.y)
	}

	* { arg scale;
		var scalePoint;
		scalePoint = scale.asPoint;
		^(this.x * scalePoint.x) @ (this.y * scalePoint.y)
	}
	/ { arg scale;
		var scalePoint;
		scalePoint = scale.asPoint;
		^(this.x / scalePoint.x) @ (this.y / scalePoint.y)
	}
	div { arg scale;
		var scalePoint;
		scalePoint = scale.asPoint;
		^(this.x div: scalePoint.x) @ (this.y div: scalePoint.y)
	}
	translate { arg delta;
		^(this.x + delta.x) @ (this.y + delta.y)
	}
	scale { arg scale;
		^(this.x * scale.x) @ (this.y * scale.y)
	}
	rotate { arg angle; // in radians
		var sinr, cosr;
		sinr = angle.sin;
		cosr = angle.cos;
		^((x * cosr) - (y * sinr)) @ ((y * cosr) + (x * sinr))
	}

	abs { ^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 { ^y @ x }

	round { arg quant;
		quant = quant.asPoint;
		^x.round(quant.x) @ y.round(quant.y)
	}
	trunc { arg quant;
		quant = quant.asPoint;
		^x.trunc(quant.x) @ y.trunc(quant.y)
	}

	mod {|that|
		var thatPoint;
		thatPoint = that.asPoint;
		^(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
//{
//}