cornerstone-source 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/Gemfile +1 -2
  2. data/Rakefile +0 -6
  3. data/cornerstone-source.gemspec +5 -11
  4. data/lib/cornerstone-source/sprockets.rb +1 -1
  5. data/lib/cornerstone-source/version.rb +1 -1
  6. data/source/{javascripts/_cornerstone/_object_extensions.js.coffee → _object_extensions.js.coffee} +0 -0
  7. data/source/{javascripts/_cornerstone/array_extensions.js.coffee → array_extensions.js.coffee} +28 -26
  8. data/source/{javascripts/_cornerstone/bindable.js.coffee → bindable.js.coffee} +0 -0
  9. data/source/{javascripts/_cornerstone/command_stack.js.coffee → command_stack.js.coffee} +0 -0
  10. data/source/{javascripts/_cornerstone/core_object.js.coffee → core_object.js.coffee} +0 -0
  11. data/source/{javascripts/_cornerstone/function_extensions.js.coffee → function_extensions.js.coffee} +0 -0
  12. data/source/{javascripts/_cornerstone/logging.js.coffee → logging.js.coffee} +0 -0
  13. data/source/{javascripts/_cornerstone/matrix.js.coffee → matrix.js.coffee} +0 -0
  14. data/source/{javascripts/_cornerstone/number_extensions.js.coffee → number_extensions.js.coffee} +0 -0
  15. data/source/{javascripts/_cornerstone/point.js.coffee → point.js.coffee} +0 -0
  16. data/source/{javascripts/_cornerstone/random.js.coffee → random.js.coffee} +0 -0
  17. data/source/{javascripts/_cornerstone/rectangle.js.coffee → rectangle.js.coffee} +0 -0
  18. data/source/{javascripts/_cornerstone/string_extensions.js.coffee → string_extensions.js.coffee} +3 -0
  19. data/source/{javascripts/_cornerstone/uuid.js → uuid.js} +0 -0
  20. data/{source/javascripts/_test → test}/array_extensions.coffee +0 -0
  21. data/{source/javascripts/_test → test}/bindable.coffee +0 -0
  22. data/{source/javascripts/_test → test}/command_stack.coffee +0 -0
  23. data/{source/javascripts/_test → test}/core_object.coffee +0 -0
  24. data/{source/javascripts/_test → test}/function_extensions.coffee +0 -0
  25. data/{source/javascripts/_test → test}/logging.coffee +0 -0
  26. data/{source/javascripts/_test → test}/matrix.coffee +0 -0
  27. data/{source/javascripts/_test → test}/number_extensions.coffee +0 -0
  28. data/{source/javascripts/_test → test}/object_extensions.coffee +0 -0
  29. data/{source/javascripts/_test → test}/point.coffee +0 -0
  30. data/{source/javascripts/_test → test}/random.coffee +0 -0
  31. data/{source/javascripts/_test → test}/rectangle.coffee +0 -0
  32. data/{source/javascripts/_test → test}/string_extensions.coffee +10 -0
  33. metadata +37 -113
  34. data/config.rb +0 -79
  35. data/config.ru +0 -4
  36. data/doc_scraper.rb +0 -51
  37. data/game.js +0 -4295
  38. data/lib/assets/javascripts/cornerstone.js +0 -4722
  39. data/manifest.json +0 -15
  40. data/pixie.json +0 -12
  41. data/source/javascripts/_cornerstone/stubs.js.coffee +0 -1042
  42. data/source/javascripts/cornerstone.js.coffee +0 -1
  43. data/source/javascripts/cornerstone_tests.js.coffee +0 -2
  44. data/source/test.html.haml +0 -13
