cornerstone-source 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,18 +4,18 @@
4
4
  defaults to (0, 0).
5
5
 
6
6
  point = Point()
7
-
7
+
8
8
  p.x
9
9
  # => 0
10
-
10
+
11
11
  p.y
12
12
  # => 0
13
-
13
+
14
14
  point = Point(-2, 5)
15
-
15
+
16
16
  p.x
17
17
  # => -2
18
-
18
+
19
19
  p.y
20
20
  # => 5
21
21
 
@@ -70,12 +70,12 @@
70
70
 
71
71
  point = Point(1, 1)
72
72
  pointCopy = point.copy()
73
-
73
+
74
74
  point.equal(pointCopy)
75
75
  # => true
76
-
76
+
77
77
  point == pointCopy
78
- # => false
78
+ # => false
79
79
  ###
80
80
  copy: ->
81
81
  Point(@x, @y)
@@ -86,18 +86,18 @@
86
86
  to add x and y values without a second point object.
87
87
 
88
88
  point = Point(2, 3).add(Point(3, 4))
89
-
89
+
90
90
  point.x
91
91
  # => 5
92
-
92
+
93
93
  point.y
94
94
  # => 7
95
-
95
+
96
96
  anotherPoint = Point(2, 3).add(3, 4)
97
-
97
+
98
98
  anotherPoint.x
99
99
  # => 5
100
-
100
+
101
101
  anotherPoint.y
102
102
  # => 7
103
103
 
@@ -115,27 +115,27 @@
115
115
  to add x and y values without a second point object.
116
116
 
117
117
  point = Point(2, 3)
118
-
118
+
119
119
  point.x
120
120
  # => 2
121
-
121
+
122
122
  point.y
123
123
  # => 3
124
-
124
+
125
125
  point.add$(Point(3, 4))
126
-
126
+
127
127
  point.x
128
128
  # => 5
129
-
129
+
130
130
  point.y
131
131
  # => 7
132
-
132
+
133
133
  anotherPoint = Point(2, 3)
134
134
  anotherPoint.add$(3, 4)
135
-
135
+
136
136
  anotherPoint.x
137
137
  # => 5
138
-
138
+
139
139
  anotherPoint.y
140
140
  # => 7
141
141
 
@@ -158,18 +158,18 @@
158
158
  Subtracts a point to this one and returns the new point.
159
159
 
160
160
  point = Point(1, 2).subtract(Point(2, 0))
161
-
161
+
162
162
  point.x
163
163
  # => -1
164
-
164
+
165
165
  point.y
166
166
  # => 2
167
-
167
+
168
168
  anotherPoint = Point(1, 2).subtract(2, 0)
169
-
169
+
170
170
  anotherPoint.x
171
171
  # => -1
172
-
172
+
173
173
  anotherPoint.y
174
174
  # => 2
175
175
 
@@ -185,27 +185,27 @@
185
185
  Subtracts a point to this one and returns the new point.
186
186
 
187
187
  point = Point(1, 2)
188
-
188
+
189
189
  point.x
190
190
  # => 1
191
-
191
+
192
192
  point.y
193
193
  # => 2
194
-
194
+
195
195
  point.subtract$(Point(2, 0))
196
-
196
+
197
197
  point.x
198
198
  # => -1
199
-
199
+
200
200
  point.y
201
201
  # => 2
202
-
202
+
203
203
  anotherPoint = Point(1, 2)
204
204
  anotherPoint.subtract$(2, 0)
205
-
205
+
206
206
  anotherPoint.x
207
207
  # => -1
208
-
208
+
209
209
  anotherPoint.y
210
210
  # => 2
211
211
 
@@ -228,10 +228,10 @@
228
228
  Scale this Point (Vector) by a constant amount.
229
229
 
230
230
  point = Point(5, 6).scale(2)
231
-
231
+
232
232
  point.x
233
233
  # => 10
234
-
234
+
235
235
  point.y
236
236
  # => 12
237
237
 
@@ -247,18 +247,18 @@
247
247
  Scale this Point (Vector) by a constant amount. Modifies the point in place.
248
248
 
249
249
  point = Point(5, 6)
250
-
250
+
251
251
  point.x
252
252
  # => 5
253
-
253
+
254
254
  point.y
255
255
  # => 6
256
-
256
+
257
257
  point.scale$(2)
