cornerstone-source 0.1.1

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