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