258
-
258
+
259
259
  point.x
260
260
  # => 10
261
-
261
+
262
262
  point.y
263
263
  # => 12
264
264
 
@@ -278,20 +278,20 @@
278
278
  treats the point as though it is a vector from the origin to (x, y).
279
279
 
280
280
  point = Point(2, 3).norm()
281
-
281
+
282
282
  point.x
283
283
  # => 0.5547001962252291
284
-
285
- point.y
284
+
285
+ point.y
286
286
  # => 0.8320502943378437
287
-
287
+
288
288
  anotherPoint = Point(2, 3).norm(2)
289
-
289
+
290
290
  anotherPoint.x
291
291
  # => 1.1094003924504583
292
-
293
- anotherPoint.y
294
- # => 1.6641005886756874
292
+
293
+ anotherPoint.y
294
+ # => 1.6641005886756874
295
295
 
296
296
  @name norm
297
297
  @methodOf Point#
@@ -305,20 +305,20 @@
305
305
  treats the point as though it is a vector from the origin to (x, y). Modifies the point in place.
306
306
 
307
307
  point = Point(2, 3).norm$()
308
-
308
+
309
309
  point.x
310
310
  # => 0.5547001962252291
311
-
312
- point.y
311
+
312
+ point.y
313
313
  # => 0.8320502943378437
314
-
314
+
315
315
  anotherPoint = Point(2, 3).norm$(2)
316
-
316
+
317
317
  anotherPoint.x
318
318
  # => 1.1094003924504583
319
-
320
- anotherPoint.y
321
- # => 1.6641005886756874
319
+
320
+ anotherPoint.y
321
+ # => 1.6641005886756874
322
322
 
323
323
  @name norm$
324
324
  @methodOf Point#
@@ -334,10 +334,10 @@
334
334
  Floor the x and y values, returning a new point.
335
335
 
336
336
  point = Point(3.4, 5.8).floor()
337
-
337
+
338
338
  point.x
339
339
  # => 3
340
-
340
+
341
341
  point.y
342
342
  # => 5
343
343
 
@@ -353,10 +353,10 @@
353
353
 
354
354
  point = Point(3.4, 5.8)
355
355
  point.floor$()
356
-
356
+
357
357
  point.x
358
358
  # => 3
359
-
359
+
360
360
  point.y
361
361
  # => 5
362
362
 
@@ -376,10 +376,10 @@
376
376
  pointA = Point(2, 3)
377
377
  pointB = Point(2, 3)
378
378
  pointC = Point(4, 5)
379
-
379
+
380
380
  pointA.equal(pointB)
381
381
  # => true
382
-
382
+
383
383
  pointA.equal(pointC)
384
384
  # => false
385
385
 
@@ -395,7 +395,7 @@
395
395
  Computed the length of this point as though it were a vector from (0,0) to (x,y).
396
396
 
397
397
  point = Point(5, 7)
398
-
398
+
399
399
  point.length()
400
400
  # => 8.602325267042627
401
401
 
@@ -410,7 +410,7 @@
410
410
  Calculate the magnitude of this Point (Vector).
411
411
 
412
412
  point = Point(5, 7)
413
-
413
+
414
414
  point.magnitude()
415
415
  # => 8.602325267042627
416
416
 
@@ -425,7 +425,7 @@
425
425
  Returns the direction in radians of this point from the origin.
426
426
 
427
427
  point = Point(0, 1)
428
-
428
+
429
429
  point.direction()
430
430
  # => 1.5707963267948966 # Math.PI / 2
431
431
 
@@ -447,9 +447,9 @@
447
447
  @x * other.x + @y * other.y
448
448
 
449
449
  ###*
450
- Calculate the cross product of this point and another point (Vector).
450
+ Calculate the cross product of this point and another point (Vector).
451
451
  Usually cross products are thought of as only applying to three dimensional vectors,
452
- but z can be treated as zero. The result of this method is interpreted as the magnitude
452
+ but z can be treated as zero. The result of this method is interpreted as the magnitude
453
453
  of the vector result of the cross product between [x1, y1, 0] x [x2, y2, 0]
454
454
  perpendicular to the xy plane.
455
455
 
@@ -466,7 +466,7 @@
466
466
 
467
467
  pointA = Point(2, 3)
468
468
  pointB = Point(9, 2)
