cornerstone-source 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +20 -0
- data/Rakefile +8 -0
- data/config.rb +79 -0
- data/config.ru +4 -0
- data/cornerstone.gemspec +22 -0
- data/doc_scraper.rb +51 -0
- data/game.js +4293 -0
- data/lib/assets/javascripts/cornerstone.js +4719 -0
- data/lib/cornerstone.rb +11 -0
- data/lib/cornerstone/rails.rb +5 -0
- data/lib/cornerstone/sprockets.rb +2 -0
- data/lib/cornerstone/version.rb +3 -0
- data/manifest.json +15 -0
- data/pixie.json +12 -0
- data/source/javascripts/_cornerstone/_object_extensions.js.coffee +108 -0
- data/source/javascripts/_cornerstone/array_extensions.js.coffee +570 -0
- data/source/javascripts/_cornerstone/bindable.js.coffee +125 -0
- data/source/javascripts/_cornerstone/command_stack.js.coffee +36 -0
- data/source/javascripts/_cornerstone/core_object.js.coffee +183 -0
- data/source/javascripts/_cornerstone/function_extensions.js.coffee +60 -0
- data/source/javascripts/_cornerstone/logging.js.coffee +19 -0
- data/source/javascripts/_cornerstone/matrix.js.coffee +337 -0
- data/source/javascripts/_cornerstone/number_extensions.js.coffee +491 -0
- data/source/javascripts/_cornerstone/point.js.coffee +641 -0
- data/source/javascripts/_cornerstone/random.js.coffee +86 -0
- data/source/javascripts/_cornerstone/rectangle.js.coffee +35 -0
- data/source/javascripts/_cornerstone/string_extensions.js.coffee +232 -0
- data/source/javascripts/_cornerstone/stubs.js.coffee +1042 -0
- data/source/javascripts/_cornerstone/uuid.js +96 -0
- data/source/javascripts/_test/array_extensions.coffee +173 -0
- data/source/javascripts/_test/bindable.coffee +68 -0
- data/source/javascripts/_test/command_stack.coffee +99 -0
- data/source/javascripts/_test/core_object.coffee +95 -0
- data/source/javascripts/_test/function_extensions.coffee +50 -0
- data/source/javascripts/_test/logging.coffee +7 -0
- data/source/javascripts/_test/matrix.coffee +174 -0
- data/source/javascripts/_test/number_extensions.coffee +138 -0
- data/source/javascripts/_test/object_extensions.coffee +53 -0
- data/source/javascripts/_test/point.coffee +196 -0
- data/source/javascripts/_test/random.coffee +22 -0
- data/source/javascripts/_test/rectangle.coffee +70 -0
- data/source/javascripts/_test/string_extensions.coffee +59 -0
- data/source/javascripts/cornerstone.js.coffee +1 -0
- data/source/javascripts/cornerstone_tests.js.coffee +2 -0
- data/source/test.html.haml +13 -0
- data/vendor/javascripts/qunit.js +1275 -0
- data/vendor/stylesheets/qunit.css.sass +115 -0
- metadata +141 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
module "Function"
|
2
|
+
|
3
|
+
test "#once", ->
|
4
|
+
score = 0
|
5
|
+
|
6
|
+
addScore = ->
|
7
|
+
score += 100
|
8
|
+
|
9
|
+
onceScore = addScore.once()
|
10
|
+
|
11
|
+
100.times ->
|
12
|
+
onceScore()
|
13
|
+
|
14
|
+
equals score, 100
|
15
|
+
|
16
|
+
test "#returning", ->
|
17
|
+
x = 0
|
18
|
+
sideEffectsAdd = (a) ->
|
19
|
+
x += a
|
20
|
+
|
21
|
+
returnValue = sideEffectsAdd.returning(-1)(4)
|
22
|
+
|
23
|
+
equals x, 4
|
24
|
+
equals returnValue, -1
|
25
|
+
|
26
|
+
asyncTest "#debounce", 1, ->
|
27
|
+
fn = (-> ok true; start()).debounce(50)
|
28
|
+
|
29
|
+
# Though called multiple times the function is only triggered once
|
30
|
+
fn()
|
31
|
+
fn()
|
32
|
+
fn()
|
33
|
+
|
34
|
+
asyncTest "#delay", 2, ->
|
35
|
+
fn = (x, y) ->
|
36
|
+
equals x, 3
|
37
|
+
equals y, "testy"
|
38
|
+
start()
|
39
|
+
|
40
|
+
fn.delay 25, 3, "testy"
|
41
|
+
|
42
|
+
asyncTest "#defer", 1, ->
|
43
|
+
fn = (x) ->
|
44
|
+
equals x, 3
|
45
|
+
start()
|
46
|
+
|
47
|
+
fn.defer 3
|
48
|
+
|
49
|
+
module()
|
50
|
+
|
@@ -0,0 +1,174 @@
|
|
1
|
+
( ->
|
2
|
+
module "Matrix"
|
3
|
+
|
4
|
+
TOLERANCE = 0.00001
|
5
|
+
|
6
|
+
equalEnough = (expected, actual, tolerance, message) ->
|
7
|
+
message ||= "" + expected + " within " + tolerance + " of " + actual
|
8
|
+
ok(expected + tolerance >= actual && expected - tolerance <= actual, message)
|
9
|
+
|
10
|
+
matrixEqual = (m1, m2) ->
|
11
|
+
equalEnough(m1.a, m2.a, TOLERANCE)
|
12
|
+
equalEnough(m1.b, m2.b, TOLERANCE)
|
13
|
+
equalEnough(m1.c, m2.c, TOLERANCE)
|
14
|
+
equalEnough(m1.d, m2.d, TOLERANCE)
|
15
|
+
equalEnough(m1.tx, m2.tx, TOLERANCE)
|
16
|
+
equalEnough(m1.ty, m2.ty, TOLERANCE)
|
17
|
+
|
18
|
+
test "copy constructor", ->
|
19
|
+
matrix = Matrix(1, 0, 0, 1, 10, 12)
|
20
|
+
|
21
|
+
matrix2 = Matrix(matrix)
|
22
|
+
|
23
|
+
ok matrix != matrix2
|
24
|
+
matrixEqual(matrix2, matrix)
|
25
|
+
|
26
|
+
test "Matrix() (Identity)", ->
|
27
|
+
matrix = Matrix()
|
28
|
+
|
29
|
+
equals(matrix.a, 1, "a")
|
30
|
+
equals(matrix.b, 0, "b")
|
31
|
+
equals(matrix.c, 0, "c")
|
32
|
+
equals(matrix.d, 1, "d")
|
33
|
+
equals(matrix.tx, 0, "tx")
|
34
|
+
equals(matrix.ty, 0, "ty")
|
35
|
+
|
36
|
+
matrixEqual(matrix, Matrix.IDENTITY)
|
37
|
+
|
38
|
+
test "Empty", ->
|
39
|
+
matrix = Matrix(0, 0, 0, 0, 0, 0)
|
40
|
+
|
41
|
+
equals(matrix.a, 0, "a")
|
42
|
+
equals(matrix.b, 0, "b")
|
43
|
+
equals(matrix.c, 0, "c")
|
44
|
+
equals(matrix.d, 0, "d")
|
45
|
+
equals(matrix.tx, 0, "tx")
|
46
|
+
equals(matrix.ty, 0, "ty")
|
47
|
+
|
48
|
+
test "#copy", ->
|
49
|
+
matrix = Matrix(2, 0, 0, 2)
|
50
|
+
|
51
|
+
copyMatrix = matrix.copy()
|
52
|
+
|
53
|
+
matrixEqual copyMatrix, matrix
|
54
|
+
|
55
|
+
copyMatrix.a = 4
|
56
|
+
|
57
|
+
equals copyMatrix.a, 4
|
58
|
+
equals matrix.a, 2, "Old 'a' value is unchanged"
|
59
|
+
|
60
|
+
test ".scale", ->
|
61
|
+
matrix = Matrix.scale(2, 2)
|
62
|
+
|
63
|
+
equals(matrix.a, 2, "a")
|
64
|
+
equals(matrix.b, 0, "b")
|
65
|
+
equals(matrix.c, 0, "c")
|
66
|
+
equals(matrix.d, 2, "d")
|
67
|
+
|
68
|
+
matrix = Matrix.scale(3)
|
69
|
+
|
70
|
+
equals(matrix.a, 3, "a")
|
71
|
+
equals(matrix.b, 0, "b")
|
72
|
+
equals(matrix.c, 0, "c")
|
73
|
+
equals(matrix.d, 3, "d")
|
74
|
+
|
75
|
+
test ".scale (about a point)", ->
|
76
|
+
p = Point(5, 17)
|
77
|
+
|
78
|
+
transformedPoint = Matrix.scale(3, 7, p).transformPoint(p)
|
79
|
+
|
80
|
+
equals(transformedPoint.x, p.x, "Point should remain the same")
|
81
|
+
equals(transformedPoint.y, p.y, "Point should remain the same")
|
82
|
+
|
83
|
+
test "#scale (about a point)", ->
|
84
|
+
p = Point(3, 11)
|
85
|
+
|
86
|
+
transformedPoint = Matrix.IDENTITY.scale(3, 7, p).transformPoint(p)
|
87
|
+
|
88
|
+
equals(transformedPoint.x, p.x, "Point should remain the same")
|
89
|
+
equals(transformedPoint.y, p.y, "Point should remain the same")
|
90
|
+
|
91
|
+
test "#skew", ->
|
92
|
+
matrix = Matrix()
|
93
|
+
|
94
|
+
matrix = matrix.skew(0.125.turns, 0)
|
95
|
+
|
96
|
+
equals matrix.c, Math.tan(0.125.turns)
|
97
|
+
|
98
|
+
test ".rotation", ->
|
99
|
+
matrix = Matrix.rotation(Math.PI / 2)
|
100
|
+
|
101
|
+
equalEnough(matrix.a, 0, TOLERANCE)
|
102
|
+
equalEnough(matrix.b, 1, TOLERANCE)
|
103
|
+
equalEnough(matrix.c,-1, TOLERANCE)
|
104
|
+
equalEnough(matrix.d, 0, TOLERANCE)
|
105
|
+
|
106
|
+
test ".rotation (about a point)", ->
|
107
|
+
p = Point(11, 7)
|
108
|
+
|
109
|
+
transformedPoint = Matrix.rotation(Math.PI / 2, p).transformPoint(p)
|
110
|
+
|
111
|
+
equals transformedPoint.x, p.x, "Point should remain the same"
|
112
|
+
equals transformedPoint.y, p.y, "Point should remain the same"
|
113
|
+
|
114
|
+
test "#rotate (about a point)", ->
|
115
|
+
p = Point(8, 5);
|
116
|
+
|
117
|
+
transformedPoint = Matrix.IDENTITY.rotate(Math.PI / 2, p).transformPoint(p)
|
118
|
+
|
119
|
+
equals transformedPoint.x, p.x, "Point should remain the same"
|
120
|
+
equals transformedPoint.y, p.y, "Point should remain the same"
|
121
|
+
|
122
|
+
test "#inverse (Identity)", ->
|
123
|
+
matrix = Matrix().inverse()
|
124
|
+
|
125
|
+
equals(matrix.a, 1, "a")
|
126
|
+
equals(matrix.b, 0, "b")
|
127
|
+
equals(matrix.c, 0, "c")
|
128
|
+
equals(matrix.d, 1, "d")
|
129
|
+
equals(matrix.tx, 0, "tx")
|
130
|
+
equals(matrix.ty, 0, "ty")
|
131
|
+
|
132
|
+
test "#concat", ->
|
133
|
+
matrix = Matrix.rotation(Math.PI / 2).concat(Matrix.rotation(-Math.PI / 2))
|
134
|
+
|
135
|
+
matrixEqual(matrix, Matrix.IDENTITY)
|
136
|
+
|
137
|
+
test "#toString", ->
|
138
|
+
matrix = Matrix(0.5, 2, 0.5, -2, 3, 4.5)
|
139
|
+
matrixEqual eval(matrix.toString()), matrix
|
140
|
+
|
141
|
+
test "Maths", ->
|
142
|
+
a = Matrix(12, 3, 3, 1, 7, 9)
|
143
|
+
b = Matrix(3, 8, 3, 2, 1, 5)
|
144
|
+
|
145
|
+
c = a.concat(b)
|
146
|
+
|
147
|
+
equals(c.a, 60)
|
148
|
+
equals(c.b, 17)
|
149
|
+
equals(c.c, 42)
|
150
|
+
equals(c.d, 11)
|
151
|
+
equals(c.tx, 34)
|
152
|
+
equals(c.ty, 17)
|
153
|
+
|
154
|
+
test "Order of transformations should match manual concat", ->
|
155
|
+
tx = 10
|
156
|
+
ty = 5
|
157
|
+
theta = Math.PI/3
|
158
|
+
s = 2
|
159
|
+
|
160
|
+
m1 = Matrix().translate(tx, ty).scale(s).rotate(theta)
|
161
|
+
m2 = Matrix().concat(Matrix.translation(tx, ty)).concat(Matrix.scale(s)).concat(Matrix.rotation(theta))
|
162
|
+
|
163
|
+
matrixEqual(m1, m2)
|
164
|
+
|
165
|
+
test "IDENTITY is immutable", ->
|
166
|
+
identity = Matrix.IDENTITY
|
167
|
+
|
168
|
+
identity.a = 5
|
169
|
+
|
170
|
+
equals identity.a, 1
|
171
|
+
|
172
|
+
module undefined
|
173
|
+
)()
|
174
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
equalEnough = (expected, actual, tolerance, message) ->
|
2
|
+
message ||= "" + expected + " within " + tolerance + " of " + actual
|
3
|
+
ok(expected + tolerance >= actual && expected - tolerance <= actual, message)
|
4
|
+
|
5
|
+
module "Number"
|
6
|
+
|
7
|
+
test "#abs", ->
|
8
|
+
equals 5.abs(), 5, "(5).abs() equals 5"
|
9
|
+
equals 4.2.abs(), 4.2, "(4.2).abs() equals 4.2"
|
10
|
+
equals (-1.2).abs(), 1.2, "(-1.2).abs() equals 1.2"
|
11
|
+
equals 0.abs(), 0, "(0).abs() equals 0"
|
12
|
+
|
13
|
+
test "#ceil", ->
|
14
|
+
equals 4.9.ceil(), 5, "(4.9).floor() equals 5"
|
15
|
+
equals 4.2.ceil(), 5, "(4.2).ceil() equals 5"
|
16
|
+
equals (-1.2).ceil(), -1, "(-1.2).ceil() equals -1"
|
17
|
+
equals 3.ceil(), 3, "(3).ceil() equals 3"
|
18
|
+
|
19
|
+
test "#clamp", ->
|
20
|
+
equals 5.clamp(0, 3), 3
|
21
|
+
equals 5.clamp(-1, 0), 0
|
22
|
+
equals (-5).clamp(0, 1), 0
|
23
|
+
equals 1.clamp(0, null), 1
|
24
|
+
equals (-1).clamp(0, null), 0
|
25
|
+
equals (-10).clamp(-5, 0), -5
|
26
|
+
equals (-10).clamp(null, 0), -10
|
27
|
+
equals 50.clamp(null, 10), 10
|
28
|
+
|
29
|
+
test "#floor", ->
|
30
|
+
equals 4.9.floor(), 4, "(4.9).floor() equals 4"
|
31
|
+
equals 4.2.floor(), 4, "(4.2).floor() equals 4"
|
32
|
+
equals (-1.2).floor(), -2, "(-1.2).floor() equals -2"
|
33
|
+
equals 3.floor(), 3, "(3).floor() equals 3"
|
34
|
+
|
35
|
+
test "#round", ->
|
36
|
+
equals 4.5.round(), 5, "(4.5).round() equals 5"
|
37
|
+
equals 4.4.round(), 4, "(4.4).round() equals 4"
|
38
|
+
|
39
|
+
test "#sign", ->
|
40
|
+
equals 5.sign(), 1, "Positive number's sign is 1"
|
41
|
+
equals (-3).sign(), -1, "Negative number's sign is -1"
|
42
|
+
equals 0.sign(), 0, "Zero's sign is 0"
|
43
|
+
|
44
|
+
test "#even", ->
|
45
|
+
[0, 2, -32].each (n) ->
|
46
|
+
ok n.even(), "#{n} is even"
|
47
|
+
|
48
|
+
[1, -1, 2.2, -3.784].each (n) ->
|
49
|
+
equals n.even(), false, "#{n} is not even"
|
50
|
+
|
51
|
+
test "#odd", ->
|
52
|
+
[1, 9, -37].each (n) ->
|
53
|
+
ok n.odd(), "#{n} is odd"
|
54
|
+
|
55
|
+
[0, 32, 2.2, -1.1].each (n) ->
|
56
|
+
equals n.odd(), false, "#{n} is not odd"
|
57
|
+
|
58
|
+
test "#times", ->
|
59
|
+
n = 5
|
60
|
+
equals n.times(->), n, "returns n"
|
61
|
+
|
62
|
+
test "#times called correct amount", ->
|
63
|
+
n = 5
|
64
|
+
count = 0
|
65
|
+
|
66
|
+
n.times -> count++
|
67
|
+
|
68
|
+
equals n, count, "returns n"
|
69
|
+
|
70
|
+
test "#constrainRotation", ->
|
71
|
+
equals (Math.PI * 5).constrainRotation(), Math.PI
|
72
|
+
equals (-Math.PI * 5).constrainRotation(), -Math.PI
|
73
|
+
|
74
|
+
equals (Math.TAU/4 * 5).constrainRotation(), Math.TAU/4
|
75
|
+
equals (Math.TAU/4 * 3).constrainRotation(), -Math.TAU/4
|
76
|
+
|
77
|
+
test "#mod should have a positive result when used with a positive base and a negative number", ->
|
78
|
+
n = -3
|
79
|
+
|
80
|
+
equals n.mod(8), 5, "Should 'wrap' and be positive."
|
81
|
+
|
82
|
+
test "#primeFactors", ->
|
83
|
+
|
84
|
+
factors = 15.primeFactors()
|
85
|
+
|
86
|
+
equals factors.length, 2
|
87
|
+
equals factors[0], 3
|
88
|
+
equals factors[1], 5
|
89
|
+
equals factors.product(), 15
|
90
|
+
|
91
|
+
factors = 256.primeFactors()
|
92
|
+
|
93
|
+
equals factors.product(), 256
|
94
|
+
equals factors.length, 8
|
95
|
+
equals factors.first(), 2
|
96
|
+
equals factors.last(), 2
|
97
|
+
|
98
|
+
factors = 997.primeFactors()
|
99
|
+
|
100
|
+
equals factors.length, 1
|
101
|
+
equals factors.first(), 997
|
102
|
+
equals factors.product(), 997
|
103
|
+
|
104
|
+
equals 0.primeFactors(), undefined
|
105
|
+
|
106
|
+
factors = (-3).primeFactors()
|
107
|
+
equals factors.first(), -1
|
108
|
+
equals factors.product(), -3
|
109
|
+
|
110
|
+
test "#seconds", ->
|
111
|
+
equals 1.second, 1000
|
112
|
+
equals 3.seconds, 3000
|
113
|
+
|
114
|
+
test "#degrees", ->
|
115
|
+
equals 180.degrees, Math.PI
|
116
|
+
equals 1.degree, Math.TAU / 360
|
117
|
+
|
118
|
+
test "#rotations", ->
|
119
|
+
equals 1.rotation, Math.TAU
|
120
|
+
equals 0.5.rotations, Math.TAU / 2
|
121
|
+
|
122
|
+
test "#turns", ->
|
123
|
+
equals 1.turn, Math.TAU
|
124
|
+
equals 0.5.turns, Math.TAU / 2
|
125
|
+
|
126
|
+
test "#circularPoints", ->
|
127
|
+
points = [
|
128
|
+
Point(1, 0)
|
129
|
+
Point(0, 1)
|
130
|
+
Point(-1, 0)
|
131
|
+
Point(0, -1)
|
132
|
+
]
|
133
|
+
|
134
|
+
4.circularPoints (p, i) ->
|
135
|
+
equalEnough p.x, points[i].x, 0.001
|
136
|
+
equalEnough p.y, points[i].y, 0.001
|
137
|
+
|
138
|
+
module undefined
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module "Object"
|
2
|
+
|
3
|
+
test "isArray", ->
|
4
|
+
array = [1,2,3]
|
5
|
+
object = {
|
6
|
+
blah: "blah"
|
7
|
+
second: "another"
|
8
|
+
}
|
9
|
+
number = 5
|
10
|
+
string = "string"
|
11
|
+
|
12
|
+
ok Object.isArray(array), "an array is an array"
|
13
|
+
ok !Object.isArray(object), "an object is not an array"
|
14
|
+
ok !Object.isArray(number), "a number is not an array"
|
15
|
+
ok !Object.isArray(string), "a string is not array"
|
16
|
+
|
17
|
+
test "isString", ->
|
18
|
+
ok Object.isString("a string"), "'a string' is a string"
|
19
|
+
ok !Object.isString([1, 2, 4]), "an array is not a string"
|
20
|
+
ok !Object.isString({key: "value"}), "an object literal is not a string"
|
21
|
+
|
22
|
+
test "reverseMerge", ->
|
23
|
+
object =
|
24
|
+
test: true
|
25
|
+
b: "b"
|
26
|
+
|
27
|
+
Object.reverseMerge object,
|
28
|
+
test: false
|
29
|
+
c: "c"
|
30
|
+
|
31
|
+
ok object.test
|
32
|
+
equals object.c, "c"
|
33
|
+
|
34
|
+
test "extend", ->
|
35
|
+
object =
|
36
|
+
test: true
|
37
|
+
b: "b"
|
38
|
+
|
39
|
+
Object.extend object,
|
40
|
+
test: false
|
41
|
+
c: "c"
|
42
|
+
|
43
|
+
equals object.test, false
|
44
|
+
equals object.b, "b"
|
45
|
+
equals object.c, "c"
|
46
|
+
|
47
|
+
test "isObject", ->
|
48
|
+
object = {}
|
49
|
+
|
50
|
+
equals Object.isObject(object), true
|
51
|
+
|
52
|
+
module()
|
53
|
+
|
@@ -0,0 +1,196 @@
|
|
1
|
+
( ->
|
2
|
+
module "Point"
|
3
|
+
|
4
|
+
TOLERANCE = 0.00001
|
5
|
+
|
6
|
+
equalEnough = (expected, actual, tolerance, message) ->
|
7
|
+
message ||= "" + expected + " within " + tolerance + " of " + actual
|
8
|
+
ok(expected + tolerance >= actual && expected - tolerance <= actual, message)
|
9
|
+
|
10
|
+
test "copy constructor", ->
|
11
|
+
p = Point(3, 7)
|
12
|
+
|
13
|
+
p2 = Point(p)
|
14
|
+
|
15
|
+
equals p2.x, p.x
|
16
|
+
equals p2.y, p.y
|
17
|
+
|
18
|
+
test "#add", ->
|
19
|
+
p1 = Point(5, 6)
|
20
|
+
p2 = Point(7, 5)
|
21
|
+
|
22
|
+
result = p1.add(p2)
|
23
|
+
|
24
|
+
equals result.x, p1.x + p2.x
|
25
|
+
equals result.y, p1.y + p2.y
|
26
|
+
|
27
|
+
equals p1.x, 5
|
28
|
+
equals p1.y, 6
|
29
|
+
equals p2.x, 7
|
30
|
+
equals p2.y, 5
|
31
|
+
|
32
|
+
test "#add with two arguments", ->
|
33
|
+
point = Point(3, 7)
|
34
|
+
x = 2
|
35
|
+
y = 1
|
36
|
+
|
37
|
+
result = point.add(x, y)
|
38
|
+
|
39
|
+
equals result.x, point.x + x
|
40
|
+
equals result.y, point.y + y
|
41
|
+
|
42
|
+
x = 2
|
43
|
+
y = 0
|
44
|
+
|
45
|
+
result = point.add(x, y)
|
46
|
+
|
47
|
+
equals result.x, point.x + x
|
48
|
+
equals result.y, point.y + y
|
49
|
+
|
50
|
+
test "#add$", ->
|
51
|
+
p = Point(0, 0)
|
52
|
+
|
53
|
+
p.add$(Point(3, 5))
|
54
|
+
|
55
|
+
equals p.x, 3
|
56
|
+
equals p.y, 5
|
57
|
+
|
58
|
+
p.add$(2, 1)
|
59
|
+
|
60
|
+
equals p.x, 5
|
61
|
+
equals p.y, 6
|
62
|
+
|
63
|
+
test "#subtract", ->
|
64
|
+
p1 = Point(5, 6)
|
65
|
+
p2 = Point(7, 5)
|
66
|
+
|
67
|
+
result = p1.subtract(p2)
|
68
|
+
|
69
|
+
equals result.x, p1.x - p2.x
|
70
|
+
equals result.y, p1.y - p2.y
|
71
|
+
|
72
|
+
test "#subtract$", ->
|
73
|
+
p = Point(8, 6)
|
74
|
+
|
75
|
+
p.subtract$(3, 4)
|
76
|
+
|
77
|
+
equals p.x, 5
|
78
|
+
equals p.y, 2
|
79
|
+
|
80
|
+
test "#norm", ->
|
81
|
+
p = Point(2, 0)
|
82
|
+
|
83
|
+
normal = p.norm()
|
84
|
+
equals normal.x, 1
|
85
|
+
|
86
|
+
normal = p.norm(5)
|
87
|
+
equals normal.x, 5
|
88
|
+
|
89
|
+
p = Point(0, 0)
|
90
|
+
|
91
|
+
normal = p.norm()
|
92
|
+
equals normal.x, 0, "x value of norm of point(0,0) is 0"
|
93
|
+
equals normal.y, 0, "y value of norm of point(0,0) is 0"
|
94
|
+
|
95
|
+
test "#norm$", ->
|
96
|
+
p = Point(6, 8)
|
97
|
+
|
98
|
+
p.norm$(5)
|
99
|
+
|
100
|
+
equals p.x, 3
|
101
|
+
equals p.y, 4
|
102
|
+
|
103
|
+
test "#scale", ->
|
104
|
+
p = Point(5, 6)
|
105
|
+
scalar = 2
|
106
|
+
|
107
|
+
result = p.scale(scalar)
|
108
|
+
|
109
|
+
equals result.x, p.x * scalar
|
110
|
+
equals result.y, p.y * scalar
|
111
|
+
|
112
|
+
equals p.x, 5
|
113
|
+
equals p.y, 6
|
114
|
+
|
115
|
+
test "#scale$", ->
|
116
|
+
p = Point(0, 1)
|
117
|
+
scalar = 3
|
118
|
+
|
119
|
+
p.scale$(scalar)
|
120
|
+
|
121
|
+
equals p.x, 0
|
122
|
+
equals p.y, 3
|
123
|
+
|
124
|
+
test "#floor", ->
|
125
|
+
p1 = Point(7.2, 6.9)
|
126
|
+
|
127
|
+
ok Point(7, 6).equal(p1.floor())
|
128
|
+
|
129
|
+
test "#floor$", ->
|
130
|
+
p1 = Point(7.2, 6.9)
|
131
|
+
|
132
|
+
p1.floor$()
|
133
|
+
|
134
|
+
ok Point(7, 6).equal(p1)
|
135
|
+
|
136
|
+
test "#equal", ->
|
137
|
+
ok Point(7, 8).equal(Point(7, 8))
|
138
|
+
|
139
|
+
test "#magnitude", ->
|
140
|
+
equals Point(3, 4).magnitude(), 5
|
141
|
+
|
142
|
+
test "#length", ->
|
143
|
+
equals Point(0, 0).length(), 0
|
144
|
+
equals Point(-1, 0).length(), 1
|
145
|
+
|
146
|
+
test "#toString", ->
|
147
|
+
p = Point(7, 5)
|
148
|
+
ok eval(p.toString()).equal(p)
|
149
|
+
|
150
|
+
test "#clamp", ->
|
151
|
+
p = Point(10, 10)
|
152
|
+
p2 = p.clamp(5)
|
153
|
+
|
154
|
+
equals p2.length(), 5
|
155
|
+
|
156
|
+
test ".centroid", ->
|
157
|
+
centroid = Point.centroid(
|
158
|
+
Point(0, 0),
|
159
|
+
Point(10, 10),
|
160
|
+
Point(10, 0),
|
161
|
+
Point(0, 10)
|
162
|
+
)
|
163
|
+
|
164
|
+
equals centroid.x, 5
|
165
|
+
equals centroid.y, 5
|
166
|
+
|
167
|
+
test ".fromAngle", ->
|
168
|
+
p = Point.fromAngle(Math.TAU / 4)
|
169
|
+
|
170
|
+
equalEnough p.x, 0, TOLERANCE
|
171
|
+
equals p.y, 1
|
172
|
+
|
173
|
+
test ".random", ->
|
174
|
+
p = Point.random()
|
175
|
+
|
176
|
+
ok p
|
177
|
+
|
178
|
+
test ".interpolate", ->
|
179
|
+
p1 = Point(10, 7)
|
180
|
+
p2 = Point(-6, 29)
|
181
|
+
|
182
|
+
ok p1.equal(Point.interpolate(p1, p2, 0))
|
183
|
+
ok p2.equal(Point.interpolate(p1, p2, 1))
|
184
|
+
|
185
|
+
test "ZERO is immutable", ->
|
186
|
+
zero= Point.ZERO
|
187
|
+
|
188
|
+
zero.x = 5
|
189
|
+
zero.y = 2
|
190
|
+
|
191
|
+
equals zero.x, 0
|
192
|
+
equals zero.y, 0
|
193
|
+
|
194
|
+
module undefined
|
195
|
+
)()
|
196
|
+
|