@@ -1,4722 +0,0 @@
1
-
2
- /**
3
- Checks whether an object is an array.
4
-
5
- Object.isArray([1, 2, 4])
6
- # => true
7
-
8
- Object.isArray({key: "value"})
9
- # => false
10
-
11
- @name isArray
12
- @methodOf Object
13
- @param {Object} object The object to check for array-ness.
14
- @returns {Boolean} A boolean expressing whether the object is an instance of Array
15
- */
16
-
17
-
18
- (function() {
19
- var __slice = [].slice;
20
-
21
- Object.isArray = function(object) {
22
- return Object.prototype.toString.call(object) === "[object Array]";
23
- };
24
-
25
- /**
26
- Checks whether an object is a string.
27
-
28
- Object.isString("a string")
29
- # => true
30
-
31
- Object.isString([1, 2, 4])
32
- # => false
33
-
34
- Object.isString({key: "value"})
35
- # => false
36
-
37
- @name isString
38
- @methodOf Object
39
- @param {Object} object The object to check for string-ness.
40
- @returns {Boolean} A boolean expressing whether the object is an instance of String
41
- */
42
-
43
-
44
- Object.isString = function(object) {
45
- return Object.prototype.toString.call(object) === "[object String]";
46
- };
47
-
48
- /**
49
- Merges properties from objects into target without overiding.
50
- First come, first served.
51
-
52
- I =
53
- a: 1
54
- b: 2
55
- c: 3
56
-
57
- Object.reverseMerge I,
58
- c: 6
59
- d: 4
60
-
61
- I # => {a: 1, b:2, c:3, d: 4}
62
-
63
- @name reverseMerge
64
- @methodOf Object
65
- @param {Object} target The object to merge the properties into.
66
- @returns {Object} target
67
- */
68
-
69
-
70
- Object.defaults = Object.reverseMerge = function() {
71
- var name, object, objects, target, _i, _len;
72
- target = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
73
- for (_i = 0, _len = objects.length; _i < _len; _i++) {
74
- object = objects[_i];
75
- for (name in object) {
76
- if (!target.hasOwnProperty(name)) {
77
- target[name] = object[name];
78
- }
79
- }
80
- }
81
- return target;
82
- };
83
-
84
- /**
85
- Merges properties from sources into target with overiding.
86
- Last in covers earlier properties.
87
-
88
- I =
89
- a: 1
90
- b: 2
91
- c: 3
92
-
93
- Object.extend I,
94
- c: 6
95
- d: 4
96
-
97
- I # => {a: 1, b:2, c:6, d: 4}
98
-
99
- @name extend
100
- @methodOf Object
101
- @param {Object} target The object to merge the properties into.
102
- @returns {Object} target
103
- */
104
-
105
-
106
- Object.extend = function() {
107
- var name, source, sources, target, _i, _len;
108
- target = arguments[0], sources = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
109
- for (_i = 0, _len = sources.length; _i < _len; _i++) {
110
- source = sources[_i];
111
- for (name in source) {
112
- target[name] = source[name];
113
- }
114
- }
115
- return target;
116
- };
117
-
118
- /**
119
- Helper method that tells you if something is an object.
120
-
121
- object = {a: 1}
122
-
123
- Object.isObject(object)
124
- # => true
125
-
126
- @name isObject
127
- @methodOf Object
128
- @param {Object} object Maybe this guy is an object.
129
- @returns {Boolean} true if this guy is an object.
130
- */
131
-
132
-
133
- Object.isObject = function(object) {
134
- return Object.prototype.toString.call(object) === '[object Object]';
135
- };
136
-
137
- }).call(this);
138
-
139
- /**
140
- Calculate the average value of an array. Returns undefined if some elements
141
- are not numbers.
142
-
143
- [1, 3, 5, 7].average()
144
- # => 4
145
-
146
- @name average
147
- @methodOf Array#
148
- @returns {Number} The average (arithmetic mean) of the list of numbers.
149
- */
150
-
151
-
152
- (function() {
153
- var _base,
154
- __slice = [].slice;
155
-
156
- Array.prototype.average = function() {
157
- return this.sum() / this.length;
158
- };
159
-
160
- /**
161
- Returns a copy of the array without null and undefined values.
162
-
163
- [null, undefined, 3, 3, undefined, 5].compact()
164
- # => [3, 3, 5]
165
-
166
- @name compact
167
- @methodOf Array#
168
- @returns {Array} A new array that contains only the non-null values.
169
- */
170
-
171
-
172
- Array.prototype.compact = function() {
173
- return this.select(function(element) {
174
- return element != null;
175
- });
176
- };
177
-
178
- /**
179
- Creates and returns a copy of the array. The copy contains
180
- the same objects.
181
-
182
- a = ["a", "b", "c"]
183
- b = a.copy()
184
-
185
- # their elements are equal
186
- a[0] == b[0] && a[1] == b[1] && a[2] == b[2]
187
- # => true
188
-
189
- # but they aren't the same object in memory
190
- a === b
191
- # => false
192
-
193
- @name copy
194
- @methodOf Array#
195
- @returns {Array} A new array that is a copy of the array
196
- */
197
-
198
-
199
- Array.prototype.copy = function() {
200
- return this.concat();
201
- };
202
-
203
- /**
204
- Empties the array of its contents. It is modified in place.
205
-
206
- fullArray = [1, 2, 3]
207
- fullArray.clear()
208
- fullArray
209
- # => []
210
-
211
- @name clear
212
- @methodOf Array#
213
- @returns {Array} this, now emptied.
214
- */
215
-
216
-
217
- Array.prototype.clear = function() {
218
- this.length = 0;
219
- return this;
220
- };
221
-
222
- /**
223
- Flatten out an array of arrays into a single array of elements.
224
-
225
- [[1, 2], [3, 4], 5].flatten()
226
- # => [1, 2, 3, 4, 5]
227
-
228
- # won't flatten twice nested arrays. call
229
- # flatten twice if that is what you want
230
- [[1, 2], [3, [4, 5]], 6].flatten()
231
- # => [1, 2, 3, [4, 5], 6]
232
-
233
- @name flatten
234
- @methodOf Array#
235
- @returns {Array} A new array with all the sub-arrays flattened to the top.
236
- */
237
-
238
-
239
- Array.prototype.flatten = function() {
240
- return this.inject([], function(a, b) {
241
- return a.concat(b);
242
- });
243
- };
244
-
245
- /**
246
- Invoke the named method on each element in the array
247
- and return a new array containing the results of the invocation.
248
-
249
- [1.1, 2.2, 3.3, 4.4].invoke("floor")
250
- # => [1, 2, 3, 4]
251
-
252
- ['hello', 'world', 'cool!'].invoke('substring', 0, 3)
253
- # => ['hel', 'wor', 'coo']
254
-
255
- @param {String} method The name of the method to invoke.
256
- @param [arg...] Optional arguments to pass to the method being invoked.
257
- @name invoke
258
- @methodOf Array#
259
- @returns {Array} A new array containing the results of invoking the named method on each element.
260
- */
261
-
262
-
263
- Array.prototype.invoke = function() {
264
- var args, method;
265
- method = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
266
- return this.map(function(element) {
267
- return element[method].apply(element, args);
268
- });
269
- };
270
-
271
- /**
272
- Randomly select an element from the array.
273
-
274
- [1, 2, 3].rand()
275
- # => 2
276
-
277
- @name rand
278
- @methodOf Array#
279
- @returns {Object} A random element from an array
280
- */
281
-
282
-
283
- Array.prototype.rand = function() {
284
- return this[rand(this.length)];
285
- };
286
-
287
- /**
288
- Remove the first occurrence of the given object from the array if it is
289
- present. The array is modified in place.
290
-
291
- a = [1, 1, "a", "b"]
292
- a.remove(1)
293
- # => 1
294
-
295
- a
296
- # => [1, "a", "b"]
297
-
298
- @name remove
299
- @methodOf Array#
300
- @param {Object} object The object to remove from the array if present.
301
- @returns {Object} The removed object if present otherwise undefined.
302
- */
303
-
304
-
305
- Array.prototype.remove = function(object) {
306
- var index;
307
- index = this.indexOf(object);
308
- if (index >= 0) {
309
- return this.splice(index, 1)[0];
310
- } else {
311
- return void 0;
312
- }
313
- };
314
-
315
- /**
316
- Returns true if the element is present in the array.
317
-
318
- ["a", "b", "c"].include("c")
319
- # => true
320
-
321
- [40, "a"].include(700)
322
- # => false
323
-
324
- @name include
325
- @methodOf Array#
326
- @param {Object} element The element to check if present.
327
- @returns {Boolean} true if the element is in the array, false otherwise.
328
- */
329
-
330
-
331
- Array.prototype.include = function(element) {
332
- return this.indexOf(element) !== -1;
333
- };
334
-
335
- /**
336
- Call the given iterator once for each element in the array,
337
- passing in the element as the first argument, the index of
338
- the element as the second argument, and <code>this</code> array as the
339
- third argument.
340
-
341
- word = ""
342
- indices = []
343
- ["r", "a", "d"].each (letter, index) ->
344
- word += letter
345
- indices.push(index)
346
-
347
- # => ["r", "a", "d"]
348
-
349
- word
350
- # => "rad"
351
-
352
- indices
353
- # => [0, 1, 2]
354
-
355
- @name each
356
- @methodOf Array#
357
- @param {Function} iterator Function to be called once for each element in the array.
358
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
359
- @returns {Array} this to enable method chaining.
360
- */
361
-
362
-
363
- Array.prototype.each = function(iterator, context) {
364
- var element, i, _i, _len;
365
- if (this.forEach) {
366
- this.forEach(iterator, context);
367
- } else {
368
- for (i = _i = 0, _len = this.length; _i < _len; i = ++_i) {
369
- element = this[i];
370
- iterator.call(context, element, i, this);
371
- }
372
- }
373
- return this;
374
- };
375
-
376
- /**
377
- Call the given iterator once for each element in the array,
378
- passing in the element as the first argument, the index of
379
- the element as the second argument, and `this` array as the
380
- third argument.
381
-
382
- [1, 2, 3].map (number) ->
383
- number * number
384
- # => [1, 4, 9]
385
-
386
- @name map
387
- @methodOf Array#
388
- @param {Function} iterator Function to be called once for each element in the array.
389
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
390
- @returns {Array} An array of the results of the iterator function being called on the original array elements.
391
- */
392
-
393
-
394
- (_base = Array.prototype).map || (_base.map = function(iterator, context) {
395
- var element, i, results, _i, _len;
396
- results = [];
397
- for (i = _i = 0, _len = this.length; _i < _len; i = ++_i) {
398
- element = this[i];
399
- results.push(iterator.call(context, element, i, this));
400
- }
401
- return results;
402
- });
403
-
404
- /**
405
- Call the given iterator once for each pair of objects in the array.
406
-
407
- [1, 2, 3, 4].eachPair (a, b) ->
408
- # 1, 2
409
- # 1, 3
410
- # 1, 4
411
- # 2, 3
412
- # 2, 4
413
- # 3, 4
414
-
415
- @name eachPair
416
- @methodOf Array#
417
- @param {Function} iterator Function to be called once for each pair of elements in the array.
418
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
419
- */
420
-
421
-
422
- Array.prototype.eachPair = function(iterator, context) {
423
- var a, b, i, j, length, _results;
424
- length = this.length;
425
- i = 0;
426
- _results = [];
427
- while (i < length) {
428
- a = this[i];
429
- j = i + 1;
430
- i += 1;
431
- _results.push((function() {
432
- var _results1;
433
- _results1 = [];
434
- while (j < length) {
435
- b = this[j];
436
- j += 1;
437
- _results1.push(iterator.call(context, a, b));
438
- }
439
- return _results1;
440
- }).call(this));
441
- }
442
- return _results;
443
- };
444
-
445
- /**
446
- Call the given iterator once for each element in the array,
447
- passing in the element as the first argument and the given object
448
- as the second argument. Additional arguments are passed similar to
449
- <code>each</code>.
450
-
451
- @see Array#each
452
- @name eachWithObject
453
- @methodOf Array#
454
- @param {Object} object The object to pass to the iterator on each visit.
455
- @param {Function} iterator Function to be called once for each element in the array.
456
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
457
- @returns {Array} this
458
- */
459
-
460
-
461
- Array.prototype.eachWithObject = function(object, iterator, context) {
462
- this.each(function(element, i, self) {
463
- return iterator.call(context, element, object, i, self);
464
- });
465
- return object;
466
- };
467
-
468
- /**
469
- Call the given iterator once for each group of elements in the array,
470
- passing in the elements in groups of n. Additional argumens are
471
- passed as in each.
472
-
473
- results = []
474
- [1, 2, 3, 4].eachSlice 2, (slice) ->
475
- results.push(slice)
476
- # => [1, 2, 3, 4]
477
-
478
- results
479
- # => [[1, 2], [3, 4]]
480
-
481
- @see Array#each
482
- @name eachSlice
483
- @methodOf Array#
484
- @param {Number} n The number of elements in each group.
485
- @param {Function} iterator Function to be called once for each group of elements in the array.
486
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
487
- @returns {Array} this
488
- */
489
-
490
-
491
- Array.prototype.eachSlice = function(n, iterator, context) {
492
- var i, len;
493
- if (n > 0) {
494
- len = (this.length / n).floor();
495
- i = -1;
496
- while (++i < len) {
497
- iterator.call(context, this.slice(i * n, (i + 1) * n), i * n, this);
498
- }
499
- }
500
- return this;
501
- };
502
-
503
- /**
504
- Pipe the input through each function in the array in turn. For example, if you have a
505
- list of objects you can perform a series of selection, sorting, and other processing
506
- methods and then receive the processed list. This array must contain functions that
507
- accept a single input and return the processed input. The output of the first function
508
- is fed to the input of the second and so on until the final processed output is returned.
509
-
510
- @name pipeline
511
- @methodOf Array#
512
-
513
- @param {Object} input The initial input to pass to the first function in the pipeline.
514
- @returns {Object} The result of processing the input by each function in the array.
515
- */
516
-
517
-
518
- Array.prototype.pipeline = function(input) {
519
- var fn, _i, _len;
520
- for (_i = 0, _len = this.length; _i < _len; _i++) {
521
- fn = this[_i];
522
- input = fn(input);
523
- }
524
- return input;
525
- };
526
-
527
- /**
528
- Returns a new array with the elements all shuffled up.
529
-
530
- a = [1, 2, 3]
531
-
532
- a.shuffle()
533
- # => [2, 3, 1]
534
-
535
- a # => [1, 2, 3]
536
-
537
- @name shuffle
538
- @methodOf Array#
539
- @returns {Array} A new array that is randomly shuffled.
540
- */
541
-
542
-
543
- Array.prototype.shuffle = function() {
544
- var shuffledArray;
545
- shuffledArray = [];
546
- this.each(function(element) {
547
- return shuffledArray.splice(rand(shuffledArray.length + 1), 0, element);
548
- });
549
- return shuffledArray;
550
- };
551
-
552
- /**
553
- Returns the first element of the array, undefined if the array is empty.
554
-
555
- ["first", "second", "third"].first()
556
- # => "first"
557
-
558
- @name first
559
- @methodOf Array#
560
- @returns {Object} The first element, or undefined if the array is empty.
561
- */
562
-
563
-
564
- Array.prototype.first = function() {
565
- return this[0];
566
- };
567
-
568
- /**
569
- Returns the last element of the array, undefined if the array is empty.
570
-
571
- ["first", "second", "third"].last()
572
- # => "third"
573
-
574
- @name last
575
- @methodOf Array#
576
- @returns {Object} The last element, or undefined if the array is empty.
577
- */
578
-
579
-
580
- Array.prototype.last = function() {
581
- return this[this.length - 1];
582
- };
583
-
584
- /**
585
- Returns an object containing the extremes of this array.
586
-
587
- [-1, 3, 0].extremes()
588
- # => {min: -1, max: 3}
589
-
590
- @name extremes
591
- @methodOf Array#
592
- @param {Function} [fn] An optional funtion used to evaluate each element to calculate its value for determining extremes.
593
- @returns {Object} {min: minElement, max: maxElement}
594
- */
595
-
596
-
597
- Array.prototype.extremes = function(fn) {
598
- var max, maxResult, min, minResult;
599
- fn || (fn = function(n) {
600
- return n;
601
- });
602
- min = max = void 0;
603
- minResult = maxResult = void 0;
604
- this.each(function(object) {
605
- var result;
606
- result = fn(object);
607
- if (min != null) {
608
- if (result < minResult) {
609
- min = object;
610
- minResult = result;
611
- }
612
- } else {
613
- min = object;
614
- minResult = result;
615
- }
616
- if (max != null) {
617
- if (result > maxResult) {
618
- max = object;
619
- return maxResult = result;
620
- }
621
- } else {
622
- max = object;
623
- return maxResult = result;
624
- }
625
- });
626
- return {
627
- min: min,
628
- max: max
629
- };
630
- };
631
-
632
- /**
633
- Pretend the array is a circle and grab a new array containing length elements.
634
- If length is not given return the element at start, again assuming the array
635
- is a circle.
636
-
637
- [1, 2, 3].wrap(-1)
638
- # => 3
639
-
640
- [1, 2, 3].wrap(6)
641
- # => 1
642
-
643
- ["l", "o", "o", "p"].wrap(0, 16)
644
- # => ["l", "o", "o", "p", "l", "o", "o", "p", "l", "o", "o", "p", "l", "o", "o", "p"]
645
-
646
- @name wrap
647
- @methodOf Array#
648
- @param {Number} start The index to start wrapping at, or the index of the sole element to return if no length is given.
649
- @param {Number} [length] Optional length determines how long result array should be.
650
- @returns {Object} or {Array} The element at start mod array.length, or an array of length elements, starting from start and wrapping.
651
- */
652
-
653
-
654
- Array.prototype.wrap = function(start, length) {
655
- var end, i, result;
656
- if (length != null) {
657
- end = start + length;
658
- i = start;
659
- result = [];
660
- while (i++ < end) {
661
- result.push(this[i.mod(this.length)]);
662
- }
663
- return result;
664
- } else {
665
- return this[start.mod(this.length)];
666
- }
667
- };
668
-
669
- /**
670
- Partitions the elements into two groups: those for which the iterator returns
671
- true, and those for which it returns false.
672
-
673
- [evens, odds] = [1, 2, 3, 4].partition (n) ->
674
- n.even()
675
-
676
- evens
677
- # => [2, 4]
678
-
679
- odds
680
- # => [1, 3]
681
-
682
- @name partition
683
- @methodOf Array#
684
- @param {Function} iterator
685
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
686
- @returns {Array} An array in the form of [trueCollection, falseCollection]
687
- */
688
-
689
-
690
- Array.prototype.partition = function(iterator, context) {
691
- var falseCollection, trueCollection;
692
- trueCollection = [];
693
- falseCollection = [];
694
- this.each(function(element) {
695
- if (iterator.call(context, element)) {
696
- return trueCollection.push(element);
697
- } else {
698
- return falseCollection.push(element);
699
- }
700
- });
701
- return [trueCollection, falseCollection];
702
- };
703
-
704
- /**
705
- Return the group of elements for which the return value of the iterator is true.
706
-
707
- @name select
708
- @methodOf Array#
709
- @param {Function} iterator The iterator receives each element in turn as the first agument.
710
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
711
- @returns {Array} An array containing the elements for which the iterator returned true.
712
- */
713
-
714
-
715
- Array.prototype.select = function(iterator, context) {
716
- return this.partition(iterator, context)[0];
717
- };
718
-
719
- /**
720
- Return the group of elements that are not in the passed in set.
721
-
722
- [1, 2, 3, 4].without ([2, 3])
723
- # => [1, 4]
724
-
725
- @name without
726
- @methodOf Array#
727
- @param {Array} values List of elements to exclude.
728
- @returns {Array} An array containing the elements that are not passed in.
729
- */
730
-
731
-
732
- Array.prototype.without = function(values) {
733
- return this.reject(function(element) {
734
- return values.include(element);
735
- });
736
- };
737
-
738
- /**
739
- Return the group of elements for which the return value of the iterator is false.
740
-
741
- @name reject
742
- @methodOf Array#
743
- @param {Function} iterator The iterator receives each element in turn as the first agument.
744
- @param {Object} [context] Optional context parameter to be used as `this` when calling the iterator function.
745
- @returns {Array} An array containing the elements for which the iterator returned false.
746
- */
747
-
748
-
749
- Array.prototype.reject = function(iterator, context) {
750
- return this.partition(iterator, context)[1];
751
- };
752
-
753
- /**
754
- Combines all elements of the array by applying a binary operation.
755
- for each element in the arra the iterator is passed an accumulator
756
- value (memo) and the element.
757
-
758
- @name inject
759
- @methodOf Array#
760
- @returns {Object} The result of a
761
- */
762
-
763
-
764
- Array.prototype.inject = function(initial, iterator) {
765
- this.each(function(element) {
766
- return initial = iterator(initial, element);
767
- });
768
- return initial;
769
- };
770
-
771
- /**
772
- Add all the elements in the array.
773
-
774
- [1, 2, 3, 4].sum()
775
- # => 10
776
-
777
- @name sum
778
- @methodOf Array#
779
- @returns {Number} The sum of the elements in the array.
780
- */
781
-
782
-
783
- Array.prototype.sum = function() {
784
- return this.inject(0, function(sum, n) {
785
- return sum + n;
786
- });
787
- };
788
-
789
- /**
790
- Multiply all the elements in the array.
791
-
792
- [1, 2, 3, 4].product()
793
- # => 24
794
-
795
- @name product
796
- @methodOf Array#
797
- @returns {Number} The product of the elements in the array.
798
- */
799
-
800
-
801
- Array.prototype.product = function() {
802
- return this.inject(1, function(product, n) {
803
- return product * n;
804
- });
805
- };
806
-
807
- /**
808
- Merges together the values of each of the arrays with the values at the corresponding position.
809
-
810
- ['a', 'b', 'c'].zip([1, 2, 3])
811
- # => [['a', 1], ['b', 2], ['c', 3]]
812
-
813
- @name zip
814
- @methodOf Array#
815
- @returns {Array} Array groupings whose values are arranged by their positions in the original input arrays.
816
- */
817
-
818
-
819
- Array.prototype.zip = function() {
820
- var args;
821
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
822
- return this.map(function(element, index) {
823
- var output;
824
- output = args.map(function(arr) {
825
- return arr[index];
826
- });
827
- output.unshift(element);
828
- return output;
829
- });
830
- };
831
-
832
- }).call(this);
833
-
834
- /**
835
- Bindable module.
836
-
837
- player = Core
838
- x: 5
839
- y: 10
840
-
841
- player.bind "update", ->
842
- updatePlayer()
843
- # => Uncaught TypeError: Object has no method 'bind'
844
-
845
- player.include(Bindable)
846
-
847
- player.bind "update", ->
848
- updatePlayer()
849
- # => this will call updatePlayer each time through the main loop
850
-
851
- @name Bindable
852
- @module
853
- @constructor
854
- */
855
-
856
-
857
- (function() {
858
- var Bindable,
859
- __slice = [].slice;
860
-
861
- Bindable = function(I, self) {
862
- var eventCallbacks;
863
- if (I == null) {
864
- I = {};
865
- }
866
- eventCallbacks = {};
867
- return {
868
- bind: function() {
869
- var args;
870
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
871
- return self.on.apply(self, args);
872
- },
873
- unbind: function() {
874
- var args;
875
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
876
- return self.off.apply(self, args);
877
- },
878
- /**
879
- Adds a function as an event listener.
880
-
881
- # this will call coolEventHandler after
882
- # yourObject.trigger "someCustomEvent" is called.
883
- yourObject.on "someCustomEvent", coolEventHandler
884
-
885
- #or
886
- yourObject.on "anotherCustomEvent", ->
887
- doSomething()
888
-
889
- @name on
890
- @methodOf Bindable#
891
- @param {String} event The event to listen to.
892
- @param {Function} callback The function to be called when the specified event
893
- is triggered.
894
- */
895
-
896
- on: function(namespacedEvent, callback) {
897
- var event, namespace, _ref;
898
- _ref = namespacedEvent.split("."), event = _ref[0], namespace = _ref[1];
899
- if (namespace) {
900
- callback.__PIXIE || (callback.__PIXIE = {});
901
- callback.__PIXIE[namespace] = true;
902
- }
903
- eventCallbacks[event] || (eventCallbacks[event] = []);
904
- eventCallbacks[event].push(callback);
905
- return this;
906
- },
907
- /**
908
- Removes a specific event listener, or all event listeners if
909
- no specific listener is given.
910
-
911
- # removes the handler coolEventHandler from the event
912
- # "someCustomEvent" while leaving the other events intact.
913
- yourObject.off "someCustomEvent", coolEventHandler
914
-
915
- # removes all handlers attached to "anotherCustomEvent"
916
- yourObject.off "anotherCustomEvent"
917
-
918
- @name off
919
- @methodOf Bindable#
920
- @param {String} event The event to remove the listener from.
921
- @param {Function} [callback] The listener to remove.
922
- */
923
-
924
- off: function(namespacedEvent, callback) {
925
- var callbacks, event, key, namespace, _ref;
926
- _ref = namespacedEvent.split("."), event = _ref[0], namespace = _ref[1];
927
- if (event) {
928
- eventCallbacks[event] || (eventCallbacks[event] = []);
929
- if (namespace) {
930
- eventCallbacks[event] = eventCallbacks.select(function(callback) {
931
- var _ref1;
932
- return !(((_ref1 = callback.__PIXIE) != null ? _ref1[namespace] : void 0) != null);
933
- });
934
- } else {
935
- if (callback) {
936
- eventCallbacks[event].remove(callback);
937
- } else {
938
- eventCallbacks[event] = [];
939
- }
940
- }
941
- } else if (namespace) {
942
- for (key in eventCallbacks) {
943
- callbacks = eventCallbacks[key];
944
- eventCallbacks[key] = callbacks.select(function(callback) {
945
- var _ref1;
946
- return !(((_ref1 = callback.__PIXIE) != null ? _ref1[namespace] : void 0) != null);
947
- });
948
- }
949
- }
950
- return this;
951
- },
952
- /**
953
- Calls all listeners attached to the specified event.
954
-
955
- # calls each event handler bound to "someCustomEvent"
956
- yourObject.trigger "someCustomEvent"
957
-
958
- @name trigger
959
- @methodOf Bindable#
960
- @param {String} event The event to trigger.
961
- @param {Array} [parameters] Additional parameters to pass to the event listener.
962
- */
963
-
964
- trigger: function() {
965
- var callbacks, event, parameters;
966
- event = arguments[0], parameters = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
967
- callbacks = eventCallbacks[event];
968
- if (callbacks && callbacks.length) {
969
- self = this;
970
- return callbacks.each(function(callback) {
971
- return callback.apply(self, parameters);
972
- });
973
- }
974
- }
975
- };
976
- };
977
-
978
- (typeof exports !== "undefined" && exports !== null ? exports : this)["Bindable"] = Bindable;
979
-
980
- }).call(this);
981
- (function() {
982
- var CommandStack;
983
-
984
- CommandStack = function() {
985
- var index, stack;
986
- stack = [];
987
- index = 0;
988
- return {
989
- execute: function(command) {
990
- stack[index] = command;
991
- command.execute();
992
- return stack.length = index += 1;
993
- },
994
- undo: function() {
995
- var command;
996
- if (this.canUndo()) {
997
- index -= 1;
998
- command = stack[index];
999
- command.undo();
1000
- return command;
1001
- }
1002
- },
1003
- redo: function() {
1004
- var command;
1005
- if (this.canRedo()) {
1006
- command = stack[index];
1007
- command.execute();
1008
- index += 1;
1009
- return command;
1010
- }
1011
- },
1012
- current: function() {
1013
- return stack[index - 1];
1014
- },
1015
- canUndo: function() {
1016
- return index > 0;
1017
- },
1018
- canRedo: function() {
1019
- return stack[index] != null;
1020
- }
1021
- };
1022
- };
1023
-
1024
- (typeof exports !== "undefined" && exports !== null ? exports : this)["CommandStack"] = CommandStack;
1025
-
1026
- }).call(this);
1027
-
1028
- /**
1029
- The Core class is used to add extended functionality to objects without
1030
- extending the object class directly. Inherit from Core to gain its utility
1031
- methods.
1032
-
1033
- @name Core
1034
- @constructor
1035
-
1036
- @param {Object} I Instance variables
1037
- */
1038
-
1039
-
1040
- (function() {
1041
- var __slice = [].slice;
1042
-
1043
- (function() {
1044
- var root;
1045
- root = typeof exports !== "undefined" && exports !== null ? exports : this;
1046
- return root.Core = function(I) {
1047
- var Module, moduleName, self, _i, _len, _ref;
1048
- if (I == null) {
1049
- I = {};
1050
- }
1051
- Object.reverseMerge(I, {
1052
- includedModules: []
1053
- });
1054
- self = {
1055
- /**
1056
- External access to instance variables. Use of this property should be avoided
1057
- in general, but can come in handy from time to time.
1058
-
1059
- I =
1060
- r: 255
1061
- g: 0
1062
- b: 100
1063
-
1064
- myObject = Core(I)
1065
-
1066
- # a bad idea most of the time, but it's
1067
- # pretty convenient to have available.
1068
- myObject.I.r
1069
- # => 255
1070
-
1071
- myObject.I.g
1072
- # => 0
1073
-
1074
- myObject.I.b
1075
- # => 100
1076
-
1077
- @name I
1078
- @fieldOf Core#
1079
- */
1080
-
1081
- I: I,
1082
- /**
1083
- Generates a public jQuery style getter / setter method for each
1084
- String argument.
1085
-
1086
- myObject = Core
1087
- r: 255
1088
- g: 0
1089
- b: 100
1090
-
1091
- myObject.attrAccessor "r", "g", "b"
1092
-
1093
- myObject.r(254)
1094
- myObject.r()
1095
-
1096
- => 254
1097
-
1098
- @name attrAccessor
1099
- @methodOf Core#
1100
- */
1101
-
1102
- attrAccessor: function() {
1103
- var attrNames;
1104
- attrNames = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1105
- return attrNames.each(function(attrName) {
1106
- return self[attrName] = function(newValue) {
1107
- if (newValue != null) {
1108
- I[attrName] = newValue;
1109
- return self;
1110
- } else {
1111
- return I[attrName];
1112
- }
1113
- };
1114
- });
1115
- },
1116
- /**
1117
- Generates a public jQuery style getter method for each String argument.
1118
-
1119
- myObject = Core
1120
- r: 255
1121
- g: 0
1122
- b: 100
1123
-
1124
- myObject.attrReader "r", "g", "b"
1125
-
1126
- myObject.r()
1127
- => 255
1128
-
1129
- myObject.g()
1130
- => 0
1131
-
1132
- myObject.b()
1133
- => 100
1134
-
1135
- @name attrReader
1136
- @methodOf Core#
1137
- */
1138
-
1139
- attrReader: function() {
1140
- var attrNames;
1141
- attrNames = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1142
- return attrNames.each(function(attrName) {
1143
- return self[attrName] = function() {
1144
- return I[attrName];
1145
- };
1146
- });
1147
- },
1148
- /**
1149
- Extends this object with methods from the passed in object. A shortcut for Object.extend(self, methods)
1150
-
1151
- I =
1152
- x: 30
1153
- y: 40
1154
- maxSpeed: 5
1155
-
1156
- # we are using extend to give player
1157
- # additional methods that Core doesn't have
1158
- player = Core(I).extend
1159
- increaseSpeed: ->
1160
- I.maxSpeed += 1
1161
-
1162
- player.I.maxSpeed
1163
- => 5
1164
-
1165
- player.increaseSpeed()
1166
-
1167
- player.I.maxSpeed
1168
- => 6
1169
-
1170
- @name extend
1171
- @methodOf Core#
1172
- @see Object.extend
1173
- @returns self
1174
- */
1175
-
1176
- extend: function(options) {
1177
- Object.extend(self, options);
1178
- return self;
1179
- },
1180
- /**
1181
- Includes a module in this object.
1182
-
1183
- myObject = Core()
1184
- myObject.include(Bindable)
1185
-
1186
- # now you can bind handlers to functions
1187
- myObject.bind "someEvent", ->
1188
- alert("wow. that was easy.")
1189
-
1190
- @name include
1191
- @methodOf Core#
1192
- @param {String} Module the module to include. A module is a constructor that takes two parameters, I and self, and returns an object containing the public methods to extend the including object with.
1193
- */
1194
-
1195
- include: function() {
1196
- var Module, key, moduleName, modules, value, _i, _len;
1197
- modules = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1198
- for (_i = 0, _len = modules.length; _i < _len; _i++) {
1199
- Module = modules[_i];
1200
- if (typeof Module.isString === "function" ? Module.isString() : void 0) {
1201
- moduleName = Module;
1202
- Module = Module.constantize();
1203
- } else if (moduleName = Module._name) {
1204
-
1205
- } else {
1206
- for (key in root) {
1207
- value = root[key];
1208
- if (value === Module) {
1209
- Module._name = moduleName = key;
1210
- }
1211
- }
1212
- }
1213
- if (moduleName) {
1214
- if (!I.includedModules.include(moduleName)) {
1215
- I.includedModules.push(moduleName);
1216
- self.extend(Module(I, self));
1217
- }
1218
- } else {
1219
- warn("Unable to discover name for module: ", Module, "\nSerialization issues may occur.");
1220
- self.extend(Module(I, self));
1221
- }
1222
- }
1223
- return self;
1224
- },
1225
- send: function() {
1226
- var args, name;
1227
- name = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
1228
- return self[name].apply(self, args);
1229
- }
1230
- };
1231
- self.include("Bindable");
1232
- _ref = I.includedModules;
1233
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1234
- moduleName = _ref[_i];
1235
- Module = moduleName.constantize();
1236
- self.extend(Module(I, self));
1237
- }
1238
- return self;
1239
- };
1240
- })();
1241
-
1242
- }).call(this);
1243
- (function() {
1244
- var __slice = [].slice;
1245
-
1246
- Function.prototype.once = function() {
1247
- var func, memo, ran;
1248
- func = this;
1249
- ran = false;
1250
- memo = void 0;
1251
- return function() {
1252
- if (ran) {
1253
- return memo;
1254
- }
1255
- ran = true;
1256
- return memo = func.apply(this, arguments);
1257
- };
1258
- };
1259
-
1260
- /**
1261
- Calling a debounced function will postpone its execution until after
1262
- wait milliseconds have elapsed since the last time the function was
1263
- invoked. Useful for implementing behavior that should only happen after
1264
- the input has stopped arriving. For example: rendering a preview of a
1265
- Markdown comment, recalculating a layout after the window has stopped
1266
- being resized...
1267
-
1268
- lazyLayout = calculateLayout.debounce(300)
1269
- $(window).resize(lazyLayout)
1270
-
1271
- @name debounce
1272
- @methodOf Function#
1273
- @returns {Function} The debounced version of this function.
1274
- */
1275
-
1276
-
1277
- Function.prototype.debounce = function(wait) {
1278
- var func, timeout;
1279
- timeout = null;
1280
- func = this;
1281
- return function() {
1282
- var args, context, later;
1283
- context = this;
1284
- args = arguments;
1285
- later = function() {
1286
- timeout = null;
1287
- return func.apply(context, args);
1288
- };
1289
- clearTimeout(timeout);
1290
- return timeout = setTimeout(later, wait);
1291
- };
1292
- };
1293
-
1294
- Function.prototype.returning = function(x) {
1295
- var func;
1296
- func = this;
1297
- return function() {
1298
- func.apply(this, arguments);
1299
- return x;
1300
- };
1301
- };
1302
-
1303
- Function.prototype.delay = function() {
1304
- var args, func, wait;
1305
- wait = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
1306
- func = this;
1307
- return setTimeout(function() {
1308
- return func.apply(null, args);
1309
- }, wait);
1310
- };
1311
-
1312
- Function.prototype.defer = function() {
1313
- var args;
1314
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1315
- return this.delay.apply(this, [1].concat(args));
1316
- };
1317
-
1318
- }).call(this);
1319
-
1320
- /**
1321
- @name Logging
1322
- @namespace
1323
-
1324
- Gives you some convenience methods for outputting data while developing.
1325
-
1326
- log "Testing123"
1327
- info "Hey, this is happening"
1328
- warn "Be careful, this might be a problem"
1329
- error "Kaboom!"
1330
- */
1331
-
1332
-
1333
- (function() {
1334
- var __slice = [].slice;
1335
-
1336
- ["log", "info", "warn", "error"].each(function(name) {
1337
- if (typeof console !== "undefined") {
1338
- return (typeof exports !== "undefined" && exports !== null ? exports : this)[name] = function() {
1339
- var args;
1340
- args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
1341
- if (console[name]) {
1342
- return console[name].apply(console, args);
1343
- }
1344
- };
1345
- } else {
1346
- return (typeof exports !== "undefined" && exports !== null ? exports : this)[name] = function() {};
1347
- }
1348
- });
1349
-
1350
- }).call(this);
1351
-
1352
- /**
1353
- * Matrix.js v1.3.0pre
1354
- *
1355
- * Copyright (c) 2010 STRd6
1356
- *
1357
- * Permission is hereby granted, free of charge, to any person obtaining a copy
1358
- * of this software and associated documentation files (the "Software"), to deal
1359
- * in the Software without restriction, including without limitation the rights
1360
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1361
- * copies of the Software, and to permit persons to whom the Software is
1362
- * furnished to do so, subject to the following conditions:
1363
- *
1364
- * The above copyright notice and this permission notice shall be included in
1365
- * all copies or substantial portions of the Software.
1366
- *
1367
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1368
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1369
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1370
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1371
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1372
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1373
- * THE SOFTWARE.
1374
- *
1375
- * Loosely based on flash:
1376
- * http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/geom/Matrix.html
1377
- */
1378
-
1379
-
1380
- (function() {
1381
-
1382
- (function() {
1383
- /**
1384
- <pre>
1385
- _ _
1386
- | a c tx |
1387
- | b d ty |
1388
- |_0 0 1 _|
1389
- </pre>
1390
- Creates a matrix for 2d affine transformations.
1391
-
1392
- concat, inverse, rotate, scale and translate return new matrices with the
1393
- transformations applied. The matrix is not modified in place.
1394
-
1395
- Returns the identity matrix when called with no arguments.
1396
-
1397
- @name Matrix
1398
- @param {Number} [a]
1399
- @param {Number} [b]
1400
- @param {Number} [c]
1401
- @param {Number} [d]
1402
- @param {Number} [tx]
1403
- @param {Number} [ty]
1404
- @constructor
1405
- */
1406
-
1407
- var Matrix;
1408
- Matrix = function(a, b, c, d, tx, ty) {
1409
- var _ref;
1410
- if (Object.isObject(a)) {
1411
- _ref = a, a = _ref.a, b = _ref.b, c = _ref.c, d = _ref.d, tx = _ref.tx, ty = _ref.ty;
1412
- }
1413
- return {
1414
- __proto__: Matrix.prototype,
1415
- /**
1416
- @name a
1417
- @fieldOf Matrix#
1418
- */
1419
-
1420
- a: a != null ? a : 1,
1421
- /**
1422
- @name b
1423
- @fieldOf Matrix#
1424
- */
1425
-
1426
- b: b || 0,
1427
- /**
1428
- @name c
1429
- @fieldOf Matrix#
1430
- */
1431
-
1432
- c: c || 0,
1433
- /**
1434
- @name d
1435
- @fieldOf Matrix#
1436
- */
1437
-
1438
- d: d != null ? d : 1,
1439
- /**
1440
- @name tx
1441
- @fieldOf Matrix#
1442
- */
1443
-
1444
- tx: tx || 0,
1445
- /**
1446
- @name ty
1447
- @fieldOf Matrix#
1448
- */
1449
-
1450
- ty: ty || 0
1451
- };
1452
- };
1453
- Matrix.prototype = {
1454
- /**
1455
- Returns the result of this matrix multiplied by another matrix
1456
- combining the geometric effects of the two. In mathematical terms,
1457
- concatenating two matrixes is the same as combining them using matrix multiplication.
1458
- If this matrix is A and the matrix passed in is B, the resulting matrix is A x B
1459
- http://mathworld.wolfram.com/MatrixMultiplication.html
1460
- @name concat
1461
- @methodOf Matrix#
1462
- @param {Matrix} matrix The matrix to multiply this matrix by.
1463
- @returns {Matrix} The result of the matrix multiplication, a new matrix.
1464
- */
1465
-
1466
- concat: function(matrix) {
1467
- return Matrix(this.a * matrix.a + this.c * matrix.b, this.b * matrix.a + this.d * matrix.b, this.a * matrix.c + this.c * matrix.d, this.b * matrix.c + this.d * matrix.d, this.a * matrix.tx + this.c * matrix.ty + this.tx, this.b * matrix.tx + this.d * matrix.ty + this.ty);
1468
- },
1469
- /**
1470
- Copy this matrix.
1471
- @name copy
1472
- @methodOf Matrix#
1473
- @returns {Matrix} A copy of this matrix.
1474
- */
1475
-
1476
- copy: function() {
1477
- return Matrix(this.a, this.b, this.c, this.d, this.tx, this.ty);
1478
- },
1479
- /**
1480
- Given a point in the pretransform coordinate space, returns the coordinates of
1481
- that point after the transformation occurs. Unlike the standard transformation
1482
- applied using the transformPoint() method, the deltaTransformPoint() method
1483
- does not consider the translation parameters tx and ty.
1484
- @name deltaTransformPoint
1485
- @methodOf Matrix#
1486
- @see #transformPoint
1487
- @return {Point} A new point transformed by this matrix ignoring tx and ty.
1488
- */
1489
-
1490
- deltaTransformPoint: function(point) {
1491
- return Point(this.a * point.x + this.c * point.y, this.b * point.x + this.d * point.y);
1492
- },
1493
- /**
1494
- Returns the inverse of the matrix.
1495
- http://mathworld.wolfram.com/MatrixInverse.html
1496
- @name inverse
1497
- @methodOf Matrix#
1498
- @returns {Matrix} A new matrix that is the inverse of this matrix.
1499
- */
1500
-
1501
- inverse: function() {
1502
- var determinant;
1503
- determinant = this.a * this.d - this.b * this.c;
1504
- return Matrix(this.d / determinant, -this.b / determinant, -this.c / determinant, this.a / determinant, (this.c * this.ty - this.d * this.tx) / determinant, (this.b * this.tx - this.a * this.ty) / determinant);
1505
- },
1506
- /**
1507
- Returns a new matrix that corresponds this matrix multiplied by a
1508
- a rotation matrix.
1509
- @name rotate
1510
- @methodOf Matrix#
1511
- @see Matrix.rotation
1512
- @param {Number} theta Amount to rotate in radians.
1513
- @param {Point} [aboutPoint] The point about which this rotation occurs. Defaults to (0,0).
1514
- @returns {Matrix} A new matrix, rotated by the specified amount.
1515
- */
1516
-
1517
- rotate: function(theta, aboutPoint) {
1518
- return this.concat(Matrix.rotation(theta, aboutPoint));
1519
- },
1520
- /**
1521
- Returns a new matrix that corresponds this matrix multiplied by a
1522
- a scaling matrix.
1523
- @name scale
1524
- @methodOf Matrix#
1525
- @see Matrix.scale
1526
- @param {Number} sx
1527
- @param {Number} [sy]
1528
- @param {Point} [aboutPoint] The point that remains fixed during the scaling
1529
- @returns {Matrix} A new Matrix. The original multiplied by a scaling matrix.
1530
- */
1531
-
1532
- scale: function(sx, sy, aboutPoint) {
1533
- return this.concat(Matrix.scale(sx, sy, aboutPoint));
1534
- },
1535
- /**
1536
- Returns a new matrix that corresponds this matrix multiplied by a
1537
- a skewing matrix.
1538
-
1539
- @name skew
1540
- @methodOf Matrix#
1541
- @see Matrix.skew
1542
- @param {Number} skewX The angle of skew in the x dimension.
1543
- @param {Number} skewY The angle of skew in the y dimension.
1544
- */
1545
-
1546
- skew: function(skewX, skewY) {
1547
- return this.concat(Matrix.skew(skewX, skewY));
1548
- },
1549
- /**
1550
- Returns a string representation of this matrix.
1551
-
1552
- @name toString
1553
- @methodOf Matrix#
1554
- @returns {String} A string reperesentation of this matrix.
1555
- */
1556
-
1557
- toString: function() {
1558
- return "Matrix(" + this.a + ", " + this.b + ", " + this.c + ", " + this.d + ", " + this.tx + ", " + this.ty + ")";
1559
- },
1560
- /**
1561
- Returns the result of applying the geometric transformation represented by the
1562
- Matrix object to the specified point.
1563
- @name transformPoint
1564
- @methodOf Matrix#
1565
- @see #deltaTransformPoint
1566
- @returns {Point} A new point with the transformation applied.
1567
- */
1568
-
1569
- transformPoint: function(point) {
1570
- return Point(this.a * point.x + this.c * point.y + this.tx, this.b * point.x + this.d * point.y + this.ty);
1571
- },
1572
- /**
1573
- Translates the matrix along the x and y axes, as specified by the tx and ty parameters.
1574
- @name translate
1575
- @methodOf Matrix#
1576
- @see Matrix.translation
1577
- @param {Number} tx The translation along the x axis.
1578
- @param {Number} ty The translation along the y axis.
1579
- @returns {Matrix} A new matrix with the translation applied.
1580
- */
1581
-
1582
- translate: function(tx, ty) {
1583
- return this.concat(Matrix.translation(tx, ty));
1584
- }
1585
- };
1586
- /**
1587
- Creates a matrix transformation that corresponds to the given rotation,
1588
- around (0,0) or the specified point.
1589
- @see Matrix#rotate
1590
- @param {Number} theta Rotation in radians.
1591
- @param {Point} [aboutPoint] The point about which this rotation occurs. Defaults to (0,0).
1592
- @returns {Matrix} A new matrix rotated by the given amount.
1593
- */
1594
-
1595
- Matrix.rotate = Matrix.rotation = function(theta, aboutPoint) {
1596
- var rotationMatrix;
1597
- rotationMatrix = Matrix(Math.cos(theta), Math.sin(theta), -Math.sin(theta), Math.cos(theta));
1598
- if (aboutPoint != null) {
1599
- rotationMatrix = Matrix.translation(aboutPoint.x, aboutPoint.y).concat(rotationMatrix).concat(Matrix.translation(-aboutPoint.x, -aboutPoint.y));
1600
- }
1601
- return rotationMatrix;
1602
- };
1603
- /**
1604
- Returns a matrix that corresponds to scaling by factors of sx, sy along
1605
- the x and y axis respectively.
1606
- If only one parameter is given the matrix is scaled uniformly along both axis.
1607
- If the optional aboutPoint parameter is given the scaling takes place
1608
- about the given point.
1609
- @see Matrix#scale
1610
- @param {Number} sx The amount to scale by along the x axis or uniformly if no sy is given.
1611
- @param {Number} [sy] The amount to scale by along the y axis.
1612
- @param {Point} [aboutPoint] The point about which the scaling occurs. Defaults to (0,0).
1613
- @returns {Matrix} A matrix transformation representing scaling by sx and sy.
1614
- */
1615
-
1616
- Matrix.scale = function(sx, sy, aboutPoint) {
1617
- var scaleMatrix;
1618
- sy = sy || sx;
1619
- scaleMatrix = Matrix(sx, 0, 0, sy);
1620
- if (aboutPoint) {
1621
- scaleMatrix = Matrix.translation(aboutPoint.x, aboutPoint.y).concat(scaleMatrix).concat(Matrix.translation(-aboutPoint.x, -aboutPoint.y));
1622
- }
1623
- return scaleMatrix;
1624
- };
1625
- /**
1626
- Returns a matrix that corresponds to a skew of skewX, skewY.
1627
-
1628
- @see Matrix#skew
1629
- @param {Number} skewX The angle of skew in the x dimension.
1630
- @param {Number} skewY The angle of skew in the y dimension.
1631
- @return {Matrix} A matrix transformation representing a skew by skewX and skewY.
1632
- */
1633
-
1634
- Matrix.skew = function(skewX, skewY) {
1635
- return Matrix(0, Math.tan(skewY), Math.tan(skewX), 0);
1636
- };
1637
- /**
1638
- Returns a matrix that corresponds to a translation of tx, ty.
1639
- @see Matrix#translate
1640
- @param {Number} tx The amount to translate in the x direction.
1641
- @param {Number} ty The amount to translate in the y direction.
1642
- @return {Matrix} A matrix transformation representing a translation by tx and ty.
1643
- */
1644
-
1645
- Matrix.translate = Matrix.translation = function(tx, ty) {
1646
- return Matrix(1, 0, 0, 1, tx, ty);
1647
- };
1648
- /**
1649
- A constant representing the identity matrix.
1650
- @name IDENTITY
1651
- @fieldOf Matrix
1652
- */
1653
-
1654
- Matrix.IDENTITY = Matrix();
1655
- /**
1656
- A constant representing the horizontal flip transformation matrix.
1657
- @name HORIZONTAL_FLIP
1658
- @fieldOf Matrix
1659
- */
1660
-
1661
- Matrix.HORIZONTAL_FLIP = Matrix(-1, 0, 0, 1);
1662
- /**
1663
- A constant representing the vertical flip transformation matrix.
1664
- @name VERTICAL_FLIP
1665
- @fieldOf Matrix
1666
- */
1667
-
1668
- Matrix.VERTICAL_FLIP = Matrix(1, 0, 0, -1);
1669
- if (Object.freeze) {
1670
- Object.freeze(Matrix.IDENTITY);
1671
- Object.freeze(Matrix.HORIZONTAL_FLIP);
1672
- Object.freeze(Matrix.VERTICAL_FLIP);
1673
- }
1674
- return (typeof exports !== "undefined" && exports !== null ? exports : this)["Matrix"] = Matrix;
1675
- })();
1676
-
1677
- }).call(this);
1678
-
1679
- /**
1680
- Returns the absolute value of this number.
1681
-
1682
- (-4).abs()
1683
- # => 4
1684
-
1685
- @name abs
1686
- @methodOf Number#
1687
- @returns {Number} The absolute value of the number.
1688
- */
1689
-
1690
-
1691
- (function() {
1692
-
1693
- Number.prototype.abs = function() {
1694
- return Math.abs(this);
1695
- };
1696
-
1697
- /**
1698
- Returns the mathematical ceiling of this number.
1699
-
1700
- 4.9.ceil()
1701
- # => 5
1702
-
1703
- 4.2.ceil()
1704
- # => 5
1705
-
1706
- (-1.2).ceil()
1707
- # => -1
1708
-
1709
- @name ceil
1710
- @methodOf Number#
1711
- @returns {Number} The number truncated to the nearest integer of greater than or equal value.
1712
- */
1713
-
1714
-
1715
- Number.prototype.ceil = function() {
1716
- return Math.ceil(this);
1717
- };
1718
-
1719
- /**
1720
- Returns the mathematical floor of this number.
1721
-
1722
- 4.9.floor()
1723
- # => 4
1724
-
1725
- 4.2.floor()
1726
- # => 4
1727
-
1728
- (-1.2).floor()
1729
- # => -2
1730
-
1731
- @name floor
1732
- @methodOf Number#
1733
- @returns {Number} The number truncated to the nearest integer of less than or equal value.
1734
- */
1735
-
1736
-
1737
- Number.prototype.floor = function() {
1738
- return Math.floor(this);
1739
- };
1740
-
1741
- /**
1742
- Returns this number rounded to the nearest integer.
1743
-
1744
- 4.5.round()
1745
- # => 5
1746
-
1747
- 4.4.round()
1748
- # => 4
1749
-
1750
- @name round
1751
- @methodOf Number#
1752
- @returns {Number} The number rounded to the nearest integer.
1753
- */
1754
-
1755
-
1756
- Number.prototype.round = function() {
1757
- return Math.round(this);
1758
- };
1759
-
1760
- /**
1761
- Get a bunch of points equally spaced around the unit circle.
1762
-
1763
- 4.circularPoints (p) ->
1764
-
1765
- # p gets Point(1, 0), Point(0, 1), Point(-1, 0), Point(0, -1)
1766
-
1767
- @name circularPoint
1768
- @methodOf Number#
1769
- */
1770
-
1771
-
1772
- Number.prototype.circularPoints = function(block) {
1773
- var n;
1774
- n = this;
1775
- return n.times(function(i) {
1776
- return block(Point.fromAngle((i / n).turns), i);
1777
- });
1778
- };
1779
-
1780
- /**
1781
- Returns a number whose value is limited to the given range.
1782
-
1783
- # limit the output of this computation to between 0 and 255
1784
- (2 * 255).clamp(0, 255)
1785
- # => 255
1786
-
1787
- @name clamp
1788
- @methodOf Number#
1789
- @param {Number} min The lower boundary of the output range
1790
- @param {Number} max The upper boundary of the output range
1791
- @returns {Number} A number in the range [min, max]
1792
- */
1793
-
1794
-
1795
- Number.prototype.clamp = function(min, max) {
1796
- if ((min != null) && (max != null)) {
1797
- return Math.min(Math.max(this, min), max);
1798
- } else if (min != null) {
1799
- return Math.max(this, min);
1800
- } else if (max != null) {
1801
- return Math.min(this, max);
1802
- } else {
1803
- return this;
1804
- }
1805
- };
1806
-
1807
- /**
1808
- A mod method useful for array wrapping. The range of the function is
1809
- constrained to remain in bounds of array indices.
1810
-
1811
- (-1).mod(5)
1812
- # => 4
1813
-
1814
- @name mod
1815
- @methodOf Number#
1816
- @param {Number} base
1817
- @returns {Number} An integer between 0 and (base - 1) if base is positive.
1818
- */
1819
-
1820
-
1821
- Number.prototype.mod = function(base) {
1822
- var result;
1823
- result = this % base;
1824
- if (result < 0 && base > 0) {
1825
- result += base;
1826
- }
1827
- return result;
1828
- };
1829
-
1830
- /**
1831
- Get the sign of this number as an integer (1, -1, or 0).
1832
-
1833
- (-5).sign()
1834
- # => -1
1835
-
1836
- 0.sign()
1837
- # => 0
1838
-
1839
- 5.sign()
1840
- # => 1
1841
-
1842
- @name sign
1843
- @methodOf Number#
1844
- @returns {Number} The sign of this number, 0 if the number is 0.
1845
- */
1846
-
1847
-
1848
- Number.prototype.sign = function() {
1849
- if (this > 0) {
1850
- return 1;
1851
- } else if (this < 0) {
1852
- return -1;
1853
- } else {
1854
- return 0;
1855
- }
1856
- };
1857
-
1858
- /**
1859
- Returns true if this number is even (evenly divisible by 2).
1860
-
1861
- 2.even()
1862
- # => true
1863
-
1864
- 3.even()
1865
- # => false
1866
-
1867
- 0.even()
1868
- # => true
1869
-
1870
- @name even
1871
- @methodOf Number#
1872
- @returns {Boolean} true if this number is an even integer, false otherwise.
1873
- */
1874
-
1875
-
1876
- Number.prototype.even = function() {
1877
- return this % 2 === 0;
1878
- };
1879
-
1880
- /**
1881
- Returns true if this number is odd (has remainder of 1 when divided by 2).
1882
-
1883
- 2.odd()
1884
- # => false
1885
-
1886
- 3.odd()
1887
- # => true
1888
-
1889
- 0.odd()
1890
- # => false
1891
-
1892
- @name odd
1893
- @methodOf Number#
1894
- @returns {Boolean} true if this number is an odd integer, false otherwise.
1895
- */
1896
-
1897
-
1898
- Number.prototype.odd = function() {
1899
- if (this > 0) {
1900
- return this % 2 === 1;
1901
- } else {
1902
- return this % 2 === -1;
1903
- }
1904
- };
1905
-
1906
- /**
1907
- Calls iterator the specified number of times, passing in the number of the
1908
- current iteration as a parameter: 0 on first call, 1 on the second call, etc.
1909
-
1910
- output = []
1911
-
1912
- 5.times (n) ->
1913
- output.push(n)
1914
-
1915
- output
1916
- # => [0, 1, 2, 3, 4]
1917
-
1918
- @name times
1919
- @methodOf Number#
1920
- @param {Function} iterator The iterator takes a single parameter, the number of the current iteration.
1921
- @param {Object} [context] The optional context parameter specifies an object to treat as <code>this</code> in the iterator block.
1922
- @returns {Number} The number of times the iterator was called.
1923
- */
1924
-
1925
-
1926
- Number.prototype.times = function(iterator, context) {
1927
- var i;
1928
- i = -1;
1929
- while (++i < this) {
1930
- iterator.call(context, i);
1931
- }
1932
- return i;
1933
- };
1934
-
1935
- /**
1936
- Returns the the nearest grid resolution less than or equal to the number.
1937
-
1938
- 7.snap(8)
1939
- # => 0
1940
-
1941
- 4.snap(8)
1942
- # => 0
1943
-
1944
- 12.snap(8)
1945
- # => 8
1946
-
1947
- @name snap
1948
- @methodOf Number#
1949
- @param {Number} resolution The grid resolution to snap to.
1950
- @returns {Number} The nearest multiple of resolution lower than the number.
1951
- */
1952
-
1953
-
1954
- Number.prototype.snap = function(resolution) {
1955
- var n;
1956
- n = this / resolution;
1957
- 1 / 1;
1958
- return n.floor() * resolution;
1959
- };
1960
-
1961
- /**
1962
- In number theory, integer factorization or prime factorization is the
1963
- breaking down of a composite number into smaller non-trivial divisors,
1964
- which when multiplied together equal the original integer.
1965
-
1966
- Floors the number for purposes of factorization.
1967
-
1968
- 60.primeFactors()
1969
- # => [2, 2, 3, 5]
1970
-
1971
- 37.primeFactors()
1972
- # => [37]
1973
-
1974
- @name primeFactors
1975
- @methodOf Number#
1976
- @returns {Array} An array containing the factorization of this number.
1977
- */
1978
-
1979
-
1980
- Number.prototype.primeFactors = function() {
1981
- var factors, i, iSquared, n;
1982
- factors = [];
1983
- n = Math.floor(this);
1984
- if (n === 0) {
1985
- return void 0;
1986
- }
1987
- if (n < 0) {
1988
- factors.push(-1);
1989
- n /= -1;
1990
- }
1991
- i = 2;
1992
- iSquared = i * i;
1993
- while (iSquared < n) {
1994
- while ((n % i) === 0) {
1995
- factors.push(i);
1996
- n /= i;
1997
- }
1998
- i += 1;
1999
- iSquared = i * i;
2000
- }
2001
- if (n !== 1) {
2002
- factors.push(n);
2003
- }
2004
- return factors;
2005
- };
2006
-
2007
- /**
2008
- Returns the two character hexidecimal
2009
- representation of numbers 0 through 255.
2010
-
2011
- 255.toColorPart()
2012
- # => "ff"
2013
-
2014
- 0.toColorPart()
2015
- # => "00"
2016
-
2017
- 200.toColorPart()
2018
- # => "c8"
2019
-
2020
- @name toColorPart
2021
- @methodOf Number#
2022
- @returns {String} Hexidecimal representation of the number
2023
- */
2024
-
2025
-
2026
- Number.prototype.toColorPart = function() {
2027
- var s;
2028
- s = parseInt(this.clamp(0, 255), 10).toString(16);
2029
- if (s.length === 1) {
2030
- s = '0' + s;
2031
- }
2032
- return s;
2033
- };
2034
-
2035
- /**
2036
- Returns a number that is maxDelta closer to target.
2037
-
2038
- 255.approach(0, 5)
2039
- # => 250
2040
-
2041
- 5.approach(0, 10)
2042
- # => 0
2043
-
2044
- @name approach
2045
- @methodOf Number#
2046
- @returns {Number} A number maxDelta toward target
2047
- */
2048
-
2049
-
2050
- Number.prototype.approach = function(target, maxDelta) {
2051
- return (target - this).clamp(-maxDelta, maxDelta) + this;
2052
- };
2053
-
2054
- /**
2055
- Returns a number that is closer to the target by the ratio.
2056
-
2057
- 255.approachByRatio(0, 0.1)
2058
- # => 229.5
2059
-
2060
- @name approachByRatio
2061
- @methodOf Number#
2062
- @returns {Number} A number toward target by the ratio
2063
- */
2064
-
2065
-
2066
- Number.prototype.approachByRatio = function(target, ratio) {
2067
- return this.approach(target, this * ratio);
2068
- };
2069
-
2070
- /**
2071
- Returns a number that is closer to the target angle by the delta.
2072
-
2073
- Math.PI.approachRotation(0, Math.PI/4)
2074
- # => 2.356194490192345 # this is (3/4) * Math.PI, which is (1/4) * Math.PI closer to 0 from Math.PI
2075
-
2076
- @name approachRotation
2077
- @methodOf Number#
2078
- @returns {Number} A number toward the target angle by maxDelta
2079
- */
2080
-
2081
-
2082
- Number.prototype.approachRotation = function(target, maxDelta) {
2083
- while (target > this + Math.PI) {
2084
- target -= Math.TAU;
2085
- }
2086
- while (target < this - Math.PI) {
2087
- target += Math.TAU;
2088
- }
2089
- return (target - this).clamp(-maxDelta, maxDelta) + this;
2090
- };
2091
-
2092
- /**
2093
- Constrains a rotation to between -PI and PI.
2094
-
2095
- (9/4 * Math.PI).constrainRotation()
2096
- # => 0.7853981633974483 # this is (1/4) * Math.PI
2097
-
2098
- @name constrainRotation
2099
- @methodOf Number#
2100
- @returns {Number} This number constrained between -PI and PI.
2101
- */
2102
-
2103
-
2104
- Number.prototype.constrainRotation = function() {
2105
- var target;
2106
- target = this;
2107
- while (target > Math.PI) {
2108
- target -= Math.TAU;
2109
- }
2110
- while (target < -Math.PI) {
2111
- target += Math.TAU;
2112
- }
2113
- return target;
2114
- };
2115
-
2116
- /**
2117
- The mathematical d operator. Useful for simulating dice rolls.
2118
-
2119
- @name d
2120
- @methodOf Number#
2121
- @returns {Number} The sum of rolling <code>this</code> many <code>sides</code>-sided dice
2122
- */
2123
-
2124
-
2125
- Number.prototype.d = function(sides) {
2126
- var sum;
2127
- sum = 0;
2128
- this.times(function() {
2129
- return sum += rand(sides) + 1;
2130
- });
2131
- return sum;
2132
- };
2133
-
2134
- /**
2135
- Utility method to convert a number to a duration of seconds.
2136
-
2137
- 3.seconds
2138
- # => 3000
2139
-
2140
- setTimout doSometing, 3.seconds
2141
-
2142
- @name seconds
2143
- @propertyOf Number#
2144
- @returns {Number} This number as a duration of seconds
2145
- */
2146
-
2147
-
2148
- if (!5..seconds) {
2149
- Object.defineProperty(Number.prototype, 'seconds', {
2150
- get: function() {
2151
- return this * 1000;
2152
- }
2153
- });
2154
- }
2155
-
2156
- if (!1..second) {
2157
- Object.defineProperty(Number.prototype, 'second', {
2158
- get: function() {
2159
- return this * 1000;
2160
- }
2161
- });
2162
- }
2163
-
2164
- /**
2165
- Utility method to convert a number to an amount of rotations.
2166
-
2167
- 0.5.rotations
2168
- # => 3.141592653589793
2169
-
2170
- I.rotation = 0.25.rotations
2171
-
2172
- @name rotations
2173
- @propertyOf Number#
2174
- @returns {Number} This number as an amount of rotations
2175
- */
2176
-
2177
-
2178
- if (!5..rotations) {
2179
- Object.defineProperty(Number.prototype, 'rotations', {
2180
- get: function() {
2181
- return this * Math.TAU;
2182
- }
2183
- });
2184
- }
2185
-
2186
- if (!1..rotation) {
2187
- Object.defineProperty(Number.prototype, 'rotation', {
2188
- get: function() {
2189
- return this * Math.TAU;
2190
- }
2191
- });
2192
- }
2193
-
2194
- /**
2195
- Utility method to convert a number to an amount of rotations.
2196
-
2197
- 0.5.turns
2198
- # => 3.141592653589793
2199
-
2200
- I.rotation = 0.25.turns
2201
-
2202
- 1.turn # => Math.TAU (aka 2 * Math.PI)
2203
-
2204
- @name turns
2205
- @propertyOf Number#
2206
- @returns {Number} This number as an amount of rotation.
2207
- 1 turn is one complete rotation.
2208
- */
2209
-
2210
-
2211
- if (!5..turns) {
2212
- Object.defineProperty(Number.prototype, 'turns', {
2213
- get: function() {
2214
- return this * Math.TAU;
2215
- }
2216
- });
2217
- }
2218
-
2219
- if (!1..turn) {
2220
- Object.defineProperty(Number.prototype, 'turn', {
2221
- get: function() {
2222
- return this * Math.TAU;
2223
- }
2224
- });
2225
- }
2226
-
2227
- /**
2228
- Utility method to convert a number to an amount of degrees.
2229
-
2230
- 180.degrees
2231
- # => 3.141592653589793
2232
-
2233
- I.rotation = 90.degrees
2234
-
2235
- @name degrees
2236
- @propertyOf Number#
2237
- @returns {Number} This number as an amount of degrees
2238
- */
2239
-
2240
-
2241
- if (!2..degrees) {
2242
- Object.defineProperty(Number.prototype, 'degrees', {
2243
- get: function() {
2244
- return this * Math.TAU / 360;
2245
- }
2246
- });
2247
- }
2248
-
2249
- if (!1..degree) {
2250
- Object.defineProperty(Number.prototype, 'degree', {
2251
- get: function() {
2252
- return this * Math.TAU / 360;
2253
- }
2254
- });
2255
- }
2256
-
2257
- /**
2258
- The mathematical circle constant of 1 turn.
2259
-
2260
- @name TAU
2261
- @fieldOf Math
2262
- */
2263
-
2264
-
2265
- Math.TAU = 2 * Math.PI;
2266
-
2267
- }).call(this);
2268
- (function() {
2269
- var __slice = [].slice;
2270
-
2271
- (function() {
2272
- /**
2273
- Create a new point with given x and y coordinates. If no arguments are given
2274
- defaults to (0, 0).
2275
-
2276
- point = Point()
2277
-
2278
- p.x
2279
- # => 0
2280
-
2281
- p.y
2282
- # => 0
2283
-
2284
- point = Point(-2, 5)
2285
-
2286
- p.x
2287
- # => -2
2288
-
2289
- p.y
2290
- # => 5
2291
-
2292
- @name Point
2293
- @param {Number} [x]
2294
- @param {Number} [y]
2295
- @constructor
2296
- */
2297
-
2298
- var Point;
2299
- Point = function(x, y) {
2300
- var _ref;
2301
- if (Object.isObject(x)) {
2302
- _ref = x, x = _ref.x, y = _ref.y;
2303
- }
2304
- return {
2305
- __proto__: Point.prototype,
2306
- /**
2307
- The x coordinate of this point.
2308
- @name x
2309
- @fieldOf Point#
2310
- */
2311
-
2312
- x: x || 0,
2313
- /**
2314
- The y coordinate of this point.
2315
- @name y
2316
- @fieldOf Point#
2317
- */
2318
-
2319
- y: y || 0
2320
- };
2321
- };
2322
- Point.prototype = {
2323
- /**
2324
- Constrain the magnitude of a vector.
2325
-
2326
- @name clamp
2327
- @methodOf Point#
2328
- @param {Number} n Maximum value for magnitude.
2329
- @returns {Point} A new point whose magnitude has been clamped to the given value.
2330
- */
2331
-
2332
- clamp: function(n) {
2333
- return this.copy().clamp$(n);
2334
- },
2335
- clamp$: function(n) {
2336
- if (this.magnitude() > n) {
2337
- return this.norm$(n);
2338
- } else {
2339
- return this;
2340
- }
2341
- },
2342
- /**
2343
- Creates a copy of this point.
2344
-
2345
- @name copy
2346
- @methodOf Point#
2347
- @returns {Point} A new point with the same x and y value as this point.
2348
-
2349
- point = Point(1, 1)
2350
- pointCopy = point.copy()
2351
-
2352
- point.equal(pointCopy)
2353
- # => true
2354
-
2355
- point == pointCopy
2356
- # => false
2357
- */
2358
-
2359
- copy: function() {
2360
- return Point(this.x, this.y);
2361
- },
2362
- /**
2363
- Adds a point to this one and returns the new point. You may
2364
- also use a two argument call like <code>point.add(x, y)</code>
2365
- to add x and y values without a second point object.
2366
-
2367
- point = Point(2, 3).add(Point(3, 4))
2368
-
2369
- point.x
2370
- # => 5
2371
-
2372
- point.y
2373
- # => 7
2374
-
2375
- anotherPoint = Point(2, 3).add(3, 4)
2376
-
2377
- anotherPoint.x
2378
- # => 5
2379
-
2380
- anotherPoint.y
2381
- # => 7
2382
-
2383
- @name add
2384
- @methodOf Point#
2385
- @param {Point} other The point to add this point to.
2386
- @returns {Point} A new point, the sum of both.
2387
- */
2388
-
2389
- add: function(first, second) {
2390
- return this.copy().add$(first, second);
2391
- },
2392
- /**
2393
- Adds a point to this one, returning a modified point. You may
2394
- also use a two argument call like <code>point.add(x, y)</code>
2395
- to add x and y values without a second point object.
2396
-
2397
- point = Point(2, 3)
2398
-
2399
- point.x
2400
- # => 2
2401
-
2402
- point.y
2403
- # => 3
2404
-
2405
- point.add$(Point(3, 4))
2406
-
2407
- point.x
2408
- # => 5
2409
-
2410
- point.y
2411
- # => 7
2412
-
2413
- anotherPoint = Point(2, 3)
2414
- anotherPoint.add$(3, 4)
2415
-
2416
- anotherPoint.x
2417
- # => 5
2418
-
2419
- anotherPoint.y
2420
- # => 7
2421
-
2422
- @name add$
2423
- @methodOf Point#
2424
- @param {Point} other The point to add this point to.
2425
- @returns {Point} The sum of both points.
2426
- */
2427
-
2428
- add$: function(first, second) {
2429
- if (second != null) {
2430
- this.x += first;
2431
- this.y += second;
2432
- } else {
2433
- this.x += first.x;
2434
- this.y += first.y;
2435
- }
2436
- return this;
2437
- },
2438
- /**
2439
- Subtracts a point to this one and returns the new point.
2440
-
2441
- point = Point(1, 2).subtract(Point(2, 0))
2442
-
2443
- point.x
2444
- # => -1
2445
-
2446
- point.y
2447
- # => 2
2448
-
2449
- anotherPoint = Point(1, 2).subtract(2, 0)
2450
-
2451
- anotherPoint.x
2452
- # => -1
2453
-
2454
- anotherPoint.y
2455
- # => 2
2456
-
2457
- @name subtract
2458
- @methodOf Point#
2459
- @param {Point} other The point to subtract from this point.
2460
- @returns {Point} A new point, this - other.
2461
- */
2462
-
2463
- subtract: function(first, second) {
2464
- return this.copy().subtract$(first, second);
2465
- },
2466
- /**
2467
- Subtracts a point to this one and returns the new point.
2468
-
2469
- point = Point(1, 2)
2470
-
2471
- point.x
2472
- # => 1
2473
-
2474
- point.y
2475
- # => 2
2476
-
2477
- point.subtract$(Point(2, 0))
2478
-
2479
- point.x
2480
- # => -1
2481
-
2482
- point.y
2483
- # => 2
2484
-
2485
- anotherPoint = Point(1, 2)
2486
- anotherPoint.subtract$(2, 0)
2487
-
2488
- anotherPoint.x
2489
- # => -1
2490
-
2491
- anotherPoint.y
2492
- # => 2
2493
-
2494
- @name subtract$
2495
- @methodOf Point#
2496
- @param {Point} other The point to subtract from this point.
2497
- @returns {Point} The difference of the two points.
2498
- */
2499
-
2500
- subtract$: function(first, second) {
2501
- if (second != null) {
2502
- this.x -= first;
2503
- this.y -= second;
2504
- } else {
2505
- this.x -= first.x;
2506
- this.y -= first.y;
2507
- }
2508
- return this;
2509
- },
2510
- /**
2511
- Scale this Point (Vector) by a constant amount.
2512
-
2513
- point = Point(5, 6).scale(2)
2514
-
2515
- point.x
2516
- # => 10
2517
-
2518
- point.y
2519
- # => 12
2520
-
2521
- @name scale
2522
- @methodOf Point#
2523
- @param {Number} scalar The amount to scale this point by.
2524
- @returns {Point} A new point, this * scalar.
2525
- */
2526
-
2527
- scale: function(scalar) {
2528
- return this.copy().scale$(scalar);
2529
- },
2530
- /**
2531
- Scale this Point (Vector) by a constant amount. Modifies the point in place.
2532
-
2533
- point = Point(5, 6)
2534
-
2535
- point.x
2536
- # => 5
2537
-
2538
- point.y
2539
- # => 6
2540
-
2541
- point.scale$(2)
2542
-
2543
- point.x
2544
- # => 10
2545
-
2546
- point.y
2547
- # => 12
2548
-
2549
- @name scale$
2550
- @methodOf Point#
2551
- @param {Number} scalar The amount to scale this point by.
2552
- @returns {Point} this * scalar.
2553
- */
2554
-
2555
- scale$: function(scalar) {
2556
- this.x *= scalar;
2557
- this.y *= scalar;
2558
- return this;
2559
- },
2560
- /**
2561
- The norm of a vector is the unit vector pointing in the same direction. This method
2562
- treats the point as though it is a vector from the origin to (x, y).
2563
-
2564
- point = Point(2, 3).norm()
2565
-
2566
- point.x
2567
- # => 0.5547001962252291
2568
-
2569
- point.y
2570
- # => 0.8320502943378437
2571
-
2572
- anotherPoint = Point(2, 3).norm(2)
2573
-
2574
- anotherPoint.x
2575
- # => 1.1094003924504583
2576
-
2577
- anotherPoint.y
2578
- # => 1.6641005886756874
2579
-
2580
- @name norm
2581
- @methodOf Point#
2582
- @returns {Point} The unit vector pointing in the same direction as this vector.
2583
- */
2584
-
2585
- norm: function(length) {
2586
- if (length == null) {
2587
- length = 1.0;
2588
- }
2589
- return this.copy().norm$(length);
2590
- },
2591
- /**
2592
- The norm of a vector is the unit vector pointing in the same direction. This method
2593
- treats the point as though it is a vector from the origin to (x, y). Modifies the point in place.
2594
-
2595
- point = Point(2, 3).norm$()
2596
-
2597
- point.x
2598
- # => 0.5547001962252291
2599
-
2600
- point.y
2601
- # => 0.8320502943378437
2602
-
2603
- anotherPoint = Point(2, 3).norm$(2)
2604
-
2605
- anotherPoint.x
2606
- # => 1.1094003924504583
2607
-
2608
- anotherPoint.y
2609
- # => 1.6641005886756874
2610
-
2611
- @name norm$
2612
- @methodOf Point#
2613
- @returns {Point} The unit vector pointing in the same direction as this vector.
2614
- */
2615
-
2616
- norm$: function(length) {
2617
- var m;
2618
- if (length == null) {
2619
- length = 1.0;
2620
- }
2621
- if (m = this.length()) {
2622
- return this.scale$(length / m);
2623
- } else {
2624
- return this;
2625
- }
2626
- },
2627
- /**
2628
- Floor the x and y values, returning a new point.
2629
-
2630
- point = Point(3.4, 5.8).floor()
2631
-
2632
- point.x
2633
- # => 3
2634
-
2635
- point.y
2636
- # => 5
2637
-
2638
- @name floor
2639
- @methodOf Point#
2640
- @returns {Point} A new point, with x and y values each floored to the largest previous integer.
2641
- */
2642
-
2643
- floor: function() {
2644
- return this.copy().floor$();
2645
- },
2646
- /**
2647
- Floor the x and y values, returning a modified point.
2648
-
2649
- point = Point(3.4, 5.8)
2650
- point.floor$()
2651
-
2652
- point.x
2653
- # => 3
2654
-
2655
- point.y
2656
- # => 5
2657
-
2658
- @name floor$
2659
- @methodOf Point#
2660
- @returns {Point} A modified point, with x and y values each floored to the largest previous integer.
2661
- */
2662
-
2663
- floor$: function() {
2664
- this.x = this.x.floor();
2665
- this.y = this.y.floor();
2666
- return this;
2667
- },
2668
- /**
2669
- Determine whether this point is equal to another point.
2670
-
2671
- pointA = Point(2, 3)
2672
- pointB = Point(2, 3)
2673
- pointC = Point(4, 5)
2674
-
2675
- pointA.equal(pointB)
2676
- # => true
2677
-
2678
- pointA.equal(pointC)
2679
- # => false
2680
-
2681
- @name equal
2682
- @methodOf Point#
2683
- @param {Point} other The point to check for equality.
2684
- @returns {Boolean} true if the other point has the same x, y coordinates, false otherwise.
2685
- */
2686
-
2687
- equal: function(other) {
2688
- return this.x === other.x && this.y === other.y;
2689
- },
2690
- /**
2691
- Computed the length of this point as though it were a vector from (0,0) to (x,y).
2692
-
2693
- point = Point(5, 7)
2694
-
2695
- point.length()
2696
- # => 8.602325267042627
2697
-
2698
- @name length
2699
- @methodOf Point#
2700
- @returns {Number} The length of the vector from the origin to this point.
2701
- */
2702
-
2703
- length: function() {
2704
- return Math.sqrt(this.dot(this));
2705
- },
2706
- /**
2707
- Calculate the magnitude of this Point (Vector).
2708
-
2709
- point = Point(5, 7)
2710
-
2711
- point.magnitude()
2712
- # => 8.602325267042627
2713
-
2714
- @name magnitude
2715
- @methodOf Point#
2716
- @returns {Number} The magnitude of this point as if it were a vector from (0, 0) -> (x, y).
2717
- */
2718
-
2719
- magnitude: function() {
2720
- return this.length();
2721
- },
2722
- /**
2723
- Returns the direction in radians of this point from the origin.
2724
-
2725
- point = Point(0, 1)
2726
-
2727
- point.direction()
2728
- # => 1.5707963267948966 # Math.PI / 2
2729
-
2730
- @name direction
2731
- @methodOf Point#
2732
- @returns {Number} The direction in radians of this point from the origin
2733
- */
2734
-
2735
- direction: function() {
2736
- return Math.atan2(this.y, this.x);
2737
- },
2738
- /**
2739
- Calculate the dot product of this point and another point (Vector).
2740
- @name dot
2741
- @methodOf Point#
2742
- @param {Point} other The point to dot with this point.
2743
- @returns {Number} The dot product of this point dot other as a scalar value.
2744
- */
2745
-
2746
- dot: function(other) {
2747
- return this.x * other.x + this.y * other.y;
2748
- },
2749
- /**
2750
- Calculate the cross product of this point and another point (Vector).
2751
- Usually cross products are thought of as only applying to three dimensional vectors,
2752
- but z can be treated as zero. The result of this method is interpreted as the magnitude
2753
- of the vector result of the cross product between [x1, y1, 0] x [x2, y2, 0]
2754
- perpendicular to the xy plane.
2755
-
2756
- @name cross
2757
- @methodOf Point#
2758
- @param {Point} other The point to cross with this point.
2759
- @returns {Number} The cross product of this point with the other point as scalar value.
2760
- */
2761
-
2762
- cross: function(other) {
2763
- return this.x * other.y - other.x * this.y;
2764
- },
2765
- /**
2766
- Compute the Euclidean distance between this point and another point.
2767
-
2768
- pointA = Point(2, 3)
2769
- pointB = Point(9, 2)
2770
-
2771
- pointA.distance(pointB)
2772
- # => 7.0710678118654755 # Math.sqrt(50)
2773
-
2774
- @name distance
2775
- @methodOf Point#
2776
- @param {Point} other The point to compute the distance to.
2777
- @returns {Number} The distance between this point and another point.
2778
- */
2779
-
2780
- distance: function(other) {
2781
- return Point.distance(this, other);
2782
- },
2783
- /**
2784
- @name toString
2785
- @methodOf Point#
2786
- @returns {String} A string representation of this point.
2787
- */
2788
-
2789
- toString: function() {
2790
- return "Point(" + this.x + ", " + this.y + ")";
2791
- }
2792
- };
2793
- /**
2794
- Compute the Euclidean distance between two points.
2795
-
2796
- pointA = Point(2, 3)
2797
- pointB = Point(9, 2)
2798
-
2799
- Point.distance(pointA, pointB)
2800
- # => 7.0710678118654755 # Math.sqrt(50)
2801
-
2802
- @name distance
2803
- @fieldOf Point
2804
- @param {Point} p1
2805
- @param {Point} p2
2806
- @returns {Number} The Euclidean distance between two points.
2807
- */
2808
-
2809
- Point.distance = function(p1, p2) {
2810
- return Math.sqrt(Point.distanceSquared(p1, p2));
2811
- };
2812
- /**
2813
- pointA = Point(2, 3)
2814
- pointB = Point(9, 2)
2815
-
2816
- Point.distanceSquared(pointA, pointB)
2817
- # => 50
2818
-
2819
- @name distanceSquared
2820
- @fieldOf Point
2821
- @param {Point} p1
2822
- @param {Point} p2
2823
- @returns {Number} The square of the Euclidean distance between two points.
2824
- */
2825
-
2826
- Point.distanceSquared = function(p1, p2) {
2827
- return Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2);
2828
- };
2829
- /**
2830
- @name interpolate
2831
- @fieldOf Point
2832
-
2833
- @param {Point} p1
2834
- @param {Point} p2
2835
- @param {Number} t
2836
- @returns {Point} A point along the path from p1 to p2
2837
- */
2838
-
2839
- Point.interpolate = function(p1, p2, t) {
2840
- return p2.subtract(p1).scale(t).add(p1);
2841
- };
2842
- /**
2843
- Construct a point on the unit circle for the given angle.
2844
-
2845
- point = Point.fromAngle(Math.PI / 2)
2846
-
2847
- point.x
2848
- # => 0
2849
-
2850
- point.y
2851
- # => 1
2852
-
2853
- @name fromAngle
2854
- @fieldOf Point
2855
- @param {Number} angle The angle in radians
2856
- @returns {Point} The point on the unit circle.
2857
- */
2858
-
2859
- Point.fromAngle = function(angle) {
2860
- return Point(Math.cos(angle), Math.sin(angle));
2861
- };
2862
- /**
2863
- If you have two dudes, one standing at point p1, and the other
2864
- standing at point p2, then this method will return the direction
2865
- that the dude standing at p1 will need to face to look at p2.
2866
-
2867
- p1 = Point(0, 0)
2868
- p2 = Point(7, 3)
2869
-
2870
- Point.direction(p1, p2)
2871
- # => 0.40489178628508343
2872
-
2873
- @name direction
2874
- @fieldOf Point
2875
- @param {Point} p1 The starting point.
2876
- @param {Point} p2 The ending point.
2877
- @returns {Number} The direction from p1 to p2 in radians.
2878
- */
2879
-
2880
- Point.direction = function(p1, p2) {
2881
- return Math.atan2(p2.y - p1.y, p2.x - p1.x);
2882
- };
2883
- /**
2884
- The centroid of a set of points is their arithmetic mean.
2885
-
2886
- @name centroid
2887
- @methodOf Point
2888
- @param points... The points to find the centroid of.
2889
- */
2890
-
2891
- Point.centroid = function() {
2892
- var points;
2893
- points = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
2894
- return points.inject(Point(0, 0), function(sumPoint, point) {
2895
- return sumPoint.add(point);
2896
- }).scale(1 / points.length);
2897
- };
2898
- /**
2899
- Generate a random point on the unit circle.
2900
-
2901
- @returns {Point} A random point on the unit circle.
2902
- */
2903
-
2904
- Point.random = function() {
2905
- return Point.fromAngle(Random.angle());
2906
- };
2907
- /**
2908
- @name ZERO
2909
- @fieldOf Point
2910
- @returns {Point} The point (0, 0)
2911
- */
2912
-
2913
- Point.ZERO = Point(0, 0);
2914
- /**
2915
- @name LEFT
2916
- @fieldOf Point
2917
- @returns {Point} The point (-1, 0)
2918
- */
2919
-
2920
- Point.LEFT = Point(-1, 0);
2921
- /**
2922
- @name RIGHT
2923
- @fieldOf Point
2924
- @returns {Point} The point (1, 0)
2925
- */
2926
-
2927
- Point.RIGHT = Point(1, 0);
2928
- /**
2929
- @name UP
2930
- @fieldOf Point
2931
- @returns {Point} The point (0, -1)
2932
- */
2933
-
2934
- Point.UP = Point(0, -1);
2935
- /**
2936
- @name DOWN
2937
- @fieldOf Point
2938
- @returns {Point} The point (0, 1)
2939
- */
2940
-
2941
- Point.DOWN = Point(0, 1);
2942
- if (Object.freeze) {
2943
- Object.freeze(Point.ZERO);
2944
- Object.freeze(Point.LEFT);
2945
- Object.freeze(Point.RIGHT);
2946
- Object.freeze(Point.UP);
2947
- Object.freeze(Point.DOWN);
2948
- }
2949
- return (typeof exports !== "undefined" && exports !== null ? exports : this)["Point"] = Point;
2950
- })();
2951
-
2952
- }).call(this);
2953
- (function() {
2954
-
2955
- (function() {
2956
- /**
2957
- @name Random
2958
- @namespace Some useful methods for generating random things.
2959
- */
2960
- (typeof exports !== "undefined" && exports !== null ? exports : this)["Random"] = {
2961
- /**
2962
- Returns a random angle, uniformly distributed, between 0 and 2pi.
2963
-
2964
- @name angle
2965
- @methodOf Random
2966
- @returns {Number} A random angle between 0 and 2pi
2967
- */
2968
-
2969
- angle: function() {
2970
- return rand() * Math.TAU;
2971
- },
2972
- /**
2973
- Returns a random angle between the given angles.
2974
-
2975
- @name angleBetween
2976
- @methodOf Random
2977
- @returns {Number} A random angle between the angles given.
2978
- */
2979
-
2980
- angleBetween: function(min, max) {
2981
- return rand() * (max - min) + min;
2982
- },
2983
- /**
2984
- Returns a random color.
2985
-
2986
- @name color
2987
- @methodOf Random
2988
- @returns {Color} A random color
2989
- */
2990
-
2991
- color: function() {
2992
- return Color.random();
2993
- },
2994
- /**
2995
- Happens often.
2996
-
2997
- @name often
2998
- @methodOf Random
2999
- */
3000
-
3001
- often: function() {
3002
- return rand(3);
3003
- },
3004
- /**
3005
- Happens sometimes.
3006
-
3007
- @name sometimes
3008
- @methodOf Random
3009
- */
3010
-
3011
- sometimes: function() {
3012
- return !rand(3);
3013
- }
3014
- };
3015
- /**
3016
- Returns random integers from [0, n) if n is given.
3017
- Otherwise returns random float between 0 and 1.
3018
-
3019
- @name rand
3020
- @methodOf window
3021
- @param {Number} n
3022
- @returns {Number} A random integer from 0 to n - 1 if n is given. If n is not given, a random float between 0 and 1.
3023
- */
3024
-
3025
- (typeof exports !== "undefined" && exports !== null ? exports : this)["rand"] = function(n) {
3026
- if (n) {
3027
- return Math.floor(n * Math.random());
3028
- } else {
3029
- return Math.random();
3030
- }
3031
- };
3032
- /**
3033
- Returns random float from [-n / 2, n / 2] if n is given.
3034
- Otherwise returns random float between -0.5 and 0.5.
3035
-
3036
- @name signedRand
3037
- @methodOf window
3038
- @param {Number} n
3039
- @returns {Number} A random float from -n / 2 to n / 2 if n is given. If n is not given, a random float between -0.5 and 0.5.
3040
- */
3041
-
3042
- return (typeof exports !== "undefined" && exports !== null ? exports : this)["signedRand"] = function(n) {
3043
- if (n) {
3044
- return (n * Math.random()) - (n / 2);
3045
- } else {
3046
- return Math.random() - 0.5;
3047
- }
3048
- };
3049
- })();
3050
-
3051
- }).call(this);
3052
- (function() {
3053
-
3054
- (function() {
3055
- var Rectangle;
3056
- Rectangle = function(_arg) {
3057
- var height, width, x, y;
3058
- x = _arg.x, y = _arg.y, width = _arg.width, height = _arg.height;
3059
- return {
3060
- __proto__: Rectangle.prototype,
3061
- x: x || 0,
3062
- y: y || 0,
3063
- width: width || 0,
3064
- height: height || 0
3065
- };
3066
- };
3067
- Rectangle.prototype = {
3068
- center: function() {
3069
- return Point(this.x + this.width / 2, this.y + this.height / 2);
3070
- },
3071
- equal: function(other) {
3072
- return this.x === other.x && this.y === other.y && this.width === other.width && this.height === other.height;
3073
- }
3074
- };
3075
- Rectangle.prototype.__defineGetter__('left', function() {
3076
- return this.x;
3077
- });
3078
- Rectangle.prototype.__defineGetter__('right', function() {
3079
- return this.x + this.width;
3080
- });
3081
- Rectangle.prototype.__defineGetter__('top', function() {
3082
- return this.y;
3083
- });
3084
- Rectangle.prototype.__defineGetter__('bottom', function() {
3085
- return this.y + this.height;
3086
- });
3087
- return (typeof exports !== "undefined" && exports !== null ? exports : this)["Rectangle"] = Rectangle;
3088
- })();
3089
-
3090
- }).call(this);
3091
-
3092
- /**
3093
- Returns true if this string only contains whitespace characters.
3094
-
3095
- "".blank()
3096
- # => true
3097
-
3098
- "hello".blank()
3099
- # => false
3100
-
3101
- " ".blank()
3102
- # => true
3103
-
3104
- @name blank
3105
- @methodOf String#
3106
- @returns {Boolean} Whether or not this string is blank.
3107
- */
3108
-
3109
-
3110
- (function() {
3111
-
3112
- String.prototype.blank = function() {
3113
- return /^\s*$/.test(this);
3114
- };
3115
-
3116
- /**
3117
- Returns a new string that is a camelCase version.
3118
-
3119
- "camel_case".camelize()
3120
- "camel-case".camelize()
3121
- "camel case".camelize()
3122
-
3123
- # => "camelCase"
3124
-
3125
- @name camelize
3126
- @methodOf String#
3127
- @returns {String} A new string. camelCase version of `this`.
3128
- */
3129
-
3130
-
3131
- String.prototype.camelize = function() {
3132
- return this.trim().replace(/(\-|_|\s)+(.)?/g, function(match, separator, chr) {
3133
- if (chr) {
3134
- return chr.toUpperCase();
3135
- } else {
3136
- return '';
3137
- }
3138
- });
3139
- };
3140
-
3141
- /**
3142
- Returns a new string with the first letter capitalized and the rest lower cased.
3143
-
3144
- "capital".capitalize()
3145
- "cAPITAL".capitalize()
3146
- "cApItAl".capitalize()
3147
- "CAPITAL".capitalize()
3148
-
3149
- # => "Capital"
3150
-
3151
- @name capitalize
3152
- @methodOf String#
3153
- @returns {String} A new string. Capitalized version of `this`
3154
- */
3155
-
3156
-
3157
- String.prototype.capitalize = function() {
3158
- return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
3159
- };
3160
-
3161
- /**
3162
- Return the class or constant named in this string.
3163
-
3164
-
3165
- "Constant".constantize()
3166
- # => Constant
3167
- # notice this isn't a string. Useful for calling methods on class with the same name as `this`.
3168
-
3169
- @name constantize
3170
- @methodOf String#
3171
- @returns {Object} The class or constant named in this string.
3172
- */
3173
-
3174
-
3175
- String.prototype.constantize = function() {
3176
- var item, target, _i, _len, _ref;
3177
- target = typeof exports !== "undefined" && exports !== null ? exports : window;
3178
- _ref = this.split('.');
3179
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3180
- item = _ref[_i];
3181
- target = target[item];
3182
- }
3183
- return target;
3184
- };
3185
-
3186
- /**
3187
- Get the file extension of a string.
3188
-
3189
- "README.md".extension() # => "md"
3190
- "README".extension() # => ""
3191
-
3192
- @name extension
3193
- @methodOf String#
3194
- @returns {String} File extension
3195
- */
3196
-
3197
-
3198
- String.prototype.extension = function() {
3199
- var extension, _ref;
3200
- if (extension = (_ref = this.match(/\.([^\.]*)$/, '')) != null ? _ref.last() : void 0) {
3201
- return extension;
3202
- } else {
3203
- return '';
3204
- }
3205
- };
3206
-
3207
- /**
3208
- Returns a new string that is a more human readable version.
3209
-
3210
- "player_id".humanize()
3211
- # => "Player"
3212
-
3213
- "player_ammo".humanize()
3214
- # => "Player ammo"
3215
-
3216
- @name humanize
3217
- @methodOf String#
3218
- @returns {String} A new string. Replaces _id and _ with "" and capitalizes the word.
3219
- */
3220
-
3221
-
3222
- String.prototype.humanize = function() {
3223
- return this.replace(/_id$/, "").replace(/_/g, " ").capitalize();
3224
- };
3225
-
3226
- /**
3227
- Returns true.
3228
-
3229
- @name isString
3230
- @methodOf String#
3231
- @returns {Boolean} true
3232
- */
3233
-
3234
-
3235
- String.prototype.isString = function() {
3236
- return true;
3237
- };
3238
-
3239
- /**
3240
- Parse this string as though it is JSON and return the object it represents. If it
3241
- is not valid JSON returns the string itself.
3242
-
3243
- # this is valid json, so an object is returned
3244
- '{"a": 3}'.parse()
3245
- # => {a: 3}
3246
-
3247
- # double quoting instead isn't valid JSON so a string is returned
3248
- "{'a': 3}".parse()
3249
- # => "{'a': 3}"
3250
-
3251
-
3252
- @name parse
3253
- @methodOf String#
3254
- @returns {Object} Returns an object from the JSON this string contains. If it is not valid JSON returns the string itself.
3255
- */
3256
-
3257
-
3258
- String.prototype.parse = function() {
3259
- try {
3260
- return JSON.parse(this.toString());
3261
- } catch (e) {
3262
- return this.toString();
3263
- }
3264
- };
3265
-
3266
- /**
3267
- Returns true if this string starts with the given string.
3268
-
3269
- @name startsWith
3270
- @methodOf String#
3271
- @param {String} str The string to check.
3272
-
3273
- @returns {Boolean} True if this string starts with the given string, false otherwise.
3274
- */
3275
-
3276
-
3277
- String.prototype.startsWith = function(str) {
3278
- return this.lastIndexOf(str, 0) === 0;
3279
- };
3280
-
3281
- /**
3282
- Returns a new string in Title Case.
3283
-
3284
- "title-case".titleize()
3285
- # => "Title Case"
3286
-
3287
- "title case".titleize()
3288
- # => "Title Case"
3289
-
3290
- @name titleize
3291
- @methodOf String#
3292
- @returns {String} A new string. Title Cased.
3293
- */
3294
-
3295
-
3296
- String.prototype.titleize = function() {
3297
- return this.split(/[- ]/).map(function(word) {
3298
- return word.capitalize();
3299
- }).join(' ');
3300
- };
3301
-
3302
- /**
3303
- Underscore a word, changing camelCased with under_scored.
3304
-
3305
- "UNDERScore".underscore()
3306
- # => "under_score"
3307
-
3308
- "UNDER-SCORE".underscore()
3309
- # => "under_score"
3310
-
3311
- "UnDEr-SCorE".underscore()
3312
- # => "un_d_er_s_cor_e"
3313
-
3314
- @name underscore
3315
- @methodOf String#
3316
- @returns {String} A new string. Separated by _.
3317
- */
3318
-
3319
-
3320
- String.prototype.underscore = function() {
3321
- return this.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase();
3322
- };
3323
-
3324
- /**
3325
- Assumes the string is something like a file name and returns the
3326
- contents of the string without the extension.
3327
-
3328
- "neat.png".witouthExtension()
3329
- # => "neat"
3330
-
3331
- @name withoutExtension
3332
- @methodOf String#
3333
- @returns {String} A new string without the extension name.
3334
- */
3335
-
3336
-
3337
- String.prototype.withoutExtension = function() {
3338
- return this.replace(/\.[^\.]*$/, '');
3339
- };
3340
-
3341
- String.prototype.parseHex = function() {
3342
- var alpha, hexString, i, rgb;
3343
- hexString = this.replace(/#/, '');
3344
- switch (hexString.length) {
3345
- case 3:
3346
- case 4:
3347
- if (hexString.length === 4) {
3348
- alpha = (parseInt(hexString.substr(3, 1), 16) * 0x11) / 255;
3349
- } else {
3350
- alpha = 1;
3351
- }
3352
- rgb = (function() {
3353
- var _i, _results;
3354
- _results = [];
3355
- for (i = _i = 0; _i <= 2; i = ++_i) {
3356
- _results.push(parseInt(hexString.substr(i, 1), 16) * 0x11);
3357
- }
3358
- return _results;
3359
- })();
3360
- rgb.push(alpha);
3361
- return rgb;
3362
- case 6:
3363
- case 8:
3364
- if (hexString.length === 8) {
3365
- alpha = parseInt(hexString.substr(6, 2), 16) / 255;
3366
- } else {
3367
- alpha = 1;
3368
- }
3369
- rgb = (function() {
3370
- var _i, _results;
3371
- _results = [];
3372
- for (i = _i = 0; _i <= 2; i = ++_i) {
3373
- _results.push(parseInt(hexString.substr(2 * i, 2), 16));
3374
- }
3375
- return _results;
3376
- })();
3377
- rgb.push(alpha);
3378
- return rgb;
3379
- default:
3380
- return void 0;
3381
- }
3382
- };
3383
-
3384
- }).call(this);
3385
-
3386
- /**
3387
- Returns a string representing the specified Boolean object.
3388
-
3389
- <code><em>bool</em>.toString()</code>
3390
-
3391
- @name toString
3392
- @methodOf Boolean#
3393
- */
3394
-
3395
-
3396
- /**
3397
- Returns the primitive value of a Boolean object.
3398
-
3399
- <code><em>bool</em>.valueOf()</code>
3400
-
3401
- @name valueOf
3402
- @methodOf Boolean#
3403
- */
3404
-
3405
-
3406
- /**
3407
- Returns a string representing the Number object in exponential notation
3408
-
3409
- <code><i>number</i>.toExponential( [<em>fractionDigits</em>] )</code>
3410
- @param fractionDigits
3411
- An integer specifying the number of digits after the decimal point. Defaults
3412
- to as many digits as necessary to specify the number.
3413
- @name toExponential
3414
- @methodOf Number#
3415
- */
3416
-
3417
-
3418
- /**
3419
- Formats a number using fixed-point notation
3420
-
3421
- <code><i>number</i>.toFixed( [<em>digits</em>] )</code>
3422
- @param digits The number of digits to appear after the decimal point; this
3423
- may be a value between 0 and 20, inclusive, and implementations may optionally
3424
- support a larger range of values. If this argument is omitted, it is treated as
3425
- 0.
3426
- @name toFixed
3427
- @methodOf Number#
3428
- */
3429
-
3430
-
3431
- /**
3432
- number.toLocaleString();
3433
-
3434
- @name toLocaleString
3435
- @methodOf Number#
3436
- */
3437
-
3438
-
3439
- /**
3440
- Returns a string representing the Number object to the specified precision.
3441
-
3442
- <code><em>number</em>.toPrecision( [ <em>precision</em> ] )</code>
3443
- @param precision An integer specifying the number of significant digits.
3444
- @name toPrecision
3445
- @methodOf Number#
3446
- */
3447
-
3448
-
3449
- /**
3450
- Returns a string representing the specified Number object
3451
-
3452
- <code><i>number</i>.toString( [<em>radix</em>] )</code>
3453
- @param radix
3454
- An integer between 2 and 36 specifying the base to use for representing
3455
- numeric values.
3456
- @name toString
3457
- @methodOf Number#
3458
- */
3459
-
3460
-
3461
- /**
3462
- Returns the primitive value of a Number object.
3463
-
3464
- @name valueOf
3465
- @methodOf Number#
3466
- */
3467
-
3468
-
3469
- /**
3470
- Returns the specified character from a string.
3471
-
3472
- <code><em>string</em>.charAt(<em>index</em>)</code>
3473
- @param index An integer between 0 and 1 less than the length of the string.
3474
- @name charAt
3475
- @methodOf String#
3476
- */
3477
-
3478
-
3479
- /**
3480
- Returns the numeric Unicode value of the character at the given index (except
3481
- for unicode codepoints > 0x10000).
3482
-
3483
-
3484
- @param index An integer greater than 0 and less than the length of the string;
3485
- if it is not a number, it defaults to 0.
3486
- @name charCodeAt
3487
- @methodOf String#
3488
- */
3489
-
3490
-
3491
- /**
3492
- Combines the text of two or more strings and returns a new string.
3493
-
3494
- <code><em>string</em>.concat(<em>string2</em>, <em>string3</em>[, ..., <em>stringN</em>])</code>
3495
- @param string2...stringN Strings to concatenate to this string.
3496
- @name concat
3497
- @methodOf String#
3498
- */
3499
-
3500
-
3501
- /**
3502
- Returns the index within the calling String object of the first occurrence of
3503
- the specified value, starting the search at fromIndex,
3504
- returns -1 if the value is not found.
3505
-
3506
- <code><em>string</em>.indexOf(<em>searchValue</em>[, <em>fromIndex</em>]</code>
3507
- @param searchValue A string representing the value to search for.
3508
- @param fromIndex The location within the calling string to start the search
3509
- from. It can be any integer between 0 and the length of the string. The default
3510
- value is 0.
3511
- @name indexOf
3512
- @methodOf String#
3513
- */
3514
-
3515
-
3516
- /**
3517
- Returns the index within the calling String object of the last occurrence of the
3518
- specified value, or -1 if not found. The calling string is searched backward,
3519
- starting at fromIndex.
3520
-
3521
- <code><em>string</em>.lastIndexOf(<em>searchValue</em>[, <em>fromIndex</em>])</code>
3522
- @param searchValue A string representing the value to search for.
3523
- @param fromIndex The location within the calling string to start the search
3524
- from, indexed from left to right. It can be any integer between 0 and the length
3525
- of the string. The default value is the length of the string.
3526
- @name lastIndexOf
3527
- @methodOf String#
3528
- */
3529
-
3530
-
3531
- /**
3532
- Returns a number indicating whether a reference string comes before or after or
3533
- is the same as the given string in sort order.
3534
-
3535
- <code> localeCompare(compareString) </code>
3536
-
3537
- @name localeCompare
3538
- @methodOf String#
3539
- */
3540
-
3541
-
3542
- /**
3543
- Used to retrieve the matches when matching a string against a regular
3544
- expression.
3545
-
3546
- <code><em>string</em>.match(<em>regexp</em>)</code>
3547
- @param regexp A regular expression object. If a non-RegExp object obj is passed,
3548
- it is implicitly converted to a RegExp by using new RegExp(obj).
3549
- @name match
3550
- @methodOf String#
3551
- */
3552
-
3553
-
3554
- /**
3555
- Returns a new string with some or all matches of a pattern replaced by a
3556
- replacement. The pattern can be a string or a RegExp, and the replacement can
3557
- be a string or a function to be called for each match.
3558
-
3559
- <code><em>str</em>.replace(<em>regexp|substr</em>, <em>newSubStr|function[</em>, </code><code><em>flags]</em>);</code>
3560
- @param regexp A RegExp object. The match is replaced by the return value of
3561
- parameter #2.
3562
- @param substr A String that is to be replaced by newSubStr.
3563
- @param newSubStr The String that replaces the substring received from parameter
3564
- #1. A number of special replacement patterns are supported; see the "Specifying
3565
- a string as a parameter" section below.
3566
- @param function A function to be invoked to create the new substring (to put in
3567
- place of the substring received from parameter #1). The arguments supplied to
3568
- this function are described in the "Specifying a function as a parameter"
3569
- section below.
3570
- @param flags gimy
3571
-
3572
- Non-standardThe use of the flags parameter in the String.replace method is
3573
- non-standard. For cross-browser compatibility, use a RegExp object with
3574
- corresponding flags.A string containing any combination of the RegExp flags: g
3575
- global match i ignore case m match over multiple lines y Non-standard
3576
- sticky global matchignore casematch over multiple linesNon-standard sticky
3577
- @name replace
3578
- @methodOf String#
3579
- */
3580
-
3581
-
3582
- /**
3583
- Executes the search for a match between a regular expression and this String
3584
- object.
3585
-
3586
- <code><em>string</em>.search(<em>regexp</em>)</code>
3587
- @param regexp A regular expression object. If a non-RegExp object obj is
3588
- passed, it is implicitly converted to a RegExp by using new RegExp(obj).
3589
- @name search
3590
- @methodOf String#
3591
- */
3592
-
3593
-
3594
- /**
3595
- Extracts a section of a string and returns a new string.
3596
-
3597
- <code><em>string</em>.slice(<em>beginslice</em>[, <em>endSlice</em>])</code>
3598
- @param beginSlice The zero-based index at which to begin extraction.
3599
- @param endSlice The zero-based index at which to end extraction. If omitted,
3600
- slice extracts to the end of the string.
3601
- @name slice
3602
- @methodOf String#
3603
- */
3604
-
3605
-
3606
- /**
3607
- Splits a String object into an array of strings by separating the string into
3608
- substrings.
3609
-
3610
- <code><em>string</em>.split([<em>separator</em>][, <em>limit</em>])</code>
3611
- @param separator Specifies the character to use for separating the string. The
3612
- separator is treated as a string or a regular expression. If separator is
3613
- omitted, the array returned contains one element consisting of the entire
3614
- string.
3615
- @param limit Integer specifying a limit on the number of splits to be found.
3616
- @name split
3617
- @methodOf String#
3618
- */
3619
-
3620
-
3621
- /**
3622
- Returns the characters in a string beginning at the specified location through
3623
- the specified number of characters.
3624
-
3625
- <code><em>string</em>.substr(<em>start</em>[, <em>length</em>])</code>
3626
- @param start Location at which to begin extracting characters.
3627
- @param length The number of characters to extract.
3628
- @name substr
3629
- @methodOf String#
3630
- */
3631
-
3632
-
3633
- /**
3634
- Returns a subset of a string between one index and another, or through the end
3635
- of the string.
3636
-
3637
- <code><em>string</em>.substring(<em>indexA</em>[, <em>indexB</em>])</code>
3638
- @param indexA An integer between 0 and one less than the length of the string.
3639
- @param indexB (optional) An integer between 0 and the length of the string.
3640
- @name substring
3641
- @methodOf String#
3642
- */
3643
-
3644
-
3645
- /**
3646
- Returns the calling string value converted to lower case, according to any
3647
- locale-specific case mappings.
3648
-
3649
- <code> toLocaleLowerCase() </code>
3650
-
3651
- @name toLocaleLowerCase
3652
- @methodOf String#
3653
- */
3654
-
3655
-
3656
- /**
3657
- Returns the calling string value converted to upper case, according to any
3658
- locale-specific case mappings.
3659
-
3660
- <code> toLocaleUpperCase() </code>
3661
-
3662
- @name toLocaleUpperCase
3663
- @methodOf String#
3664
- */
3665
-
3666
-
3667
- /**
3668
- Returns the calling string value converted to lowercase.
3669
-
3670
- <code><em>string</em>.toLowerCase()</code>
3671
-
3672
- @name toLowerCase
3673
- @methodOf String#
3674
- */
3675
-
3676
-
3677
- /**
3678
- Returns a string representing the specified object.
3679
-
3680
- <code><em>string</em>.toString()</code>
3681
-
3682
- @name toString
3683
- @methodOf String#
3684
- */
3685
-
3686
-
3687
- /**
3688
- Returns the calling string value converted to uppercase.
3689
-
3690
- <code><em>string</em>.toUpperCase()</code>
3691
-
3692
- @name toUpperCase
3693
- @methodOf String#
3694
- */
3695
-
3696
-
3697
- /**
3698
- Removes whitespace from both ends of the string.
3699
-
3700
- <code><em>string</em>.trim()</code>
3701
-
3702
- @name trim
3703
- @methodOf String#
3704
- */
3705
-
3706
-
3707
- /**
3708
- Returns the primitive value of a String object.
3709
-
3710
- <code><em>string</em>.valueOf()</code>
3711
-
3712
- @name valueOf
3713
- @methodOf String#
3714
- */
3715
-
3716
-
3717
- /**
3718
- Removes the last element from an array and returns that element.
3719
-
3720
- <code>
3721
- <i>array</i>.pop()
3722
- </code>
3723
-
3724
- @name pop
3725
- @methodOf Array#
3726
- */
3727
-
3728
-
3729
- /**
3730
- Mutates an array by appending the given elements and returning the new length of
3731
- the array.
3732
-
3733
- <code><em>array</em>.push(<em>element1</em>, ..., <em>elementN</em>)</code>
3734
- @param element1, ..., elementN The elements to add to the end of the array.
3735
- @name push
3736
- @methodOf Array#
3737
- */
3738
-
3739
-
3740
- /**
3741
- Reverses an array in place. The first array element becomes the last and the
3742
- last becomes the first.
3743
-
3744
- <code><em>array</em>.reverse()</code>
3745
-
3746
- @name reverse
3747
- @methodOf Array#
3748
- */
3749
-
3750
-
3751
- /**
3752
- Removes the first element from an array and returns that element. This method
3753
- changes the length of the array.
3754
-
3755
- <code><em>array</em>.shift()</code>
3756
-
3757
- @name shift
3758
- @methodOf Array#
3759
- */
3760
-
3761
-
3762
- /**
3763
- Sorts the elements of an array in place.
3764
-
3765
- <code><em>array</em>.sort([<em>compareFunction</em>])</code>
3766
- @param compareFunction Specifies a function that defines the sort order. If
3767
- omitted, the array is sorted lexicographically (in dictionary order) according
3768
- to the string conversion of each element.
3769
- @name sort
3770
- @methodOf Array#
3771
- */
3772
-
3773
-
3774
- /**
3775
- Changes the content of an array, adding new elements while removing old
3776
- elements.
3777
-
3778
- <code><em>array</em>.splice(<em>index</em>, <em>howMany</em>[, <em>element1</em>[, ...[, <em>elementN</em>]]])</code>
3779
- @param index Index at which to start changing the array. If negative, will
3780
- begin that many elements from the end.
3781
- @param howMany An integer indicating the number of old array elements to
3782
- remove. If howMany is 0, no elements are removed. In this case, you should
3783
- specify at least one new element. If no howMany parameter is specified (second
3784
- syntax above, which is a SpiderMonkey extension), all elements after index are
3785
- removed.
3786
- @param element1, ..., elementN The elements to add to the array. If you don't
3787
- specify any elements, splice simply removes elements from the array.
3788
- @name splice
3789
- @methodOf Array#
3790
- */
3791
-
3792
-
3793
- /**
3794
- Adds one or more elements to the beginning of an array and returns the new
3795
- length of the array.
3796
-
3797
- <code><em>arrayName</em>.unshift(<em>element1</em>, ..., <em>elementN</em>) </code>
3798
- @param element1, ..., elementN The elements to add to the front of the array.
3799
- @name unshift
3800
- @methodOf Array#
3801
- */
3802
-
3803
-
3804
- /**
3805
- Returns a new array comprised of this array joined with other array(s) and/or
3806
- value(s).
3807
-
3808
- <code><em>array</em>.concat(<em>value1</em>, <em>value2</em>, ..., <em>valueN</em>)</code>
3809
- @param valueN Arrays and/or values to concatenate to the resulting array.
3810
- @name concat
3811
- @methodOf Array#
3812
- */
3813
-
3814
-
3815
- /**
3816
- Joins all elements of an array into a string.
3817
-
3818
- <code><em>array</em>.join(<em>separator</em>)</code>
3819
- @param separator Specifies a string to separate each element of the array. The
3820
- separator is converted to a string if necessary. If omitted, the array elements
3821
- are separated with a comma.
3822
- @name join
3823
- @methodOf Array#
3824
- */
3825
-
3826
-
3827
- /**
3828
- Returns a one-level deep copy of a portion of an array.
3829
-
3830
- <code><em>array</em>.slice(<em>begin</em>[, <em>end</em>])</code>
3831
- @param begin Zero-based index at which to begin extraction.As a negative index,
3832
- start indicates an offset from the end of the sequence. slice(-2) extracts the
3833
- second-to-last element and the last element in the sequence.
3834
- @param end Zero-based index at which to end extraction. slice extracts up to
3835
- but not including end.slice(1,4) extracts the second element through the fourth
3836
- element (elements indexed 1, 2, and 3).As a negative index, end indicates an
3837
- offset from the end of the sequence. slice(2,-1) extracts the third element
3838
- through the second-to-last element in the sequence.If end is omitted, slice
3839
- extracts to the end of the sequence.
3840
- @name slice
3841
- @methodOf Array#
3842
- */
3843
-
3844
-
3845
- /**
3846
- Returns a string representing the specified array and its elements.
3847
-
3848
- <code><em>array</em>.toString()</code>
3849
-
3850
- @name toString
3851
- @methodOf Array#
3852
- */
3853
-
3854
-
3855
- /**
3856
- Returns the first index at which a given element can be found in the array, or
3857
- -1 if it is not present.
3858
-
3859
- <code><em>array</em>.indexOf(<em>searchElement</em>[, <em>fromIndex</em>])</code>
3860
- @param searchElement fromIndex Element to locate in the array.The index at
3861
- which to begin the search. Defaults to 0, i.e. the whole array will be searched.
3862
- If the index is greater than or equal to the length of the array, -1 is
3863
- returned, i.e. the array will not be searched. If negative, it is taken as the
3864
- offset from the end of the array. Note that even when the index is negative, the
3865
- array is still searched from front to back. If the calculated index is less than
3866
- 0, the whole array will be searched.
3867
- @name indexOf
3868
- @methodOf Array#
3869
- */
3870
-
3871
-
3872
- /**
3873
- Returns the last index at which a given element can be found in the array, or -1
3874
- if it is not present. The array is searched backwards, starting at fromIndex.
3875
-
3876
- <code><em>array</em>.lastIndexOf(<em>searchElement</em>[, <em>fromIndex</em>])</code>
3877
- @param searchElement fromIndex Element to locate in the array.The index at
3878
- which to start searching backwards. Defaults to the array's length, i.e. the
3879
- whole array will be searched. If the index is greater than or equal to the
3880
- length of the array, the whole array will be searched. If negative, it is taken
3881
- as the offset from the end of the array. Note that even when the index is
3882
- negative, the array is still searched from back to front. If the calculated
3883
- index is less than 0, -1 is returned, i.e. the array will not be searched.
3884
- @name lastIndexOf
3885
- @methodOf Array#
3886
- */
3887
-
3888
-
3889
- /**
3890
- Creates a new array with all elements that pass the test implemented by the
3891
- provided function.
3892
-
3893
- <code><em>array</em>.filter(<em>callback</em>[, <em>thisObject</em>])</code>
3894
- @param callback thisObject Function to test each element of the array.Object to
3895
- use as this when executing callback.
3896
- @name filter
3897
- @methodOf Array#
3898
- */
3899
-
3900
-
3901
- /**
3902
- Executes a provided function once per array element.
3903
-
3904
- <code><em>array</em>.forEach(<em>callback</em>[, <em>thisObject</em>])</code>
3905
- @param callback thisObject Function to execute for each element.Object to use
3906
- as this when executing callback.
3907
- @name forEach
3908
- @methodOf Array#
3909
- */
3910
-
3911
-
3912
- /**
3913
- Tests whether all elements in the array pass the test implemented by the
3914
- provided function.
3915
-
3916
- <code><em>array</em>.every(<em>callback</em>[, <em>thisObject</em>])</code>
3917
- @param callbackthisObject Function to test for each element.Object to use as
3918
- this when executing callback.
3919
- @name every
3920
- @methodOf Array#
3921
- */
3922
-
3923
-
3924
- /**
3925
- Creates a new array with the results of calling a provided function on every
3926
- element in this array.
3927
-
3928
- <code><em>array</em>.map(<em>callback</em>[, <em>thisObject</em>])</code>
3929
- @param callbackthisObject Function that produces an element of the new Array
3930
- from an element of the current one.Object to use as this when executing
3931
- callback.
3932
- @name map
3933
- @methodOf Array#
3934
- */
3935
-
3936
-
3937
- /**
3938
- Tests whether some element in the array passes the test implemented by the
3939
- provided function.
3940
-
3941
- <code><em>array</em>.some(<em>callback</em>[, <em>thisObject</em>])</code>
3942
- @param callback thisObject Function to test for each element.Object to use as
3943
- this when executing callback.
3944
- @name some
3945
- @methodOf Array#
3946
- */
3947
-
3948
-
3949
- /**
3950
- Apply a function against an accumulator and each value of the array (from
3951
- left-to-right) as to reduce it to a single value.
3952
-
3953
- <code><em>array</em>.reduce(<em>callback</em>[, <em>initialValue</em>])</code>
3954
- @param callbackinitialValue Function to execute on each value in the
3955
- array.Object to use as the first argument to the first call of the callback.
3956
- @name reduce
3957
- @methodOf Array#
3958
- */
3959
-
3960
-
3961
- /**
3962
- Apply a function simultaneously against two values of the array (from
3963
- right-to-left) as to reduce it to a single value.
3964
-
3965
- <code><em>array</em>.reduceRight(<em>callback</em>[, <em>initialValue</em>])</code>
3966
- @param callback initialValue Function to execute on each value in the
3967
- array.Object to use as the first argument to the first call of the callback.
3968
- @name reduceRight
3969
- @methodOf Array#
3970
- */
3971
-
3972
-
3973
- /**
3974
- Returns a boolean indicating whether the object has the specified property.
3975
-
3976
- <code><em>obj</em>.hasOwnProperty(<em>prop</em>)</code>
3977
- @param prop The name of the property to test.
3978
- @name hasOwnProperty
3979
- @methodOf Object#
3980
- */
3981
-
3982
-
3983
- /**
3984
- Calls a function with a given this value and arguments provided as an array.
3985
-
3986
- <code><em>fun</em>.apply(<em>thisArg</em>[, <em>argsArray</em>])</code>
3987
- @param thisArg Determines the value of this inside fun. If thisArg is null or
3988
- undefined, this will be the global object. Otherwise, this will be equal to
3989
- Object(thisArg) (which is thisArg if thisArg is already an object, or a String,
3990
- Boolean, or Number if thisArg is a primitive value of the corresponding type).
3991
- Therefore, it is always true that typeof this == "object" when the function
3992
- executes.
3993
- @param argsArray An argument array for the object, specifying the arguments
3994
- with which fun should be called, or null or undefined if no arguments should be
3995
- provided to the function.
3996
- @name apply
3997
- @methodOf Function#
3998
- */
3999
-
4000
-
4001
- /**
4002
- Creates a new function that, when called, itself calls this function in the
4003
- context of the provided this value, with a given sequence of arguments preceding
4004
- any provided when the new function was called.
4005
-
4006
- <code><em>fun</em>.bind(<em>thisArg</em>[, <em>arg1</em>[, <em>arg2</em>[, ...]]])</code>
4007
- @param thisValuearg1, arg2, ... The value to be passed as the this parameter to
4008
- the target function when the bound function is called. The value is ignored if
4009
- the bound function is constructed using the new operator.Arguments to prepend to
4010
- arguments provided to the bound function when invoking the target function.
4011
- @name bind
4012
- @methodOf Function#
4013
- */
4014
-
4015
-
4016
- /**
4017
- Calls a function with a given this value and arguments provided individually.
4018
-
4019
- <code><em>fun</em>.call(<em>thisArg</em>[, <em>arg1</em>[, <em>arg2</em>[, ...]]])</code>
4020
- @param thisArg Determines the value of this inside fun. If thisArg is null or
4021
- undefined, this will be the global object. Otherwise, this will be equal to
4022
- Object(thisArg) (which is thisArg if thisArg is already an object, or a String,
4023
- Boolean, or Number if thisArg is a primitive value of the corresponding type).
4024
- Therefore, it is always true that typeof this == "object" when the function
4025
- executes.
4026
- @param arg1, arg2, ... Arguments for the object.
4027
- @name call
4028
- @methodOf Function#
4029
- */
4030
-
4031
-
4032
- /**
4033
- Returns a string representing the source code of the function.
4034
-
4035
- <code><em>function</em>.toString(<em>indentation</em>)</code>
4036
- @param indentation Non-standard The amount of spaces to indent the string
4037
- representation of the source code. If indentation is less than or equal to -1,
4038
- most unnecessary spaces are removed.
4039
- @name toString
4040
- @methodOf Function#
4041
- */
4042
-
4043
-
4044
- /**
4045
- Executes a search for a match in a specified string. Returns a result array, or
4046
- null.
4047
-
4048
-
4049
- @param regexp The name of the regular expression. It can be a variable name or
4050
- a literal.
4051
- @param str The string against which to match the regular expression.
4052
- @name exec
4053
- @methodOf RegExp#
4054
- */
4055
-
4056
-
4057
- /**
4058
- Executes the search for a match between a regular expression and a specified
4059
- string. Returns true or false.
4060
-
4061
- <code> <em>regexp</em>.test([<em>str</em>]) </code>
4062
- @param regexp The name of the regular expression. It can be a variable name or
4063
- a literal.
4064
- @param str The string against which to match the regular expression.
4065
- @name test
4066
- @methodOf RegExp#
4067
- */
4068
-
4069
-
4070
- /**
4071
- Returns a string representing the specified object.
4072
-
4073
- <code><i>regexp</i>.toString()</code>
4074
-
4075
- @name toString
4076
- @methodOf RegExp#
4077
- */
4078
-
4079
-
4080
- /**
4081
- Returns a reference to the Date function that created the instance's prototype.
4082
- Note that the value of this property is a reference to the function itself, not
4083
- a string containing the function's name.
4084
-
4085
-
4086
-
4087
- @name constructor
4088
- @methodOf Date#
4089
- */
4090
-
4091
-
4092
- /**
4093
- Returns the day of the month for the specified date according to local time.
4094
-
4095
- <code>
4096
- getDate()
4097
- </code>
4098
-
4099
- @name getDate
4100
- @methodOf Date#
4101
- */
4102
-
4103
-
4104
- /**
4105
- Returns the day of the week for the specified date according to local time.
4106
-
4107
- <code>
4108
- getDay()
4109
- </code>
4110
-
4111
- @name getDay
4112
- @methodOf Date#
4113
- */
4114
-
4115
-
4116
- /**
4117
- Returns the year of the specified date according to local time.
4118
-
4119
- <code>
4120
- getFullYear()
4121
- </code>
4122
-
4123
- @name getFullYear
4124
- @methodOf Date#
4125
- */
4126
-
4127
-
4128
- /**
4129
- Returns the hour for the specified date according to local time.
4130
-
4131
- <code>
4132
- getHours()
4133
- </code>
4134
-
4135
- @name getHours
4136
- @methodOf Date#
4137
- */
4138
-
4139
-
4140
- /**
4141
- Returns the milliseconds in the specified date according to local time.
4142
-
4143
- <code>
4144
- getMilliseconds()
4145
- </code>
4146
-
4147
- @name getMilliseconds
4148
- @methodOf Date#
4149
- */
4150
-
4151
-
4152
- /**
4153
- Returns the minutes in the specified date according to local time.
4154
-
4155
- <code>
4156
- getMinutes()
4157
- </code>
4158
-
4159
- @name getMinutes
4160
- @methodOf Date#
4161
- */
4162
-
4163
-
4164
- /**
4165
- Returns the month in the specified date according to local time.
4166
-
4167
- <code>
4168
- getMonth()
4169
- </code>
4170
-
4171
- @name getMonth
4172
- @methodOf Date#
4173
- */
4174
-
4175
-
4176
- /**
4177
- Returns the seconds in the specified date according to local time.
4178
-
4179
- <code>
4180
- getSeconds()
4181
- </code>
4182
-
4183
- @name getSeconds
4184
- @methodOf Date#
4185
- */
4186
-
4187
-
4188
- /**
4189
- Returns the numeric value corresponding to the time for the specified date
4190
- according to universal time.
4191
-
4192
- <code> getTime() </code>
4193
-
4194
- @name getTime
4195
- @methodOf Date#
4196
- */
4197
-
4198
-
4199
- /**
4200
- Returns the time-zone offset from UTC, in minutes, for the current locale.
4201
-
4202
- <code> getTimezoneOffset() </code>
4203
-
4204
- @name getTimezoneOffset
4205
- @methodOf Date#
4206
- */
4207
-
4208
-
4209
- /**
4210
- Returns the day (date) of the month in the specified date according to universal
4211
- time.
4212
-
4213
- <code>
4214
- getUTCDate()
4215
- </code>
4216
-
4217
- @name getUTCDate
4218
- @methodOf Date#
4219
- */
4220
-
4221
-
4222
- /**
4223
- Returns the day of the week in the specified date according to universal time.
4224
-
4225
- <code>
4226
- getUTCDay()
4227
- </code>
4228
-
4229
- @name getUTCDay
4230
- @methodOf Date#
4231
- */
4232
-
4233
-
4234
- /**
4235
- Returns the year in the specified date according to universal time.
4236
-
4237
- <code>
4238
- getUTCFullYear()
4239
- </code>
4240
-
4241
- @name getUTCFullYear
4242
- @methodOf Date#
4243
- */
4244
-
4245
-
4246
- /**
4247
- Returns the hours in the specified date according to universal time.
4248
-
4249
- <code>
4250
- getUTCHours
4251
- </code>
4252
-
4253
- @name getUTCHours
4254
- @methodOf Date#
4255
- */
4256
-
4257
-
4258
- /**
4259
- Returns the milliseconds in the specified date according to universal time.
4260
-
4261
- <code>
4262
- getUTCMilliseconds()
4263
- </code>
4264
-
4265
- @name getUTCMilliseconds
4266
- @methodOf Date#
4267
- */
4268
-
4269
-
4270
- /**
4271
- Returns the minutes in the specified date according to universal time.
4272
-
4273
- <code>
4274
- getUTCMinutes()
4275
- </code>
4276
-
4277
- @name getUTCMinutes
4278
- @methodOf Date#
4279
- */
4280
-
4281
-
4282
- /**
4283
- Returns the month of the specified date according to universal time.
4284
-
4285
- <code>
4286
- getUTCMonth()
4287
- </code>
4288
-
4289
- @name getUTCMonth
4290
- @methodOf Date#
4291
- */
4292
-
4293
-
4294
- /**
4295
- Returns the seconds in the specified date according to universal time.
4296
-
4297
- <code>
4298
- getUTCSeconds()
4299
- </code>
4300
-
4301
- @name getUTCSeconds
4302
- @methodOf Date#
4303
- */
4304
-
4305
-
4306
- /**
4307
- Sets the day of the month for a specified date according to local time.
4308
-
4309
- <code> setDate(<em>dayValue</em>) </code>
4310
- @param dayValue An integer from 1 to 31, representing the day of the month.
4311
- @name setDate
4312
- @methodOf Date#
4313
- */
4314
-
4315
-
4316
- /**
4317
- Sets the full year for a specified date according to local time.
4318
-
4319
- <code>
4320
- setFullYear(<i>yearValue</i>[, <i>monthValue</i>[, <em>dayValue</em>]])
4321
- </code>
4322
- @param yearValue An integer specifying the numeric value of the year, for
4323
- example, 1995.
4324
- @param monthValue An integer between 0 and 11 representing the months January
4325
- through December.
4326
- @param dayValue An integer between 1 and 31 representing the day of the
4327
- month. If you specify the dayValue parameter, you must also specify the
4328
- monthValue.
4329
- @name setFullYear
4330
- @methodOf Date#
4331
- */
4332
-
4333
-
4334
- /**
4335
- Sets the hours for a specified date according to local time.
4336
-
4337
- <code>
4338
- setHours(<i>hoursValue</i>[, <i>minutesValue</i>[, <i>secondsValue</i>[, <em>msValue</em>]]])
4339
- </code>
4340
- @param hoursValue An integer between 0 and 23, representing the hour.
4341
- @param minutesValue An integer between 0 and 59, representing the minutes.
4342
- @param secondsValue An integer between 0 and 59, representing the seconds. If
4343
- you specify the secondsValue parameter, you must also specify the minutesValue.
4344
- @param msValue A number between 0 and 999, representing the milliseconds. If
4345
- you specify the msValue parameter, you must also specify the minutesValue and
4346
- secondsValue.
4347
- @name setHours
4348
- @methodOf Date#
4349
- */
4350
-
4351
-
4352
- /**
4353
- Sets the milliseconds for a specified date according to local time.
4354
-
4355
- <code>
4356
- setMilliseconds(<i>millisecondsValue</i>)
4357
- </code>
4358
- @param millisecondsValue A number between 0 and 999, representing the
4359
- milliseconds.
4360
- @name setMilliseconds
4361
- @methodOf Date#
4362
- */
4363
-
4364
-
4365
- /**
4366
- Sets the minutes for a specified date according to local time.
4367
-
4368
- <code>
4369
- setMinutes(<i>minutesValue</i>[, <i>secondsValue</i>[, <em>msValue</em>]])
4370
- </code>
4371
- @param minutesValue An integer between 0 and 59, representing the minutes.
4372
- @param secondsValue An integer between 0 and 59, representing the seconds. If
4373
- you specify the secondsValue parameter, you must also specify the minutesValue.
4374
- @param msValue A number between 0 and 999, representing the milliseconds. If
4375
- you specify the msValue parameter, you must also specify the minutesValue and
4376
- secondsValue.
4377
- @name setMinutes
4378
- @methodOf Date#
4379
- */
4380
-
4381
-
4382
- /**
4383
- Set the month for a specified date according to local time.
4384
-
4385
- <code>
4386
- setMonth(<i>monthValue</i>[, <em>dayValue</em>])
4387
- </code>
4388
- @param monthValue An integer between 0 and 11 (representing the months
4389
- January through December).
4390
- @param dayValue An integer from 1 to 31, representing the day of the month.
4391
- @name setMonth
4392
- @methodOf Date#
4393
- */
4394
-
4395
-
4396
- /**
4397
- Sets the seconds for a specified date according to local time.
4398
-
4399
- <code>
4400
- setSeconds(<i>secondsValue</i>[, <em>msValue</em>])
4401
- </code>
4402
- @param secondsValue An integer between 0 and 59.
4403
- @param msValue A number between 0 and 999, representing the milliseconds.
4404
- @name setSeconds
4405
- @methodOf Date#
4406
- */
4407
-
4408
-
4409
- /**
4410
- Sets the Date object to the time represented by a number of milliseconds since
4411
- January 1, 1970, 00:00:00 UTC.
4412
-
4413
- <code>
4414
- setTime(<i>timeValue</i>)
4415
- </code>
4416
- @param timeValue An integer representing the number of milliseconds since 1
4417
- January 1970, 00:00:00 UTC.
4418
- @name setTime
4419
- @methodOf Date#
4420
- */
4421
-
4422
-
4423
- /**
4424
- Sets the day of the month for a specified date according to universal time.
4425
-
4426
- <code>
4427
- setUTCDate(<i>dayValue</i>)
4428
- </code>
4429
- @param dayValue An integer from 1 to 31, representing the day of the month.
4430
- @name setUTCDate
4431
- @methodOf Date#
4432
- */
4433
-
4434
-
4435
- /**
4436
- Sets the full year for a specified date according to universal time.
4437
-
4438
- <code>
4439
- setUTCFullYear(<i>yearValue</i>[, <i>monthValue</i>[, <em>dayValue</em>]])
4440
- </code>
4441
- @param yearValue An integer specifying the numeric value of the year, for
4442
- example, 1995.
4443
- @param monthValue An integer between 0 and 11 representing the months January
4444
- through December.
4445
- @param dayValue An integer between 1 and 31 representing the day of the
4446
- month. If you specify the dayValue parameter, you must also specify the
4447
- monthValue.
4448
- @name setUTCFullYear
4449
- @methodOf Date#
4450
- */
4451
-
4452
-
4453
- /**
4454
- Sets the hour for a specified date according to universal time.
4455
-
4456
- <code>
4457
- setUTCHours(<i>hoursValue</i>[, <i>minutesValue</i>[, <i>secondsValue</i>[, <em>msValue</em>]]])
4458
- </code>
4459
- @param hoursValue An integer between 0 and 23, representing the hour.
4460
- @param minutesValue An integer between 0 and 59, representing the minutes.
4461
- @param secondsValue An integer between 0 and 59, representing the seconds. If
4462
- you specify the secondsValue parameter, you must also specify the minutesValue.
4463
- @param msValue A number between 0 and 999, representing the milliseconds. If
4464
- you specify the msValue parameter, you must also specify the minutesValue and
4465
- secondsValue.
4466
- @name setUTCHours
4467
- @methodOf Date#
4468
- */
4469
-
4470
-
4471
- /**
4472
- Sets the milliseconds for a specified date according to universal time.
4473
-
4474
- <code>
4475
- setUTCMilliseconds(<i>millisecondsValue</i>)
4476
- </code>
4477
- @param millisecondsValue A number between 0 and 999, representing the
4478
- milliseconds.
4479
- @name setUTCMilliseconds
4480
- @methodOf Date#
4481
- */
4482
-
4483
-
4484
- /**
4485
- Sets the minutes for a specified date according to universal time.
4486
-
4487
- <code>
4488
- setUTCMinutes(<i>minutesValue</i>[, <i>secondsValue</i>[, <em>msValue</em>]])
4489
- </code>
4490
- @param minutesValue An integer between 0 and 59, representing the minutes.
4491
- @param secondsValue An integer between 0 and 59, representing the seconds. If
4492
- you specify the secondsValue parameter, you must also specify the minutesValue.
4493
- @param msValue A number between 0 and 999, representing the milliseconds. If
4494
- you specify the msValue parameter, you must also specify the minutesValue and
4495
- secondsValue.
4496
- @name setUTCMinutes
4497
- @methodOf Date#
4498
- */
4499
-
4500
-
4501
- /**
4502
- Sets the month for a specified date according to universal time.
4503
-
4504
- <code>
4505
- setUTCMonth(<i>monthValue</i>[, <em>dayValue</em>])
4506
- </code>
4507
- @param monthValue An integer between 0 and 11, representing the months
4508
- January through December.
4509
- @param dayValue An integer from 1 to 31, representing the day of the month.
4510
- @name setUTCMonth
4511
- @methodOf Date#
4512
- */
4513
-
4514
-
4515
- /**
4516
- Sets the seconds for a specified date according to universal time.
4517
-
4518
- <code>
4519
- setUTCSeconds(<i>secondsValue</i>[, <em>msValue</em>])
4520
- </code>
4521
- @param secondsValue An integer between 0 and 59.
4522
- @param msValue A number between 0 and 999, representing the milliseconds.
4523
- @name setUTCSeconds
4524
- @methodOf Date#
4525
- */
4526
-
4527
-
4528
- /**
4529
- Returns the date portion of a Date object in human readable form in American
4530
- English.
4531
-
4532
- <code><em>date</em>.toDateString()</code>
4533
-
4534
- @name toDateString
4535
- @methodOf Date#
4536
- */
4537
-
4538
-
4539
- /**
4540
- Returns a JSON representation of the Date object.
4541
-
4542
- <code><em>date</em>.prototype.toJSON()</code>
4543
-
4544
- @name toJSON
4545
- @methodOf Date#
4546
- */
4547
-
4548
-
4549
- /**
4550
- Converts a date to a string, returning the "date" portion using the operating
4551
- system's locale's conventions.
4552
-
4553
- <code>
4554
- toLocaleDateString()
4555
- </code>
4556
-
4557
- @name toLocaleDateString
4558
- @methodOf Date#
4559
- */
4560
-
4561
-
4562
- /**
4563
- Converts a date to a string, using the operating system's locale's conventions.
4564
-
4565
- <code>
4566
- toLocaleString()
4567
- </code>
4568
-
4569
- @name toLocaleString
4570
- @methodOf Date#
4571
- */
4572
-
4573
-
4574
- /**
4575
- Converts a date to a string, returning the "time" portion using the current
4576
- locale's conventions.
4577
-
4578
- <code> toLocaleTimeString() </code>
4579
-
4580
- @name toLocaleTimeString
4581
- @methodOf Date#
4582
- */
4583
-
4584
-
4585
- /**
4586
- Returns a string representing the specified Date object.
4587
-
4588
- <code> toString() </code>
4589
-
4590
- @name toString
4591
- @methodOf Date#
4592
- */
4593
-
4594
-
4595
- /**
4596
- Returns the time portion of a Date object in human readable form in American
4597
- English.
4598
-
4599
- <code><em>date</em>.toTimeString()</code>
4600
-
4601
- @name toTimeString
4602
- @methodOf Date#
4603
- */
4604
-
4605
-
4606
- /**
4607
- Converts a date to a string, using the universal time convention.
4608
-
4609
- <code> toUTCString() </code>
4610
-
4611
- @name toUTCString
4612
- @methodOf Date#
4613
- */
4614
-
4615
-
4616
- (function() {
4617
-
4618
-
4619
-
4620
- }).call(this);
4621
- /*!
4622
- Math.uuid.js (v1.4)
4623
- http://www.broofa.com
4624
- mailto:robert@broofa.com
4625
-
4626
- Copyright (c) 2010 Robert Kieffer
4627
- Dual licensed under the MIT and GPL licenses.
4628
- */
4629
-
4630
- /**
4631
- Generate a random uuid.
4632
-
4633
- <code><pre>
4634
- // No arguments - returns RFC4122, version 4 ID
4635
- Math.uuid()
4636
- => "92329D39-6F5C-4520-ABFC-AAB64544E172"
4637
-
4638
- // One argument - returns ID of the specified length
4639
- Math.uuid(15) // 15 character ID (default base=62)
4640
- => "VcydxgltxrVZSTV"
4641
-
4642
- // Two arguments - returns ID of the specified length, and radix. (Radix must be <= 62)
4643
- Math.uuid(8, 2) // 8 character ID (base=2)
4644
- => "01001010"
4645
-
4646
- Math.uuid(8, 10) // 8 character ID (base=10)
4647
- => "47473046"
4648
-
4649
- Math.uuid(8, 16) // 8 character ID (base=16)
4650
- => "098F4D35"
4651
- </pre></code>
4652
-
4653
- @name uuid
4654
- @methodOf Math
4655
- @param length The desired number of characters
4656
- @param radix The number of allowable values for each character.
4657
- */
4658
-
4659
- (function() {
4660
- // Private array of chars to use
4661
- var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
4662
-
4663
- Math.uuid = function (len, radix) {
4664
- var chars = CHARS, uuid = [];
4665
- radix = radix || chars.length;
4666
-
4667
- if (len) {
4668
- // Compact form
4669
- for (var i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
4670
- } else {
4671
- // rfc4122, version 4 form
4672
- var r;
4673
-
4674
- // rfc4122 requires these characters
4675
- uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
4676
- uuid[14] = '4';
4677
-
4678
- // Fill in random data. At i==19 set the high bits of clock sequence as
4679
- // per rfc4122, sec. 4.1.5
4680
- for (var i = 0; i < 36; i++) {
4681
- if (!uuid[i]) {
4682
- r = 0 | Math.random()*16;
4683
- uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
4684
- }
4685
- }
4686
- }
4687
-
4688
- return uuid.join('');
4689
- };
4690
-
4691
- // A more performant, but slightly bulkier, RFC4122v4 solution. We boost performance
4692
- // by minimizing calls to random()
4693
- Math.uuidFast = function() {
4694
- var chars = CHARS, uuid = new Array(36), rnd=0, r;
4695
- for (var i = 0; i < 36; i++) {
4696
- if (i==8 || i==13 || i==18 || i==23) {
4697
- uuid[i] = '-';
4698
- } else if (i==14) {
4699
- uuid[i] = '4';
4700
- } else {
4701
- if (rnd <= 0x02) rnd = 0x2000000 + (Math.random()*0x1000000)|0;
4702
- r = rnd & 0xf;
4703
- rnd = rnd >> 4;
4704
- uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
4705
- }
4706
- }
4707
- return uuid.join('');
4708
- };
4709
-
4710
- // A more compact, but less performant, RFC4122v4 solution:
4711
- Math.uuidCompact = function() {
4712
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
4713
- var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
4714
- return v.toString(16);
4715
- }).toUpperCase();
4716
- };
4717
- })();
4718
- (function() {
4719
-
4720
-
4721
-
4722
- }).call(this);