469
-
469
+
470
470
  pointA.distance(pointB)
471
471
  # => 7.0710678118654755 # Math.sqrt(50)
472
472
 
@@ -486,12 +486,26 @@
486
486
  toString: ->
487
487
  "Point(#{@x}, #{@y})"
488
488
 
489
+ # TODO: Extract as list of math methods to map onto point
490
+ abs: ->
491
+ Point
492
+ x: @x.abs()
493
+ y: @y.abs()
494
+
495
+ snap: (n) ->
496
+ Point
497
+ x: @x.snap(n)
498
+ y: @y.snap(n)
499
+
500
+ angle: ->
501
+ Math.atan2(@y, @x)
502
+
489
503
  ###*
490
504
  Compute the Euclidean distance between two points.
491
505
 
492
506
  pointA = Point(2, 3)
493
507
  pointB = Point(9, 2)
494
-
508
+
495
509
  Point.distance(pointA, pointB)
496
510
  # => 7.0710678118654755 # Math.sqrt(50)
497
511
 
@@ -507,7 +521,7 @@
507
521
  ###*
508
522
  pointA = Point(2, 3)
509
523
  pointB = Point(9, 2)
510
-
524
+
511
525
  Point.distanceSquared(pointA, pointB)
512
526
  # => 50
513
527
 
@@ -536,10 +550,10 @@
536
550
  Construct a point on the unit circle for the given angle.
537
551
 
538
552
  point = Point.fromAngle(Math.PI / 2)
539
-
553
+
540
554
  point.x
541
555
  # => 0
542
-
556
+
543
557
  point.y
544
558
  # => 1
545
559
 
@@ -558,7 +572,7 @@
558
572
 
559
573
  p1 = Point(0, 0)
560
574
  p2 = Point(7, 3)
561
-
575
+
562
576
  Point.direction(p1, p2)
563
577
  # => 0.40489178628508343
564
578
 
@@ -107,6 +107,51 @@ test "#last", ->
107
107
  equals [1, 2, 3].last(), 3
108
108
  equals [].first(), undefined
109
109
 
110
+ test "#maxima", ->
111
+ maxima = [-52, 0, 78].maxima()
112
+
113
+ maxima.each (n) ->
114
+ equals n, 78
115
+
116
+ maxima = [0, 0, 1, 0, 1, 0, 1, 0].maxima()
117
+
118
+ equals 3, maxima.length
119
+
120
+ maxima.each (n) ->
121
+ equals n, 1
122
+
123
+ test "#maximum", ->
124
+ equals [-345, 38, 8347].maximum(), 8347
125
+
126
+ test "#maximum with function", ->
127
+ equals [3, 4, 5].maximum((n) ->
128
+ n % 4
129
+ ), 3
130
+
131
+ test "#minima", ->
132
+ minima = [-52, 0, 78].minima()
133
+
134
+ minima.each (n) ->
135
+ equals n, -52
136
+
137
+ minima = [0, 0, 1, 0, 1, 0, 1, 0].minima()
138
+
139
+ equals 5, minima.length
140
+
141
+ minima.each (n) ->
142
+ equals n, 0
143
+
144
+ test "#minimum", ->
145
+ equals [-345, 38, 8347].minimum(), -345
146
+
147
+ test "#pipeline", ->
148
+ pipe = [
149
+ (x) -> x * x
150
+ (x) -> x - 10
151
+ ]
152
+
153
+ equals pipe.pipeline(5), 15
154
+
110
155
  test "#extremes", ->
111
156
  array = [-7, 1, 11, 94]
112
157
 
@@ -13,6 +13,12 @@ test "#once", ->
13
13
 
14
14
  equals score, 100
15
15
 
16
+ test ".identity", ->
17
+ I = Function.identity
18
+
19
+ [0, 1, true, false, null, undefined].each (x) ->
20
+ equals I(x), x
21
+
16
22
  test "#returning", ->
17
23
  x = 0
18
24
  sideEffectsAdd = (a) ->
@@ -40,7 +46,7 @@ asyncTest "#delay", 2, ->
40
46
  fn.delay 25, 3, "testy"
41
47
 
42
48
  asyncTest "#defer", 1, ->
43
- fn = (x) ->
49
+ fn = (x) ->
44
50
  equals x, 3
45
51
  start()
46
52