This repository has been archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
box2dweb-closure.compiled.js
611 lines (611 loc) · 287 KB
/
box2dweb-closure.compiled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
var COMPILED=!0,goog=goog||{};goog.global=this;goog.DEBUG=!0;goog.LOCALE="en";goog.provide=function(a){if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a];for(var b=a;b=b.substring(0,b.lastIndexOf("."));){if(goog.getObjectByName(b))break;goog.implicitNamespaces_[b]=!0}}goog.exportPath_(a)};
goog.setTestOnly=function(a){if(COMPILED&&!goog.DEBUG)throw a=a||"",Error("Importing test-only code into non-debug environment"+a?": "+a:".");};if(!COMPILED)goog.isProvided_=function(a){return!goog.implicitNamespaces_[a]&&!!goog.getObjectByName(a)},goog.implicitNamespaces_={};goog.exportPath_=function(a,b,c){a=a.split(".");c=c||goog.global;!(a[0]in c)&&c.execScript&&c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&goog.isDef(b)?c[d]=b:c=c[d]?c[d]:c[d]={}};
goog.getObjectByName=function(a,b){for(var c=a.split("."),d=b||goog.global,e;e=c.shift();)if(goog.isDefAndNotNull(d[e]))d=d[e];else return null;return d};goog.globalize=function(a,b){var c=b||goog.global,d;for(d in a)c[d]=a[d]};
goog.addDependency=function(a,b,c){if(!COMPILED){for(var d,a=a.replace(/\\/g,"/"),e=goog.dependencies_,f=0;d=b[f];f++)e.nameToPath[d]=a,a in e.pathToNames||(e.pathToNames[a]={}),e.pathToNames[a][d]=!0;for(d=0;b=c[d];d++)a in e.requires||(e.requires[a]={}),e.requires[a][b]=!0}};goog.ENABLE_DEBUG_LOADER=!0;
goog.require=function(a){if(!COMPILED&&!goog.isProvided_(a)){if(goog.ENABLE_DEBUG_LOADER){var b=goog.getPathFromDeps_(a);if(b){goog.included_[b]=!0;goog.writeScripts_();return}}a="goog.require could not find: "+a;goog.global.console&&goog.global.console.error(a);throw Error(a);}};goog.basePath="";goog.nullFunction=function(){};goog.identityFunction=function(a){return a};goog.abstractMethod=function(){throw Error("unimplemented abstract method");};
goog.addSingletonGetter=function(a){a.getInstance=function(){return a.instance_||(a.instance_=new a)}};
if(!COMPILED&&goog.ENABLE_DEBUG_LOADER)goog.included_={},goog.dependencies_={pathToNames:{},nameToPath:{},requires:{},visited:{},written:{}},goog.inHtmlDocument_=function(){var a=goog.global.document;return typeof a!="undefined"&&"write"in a},goog.findBasePath_=function(){if(goog.global.CLOSURE_BASE_PATH)goog.basePath=goog.global.CLOSURE_BASE_PATH;else if(goog.inHtmlDocument_())for(var a=goog.global.document.getElementsByTagName("script"),b=a.length-1;b>=0;--b){var c=a[b].src,d=c.lastIndexOf("?"),
d=d==-1?c.length:d;if(c.substr(d-7,7)=="base.js"){goog.basePath=c.substr(0,d-7);break}}},goog.importScript_=function(a){var b=goog.global.CLOSURE_IMPORT_SCRIPT||goog.writeScriptTag_;!goog.dependencies_.written[a]&&b(a)&&(goog.dependencies_.written[a]=!0)},goog.writeScriptTag_=function(a){return goog.inHtmlDocument_()?(goog.global.document.write('<script type="text/javascript" src="'+a+'"><\/script>'),!0):!1},goog.writeScripts_=function(){function a(e){if(!(e in d.written)){if(!(e in d.visited)&&(d.visited[e]=
!0,e in d.requires))for(var g in d.requires[e])if(!goog.isProvided_(g))if(g in d.nameToPath)a(d.nameToPath[g]);else throw Error("Undefined nameToPath for "+g);e in c||(c[e]=!0,b.push(e))}}var b=[],c={},d=goog.dependencies_,e;for(e in goog.included_)d.written[e]||a(e);for(e=0;e<b.length;e++)if(b[e])goog.importScript_(goog.basePath+b[e]);else throw Error("Undefined script input");},goog.getPathFromDeps_=function(a){return a in goog.dependencies_.nameToPath?goog.dependencies_.nameToPath[a]:null},goog.findBasePath_(),
goog.global.CLOSURE_NO_DEPS||goog.importScript_(goog.basePath+"deps.js");
goog.typeOf=function(a){var b=typeof a;if(b=="object")if(a){if(a instanceof Array)return"array";else if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if(c=="[object Window]")return"object";if(c=="[object Array]"||typeof a.length=="number"&&typeof a.splice!="undefined"&&typeof a.propertyIsEnumerable!="undefined"&&!a.propertyIsEnumerable("splice"))return"array";if(c=="[object Function]"||typeof a.call!="undefined"&&typeof a.propertyIsEnumerable!="undefined"&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if(b=="function"&&typeof a.call=="undefined")return"object";return b};goog.propertyIsEnumerableCustom_=function(a,b){if(b in a)for(var c in a)if(c==b&&Object.prototype.hasOwnProperty.call(a,b))return!0;return!1};goog.propertyIsEnumerable_=function(a,b){return a instanceof Object?Object.prototype.propertyIsEnumerable.call(a,b):goog.propertyIsEnumerableCustom_(a,b)};goog.isDef=function(a){return a!==void 0};goog.isNull=function(a){return a===null};goog.isDefAndNotNull=function(a){return a!=null};
goog.isArray=function(a){return goog.typeOf(a)=="array"};goog.isArrayLike=function(a){var b=goog.typeOf(a);return b=="array"||b=="object"&&typeof a.length=="number"};goog.isDateLike=function(a){return goog.isObject(a)&&typeof a.getFullYear=="function"};goog.isString=function(a){return typeof a=="string"};goog.isBoolean=function(a){return typeof a=="boolean"};goog.isNumber=function(a){return typeof a=="number"};goog.isFunction=function(a){return goog.typeOf(a)=="function"};
goog.isObject=function(a){a=goog.typeOf(a);return a=="object"||a=="array"||a=="function"};goog.getUid=function(a){return a[goog.UID_PROPERTY_]||(a[goog.UID_PROPERTY_]=++goog.uidCounter_)};goog.removeUid=function(a){"removeAttribute"in a&&a.removeAttribute(goog.UID_PROPERTY_);try{delete a[goog.UID_PROPERTY_]}catch(b){}};goog.UID_PROPERTY_="closure_uid_"+Math.floor(Math.random()*2147483648).toString(36);goog.uidCounter_=0;goog.getHashCode=goog.getUid;goog.removeHashCode=goog.removeUid;
goog.cloneObject=function(a){var b=goog.typeOf(a);if(b=="object"||b=="array"){if(a.clone)return a.clone();var b=b=="array"?[]:{},c;for(c in a)b[c]=goog.cloneObject(a[c]);return b}return a};goog.bindNative_=function(a,b,c){return a.call.apply(a.bind,arguments)};
goog.bindJs_=function(a,b,c){if(!a)throw Error();if(arguments.length>2){var d=Array.prototype.slice.call(arguments,2);return function(){var c=Array.prototype.slice.call(arguments);Array.prototype.unshift.apply(c,d);return a.apply(b,c)}}else return function(){return a.apply(b,arguments)}};goog.bind=function(a,b,c){goog.bind=Function.prototype.bind&&Function.prototype.bind.toString().indexOf("native code")!=-1?goog.bindNative_:goog.bindJs_;return goog.bind.apply(null,arguments)};
goog.partial=function(a,b){var c=Array.prototype.slice.call(arguments,1);return function(){var b=Array.prototype.slice.call(arguments);b.unshift.apply(b,c);return a.apply(this,b)}};goog.mixin=function(a,b){for(var c in b)a[c]=b[c]};goog.now=Date.now||function(){return+new Date};
goog.globalEval=function(a){if(goog.global.execScript)goog.global.execScript(a,"JavaScript");else if(goog.global.eval){if(goog.evalWorksForGlobals_==null)goog.global.eval("var _et_ = 1;"),typeof goog.global._et_!="undefined"?(delete goog.global._et_,goog.evalWorksForGlobals_=!0):goog.evalWorksForGlobals_=!1;if(goog.evalWorksForGlobals_)goog.global.eval(a);else{var b=goog.global.document,c=b.createElement("script");c.type="text/javascript";c.defer=!1;c.appendChild(b.createTextNode(a));b.body.appendChild(c);
b.body.removeChild(c)}}else throw Error("goog.globalEval not available");};goog.evalWorksForGlobals_=null;goog.getCssName=function(a,b){var c=function(a){return goog.cssNameMapping_[a]||a},d;d=goog.cssNameMapping_?goog.cssNameMappingStyle_=="BY_WHOLE"?c:function(a){for(var a=a.split("-"),b=[],d=0;d<a.length;d++)b.push(c(a[d]));return b.join("-")}:function(a){return a};return b?a+"-"+d(b):d(a)};goog.setCssNameMapping=function(a,b){goog.cssNameMapping_=a;goog.cssNameMappingStyle_=b};
goog.getMsg=function(a,b){var c=b||{},d;for(d in c)var e=(""+c[d]).replace(/\$/g,"$$$$"),a=a.replace(RegExp("\\{\\$"+d+"\\}","gi"),e);return a};goog.exportSymbol=function(a,b,c){goog.exportPath_(a,b,c)};goog.exportProperty=function(a,b,c){a[b]=c};goog.inherits=function(a,b){function c(){}c.prototype=b.prototype;a.superClass_=b.prototype;a.prototype=new c;a.prototype.constructor=a};
goog.base=function(a,b,c){var d=arguments.callee.caller;if(d.superClass_)return d.superClass_.constructor.apply(a,Array.prototype.slice.call(arguments,1));for(var e=Array.prototype.slice.call(arguments,2),f=!1,g=a.constructor;g;g=g.superClass_&&g.superClass_.constructor)if(g.prototype[b]===d)f=!0;else if(f)return g.prototype[b].apply(a,e);if(a[b]===d)return a.constructor.prototype[b].apply(a,e);else throw Error("goog.base called from a method of one name to a method of a different name");};
goog.scope=function(a){a.call(goog.global)};var UsageTracker=function(a){this.doTrack=!1;this.id=a;this.freeCount=this.getCount=this.createCount=0;this.creates={};this.gets={};this.frees={};this.callers=[];UsageTracker.trackers.push(this);UsageTracker.trackersByID[a]=this};UsageTracker.trackers=[];UsageTracker.trackersByID={};UsageTracker.ENABLED=!1;if(!UsageTracker.ENABLED)UsageTracker.dummyTracker=new UsageTracker("NotTracking");
UsageTracker.get=function(a){if(!UsageTracker.ENABLED)return UsageTracker.dummyTracker;var b=UsageTracker.trackersByID[a];b==null&&(b=new UsageTracker(a));return b};UsageTracker.logStatsToConsole=function(){for(var a=0;a<UsageTracker.trackers.length;a++){var b=UsageTracker.trackers[a],c=b.getCount-b.freeCount;window.console.log(b.id+": "+b.createCount+"; "+b.getCount+" - "+b.freeCount+" = "+c+(c>0?" ("+Math.round(c/b.getCount*1E4)/100+"%)":""))}};
UsageTracker.prototype.trackCreate=function(){UsageTracker.ENABLED&&(this.createCount++,this.doTrack&&this.increment(this.creates,this.getCallers()))};UsageTracker.prototype.trackGet=function(){UsageTracker.ENABLED&&(this.getCount++,this.doTrack&&this.increment(this.gets,this.getCallers()))};UsageTracker.prototype.trackFree=function(){UsageTracker.ENABLED&&(this.freeCount++,this.doTrack&&this.increment(this.frees,this.getCallers()))};
UsageTracker.prototype.getOffenders=function(){for(var a=[],b=0;b<this.callers.length;b++){var c=this.gets[this.callers[b]]-this.frees[this.callers[b]];c!=0&&a.push(this.callers[b]+" = "+c)}return a};UsageTracker.prototype.increment=function(a,b){for(var c=0;c<b.length;c++){var d=b[c];a[d]==null&&(this.gets[d]=0,this.frees[d]=0,this.creates[d]=0,this.callers.push(d));a[d]++}};
UsageTracker.prototype.getCallers=function(){var a=["unknown"];try{this.nonMethod()}catch(b){var c=b.stack.match(/[A-Za-z0-9]+\.js:\d+:\d+/g).splice(3);c.length!=0&&(a=c)}return a};var Box2D={Common:{}};Box2D.Common.Math={};Box2D.Common.Math.b2Vec2=function(a,b){UsageTracker.get("Box2D.Common.Math.b2Vec2").trackCreate();this.x=a;this.y=b};Box2D.Common.Math.b2Vec2._freeCache=[];Box2D.Common.Math.b2Vec2.Get=function(a,b){UsageTracker.get("Box2D.Common.Math.b2Vec2").trackGet();if(Box2D.Common.Math.b2Vec2._freeCache.length>0){var c=Box2D.Common.Math.b2Vec2._freeCache.pop();c.Set(a,b);return c}return new Box2D.Common.Math.b2Vec2(a,b)};
Box2D.Common.Math.b2Vec2.Free=function(a){a!=null&&(UsageTracker.get("Box2D.Common.Math.b2Vec2").trackFree(),Box2D.Common.Math.b2Vec2._freeCache.push(a))};Box2D.Common.Math.b2Vec2.prototype.SetZero=function(){this.y=this.x=0};Box2D.Common.Math.b2Vec2.prototype.Set=function(a,b){this.x=a;this.y=b};Box2D.Common.Math.b2Vec2.prototype.SetV=function(a){this.x=a.x;this.y=a.y};Box2D.Common.Math.b2Vec2.prototype.GetNegative=function(){return Box2D.Common.Math.b2Vec2.Get(-this.x,-this.y)};
Box2D.Common.Math.b2Vec2.prototype.NegativeSelf=function(){this.x=-this.x;this.y=-this.y};Box2D.Common.Math.b2Vec2.prototype.Copy=function(){return Box2D.Common.Math.b2Vec2.Get(this.x,this.y)};Box2D.Common.Math.b2Vec2.prototype.Add=function(a){this.x+=a.x;this.y+=a.y};Box2D.Common.Math.b2Vec2.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y};Box2D.Common.Math.b2Vec2.prototype.Multiply=function(a){this.x*=a;this.y*=a};
Box2D.Common.Math.b2Vec2.prototype.MulM=function(a){var b=this.x;this.x=a.col1.x*b+a.col2.x*this.y;this.y=a.col1.y*b+a.col2.y*this.y};Box2D.Common.Math.b2Vec2.prototype.MulTM=function(a){var b=this.x*a.col1.x+this.y*a.col1.y;this.y=this.x*a.col2.x+this.y*a.col2.y;this.x=b};Box2D.Common.Math.b2Vec2.prototype.CrossVF=function(a){var b=this.x;this.x=a*this.y;this.y=-a*b};Box2D.Common.Math.b2Vec2.prototype.CrossFV=function(a){var b=this.x;this.x=-a*this.y;this.y=a*b};
Box2D.Common.Math.b2Vec2.prototype.MinV=function(a){this.x=Math.min(this.x,a.x);this.y=Math.min(this.y,a.y)};Box2D.Common.Math.b2Vec2.prototype.MaxV=function(a){this.x=Math.max(this.x,a.x);this.y=Math.max(this.y,a.y)};Box2D.Common.Math.b2Vec2.prototype.Abs=function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y)};Box2D.Common.Math.b2Vec2.prototype.Length=function(){return Math.sqrt(this.LengthSquared())};Box2D.Common.Math.b2Vec2.prototype.LengthSquared=function(){return this.x*this.x+this.y*this.y};
Box2D.Common.Math.b2Vec2.prototype.Normalize=function(){var a=this.Length();if(a<Number.MIN_VALUE)return 0;var b=1/a;this.x*=b;this.y*=b;return a};Box2D.Common.Math.b2Vec2.prototype.IsValid=function(){return isFinite(this.x)&&isFinite(this.y)};Box2D.Common.b2Settings={};Box2D.Common.b2Settings.b2MixFriction=function(a,b){return Math.sqrt(a*b)};Box2D.Common.b2Settings.b2MixRestitution=function(a,b){return a>b?a:b};Box2D.Common.b2Settings.b2Assert=function(a){if(!a)throw"Assertion Failed";};Box2D.Common.b2Settings.VERSION="2.1alpha-illandril";Box2D.Common.b2Settings.USHRT_MAX=65535;Box2D.Common.b2Settings.b2_maxManifoldPoints=2;Box2D.Common.b2Settings.b2_aabbExtension=0.1;Box2D.Common.b2Settings.b2_aabbMultiplier=2;
Box2D.Common.b2Settings.b2_polygonRadius=2*Box2D.Common.b2Settings.b2_linearSlop;Box2D.Common.b2Settings.b2_linearSlop=0.005;Box2D.Common.b2Settings.b2_angularSlop=2/180*Math.PI;Box2D.Common.b2Settings.b2_toiSlop=8*Box2D.Common.b2Settings.b2_linearSlop;Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland=32;Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland=32;Box2D.Common.b2Settings.b2_velocityThreshold=1;Box2D.Common.b2Settings.b2_maxLinearCorrection=0.2;
Box2D.Common.b2Settings.b2_maxAngularCorrection=8/180*Math.PI;Box2D.Common.b2Settings.b2_maxTranslation=2;Box2D.Common.b2Settings.b2_maxTranslationSquared=Box2D.Common.b2Settings.b2_maxTranslation*Box2D.Common.b2Settings.b2_maxTranslation;Box2D.Common.b2Settings.b2_maxRotation=0.5*Math.PI;Box2D.Common.b2Settings.b2_maxRotationSquared=Box2D.Common.b2Settings.b2_maxRotation*Box2D.Common.b2Settings.b2_maxRotation;Box2D.Common.b2Settings.b2_contactBaumgarte=0.2;
Box2D.Common.b2Settings.b2_timeToSleep=0.5;Box2D.Common.b2Settings.b2_linearSleepTolerance=0.01;Box2D.Common.b2Settings.b2_linearSleepToleranceSquared=Box2D.Common.b2Settings.b2_linearSleepTolerance*Box2D.Common.b2Settings.b2_linearSleepTolerance;Box2D.Common.b2Settings.b2_angularSleepTolerance=2/180*Math.PI;Box2D.Common.b2Settings.b2_angularSleepToleranceSquared=Box2D.Common.b2Settings.b2_angularSleepTolerance*Box2D.Common.b2Settings.b2_angularSleepTolerance;
Box2D.Common.b2Settings.MIN_VALUE_SQUARED=Number.MIN_VALUE*Number.MIN_VALUE;Box2D.Common.Math.b2Mat22=function(){UsageTracker.get("Box2D.Common.Math.b2Mat22").trackCreate();this.col1=Box2D.Common.Math.b2Vec2.Get(0,0);this.col2=Box2D.Common.Math.b2Vec2.Get(0,0);this.SetIdentity()};Box2D.Common.Math.b2Mat22._freeCache=[];Box2D.Common.Math.b2Mat22.Get=function(){UsageTracker.get("Box2D.Common.Math.b2Mat22").trackGet();if(Box2D.Common.Math.b2Mat22._freeCache.length>0){var a=Box2D.Common.Math.b2Mat22._freeCache.pop();a.SetZero();return a}return new Box2D.Common.Math.b2Mat22};
Box2D.Common.Math.b2Mat22.Free=function(a){a!=null&&(UsageTracker.get("Box2D.Common.Math.b2Mat22").trackFree(),Box2D.Common.Math.b2Mat22._freeCache.push(a))};Box2D.Common.Math.b2Mat22.FromAngle=function(a){var b=Box2D.Common.Math.b2Mat22.Get();b.Set(a);return b};Box2D.Common.Math.b2Mat22.FromVV=function(a,b){var c=Box2D.Common.Math.b2Mat22.Get();c.SetVV(a,b);return c};Box2D.Common.Math.b2Mat22.prototype.Set=function(a){var b=Math.cos(a),a=Math.sin(a);this.col1.Set(b,a);this.col2.Set(-a,b)};
Box2D.Common.Math.b2Mat22.prototype.SetVV=function(a,b){this.col1.SetV(a);this.col2.SetV(b)};Box2D.Common.Math.b2Mat22.prototype.Copy=function(){var a=Box2D.Common.Math.b2Mat22.Get();a.SetM(this);return a};Box2D.Common.Math.b2Mat22.prototype.SetM=function(a){this.col1.SetV(a.col1);this.col2.SetV(a.col2)};Box2D.Common.Math.b2Mat22.prototype.AddM=function(a){this.col1.Add(a.col1);this.col2.Add(a.col2)};Box2D.Common.Math.b2Mat22.prototype.SetIdentity=function(){this.col1.Set(1,0);this.col2.Set(0,1)};
Box2D.Common.Math.b2Mat22.prototype.SetZero=function(){this.col1.Set(0,0);this.col2.Set(0,0)};Box2D.Common.Math.b2Mat22.prototype.GetAngle=function(){return Math.atan2(this.col1.y,this.col1.x)};Box2D.Common.Math.b2Mat22.prototype.GetInverse=function(a){var b=this.col1.x*this.col2.y-this.col2.x*this.col1.y;b!==0&&(b=1/b);a.col1.x=b*this.col2.y;a.col2.x=-b*this.col2.x;a.col1.y=-b*this.col1.y;a.col2.y=b*this.col1.x;return a};
Box2D.Common.Math.b2Mat22.prototype.Solve=function(a,b,c){var d=this.col1.x*this.col2.y-this.col2.x*this.col1.y;d!==0&&(d=1/d);a.x=d*(this.col2.y*b-this.col2.x*c);a.y=d*(this.col1.x*c-this.col1.y*b);return a};Box2D.Common.Math.b2Mat22.prototype.Abs=function(){this.col1.Abs();this.col2.Abs()};Box2D.Common.Math.b2Math={};Box2D.Common.Math.b2Math.Dot=function(a,b){return a.x*b.x+a.y*b.y};Box2D.Common.Math.b2Math.CrossVV=function(a,b){return a.x*b.y-a.y*b.x};Box2D.Common.Math.b2Math.CrossVF=function(a,b){return Box2D.Common.Math.b2Vec2.Get(b*a.y,-b*a.x)};Box2D.Common.Math.b2Math.CrossFV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(-a*b.y,a*b.x)};Box2D.Common.Math.b2Math.MulMV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a.col1.x*b.x+a.col2.x*b.y,a.col1.y*b.x+a.col2.y*b.y)};
Box2D.Common.Math.b2Math.MulTMV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(Box2D.Common.Math.b2Math.Dot(b,a.col1),Box2D.Common.Math.b2Math.Dot(b,a.col2))};Box2D.Common.Math.b2Math.MulX=function(a,b){var c=Box2D.Common.Math.b2Math.MulMV(a.R,b);c.x+=a.position.x;c.y+=a.position.y;return c};Box2D.Common.Math.b2Math.MulXT=function(a,b){var c=Box2D.Common.Math.b2Math.SubtractVV(b,a.position),d=c.x*a.R.col1.x+c.y*a.R.col1.y;c.y=c.x*a.R.col2.x+c.y*a.R.col2.y;c.x=d;return c};
Box2D.Common.Math.b2Math.AddVV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a.x+b.x,a.y+b.y)};Box2D.Common.Math.b2Math.SubtractVV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a.x-b.x,a.y-b.y)};Box2D.Common.Math.b2Math.Distance=function(a,b){return Math.sqrt(Box2D.Common.Math.b2Math.DistanceSquared(a,b))};Box2D.Common.Math.b2Math.DistanceSquared=function(a,b){var c=a.x-b.x,d=a.y-b.y;return c*c+d*d};Box2D.Common.Math.b2Math.MulFV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a*b.x,a*b.y)};
Box2D.Common.Math.b2Math.AddMM=function(a,b){var c=Box2D.Common.Math.b2Math.AddVV(a.col1,b.col1),d=Box2D.Common.Math.b2Math.AddVV(a.col2,b.col2),e=Box2D.Common.Math.b2Mat22.FromVV(c,d);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(d);return e};
Box2D.Common.Math.b2Math.MulMM=function(a,b){var c=Box2D.Common.Math.b2Math.MulMV(a,b.col1),d=Box2D.Common.Math.b2Math.MulMV(a,b.col2),e=Box2D.Common.Math.b2Mat22.FromVV(c,d);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(d);return e};
Box2D.Common.Math.b2Math.MulTMM=function(a,b){var c=Box2D.Common.Math.b2Vec2.Get(Box2D.Common.Math.b2Math.Dot(a.col1,b.col1),Box2D.Common.Math.b2Math.Dot(a.col2,b.col1)),d=Box2D.Common.Math.b2Vec2.Get(Box2D.Common.Math.b2Math.Dot(a.col1,b.col2),Box2D.Common.Math.b2Math.Dot(a.col2,b.col2)),e=Box2D.Common.Math.b2Mat22.FromVV(c,d);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(d);return e};Box2D.Common.Math.b2Math.AbsV=function(a){return Box2D.Common.Math.b2Vec2.Get(Math.abs(a.x),Math.abs(a.y))};
Box2D.Common.Math.b2Math.AbsM=function(a){var b=Box2D.Common.Math.b2Math.AbsV(a.col1),a=Box2D.Common.Math.b2Math.AbsV(a.col2),c=Box2D.Common.Math.b2Mat22.FromVV(b,a);Box2D.Common.Math.b2Vec2.Free(b);Box2D.Common.Math.b2Vec2.Free(a);return c};Box2D.Common.Math.b2Math.Clamp=function(a,b,c){return a<b?b:a>c?c:a};Box2D.Common.Math.b2Math.ClampV=function(a,b,c){var d=Box2D.Common.Math.b2Math.Clamp(a.x,b.x,c.x),a=Box2D.Common.Math.b2Math.Clamp(a.y,b.y,c.y);return Box2D.Common.Math.b2Vec2.Get(d,a)};Box2D.Dynamics={};Box2D.Dynamics.Joints={};Box2D.Dynamics.Joints.b2JointEdge=function(){};Box2D.Dynamics.Joints.b2Joint=function(a){this.m_edgeA=new Box2D.Dynamics.Joints.b2JointEdge;this.m_edgeB=new Box2D.Dynamics.Joints.b2JointEdge;this.m_localCenterA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localCenterB=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Common.b2Settings.b2Assert(a.bodyA!=a.bodyB);this.m_type=a.type;this.m_next=this.m_prev=null;this.m_bodyA=a.bodyA;this.m_bodyB=a.bodyB;this.m_collideConnected=a.collideConnected};Box2D.Dynamics.Joints.b2Joint.prototype.GetType=function(){return this.m_type};
Box2D.Dynamics.Joints.b2Joint.prototype.GetAnchorA=function(){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetAnchorB=function(){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetReactionForce=function(){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetReactionTorque=function(){return 0};Box2D.Dynamics.Joints.b2Joint.prototype.GetBodyA=function(){return this.m_bodyA};Box2D.Dynamics.Joints.b2Joint.prototype.GetBodyB=function(){return this.m_bodyB};
Box2D.Dynamics.Joints.b2Joint.prototype.GetNext=function(){return this.m_next};Box2D.Dynamics.Joints.b2Joint.prototype.IsActive=function(){return this.m_bodyA.IsActive()&&this.m_bodyB.IsActive()};Box2D.Dynamics.Joints.b2Joint.Create=function(a){return a.Create()};Box2D.Dynamics.Joints.b2Joint.prototype.InitVelocityConstraints=function(){};Box2D.Dynamics.Joints.b2Joint.prototype.SolveVelocityConstraints=function(){};Box2D.Dynamics.Joints.b2Joint.prototype.FinalizeVelocityConstraints=function(){};
Box2D.Dynamics.Joints.b2Joint.prototype.SolvePositionConstraints=function(){return!1};Box2D.Dynamics.Joints.b2Joint.e_unknownJoint=0;Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint=1;Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint=2;Box2D.Dynamics.Joints.b2Joint.e_distanceJoint=3;Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint=4;Box2D.Dynamics.Joints.b2Joint.e_mouseJoint=5;Box2D.Dynamics.Joints.b2Joint.e_gearJoint=6;Box2D.Dynamics.Joints.b2Joint.e_lineJoint=7;Box2D.Dynamics.Joints.b2Joint.e_weldJoint=8;
Box2D.Dynamics.Joints.b2Joint.e_frictionJoint=9;Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit=0;Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit=1;Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit=2;Box2D.Dynamics.Joints.b2Joint.e_equalLimits=3;Box2D.Dynamics.Joints.b2LineJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localXAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localYAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_perp=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K=Box2D.Common.Math.b2Mat22.Get();this.m_impulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1.SetV(a.localAnchorA);
this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=-this.m_localXAxis1.y;this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_impulse.SetZero();this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;
this.m_axis.SetZero();this.m_perp.SetZero()};goog.inherits(Box2D.Dynamics.Joints.b2LineJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2LineJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};
Box2D.Dynamics.Joints.b2LineJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y))};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.y};
Box2D.Dynamics.Joints.b2LineJoint.prototype.GetJointTranslation=function(){var a=this.m_bodyA,b=this.m_bodyB,c=a.GetWorldPoint(this.m_localAnchor1),d=b.GetWorldPoint(this.m_localAnchor2),b=d.x-c.x,c=d.y-c.y,a=a.GetWorldVector(this.m_localXAxis1);return a.x*b+a.y*c};
Box2D.Dynamics.Joints.b2LineJoint.prototype.GetJointSpeed=function(){var a=this.m_bodyA,b=this.m_bodyB,c;c=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,e=this.m_localAnchor1.y-a.m_sweep.localCenter.y,f=c.col1.x*d+c.col2.x*e,e=c.col1.y*d+c.col2.y*e,d=f;c=b.m_xf.R;var g=this.m_localAnchor2.x-b.m_sweep.localCenter.x,h=this.m_localAnchor2.y-b.m_sweep.localCenter.y,f=c.col1.x*g+c.col2.x*h,h=c.col1.y*g+c.col2.y*h,g=f;c=b.m_sweep.c.x+g-(a.m_sweep.c.x+d);var f=b.m_sweep.c.y+h-(a.m_sweep.c.y+
e),i=a.GetWorldVector(this.m_localXAxis1),j=a.m_linearVelocity,k=b.m_linearVelocity,a=a.m_angularVelocity,b=b.m_angularVelocity;return c*-a*i.y+f*a*i.x+(i.x*(k.x+-b*h-j.x- -a*e)+i.y*(k.y+b*g-j.y-a*d))};Box2D.Dynamics.Joints.b2LineJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2LineJoint.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableLimit=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};
Box2D.Dynamics.Joints.b2LineJoint.prototype.GetUpperLimit=function(){return this.m_upperTranslation};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetLimits=function(a,b){a===void 0&&(a=0);b===void 0&&(b=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_lowerTranslation=a;this.m_upperTranslation=b};Box2D.Dynamics.Joints.b2LineJoint.prototype.IsMotorEnabled=function(){return this.m_enableMotor};
Box2D.Dynamics.Joints.b2LineJoint.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableMotor=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetMotorSpeed=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};
Box2D.Dynamics.Joints.b2LineJoint.prototype.SetMaxMotorForce=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_maxMotorForce=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMaxMotorForce=function(){return this.m_maxMotorForce};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMotorForce=function(){return this.m_motorImpulse};
Box2D.Dynamics.Joints.b2LineJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d,e=0;this.m_localCenterA.SetV(b.GetLocalCenter());this.m_localCenterB.SetV(c.GetLocalCenter());var f=b.GetTransform();c.GetTransform();d=b.m_xf.R;var g=this.m_localAnchor1.x-this.m_localCenterA.x,h=this.m_localAnchor1.y-this.m_localCenterA.y,e=d.col1.x*g+d.col2.x*h,h=d.col1.y*g+d.col2.y*h,g=e;d=c.m_xf.R;var i=this.m_localAnchor2.x-this.m_localCenterB.x,j=this.m_localAnchor2.y-this.m_localCenterB.y,
e=d.col1.x*i+d.col2.x*j,j=d.col1.y*i+d.col2.y*j,i=e;d=c.m_sweep.c.x+i-b.m_sweep.c.x-g;e=c.m_sweep.c.y+j-b.m_sweep.c.y-h;this.m_invMassA=b.m_invMass;this.m_invMassB=c.m_invMass;this.m_invIA=b.m_invI;this.m_invIB=c.m_invI;this.m_axis.SetV(Box2D.Common.Math.b2Math.MulMV(f.R,this.m_localXAxis1));this.m_a1=(d+g)*this.m_axis.y-(e+h)*this.m_axis.x;this.m_a2=i*this.m_axis.y-j*this.m_axis.x;this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+this.m_invIB*this.m_a2*this.m_a2;this.m_motorMass=
this.m_motorMass>Number.MIN_VALUE?1/this.m_motorMass:0;this.m_perp.SetV(Box2D.Common.Math.b2Math.MulMV(f.R,this.m_localYAxis1));this.m_s1=(d+g)*this.m_perp.y-(e+h)*this.m_perp.x;this.m_s2=i*this.m_perp.y-j*this.m_perp.x;f=this.m_invMassA;g=this.m_invMassB;h=this.m_invIA;i=this.m_invIB;this.m_K.col1.x=f+g+h*this.m_s1*this.m_s1+i*this.m_s2*this.m_s2;this.m_K.col1.y=h*this.m_s1*this.m_a1+i*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=f+g+h*this.m_a1*this.m_a1+i*this.m_a2*this.m_a2;
if(this.m_enableLimit)if(d=this.m_axis.x*d+this.m_axis.y*e,Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop)this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits;else if(d<=this.m_lowerTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit)this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit,this.m_impulse.y=0}else if(d>=this.m_upperTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)this.m_limitState=
Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit,this.m_impulse.y=0}else this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse.y=0;else this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;if(this.m_enableMotor==!1)this.m_motorImpulse=0;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x,d=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+
this.m_impulse.y)*this.m_axis.y,e=this.m_impulse.x*this.m_s1+(this.m_motorImpulse+this.m_impulse.y)*this.m_a1,f=this.m_impulse.x*this.m_s2+(this.m_motorImpulse+this.m_impulse.y)*this.m_a2,b.m_linearVelocity.x-=this.m_invMassA*a,b.m_linearVelocity.y-=this.m_invMassA*d,b.m_angularVelocity-=this.m_invIA*e,c.m_linearVelocity.x+=this.m_invMassB*a,c.m_linearVelocity.y+=this.m_invMassB*d,c.m_angularVelocity+=this.m_invIB*f):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};
Box2D.Dynamics.Joints.b2LineJoint.prototype.SolveVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d=b.m_linearVelocity,e=b.m_angularVelocity,f=c.m_linearVelocity,g=c.m_angularVelocity,h=0,i=0,j=0,k=0;if(this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits)k=this.m_motorMass*(this.m_motorSpeed-(this.m_axis.x*(f.x-d.x)+this.m_axis.y*(f.y-d.y)+this.m_a2*g-this.m_a1*e)),h=this.m_motorImpulse,a=a.dt*this.m_maxMotorForce,this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+
k,-a,a),k=this.m_motorImpulse-h,h=k*this.m_axis.x,i=k*this.m_axis.y,j=k*this.m_a1,k*=this.m_a2,d.x-=this.m_invMassA*h,d.y-=this.m_invMassA*i,e-=this.m_invIA*j,f.x+=this.m_invMassB*h,f.y+=this.m_invMassB*i,g+=this.m_invIB*k;i=this.m_perp.x*(f.x-d.x)+this.m_perp.y*(f.y-d.y)+this.m_s2*g-this.m_s1*e;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){a=this.m_axis.x*(f.x-d.x)+this.m_axis.y*(f.y-d.y)+this.m_a2*g-this.m_a1*e;h=this.m_impulse.Copy();j=Box2D.Common.Math.b2Vec2.Get(0,
0);a=this.m_K.Solve(j,-i,-a);Box2D.Common.Math.b2Vec2.Free(j);this.m_impulse.Add(a);if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit)this.m_impulse.y=Math.max(this.m_impulse.y,0);else if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)this.m_impulse.y=Math.min(this.m_impulse.y,0);i=-i-(this.m_impulse.y-h.y)*this.m_K.col2.x;j=0;j=this.m_K.col1.x!=0?i/this.m_K.col1.x+h.x:h.x;this.m_impulse.x=j;a.x=this.m_impulse.x-h.x;a.y=this.m_impulse.y-h.y;Box2D.Common.Math.b2Vec2.Free(h);
h=a.x*this.m_perp.x+a.y*this.m_axis.x;i=a.x*this.m_perp.y+a.y*this.m_axis.y;j=a.x*this.m_s1+a.y*this.m_a1;k=a.x*this.m_s2+a.y*this.m_a2}else a=0,a=this.m_K.col1.x!=0?-i/this.m_K.col1.x:0,this.m_impulse.x+=a,h=a*this.m_perp.x,i=a*this.m_perp.y,j=a*this.m_s1,k=a*this.m_s2;d.x-=this.m_invMassA*h;d.y-=this.m_invMassA*i;e-=this.m_invIA*j;f.x+=this.m_invMassB*h;f.y+=this.m_invMassB*i;g+=this.m_invIB*k;b.m_linearVelocity.SetV(d);b.m_angularVelocity=e;c.m_linearVelocity.SetV(f);c.m_angularVelocity=g};
Box2D.Dynamics.Joints.b2LineJoint.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,b=this.m_bodyB,c=a.m_sweep.c,d=a.m_sweep.a,e=b.m_sweep.c,f=b.m_sweep.a,g,h=0,i=0,j=0,k=0,l=g=0,n=0,i=!1,m=0,o=Box2D.Common.Math.b2Mat22.FromAngle(d),j=Box2D.Common.Math.b2Mat22.FromAngle(f);g=o;var n=this.m_localAnchor1.x-this.m_localCenterA.x,p=this.m_localAnchor1.y-this.m_localCenterA.y,h=g.col1.x*n+g.col2.x*p,p=g.col1.y*n+g.col2.y*p,n=h;g=j;j=this.m_localAnchor2.x-this.m_localCenterB.x;k=this.m_localAnchor2.y-
this.m_localCenterB.y;h=g.col1.x*j+g.col2.x*k;k=g.col1.y*j+g.col2.y*k;j=h;g=e.x+j-c.x-n;h=e.y+k-c.y-p;if(this.m_enableLimit){this.m_axis=Box2D.Common.Math.b2Math.MulMV(o,this.m_localXAxis1);this.m_a1=(g+n)*this.m_axis.y-(h+p)*this.m_axis.x;this.m_a2=j*this.m_axis.y-k*this.m_axis.x;var q=this.m_axis.x*g+this.m_axis.y*h;Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop?(m=Box2D.Common.Math.b2Math.Clamp(q,-Box2D.Common.b2Settings.b2_maxLinearCorrection,
Box2D.Common.b2Settings.b2_maxLinearCorrection),l=Math.abs(q),i=!0):q<=this.m_lowerTranslation?(m=Box2D.Common.Math.b2Math.Clamp(q-this.m_lowerTranslation+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),l=this.m_lowerTranslation-q,i=!0):q>=this.m_upperTranslation&&(m=Box2D.Common.Math.b2Math.Clamp(q-this.m_upperTranslation+Box2D.Common.b2Settings.b2_linearSlop,0,Box2D.Common.b2Settings.b2_maxLinearCorrection),l=q-this.m_upperTranslation,i=!0)}this.m_perp=Box2D.Common.Math.b2Math.MulMV(o,
this.m_localYAxis1);this.m_s1=(g+n)*this.m_perp.y-(h+p)*this.m_perp.x;this.m_s2=j*this.m_perp.y-k*this.m_perp.x;o=Box2D.Common.Math.b2Vec2.Get(0,0);p=this.m_perp.x*g+this.m_perp.y*h;l=Math.max(l,Math.abs(p));n=0;i?(i=this.m_invMassA,j=this.m_invMassB,k=this.m_invIA,g=this.m_invIB,this.m_K.col1.x=i+j+k*this.m_s1*this.m_s1+g*this.m_s2*this.m_s2,this.m_K.col1.y=k*this.m_s1*this.m_a1+g*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=i+j+k*this.m_a1*this.m_a1+g*this.m_a2*this.m_a2,
this.m_K.Solve(o,-p,-m)):(i=this.m_invMassA,j=this.m_invMassB,k=this.m_invIA,g=this.m_invIB,m=i+j+k*this.m_s1*this.m_s1+g*this.m_s2*this.m_s2,i=0,o.x=m!=0?-p/m:0,o.y=0);m=o.x*this.m_perp.x+o.y*this.m_axis.x;i=o.x*this.m_perp.y+o.y*this.m_axis.y;p=o.x*this.m_s1+o.y*this.m_a1;o=o.x*this.m_s2+o.y*this.m_a2;c.x-=this.m_invMassA*m;c.y-=this.m_invMassA*i;d-=this.m_invIA*p;e.x+=this.m_invMassB*m;e.y+=this.m_invMassB*i;f+=this.m_invIB*o;a.m_sweep.a=d;b.m_sweep.a=f;a.SynchronizeTransform();b.SynchronizeTransform();
return l<=Box2D.Common.b2Settings.b2_linearSlop&&n<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2JointDef=function(){this.type=Box2D.Dynamics.Joints.b2Joint.e_unknownJoint;this.bodyB=this.bodyA=null;this.collideConnected=!1};Box2D.Dynamics.Joints.b2LineJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAxisA=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_lineJoint;this.localAxisA.Set(1,0);this.enableLimit=!1;this.upperTranslation=this.lowerTranslation=0;this.enableMotor=!1;this.motorSpeed=this.maxMotorForce=0};goog.inherits(Box2D.Dynamics.Joints.b2LineJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2LineJointDef.prototype.Initialize=function(a,b,c,d){this.bodyA=a;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(c);this.localAnchorB=this.bodyB.GetLocalPoint(c);this.localAxisA=this.bodyA.GetLocalVector(d)};Box2D.Dynamics.Joints.b2LineJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2LineJoint(this)};Box2D.Collision={};Box2D.Collision.b2DistanceProxy=function(){UsageTracker.get("Box2D.Collision.b2DistanceProxy").trackCreate();this.m_radius=this.m_count=0;this.m_vertices=[]};Box2D.Collision.b2DistanceProxy.prototype.SetValues=function(a,b,c){this.m_count=a;this.m_radius=b;this.m_vertices=c};Box2D.Collision.b2DistanceProxy.prototype.Set=function(a){a.SetDistanceProxy(this)};
Box2D.Collision.b2DistanceProxy.prototype.GetSupport=function(a){for(var b=0,c=this.m_vertices[0].x*a.x+this.m_vertices[0].y*a.y,d=1;d<this.m_count;d++){var e=this.m_vertices[d].x*a.x+this.m_vertices[d].y*a.y;e>c&&(b=d,c=e)}return b};Box2D.Collision.b2DistanceProxy.prototype.GetSupportVertex=function(a){return this.m_vertices[this.GetSupport(a)]};Box2D.Collision.b2DistanceProxy.prototype.GetVertexCount=function(){return this.m_count};
Box2D.Collision.b2DistanceProxy.prototype.GetVertex=function(a){a===void 0&&(a=0);Box2D.Common.b2Settings.b2Assert(0<=a&&a<this.m_count);return this.m_vertices[a]};Box2D.Collision.b2DistanceProxy.prototype.GetRadius=function(){return this.m_radius};Box2D.Common.Math.b2Sweep=function(){UsageTracker.get("Box2D.Common.Math.b2Sweep").trackCreate();this.localCenter=Box2D.Common.Math.b2Vec2.Get(0,0);this.c0=Box2D.Common.Math.b2Vec2.Get(0,0);this.c=Box2D.Common.Math.b2Vec2.Get(0,0);this.t0=this.a=this.a0=null};Box2D.Common.Math.b2Sweep.prototype.Set=function(a){this.localCenter.SetV(a.localCenter);this.c0.SetV(a.c0);this.c.SetV(a.c);this.a0=a.a0;this.a=a.a;this.t0=a.t0};
Box2D.Common.Math.b2Sweep.prototype.Copy=function(){var a=new Box2D.Common.Math.b2Sweep;a.localCenter.SetV(this.localCenter);a.c0.SetV(this.c0);a.c.SetV(this.c);a.a0=this.a0;a.a=this.a;a.t0=this.t0;return a};
Box2D.Common.Math.b2Sweep.prototype.GetTransform=function(a,b){b===void 0&&(b=0);a.position.x=(1-b)*this.c0.x+b*this.c.x;a.position.y=(1-b)*this.c0.y+b*this.c.y;a.R.Set((1-b)*this.a0+b*this.a);var c=a.R;a.position.x-=c.col1.x*this.localCenter.x+c.col2.x*this.localCenter.y;a.position.y-=c.col1.y*this.localCenter.x+c.col2.y*this.localCenter.y};
Box2D.Common.Math.b2Sweep.prototype.Advance=function(a){a===void 0&&(a=0);if(this.t0<a&&1-this.t0>Number.MIN_VALUE){var b=(a-this.t0)/(1-this.t0);this.c0.x=(1-b)*this.c0.x+b*this.c.x;this.c0.y=(1-b)*this.c0.y+b*this.c.y;this.a0=(1-b)*this.a0+b*this.a;this.t0=a}};Box2D.Collision.b2TOIInput=function(){UsageTracker.get("Box2D.Collision.b2TOIInput").trackCreate();this.proxyA=new Box2D.Collision.b2DistanceProxy;this.proxyB=new Box2D.Collision.b2DistanceProxy;this.sweepA=new Box2D.Common.Math.b2Sweep;this.sweepB=new Box2D.Common.Math.b2Sweep};Box2D.Common.Math.b2Vec3=function(a,b,c){UsageTracker.get("Box2D.Common.Math.b2Vec3").trackCreate();this.x=a;this.y=b;this.z=c};Box2D.Common.Math.b2Vec3._freeCache=[];Box2D.Common.Math.b2Vec3.Get=function(a,b,c){UsageTracker.get("Box2D.Common.Math.b2Vec3").trackGet();if(Box2D.Common.Math.b2Vec3._freeCache.length>0){var d=Box2D.Common.Math.b2Vec3._freeCache.pop();d.Set(a,b,c);return d}return new Box2D.Common.Math.b2Vec3(a,b,c)};
Box2D.Common.Math.b2Vec3.Free=function(a){a!=null&&(UsageTracker.get("Box2D.Common.Math.b2Vec3").trackFree(),Box2D.Common.Math.b2Vec3._freeCache.push(a))};Box2D.Common.Math.b2Vec3.prototype.SetZero=function(){this.z=this.y=this.x=0};Box2D.Common.Math.b2Vec3.prototype.Set=function(a,b,c){this.x=a;this.y=b;this.z=c};Box2D.Common.Math.b2Vec3.prototype.SetV=function(a){this.x=a.x;this.y=a.y;this.z=a.z};
Box2D.Common.Math.b2Vec3.prototype.GetNegative=function(){return Box2D.Common.Math.b2Vec3.Get(-this.x,-this.y,-this.z)};Box2D.Common.Math.b2Vec3.prototype.NegativeSelf=function(){this.x=-this.x;this.y=-this.y;this.z=-this.z};Box2D.Common.Math.b2Vec3.prototype.Copy=function(){return Box2D.Common.Math.b2Vec3.Get(this.x,this.y,this.z)};Box2D.Common.Math.b2Vec3.prototype.Add=function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z};
Box2D.Common.Math.b2Vec3.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z};Box2D.Common.Math.b2Vec3.prototype.Multiply=function(a){this.x*=a;this.y*=a;this.z*=a};Box2D.Common.Math.b2Mat33=function(a,b,c){UsageTracker.get("Box2D.Common.Math.b2Mat33").trackCreate();this.col1=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.col2=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.col3=Box2D.Common.Math.b2Vec3.Get(0,0,0);a&&this.col1.SetV(a);b&&this.col2.SetV(b);c&&this.col3.SetV(c)};Box2D.Common.Math.b2Mat33.prototype.SetVVV=function(a,b,c){this.col1.SetV(a);this.col2.SetV(b);this.col3.SetV(c)};
Box2D.Common.Math.b2Mat33.prototype.Copy=function(){return new Box2D.Common.Math.b2Mat33(this.col1,this.col2,this.col3)};Box2D.Common.Math.b2Mat33.prototype.SetM=function(a){this.col1.SetV(a.col1);this.col2.SetV(a.col2);this.col3.SetV(a.col3)};Box2D.Common.Math.b2Mat33.prototype.AddM=function(a){this.col1.x+=a.col1.x;this.col1.y+=a.col1.y;this.col1.z+=a.col1.z;this.col2.x+=a.col2.x;this.col2.y+=a.col2.y;this.col2.z+=a.col2.z;this.col3.x+=a.col3.x;this.col3.y+=a.col3.y;this.col3.z+=a.col3.z};
Box2D.Common.Math.b2Mat33.prototype.SetIdentity=function(){this.col1.Set(1,0,0);this.col2.Set(0,1,0);this.col3.Set(0,0,1)};Box2D.Common.Math.b2Mat33.prototype.SetZero=function(){this.col1.Set(0,0,0);this.col2.Set(0,0,0);this.col3.Set(0,0,0)};Box2D.Common.Math.b2Mat33.prototype.Solve22=function(a,b,c){var d=this.col1.x,e=this.col2.x,f=this.col1.y,g=this.col2.y,h=d*g-e*f;h!=0&&(h=1/h);a.x=h*(g*b-e*c);a.y=h*(d*c-f*b);return a};
Box2D.Common.Math.b2Mat33.prototype.Solve33=function(a,b,c,d){var e=this.col1.x,f=this.col1.y,g=this.col1.z,h=this.col2.x,i=this.col2.y,j=this.col2.z,k=this.col3.x,l=this.col3.y,n=this.col3.z,m=e*(i*n-j*l)+f*(j*k-h*n)+g*(h*l-i*k);m!=0&&(m=1/m);a.x=m*(b*(i*n-j*l)+c*(j*k-h*n)+d*(h*l-i*k));a.y=m*(e*(c*n-d*l)+f*(d*k-b*n)+g*(b*l-c*k));a.z=m*(e*(i*d-j*c)+f*(j*b-h*d)+g*(h*c-i*b));return a};Box2D.Dynamics.Joints.b2PrismaticJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localXAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localYAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_perp=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K=new Box2D.Common.Math.b2Mat33;this.m_impulse=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_localAnchor1.SetV(a.localAnchorA);
this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=-this.m_localXAxis1.y;this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_refAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;
this.m_axis.SetZero();this.m_perp.SetZero()};goog.inherits(Box2D.Dynamics.Joints.b2PrismaticJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y))};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.y};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetJointTranslation=function(){var a=this.m_bodyA,b=this.m_bodyB,c=a.GetWorldPoint(this.m_localAnchor1),d=b.GetWorldPoint(this.m_localAnchor2),b=d.x-c.x,e=d.y-c.y;Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(d);a=a.GetWorldVector(this.m_localXAxis1);c=a.x*b+a.y*e;Box2D.Common.Math.b2Vec2.Free(a);return c};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetJointSpeed=function(){var a=this.m_bodyA,b=this.m_bodyB,c;c=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,e=this.m_localAnchor1.y-a.m_sweep.localCenter.y,f=c.col1.x*d+c.col2.x*e,e=c.col1.y*d+c.col2.y*e,d=f;c=b.m_xf.R;var g=this.m_localAnchor2.x-b.m_sweep.localCenter.x,h=this.m_localAnchor2.y-b.m_sweep.localCenter.y,f=c.col1.x*g+c.col2.x*h,h=c.col1.y*g+c.col2.y*h,g=f,f=b.m_sweep.c.x+g-(a.m_sweep.c.x+d),i=b.m_sweep.c.y+h-(a.m_sweep.c.y+
e);c=a.GetWorldVector(this.m_localXAxis1);var j=a.m_linearVelocity,k=b.m_linearVelocity,a=a.m_angularVelocity,b=b.m_angularVelocity,d=f*-a*c.y+i*a*c.x+(c.x*(k.x+-b*h-j.x- -a*e)+c.y*(k.y+b*g-j.y-a*d));Box2D.Common.Math.b2Vec2.Free(c);return d};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableLimit=a};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetUpperLimit=function(){return this.m_upperTranslation};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetLimits=function(a,b){a===void 0&&(a=0);b===void 0&&(b=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_lowerTranslation=a;this.m_upperTranslation=b};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.IsMotorEnabled=function(){return this.m_enableMotor};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableMotor=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetMotorSpeed=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetMaxMotorForce=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_maxMotorForce=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetMotorForce=function(){return this.m_motorImpulse};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d,e=0;this.m_localCenterA.SetV(b.GetLocalCenter());this.m_localCenterB.SetV(c.GetLocalCenter());var f=b.GetTransform();d=b.m_xf.R;var g=this.m_localAnchor1.x-this.m_localCenterA.x,h=this.m_localAnchor1.y-this.m_localCenterA.y,e=d.col1.x*g+d.col2.x*h,h=d.col1.y*g+d.col2.y*h,g=e;d=c.m_xf.R;var i=this.m_localAnchor2.x-this.m_localCenterB.x,j=this.m_localAnchor2.y-this.m_localCenterB.y,
e=d.col1.x*i+d.col2.x*j,j=d.col1.y*i+d.col2.y*j,i=e;d=c.m_sweep.c.x+i-b.m_sweep.c.x-g;e=c.m_sweep.c.y+j-b.m_sweep.c.y-h;this.m_invMassA=b.m_invMass;this.m_invMassB=c.m_invMass;this.m_invIA=b.m_invI;this.m_invIB=c.m_invI;var k=Box2D.Common.Math.b2Math.MulMV(f.R,this.m_localXAxis1);this.m_axis.SetV(k);Box2D.Common.Math.b2Vec2.Free(k);this.m_a1=(d+g)*this.m_axis.y-(e+h)*this.m_axis.x;this.m_a2=i*this.m_axis.y-j*this.m_axis.x;this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+
this.m_invIB*this.m_a2*this.m_a2;if(this.m_motorMass>Number.MIN_VALUE)this.m_motorMass=1/this.m_motorMass;f=Box2D.Common.Math.b2Math.MulMV(f.R,this.m_localYAxis1);this.m_perp.SetV(f);Box2D.Common.Math.b2Vec2.Free(f);this.m_s1=(d+g)*this.m_perp.y-(e+h)*this.m_perp.x;this.m_s2=i*this.m_perp.y-j*this.m_perp.x;g=this.m_invMassA;h=this.m_invMassB;i=this.m_invIA;j=this.m_invIB;this.m_K.col1.x=g+h+i*this.m_s1*this.m_s1+j*this.m_s2*this.m_s2;this.m_K.col1.y=i*this.m_s1+j*this.m_s2;this.m_K.col1.z=i*this.m_s1*
this.m_a1+j*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=i+j;this.m_K.col2.z=i*this.m_a1+j*this.m_a2;this.m_K.col3.x=this.m_K.col1.z;this.m_K.col3.y=this.m_K.col2.z;this.m_K.col3.z=g+h+i*this.m_a1*this.m_a1+j*this.m_a2*this.m_a2;if(this.m_enableLimit)if(d=this.m_axis.x*d+this.m_axis.y*e,Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop)this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits;else if(d<=this.m_lowerTranslation){if(this.m_limitState!=
Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit)this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit,this.m_impulse.z=0}else if(d>=this.m_upperTranslation){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit,this.m_impulse.z=0}else this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse.z=0;else this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;if(this.m_enableMotor==!1)this.m_motorImpulse=
0;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x,d=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y,e=this.m_impulse.x*this.m_s1+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a1,g=this.m_impulse.x*this.m_s2+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a2,b.m_linearVelocity.x-=this.m_invMassA*
a,b.m_linearVelocity.y-=this.m_invMassA*d,b.m_angularVelocity-=this.m_invIA*e,c.m_linearVelocity.x+=this.m_invMassB*a,c.m_linearVelocity.y+=this.m_invMassB*d,c.m_angularVelocity+=this.m_invIB*g):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SolveVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d=b.m_linearVelocity,e=b.m_angularVelocity,f=c.m_linearVelocity,g=c.m_angularVelocity,h=0,i=0,j=0,k=0;if(this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits)k=this.m_motorMass*(this.m_motorSpeed-(this.m_axis.x*(f.x-d.x)+this.m_axis.y*(f.y-d.y)+this.m_a2*g-this.m_a1*e)),h=this.m_motorImpulse,a=a.dt*this.m_maxMotorForce,this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+
k,-a,a),k=this.m_motorImpulse-h,h=k*this.m_axis.x,i=k*this.m_axis.y,j=k*this.m_a1,k*=this.m_a2,d.x-=this.m_invMassA*h,d.y-=this.m_invMassA*i,e-=this.m_invIA*j,f.x+=this.m_invMassB*h,f.y+=this.m_invMassB*i,g+=this.m_invIB*k;j=this.m_perp.x*(f.x-d.x)+this.m_perp.y*(f.y-d.y)+this.m_s2*g-this.m_s1*e;i=g-e;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){k=this.m_axis.x*(f.x-d.x)+this.m_axis.y*(f.y-d.y)+this.m_a2*g-this.m_a1*e;h=this.m_impulse.Copy();a=Box2D.Common.Math.b2Vec3.Get(0,
0,0);this.m_K.Solve33(a,-j,-i,-k);this.m_impulse.Add(a);if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit)this.m_impulse.z=Math.max(this.m_impulse.z,0);else if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)this.m_impulse.z=Math.min(this.m_impulse.z,0);j=-j-(this.m_impulse.z-h.z)*this.m_K.col3.x;i=-i-(this.m_impulse.z-h.z)*this.m_K.col3.y;k=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K.Solve22(k,j,i);k.x+=h.x;k.y+=h.y;this.m_impulse.x=k.x;this.m_impulse.y=k.y;Box2D.Common.Math.b2Vec2.Free(k);
a.x=this.m_impulse.x-h.x;a.y=this.m_impulse.y-h.y;a.z=this.m_impulse.z-h.z;h=a.x*this.m_perp.x+a.z*this.m_axis.x;i=a.x*this.m_perp.y+a.z*this.m_axis.y;j=a.x*this.m_s1+a.y+a.z*this.m_a1;k=a.x*this.m_s2+a.y+a.z*this.m_a2;Box2D.Common.Math.b2Vec3.Free(a)}else a=Box2D.Common.Math.b2Vec2.Get(0,0),this.m_K.Solve22(a,-j,-i),this.m_impulse.x+=a.x,this.m_impulse.y+=a.y,h=a.x*this.m_perp.x,i=a.x*this.m_perp.y,j=a.x*this.m_s1+a.y,k=a.x*this.m_s2+a.y,Box2D.Common.Math.b2Vec2.Free(a);d.x-=this.m_invMassA*h;d.y-=
this.m_invMassA*i;e-=this.m_invIA*j;f.x+=this.m_invMassB*h;f.y+=this.m_invMassB*i;g+=this.m_invIB*k;b.m_linearVelocity.SetV(d);b.m_angularVelocity=e;c.m_linearVelocity.SetV(f);c.m_angularVelocity=g};
Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,b=this.m_bodyB,c=a.m_sweep.c,d=a.m_sweep.a,e=b.m_sweep.c,f=b.m_sweep.a,g=0,h=0,i=0,j=g=0,k=0,l=0,h=!1,n=0,m=Box2D.Common.Math.b2Mat22.FromAngle(d),l=this.m_localAnchor1.x-this.m_localCenterA.x,o=this.m_localAnchor1.y-this.m_localCenterA.y,g=m.col1.x*l+m.col2.x*o,o=m.col1.y*l+m.col2.y*o;Box2D.Common.Math.b2Mat22.Free(m);var l=g,j=Box2D.Common.Math.b2Mat22.FromAngle(f),p=this.m_localAnchor2.x-this.m_localCenterB.x,
i=this.m_localAnchor2.y-this.m_localCenterB.y,g=j.col1.x*p+j.col2.x*i,i=j.col1.y*p+j.col2.y*i;Box2D.Common.Math.b2Mat22.Free(j);p=g;g=e.x+p-c.x-l;j=e.y+i-c.y-o;if(this.m_enableLimit){Box2D.Common.Math.b2Vec2.Free(this.m_axis);this.m_axis=Box2D.Common.Math.b2Math.MulMV(m,this.m_localXAxis1);this.m_a1=(g+l)*this.m_axis.y-(j+o)*this.m_axis.x;this.m_a2=p*this.m_axis.y-i*this.m_axis.x;var q=this.m_axis.x*g+this.m_axis.y*j;Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop?
(n=Box2D.Common.Math.b2Math.Clamp(q,-Box2D.Common.b2Settings.b2_maxLinearCorrection,Box2D.Common.b2Settings.b2_maxLinearCorrection),k=Math.abs(q),h=!0):q<=this.m_lowerTranslation?(n=Box2D.Common.Math.b2Math.Clamp(q-this.m_lowerTranslation+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),k=this.m_lowerTranslation-q,h=!0):q>=this.m_upperTranslation&&(n=Box2D.Common.Math.b2Math.Clamp(q-this.m_upperTranslation+Box2D.Common.b2Settings.b2_linearSlop,0,Box2D.Common.b2Settings.b2_maxLinearCorrection),
k=q-this.m_upperTranslation,h=!0)}Box2D.Common.Math.b2Vec2.Free(this.m_perp);this.m_perp=Box2D.Common.Math.b2Math.MulMV(m,this.m_localYAxis1);this.m_s1=(g+l)*this.m_perp.y-(j+o)*this.m_perp.x;this.m_s2=p*this.m_perp.y-i*this.m_perp.x;m=Box2D.Common.Math.b2Vec3.Get(0,0,0);o=this.m_perp.x*g+this.m_perp.y*j;p=f-d-this.m_refAngle;k=Math.max(k,Math.abs(o));l=Math.abs(p);h?(h=this.m_invMassA,i=this.m_invMassB,g=this.m_invIA,j=this.m_invIB,this.m_K.col1.x=h+i+g*this.m_s1*this.m_s1+j*this.m_s2*this.m_s2,
this.m_K.col1.y=g*this.m_s1+j*this.m_s2,this.m_K.col1.z=g*this.m_s1*this.m_a1+j*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=g+j,this.m_K.col2.z=g*this.m_a1+j*this.m_a2,this.m_K.col3.x=this.m_K.col1.z,this.m_K.col3.y=this.m_K.col2.z,this.m_K.col3.z=h+i+g*this.m_a1*this.m_a1+j*this.m_a2*this.m_a2,this.m_K.Solve33(m,-o,-p,-n)):(h=this.m_invMassA,i=this.m_invMassB,g=this.m_invIA,j=this.m_invIB,n=g*this.m_s1+j*this.m_s2,q=g+j,this.m_K.col1.Set(h+i+g*this.m_s1*this.m_s1+j*this.m_s2*
this.m_s2,n,0),this.m_K.col2.Set(n,q,0),n=Box2D.Common.Math.b2Vec2.Get(0,0),this.m_K.Solve22(n,-o,-p),m.x=n.x,m.y=n.y,Box2D.Common.Math.b2Vec2.Free(n),m.z=0);n=m.x*this.m_perp.x+m.z*this.m_axis.x;h=m.x*this.m_perp.y+m.z*this.m_axis.y;o=m.x*this.m_s1+m.y+m.z*this.m_a1;p=m.x*this.m_s2+m.y+m.z*this.m_a2;Box2D.Common.Math.b2Vec3.Free(m);c.x-=this.m_invMassA*n;c.y-=this.m_invMassA*h;d-=this.m_invIA*o;e.x+=this.m_invMassB*n;e.y+=this.m_invMassB*h;f+=this.m_invIB*p;a.m_sweep.a=d;b.m_sweep.a=f;a.SynchronizeTransform();
b.SynchronizeTransform();return k<=Box2D.Common.b2Settings.b2_linearSlop&&l<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2PrismaticJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAxisA=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint;this.localAxisA.Set(1,0);this.referenceAngle=0;this.enableLimit=!1;this.upperTranslation=this.lowerTranslation=0;this.enableMotor=!1;this.motorSpeed=this.maxMotorForce=0};
goog.inherits(Box2D.Dynamics.Joints.b2PrismaticJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2PrismaticJointDef.prototype.Initialize=function(a,b,c,d){this.bodyA=a;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(c);this.localAnchorB=this.bodyB.GetLocalPoint(c);this.localAxisA=this.bodyA.GetLocalVector(d);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2PrismaticJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2PrismaticJoint(this)};Box2D.Dynamics.Joints.b2WeldJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass=new Box2D.Common.Math.b2Mat33;this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle};goog.inherits(Box2D.Dynamics.Joints.b2WeldJoint,Box2D.Dynamics.Joints.b2Joint);
Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetReactionForce=function(a){return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetReactionTorque=function(a){return a*this.m_impulse.z};
Box2D.Dynamics.Joints.b2WeldJoint.prototype.InitVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB;b=d.m_xf.R;var f=this.m_localAnchorA.x-d.m_sweep.localCenter.x,g=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=b.col1.x*f+b.col2.x*g,g=b.col1.y*f+b.col2.y*g,f=c;b=e.m_xf.R;var h=this.m_localAnchorB.x-e.m_sweep.localCenter.x,i=this.m_localAnchorB.y-e.m_sweep.localCenter.y,c=b.col1.x*h+b.col2.x*i,i=b.col1.y*h+b.col2.y*i,h=c;b=d.m_invMass;var c=e.m_invMass,j=d.m_invI,k=e.m_invI;this.m_mass.col1.x=
b+c+g*g*j+i*i*k;this.m_mass.col2.x=-g*f*j-i*h*k;this.m_mass.col3.x=-g*j-i*k;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=b+c+f*f*j+h*h*k;this.m_mass.col3.y=f*j+h*k;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=j+k;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_impulse.z*=a.dtRatio,d.m_linearVelocity.x-=b*this.m_impulse.x,d.m_linearVelocity.y-=b*this.m_impulse.y,d.m_angularVelocity-=j*(f*this.m_impulse.y-g*
this.m_impulse.x+this.m_impulse.z),e.m_linearVelocity.x+=c*this.m_impulse.x,e.m_linearVelocity.y+=c*this.m_impulse.y,e.m_angularVelocity+=k*(h*this.m_impulse.y-i*this.m_impulse.x+this.m_impulse.z)):this.m_impulse.SetZero()};
Box2D.Dynamics.Joints.b2WeldJoint.prototype.SolveVelocityConstraints=function(){var a,b=0,c=this.m_bodyA,d=this.m_bodyB,e=c.m_linearVelocity,f=c.m_angularVelocity,g=d.m_linearVelocity,h=d.m_angularVelocity,i=c.m_invMass,j=d.m_invMass,k=c.m_invI,l=d.m_invI;a=c.m_xf.R;var n=this.m_localAnchorA.x-c.m_sweep.localCenter.x,m=this.m_localAnchorA.y-c.m_sweep.localCenter.y,b=a.col1.x*n+a.col2.x*m,m=a.col1.y*n+a.col2.y*m,n=b;a=d.m_xf.R;var o=this.m_localAnchorB.x-d.m_sweep.localCenter.x,p=this.m_localAnchorB.y-
d.m_sweep.localCenter.y,b=a.col1.x*o+a.col2.x*p,p=a.col1.y*o+a.col2.y*p,o=b;a=g.x-h*p-e.x+f*m;var b=g.y+h*o-e.y-f*n,q=h-f,r=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass.Solve33(r,-a,-b,-q);this.m_impulse.Add(r);e.x-=i*r.x;e.y-=i*r.y;f-=k*(n*r.y-m*r.x+r.z);g.x+=j*r.x;g.y+=j*r.y;h+=l*(o*r.y-p*r.x+r.z);Box2D.Common.Math.b2Vec3.Free(r);c.m_angularVelocity=f;d.m_angularVelocity=h};
Box2D.Dynamics.Joints.b2WeldJoint.prototype.SolvePositionConstraints=function(){var a,b=0,c=this.m_bodyA,d=this.m_bodyB;a=c.m_xf.R;var e=this.m_localAnchorA.x-c.m_sweep.localCenter.x,f=this.m_localAnchorA.y-c.m_sweep.localCenter.y,b=a.col1.x*e+a.col2.x*f,f=a.col1.y*e+a.col2.y*f,e=b;a=d.m_xf.R;var g=this.m_localAnchorB.x-d.m_sweep.localCenter.x,h=this.m_localAnchorB.y-d.m_sweep.localCenter.y,b=a.col1.x*g+a.col2.x*h,h=a.col1.y*g+a.col2.y*h,g=b;a=c.m_invMass;var b=d.m_invMass,i=c.m_invI,j=d.m_invI,k=
d.m_sweep.c.x+g-c.m_sweep.c.x-e,l=d.m_sweep.c.y+h-c.m_sweep.c.y-f,n=d.m_sweep.a-c.m_sweep.a-this.m_referenceAngle,m=Math.sqrt(k*k+l*l),o=Math.abs(n);m>10*Box2D.Common.b2Settings.b2_linearSlop&&(i*=1,j*=1);this.m_mass.col1.x=a+b+f*f*i+h*h*j;this.m_mass.col2.x=-f*e*i-h*g*j;this.m_mass.col3.x=-f*i-h*j;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=a+b+e*e*i+g*g*j;this.m_mass.col3.y=e*i+g*j;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=i+j;var p=
Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass.Solve33(p,-k,-l,-n);c.m_sweep.c.x-=a*p.x;c.m_sweep.c.y-=a*p.y;c.m_sweep.a-=i*(e*p.y-f*p.x+p.z);d.m_sweep.c.x+=b*p.x;d.m_sweep.c.y+=b*p.y;d.m_sweep.a+=j*(g*p.y-h*p.x+p.z);Box2D.Common.Math.b2Vec3.Free(p);c.SynchronizeTransform();d.SynchronizeTransform();return m<=Box2D.Common.b2Settings.b2_linearSlop&&o<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2WeldJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_weldJoint;this.referenceAngle=0};goog.inherits(Box2D.Dynamics.Joints.b2WeldJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2WeldJointDef.prototype.Initialize=function(a,b,c){this.bodyA=a;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c));this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2WeldJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2WeldJoint(this)};Box2D.Collision.b2DistanceOutput=function(){UsageTracker.get("Box2D.Collision.b2DistanceOutput").trackCreate();this.pointA=Box2D.Common.Math.b2Vec2.Get(0,0);this.pointB=Box2D.Common.Math.b2Vec2.Get(0,0);this.distance=0};Box2D.Collision.b2SimplexVertex=function(){UsageTracker.get("Box2D.Collision.b2SimplexVertex").trackCreate();this.wA=Box2D.Common.Math.b2Vec2.Get(0,0);this.wB=Box2D.Common.Math.b2Vec2.Get(0,0);this.w=Box2D.Common.Math.b2Vec2.Get(0,0);this.indexB=this.indexA=this.a=0};Box2D.Collision.b2SimplexVertex.prototype.Set=function(a){this.wA.SetV(a.wA);this.wB.SetV(a.wB);this.w.SetV(a.w);this.a=a.a;this.indexA=a.indexA;this.indexB=a.indexB};Box2D.Collision.b2Simplex=function(){UsageTracker.get("Box2D.Collision.b2Simplex").trackCreate();this.m_v1=new Box2D.Collision.b2SimplexVertex;this.m_v2=new Box2D.Collision.b2SimplexVertex;this.m_v3=new Box2D.Collision.b2SimplexVertex;this.m_vertices=[this.m_v1,this.m_v2,this.m_v3]};Box2D.Collision.b2Simplex._freeCache=[];
Box2D.Collision.b2Simplex.Get=function(){if(Box2D.Collision.b2Simplex._freeCache.length>0){for(var a=Box2D.Collision.b2Simplex._freeCache.pop(),b=0;b<a.m_vertices.length;b++){var c=a.m_vertices[b];c.wA!=null&&c.wA.Set(0,0);c.wB!=null&&c.wB.Set(0,0);c.w!=null&&c.w.Set(0,0);c.indexA=0;c.indexB=0;c.a=0}return a}return new Box2D.Collision.b2Simplex};Box2D.Collision.b2Simplex.Free=function(a){a!=null&&Box2D.Collision.b2Simplex._freeCache.push(a)};
Box2D.Collision.b2Simplex.prototype.ReadCache=function(a,b,c,d,e){Box2D.Common.b2Settings.b2Assert(0<=a.count&&a.count<=3);var f,g;this.m_count=a.count;for(var h=this.m_vertices,i=0;i<this.m_count;i++){var j=h[i];j.indexA=a.indexA[i];j.indexB=a.indexB[i];f=b.GetVertex(j.indexA);g=d.GetVertex(j.indexB);Box2D.Common.Math.b2Vec2.Free(j.wA);Box2D.Common.Math.b2Vec2.Free(j.wB);Box2D.Common.Math.b2Vec2.Free(j.w);j.wA=Box2D.Common.Math.b2Math.MulX(c,f);j.wB=Box2D.Common.Math.b2Math.MulX(e,g);j.w=Box2D.Common.Math.b2Math.SubtractVV(j.wB,
j.wA);j.a=0}if(this.m_count>1&&(a=a.metric,f=this.GetMetric(),f<0.5*a||2*a<f||f<Number.MIN_VALUE))this.m_count=0;if(this.m_count==0)j=h[0],j.indexA=0,j.indexB=0,f=b.GetVertex(0),g=d.GetVertex(0),Box2D.Common.Math.b2Vec2.Free(j.wA),Box2D.Common.Math.b2Vec2.Free(j.wB),Box2D.Common.Math.b2Vec2.Free(j.w),j.wA=Box2D.Common.Math.b2Math.MulX(c,f),j.wB=Box2D.Common.Math.b2Math.MulX(e,g),j.w=Box2D.Common.Math.b2Math.SubtractVV(j.wB,j.wA),this.m_count=1};
Box2D.Collision.b2Simplex.prototype.WriteCache=function(a){a.metric=this.GetMetric();a.count=this.m_count;for(var b=this.m_vertices,c=0;c<this.m_count;c++)a.indexA[c]=b[c].indexA,a.indexB[c]=b[c].indexB};
Box2D.Collision.b2Simplex.prototype.GetSearchDirection=function(){if(this.m_count==1)return this.m_v1.w.GetNegative();else if(this.m_count==2){var a=Box2D.Common.Math.b2Math.SubtractVV(this.m_v2.w,this.m_v1.w),b=this.m_v1.w.GetNegative(),c=Box2D.Common.Math.b2Math.CrossVV(a,b);Box2D.Common.Math.b2Vec2.Free(b);b=null;b=c>0?Box2D.Common.Math.b2Math.CrossFV(1,a):Box2D.Common.Math.b2Math.CrossVF(a,1);Box2D.Common.Math.b2Vec2.Free(a);return b}else return Box2D.Common.b2Settings.b2Assert(!1),Box2D.Common.Math.b2Vec2.Get(0,
0)};Box2D.Collision.b2Simplex.prototype.GetClosestPoint=function(){return this.m_count==1?this.m_v1.w:this.m_count==2?Box2D.Common.Math.b2Vec2.Get(this.m_v1.a*this.m_v1.w.x+this.m_v2.a*this.m_v2.w.x,this.m_v1.a*this.m_v1.w.y+this.m_v2.a*this.m_v2.w.y):(Box2D.Common.b2Settings.b2Assert(!1),Box2D.Common.Math.b2Vec2.Get(0,0))};
Box2D.Collision.b2Simplex.prototype.GetWitnessPoints=function(a,b){this.m_count==1?(a.SetV(this.m_v1.wA),b.SetV(this.m_v1.wB)):this.m_count==2?(a.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x,a.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y,b.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x,b.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y):this.m_count==3?(b.x=a.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x+this.m_v3.a*this.m_v3.wA.x,b.y=a.y=this.m_v1.a*
this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y+this.m_v3.a*this.m_v3.wA.y):Box2D.Common.b2Settings.b2Assert(!1)};
Box2D.Collision.b2Simplex.prototype.GetMetric=function(){if(this.m_count==1)return 0;else if(this.m_count==2){var a=Box2D.Common.Math.b2Math.SubtractVV(this.m_v1.w,this.m_v2.w),b=a.Length();Box2D.Common.Math.b2Vec2.Free(a);return b}else if(this.m_count==3){var a=Box2D.Common.Math.b2Math.SubtractVV(this.m_v2.w,this.m_v1.w),c=Box2D.Common.Math.b2Math.SubtractVV(this.m_v3.w,this.m_v1.w),b=Box2D.Common.Math.b2Math.CrossVV(a,c);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(c);return b}else return Box2D.Common.b2Settings.b2Assert(!1),
0};Box2D.Collision.b2Simplex.prototype.Solve2=function(){var a=this.m_v1.w,b=this.m_v2.w,c=Box2D.Common.Math.b2Math.SubtractVV(b,a),a=-(a.x*c.x+a.y*c.y);a<=0?(Box2D.Common.Math.b2Vec2.Free(c),this.m_count=this.m_v1.a=1):(b=b.x*c.x+b.y*c.y,Box2D.Common.Math.b2Vec2.Free(c),b<=0?(this.m_count=this.m_v2.a=1,this.m_v1.Set(this.m_v2)):(c=1/(b+a),this.m_v1.a=b*c,this.m_v2.a=a*c,this.m_count=2))};
Box2D.Collision.b2Simplex.prototype.Solve3=function(){var a=this.m_v1.w,b=this.m_v2.w,c=this.m_v3.w,d=Box2D.Common.Math.b2Math.SubtractVV(b,a),e=Box2D.Common.Math.b2Math.Dot(a,d),f=Box2D.Common.Math.b2Math.Dot(b,d),e=-e,g=Box2D.Common.Math.b2Math.SubtractVV(c,a),h=Box2D.Common.Math.b2Math.Dot(a,g),i=Box2D.Common.Math.b2Math.Dot(c,g),j=Box2D.Common.Math.b2Math.CrossVV(d,g);Box2D.Common.Math.b2Vec2.Free(d);Box2D.Common.Math.b2Vec2.Free(g);var d=-h,h=Box2D.Common.Math.b2Math.SubtractVV(c,b),k=Box2D.Common.Math.b2Math.Dot(b,
h),g=Box2D.Common.Math.b2Math.Dot(c,h);Box2D.Common.Math.b2Vec2.Free(h);h=-k;k=j*Box2D.Common.Math.b2Math.CrossVV(b,c);c=j*Box2D.Common.Math.b2Math.CrossVV(c,a);a=j*Box2D.Common.Math.b2Math.CrossVV(a,b);e<=0&&d<=0?this.m_count=this.m_v1.a=1:f>0&&e>0&&a<=0?(i=1/(f+e),this.m_v1.a=f*i,this.m_v2.a=e*i,this.m_count=2):i>0&&d>0&&c<=0?(f=1/(i+d),this.m_v1.a=i*f,this.m_v3.a=d*f,this.m_count=2,this.m_v2.Set(this.m_v3)):f<=0&&h<=0?(this.m_count=this.m_v2.a=1,this.m_v1.Set(this.m_v2)):i<=0&&g<=0?(this.m_count=
this.m_v3.a=1,this.m_v1.Set(this.m_v3)):g>0&&h>0&&k<=0?(f=1/(g+h),this.m_v2.a=g*f,this.m_v3.a=h*f,this.m_count=2,this.m_v1.Set(this.m_v3)):(f=1/(k+c+a),this.m_v1.a=k*f,this.m_v2.a=c*f,this.m_v3.a=a*f,this.m_count=3)};Box2D.Collision.b2Distance={};
Box2D.Collision.b2Distance.Distance=function(a,b,c){var d=Box2D.Collision.b2Simplex.Get();d.ReadCache(b,c.proxyA,c.transformA,c.proxyB,c.transformB);(d.m_count<1||d.m_count>3)&&Box2D.Common.b2Settings.b2Assert(!1);for(var e=0;e<20;){for(var f=[],g=0;g<d.m_count;g++)f[g]={},f[g].indexA=d.m_vertices[g].indexA,f[g].indexB=d.m_vertices[g].indexB;d.m_count==2?d.Solve2():d.m_count==3&&d.Solve3();if(d.m_count==3)break;g=d.GetSearchDirection();if(g.LengthSquared()<Box2D.Common.b2Settings.MIN_VALUE_SQUARED){Box2D.Common.Math.b2Vec2.Free(g);break}Box2D.Common.Math.b2Vec2.Free(d.m_vertices[d.m_count].wA);
Box2D.Common.Math.b2Vec2.Free(d.m_vertices[d.m_count].wB);Box2D.Common.Math.b2Vec2.Free(d.m_vertices[d.m_count].w);var h=g.GetNegative(),i=Box2D.Common.Math.b2Math.MulTMV(c.transformA.R,h);Box2D.Common.Math.b2Vec2.Free(h);d.m_vertices[d.m_count].indexA=c.proxyA.GetSupport(i);Box2D.Common.Math.b2Vec2.Free(i);d.m_vertices[d.m_count].wA=Box2D.Common.Math.b2Math.MulX(c.transformA,c.proxyA.GetVertex(d.m_vertices[d.m_count].indexA));h=Box2D.Common.Math.b2Math.MulTMV(c.transformB.R,g);Box2D.Common.Math.b2Vec2.Free(g);
d.m_vertices[d.m_count].indexB=c.proxyB.GetSupport(h);Box2D.Common.Math.b2Vec2.Free(h);d.m_vertices[d.m_count].wB=Box2D.Common.Math.b2Math.MulX(c.transformB,c.proxyB.GetVertex(d.m_vertices[d.m_count].indexB));d.m_vertices[d.m_count].w=Box2D.Common.Math.b2Math.SubtractVV(d.m_vertices[d.m_count].wB,d.m_vertices[d.m_count].wA);e++;h=!1;for(g=0;g<f.length;g++)if(d.m_vertices[d.m_count].indexA==f[g].indexA&&d.m_vertices[d.m_count].indexB==f[g].indexB){h=!0;break}if(h)break;d.m_count++}d.GetWitnessPoints(a.pointA,
a.pointB);e=Box2D.Common.Math.b2Math.SubtractVV(a.pointA,a.pointB);a.distance=e.Length();Box2D.Common.Math.b2Vec2.Free(e);d.WriteCache(b);Box2D.Collision.b2Simplex.Free(d);if(c.useRadii)b=c.proxyA.GetRadius(),c=c.proxyB.GetRadius(),a.distance>b+c&&a.distance>Number.MIN_VALUE?(a.distance-=b+c,d=Box2D.Common.Math.b2Math.SubtractVV(a.pointB,a.pointA),d.Normalize(),a.pointA.x+=b*d.x,a.pointA.y+=b*d.y,a.pointB.x-=c*d.x,a.pointB.y-=c*d.y,Box2D.Common.Math.b2Vec2.Free(d)):(c=Box2D.Common.Math.b2Vec2.Get(0,
0),c.x=0.5*(a.pointA.x+a.pointB.x),c.y=0.5*(a.pointA.y+a.pointB.y),a.pointA.x=a.pointB.x=c.x,a.pointA.y=a.pointB.y=c.y,a.distance=0,Box2D.Common.Math.b2Vec2.Free(c))};Box2D.Collision.b2SimplexCache=function(){UsageTracker.get("Box2D.Collision.b2SimplexCache").trackCreate();this.indexA=[0,0,0];this.indexB=[0,0,0]};Box2D.Collision.b2DistanceInput=function(){UsageTracker.get("Box2D.Collision.b2DistanceInput").trackCreate();this.useRadii=!1;this.transformB=this.transformA=this.proxyB=this.proxyA=null};Box2D.Collision.Shapes={};Box2D.Collision.Shapes.b2Shape=function(){UsageTracker.get("Box2D.Collision.Shapes.b2Shape").trackCreate();this.m_radius=Box2D.Common.b2Settings.b2_linearSlop};Box2D.Collision.Shapes.b2Shape.prototype.Set=function(a){this.m_radius=a.m_radius};
Box2D.Collision.Shapes.b2Shape.TestOverlap=function(a,b,c,d){var e=new Box2D.Collision.b2DistanceInput;e.proxyA=new Box2D.Collision.b2DistanceProxy;e.proxyA.Set(a);e.proxyB=new Box2D.Collision.b2DistanceProxy;e.proxyB.Set(c);e.transformA=b;e.transformB=d;e.useRadii=!0;a=new Box2D.Collision.b2SimplexCache;a.count=0;b=new Box2D.Collision.b2DistanceOutput;Box2D.Collision.b2Distance.Distance(b,a,e);Box2D.Common.Math.b2Vec2.Free(b.pointA);Box2D.Common.Math.b2Vec2.Free(b.pointB);return b.distance<10*Number.MIN_VALUE};
Box2D.Collision.Shapes.b2Shape.prototype.GetRadius=function(){return this.m_radius};Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide=-1;Box2D.Collision.Shapes.b2Shape.e_missCollide=0;Box2D.Collision.Shapes.b2Shape.e_hitCollide=1;Box2D.Collision.Shapes.b2CircleShape=function(a){UsageTracker.get("Box2D.Collision.Shapes.b2CircleShape").trackCreate();Box2D.Collision.Shapes.b2Shape.call(this);this.m_radius=a;this.m_radiusSquared=a*a;this.m_p=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_vertices=[this.m_p]};goog.inherits(Box2D.Collision.Shapes.b2CircleShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2CircleShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2CircleShape.NAME};
Box2D.Collision.Shapes.b2CircleShape.prototype.Copy=function(){var a=new Box2D.Collision.Shapes.b2CircleShape(this.m_radius);a.Set(this);return a};Box2D.Collision.Shapes.b2CircleShape.prototype.Set=function(a){Box2D.Collision.Shapes.b2Shape.prototype.Set.call(this,a);a instanceof Box2D.Collision.Shapes.b2CircleShape&&this.m_p.SetV(a.m_p)};
Box2D.Collision.Shapes.b2CircleShape.prototype.TestPoint=function(a,b){var c=b.x-(a.position.x+(a.R.col1.x*this.m_p.x+a.R.col2.x*this.m_p.y)),d=b.y-(a.position.y+(a.R.col1.y*this.m_p.x+a.R.col2.y*this.m_p.y));return c*c+d*d<=this.m_radiusSquared};
Box2D.Collision.Shapes.b2CircleShape.prototype.RayCast=function(a,b,c){var d=c.R,e=b.p1.x-(c.position.x+(d.col1.x*this.m_p.x+d.col2.x*this.m_p.y)),c=b.p1.y-(c.position.y+(d.col1.y*this.m_p.x+d.col2.y*this.m_p.y)),d=b.p2.x-b.p1.x,f=b.p2.y-b.p1.y,g=e*d+c*f,h=d*d+f*f,i=g*g-h*(e*e+c*c-this.m_radiusSquared);if(i<0||h<Number.MIN_VALUE)return!1;g=-(g+Math.sqrt(i));return 0<=g&&g<=b.maxFraction*h?(g/=h,a.fraction=g,a.normal.x=e+g*d,a.normal.y=c+g*f,a.normal.Normalize(),!0):!1};
Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeAABB=function(a,b){var c=b.R,d=b.position.x+(c.col1.x*this.m_p.x+c.col2.x*this.m_p.y),c=b.position.y+(c.col1.y*this.m_p.x+c.col2.y*this.m_p.y);a.lowerBound.Set(d-this.m_radius,c-this.m_radius);a.upperBound.Set(d+this.m_radius,c+this.m_radius)};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeMass=function(a,b){var c=b*Math.PI*this.m_radiusSquared;a.SetV(c,this.m_p,c*(0.5*this.m_radiusSquared+(this.m_p.x*this.m_p.x+this.m_p.y*this.m_p.y)))};
Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeSubmergedArea=function(a,b,c,d){var c=Box2D.Common.Math.b2Math.MulX(c,this.m_p),e=-(Box2D.Common.Math.b2Math.Dot(a,c)-b);if(e<-this.m_radius+Number.MIN_VALUE)return Box2D.Common.Math.b2Vec2.Free(c),0;if(e>this.m_radius)return Box2D.Common.Math.b2Vec2.Free(c),d.SetV(c),Math.PI*this.m_radiusSquared;b=e*e;e=this.m_radiusSquared*(Math.asin(e/this.m_radius)+Math.PI/2)+e*Math.sqrt(this.m_radiusSquared-b);b=-2/3*Math.pow(this.m_radiusSquared-b,1.5)/e;
d.x=c.x+a.x*b;d.y=c.y+a.y*b;Box2D.Common.Math.b2Vec2.Free(c);return e};Box2D.Collision.Shapes.b2CircleShape.prototype.SetDistanceProxy=function(a){a.SetValues(1,this.m_radius,this.m_vertices)};Box2D.Collision.Shapes.b2CircleShape.prototype.GetLocalPosition=function(){return this.m_p};Box2D.Collision.Shapes.b2CircleShape.prototype.SetLocalPosition=function(a){this.m_p.SetV(a)};Box2D.Collision.Shapes.b2CircleShape.prototype.GetRadius=function(){return this.m_radius};
Box2D.Collision.Shapes.b2CircleShape.prototype.SetRadius=function(a){this.m_radius=a;this.m_radiusSquared=a*a};Box2D.Collision.Shapes.b2CircleShape.NAME="b2CircleShape";Box2D.Consts={};Box2D.Consts.MIN_VALUE_SQUARED=Number.MIN_VALUE*Number.MIN_VALUE;Box2D.Collision.b2AABB=function(){UsageTracker.get("Box2D.Collision.b2AABB").trackCreate();this.lowerBound=Box2D.Common.Math.b2Vec2.Get(0,0);this.upperBound=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2AABB._freeCache=[];Box2D.Collision.b2AABB.Get=function(){UsageTracker.get("Box2D.Collision.b2AABB").trackGet();if(Box2D.Collision.b2AABB._freeCache.length>0){var a=Box2D.Collision.b2AABB._freeCache.pop();a.SetZero();return a}return new Box2D.Collision.b2AABB};
Box2D.Collision.b2AABB.Free=function(a){a!=null&&(UsageTracker.get("Box2D.Collision.b2AABB").trackFree(),Box2D.Collision.b2AABB._freeCache.push(a))};Box2D.Collision.b2AABB.prototype.Set=function(a,b,c,d){this.lowerBound.Set(a,b);this.upperBound.Set(c,d)};Box2D.Collision.b2AABB.prototype.SetVV=function(a,b){this.lowerBound.SetV(a);this.upperBound.SetV(b)};Box2D.Collision.b2AABB.prototype.SetZero=function(){this.lowerBound.Set(0,0);this.upperBound.Set(0,0)};
Box2D.Collision.b2AABB.prototype.IsValid=function(){return this.upperBound.x-this.lowerBound.x<0?!1:this.upperBound.y-this.lowerBound.y<0?!1:this.lowerBound.IsValid()&&this.upperBound.IsValid()};Box2D.Collision.b2AABB.prototype.GetCenter=function(){return Box2D.Common.Math.b2Vec2.Get((this.lowerBound.x+this.upperBound.x)/2,(this.lowerBound.y+this.upperBound.y)/2)};
Box2D.Collision.b2AABB.prototype.SetCenter=function(a){var b=this.GetCenter();this.lowerBound.Subtract(b);this.upperBound.Subtract(b);this.lowerBound.Add(a);this.upperBound.Add(a);Box2D.Common.Math.b2Vec2.Free(b)};Box2D.Collision.b2AABB.prototype.GetExtents=function(){return Box2D.Common.Math.b2Vec2.Get((this.upperBound.x-this.lowerBound.x)/2,(this.upperBound.y-this.lowerBound.y)/2)};
Box2D.Collision.b2AABB.prototype.Contains=function(a){var b;return b=(b=(b=(b=this.lowerBound.x<=a.lowerBound.x)&&this.lowerBound.y<=a.lowerBound.y)&&a.upperBound.x<=this.upperBound.x)&&a.upperBound.y<=this.upperBound.y};
Box2D.Collision.b2AABB.prototype.RayCast=function(a,b){var c=-Number.MAX_VALUE,d=Number.MAX_VALUE,e=b.p2.x-b.p1.x;if(Math.abs(e)<Number.MIN_VALUE){if(b.p1.x<this.lowerBound.x||this.upperBound.x<b.p1.x)return!1}else{var f=1/e,e=(this.lowerBound.x-b.p1.x)*f;f*=this.upperBound.x-b.p1.x;var g=-1;e>f&&(g=e,e=f,f=g,g=1);if(e>c)a.normal.x=g,a.normal.y=0,c=e;d=Math.min(d,f);if(c>d)return!1}e=b.p2.y-b.p1.y;if(Math.abs(e)<Number.MIN_VALUE){if(b.p1.y<this.lowerBound.y||this.upperBound.y<b.p1.y)return!1}else{f=
1/e;e=(this.lowerBound.y-b.p1.y)*f;f*=this.upperBound.y-b.p1.y;g=-1;e>f&&(g=e,e=f,f=g,g=1);if(e>c)a.normal.y=g,a.normal.x=0,c=e;d=Math.min(d,f);if(c>d)return!1}a.fraction=c;return!0};Box2D.Collision.b2AABB.prototype.TestOverlap=function(a){return a.lowerBound.x-this.upperBound.x>0?!1:a.lowerBound.y-this.upperBound.y>0?!1:this.lowerBound.x-a.upperBound.x>0?!1:this.lowerBound.y-a.upperBound.y>0?!1:!0};Box2D.Collision.b2AABB.Combine=function(a,b){var c=Box2D.Collision.b2AABB.Get();c.Combine(a,b);return c};
Box2D.Collision.b2AABB.prototype.Combine=function(a,b){this.lowerBound.x=Math.min(a.lowerBound.x,b.lowerBound.x);this.lowerBound.y=Math.min(a.lowerBound.y,b.lowerBound.y);this.upperBound.x=Math.max(a.upperBound.x,b.upperBound.x);this.upperBound.y=Math.max(a.upperBound.y,b.upperBound.y)};Box2D.Collision.b2AABB.prototype.GetMinX=function(){return this.lowerBound.x};Box2D.Collision.b2AABB.prototype.GetMaxX=function(){return this.upperBound.x};Box2D.Collision.b2AABB.prototype.GetMinY=function(){return this.lowerBound.y};
Box2D.Collision.b2AABB.prototype.GetMaxY=function(){return this.upperBound.y};Box2D.Dynamics.b2FixtureListNode=function(a){UsageTracker.get("Box2D.Dynamics.b2FixtureListNode").trackCreate();this.fixture=a;this.previous=this.next=null};Box2D.Dynamics.b2FixtureListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.b2FixtureListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.b2FixtureListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.b2FixtureListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Collision.b2ContactID=function(){UsageTracker.get("Box2D.Collision.b2ContactID").trackCreate();this._incidentVertex=this._incidentEdge=this._referenceEdge=this._key=0};Box2D.Collision.b2ContactID.prototype.GetKey=function(){return this._key};Box2D.Collision.b2ContactID.prototype.SetKey=function(a){this._key=a;this._referenceEdge=this._key&255;this._incidentEdge=(this._key&65280)>>8&255;this._incidentVertex=(this._key&16711680)>>16&255;this._flip=(this._key&4278190080)>>24&255};
Box2D.Collision.b2ContactID.prototype.Set=function(a){this.SetKey(a._key)};Box2D.Collision.b2ContactID.prototype.SetReferenceEdge=function(a){this._referenceEdge=a;this._key=this._key&4294967040|this._referenceEdge&255};Box2D.Collision.b2ContactID.prototype.SetIncidentEdge=function(a){this._incidentEdge=a;this._key=this._key&4294902015|this._incidentEdge<<8&65280};
Box2D.Collision.b2ContactID.prototype.SetIncidentVertex=function(a){this._incidentVertex=a;this._key=this._key&4278255615|this._incidentVertex<<16&16711680};Box2D.Collision.b2ContactID.prototype.SetFlip=function(a){this._flip=a;this._key=this._key&16777215|this._flip<<24&4278190080};Box2D.Collision.b2ContactID.prototype.Copy=function(){var a=new Box2D.Collision.b2ContactID;a.Set(this);return a};Box2D.Collision.b2ManifoldPoint=function(){UsageTracker.get("Box2D.Collision.b2ManifoldPoint").trackCreate();this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_id=new Box2D.Collision.b2ContactID;this.m_tangentImpulse=this.m_normalImpulse=0};Box2D.Collision.b2ManifoldPoint.prototype.Reset=function(){this.m_localPoint.SetZero();this.m_tangentImpulse=this.m_normalImpulse=0;this.m_id.SetKey(0)};
Box2D.Collision.b2ManifoldPoint.prototype.Set=function(a){this.m_localPoint.SetV(a.m_localPoint);this.m_normalImpulse=a.m_normalImpulse;this.m_tangentImpulse=a.m_tangentImpulse;this.m_id.Set(a.m_id)};Box2D.Collision.b2DynamicTreeNode=function(a){UsageTracker.get("Box2D.Collision.b2DynamicTreeNode").trackCreate();this.aabb=Box2D.Collision.b2AABB.Get();this.parent=this.child2=this.child1=null;this.fixture=a};Box2D.Collision.b2DynamicTreeNode._freeCache=[];Box2D.Collision.b2DynamicTreeNode.Get=function(a){typeof a=="undefined"&&(a=null);if(Box2D.Collision.b2DynamicTreeNode._freeCache.length>0){var b=Box2D.Collision.b2DynamicTreeNode._freeCache.pop();b.fixture=a;b.aabb.SetZero();return b}return new Box2D.Collision.b2DynamicTreeNode(a)};
Box2D.Collision.b2DynamicTreeNode.prototype.Destroy=function(){this.fixture=this.parent=this.child2=this.child1=null;Box2D.Collision.b2DynamicTreeNode._freeCache.push(this)};Box2D.Collision.b2DynamicTreeNode.prototype.IsLeaf=function(){return this.child1===null};Box2D.Collision.b2DynamicTreeNode.prototype.SetChild1=function(a){this.child1=a};Box2D.Collision.b2DynamicTreeNode.prototype.GetChild1=function(){return this.child1};
Box2D.Collision.b2DynamicTreeNode.prototype.SetChild2=function(a){this.child2=a};Box2D.Collision.b2DynamicTreeNode.prototype.GetChild2=function(){return this.child2};Box2D.Collision.b2DynamicTreeNode.prototype.SetParent=function(a){this.parent=a};Box2D.Collision.b2DynamicTreeNode.prototype.GetParent=function(){return this.parent};Box2D.Collision.b2DynamicTreeNode.prototype.GetAABB=function(){return this.aabb};Box2D.Collision.b2DynamicTreeNode.prototype.GetFixture=function(){return this.fixture};Box2D.Collision.b2RayCastInput=function(a,b,c){UsageTracker.get("Box2D.Collision.b2RayCastInput").trackCreate();this.p1=Box2D.Common.Math.b2Vec2.Get(a.x,a.y);this.p2=Box2D.Common.Math.b2Vec2.Get(b.x,b.y);this.maxFraction=c};Box2D.Collision.b2DynamicTree=function(){UsageTracker.get("Box2D.Collision.b2DynamicTree").trackCreate();this.m_root=null;this.m_path=0};Box2D.Collision.b2DynamicTree.prototype.CreateProxy=function(a,b){var c=Box2D.Collision.b2DynamicTreeNode.Get(b),d=Box2D.Common.b2Settings.b2_aabbExtension,e=Box2D.Common.b2Settings.b2_aabbExtension;c.GetAABB().Set(a.GetMinX()-d,a.GetMinY()-e,a.GetMaxX()+d,a.GetMaxY()+e);this.InsertLeaf(c);return c};
Box2D.Collision.b2DynamicTree.prototype.DestroyProxy=function(a){this.RemoveLeaf(a);a.Destroy()};
Box2D.Collision.b2DynamicTree.prototype.MoveProxy=function(a,b,c){Box2D.Common.b2Settings.b2Assert(a.IsLeaf());if(a.GetAABB().Contains(b))return!1;this.RemoveLeaf(a);var d=Box2D.Common.b2Settings.b2_aabbExtension+Box2D.Common.b2Settings.b2_aabbMultiplier*Math.abs(c.x),c=Box2D.Common.b2Settings.b2_aabbExtension+Box2D.Common.b2Settings.b2_aabbMultiplier*Math.abs(c.y);a.GetAABB().Set(b.GetMinX()-d,b.GetMinY()-c,b.GetMaxX()+d,b.GetMaxY()+c);this.InsertLeaf(a);return!0};
Box2D.Collision.b2DynamicTree.prototype.Rebalance=function(a){if(this.m_root!==null)for(var b=0;b<a;b++){for(var c=this.m_root,d=0;!c.IsLeaf();)c=this.m_path>>d&1?c.GetChild2():c.GetChild1(),d=d+1&31;this.m_path++;this.RemoveLeaf(c);this.InsertLeaf(c)}};Box2D.Collision.b2DynamicTree.prototype.GetFatAABB=function(a){return a.GetAABB()};
Box2D.Collision.b2DynamicTree.prototype.Query=function(a,b,c){if(this.m_root!==null){var d=[];for(d.push(this.m_root);d.length>0;){var e=d.pop();if(e.GetAABB().TestOverlap(b))if(e.IsLeaf()){if(!a.call(c,e.fixture))break}else d.push(e.GetChild1()),d.push(e.GetChild2())}}};
Box2D.Collision.b2DynamicTree.prototype.RayCast=function(a,b){if(this.m_root!==null){var c=Box2D.Common.Math.b2Math.SubtractVV(b.p1,b.p2);c.Normalize();var d=Box2D.Common.Math.b2Math.CrossFV(1,c);Box2D.Common.Math.b2Vec2.Free(c);var c=Box2D.Common.Math.b2Math.AbsV(d),e=b.maxFraction,f=b.p1.x+e*(b.p2.x-b.p1.x),e=b.p1.y+e*(b.p2.y-b.p1.y),g=Box2D.Collision.b2AABB.Get();g.Set(Math.min(b.p1.x,f),Math.min(b.p1.y,e),Math.max(b.p1.x,f),Math.max(b.p1.y,e));var h=[];for(h.push(this.m_root);h.length>0;)if(f=
h.pop(),f.GetAABB().TestOverlap(g)){var e=f.GetAABB().GetCenter(),i=f.GetAABB().GetExtents(),j=Math.abs(d.x*(b.p1.x-e.x)+d.y*(b.p1.y-e.y))-c.x*i.x-c.y*i.y;Box2D.Common.Math.b2Vec2.Free(e);Box2D.Common.Math.b2Vec2.Free(i);if(!(j>0))if(f.IsLeaf()){new Box2D.Collision.b2RayCastInput(b.p1,b.p2,b.maxFraction);e=a(b,f.GetFixture());if(e==0)break;e>0&&(f=b.p1.x+e*(b.p2.x-b.p1.x),e=b.p1.y+e*(b.p2.y-b.p1.y),g.Set(Math.min(b.p1.x,f),Math.min(b.p1.y,e),Math.max(b.p1.x,f),Math.max(b.p1.y,e)))}else h.push(f.GetChild1()),
h.push(f.GetChild2())}Box2D.Common.Math.b2Vec2.Free(d);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Collision.b2AABB.Free(g)}};
Box2D.Collision.b2DynamicTree.prototype.InsertLeaf=function(a){if(this.m_root===null)this.m_root=a,this.m_root.SetParent(null);else{var b=this.GetBestSibling(a),c=b.GetParent(),d=Box2D.Collision.b2DynamicTreeNode.Get();d.SetParent(c);d.GetAABB().Combine(a.GetAABB(),b.GetAABB());if(c){b.GetParent().GetChild1()==b?c.SetChild1(d):c.SetChild2(d);d.SetChild1(b);d.SetChild2(a);b.SetParent(d);for(a.SetParent(d);c;){if(c.GetAABB().Contains(d.GetAABB()))break;c.GetAABB().Combine(c.GetChild1().GetAABB(),c.GetChild2().GetAABB());
d=c;c=c.GetParent()}}else d.SetChild1(b),d.SetChild2(a),b.SetParent(d),a.SetParent(d),this.m_root=d}};
Box2D.Collision.b2DynamicTree.prototype.GetBestSibling=function(a){for(var a=a.GetAABB().GetCenter(),b=this.m_root;!b.IsLeaf();)var c=b.GetChild1(),b=b.GetChild2(),d=Math.abs((c.GetAABB().GetMinX()+c.GetAABB().GetMaxX())/2-a.x)+Math.abs((c.GetAABB().GetMinY()+c.GetAABB().GetMaxY())/2-a.y),e=Math.abs((b.GetAABB().GetMinX()+b.GetAABB().GetMaxX())/2-a.x)+Math.abs((b.GetAABB().GetMinY()+b.GetAABB().GetMaxY())/2-a.y),b=d<e?c:b;Box2D.Common.Math.b2Vec2.Free(a);return b};
Box2D.Collision.b2DynamicTree.prototype.RemoveLeaf=function(a){if(a==this.m_root)this.m_root=null;else{var b=a.GetParent(),c=b.GetParent(),a=b.GetChild1()==a?b.GetChild2():b.GetChild1();if(c){c.GetChild1()==b?c.SetChild1(a):c.SetChild2(a);for(a.SetParent(c);c;){a=c.GetAABB();c.GetAABB().Combine(c.GetChild1().GetAABB(),c.GetChild2().GetAABB());if(a.Contains(c.GetAABB()))break;c=c.GetParent()}}else this.m_root=a,a.SetParent(null);b.Destroy()}};Box2D.Collision.ClipVertex=function(){UsageTracker.get("Box2D.Collision.ClipVertex").trackCreate();this.v=Box2D.Common.Math.b2Vec2.Get(0,0);this.id=new Box2D.Collision.b2ContactID};Box2D.Collision.ClipVertex.prototype.Set=function(a){this.v.SetV(a.v);this.id.Set(a.id)};Box2D.Collision.b2Manifold=function(){UsageTracker.get("Box2D.Collision.b2Manifold").trackCreate();this.m_type=this.m_pointCount=0;this.m_points=[];for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a]=new Box2D.Collision.b2ManifoldPoint;this.m_localPlaneNormal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0)};
Box2D.Collision.b2Manifold.prototype.Reset=function(){for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a].Reset();this.m_localPlaneNormal.SetZero();this.m_localPoint.SetZero();this.m_pointCount=this.m_type=0};
Box2D.Collision.b2Manifold.prototype.Set=function(a){this.m_pointCount=a.m_pointCount;for(var b=0;b<Box2D.Common.b2Settings.b2_maxManifoldPoints;b++)this.m_points[b].Set(a.m_points[b]);this.m_localPlaneNormal.SetV(a.m_localPlaneNormal);this.m_localPoint.SetV(a.m_localPoint);this.m_type=a.m_type};Box2D.Collision.b2Manifold.prototype.Copy=function(){var a=new Box2D.Collision.b2Manifold;a.Set(this);return a};Box2D.Collision.b2Manifold.prototype.SetPointCount=function(a){this.m_pointCount=a};
Box2D.Collision.b2Manifold.prototype.SetType=function(a){this.m_type=a};Box2D.Collision.b2Manifold.e_circles=1;Box2D.Collision.b2Manifold.e_faceA=2;Box2D.Collision.b2Manifold.e_faceB=4;Box2D.Collision.b2Collision={};Box2D.Collision.b2Collision.ClipSegmentToLine=function(a,b,c,d){var e=0,f=b[0].v,g=b[1].v,h=c.x*f.x+c.y*f.y-d,c=c.x*g.x+c.y*g.y-d;h<=0&&a[e++].Set(b[0]);c<=0&&a[e++].Set(b[1]);if(h*c<0)c=h/(h-c),d=a[e].v,d.x=f.x+c*(g.x-f.x),d.y=f.y+c*(g.y-f.y),a[e].id=h>0?b[0].id:b[1].id,e++;return e};
Box2D.Collision.b2Collision.EdgeSeparation=function(a,b,c,d,e){for(var f=b.R.col1.x*a.GetNormal(c).x+b.R.col2.x*a.GetNormal(c).y,g=b.R.col1.y*a.GetNormal(c).x+b.R.col2.y*a.GetNormal(c).y,h=e.R.col1.x*f+e.R.col1.y*g,i=e.R.col2.x*f+e.R.col2.y*g,j=0,k=Number.MAX_VALUE,l=0;l<d.m_vertexCount;l++){var n=d.GetVertex(l).x*h+d.GetVertex(l).y*i;n<k&&(k=n,j=l)}h=b.position.x+(b.R.col1.x*a.GetVertex(c).x+b.R.col2.x*a.GetVertex(c).y);a=b.position.y+(b.R.col1.y*a.GetVertex(c).x+b.R.col2.y*a.GetVertex(c).y);b=e.position.x+
(e.R.col1.x*d.GetVertex(j).x+e.R.col2.x*d.GetVertex(j).y);d=e.position.y+(e.R.col1.y*d.GetVertex(j).x+e.R.col2.y*d.GetVertex(j).y);return(b-h)*f+(d-a)*g};
Box2D.Collision.b2Collision.FindMaxSeparation=function(a,b,c,d){var e=d.position.x+(d.R.col1.x*c.GetCentroid().x+d.R.col2.x*c.GetCentroid().y),f=d.position.y+(d.R.col1.y*c.GetCentroid().x+d.R.col2.y*c.GetCentroid().y);e-=b.position.x+(b.R.col1.x*a.GetCentroid().x+b.R.col2.x*a.GetCentroid().y);f-=b.position.y+(b.R.col1.y*a.GetCentroid().x+b.R.col2.y*a.GetCentroid().y);for(var g=e*b.R.col1.x+f*b.R.col1.y,f=e*b.R.col2.x+f*b.R.col2.y,e=0,h=-Number.MAX_VALUE,i=0;i<a.m_vertexCount;++i){var j=a.GetNormal(i).x*
g+a.GetNormal(i).y*f;j>h&&(h=j,e=i)}g=Box2D.Collision.b2Collision.EdgeSeparation(a,b,e,c,d);f=e-1;f<0&&(f=a.m_vertexCount-1);h=Box2D.Collision.b2Collision.EdgeSeparation(a,b,f,c,d);i=e+1;i>=a.m_vertexCount&&(i=0);var j=Box2D.Collision.b2Collision.EdgeSeparation(a,b,i,c,d),k=0,l=0;if(h>g&&h>j){k=f;for(l=h;;)if(e=k-1,e<0&&(e=a.m_vertexCount-1),g=Box2D.Collision.b2Collision.EdgeSeparation(a,b,e,c,d),g>l)k=e,l=g;else break}else if(j>g){k=i;for(l=j;;)if(e=k+1,e>=a.m_vertexCount&&(e=0),g=Box2D.Collision.b2Collision.EdgeSeparation(a,
b,e,c,d),g>l)k=e,l=g;else break}else k=e,l=g;return{bestEdge:k,separation:l}};
Box2D.Collision.b2Collision.FindIncidentEdge=function(a,b,c,d,e,f){for(var g=c.R.col1.x*b.GetNormal(d).x+c.R.col2.x*b.GetNormal(d).y,b=c.R.col1.y*b.GetNormal(d).x+c.R.col2.y*b.GetNormal(d).y,c=f.R.col1.x*g+f.R.col1.y*b,b=f.R.col2.x*g+f.R.col2.y*b,g=c,c=0,h=Number.MAX_VALUE,i=0;i<e.m_vertexCount;i++){var j=g*e.GetNormal(i).x+b*e.GetNormal(i).y;j<h&&(h=j,c=i)}g=c+1;g>=e.m_vertexCount&&(g=0);a[0].v.x=f.position.x+(f.R.col1.x*e.GetVertex(c).x+f.R.col2.x*e.GetVertex(c).y);a[0].v.y=f.position.y+(f.R.col1.y*
e.GetVertex(c).x+f.R.col2.y*e.GetVertex(c).y);a[0].id.SetReferenceEdge(d);a[0].id.SetIncidentEdge(c);a[0].id.SetIncidentVertex(0);a[1].v.x=f.position.x+(f.R.col1.x*e.GetVertex(g).x+f.R.col2.x*e.GetVertex(g).y);a[1].v.y=f.position.y+(f.R.col1.y*e.GetVertex(g).x+f.R.col2.y*e.GetVertex(g).y);a[1].id.SetReferenceEdge(d);a[1].id.SetIncidentEdge(g);a[1].id.SetIncidentVertex(1)};Box2D.Collision.b2Collision.MakeClipPointVector=function(){return[new Box2D.Collision.ClipVertex,new Box2D.Collision.ClipVertex]};
Box2D.Collision.b2Collision.CollidePolygons=function(a,b,c,d,e){a.SetPointCount(0);var f=b.GetRadius()+d.GetRadius(),g=Box2D.Collision.b2Collision.FindMaxSeparation(b,c,d,e);if(!(g.separation>f)){var h=Box2D.Collision.b2Collision.FindMaxSeparation(d,e,b,c);if(!(h.separation>f)){var i=b,j=d,k=c,l=e,n=0,m=g.bestEdge;a.SetType(Box2D.Collision.b2Manifold.e_faceA);if(h.separation>0.98*g.separation+0.001)i=d,j=b,k=e,l=c,m=h.bestEdge,a.SetType(Box2D.Collision.b2Manifold.e_faceB),n=1;b=Box2D.Collision.b2Collision.s_incidentEdge;
Box2D.Collision.b2Collision.FindIncidentEdge(b,i,k,m,j,l);j=i.GetVertex(m);i=m+1<i.m_vertexCount?i.GetVertex(m+1):i.GetVertex(0);Box2D.Collision.b2Collision.s_localTangent.Set(i.x-j.x,i.y-j.y);Box2D.Collision.b2Collision.s_localTangent.Normalize();Box2D.Collision.b2Collision.s_localNormal.x=Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_localNormal.y=-Box2D.Collision.b2Collision.s_localTangent.x;Box2D.Collision.b2Collision.s_planePoint.Set(0.5*(j.x+i.x),0.5*(j.y+i.y));
Box2D.Collision.b2Collision.s_tangent.x=k.R.col1.x*Box2D.Collision.b2Collision.s_localTangent.x+k.R.col2.x*Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_tangent.y=k.R.col1.y*Box2D.Collision.b2Collision.s_localTangent.x+k.R.col2.y*Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_tangent2.x=-Box2D.Collision.b2Collision.s_tangent.x;Box2D.Collision.b2Collision.s_tangent2.y=-Box2D.Collision.b2Collision.s_tangent.y;Box2D.Collision.b2Collision.s_normal.x=
Box2D.Collision.b2Collision.s_tangent.y;Box2D.Collision.b2Collision.s_normal.y=-Box2D.Collision.b2Collision.s_tangent.x;Box2D.Collision.b2Collision.s_v11.x=k.position.x+(k.R.col1.x*j.x+k.R.col2.x*j.y);Box2D.Collision.b2Collision.s_v11.y=k.position.y+(k.R.col1.y*j.x+k.R.col2.y*j.y);Box2D.Collision.b2Collision.s_v12.x=k.position.x+(k.R.col1.x*i.x+k.R.col2.x*i.y);Box2D.Collision.b2Collision.s_v12.y=k.position.y+(k.R.col1.y*i.x+k.R.col2.y*i.y);if(!(Box2D.Collision.b2Collision.ClipSegmentToLine(Box2D.Collision.b2Collision.s_clipPoints1,
b,Box2D.Collision.b2Collision.s_tangent2,-Box2D.Collision.b2Collision.s_tangent.x*Box2D.Collision.b2Collision.s_v11.x-Box2D.Collision.b2Collision.s_tangent.y*Box2D.Collision.b2Collision.s_v11.y+f)<2)&&!(Box2D.Collision.b2Collision.ClipSegmentToLine(Box2D.Collision.b2Collision.s_clipPoints2,Box2D.Collision.b2Collision.s_clipPoints1,Box2D.Collision.b2Collision.s_tangent,Box2D.Collision.b2Collision.s_tangent.x*Box2D.Collision.b2Collision.s_v12.x+Box2D.Collision.b2Collision.s_tangent.y*Box2D.Collision.b2Collision.s_v12.y+
f)<2)){a.m_localPlaneNormal.SetV(Box2D.Collision.b2Collision.s_localNormal);a.m_localPoint.SetV(Box2D.Collision.b2Collision.s_planePoint);k=Box2D.Collision.b2Collision.s_normal.x*Box2D.Collision.b2Collision.s_v11.x+Box2D.Collision.b2Collision.s_normal.y*Box2D.Collision.b2Collision.s_v11.y;for(m=i=0;m<Box2D.Common.b2Settings.b2_maxManifoldPoints;++m)if(Box2D.Collision.b2Collision.s_normal.x*Box2D.Collision.b2Collision.s_clipPoints2[m].v.x+Box2D.Collision.b2Collision.s_normal.y*Box2D.Collision.b2Collision.s_clipPoints2[m].v.y-
k<=f)j=Box2D.Collision.b2Collision.s_clipPoints2[m].v.x-l.position.x,b=Box2D.Collision.b2Collision.s_clipPoints2[m].v.y-l.position.y,a.m_points[i].m_localPoint.x=j*l.R.col1.x+b*l.R.col1.y,a.m_points[i].m_localPoint.y=j*l.R.col2.x+b*l.R.col2.y,a.m_points[i].m_id.Set(Box2D.Collision.b2Collision.s_clipPoints2[m].id),a.m_points[i].m_id.SetFlip(n),i++;a.SetPointCount(i)}}}};
Box2D.Collision.b2Collision.CollideCircles=function(a,b,c,d,e){a.SetPointCount(0);var f=c.position.x+(c.R.col1.x*b.GetLocalPosition().x+c.R.col2.x*b.GetLocalPosition().y),c=c.position.y+(c.R.col1.y*b.GetLocalPosition().x+c.R.col2.y*b.GetLocalPosition().y),g=e.position.x+(e.R.col1.x*d.GetLocalPosition().x+e.R.col2.x*d.GetLocalPosition().y),e=e.position.y+(e.R.col1.y*d.GetLocalPosition().x+e.R.col2.y*d.GetLocalPosition().y),f=g-f,c=e-c,f=f*f+c*c,c=b.GetRadius()+d.GetRadius();f>c*c||(a.SetType(Box2D.Collision.b2Manifold.e_circles),
a.m_localPoint.SetV(b.GetLocalPosition()),a.m_localPlaneNormal.SetZero(),a.SetPointCount(1),a.m_points[0].m_localPoint.SetV(d.GetLocalPosition()),a.m_points[0].m_id.SetKey(0))};
Box2D.Collision.b2Collision.CollidePolygonAndCircle=function(a,b,c,d,e){a.SetPointCount(0);for(var f=e.position.x+(e.R.col1.x*d.GetLocalPosition().x+e.R.col2.x*d.GetLocalPosition().y)-c.position.x,g=e.position.y+(e.R.col1.y*d.GetLocalPosition().x+e.R.col2.y*d.GetLocalPosition().y)-c.position.y,e=f*c.R.col1.x+g*c.R.col1.y,c=f*c.R.col2.x+g*c.R.col2.y,f=0,g=-Number.MAX_VALUE,h=b.GetRadius()+d.GetRadius(),i=0;i<b.m_vertexCount;++i){var j=b.GetNormal(i).x*(e-b.GetVertex(i).x)+b.GetNormal(i).y*(c-b.GetVertex(i).y);
if(j>h)return;j>g&&(g=j,f=i)}j=f+1;j>=b.m_vertexCount&&(j=0);var i=b.GetVertex(f),k=b.GetVertex(j);if(g<Number.MIN_VALUE)a.SetPointCount(1),a.SetType(Box2D.Collision.b2Manifold.e_faceA),a.m_localPlaneNormal.SetV(b.GetNormal(f)),a.m_localPoint.x=0.5*(i.x+k.x),a.m_localPoint.y=0.5*(i.y+k.y);else if((e-i.x)*(k.x-i.x)+(c-i.y)*(k.y-i.y)<=0){if((e-i.x)*(e-i.x)+(c-i.y)*(c-i.y)>h*h)return;a.SetPointCount(1);a.SetType(Box2D.Collision.b2Manifold.e_faceA);a.m_localPlaneNormal.x=e-i.x;a.m_localPlaneNormal.y=
c-i.y;a.m_localPlaneNormal.Normalize();a.m_localPoint.SetV(i)}else if((e-k.x)*(i.x-k.x)+(c-k.y)*(i.y-k.y)<=0){if((e-k.x)*(e-k.x)+(c-k.y)*(c-k.y)>h*h)return;a.SetPointCount(1);a.SetType(Box2D.Collision.b2Manifold.e_faceA);a.m_localPlaneNormal.x=e-k.x;a.m_localPlaneNormal.y=c-k.y;a.m_localPlaneNormal.Normalize();a.m_localPoint.SetV(k)}else{j=0.5*(i.x+k.x);i=0.5*(i.y+k.y);g=(e-j)*b.GetNormal(f).x+(c-i)*b.GetNormal(f).y;if(g>h)return;a.SetPointCount(1);a.SetType(Box2D.Collision.b2Manifold.e_faceA);a.m_localPlaneNormal.x=
b.GetNormal(f).x;a.m_localPlaneNormal.y=b.GetNormal(f).y;a.m_localPlaneNormal.Normalize();a.m_localPoint.Set(j,i)}a.m_points[0].m_localPoint.SetV(d.GetLocalPosition());a.m_points[0].m_id.SetKey(0)};Box2D.Collision.b2Collision.s_incidentEdge=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints1=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints2=Box2D.Collision.b2Collision.MakeClipPointVector();
Box2D.Collision.b2Collision.s_localTangent=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_localNormal=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_planePoint=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_normal=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_tangent=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_tangent2=Box2D.Common.Math.b2Vec2.Get(0,0);
Box2D.Collision.b2Collision.s_v11=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_v12=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2SeparationFunction=function(){UsageTracker.get("Box2D.Collision.b2SeparationFunction").trackCreate();this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_proxyB=this.m_proxyA=null};
Box2D.Collision.b2SeparationFunction.prototype.Initialize=function(a,b,c,d,e){this.m_proxyA=b;this.m_proxyB=d;var f=a.count;Box2D.Common.b2Settings.b2Assert(0<f&&f<3);var g,h,i=h=g=0,j=0,d=b=0,k,l,i=0;f==1?(this.m_type=Box2D.Collision.b2SeparationFunction.e_points,f=this.m_proxyA.GetVertex(a.indexA[0]),a=this.m_proxyB.GetVertex(a.indexB[0]),l=f,k=c.R,g=c.position.x+(k.col1.x*l.x+k.col2.x*l.y),h=c.position.y+(k.col1.y*l.x+k.col2.y*l.y),l=a,k=e.R,i=e.position.x+(k.col1.x*l.x+k.col2.x*l.y),j=e.position.y+
(k.col1.y*l.x+k.col2.y*l.y),this.m_axis.x=i-g,this.m_axis.y=j-h,this.m_axis.Normalize()):a.indexB[0]==a.indexB[1]?(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceA,b=this.m_proxyA.GetVertex(a.indexA[0]),d=this.m_proxyA.GetVertex(a.indexA[1]),a=this.m_proxyB.GetVertex(a.indexB[0]),this.m_localPoint.x=0.5*(b.x+d.x),this.m_localPoint.y=0.5*(b.y+d.y),j=Box2D.Common.Math.b2Math.SubtractVV(d,b),Box2D.Common.Math.b2Vec2.Free(this.m_axis),this.m_axis=Box2D.Common.Math.b2Math.CrossVF(j,1),Box2D.Common.Math.b2Vec2.Free(j),
this.m_axis.Normalize(),l=this.m_axis,k=c.R,b=k.col1.x*l.x+k.col2.x*l.y,d=k.col1.y*l.x+k.col2.y*l.y,l=this.m_localPoint,k=c.R,g=c.position.x+(k.col1.x*l.x+k.col2.x*l.y),h=c.position.y+(k.col1.y*l.x+k.col2.y*l.y),l=a,k=e.R,i=e.position.x+(k.col1.x*l.x+k.col2.x*l.y),j=e.position.y+(k.col1.y*l.x+k.col2.y*l.y),(i-g)*b+(j-h)*d<0&&this.m_axis.NegativeSelf()):a.indexA[0]==a.indexA[0]?(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceB,g=this.m_proxyB.GetVertex(a.indexB[0]),h=this.m_proxyB.GetVertex(a.indexB[1]),
f=this.m_proxyA.GetVertex(a.indexA[0]),this.m_localPoint.x=0.5*(g.x+h.x),this.m_localPoint.y=0.5*(g.y+h.y),j=Box2D.Common.Math.b2Math.SubtractVV(h,g),Box2D.Common.Math.b2Vec2.Free(this.m_axis),this.m_axis=Box2D.Common.Math.b2Math.CrossVF(j,1),Box2D.Common.Math.b2Vec2.Free(j),this.m_axis.Normalize(),l=this.m_axis,k=e.R,b=k.col1.x*l.x+k.col2.x*l.y,d=k.col1.y*l.x+k.col2.y*l.y,l=this.m_localPoint,k=e.R,i=e.position.x+(k.col1.x*l.x+k.col2.x*l.y),j=e.position.y+(k.col1.y*l.x+k.col2.y*l.y),l=f,k=c.R,g=c.position.x+
(k.col1.x*l.x+k.col2.x*l.y),h=c.position.y+(k.col1.y*l.x+k.col2.y*l.y),(g-i)*b+(h-j)*d<0&&this.m_axis.NegativeSelf()):(b=this.m_proxyA.GetVertex(a.indexA[0]),d=this.m_proxyA.GetVertex(a.indexA[1]),g=this.m_proxyB.GetVertex(a.indexB[0]),h=this.m_proxyB.GetVertex(a.indexB[1]),j=Box2D.Common.Math.b2Math.SubtractVV(d,b),i=Box2D.Common.Math.b2Math.MulMV(c.R,j),Box2D.Common.Math.b2Vec2.Free(j),j=Box2D.Common.Math.b2Math.SubtractVV(h,g),k=Box2D.Common.Math.b2Math.MulMV(e.R,j),Box2D.Common.Math.b2Vec2.Free(j),
e=i.x*i.x+i.y*i.y,c=k.x*k.x+k.y*k.y,j=Box2D.Common.Math.b2Math.SubtractVV(k,i),a=i.x*j.x+i.y*j.y,f=k.x*j.x+k.y*j.y,Box2D.Common.Math.b2Vec2.Free(j),j=i.x*k.x+i.y*k.y,k=e*c-j*j,i=0,k!=0&&(i=Box2D.Common.Math.b2Math.Clamp((j*f-a*c)/k,0,1)),(j*i+f)/c<0&&(i=Box2D.Common.Math.b2Math.Clamp((j-a)/e,0,1)),f=Box2D.Common.Math.b2Vec2.Get(0,0),f.x=b.x+i*(d.x-b.x),f.y=b.y+i*(d.y-b.y),a=Box2D.Common.Math.b2Vec2.Get(0,0),a.x=g.x+i*(h.x-g.x),a.y=g.y+i*(h.y-g.y),i==0||i==1?(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceB,
j=Box2D.Common.Math.b2Math.SubtractVV(h,g),Box2D.Common.Math.b2Vec2.Free(this.m_axis),this.m_axis=Box2D.Common.Math.b2Math.CrossVF(j,1),Box2D.Common.Math.b2Vec2.Free(j),this.m_axis.Normalize(),this.m_localPoint=a):(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceA,j=Box2D.Common.Math.b2Math.SubtractVV(d,b),Box2D.Common.Math.b2Vec2.Free(this.m_axis),this.m_axis=Box2D.Common.Math.b2Math.CrossVF(j,1),Box2D.Common.Math.b2Vec2.Free(j),this.m_localPoint=f),i<0&&this.m_axis.NegativeSelf(),Box2D.Common.Math.b2Vec2.Free(f),
Box2D.Common.Math.b2Vec2.Free(a))};
Box2D.Collision.b2SeparationFunction.prototype.Evaluate=function(a,b){var c=0;switch(this.m_type){case Box2D.Collision.b2SeparationFunction.e_points:var c=Box2D.Common.Math.b2Math.MulTMV(a.R,this.m_axis),d=this.m_axis.GetNegative(),e=Box2D.Common.Math.b2Math.MulTMV(b.R,d);Box2D.Common.Math.b2Vec2.Free(d);var f=this.m_proxyA.GetSupportVertex(c);Box2D.Common.Math.b2Vec2.Free(c);c=this.m_proxyB.GetSupportVertex(e);Box2D.Common.Math.b2Vec2.Free(e);e=Box2D.Common.Math.b2Math.MulX(a,f);f=Box2D.Common.Math.b2Math.MulX(b,
c);c=(f.x-e.x)*this.m_axis.x+(f.y-e.y)*this.m_axis.y;Box2D.Common.Math.b2Vec2.Free(e);Box2D.Common.Math.b2Vec2.Free(f);break;case Box2D.Collision.b2SeparationFunction.e_faceA:d=Box2D.Common.Math.b2Math.MulMV(a.R,this.m_axis);f=d.GetNegative();e=Box2D.Common.Math.b2Math.MulTMV(b.R,f);Box2D.Common.Math.b2Vec2.Free(f);c=this.m_proxyB.GetSupportVertex(e);Box2D.Common.Math.b2Vec2.Free(e);e=Box2D.Common.Math.b2Math.MulX(a,this.m_localPoint);f=Box2D.Common.Math.b2Math.MulX(b,c);c=(f.x-e.x)*d.x+(f.y-e.y)*
d.y;Box2D.Common.Math.b2Vec2.Free(d);Box2D.Common.Math.b2Vec2.Free(e);Box2D.Common.Math.b2Vec2.Free(f);break;case Box2D.Collision.b2SeparationFunction.e_faceB:d=Box2D.Common.Math.b2Math.MulMV(b.R,this.m_axis);f=d.GetNegative();c=Box2D.Common.Math.b2Math.MulTMV(a.R,f);Box2D.Common.Math.b2Vec2.Free(f);f=this.m_proxyA.GetSupportVertex(c);Box2D.Common.Math.b2Vec2.Free(c);e=Box2D.Common.Math.b2Math.MulX(a,f);f=Box2D.Common.Math.b2Math.MulX(b,this.m_localPoint);c=(e.x-f.x)*d.x+(e.y-f.y)*d.y;Box2D.Common.Math.b2Vec2.Free(d);
Box2D.Common.Math.b2Vec2.Free(e);Box2D.Common.Math.b2Vec2.Free(f);break;default:Box2D.Common.b2Settings.b2Assert(!1)}return c};Box2D.Collision.b2SeparationFunction.e_points=1;Box2D.Collision.b2SeparationFunction.e_faceA=2;Box2D.Collision.b2SeparationFunction.e_faceB=4;Box2D.Common.Math.b2Transform=function(a,b){UsageTracker.get("Box2D.Common.Math.b2Transform").trackCreate();this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.R=Box2D.Common.Math.b2Mat22.Get();a&&this.position.SetV(a);b&&this.R.SetM(b)};Box2D.Common.Math.b2Transform.prototype.Initialize=function(a,b){this.position.SetV(a);this.R.SetM(b)};Box2D.Common.Math.b2Transform.prototype.SetIdentity=function(){this.position.SetZero();this.R.SetIdentity()};
Box2D.Common.Math.b2Transform.prototype.Set=function(a){this.position.SetV(a.position);this.R.SetM(a.R)};Box2D.Common.Math.b2Transform.prototype.GetAngle=function(){return Math.atan2(this.R.col1.y,this.R.col1.x)};Box2D.Collision.b2TimeOfImpact={};
Box2D.Collision.b2TimeOfImpact.TimeOfImpact=function(a){Box2D.Collision.b2TimeOfImpact.b2_toiCalls++;var b=a.proxyA,c=a.proxyB,d=a.sweepA,e=a.sweepB;Box2D.Common.b2Settings.b2Assert(d.t0==e.t0);Box2D.Common.b2Settings.b2Assert(1-d.t0>Number.MIN_VALUE);var f=b.m_radius+c.m_radius,a=a.tolerance,g=0,h=0,i=0;Box2D.Collision.b2TimeOfImpact.s_cache.count=0;for(Box2D.Collision.b2TimeOfImpact.s_distanceInput.useRadii=!1;;){d.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,g);e.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,
g);Box2D.Collision.b2TimeOfImpact.s_distanceInput.proxyA=b;Box2D.Collision.b2TimeOfImpact.s_distanceInput.proxyB=c;Box2D.Collision.b2TimeOfImpact.s_distanceInput.transformA=Box2D.Collision.b2TimeOfImpact.s_xfA;Box2D.Collision.b2TimeOfImpact.s_distanceInput.transformB=Box2D.Collision.b2TimeOfImpact.s_xfB;Box2D.Collision.b2Distance.Distance(Box2D.Collision.b2TimeOfImpact.s_distanceOutput,Box2D.Collision.b2TimeOfImpact.s_cache,Box2D.Collision.b2TimeOfImpact.s_distanceInput);if(Box2D.Collision.b2TimeOfImpact.s_distanceOutput.distance<=
0){g=1;break}Box2D.Collision.b2TimeOfImpact.s_fcn.Initialize(Box2D.Collision.b2TimeOfImpact.s_cache,b,Box2D.Collision.b2TimeOfImpact.s_xfA,c,Box2D.Collision.b2TimeOfImpact.s_xfB);var j=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(j<=0){g=1;break}h==0&&(i=j>f?Math.max(f-a,0.75*f):Math.max(j-a,0.02*f));if(j-i<0.5*a){if(h==0){g=1;break}break}var k=g,l=g,n=1;d.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,n);e.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,
n);var m=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(m>=i){g=1;break}for(var o=0;;){var p=0,p=o&1?l+(i-j)*(n-l)/(m-j):0.5*(l+n);d.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,p);e.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,p);var q=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(Math.abs(q-i)<0.025*a){k=p;break}q>i?(l=p,j=q):(n=p,m=
q);o++;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters++;if(o==50)break}Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=Math.max(Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters,o);if(k<(1+100*Number.MIN_VALUE)*g)break;g=k;h++;Box2D.Collision.b2TimeOfImpact.b2_toiIters++;if(h==1E3)break}Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=Math.max(Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters,h);return g};Box2D.Collision.b2TimeOfImpact.b2_toiCalls=0;Box2D.Collision.b2TimeOfImpact.b2_toiIters=0;
Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=0;Box2D.Collision.b2TimeOfImpact.s_cache=new Box2D.Collision.b2SimplexCache;Box2D.Collision.b2TimeOfImpact.s_distanceInput=new Box2D.Collision.b2DistanceInput;Box2D.Collision.b2TimeOfImpact.s_xfA=new Box2D.Common.Math.b2Transform;Box2D.Collision.b2TimeOfImpact.s_xfB=new Box2D.Common.Math.b2Transform;Box2D.Collision.b2TimeOfImpact.s_fcn=new Box2D.Collision.b2SeparationFunction;
Box2D.Collision.b2TimeOfImpact.s_distanceOutput=new Box2D.Collision.b2DistanceOutput;Box2D.Dynamics.b2BodyDef=function(){UsageTracker.get("Box2D.Dynamics.b2BodyDef").trackCreate();this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearVelocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.angularDamping=this.linearDamping=this.angularVelocity=this.angle=0;this.awake=this.allowSleep=!0;this.bullet=this.fixedRotation=!1;this.type=Box2D.Dynamics.b2BodyDef.b2_staticBody;this.active=!0;this.inertiaScale=1};Box2D.Dynamics.b2BodyDef.b2_staticBody=0;
Box2D.Dynamics.b2BodyDef.b2_kinematicBody=1;Box2D.Dynamics.b2BodyDef.b2_dynamicBody=2;Box2D.Dynamics.Contacts={};
Box2D.Dynamics.Contacts.b2Contact=function(a,b){UsageTracker.get("Box2D.Dynamics.Contacts.b2Contact").trackCreate();this.ID="Contact"+Box2D.Dynamics.Contacts.b2Contact.NEXT_ID++;this.m_manifold=new Box2D.Collision.b2Manifold;this.m_oldManifold=new Box2D.Collision.b2Manifold;this.touching=!1;var c=a.GetBody(),d=b.GetBody();this.continuous=c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||c.IsBullet()||d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||d.IsBullet();this.sensor=a.IsSensor()||
b.IsSensor();this.filtering=!1;this.m_fixtureA=a;this.m_fixtureB=b;this.enabled=!0;this.bodyAList=c.GetContactList();this.bodyBList=d.GetContactList();this.worldList=d.GetWorld().GetContactList();this.AddToLists()};
Box2D.Dynamics.Contacts.b2Contact.prototype.Reset=function(a,b){this.m_manifold.Reset();this.m_oldManifold.Reset();this.touching=!1;var c=a.GetBody(),d=b.GetBody();this.continuous=c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||c.IsBullet()||d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||d.IsBullet();this.sensor=a.IsSensor()||b.IsSensor();this.filtering=!1;this.m_fixtureA=a;this.m_fixtureB=b;this.enabled=!0;this.bodyAList=c.GetContactList();this.bodyBList=d.GetContactList();this.worldList=
d.GetWorld().GetContactList();this.AddToLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.AddToLists=function(){this.bodyAList.AddContact(this);this.bodyBList.AddContact(this);this.worldList.AddContact(this);this.UpdateLists()};
Box2D.Dynamics.Contacts.b2Contact.prototype.UpdateLists=function(){var a=!1,b=!1;!this.IsSensor()&&this.IsEnabled()&&(this.IsTouching()&&(a=!0),this.IsContinuous()&&(b=!0));this.bodyAList.UpdateContact(this,a,b);this.bodyBList.UpdateContact(this,a,b);this.worldList.UpdateContact(this,a,b)};Box2D.Dynamics.Contacts.b2Contact.prototype.RemoveFromLists=function(){this.bodyAList.RemoveContact(this);this.bodyBList.RemoveContact(this);this.worldList.RemoveContact(this)};
Box2D.Dynamics.Contacts.b2Contact.prototype.GetManifold=function(){return this.m_manifold};Box2D.Dynamics.Contacts.b2Contact.prototype.GetWorldManifold=function(a){var b=this.m_fixtureA.GetBody(),c=this.m_fixtureB.GetBody(),d=this.m_fixtureA.GetShape(),e=this.m_fixtureB.GetShape();a.Initialize(this.m_manifold,b.GetTransform(),d.m_radius,c.GetTransform(),e.m_radius)};Box2D.Dynamics.Contacts.b2Contact.prototype.IsTouching=function(){return this.touching};
Box2D.Dynamics.Contacts.b2Contact.prototype.IsContinuous=function(){return this.continuous};Box2D.Dynamics.Contacts.b2Contact.prototype.SetSensor=function(a){this.sensor=a;this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.IsSensor=function(){return this.sensor};Box2D.Dynamics.Contacts.b2Contact.prototype.SetEnabled=function(a){this.enabled=a;this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.IsEnabled=function(){return this.enabled};
Box2D.Dynamics.Contacts.b2Contact.prototype.GetNext=function(){return this.m_next};Box2D.Dynamics.Contacts.b2Contact.prototype.GetFixtureA=function(){return this.m_fixtureA};Box2D.Dynamics.Contacts.b2Contact.prototype.GetFixtureB=function(){return this.m_fixtureB};Box2D.Dynamics.Contacts.b2Contact.prototype.GetOther=function(a){var b=this.m_fixtureA.GetBody();return b!=a?b:this.m_fixtureB.GetBody()};Box2D.Dynamics.Contacts.b2Contact.prototype.FlagForFiltering=function(){this.filtering=!0};
Box2D.Dynamics.Contacts.b2Contact.prototype.ClearFiltering=function(){this.filtering=!1};Box2D.Dynamics.Contacts.b2Contact.prototype.IsFiltering=function(){return this.filtering};
Box2D.Dynamics.Contacts.b2Contact.prototype.Update=function(a){var b=this.m_oldManifold;this.m_oldManifold=this.m_manifold;this.m_manifold=b;this.enabled=!0;var b=!1,c=this.IsTouching(),d=this.m_fixtureA.GetBody(),e=this.m_fixtureB.GetBody(),f=this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);if(this.sensor)f&&(b=Box2D.Collision.Shapes.b2Shape.TestOverlap(this.m_fixtureA.GetShape(),d.GetTransform(),this.m_fixtureB.GetShape(),e.GetTransform())),this.m_manifold.m_pointCount=0;else{this.continuous=
d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||d.IsBullet()||e.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||e.IsBullet()?!0:!1;if(f){this.Evaluate();b=this.m_manifold.m_pointCount>0;for(f=0;f<this.m_manifold.m_pointCount;f++){var g=this.m_manifold.m_points[f];g.m_normalImpulse=0;for(var h=g.m_tangentImpulse=0;h<this.m_oldManifold.m_pointCount;h++){var i=this.m_oldManifold.m_points[h];if(i.m_id.GetKey()==g.m_id.GetKey()){g.m_normalImpulse=i.m_normalImpulse;g.m_tangentImpulse=i.m_tangentImpulse;
break}}}}else this.m_manifold.m_pointCount=0;b!=c&&(d.SetAwake(!0),e.SetAwake(!0))}this.touching=b;b!=c&&this.UpdateLists();!c&&b&&a.BeginContact(this);c&&!b&&a.EndContact(this);this.sensor||a.PreSolve(this,this.m_oldManifold)};Box2D.Dynamics.Contacts.b2Contact.prototype.Evaluate=function(){};
Box2D.Dynamics.Contacts.b2Contact.prototype.ComputeTOI=function(a,b){Box2D.Dynamics.Contacts.b2Contact.s_input.proxyA.Set(this.m_fixtureA.GetShape());Box2D.Dynamics.Contacts.b2Contact.s_input.proxyB.Set(this.m_fixtureB.GetShape());Box2D.Dynamics.Contacts.b2Contact.s_input.sweepA=a;Box2D.Dynamics.Contacts.b2Contact.s_input.sweepB=b;Box2D.Dynamics.Contacts.b2Contact.s_input.tolerance=Box2D.Common.b2Settings.b2_linearSlop;return Box2D.Collision.b2TimeOfImpact.TimeOfImpact(Box2D.Dynamics.Contacts.b2Contact.s_input)};
Box2D.Dynamics.Contacts.b2Contact.s_input=new Box2D.Collision.b2TOIInput;Box2D.Dynamics.Contacts.b2Contact.NEXT_ID=0;Box2D.Collision.Shapes.b2MassData=function(){UsageTracker.get("Box2D.Collision.Shapes.b2MassData").trackCreate();this.mass=0;this.center=Box2D.Common.Math.b2Vec2.Get(0,0);this.I=0};Box2D.Collision.Shapes.b2MassData._freeCache=[];Box2D.Collision.Shapes.b2MassData.Get=function(){UsageTracker.get("Box2D.Collision.Shapes.b2MassData").trackGet();if(Box2D.Collision.Shapes.b2MassData._freeCache.length>0){var a=Box2D.Collision.Shapes.b2MassData._freeCache.pop();a.mass=0;a.center.SetZero();a.I=0;return a}return new Box2D.Collision.Shapes.b2MassData};
Box2D.Collision.Shapes.b2MassData.Free=function(a){a!=null&&(UsageTracker.get("Box2D.Collision.Shapes.b2MassData").trackFree(),Box2D.Collision.Shapes.b2MassData._freeCache.push(a))};Box2D.Collision.Shapes.b2MassData.prototype.SetV=function(a,b,c){this.mass=a;this.center.SetV(b);this.I=c};Box2D.Collision.Shapes.b2MassData.prototype.Set=function(a,b,c,d){this.mass=a;this.center.Set(b,c);this.I=d};Box2D.Collision.Shapes.b2PolygonShape=function(){UsageTracker.get("Box2D.Collision.Shapes.b2PolygonShape").trackCreate();Box2D.Collision.Shapes.b2Shape.call(this);this.m_centroid=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_vertices=[];this.m_normals=[]};goog.inherits(Box2D.Collision.Shapes.b2PolygonShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2PolygonShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2PolygonShape.NAME};
Box2D.Collision.Shapes.b2PolygonShape.prototype.Copy=function(){var a=new Box2D.Collision.Shapes.b2PolygonShape;a.Set(this);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.Set=function(a){Box2D.Collision.Shapes.b2Shape.prototype.Set.call(this,a);if(a instanceof Box2D.Collision.Shapes.b2PolygonShape){this.m_centroid.SetV(a.m_centroid);this.m_vertexCount=a.m_vertexCount;this.Reserve(this.m_vertexCount);for(var b=0;b<this.m_vertexCount;b++)this.m_vertices[b].SetV(a.m_vertices[b]),this.m_normals[b].SetV(a.m_normals[b])}};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsArray=function(a){this.SetAsVector(a)};Box2D.Collision.Shapes.b2PolygonShape.AsArray=function(a){var b=new Box2D.Collision.Shapes.b2PolygonShape;b.SetAsArray(a);return b};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsVector=function(a){var b=a.length;Box2D.Common.b2Settings.b2Assert(2<=b);this.m_vertexCount=b;this.Reserve(b);for(b=b=0;b<this.m_vertexCount;b++)this.m_vertices[b].SetV(a[b]);for(b=0;b<this.m_vertexCount;++b){a=Box2D.Common.Math.b2Math.SubtractVV(this.m_vertices[b+1<this.m_vertexCount?b+1:0],this.m_vertices[b]);Box2D.Common.b2Settings.b2Assert(a.LengthSquared()>Number.MIN_VALUE);var c=Box2D.Common.Math.b2Math.CrossVF(a,1);Box2D.Common.Math.b2Vec2.Free(a);
this.m_normals[b].SetV(c);Box2D.Common.Math.b2Vec2.Free(c);this.m_normals[b].Normalize()}this.m_centroid=Box2D.Collision.Shapes.b2PolygonShape.ComputeCentroid(this.m_vertices,this.m_vertexCount)};Box2D.Collision.Shapes.b2PolygonShape.AsVector=function(a){var b=new Box2D.Collision.Shapes.b2PolygonShape;b.SetAsVector(a);return b};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsBox=function(a,b){this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set(-a,-b);this.m_vertices[1].Set(a,-b);this.m_vertices[2].Set(a,b);this.m_vertices[3].Set(-a,b);this.m_normals[0].Set(0,-1);this.m_normals[1].Set(1,0);this.m_normals[2].Set(0,1);this.m_normals[3].Set(-1,0);this.m_centroid.SetZero()};Box2D.Collision.Shapes.b2PolygonShape.AsBox=function(a,b){var c=new Box2D.Collision.Shapes.b2PolygonShape;c.SetAsBox(a,b);return c};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsOrientedBox=function(a,b,c,d){this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set(-a,-b);this.m_vertices[1].Set(a,-b);this.m_vertices[2].Set(a,b);this.m_vertices[3].Set(-a,b);this.m_normals[0].Set(0,-1);this.m_normals[1].Set(1,0);this.m_normals[2].Set(0,1);this.m_normals[3].Set(-1,0);this.m_centroid=c;a=Box2D.Common.Math.b2Mat22.Get();a.Set(d);c=new Box2D.Common.Math.b2Transform(c,a);for(d=0;d<this.m_vertexCount;++d)this.m_vertices[d]=Box2D.Common.Math.b2Math.MulX(c,
this.m_vertices[d]),this.m_normals[d]=Box2D.Common.Math.b2Math.MulMV(c.R,this.m_normals[d])};Box2D.Collision.Shapes.b2PolygonShape.AsOrientedBox=function(a,b,c,d){var e=new Box2D.Collision.Shapes.b2PolygonShape;e.SetAsOrientedBox(a,b,c,d);return e};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsEdge=function(a,b){this.m_vertexCount=2;this.Reserve(2);this.m_vertices[0].SetV(a);this.m_vertices[1].SetV(b);this.m_centroid.x=0.5*(a.x+b.x);this.m_centroid.y=0.5*(a.y+b.y);var c=Box2D.Common.Math.b2Math.SubtractVV(b,a),d=Box2D.Common.Math.b2Math.CrossVF(c,1);Box2D.Common.Math.b2Vec2.Free(c);this.m_normals[0]=d;this.m_normals[0].Normalize();this.m_normals[1].x=-this.m_normals[0].x;this.m_normals[1].y=-this.m_normals[0].y};
Box2D.Collision.Shapes.b2PolygonShape.AsEdge=function(a,b){var c=new Box2D.Collision.Shapes.b2PolygonShape;c.SetAsEdge(a,b);return c};Box2D.Collision.Shapes.b2PolygonShape.prototype.TestPoint=function(a,b){var c;c=a.R;for(var d=b.x-a.position.x,e=b.y-a.position.y,f=d*c.col1.x+e*c.col1.y,g=d*c.col2.x+e*c.col2.y,h=0;h<this.m_vertexCount;++h)if(c=this.m_vertices[h],d=f-c.x,e=g-c.y,c=this.m_normals[h],c.x*d+c.y*e>0)return!1;return!0};
Box2D.Collision.Shapes.b2PolygonShape.prototype.RayCast=function(a,b,c){var d=0,e=b.maxFraction,f=0,g=0,h,i,f=b.p1.x-c.position.x,g=b.p1.y-c.position.y;h=c.R;var j=f*h.col1.x+g*h.col1.y,k=f*h.col2.x+g*h.col2.y,f=b.p2.x-c.position.x,g=b.p2.y-c.position.y;h=c.R;b=f*h.col1.x+g*h.col1.y-j;h=f*h.col2.x+g*h.col2.y-k;for(var l=-1,n=0;n<this.m_vertexCount;++n){i=this.m_vertices[n];f=i.x-j;g=i.y-k;i=this.m_normals[n];f=i.x*f+i.y*g;g=i.x*b+i.y*h;if(g==0){if(f<0)return!1}else g<0&&f<d*g?(d=f/g,l=n):g>0&&f<e*
g&&(e=f/g);if(e<d-Number.MIN_VALUE)return!1}return l>=0?(a.fraction=d,h=c.R,i=this.m_normals[l],a.normal.x=h.col1.x*i.x+h.col2.x*i.y,a.normal.y=h.col1.y*i.x+h.col2.y*i.y,!0):!1};
Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeAABB=function(a,b){for(var c=b.R,d=this.m_vertices[0],e=b.position.x+(c.col1.x*d.x+c.col2.x*d.y),f=b.position.y+(c.col1.y*d.x+c.col2.y*d.y),g=e,h=f,i=1;i<this.m_vertexCount;++i)var d=this.m_vertices[i],j=b.position.x+(c.col1.x*d.x+c.col2.x*d.y),d=b.position.y+(c.col1.y*d.x+c.col2.y*d.y),e=e<j?e:j,f=f<d?f:d,g=g>j?g:j,h=h>d?h:d;a.lowerBound.x=e-this.m_radius;a.lowerBound.y=f-this.m_radius;a.upperBound.x=g+this.m_radius;a.upperBound.y=h+this.m_radius};
Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeMass=function(a,b){if(this.m_vertexCount==2)a.center.x=0.5*(this.m_vertices[0].x+this.m_vertices[1].x),a.center.y=0.5*(this.m_vertices[0].y+this.m_vertices[1].y),a.mass=0,a.I=0;else{for(var c=0,d=0,e=0,f=0,g=1/3,h=0;h<this.m_vertexCount;++h){var i=this.m_vertices[h],j=h+1<this.m_vertexCount?this.m_vertices[h+1]:this.m_vertices[0],k=i.x-0,l=i.y-0,n=j.x-0,m=j.y-0,o=k*m-l*n,p=0.5*o;e+=p;c+=p*g*(0+i.x+j.x);d+=p*g*(0+i.y+j.y);i=k;f+=o*(g*(0.25*(i*
i+n*i+n*n)+(0*i+0*n))+0+(g*(0.25*(l*l+m*l+m*m)+(0*l+0*m))+0))}c*=1/e;d*=1/e;a.Set(b*e,c,d,b*f)}};
Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeSubmergedArea=function(a,b,c,d){for(var e=Box2D.Common.Math.b2Math.MulTMV(c.R,a),f=b-Box2D.Common.Math.b2Math.Dot(a,c.position),g=[],h=0,i=-1,b=-1,j=!1,a=a=0;a<this.m_vertexCount;++a){g[a]=Box2D.Common.Math.b2Math.Dot(e,this.m_vertices[a])-f;var k=g[a]<-Number.MIN_VALUE;a>0&&(k?j||(i=a-1,h++):j&&(b=a-1,h++));j=k}Box2D.Common.Math.b2Vec2.Free(e);switch(h){case 0:return j?(a=Box2D.Collision.Shapes.b2MassData.Get(),this.ComputeMass(a,1),c=Box2D.Common.Math.b2Math.MulX(c,
a.center),d.SetV(c),Box2D.Common.Math.b2Vec2.Free(c),d=a.mass,Box2D.Collision.Shapes.b2MassData.Free(a),d):0;case 1:i==-1?i=this.m_vertexCount-1:b=this.m_vertexCount-1}a=(i+1)%this.m_vertexCount;e=(b+1)%this.m_vertexCount;f=(0-g[i])/(g[a]-g[i]);g=(0-g[b])/(g[e]-g[b]);i=Box2D.Common.Math.b2Vec2.Get(this.m_vertices[i].x*(1-f)+this.m_vertices[a].x*f,this.m_vertices[i].y*(1-f)+this.m_vertices[a].y*f);f=Box2D.Common.Math.b2Vec2.Get(this.m_vertices[b].x*(1-g)+this.m_vertices[e].x*g,this.m_vertices[b].y*
(1-g)+this.m_vertices[e].y*g);b=0;g=Box2D.Common.Math.b2Vec2.Get(0,0);for(h=this.m_vertices[a];a!=e;)a=(a+1)%this.m_vertexCount,j=a==e?f:this.m_vertices[a],k=0.5*((h.x-i.x)*(j.y-i.y)-(h.y-i.y)*(j.x-i.x)),b+=k,g.x+=k*(i.x+h.x+j.x)/3,g.y+=k*(i.y+h.y+j.y)/3,h=j;Box2D.Common.Math.b2Vec2.Free(i);Box2D.Common.Math.b2Vec2.Free(f);g.Multiply(1/b);c=Box2D.Common.Math.b2Math.MulX(c,g);Box2D.Common.Math.b2Vec2.Free(g);d.SetV(c);Box2D.Common.Math.b2Vec2.Free(c);return b};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetDistanceProxy=function(a){a.SetValues(this.m_vertexCount,this.m_radius,this.m_vertices)};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertexCount=function(){return this.m_vertexCount};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertices=function(){return this.m_vertices};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertex=function(a){return this.m_vertices[a]};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetNormals=function(){return this.m_normals};
Box2D.Collision.Shapes.b2PolygonShape.prototype.GetNormal=function(a){return this.m_normals[a]};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetCentroid=function(){return this.m_centroid};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetSupport=function(a){for(var b=0,c=this.m_vertices[0].x*a.x+this.m_vertices[0].y*a.y,d=1;d<this.m_vertexCount;++d){var e=this.m_vertices[d].x*a.x+this.m_vertices[d].y*a.y;e>c&&(b=d,c=e)}return b};
Box2D.Collision.Shapes.b2PolygonShape.prototype.GetSupportVertex=function(a){for(var b=0,c=this.m_vertices[0].x*a.x+this.m_vertices[0].y*a.y,d=1;d<this.m_vertexCount;++d){var e=this.m_vertices[d].x*a.x+this.m_vertices[d].y*a.y;e>c&&(b=d,c=e)}return this.m_vertices[b]};
Box2D.Collision.Shapes.b2PolygonShape.prototype.Reserve=function(a){for(var b=0;b<this.m_vertices.length;b++)Box2D.Common.Math.b2Vec2.Free(this.m_vertices[b]),Box2D.Common.Math.b2Vec2.Free(this.m_normals[b]);this.m_vertices=[];this.m_normals=[];for(b=0;b<a;b++)this.m_vertices[b]=Box2D.Common.Math.b2Vec2.Get(0,0),this.m_normals[b]=Box2D.Common.Math.b2Vec2.Get(0,0)};
Box2D.Collision.Shapes.b2PolygonShape.ComputeCentroid=function(a,b){for(var c=Box2D.Common.Math.b2Vec2.Get(0,0),d=0,e=1/3,f=0;f<b;++f){var g=a[f],h=f+1<b?a[f+1]:a[0],i=0.5*((g.x-0)*(h.y-0)-(g.y-0)*(h.x-0));d+=i;c.x+=i*e*(0+g.x+h.x);c.y+=i*e*(0+g.y+h.y)}c.x*=1/d;c.y*=1/d;return c};Box2D.Collision.Shapes.b2PolygonShape.s_mat=Box2D.Common.Math.b2Mat22.Get();Box2D.Collision.Shapes.b2PolygonShape.NAME="b2PolygonShape";Box2D.Collision.Shapes.b2EdgeShape=function(a,b){UsageTracker.get("Box2D.Collision.Shapes.b2EdgeShape").trackCreate();Box2D.Collision.Shapes.b2Shape.call(this);this.m_nextEdge=this.m_prevEdge=null;this.m_v1=a;this.m_v2=b;this.m_direction=Box2D.Common.Math.b2Vec2.Get(this.m_v2.x-this.m_v1.x,this.m_v2.y-this.m_v1.y);this.m_length=this.m_direction.Normalize();this.m_normal=Box2D.Common.Math.b2Vec2.Get(this.m_direction.y,-this.m_direction.x);this.m_coreV1=Box2D.Common.Math.b2Vec2.Get(-Box2D.Common.b2Settings.b2_toiSlop*
(this.m_normal.x-this.m_direction.x)+this.m_v1.x,-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.y-this.m_direction.y)+this.m_v1.y);this.m_coreV2=Box2D.Common.Math.b2Vec2.Get(-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.x+this.m_direction.x)+this.m_v2.x,-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.y+this.m_direction.y)+this.m_v2.y);this.m_cornerDir1=this.m_normal;this.m_cornerDir2=Box2D.Common.Math.b2Vec2.Get(-this.m_normal.x,-this.m_normal.y);this.m_cornerConvex2=this.m_cornerConvex1=
!1};goog.inherits(Box2D.Collision.Shapes.b2EdgeShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2EdgeShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2EdgeShape.NAME};Box2D.Collision.Shapes.b2EdgeShape.prototype.TestPoint=function(){return!1};
Box2D.Collision.Shapes.b2EdgeShape.prototype.RayCast=function(a,b,c){var d=b.p2.x-b.p1.x,e=b.p2.y-b.p1.y,f=c.R,g=c.position.x+(f.col1.x*this.m_v1.x+f.col2.x*this.m_v1.y),h=c.position.y+(f.col1.y*this.m_v1.x+f.col2.y*this.m_v1.y),i=c.position.y+(f.col1.y*this.m_v2.x+f.col2.y*this.m_v2.y)-h,c=-(c.position.x+(f.col1.x*this.m_v2.x+f.col2.x*this.m_v2.y)-g),f=100*Number.MIN_VALUE,j=-(d*i+e*c);if(j>f){var g=b.p1.x-g,k=b.p1.y-h,h=g*i+k*c;if(0<=h&&h<=b.maxFraction*j&&(b=-d*k+e*g,-f*j<=b&&b<=j*(1+f)))return h/=
j,a.fraction=h,b=Math.sqrt(i*i+c*c),a.normal.x=i/b,a.normal.y=c/b,!0}return!1};
Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeAABB=function(a,b){var c=b.R,d=b.position.x+(c.col1.x*this.m_v1.x+c.col2.x*this.m_v1.y),e=b.position.y+(c.col1.y*this.m_v1.x+c.col2.y*this.m_v1.y),f=b.position.x+(c.col1.x*this.m_v2.x+c.col2.x*this.m_v2.y),c=b.position.y+(c.col1.y*this.m_v2.x+c.col2.y*this.m_v2.y);d<f?(a.lowerBound.x=d,a.upperBound.x=f):(a.lowerBound.x=f,a.upperBound.x=d);e<c?(a.lowerBound.y=e,a.upperBound.y=c):(a.lowerBound.y=c,a.upperBound.y=e)};
Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeMass=function(a){a.mass=0;a.center.SetV(this.m_v1);a.I=0};
Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeSubmergedArea=function(a,b,c,d){b===void 0&&(b=0);var e=Box2D.Common.Math.b2Vec2.Get(a.x*b,a.y*b),f=Box2D.Common.Math.b2Math.MulX(c,this.m_v1),c=Box2D.Common.Math.b2Math.MulX(c,this.m_v2),g=Box2D.Common.Math.b2Math.Dot(a,f)-b,a=Box2D.Common.Math.b2Math.Dot(a,c)-b;if(g>0)if(a>0)return 0;else f.x=-a/(g-a)*f.x+g/(g-a)*c.x,f.y=-a/(g-a)*f.y+g/(g-a)*c.y;else if(a>0)c.x=-a/(g-a)*f.x+g/(g-a)*c.x,c.y=-a/(g-a)*f.y+g/(g-a)*c.y;d.x=(e.x+f.x+c.x)/3;d.y=(e.y+
f.y+c.y)/3;return 0.5*((f.x-e.x)*(c.y-e.y)-(f.y-e.y)*(c.x-e.x))};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetLength=function(){return this.m_length};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetVertex1=function(){return this.m_v1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetVertex2=function(){return this.m_v2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCoreVertex1=function(){return this.m_coreV1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCoreVertex2=function(){return this.m_coreV2};
Box2D.Collision.Shapes.b2EdgeShape.prototype.GetNormalVector=function(){return this.m_normal};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetDirectionVector=function(){return this.m_direction};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCorner1Vector=function(){return this.m_cornerDir1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCorner2Vector=function(){return this.m_cornerDir2};Box2D.Collision.Shapes.b2EdgeShape.prototype.Corner1IsConvex=function(){return this.m_cornerConvex1};
Box2D.Collision.Shapes.b2EdgeShape.prototype.Corner2IsConvex=function(){return this.m_cornerConvex2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetFirstVertex=function(a){var b=a.R;return Box2D.Common.Math.b2Vec2.Get(a.position.x+(b.col1.x*this.m_coreV1.x+b.col2.x*this.m_coreV1.y),a.position.y+(b.col1.y*this.m_coreV1.x+b.col2.y*this.m_coreV1.y))};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetNextEdge=function(){return this.m_nextEdge};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetPrevEdge=function(){return this.m_prevEdge};
Box2D.Collision.Shapes.b2EdgeShape.prototype.Support=function(a,b,c){var d=a.R,e=a.position.x+(d.col1.x*this.m_coreV1.x+d.col2.x*this.m_coreV1.y),f=a.position.y+(d.col1.y*this.m_coreV1.x+d.col2.y*this.m_coreV1.y),g=a.position.x+(d.col1.x*this.m_coreV2.x+d.col2.x*this.m_coreV2.y),a=a.position.y+(d.col1.y*this.m_coreV2.x+d.col2.y*this.m_coreV2.y);return e*b+f*c>g*b+a*c?Box2D.Common.Math.b2Vec2.Get(e,f):Box2D.Common.Math.b2Vec2.Get(g,a)};
Box2D.Collision.Shapes.b2EdgeShape.prototype.SetPrevEdge=function(a,b,c,d){this.m_prevEdge=a;this.m_coreV1=b;this.m_cornerDir1=c;this.m_cornerConvex1=d};Box2D.Collision.Shapes.b2EdgeShape.prototype.SetNextEdge=function(a,b,c,d){this.m_nextEdge=a;this.m_coreV2=b;this.m_cornerDir2=c;this.m_cornerConvex2=d};Box2D.Collision.Shapes.b2EdgeShape.NAME="b2EdgeShape";Box2D.Dynamics.Contacts.b2PolyAndEdgeContact=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape()instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape()instanceof Box2D.Collision.Shapes.b2EdgeShape);Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};goog.inherits(Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,Box2D.Dynamics.Contacts.b2Contact);
Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.Reset=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape()instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape()instanceof Box2D.Collision.Shapes.b2EdgeShape);Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};
Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.Evaluate=function(){this.b2CollidePolyAndEdge(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().GetTransform(),this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.b2CollidePolyAndEdge=function(){};Box2D.Dynamics.b2TimeStep=function(a,b,c,d,e){UsageTracker.get("Box2D.Dynamics.b2TimeStep").trackCreate();this.Reset(a,b,c,d,e)};Box2D.Dynamics.b2TimeStep.prototype.Reset=function(a,b,c,d,e){this.dt=a;var f=0;a>0&&(f=1/a);this.inv_dt=f;this.dtRatio=b;this.positionIterations=c;this.velocityIterations=d;this.warmStarting=e};Box2D.Dynamics.Joints.b2FrictionJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_linearMass=Box2D.Common.Math.b2Mat22.Get();this.m_linearImpulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);this.m_linearMass.SetZero();this.m_angularMass=0;this.m_linearImpulse.SetZero();this.m_angularImpulse=0;this.m_maxForce=
a.maxForce;this.m_maxTorque=a.maxTorque};goog.inherits(Box2D.Dynamics.Joints.b2FrictionJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};
Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return new Box2D.Common.Math.b2Vec2.Get(a*this.m_linearImpulse.x,a*this.m_linearImpulse.y)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_angularImpulse};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SetMaxForce=function(a){a===void 0&&(a=0);this.m_maxForce=a};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetMaxForce=function(){return this.m_maxForce};
Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SetMaxTorque=function(a){a===void 0&&(a=0);this.m_maxTorque=a};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetMaxTorque=function(){return this.m_maxTorque};
Box2D.Dynamics.Joints.b2FrictionJoint.prototype.InitVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB;b=d.m_xf.R;var f=this.m_localAnchorA.x-d.m_sweep.localCenter.x,g=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=b.col1.x*f+b.col2.x*g,g=b.col1.y*f+b.col2.y*g,f=c;b=e.m_xf.R;var h=this.m_localAnchorB.x-e.m_sweep.localCenter.x,i=this.m_localAnchorB.y-e.m_sweep.localCenter.y,c=b.col1.x*h+b.col2.x*i,i=b.col1.y*h+b.col2.y*i,h=c;b=d.m_invMass;var c=e.m_invMass,j=d.m_invI,k=e.m_invI,
l=new Box2D.Common.Math.b2Mat22;l.col1.x=b+c;l.col2.x=0;l.col1.y=0;l.col2.y=b+c;l.col1.x+=j*g*g;l.col2.x+=-j*f*g;l.col1.y+=-j*f*g;l.col2.y+=j*f*f;l.col1.x+=k*i*i;l.col2.x+=-k*h*i;l.col1.y+=-k*h*i;l.col2.y+=k*h*h;l.GetInverse(this.m_linearMass);this.m_angularMass=j+k;if(this.m_angularMass>0)this.m_angularMass=1/this.m_angularMass;a.warmStarting?(this.m_linearImpulse.x*=a.dtRatio,this.m_linearImpulse.y*=a.dtRatio,this.m_angularImpulse*=a.dtRatio,a=this.m_linearImpulse,d.m_linearVelocity.x-=b*a.x,d.m_linearVelocity.y-=
b*a.y,d.m_angularVelocity-=j*(f*a.y-g*a.x+this.m_angularImpulse),e.m_linearVelocity.x+=c*a.x,e.m_linearVelocity.y+=c*a.y,e.m_angularVelocity+=k*(h*a.y-i*a.x+this.m_angularImpulse)):(this.m_linearImpulse.SetZero(),this.m_angularImpulse=0)};
Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SolveVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB,f=d.m_linearVelocity,g=d.m_angularVelocity,h=e.m_linearVelocity,i=e.m_angularVelocity,j=d.m_invMass,k=e.m_invMass,l=d.m_invI,n=e.m_invI;b=d.m_xf.R;var m=this.m_localAnchorA.x-d.m_sweep.localCenter.x,o=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=b.col1.x*m+b.col2.x*o,o=b.col1.y*m+b.col2.y*o,m=c;b=e.m_xf.R;var p=this.m_localAnchorB.x-e.m_sweep.localCenter.x,q=this.m_localAnchorB.y-
e.m_sweep.localCenter.y,c=b.col1.x*p+b.col2.x*q,q=b.col1.y*p+b.col2.y*q,p=c;b=0;var c=-this.m_angularMass*(i-g),r=this.m_angularImpulse;b=a.dt*this.m_maxTorque;this.m_angularImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_angularImpulse+c,-b,b);c=this.m_angularImpulse-r;g-=l*c;i+=n*c;b=Box2D.Common.Math.b2Vec2.Get(-(h.x-i*q-f.x+g*o),-(h.y+i*p-f.y-g*m));b.MulM(this.m_linearMass);c=this.m_linearImpulse.Copy();this.m_linearImpulse.Add(b);Box2D.Common.Math.b2Vec2.Free(b);b=a.dt*this.m_maxForce;this.m_linearImpulse.LengthSquared()>
b*b&&(this.m_linearImpulse.Normalize(),this.m_linearImpulse.Multiply(b));b=Box2D.Common.Math.b2Math.SubtractVV(this.m_linearImpulse,c);Box2D.Common.Math.b2Vec2.Free(c);f.x-=j*b.x;f.y-=j*b.y;g-=l*(m*b.y-o*b.x);h.x+=k*b.x;h.y+=k*b.y;i+=n*(p*b.y-q*b.x);Box2D.Common.Math.b2Vec2.Free(b);d.m_angularVelocity=g;e.m_angularVelocity=i};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SolvePositionConstraints=function(){return!0};Box2D.Dynamics.b2DestructionListener=function(){};Box2D.Dynamics.b2DestructionListener.prototype.SayGoodbyeJoint=function(){};Box2D.Dynamics.b2DestructionListener.prototype.SayGoodbyeFixture=function(){};Box2D.Dynamics.b2FilterData=function(){UsageTracker.get("Box2D.Dynamics.b2FilterData").trackCreate();this.categoryBits=1;this.maskBits=65535;this.groupIndex=0};Box2D.Dynamics.b2FilterData.prototype.Copy=function(){var a=new Box2D.Dynamics.b2FilterData;a.categoryBits=this.categoryBits;a.maskBits=this.maskBits;a.groupIndex=this.groupIndex;return a};Box2D.Dynamics.b2Fixture=function(a,b,c){UsageTracker.get("Box2D.Dynamics.b2Fixture").trackCreate();this.ID="Fixture"+Box2D.Dynamics.b2Fixture.NEXT_ID++;this.m_filter=c.filter.Copy();this.m_aabb=Box2D.Collision.b2AABB.Get();this.m_aabb_temp=Box2D.Collision.b2AABB.Get();this.m_body=a;this.m_shape=c.shape.Copy();this.m_density=c.density;this.m_friction=c.friction;this.m_restitution=c.restitution;this.m_isSensor=c.isSensor;this.m_proxy=null};Box2D.Dynamics.b2Fixture.prototype.GetShape=function(){return this.m_shape};
Box2D.Dynamics.b2Fixture.prototype.SetSensor=function(a){if(this.m_isSensor!=a&&(this.m_isSensor=a,this.m_body!=null)){var b=this;this.m_body.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){var d=a.GetFixtureA(),e=a.GetFixtureB();if(d==b||e==b)a.SetSensor(d.IsSensor()||e.IsSensor())})}};Box2D.Dynamics.b2Fixture.prototype.IsSensor=function(){return this.m_isSensor};
Box2D.Dynamics.b2Fixture.prototype.SetFilterData=function(a){this.m_filter=a.Copy();if(this.m_body!=null){var b=this;this.m_body.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){(a.GetFixtureA()==b||a.GetFixtureB()==b)&&a.FlagForFiltering()})}};Box2D.Dynamics.b2Fixture.prototype.GetFilterData=function(){return this.m_filter};Box2D.Dynamics.b2Fixture.prototype.GetBody=function(){return this.m_body};
Box2D.Dynamics.b2Fixture.prototype.TestPoint=function(a){return this.m_shape.TestPoint(this.m_body.GetTransform(),a)};Box2D.Dynamics.b2Fixture.prototype.RayCast=function(a,b){return this.m_shape.RayCast(a,b,this.m_body.GetTransform())};Box2D.Dynamics.b2Fixture.prototype.GetMassData=function(a){a||(a=Box2D.Collision.Shapes.b2MassData.Get());this.m_shape.ComputeMass(a,this.m_density);return a};Box2D.Dynamics.b2Fixture.prototype.SetDensity=function(a){this.m_density=a};
Box2D.Dynamics.b2Fixture.prototype.GetDensity=function(){return this.m_density};Box2D.Dynamics.b2Fixture.prototype.GetFriction=function(){return this.m_friction};Box2D.Dynamics.b2Fixture.prototype.SetFriction=function(a){this.m_friction=a};Box2D.Dynamics.b2Fixture.prototype.GetRestitution=function(){return this.m_restitution};Box2D.Dynamics.b2Fixture.prototype.SetRestitution=function(a){this.m_restitution=a};Box2D.Dynamics.b2Fixture.prototype.GetAABB=function(){return this.m_aabb};
Box2D.Dynamics.b2Fixture.prototype.Destroy=function(){Box2D.Collision.b2AABB.Free(this.m_aabb)};Box2D.Dynamics.b2Fixture.prototype.CreateProxy=function(a,b){this.m_shape.ComputeAABB(this.m_aabb,b);this.m_proxy=a.CreateProxy(this.m_aabb,this)};Box2D.Dynamics.b2Fixture.prototype.DestroyProxy=function(a){if(this.m_proxy!=null)a.DestroyProxy(this.m_proxy),this.m_proxy=null};
Box2D.Dynamics.b2Fixture.prototype.Synchronize=function(a,b,c){this.m_proxy&&(this.m_shape.ComputeAABB(this.m_aabb,b),this.m_shape.ComputeAABB(this.m_aabb_temp,c),this.m_aabb.Combine(this.m_aabb,this.m_aabb_temp),b=Box2D.Common.Math.b2Math.SubtractVV(c.position,b.position),a.MoveProxy(this.m_proxy,this.m_aabb,b),Box2D.Common.Math.b2Vec2.Free(b))};Box2D.Dynamics.b2Fixture.NEXT_ID=0;Box2D.Dynamics.iContactListener=function(){};Box2D.Dynamics.iContactListener.prototype.BeginContact=function(){};Box2D.Dynamics.iContactListener.prototype.EndContact=function(){};Box2D.Dynamics.iContactListener.prototype.PreSolve=function(){};Box2D.Dynamics.iContactListener.prototype.PostSolve=function(){};Box2D.Dynamics.Contacts.b2CircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};goog.inherits(Box2D.Dynamics.Contacts.b2CircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2CircleContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};
Box2D.Dynamics.Contacts.b2CircleContact.prototype.Evaluate=function(){var a=this.m_fixtureA.GetShape(),b=this.m_fixtureB.GetShape();Box2D.Collision.b2Collision.CollideCircles(this.m_manifold,a,this.m_fixtureA.GetBody().GetTransform(),b,this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};goog.inherits(Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};
Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.Evaluate=function(){this.m_fixtureA.GetBody();this.m_fixtureB.GetBody();this.b2CollideEdgeAndCircle(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().GetTransform(),this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.b2CollideEdgeAndCircle=function(){};Box2D.Dynamics.Joints.b2FrictionJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_frictionJoint;this.maxTorque=this.maxForce=0};goog.inherits(Box2D.Dynamics.Joints.b2FrictionJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2FrictionJointDef.prototype.Initialize=function(a,b,c){this.bodyA=a;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c))};Box2D.Dynamics.Joints.b2FrictionJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2FrictionJoint(this)};Box2D.Dynamics.Joints.b2RevoluteJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.K=Box2D.Common.Math.b2Mat22.Get();this.K1=Box2D.Common.Math.b2Mat22.Get();this.K2=Box2D.Common.Math.b2Mat22.Get();this.K3=Box2D.Common.Math.b2Mat22.Get();this.impulse3=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.impulse2=Box2D.Common.Math.b2Vec2.Get(0,0);this.reduced=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,
0);this.m_impulse=Box2D.Common.Math.b2Vec3.Get(0,0,0);this.m_mass=new Box2D.Common.Math.b2Mat33;this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=0;this.m_lowerAngle=a.lowerAngle;this.m_upperAngle=a.upperAngle;this.m_maxMotorTorque=a.maxMotorTorque;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;
this.m_motorMass=0};goog.inherits(Box2D.Dynamics.Joints.b2RevoluteJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);return a*this.m_impulse.z};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetJointAngle=function(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a-this.m_referenceAngle};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetJointSpeed=function(){return this.m_bodyB.m_angularVelocity-this.m_bodyA.m_angularVelocity};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.EnableLimit=function(a){this.m_enableLimit=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetLowerLimit=function(){return this.m_lowerAngle};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetUpperLimit=function(){return this.m_upperAngle};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetLimits=function(a,b){a===void 0&&(a=0);b===void 0&&(b=0);this.m_lowerAngle=a;this.m_upperAngle=b};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.IsMotorEnabled=function(){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);return this.m_enableMotor};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.EnableMotor=function(a){this.m_enableMotor=a};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetMotorSpeed=function(a){a===void 0&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetMaxMotorTorque=function(a){a===void 0&&(a=0);this.m_maxMotorTorque=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetMotorTorque=function(){return this.m_maxMotorTorque};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d,e=0;d=b.m_xf.R;var f=this.m_localAnchor1.x-b.m_sweep.localCenter.x,g=this.m_localAnchor1.y-b.m_sweep.localCenter.y,e=d.col1.x*f+d.col2.x*g,g=d.col1.y*f+d.col2.y*g,f=e;d=c.m_xf.R;var h=this.m_localAnchor2.x-c.m_sweep.localCenter.x,i=this.m_localAnchor2.y-c.m_sweep.localCenter.y,e=d.col1.x*h+d.col2.x*i,i=d.col1.y*h+d.col2.y*i,h=e;d=b.m_invMass;var e=c.m_invMass,j=b.m_invI,k=c.m_invI;
this.m_mass.col1.x=d+e+g*g*j+i*i*k;this.m_mass.col2.x=-g*f*j-i*h*k;this.m_mass.col3.x=-g*j-i*k;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=d+e+f*f*j+h*h*k;this.m_mass.col3.y=f*j+h*k;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=j+k;this.m_motorMass=j+k==0?0:1/(j+k);if(!this.m_enableMotor)this.m_motorImpulse=0;if(this.m_enableLimit){var l=c.m_sweep.a-b.m_sweep.a-this.m_referenceAngle;if(Math.abs(this.m_upperAngle-this.m_lowerAngle)<2*Box2D.Common.b2Settings.b2_angularSlop)this.m_limitState=
Box2D.Dynamics.Joints.b2Joint.e_equalLimits;else if(l<=this.m_lowerAngle){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit)this.m_impulse.z=0;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit}else if(l>=this.m_upperAngle){if(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)this.m_impulse.z=0;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit}else this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse.z=0}else this.m_limitState=
Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x,l=this.m_impulse.y,b.m_linearVelocity.x-=d*a,b.m_linearVelocity.y-=d*l,b.m_angularVelocity-=j*(f*l-g*a+this.m_motorImpulse+this.m_impulse.z),c.m_linearVelocity.x+=e*a,c.m_linearVelocity.y+=e*l,c.m_angularVelocity+=k*(h*l-i*a+this.m_motorImpulse+this.m_impulse.z)):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolveVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d=0,e=d=0,f=0,g=0,h=0,i=b.m_linearVelocity,j=b.m_angularVelocity,k=c.m_linearVelocity,l=c.m_angularVelocity,n=b.m_invMass,m=c.m_invMass,o=b.m_invI,p=c.m_invI;if(this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits)e=this.m_motorMass*-(l-j-this.m_motorSpeed),f=this.m_motorImpulse,g=a.dt*this.m_maxMotorTorque,this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+
e,-g,g),e=this.m_motorImpulse-f,j-=o*e,l+=p*e;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){var a=b.m_xf.R,e=this.m_localAnchor1.x-b.m_sweep.localCenter.x,f=this.m_localAnchor1.y-b.m_sweep.localCenter.y,d=a.col1.x*e+a.col2.x*f,f=a.col1.y*e+a.col2.y*f,e=d,a=c.m_xf.R,g=this.m_localAnchor2.x-c.m_sweep.localCenter.x,h=this.m_localAnchor2.y-c.m_sweep.localCenter.y,d=a.col1.x*g+a.col2.x*h,h=a.col1.y*g+a.col2.y*h,g=d,a=k.x+-l*h-i.x- -j*f,q=k.y+l*g-i.y-j*e;this.m_mass.Solve33(this.impulse3,
-a,-q,-(l-j));if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_equalLimits)this.m_impulse.Add(this.impulse3);else if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit){if(d=this.m_impulse.z+this.impulse3.z,d<0)this.m_mass.Solve22(this.reduced,-a,-q),this.impulse3.x=this.reduced.x,this.impulse3.y=this.reduced.y,this.impulse3.z=-this.m_impulse.z,this.m_impulse.x+=this.reduced.x,this.m_impulse.y+=this.reduced.y,this.m_impulse.z=0}else if(this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&
(d=this.m_impulse.z+this.impulse3.z,d>0))this.m_mass.Solve22(this.reduced,-a,-q),this.impulse3.x=this.reduced.x,this.impulse3.y=this.reduced.y,this.impulse3.z=-this.m_impulse.z,this.m_impulse.x+=this.reduced.x,this.m_impulse.y+=this.reduced.y,this.m_impulse.z=0;i.x-=n*this.impulse3.x;i.y-=n*this.impulse3.y;j-=o*(e*this.impulse3.y-f*this.impulse3.x+this.impulse3.z);k.x+=m*this.impulse3.x;k.y+=m*this.impulse3.y;l+=p*(g*this.impulse3.y-h*this.impulse3.x+this.impulse3.z)}else a=b.m_xf.R,e=this.m_localAnchor1.x-
b.m_sweep.localCenter.x,f=this.m_localAnchor1.y-b.m_sweep.localCenter.y,d=a.col1.x*e+a.col2.x*f,f=a.col1.y*e+a.col2.y*f,e=d,a=c.m_xf.R,g=this.m_localAnchor2.x-c.m_sweep.localCenter.x,h=this.m_localAnchor2.y-c.m_sweep.localCenter.y,d=a.col1.x*g+a.col2.x*h,h=a.col1.y*g+a.col2.y*h,g=d,this.m_mass.Solve22(this.impulse2,-(k.x+-l*h-i.x- -j*f),-(k.y+l*g-i.y-j*e)),this.m_impulse.x+=this.impulse2.x,this.m_impulse.y+=this.impulse2.y,i.x-=n*this.impulse2.x,i.y-=n*this.impulse2.y,j-=o*(e*this.impulse2.y-f*this.impulse2.x),
k.x+=m*this.impulse2.x,k.y+=m*this.impulse2.y,l+=p*(g*this.impulse2.y-h*this.impulse2.x);b.m_linearVelocity.SetV(i);b.m_angularVelocity=j;c.m_linearVelocity.SetV(k);c.m_angularVelocity=l};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolvePositionConstraints=function(){var a=0,b,c=this.m_bodyA,d=this.m_bodyB,e=0,f=b=0,g=0,h=0;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){var a=d.m_sweep.a-c.m_sweep.a-this.m_referenceAngle,i=0;this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_equalLimits?(a=Box2D.Common.Math.b2Math.Clamp(a-this.m_lowerAngle,-Box2D.Common.b2Settings.b2_maxAngularCorrection,Box2D.Common.b2Settings.b2_maxAngularCorrection),
i=-this.m_motorMass*a,e=Math.abs(a)):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit?(a-=this.m_lowerAngle,e=-a,a=Box2D.Common.Math.b2Math.Clamp(a+Box2D.Common.b2Settings.b2_angularSlop,-Box2D.Common.b2Settings.b2_maxAngularCorrection,0),i=-this.m_motorMass*a):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(a-=this.m_upperAngle,e=a,a=Box2D.Common.Math.b2Math.Clamp(a-Box2D.Common.b2Settings.b2_angularSlop,0,Box2D.Common.b2Settings.b2_maxAngularCorrection),i=-this.m_motorMass*
a);c.m_sweep.a-=c.m_invI*i;d.m_sweep.a+=d.m_invI*i;c.SynchronizeTransform();d.SynchronizeTransform()}b=c.m_xf.R;i=this.m_localAnchor1.x-c.m_sweep.localCenter.x;a=this.m_localAnchor1.y-c.m_sweep.localCenter.y;f=b.col1.x*i+b.col2.x*a;a=b.col1.y*i+b.col2.y*a;i=f;b=d.m_xf.R;var j=this.m_localAnchor2.x-d.m_sweep.localCenter.x,k=this.m_localAnchor2.y-d.m_sweep.localCenter.y,f=b.col1.x*j+b.col2.x*k,k=b.col1.y*j+b.col2.y*k,j=f,g=d.m_sweep.c.x+j-c.m_sweep.c.x-i,h=d.m_sweep.c.y+k-c.m_sweep.c.y-a,l=g*g+h*h;
b=Math.sqrt(l);var f=c.m_invMass,n=d.m_invMass,m=c.m_invI,o=d.m_invI,p=10*Box2D.Common.b2Settings.b2_linearSlop;l>p*p&&(l=1/(f+n),g=l*-g,h=l*-h,c.m_sweep.c.x-=0.5*f*g,c.m_sweep.c.y-=0.5*f*h,d.m_sweep.c.x+=0.5*n*g,d.m_sweep.c.y+=0.5*n*h,g=d.m_sweep.c.x+j-c.m_sweep.c.x-i,h=d.m_sweep.c.y+k-c.m_sweep.c.y-a);this.K1.col1.x=f+n;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=f+n;this.K2.col1.x=m*a*a;this.K2.col2.x=-m*i*a;this.K2.col1.y=-m*i*a;this.K2.col2.y=m*i*i;this.K3.col1.x=o*k*k;this.K3.col2.x=-o*
j*k;this.K3.col1.y=-o*j*k;this.K3.col2.y=o*j*j;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Solve(Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse,-g,-h);g=Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse.x;h=Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse.y;c.m_sweep.c.x-=c.m_invMass*g;c.m_sweep.c.y-=c.m_invMass*h;c.m_sweep.a-=c.m_invI*(i*h-a*g);d.m_sweep.c.x+=d.m_invMass*g;d.m_sweep.c.y+=d.m_invMass*h;d.m_sweep.a+=d.m_invI*(j*h-k*g);c.SynchronizeTransform();d.SynchronizeTransform();
return b<=Box2D.Common.b2Settings.b2_linearSlop&&e<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Dynamics.Joints.b2RevoluteJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint;this.localAnchorA.SetZero();this.localAnchorB.SetZero();this.motorSpeed=this.maxMotorTorque=this.upperAngle=this.lowerAngle=this.referenceAngle=0;this.enableMotor=this.enableLimit=!1};goog.inherits(Box2D.Dynamics.Joints.b2RevoluteJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2RevoluteJointDef.prototype.Initialize=function(a,b,c){this.bodyA=a;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(c);this.localAnchorB=this.bodyB.GetLocalPoint(c);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2RevoluteJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2RevoluteJoint(this)};Box2D.Dynamics.Contacts.b2PositionSolverManifold=function(){this.m_normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_separations=[];this.m_points=[];for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a]=Box2D.Common.Math.b2Vec2.Get(0,0)};
Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype.Initialize=function(a){Box2D.Common.b2Settings.b2Assert(a.pointCount>0);switch(a.type){case Box2D.Collision.b2Manifold.e_circles:this._InitializeCircles(a);break;case Box2D.Collision.b2Manifold.e_faceA:this._InitializeFaceA(a);break;case Box2D.Collision.b2Manifold.e_faceB:this._InitializeFaceB(a)}};
Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeCircles=function(a){var b=a.bodyA.m_xf.R,c=a.localPoint,d=a.bodyA.m_xf.position.x+(b.col1.x*c.x+b.col2.x*c.y),e=a.bodyA.m_xf.position.y+(b.col1.y*c.x+b.col2.y*c.y),b=a.bodyB.m_xf.R,c=a.points[0].localPoint,f=a.bodyB.m_xf.position.x+(b.col1.x*c.x+b.col2.x*c.y),b=a.bodyB.m_xf.position.y+(b.col1.y*c.x+b.col2.y*c.y),c=f-d,g=b-e,h=c*c+g*g;h>Box2D.Common.b2Settings.MIN_VALUE_SQUARED?(h=Math.sqrt(h),this.m_normal.x=c/h,this.m_normal.y=
g/h):(this.m_normal.x=1,this.m_normal.y=0);this.m_points[0].x=0.5*(d+f);this.m_points[0].y=0.5*(e+b);this.m_separations[0]=c*this.m_normal.x+g*this.m_normal.y-a.radius};
Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeFaceA=function(a){this.m_normal.x=a.bodyA.m_xf.R.col1.x*a.localPlaneNormal.x+a.bodyA.m_xf.R.col2.x*a.localPlaneNormal.y;this.m_normal.y=a.bodyA.m_xf.R.col1.y*a.localPlaneNormal.x+a.bodyA.m_xf.R.col2.y*a.localPlaneNormal.y;for(var b=a.bodyA.m_xf.position.x+(a.bodyA.m_xf.R.col1.x*a.localPoint.x+a.bodyA.m_xf.R.col2.x*a.localPoint.y),c=a.bodyA.m_xf.position.y+(a.bodyA.m_xf.R.col1.y*a.localPoint.x+a.bodyA.m_xf.R.col2.y*a.localPoint.y),
d=0;d<a.pointCount;d++){var e=a.bodyB.m_xf.position.x+(a.bodyB.m_xf.R.col1.x*a.points[d].localPoint.x+a.bodyB.m_xf.R.col2.x*a.points[d].localPoint.y),f=a.bodyB.m_xf.position.y+(a.bodyB.m_xf.R.col1.y*a.points[d].localPoint.x+a.bodyB.m_xf.R.col2.y*a.points[d].localPoint.y);this.m_separations[d]=(e-b)*this.m_normal.x+(f-c)*this.m_normal.y-a.radius;this.m_points[d].x=e;this.m_points[d].y=f}};
Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeFaceB=function(a){this.m_normal.x=a.bodyB.m_xf.R.col1.x*a.localPlaneNormal.x+a.bodyB.m_xf.R.col2.x*a.localPlaneNormal.y;this.m_normal.y=a.bodyB.m_xf.R.col1.y*a.localPlaneNormal.x+a.bodyB.m_xf.R.col2.y*a.localPlaneNormal.y;for(var b=a.bodyB.m_xf.position.x+(a.bodyB.m_xf.R.col1.x*a.localPoint.x+a.bodyB.m_xf.R.col2.x*a.localPoint.y),c=a.bodyB.m_xf.position.y+(a.bodyB.m_xf.R.col1.y*a.localPoint.x+a.bodyB.m_xf.R.col2.y*a.localPoint.y),
d=0;d<a.pointCount;d++){var e=a.bodyA.m_xf.position.x+(a.bodyA.m_xf.R.col1.x*a.points[d].localPoint.x+a.bodyA.m_xf.R.col2.x*a.points[d].localPoint.y),f=a.bodyA.m_xf.position.y+(a.bodyA.m_xf.R.col1.y*a.points[d].localPoint.x+a.bodyA.m_xf.R.col2.y*a.points[d].localPoint.y);this.m_separations[d]=(e-b)*this.m_normal.x+(f-c)*this.m_normal.y-a.radius;this.m_points[d].Set(e,f)}this.m_normal.x*=-1;this.m_normal.y*=-1};Box2D.Dynamics.Contacts.b2PolyAndCircleContact=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape()instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape()instanceof Box2D.Collision.Shapes.b2CircleShape);Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};goog.inherits(Box2D.Dynamics.Contacts.b2PolyAndCircleContact,Box2D.Dynamics.Contacts.b2Contact);
Box2D.Dynamics.Contacts.b2PolyAndCircleContact.prototype.Reset=function(a,b){Box2D.Common.b2Settings.b2Assert(a.GetShape()instanceof Box2D.Collision.Shapes.b2PolygonShape);Box2D.Common.b2Settings.b2Assert(b.GetShape()instanceof Box2D.Collision.Shapes.b2CircleShape);Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};
Box2D.Dynamics.Contacts.b2PolyAndCircleContact.prototype.Evaluate=function(){var a=this.m_fixtureA.GetShape(),b=this.m_fixtureB.GetShape();Box2D.Collision.b2Collision.CollidePolygonAndCircle(this.m_manifold,a,this.m_fixtureA.GetBody().GetTransform(),b,this.m_fixtureB.GetBody().GetTransform())};Box2D.Dynamics.Contacts.b2ContactConstraintPoint=function(){UsageTracker.get("Box2D.Dynamics.Contacts.b2ContactConstraintPoint").trackCreate();this.localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.rA=Box2D.Common.Math.b2Vec2.Get(0,0);this.rB=Box2D.Common.Math.b2Vec2.Get(0,0);this.tangentImpulse=this.normalImpulse=0};Box2D.Dynamics.Contacts.b2ContactConstraintPoint.prototype.Reset=function(){this.localPoint.Set(0,0);this.rA.Set(0,0);this.rB.Set(0,0);this.tangentImpulse=this.normalImpulse=0};Box2D.Dynamics.Contacts.b2ContactConstraint=function(){UsageTracker.get("Box2D.Dynamics.Contacts.b2ContactConstraint").trackCreate();this.localPlaneNormal=Box2D.Common.Math.b2Vec2.Get(0,0);this.localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.normalMass=Box2D.Common.Math.b2Mat22.Get();this.K=Box2D.Common.Math.b2Mat22.Get();this.points=[];for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.points[a]=new Box2D.Dynamics.Contacts.b2ContactConstraintPoint};Box2D.Dynamics.b2FixtureList=function(){UsageTracker.get("Box2D.Dynamics.b2FixtureList").trackCreate();this.fixtureLastNode=this.fixtureFirstNode=null;this.fixtureNodeLookup={};this.fixtureCount=0};Box2D.Dynamics.b2FixtureList.prototype.GetFirstNode=function(){return this.fixtureFirstNode};
Box2D.Dynamics.b2FixtureList.prototype.AddFixture=function(a){var b=a.ID;if(this.fixtureNodeLookup[b]==null){var a=new Box2D.Dynamics.b2FixtureListNode(a),c=this.fixtureLastNode;c!=null?c.SetNextNode(a):this.fixtureFirstNode=a;a.SetPreviousNode(c);this.fixtureLastNode=a;this.fixtureNodeLookup[b]=a;this.fixtureCount++}};
Box2D.Dynamics.b2FixtureList.prototype.RemoveFixture=function(a){var a=a.ID,b=this.fixtureNodeLookup[a];if(b!=null){var c=b.GetPreviousNode(),b=b.GetNextNode();c==null?this.fixtureFirstNode=b:c.SetNextNode(b);b==null?this.fixtureLastNode=c:b.SetPreviousNode(c);delete this.fixtureNodeLookup[a];this.fixtureCount--}};Box2D.Dynamics.b2FixtureList.prototype.GetFixtureCount=function(){return this.fixtureCount};Box2D.Dynamics.Joints.b2Jacobian=function(){this.linearA=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearB=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Dynamics.Joints.b2Jacobian.prototype.SetZero=function(){this.linearA.SetZero();this.angularA=0;this.linearB.SetZero();this.angularB=0};Box2D.Dynamics.Joints.b2Jacobian.prototype.Set=function(a,b,c,d){b===void 0&&(b=0);d===void 0&&(d=0);this.linearA.SetV(a);this.angularA=b;this.linearB.SetV(c);this.angularB=d};
Box2D.Dynamics.Joints.b2Jacobian.prototype.Compute=function(a,b,c,d){b===void 0&&(b=0);d===void 0&&(d=0);return this.linearA.x*a.x+this.linearA.y*a.y+this.angularA*b+(this.linearB.x*c.x+this.linearB.y*c.y)+this.angularB*d};Box2D.Dynamics.Joints.b2GearJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_groundAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_groundAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_J=new Box2D.Dynamics.Joints.b2Jacobian;var b=a.joint1.m_type,c=a.joint2.m_type;this.m_prismatic2=this.m_revolute2=this.m_prismatic1=this.m_revolute1=null;var d=0,e=0;this.m_ground1=a.joint1.GetBodyA();
this.m_bodyA=a.joint1.GetBodyB();b==Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint?(this.m_revolute1=a.joint1,this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2),d=this.m_revolute1.GetJointAngle()):(this.m_prismatic1=a.joint1,this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2),d=this.m_prismatic1.GetJointTranslation());this.m_ground2=a.joint2.GetBodyA();this.m_bodyB=a.joint2.GetBodyB();
c==Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint?(this.m_revolute2=a.joint2,this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2),e=this.m_revolute2.GetJointAngle()):(this.m_prismatic2=a.joint2,this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2),e=this.m_prismatic2.GetJointTranslation());this.m_ratio=a.ratio;this.m_constant=d+this.m_ratio*e;this.m_impulse=0};
goog.inherits(Box2D.Dynamics.Joints.b2GearJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2GearJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};
Box2D.Dynamics.Joints.b2GearJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_J.linearB.x,a*this.m_impulse*this.m_J.linearB.y)};
Box2D.Dynamics.Joints.b2GearJoint.prototype.GetReactionTorque=function(a){a===void 0&&(a=0);var b=this.m_bodyB.m_xf.R,c=this.m_localAnchor1.x-this.m_bodyB.m_sweep.localCenter.x,d=this.m_localAnchor1.y-this.m_bodyB.m_sweep.localCenter.y,e=b.col1.x*c+b.col2.x*d,d=b.col1.y*c+b.col2.y*d;return a*(this.m_impulse*this.m_J.angularB-e*this.m_impulse*this.m_J.linearB.y+d*this.m_impulse*this.m_J.linearB.x)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetRatio=function(){return this.m_ratio};
Box2D.Dynamics.Joints.b2GearJoint.prototype.SetRatio=function(a){a===void 0&&(a=0);this.m_ratio=a};
Box2D.Dynamics.Joints.b2GearJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_ground1,c=this.m_ground2,d=this.m_bodyA,e=this.m_bodyB,f=0,g=0,h=0,i=0,j=h=0,k=0;this.m_J.SetZero();this.m_revolute1?(this.m_J.angularA=-1,k+=d.m_invI):(b=b.m_xf.R,g=this.m_prismatic1.m_localXAxis1,f=b.col1.x*g.x+b.col2.x*g.y,g=b.col1.y*g.x+b.col2.y*g.y,b=d.m_xf.R,h=this.m_localAnchor1.x-d.m_sweep.localCenter.x,i=this.m_localAnchor1.y-d.m_sweep.localCenter.y,j=b.col1.x*h+b.col2.x*i,i=b.col1.y*h+b.col2.y*i,
h=j*g-i*f,this.m_J.linearA.Set(-f,-g),this.m_J.angularA=-h,k+=d.m_invMass+d.m_invI*h*h);this.m_revolute2?(this.m_J.angularB=-this.m_ratio,k+=this.m_ratio*this.m_ratio*e.m_invI):(b=c.m_xf.R,g=this.m_prismatic2.m_localXAxis1,f=b.col1.x*g.x+b.col2.x*g.y,g=b.col1.y*g.x+b.col2.y*g.y,b=e.m_xf.R,h=this.m_localAnchor2.x-e.m_sweep.localCenter.x,i=this.m_localAnchor2.y-e.m_sweep.localCenter.y,j=b.col1.x*h+b.col2.x*i,i=b.col1.y*h+b.col2.y*i,h=j*g-i*f,this.m_J.linearB.Set(-this.m_ratio*f,-this.m_ratio*g),this.m_J.angularB=
-this.m_ratio*h,k+=this.m_ratio*this.m_ratio*(e.m_invMass+e.m_invI*h*h));this.m_mass=k>0?1/k:0;a.warmStarting?(d.m_linearVelocity.x+=d.m_invMass*this.m_impulse*this.m_J.linearA.x,d.m_linearVelocity.y+=d.m_invMass*this.m_impulse*this.m_J.linearA.y,d.m_angularVelocity+=d.m_invI*this.m_impulse*this.m_J.angularA,e.m_linearVelocity.x+=e.m_invMass*this.m_impulse*this.m_J.linearB.x,e.m_linearVelocity.y+=e.m_invMass*this.m_impulse*this.m_J.linearB.y,e.m_angularVelocity+=e.m_invI*this.m_impulse*this.m_J.angularB):
this.m_impulse=0};
Box2D.Dynamics.Joints.b2GearJoint.prototype.SolveVelocityConstraints=function(){var a=this.m_bodyA,b=this.m_bodyB,c=-this.m_mass*this.m_J.Compute(a.m_linearVelocity,a.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity);this.m_impulse+=c;a.m_linearVelocity.x+=a.m_invMass*c*this.m_J.linearA.x;a.m_linearVelocity.y+=a.m_invMass*c*this.m_J.linearA.y;a.m_angularVelocity+=a.m_invI*c*this.m_J.angularA;b.m_linearVelocity.x+=b.m_invMass*c*this.m_J.linearB.x;b.m_linearVelocity.y+=b.m_invMass*c*this.m_J.linearB.y;
b.m_angularVelocity+=b.m_invI*c*this.m_J.angularB};
Box2D.Dynamics.Joints.b2GearJoint.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,b=this.m_bodyB,c=0,d=0,c=this.m_revolute1?this.m_revolute1.GetJointAngle():this.m_prismatic1.GetJointTranslation(),d=this.m_revolute2?this.m_revolute2.GetJointAngle():this.m_prismatic2.GetJointTranslation(),c=-this.m_mass*(this.m_constant-(c+this.m_ratio*d));a.m_sweep.c.x+=a.m_invMass*c*this.m_J.linearA.x;a.m_sweep.c.y+=a.m_invMass*c*this.m_J.linearA.y;a.m_sweep.a+=a.m_invI*c*this.m_J.angularA;b.m_sweep.c.x+=
b.m_invMass*c*this.m_J.linearB.x;b.m_sweep.c.y+=b.m_invMass*c*this.m_J.linearB.y;b.m_sweep.a+=b.m_invI*c*this.m_J.angularB;a.SynchronizeTransform();b.SynchronizeTransform();return 0<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2GearJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.type=Box2D.Dynamics.Joints.b2Joint.e_gearJoint;this.joint2=this.joint1=null;this.ratio=1};goog.inherits(Box2D.Dynamics.Joints.b2GearJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2GearJointDef.prototype.Initialize=function(a,b,c){this.joint1=a;this.bodyA=a.GetBodyA();this.joint2=b;this.bodyB=b.GetBodyA();this.ratio=c};Box2D.Dynamics.Joints.b2GearJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2GearJoint(this)};Box2D.Dynamics.Joints.b2PulleyJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_groundAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_groundAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_ground=this.m_bodyA.m_world.m_groundBody;this.m_groundAnchor1.x=a.groundAnchorA.x-this.m_ground.m_xf.position.x;
this.m_groundAnchor1.y=a.groundAnchorA.y-this.m_ground.m_xf.position.y;this.m_groundAnchor2.x=a.groundAnchorB.x-this.m_ground.m_xf.position.x;this.m_groundAnchor2.y=a.groundAnchorB.y-this.m_ground.m_xf.position.y;this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_ratio=a.ratio;this.m_constant=a.lengthA+this.m_ratio*a.lengthB;this.m_maxLength1=Math.min(a.maxLengthA,this.m_constant-this.m_ratio*Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength);this.m_maxLength2=
Math.min(a.maxLengthB,(this.m_constant-Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength)/this.m_ratio);this.m_limitImpulse2=this.m_limitImpulse1=this.m_impulse=0};goog.inherits(Box2D.Dynamics.Joints.b2PulleyJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};
Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_u2.x,a*this.m_impulse*this.m_u2.y)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetReactionTorque=function(){return 0};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetGroundAnchorA=function(){var a=this.m_ground.m_xf.position.Copy();a.Add(this.m_groundAnchor1);return a};
Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetGroundAnchorB=function(){var a=this.m_ground.m_xf.position.Copy();a.Add(this.m_groundAnchor2);return a};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetLength1=function(){var a=this.m_bodyA.GetWorldPoint(this.m_localAnchor1),b=a.x-(this.m_ground.m_xf.position.x+this.m_groundAnchor1.x),a=a.y-(this.m_ground.m_xf.position.y+this.m_groundAnchor1.y);return Math.sqrt(b*b+a*a)};
Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetLength2=function(){var a=this.m_bodyB.GetWorldPoint(this.m_localAnchor2),b=a.x-(this.m_ground.m_xf.position.x+this.m_groundAnchor2.x),a=a.y-(this.m_ground.m_xf.position.y+this.m_groundAnchor2.y);return Math.sqrt(b*b+a*a)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetRatio=function(){return this.m_ratio};
Box2D.Dynamics.Joints.b2PulleyJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d;d=b.m_xf.R;var e=this.m_localAnchor1.x-b.m_sweep.localCenter.x,f=this.m_localAnchor1.y-b.m_sweep.localCenter.y,g=d.col1.x*e+d.col2.x*f,f=d.col1.y*e+d.col2.y*f,e=g;d=c.m_xf.R;var h=this.m_localAnchor2.x-c.m_sweep.localCenter.x,i=this.m_localAnchor2.y-c.m_sweep.localCenter.y,g=d.col1.x*h+d.col2.x*i,i=d.col1.y*h+d.col2.y*i,h=g;d=c.m_sweep.c.x+h;var g=c.m_sweep.c.y+i,j=this.m_ground.m_xf.position.x+
this.m_groundAnchor2.x,k=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;this.m_u1.Set(b.m_sweep.c.x+e-(this.m_ground.m_xf.position.x+this.m_groundAnchor1.x),b.m_sweep.c.y+f-(this.m_ground.m_xf.position.y+this.m_groundAnchor1.y));this.m_u2.Set(d-j,g-k);d=this.m_u1.Length();g=this.m_u2.Length();d>Box2D.Common.b2Settings.b2_linearSlop?this.m_u1.Multiply(1/d):this.m_u1.SetZero();g>Box2D.Common.b2Settings.b2_linearSlop?this.m_u2.Multiply(1/g):this.m_u2.SetZero();this.m_constant-d-this.m_ratio*g>
0?(this.m_state=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse=0):this.m_state=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;d<this.m_maxLength1?(this.m_limitState1=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_limitImpulse1=0):this.m_limitState1=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;g<this.m_maxLength2?(this.m_limitState2=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_limitImpulse2=0):this.m_limitState2=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;d=e*this.m_u1.y-
f*this.m_u1.x;g=h*this.m_u2.y-i*this.m_u2.x;this.m_limitMass1=b.m_invMass+b.m_invI*d*d;this.m_limitMass2=c.m_invMass+c.m_invI*g*g;this.m_pulleyMass=this.m_limitMass1+this.m_ratio*this.m_ratio*this.m_limitMass2;this.m_limitMass1=1/this.m_limitMass1;this.m_limitMass2=1/this.m_limitMass2;this.m_pulleyMass=1/this.m_pulleyMass;a.warmStarting?(this.m_impulse*=a.dtRatio,this.m_limitImpulse1*=a.dtRatio,this.m_limitImpulse2*=a.dtRatio,a=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.x,d=(-this.m_impulse-
this.m_limitImpulse1)*this.m_u1.y,g=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.x,j=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.y,b.m_linearVelocity.x+=b.m_invMass*a,b.m_linearVelocity.y+=b.m_invMass*d,b.m_angularVelocity+=b.m_invI*(e*d-f*a),c.m_linearVelocity.x+=c.m_invMass*g,c.m_linearVelocity.y+=c.m_invMass*j,c.m_angularVelocity+=c.m_invI*(h*j-i*g)):this.m_limitImpulse2=this.m_limitImpulse1=this.m_impulse=0};
Box2D.Dynamics.Joints.b2PulleyJoint.prototype.SolveVelocityConstraints=function(){var a=this.m_bodyA,b=this.m_bodyB,c;c=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,e=this.m_localAnchor1.y-a.m_sweep.localCenter.y,f=c.col1.x*d+c.col2.x*e,e=c.col1.y*d+c.col2.y*e,d=f;c=b.m_xf.R;var g=this.m_localAnchor2.x-b.m_sweep.localCenter.x,h=this.m_localAnchor2.y-b.m_sweep.localCenter.y,f=c.col1.x*g+c.col2.x*h,h=c.col1.y*g+c.col2.y*h,g=f,i=f=c=0,j=0;c=j=c=j=i=f=c=0;if(this.m_state==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)c=
a.m_linearVelocity.x+-a.m_angularVelocity*e,f=a.m_linearVelocity.y+a.m_angularVelocity*d,i=b.m_linearVelocity.x+-b.m_angularVelocity*h,j=b.m_linearVelocity.y+b.m_angularVelocity*g,c=-(this.m_u1.x*c+this.m_u1.y*f)-this.m_ratio*(this.m_u2.x*i+this.m_u2.y*j),j=this.m_pulleyMass*-c,c=this.m_impulse,this.m_impulse=Math.max(0,this.m_impulse+j),j=this.m_impulse-c,c=-j*this.m_u1.x,f=-j*this.m_u1.y,i=-this.m_ratio*j*this.m_u2.x,j=-this.m_ratio*j*this.m_u2.y,a.m_linearVelocity.x+=a.m_invMass*c,a.m_linearVelocity.y+=
a.m_invMass*f,a.m_angularVelocity+=a.m_invI*(d*f-e*c),b.m_linearVelocity.x+=b.m_invMass*i,b.m_linearVelocity.y+=b.m_invMass*j,b.m_angularVelocity+=b.m_invI*(g*j-h*i);if(this.m_limitState1==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)c=a.m_linearVelocity.x+-a.m_angularVelocity*e,f=a.m_linearVelocity.y+a.m_angularVelocity*d,c=-(this.m_u1.x*c+this.m_u1.y*f),j=-this.m_limitMass1*c,c=this.m_limitImpulse1,this.m_limitImpulse1=Math.max(0,this.m_limitImpulse1+j),j=this.m_limitImpulse1-c,c=-j*this.m_u1.x,
f=-j*this.m_u1.y,a.m_linearVelocity.x+=a.m_invMass*c,a.m_linearVelocity.y+=a.m_invMass*f,a.m_angularVelocity+=a.m_invI*(d*f-e*c);if(this.m_limitState2==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)i=b.m_linearVelocity.x+-b.m_angularVelocity*h,j=b.m_linearVelocity.y+b.m_angularVelocity*g,c=-(this.m_u2.x*i+this.m_u2.y*j),j=-this.m_limitMass2*c,c=this.m_limitImpulse2,this.m_limitImpulse2=Math.max(0,this.m_limitImpulse2+j),j=this.m_limitImpulse2-c,i=-j*this.m_u2.x,j=-j*this.m_u2.y,b.m_linearVelocity.x+=
b.m_invMass*i,b.m_linearVelocity.y+=b.m_invMass*j,b.m_angularVelocity+=b.m_invI*(g*j-h*i)};
Box2D.Dynamics.Joints.b2PulleyJoint.prototype.SolvePositionConstraints=function(){var a=this.m_bodyA,b=this.m_bodyB,c,d=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x,e=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y,f=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,g=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y,h=0,i=0,j=0,k=0,l=c=0,n=0,m=0,o=l=m=c=l=c=0;if(this.m_state==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)c=a.m_xf.R,h=this.m_localAnchor1.x-a.m_sweep.localCenter.x,
i=this.m_localAnchor1.y-a.m_sweep.localCenter.y,l=c.col1.x*h+c.col2.x*i,i=c.col1.y*h+c.col2.y*i,h=l,c=b.m_xf.R,j=this.m_localAnchor2.x-b.m_sweep.localCenter.x,k=this.m_localAnchor2.y-b.m_sweep.localCenter.y,l=c.col1.x*j+c.col2.x*k,k=c.col1.y*j+c.col2.y*k,j=l,c=a.m_sweep.c.x+h,l=a.m_sweep.c.y+i,n=b.m_sweep.c.x+j,m=b.m_sweep.c.y+k,this.m_u1.Set(c-d,l-e),this.m_u2.Set(n-f,m-g),c=this.m_u1.Length(),l=this.m_u2.Length(),c>Box2D.Common.b2Settings.b2_linearSlop?this.m_u1.Multiply(1/c):this.m_u1.SetZero(),
l>Box2D.Common.b2Settings.b2_linearSlop?this.m_u2.Multiply(1/l):this.m_u2.SetZero(),c=this.m_constant-c-this.m_ratio*l,o=Math.max(o,-c),c=Box2D.Common.Math.b2Math.Clamp(c+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),m=-this.m_pulleyMass*c,c=-m*this.m_u1.x,l=-m*this.m_u1.y,n=-this.m_ratio*m*this.m_u2.x,m=-this.m_ratio*m*this.m_u2.y,a.m_sweep.c.x+=a.m_invMass*c,a.m_sweep.c.y+=a.m_invMass*l,a.m_sweep.a+=a.m_invI*(h*l-i*c),b.m_sweep.c.x+=b.m_invMass*n,b.m_sweep.c.y+=
b.m_invMass*m,b.m_sweep.a+=b.m_invI*(j*m-k*n),a.SynchronizeTransform(),b.SynchronizeTransform();if(this.m_limitState1==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)c=a.m_xf.R,h=this.m_localAnchor1.x-a.m_sweep.localCenter.x,i=this.m_localAnchor1.y-a.m_sweep.localCenter.y,l=c.col1.x*h+c.col2.x*i,i=c.col1.y*h+c.col2.y*i,h=l,c=a.m_sweep.c.x+h,l=a.m_sweep.c.y+i,this.m_u1.Set(c-d,l-e),c=this.m_u1.Length(),c>Box2D.Common.b2Settings.b2_linearSlop?(this.m_u1.x*=1/c,this.m_u1.y*=1/c):this.m_u1.SetZero(),c=
this.m_maxLength1-c,o=Math.max(o,-c),c=Box2D.Common.Math.b2Math.Clamp(c+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),m=-this.m_limitMass1*c,c=-m*this.m_u1.x,l=-m*this.m_u1.y,a.m_sweep.c.x+=a.m_invMass*c,a.m_sweep.c.y+=a.m_invMass*l,a.m_sweep.a+=a.m_invI*(h*l-i*c),a.SynchronizeTransform();if(this.m_limitState2==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit)c=b.m_xf.R,j=this.m_localAnchor2.x-b.m_sweep.localCenter.x,k=this.m_localAnchor2.y-b.m_sweep.localCenter.y,
l=c.col1.x*j+c.col2.x*k,k=c.col1.y*j+c.col2.y*k,j=l,n=b.m_sweep.c.x+j,m=b.m_sweep.c.y+k,this.m_u2.Set(n-f,m-g),l=this.m_u2.Length(),l>Box2D.Common.b2Settings.b2_linearSlop?(this.m_u2.x*=1/l,this.m_u2.y*=1/l):this.m_u2.SetZero(),c=this.m_maxLength2-l,o=Math.max(o,-c),c=Box2D.Common.Math.b2Math.Clamp(c+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),m=-this.m_limitMass2*c,n=-m*this.m_u2.x,m=-m*this.m_u2.y,b.m_sweep.c.x+=b.m_invMass*n,b.m_sweep.c.y+=b.m_invMass*
m,b.m_sweep.a+=b.m_invI*(j*m-k*n),b.SynchronizeTransform();return o<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength=1;Box2D.Dynamics.b2ContactImpulse=function(){UsageTracker.get("Box2D.Dynamics.b2ContactImpulse").trackCreate();this.normalImpulses=[];this.tangentImpulses=[]};Box2D.Dynamics.b2ContactImpulse.prototype.Reset=function(){this.normalImpulses=[];this.tangentImpulses=[]};Box2D.Dynamics.Contacts.b2ContactListNode=function(a){this.contact=a;this.previous=this.next=null};Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes=[];Box2D.Dynamics.Contacts.b2ContactListNode.GetNode=function(a){if(Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.length>0){var b=Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.pop();b.contact=a;return b}else return new Box2D.Dynamics.Contacts.b2ContactListNode(a)};
Box2D.Dynamics.Contacts.b2ContactListNode.FreeNode=function(a){a.next=null;a.previous=null;a.contact=null;Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.push(a)};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetContact=function(){return this.contact};
Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetPreviousNode=function(){return this.previous};goog.debug={};goog.debug.Error=function(a){this.stack=Error().stack||"";if(a)this.message=String(a)};goog.inherits(goog.debug.Error,Error);goog.debug.Error.prototype.name="CustomError";goog.string={};goog.string.Unicode={NBSP:"\u00a0"};goog.string.startsWith=function(a,b){return a.lastIndexOf(b,0)==0};goog.string.endsWith=function(a,b){var c=a.length-b.length;return c>=0&&a.indexOf(b,c)==c};goog.string.caseInsensitiveStartsWith=function(a,b){return goog.string.caseInsensitiveCompare(b,a.substr(0,b.length))==0};goog.string.caseInsensitiveEndsWith=function(a,b){return goog.string.caseInsensitiveCompare(b,a.substr(a.length-b.length,b.length))==0};
goog.string.subs=function(a,b){for(var c=1;c<arguments.length;c++)var d=String(arguments[c]).replace(/\$/g,"$$$$"),a=a.replace(/\%s/,d);return a};goog.string.collapseWhitespace=function(a){return a.replace(/[\s\xa0]+/g," ").replace(/^\s+|\s+$/g,"")};goog.string.isEmpty=function(a){return/^[\s\xa0]*$/.test(a)};goog.string.isEmptySafe=function(a){return goog.string.isEmpty(goog.string.makeSafe(a))};goog.string.isBreakingWhitespace=function(a){return!/[^\t\n\r ]/.test(a)};goog.string.isAlpha=function(a){return!/[^a-zA-Z]/.test(a)};
goog.string.isNumeric=function(a){return!/[^0-9]/.test(a)};goog.string.isAlphaNumeric=function(a){return!/[^a-zA-Z0-9]/.test(a)};goog.string.isSpace=function(a){return a==" "};goog.string.isUnicodeChar=function(a){return a.length==1&&a>=" "&&a<="~"||a>="\u0080"&&a<="\ufffd"};goog.string.stripNewlines=function(a){return a.replace(/(\r\n|\r|\n)+/g," ")};goog.string.canonicalizeNewlines=function(a){return a.replace(/(\r\n|\r|\n)/g,"\n")};
goog.string.normalizeWhitespace=function(a){return a.replace(/\xa0|\s/g," ")};goog.string.normalizeSpaces=function(a){return a.replace(/\xa0|[ \t]+/g," ")};goog.string.collapseBreakingSpaces=function(a){return a.replace(/[\t\r\n ]+/g," ").replace(/^[\t\r\n ]+|[\t\r\n ]+$/g,"")};goog.string.trim=function(a){return a.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"")};goog.string.trimLeft=function(a){return a.replace(/^[\s\xa0]+/,"")};goog.string.trimRight=function(a){return a.replace(/[\s\xa0]+$/,"")};
goog.string.caseInsensitiveCompare=function(a,b){var c=String(a).toLowerCase(),d=String(b).toLowerCase();return c<d?-1:c==d?0:1};goog.string.numerateCompareRegExp_=/(\.\d+)|(\d+)|(\D+)/g;
goog.string.numerateCompare=function(a,b){if(a==b)return 0;if(!a)return-1;if(!b)return 1;for(var c=a.toLowerCase().match(goog.string.numerateCompareRegExp_),d=b.toLowerCase().match(goog.string.numerateCompareRegExp_),e=Math.min(c.length,d.length),f=0;f<e;f++){var g=c[f],h=d[f];if(g!=h)return c=parseInt(g,10),!isNaN(c)&&(d=parseInt(h,10),!isNaN(d)&&c-d)?c-d:g<h?-1:1}return c.length!=d.length?c.length-d.length:a<b?-1:1};goog.string.encodeUriRegExp_=/^[a-zA-Z0-9\-_.!~*'()]*$/;
goog.string.urlEncode=function(a){a=String(a);return!goog.string.encodeUriRegExp_.test(a)?encodeURIComponent(a):a};goog.string.urlDecode=function(a){return decodeURIComponent(a.replace(/\+/g," "))};goog.string.newLineToBr=function(a,b){return a.replace(/(\r\n|\r|\n)/g,b?"<br />":"<br>")};
goog.string.htmlEscape=function(a,b){if(b)return a.replace(goog.string.amperRe_,"&").replace(goog.string.ltRe_,"<").replace(goog.string.gtRe_,">").replace(goog.string.quotRe_,""");else{if(!goog.string.allRe_.test(a))return a;a.indexOf("&")!=-1&&(a=a.replace(goog.string.amperRe_,"&"));a.indexOf("<")!=-1&&(a=a.replace(goog.string.ltRe_,"<"));a.indexOf(">")!=-1&&(a=a.replace(goog.string.gtRe_,">"));a.indexOf('"')!=-1&&(a=a.replace(goog.string.quotRe_,"""));return a}};
goog.string.amperRe_=/&/g;goog.string.ltRe_=/</g;goog.string.gtRe_=/>/g;goog.string.quotRe_=/\"/g;goog.string.allRe_=/[&<>\"]/;goog.string.unescapeEntities=function(a){return goog.string.contains(a,"&")?"document"in goog.global?goog.string.unescapeEntitiesUsingDom_(a):goog.string.unescapePureXmlEntities_(a):a};
goog.string.unescapeEntitiesUsingDom_=function(a){var b={"&":"&","<":"<",">":">",""":'"'},c=document.createElement("div");return a.replace(goog.string.HTML_ENTITY_PATTERN_,function(a,e){var f=b[a];if(f)return f;if(e.charAt(0)=="#"){var g=Number("0"+e.substr(1));isNaN(g)||(f=String.fromCharCode(g))}if(!f)c.innerHTML=a+" ",f=c.firstChild.nodeValue.slice(0,-1);return b[a]=f})};
goog.string.unescapePureXmlEntities_=function(a){return a.replace(/&([^;]+);/g,function(a,c){switch(c){case "amp":return"&";case "lt":return"<";case "gt":return">";case "quot":return'"';default:if(c.charAt(0)=="#"){var d=Number("0"+c.substr(1));if(!isNaN(d))return String.fromCharCode(d)}return a}})};goog.string.HTML_ENTITY_PATTERN_=/&([^;\s<&]+);?/g;goog.string.whitespaceEscape=function(a,b){return goog.string.newLineToBr(a.replace(/ /g,"  "),b)};
goog.string.stripQuotes=function(a,b){for(var c=b.length,d=0;d<c;d++){var e=c==1?b:b.charAt(d);if(a.charAt(0)==e&&a.charAt(a.length-1)==e)return a.substring(1,a.length-1)}return a};goog.string.truncate=function(a,b,c){c&&(a=goog.string.unescapeEntities(a));a.length>b&&(a=a.substring(0,b-3)+"...");c&&(a=goog.string.htmlEscape(a));return a};
goog.string.truncateMiddle=function(a,b,c,d){c&&(a=goog.string.unescapeEntities(a));if(d&&a.length>b){d>b&&(d=b);var e=a.length-d,a=a.substring(0,b-d)+"..."+a.substring(e)}else a.length>b&&(d=Math.floor(b/2),e=a.length-d,d+=b%2,a=a.substring(0,d)+"..."+a.substring(e));c&&(a=goog.string.htmlEscape(a));return a};goog.string.specialEscapeChars_={"\000":"\\0","\u0008":"\\b","\u000c":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\u000b":"\\x0B",'"':'\\"',"\\":"\\\\"};goog.string.jsEscapeCache_={"'":"\\'"};
goog.string.quote=function(a){a=String(a);if(a.quote)return a.quote();else{for(var b=['"'],c=0;c<a.length;c++){var d=a.charAt(c),e=d.charCodeAt(0);b[c+1]=goog.string.specialEscapeChars_[d]||(e>31&&e<127?d:goog.string.escapeChar(d))}b.push('"');return b.join("")}};goog.string.escapeString=function(a){for(var b=[],c=0;c<a.length;c++)b[c]=goog.string.escapeChar(a.charAt(c));return b.join("")};
goog.string.escapeChar=function(a){if(a in goog.string.jsEscapeCache_)return goog.string.jsEscapeCache_[a];if(a in goog.string.specialEscapeChars_)return goog.string.jsEscapeCache_[a]=goog.string.specialEscapeChars_[a];var b=a,c=a.charCodeAt(0);if(c>31&&c<127)b=a;else{if(c<256){if(b="\\x",c<16||c>256)b+="0"}else b="\\u",c<4096&&(b+="0");b+=c.toString(16).toUpperCase()}return goog.string.jsEscapeCache_[a]=b};goog.string.toMap=function(a){for(var b={},c=0;c<a.length;c++)b[a.charAt(c)]=!0;return b};
goog.string.contains=function(a,b){return a.indexOf(b)!=-1};goog.string.removeAt=function(a,b,c){var d=a;b>=0&&b<a.length&&c>0&&(d=a.substr(0,b)+a.substr(b+c,a.length-b-c));return d};goog.string.remove=function(a,b){var c=RegExp(goog.string.regExpEscape(b),"");return a.replace(c,"")};goog.string.removeAll=function(a,b){var c=RegExp(goog.string.regExpEscape(b),"g");return a.replace(c,"")};
goog.string.regExpEscape=function(a){return String(a).replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g,"\\$1").replace(/\x08/g,"\\x08")};goog.string.repeat=function(a,b){return Array(b+1).join(a)};goog.string.padNumber=function(a,b,c){a=goog.isDef(c)?a.toFixed(c):String(a);c=a.indexOf(".");if(c==-1)c=a.length;return goog.string.repeat("0",Math.max(0,b-c))+a};goog.string.makeSafe=function(a){return a==null?"":String(a)};goog.string.buildString=function(a){return Array.prototype.join.call(arguments,"")};
goog.string.getRandomString=function(){return Math.floor(Math.random()*2147483648).toString(36)+Math.abs(Math.floor(Math.random()*2147483648)^goog.now()).toString(36)};
goog.string.compareVersions=function(a,b){for(var c=0,d=goog.string.trim(String(a)).split("."),e=goog.string.trim(String(b)).split("."),f=Math.max(d.length,e.length),g=0;c==0&&g<f;g++){var h=d[g]||"",i=e[g]||"",j=RegExp("(\\d*)(\\D*)","g"),k=RegExp("(\\d*)(\\D*)","g");do{var l=j.exec(h)||["","",""],n=k.exec(i)||["","",""];if(l[0].length==0&&n[0].length==0)break;var c=l[1].length==0?0:parseInt(l[1],10),m=n[1].length==0?0:parseInt(n[1],10),c=goog.string.compareElements_(c,m)||goog.string.compareElements_(l[2].length==
0,n[2].length==0)||goog.string.compareElements_(l[2],n[2])}while(c==0)}return c};goog.string.compareElements_=function(a,b){if(a<b)return-1;else if(a>b)return 1;return 0};goog.string.HASHCODE_MAX_=4294967296;goog.string.hashCode=function(a){for(var b=0,c=0;c<a.length;++c)b=31*b+a.charCodeAt(c),b%=goog.string.HASHCODE_MAX_;return b};goog.string.uniqueStringCounter_=Math.random()*2147483648|0;goog.string.createUniqueString=function(){return"goog_"+goog.string.uniqueStringCounter_++};
goog.string.toNumber=function(a){var b=Number(a);return b==0&&goog.string.isEmpty(a)?NaN:b};goog.string.toCamelCaseCache_={};goog.string.toCamelCase=function(a){return goog.string.toCamelCaseCache_[a]||(goog.string.toCamelCaseCache_[a]=String(a).replace(/\-([a-z])/g,function(a,c){return c.toUpperCase()}))};goog.string.toSelectorCaseCache_={};goog.string.toSelectorCase=function(a){return goog.string.toSelectorCaseCache_[a]||(goog.string.toSelectorCaseCache_[a]=String(a).replace(/([A-Z])/g,"-$1").toLowerCase())};goog.asserts={};goog.asserts.ENABLE_ASSERTS=goog.DEBUG;goog.asserts.AssertionError=function(a,b){b.unshift(a);goog.debug.Error.call(this,goog.string.subs.apply(null,b));b.shift();this.messagePattern=a};goog.inherits(goog.asserts.AssertionError,goog.debug.Error);goog.asserts.AssertionError.prototype.name="AssertionError";goog.asserts.doAssertFailure_=function(a,b,c,d){var e="Assertion failed";if(c){e+=": "+c;var f=d}else a&&(e+=": "+a,f=b);throw new goog.asserts.AssertionError(""+e,f||[]);};
goog.asserts.assert=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!a&&goog.asserts.doAssertFailure_("",null,b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.fail=function(a,b){if(goog.asserts.ENABLE_ASSERTS)throw new goog.asserts.AssertionError("Failure"+(a?": "+a:""),Array.prototype.slice.call(arguments,1));};
goog.asserts.assertNumber=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isNumber(a)&&goog.asserts.doAssertFailure_("Expected number but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.assertString=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isString(a)&&goog.asserts.doAssertFailure_("Expected string but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertFunction=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isFunction(a)&&goog.asserts.doAssertFailure_("Expected function but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.assertObject=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isObject(a)&&goog.asserts.doAssertFailure_("Expected object but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertArray=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isArray(a)&&goog.asserts.doAssertFailure_("Expected array but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};goog.asserts.assertBoolean=function(a,b,c){goog.asserts.ENABLE_ASSERTS&&!goog.isBoolean(a)&&goog.asserts.doAssertFailure_("Expected boolean but got %s: %s.",[goog.typeOf(a),a],b,Array.prototype.slice.call(arguments,2));return a};
goog.asserts.assertInstanceof=function(a,b,c,d){goog.asserts.ENABLE_ASSERTS&&!(a instanceof b)&&goog.asserts.doAssertFailure_("instanceof check failed.",null,c,Array.prototype.slice.call(arguments,3))};goog.array={};goog.NATIVE_ARRAY_PROTOTYPES=!0;goog.array.peek=function(a){return a[a.length-1]};goog.array.ARRAY_PROTOTYPE_=Array.prototype;
goog.array.indexOf=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.indexOf?function(a,b,c){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.indexOf.call(a,b,c)}:function(a,b,c){c=c==null?0:c<0?Math.max(0,a.length+c):c;if(goog.isString(a))return!goog.isString(b)||b.length!=1?-1:a.indexOf(b,c);for(;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1};
goog.array.lastIndexOf=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.lastIndexOf?function(a,b,c){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.lastIndexOf.call(a,b,c==null?a.length-1:c)}:function(a,b,c){c=c==null?a.length-1:c;c<0&&(c=Math.max(0,a.length+c));if(goog.isString(a))return!goog.isString(b)||b.length!=1?-1:a.lastIndexOf(b,c);for(;c>=0;c--)if(c in a&&a[c]===b)return c;return-1};
goog.array.forEach=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.forEach?function(a,b,c){goog.asserts.assert(a.length!=null);goog.array.ARRAY_PROTOTYPE_.forEach.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)f in e&&b.call(c,e[f],f,a)};goog.array.forEachRight=function(a,b,c){var d=a.length,e=goog.isString(a)?a.split(""):a;for(d-=1;d>=0;--d)d in e&&b.call(c,e[d],d,a)};
goog.array.filter=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.filter?function(a,b,c){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.filter.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=[],f=0,g=goog.isString(a)?a.split(""):a,h=0;h<d;h++)if(h in g){var i=g[h];b.call(c,i,h,a)&&(e[f++]=i)}return e};
goog.array.map=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.map?function(a,b,c){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.map.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=Array(d),f=goog.isString(a)?a.split(""):a,g=0;g<d;g++)g in f&&(e[g]=b.call(c,f[g],g,a));return e};goog.array.reduce=function(a,b,c,d){if(a.reduce)return d?a.reduce(goog.bind(b,d),c):a.reduce(b,c);var e=c;goog.array.forEach(a,function(c,g){e=b.call(d,e,c,g,a)});return e};
goog.array.reduceRight=function(a,b,c,d){if(a.reduceRight)return d?a.reduceRight(goog.bind(b,d),c):a.reduceRight(b,c);var e=c;goog.array.forEachRight(a,function(c,g){e=b.call(d,e,c,g,a)});return e};
goog.array.some=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.some?function(a,b,c){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.some.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return!0;return!1};
goog.array.every=goog.NATIVE_ARRAY_PROTOTYPES&&goog.array.ARRAY_PROTOTYPE_.every?function(a,b,c){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.every.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&!b.call(c,e[f],f,a))return!1;return!0};goog.array.find=function(a,b,c){b=goog.array.findIndex(a,b,c);return b<0?null:goog.isString(a)?a.charAt(b):a[b]};
goog.array.findIndex=function(a,b,c){for(var d=a.length,e=goog.isString(a)?a.split(""):a,f=0;f<d;f++)if(f in e&&b.call(c,e[f],f,a))return f;return-1};goog.array.findRight=function(a,b,c){b=goog.array.findIndexRight(a,b,c);return b<0?null:goog.isString(a)?a.charAt(b):a[b]};goog.array.findIndexRight=function(a,b,c){var d=a.length,e=goog.isString(a)?a.split(""):a;for(d-=1;d>=0;d--)if(d in e&&b.call(c,e[d],d,a))return d;return-1};goog.array.contains=function(a,b){return goog.array.indexOf(a,b)>=0};
goog.array.isEmpty=function(a){return a.length==0};goog.array.clear=function(a){if(!goog.isArray(a))for(var b=a.length-1;b>=0;b--)delete a[b];a.length=0};goog.array.insert=function(a,b){goog.array.contains(a,b)||a.push(b)};goog.array.insertAt=function(a,b,c){goog.array.splice(a,c,0,b)};goog.array.insertArrayAt=function(a,b,c){goog.partial(goog.array.splice,a,c,0).apply(null,b)};
goog.array.insertBefore=function(a,b,c){var d;arguments.length==2||(d=goog.array.indexOf(a,c))<0?a.push(b):goog.array.insertAt(a,b,d)};goog.array.remove=function(a,b){var c=goog.array.indexOf(a,b),d;(d=c>=0)&&goog.array.removeAt(a,c);return d};goog.array.removeAt=function(a,b){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.splice.call(a,b,1).length==1};goog.array.removeIf=function(a,b,c){b=goog.array.findIndex(a,b,c);return b>=0?(goog.array.removeAt(a,b),!0):!1};
goog.array.concat=function(a){return goog.array.ARRAY_PROTOTYPE_.concat.apply(goog.array.ARRAY_PROTOTYPE_,arguments)};goog.array.clone=function(a){if(goog.isArray(a))return goog.array.concat(a);else{for(var b=[],c=0,d=a.length;c<d;c++)b[c]=a[c];return b}};goog.array.toArray=function(a){return goog.isArray(a)?goog.array.concat(a):goog.array.clone(a)};
goog.array.extend=function(a,b){for(var c=1;c<arguments.length;c++){var d=arguments[c],e;if(goog.isArray(d)||(e=goog.isArrayLike(d))&&d.hasOwnProperty("callee"))a.push.apply(a,d);else if(e)for(var f=a.length,g=d.length,h=0;h<g;h++)a[f+h]=d[h];else a.push(d)}};goog.array.splice=function(a,b,c,d){goog.asserts.assert(a.length!=null);return goog.array.ARRAY_PROTOTYPE_.splice.apply(a,goog.array.slice(arguments,1))};
goog.array.slice=function(a,b,c){goog.asserts.assert(a.length!=null);return arguments.length<=2?goog.array.ARRAY_PROTOTYPE_.slice.call(a,b):goog.array.ARRAY_PROTOTYPE_.slice.call(a,b,c)};goog.array.removeDuplicates=function(a,b){for(var c=b||a,d={},e=0,f=0;f<a.length;){var g=a[f++],h=goog.isObject(g)?"o"+goog.getUid(g):(typeof g).charAt(0)+g;Object.prototype.hasOwnProperty.call(d,h)||(d[h]=!0,c[e++]=g)}c.length=e};
goog.array.binarySearch=function(a,b,c){return goog.array.binarySearch_(a,c||goog.array.defaultCompare,!1,b)};goog.array.binarySelect=function(a,b,c){return goog.array.binarySearch_(a,b,!0,void 0,c)};goog.array.binarySearch_=function(a,b,c,d,e){for(var f=0,g=a.length,h;f<g;){var i=f+g>>1,j;j=c?b.call(e,a[i],i,a):b(d,a[i]);j>0?f=i+1:(g=i,h=!j)}return h?f:~f};goog.array.sort=function(a,b){goog.asserts.assert(a.length!=null);goog.array.ARRAY_PROTOTYPE_.sort.call(a,b||goog.array.defaultCompare)};
goog.array.stableSort=function(a,b){for(var c=0;c<a.length;c++)a[c]={index:c,value:a[c]};var d=b||goog.array.defaultCompare;goog.array.sort(a,function(a,b){return d(a.value,b.value)||a.index-b.index});for(c=0;c<a.length;c++)a[c]=a[c].value};goog.array.sortObjectsByKey=function(a,b,c){var d=c||goog.array.defaultCompare;goog.array.sort(a,function(a,c){return d(a[b],c[b])})};
goog.array.isSorted=function(a,b,c){for(var b=b||goog.array.defaultCompare,d=1;d<a.length;d++){var e=b(a[d-1],a[d]);if(e>0||e==0&&c)return!1}return!0};goog.array.equals=function(a,b,c){if(!goog.isArrayLike(a)||!goog.isArrayLike(b)||a.length!=b.length)return!1;for(var d=a.length,c=c||goog.array.defaultCompareEquality,e=0;e<d;e++)if(!c(a[e],b[e]))return!1;return!0};goog.array.compare=function(a,b,c){return goog.array.equals(a,b,c)};
goog.array.compare3=function(a,b,c){for(var c=c||goog.array.defaultCompare,d=Math.min(a.length,b.length),e=0;e<d;e++){var f=c(a[e],b[e]);if(f!=0)return f}return goog.array.defaultCompare(a.length,b.length)};goog.array.defaultCompare=function(a,b){return a>b?1:a<b?-1:0};goog.array.defaultCompareEquality=function(a,b){return a===b};goog.array.binaryInsert=function(a,b,c){c=goog.array.binarySearch(a,b,c);return c<0?(goog.array.insertAt(a,b,-(c+1)),!0):!1};
goog.array.binaryRemove=function(a,b,c){b=goog.array.binarySearch(a,b,c);return b>=0?goog.array.removeAt(a,b):!1};goog.array.bucket=function(a,b){for(var c={},d=0;d<a.length;d++){var e=a[d],f=b(e,d,a);goog.isDef(f)&&(c[f]||(c[f]=[])).push(e)}return c};goog.array.repeat=function(a,b){for(var c=[],d=0;d<b;d++)c[d]=a;return c};goog.array.flatten=function(a){for(var b=[],c=0;c<arguments.length;c++){var d=arguments[c];goog.isArray(d)?b.push.apply(b,goog.array.flatten.apply(null,d)):b.push(d)}return b};
goog.array.rotate=function(a,b){goog.asserts.assert(a.length!=null);a.length&&(b%=a.length,b>0?goog.array.ARRAY_PROTOTYPE_.unshift.apply(a,a.splice(-b,b)):b<0&&goog.array.ARRAY_PROTOTYPE_.push.apply(a,a.splice(0,-b)));return a};goog.array.zip=function(a){if(!arguments.length)return[];for(var b=[],c=0;;c++){for(var d=[],e=0;e<arguments.length;e++){var f=arguments[e];if(c>=f.length)return b;d.push(f[c])}b.push(d)}};
goog.array.shuffle=function(a,b){for(var c=b||Math.random,d=a.length-1;d>0;d--){var e=Math.floor(c()*(d+1)),f=a[d];a[d]=a[e];a[e]=f}};Box2D.Dynamics.Contacts.b2ContactList=function(){this.contactFirstNodes=[];for(var a=0;a<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;a++)this.contactFirstNodes[a]=null;this.contactLastNodes=[];for(a=0;a<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;a++)this.contactLastNodes[a]=null;this.contactNodeLookup={};this.contactCount=0};
Box2D.Dynamics.Contacts.b2ContactList.prototype.ForEachContact=function(a,b){for(var c=this.contactFirstNodes[a],d;c!==null;)if(d=c,c=d.GetNextNode(),b(d.contact)===!0)break};
Box2D.Dynamics.Contacts.b2ContactList.prototype.AddContact=function(a){var b=a.ID;if(this.contactNodeLookup[b]==null){this.contactNodeLookup[b]=[];for(var c=0;c<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;c++)this.contactNodeLookup[b][c]=null;this.CreateNode(a,b,Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);this.contactCount++}};
Box2D.Dynamics.Contacts.b2ContactList.prototype.UpdateContact=function(a,b,c){b?this.CreateNode(a,a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts):this.RemoveNode(a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts);c?this.CreateNode(a,a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts):this.RemoveNode(a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts)};
Box2D.Dynamics.Contacts.b2ContactList.prototype.RemoveContact=function(a){a=a.ID;if(this.contactNodeLookup[a]!=null){for(var b=0;b<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;b++)this.RemoveNode(a,b);delete this.contactNodeLookup[a];this.contactCount--}};
Box2D.Dynamics.Contacts.b2ContactList.prototype.RemoveNode=function(a,b){var c=this.contactNodeLookup[a];if(c!=null){var d=c[b];if(d!=null){c[b]=null;var c=d.GetPreviousNode(),e=d.GetNextNode();c==null?this.contactFirstNodes[b]=e:c.SetNextNode(e);e==null?this.contactLastNodes[b]=c:e.SetPreviousNode(c);Box2D.Dynamics.Contacts.b2ContactListNode.FreeNode(d)}}};
Box2D.Dynamics.Contacts.b2ContactList.prototype.CreateNode=function(a,b,c){b=this.contactNodeLookup[b];b[c]==null&&(b[c]=Box2D.Dynamics.Contacts.b2ContactListNode.GetNode(a),a=this.contactLastNodes[c],a!=null?(a.SetNextNode(b[c]),b[c].SetPreviousNode(a)):this.contactFirstNodes[c]=b[c],this.contactLastNodes[c]=b[c])};Box2D.Dynamics.Contacts.b2ContactList.prototype.GetContactCount=function(){return this.contactCount};
Box2D.Dynamics.Contacts.b2ContactList.TYPES={nonSensorEnabledTouchingContacts:0,nonSensorEnabledContinuousContacts:1,allContacts:2};Box2D.Collision.b2Segment=function(){UsageTracker.get("Box2D.Collision.b2Segment").trackCreate();this.p1=Box2D.Common.Math.b2Vec2.Get(0,0);this.p2=Box2D.Common.Math.b2Vec2.Get(0,0)};
Box2D.Collision.b2Segment.prototype.TestSegment=function(a,b,c,d){var e=c.p1,f=c.p2.x-e.x,g=c.p2.y-e.y,c=this.p2.y-this.p1.y,h=-(this.p2.x-this.p1.x),i=100*Number.MIN_VALUE,j=-(f*c+g*h);if(j>i){var k=e.x-this.p1.x,l=e.y-this.p1.y,e=k*c+l*h;if(0<=e&&e<=d*j&&(d=-f*l+g*k,-i*j<=d&&d<=j*(1+i)))return e/=j,d=Math.sqrt(c*c+h*h),c/=d,h/=d,a[0]=e,b.Set(c,h),!0}return!1};Box2D.Collision.b2Segment.prototype.Extend=function(a){this.ExtendForward(a);this.ExtendBackward(a)};
Box2D.Collision.b2Segment.prototype.ExtendForward=function(a){var b=this.p2.x-this.p1.x,c=this.p2.y-this.p1.y,a=Math.min(b>0?(a.upperBound.x-this.p1.x)/b:b<0?(a.lowerBound.x-this.p1.x)/b:Number.POSITIVE_INFINITY,c>0?(a.upperBound.y-this.p1.y)/c:c<0?(a.lowerBound.y-this.p1.y)/c:Number.POSITIVE_INFINITY);this.p2.x=this.p1.x+b*a;this.p2.y=this.p1.y+c*a};
Box2D.Collision.b2Segment.prototype.ExtendBackward=function(a){var b=-this.p2.x+this.p1.x,c=-this.p2.y+this.p1.y,a=Math.min(b>0?(a.upperBound.x-this.p2.x)/b:b<0?(a.lowerBound.x-this.p2.x)/b:Number.POSITIVE_INFINITY,c>0?(a.upperBound.y-this.p2.y)/c:c<0?(a.lowerBound.y-this.p2.y)/c:Number.POSITIVE_INFINITY);this.p1.x=this.p2.x+b*a;this.p1.y=this.p2.y+c*a};Box2D.Dynamics.Joints.b2MouseJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.K=Box2D.Common.Math.b2Mat22.Get();this.K1=Box2D.Common.Math.b2Mat22.Get();this.K2=Box2D.Common.Math.b2Mat22.Get();this.m_localAnchor=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_target=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_mass=Box2D.Common.Math.b2Mat22.Get();this.m_C=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_target.SetV(a.target);var b=this.m_target.x-this.m_bodyB.m_xf.position.x,
c=this.m_target.y-this.m_bodyB.m_xf.position.y,d=this.m_bodyB.m_xf.R;this.m_localAnchor.x=b*d.col1.x+c*d.col1.y;this.m_localAnchor.y=b*d.col2.x+c*d.col2.y;this.m_maxForce=a.maxForce;this.m_impulse.SetZero();this.m_frequencyHz=a.frequencyHz;this.m_dampingRatio=a.dampingRatio;this.m_gamma=this.m_beta=0};goog.inherits(Box2D.Dynamics.Joints.b2MouseJoint,Box2D.Dynamics.Joints.b2Joint);
Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetAnchorA=function(){return Box2D.Common.Math.b2Vec2.Get(this.m_target.x,this.m_target.y)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetReactionForce=function(a){a===void 0&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetReactionTorque=function(){return 0};
Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetTarget=function(){return this.m_target};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetTarget=function(a){this.m_bodyB.IsAwake()==!1&&this.m_bodyB.SetAwake(!0);this.m_target=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetMaxForce=function(){return this.m_maxForce};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetMaxForce=function(a){a===void 0&&(a=0);this.m_maxForce=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetFrequency=function(){return this.m_frequencyHz};
Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetFrequency=function(a){a===void 0&&(a=0);this.m_frequencyHz=a};Box2D.Dynamics.Joints.b2MouseJoint.prototype.GetDampingRatio=function(){return this.m_dampingRatio};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SetDampingRatio=function(a){a===void 0&&(a=0);this.m_dampingRatio=a};
Box2D.Dynamics.Joints.b2MouseJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyB,c=b.GetMass(),d=2*Math.PI*this.m_frequencyHz,e=c*d*d;this.m_gamma=a.dt*(2*c*this.m_dampingRatio*d+a.dt*e);this.m_gamma=this.m_gamma!=0?1/this.m_gamma:0;this.m_beta=a.dt*e*this.m_gamma;var e=b.m_xf.R,c=this.m_localAnchor.x-b.m_sweep.localCenter.x,d=this.m_localAnchor.y-b.m_sweep.localCenter.y,f=e.col1.x*c+e.col2.x*d,d=e.col1.y*c+e.col2.y*d,c=f,e=b.m_invMass,f=b.m_invI;this.K1.col1.x=e;this.K1.col2.x=
0;this.K1.col1.y=0;this.K1.col2.y=e;this.K2.col1.x=f*d*d;this.K2.col2.x=-f*c*d;this.K2.col1.y=-f*c*d;this.K2.col2.y=f*c*c;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.col1.x+=this.m_gamma;this.K.col2.y+=this.m_gamma;this.K.GetInverse(this.m_mass);this.m_C.x=b.m_sweep.c.x+c-this.m_target.x;this.m_C.y=b.m_sweep.c.y+d-this.m_target.y;b.m_angularVelocity*=0.98;this.m_impulse.x*=a.dtRatio;this.m_impulse.y*=a.dtRatio;b.m_linearVelocity.x+=e*this.m_impulse.x;b.m_linearVelocity.y+=e*this.m_impulse.y;
b.m_angularVelocity+=f*(c*this.m_impulse.y-d*this.m_impulse.x)};
Box2D.Dynamics.Joints.b2MouseJoint.prototype.SolveVelocityConstraints=function(a){var b=this.m_bodyB,c,d=0,e=0;c=b.m_xf.R;var f=this.m_localAnchor.x-b.m_sweep.localCenter.x,g=this.m_localAnchor.y-b.m_sweep.localCenter.y,d=c.col1.x*f+c.col2.x*g,g=c.col1.y*f+c.col2.y*g,f=d,d=b.m_linearVelocity.x+-b.m_angularVelocity*g,h=b.m_linearVelocity.y+b.m_angularVelocity*f;c=this.m_mass;d=d+this.m_beta*this.m_C.x+this.m_gamma*this.m_impulse.x;e=h+this.m_beta*this.m_C.y+this.m_gamma*this.m_impulse.y;h=-(c.col1.x*
d+c.col2.x*e);e=-(c.col1.y*d+c.col2.y*e);c=this.m_impulse.x;d=this.m_impulse.y;this.m_impulse.x+=h;this.m_impulse.y+=e;a=a.dt*this.m_maxForce;this.m_impulse.LengthSquared()>a*a&&this.m_impulse.Multiply(a/this.m_impulse.Length());h=this.m_impulse.x-c;e=this.m_impulse.y-d;b.m_linearVelocity.x+=b.m_invMass*h;b.m_linearVelocity.y+=b.m_invMass*e;b.m_angularVelocity+=b.m_invI*(f*e-g*h)};Box2D.Dynamics.Joints.b2MouseJoint.prototype.SolvePositionConstraints=function(){return!0};Box2D.Dynamics.b2BodyListNode=function(a){UsageTracker.get("Box2D.Dynamics.b2BodyListNode").trackCreate();this.body=a;this.previous=this.next=null};Box2D.Dynamics.b2BodyListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.b2BodyListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.b2BodyListNode.prototype.GetBody=function(){return this.body};Box2D.Dynamics.b2BodyListNode.prototype.GetNextNode=function(){return this.next};
Box2D.Dynamics.b2BodyListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Common.b2Color=function(a,b,c){UsageTracker.get("Box2D.Common.b2Color").trackCreate();this._r=255*Box2D.Common.Math.b2Math.Clamp(a,0,1);this._g=255*Box2D.Common.Math.b2Math.Clamp(b,0,1);this._b=255*Box2D.Common.Math.b2Math.Clamp(c,0,1)};Box2D.Common.b2Color.prototype.Set=function(a,b,c){this._r=255*Box2D.Common.Math.b2Math.Clamp(a,0,1);this._g=255*Box2D.Common.Math.b2Math.Clamp(b,0,1);this._b=255*Box2D.Common.Math.b2Math.Clamp(c,0,1)};
Box2D.Common.b2Color.prototype.GetColor=function(){return this._r<<16|this._g<<8|this._b};Box2D.Dynamics.b2BodyList=function(){UsageTracker.get("Box2D.Dynamics.b2BodyList").trackCreate();this.bodyFirstNodes=[];for(var a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++)this.bodyFirstNodes[a]=null;this.bodyLastNodes=[];for(a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++)this.bodyLastNodes[a]=null;this.bodyNodeLookup={};this.bodyCount=0};Box2D.Dynamics.b2BodyList.prototype.GetFirstNode=function(a){return this.bodyFirstNodes[a]};
Box2D.Dynamics.b2BodyList.prototype.AddBody=function(a){var b=a.ID;this.bodyNodeLookup[b]==null&&(this.CreateNode(a,b,Box2D.Dynamics.b2BodyList.TYPES.allBodies),this.UpdateBody(a),a.m_lists.push(this),this.bodyCount++)};
Box2D.Dynamics.b2BodyList.prototype.UpdateBody=function(a){var b=a.GetType(),c=a.ID,d=a.IsAwake(),e=a.IsActive();b==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies);b!=Box2D.Dynamics.b2BodyDef.b2_staticBody?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticBodies);b!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&
e&&d?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);d?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.awakeBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);e?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.activeBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.activeBodies)};
Box2D.Dynamics.b2BodyList.prototype.RemoveBody=function(a){var b=a.ID;if(this.bodyNodeLookup[b]!=null){goog.array.remove(a.m_lists,this);for(a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++)this.RemoveNode(b,a);delete this.bodyNodeLookup[b];this.bodyCount--}};
Box2D.Dynamics.b2BodyList.prototype.RemoveNode=function(a,b){var c=this.bodyNodeLookup[a];if(c!=null){var d=c[b];d!=null&&(c[b]=null,c=d.GetPreviousNode(),d=d.GetNextNode(),c==null?this.bodyFirstNodes[b]=d:c.SetNextNode(d),d==null?this.bodyLastNodes[b]=c:d.SetPreviousNode(c))}};
Box2D.Dynamics.b2BodyList.prototype.CreateNode=function(a,b,c){var d=this.bodyNodeLookup[b];if(d==null){for(var d=[],e=0;e<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;e++)d[e]=null;this.bodyNodeLookup[b]=d}d[c]==null&&(d[c]=new Box2D.Dynamics.b2BodyListNode(a),a=this.bodyLastNodes[c],a!=null?a.SetNextNode(d[c]):this.bodyFirstNodes[c]=d[c],d[c].SetPreviousNode(a),this.bodyLastNodes[c]=d[c])};Box2D.Dynamics.b2BodyList.prototype.GetBodyCount=function(){return this.bodyCount};
Box2D.Dynamics.b2BodyList.TYPES={dynamicBodies:0,nonStaticBodies:1,activeBodies:2,nonStaticActiveAwakeBodies:3,awakeBodies:4,allBodies:5};Box2D.Dynamics.Controllers={};Box2D.Dynamics.Controllers.b2Controller=function(){this.ID="Controller"+Box2D.Dynamics.Controllers.b2Controller.NEXT_ID++;this.m_world=null;this.bodyList=new Box2D.Dynamics.b2BodyList};Box2D.Dynamics.Controllers.b2Controller.prototype.Step=function(){};Box2D.Dynamics.Controllers.b2Controller.prototype.Draw=function(){};Box2D.Dynamics.Controllers.b2Controller.prototype.AddBody=function(a){this.bodyList.AddBody(a);a.AddController(this)};
Box2D.Dynamics.Controllers.b2Controller.prototype.RemoveBody=function(a){this.bodyList.RemoveBody(a);a.RemoveController(this)};Box2D.Dynamics.Controllers.b2Controller.prototype.Clear=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);a;a=a.GetNextNode())this.RemoveBody(a.body)};Box2D.Dynamics.Controllers.b2Controller.prototype.GetBodyList=function(){return this.bodyList};Box2D.Dynamics.Controllers.b2Controller.NEXT_ID=0;Box2D.Dynamics.Controllers.b2ConstantAccelController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.A=Box2D.Common.Math.b2Vec2.Get(0,0)};goog.inherits(Box2D.Dynamics.Controllers.b2ConstantAccelController,Box2D.Dynamics.Controllers.b2Controller);
Box2D.Dynamics.Controllers.b2ConstantAccelController.prototype.Step=function(a){for(var a=Box2D.Common.Math.b2Vec2.Get(this.A.x*a.dt,this.A.y*a.dt),b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);b;b=b.GetNextNode()){var c=b.body,d=c.GetLinearVelocity(),d=Box2D.Common.Math.b2Vec2.Get(d.x+a.x,d.y+a.y);c.SetLinearVelocity(d);Box2D.Common.Math.b2Vec2.Free(d)}Box2D.Common.Math.b2Vec2.Free(a)};Box2D.Dynamics.Contacts.b2PolygonContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};goog.inherits(Box2D.Dynamics.Contacts.b2PolygonContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolygonContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};
Box2D.Dynamics.Contacts.b2PolygonContact.prototype.Evaluate=function(){var a=this.m_fixtureA.GetShape(),b=this.m_fixtureB.GetShape();Box2D.Collision.b2Collision.CollidePolygons(this.m_manifold,a,this.m_fixtureA.GetBody().GetTransform(),b,this.m_fixtureB.GetBody().GetTransform())};Box2D.Collision.IBroadPhase="Box2D.Collision.IBroadPhase";Box2D.Dynamics.b2Island=function(a,b){UsageTracker.get("Box2D.Dynamics.b2Island").trackCreate();this.m_listener=a;this.m_contactSolver=b;this.m_bodies=[];this.m_dynamicBodies=[];this.m_nonStaticBodies=[];this.m_contacts=[];this.m_joints=[];this.impulse=new Box2D.Dynamics.b2ContactImpulse};Box2D.Dynamics.b2Island.prototype.Reset=function(a,b){this.m_listener=a;this.m_contactSolver=b};
Box2D.Dynamics.b2Island.prototype.Clear=function(){this.m_bodies=[];this.m_dynamicBodies=[];this.m_nonStaticBodies=[];this.m_contacts=[];this.m_joints=[]};Box2D.Dynamics.b2Island.prototype.Solve=function(a,b,c){this._InitializeVelocities(a,b);this.m_contactSolver.Initialize(a,this.m_contacts,this.m_contacts.length);this._SolveVelocityConstraints(a);this._SolveBodies(a);this._SolvePositionConstraints(a);this.Report(this.m_contactSolver.m_constraints);c&&this._SleepIfTired(a)};
Box2D.Dynamics.b2Island.prototype._InitializeVelocities=function(a,b){for(var c=0;c<this.m_dynamicBodies.length;c++){var d=this.m_dynamicBodies[c];d.m_linearVelocity.x+=a.dt*(b.x+d.m_invMass*d.m_force.x);d.m_linearVelocity.y+=a.dt*(b.y+d.m_invMass*d.m_force.y);d.m_angularVelocity+=a.dt*d.m_invI*d.m_torque;d.m_linearVelocity.Multiply(Box2D.Common.Math.b2Math.Clamp(1-a.dt*d.m_linearDamping,0,1));d.m_angularVelocity*=Box2D.Common.Math.b2Math.Clamp(1-a.dt*d.m_angularDamping,0,1)}};
Box2D.Dynamics.b2Island.prototype._SolveVelocityConstraints=function(a){this.m_contactSolver.InitVelocityConstraints(a);for(var b=0;b<this.m_joints.length;b++)this.m_joints[b].InitVelocityConstraints(a);for(b=0;b<a.velocityIterations;b++){for(var c=0;c<this.m_joints.length;c++)this.m_joints[c].SolveVelocityConstraints(a);this.m_contactSolver.SolveVelocityConstraints()}for(a=0;a<this.m_joints.length;a++)this.m_joints[a].FinalizeVelocityConstraints();this.m_contactSolver.FinalizeVelocityConstraints()};
Box2D.Dynamics.b2Island.prototype._SolveBodies=function(a){for(var b=0;b<this.m_nonStaticBodies.length;++b){var c=this.m_nonStaticBodies[b],d=a.dt*c.m_linearVelocity.x,e=a.dt*c.m_linearVelocity.y;d*d+e*e>Box2D.Common.b2Settings.b2_maxTranslationSquared&&(c.m_linearVelocity.Normalize(),c.m_linearVelocity.x*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt,c.m_linearVelocity.y*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt);d=a.dt*c.m_angularVelocity;if(d*d>Box2D.Common.b2Settings.b2_maxRotationSquared)c.m_angularVelocity=
c.m_angularVelocity<0?-Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt:Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt;c.m_sweep.c0.SetV(c.m_sweep.c);c.m_sweep.a0=c.m_sweep.a;c.m_sweep.c.x+=a.dt*c.m_linearVelocity.x;c.m_sweep.c.y+=a.dt*c.m_linearVelocity.y;c.m_sweep.a+=a.dt*c.m_angularVelocity;c.SynchronizeTransform()}};
Box2D.Dynamics.b2Island.prototype._SolvePositionConstraints=function(a){for(var b=0;b<a.positionIterations;b++){for(var c=this.m_contactSolver.SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte),d=!0,e=0;e<this.m_joints.length;e++)var f=this.m_joints[e].SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte),d=d&&f;if(c&&d)break}};
Box2D.Dynamics.b2Island.prototype._SleepIfTired=function(a){for(var b=Number.MAX_VALUE,c=0;c<this.m_nonStaticBodies.length;c++){var d=this.m_nonStaticBodies[c];!d.m_allowSleep||Math.abs(d.m_angularVelocity)>Box2D.Common.b2Settings.b2_angularSleepTolerance||Box2D.Common.Math.b2Math.Dot(d.m_linearVelocity,d.m_linearVelocity)>Box2D.Common.b2Settings.b2_linearSleepToleranceSquared?b=d.m_sleepTime=0:(d.m_sleepTime+=a.dt,b=Math.min(b,d.m_sleepTime))}if(b>=Box2D.Common.b2Settings.b2_timeToSleep)for(a=0;a<
this.m_bodies.length;a++)this.m_bodies[a].SetAwake(!1)};
Box2D.Dynamics.b2Island.prototype.SolveTOI=function(a){var b=0,c=0;this.m_contactSolver.Initialize(a,this.m_contacts,this.m_contacts.length);for(var d=this.m_contactSolver,b=0;b<this.m_joints.length;++b)this.m_joints[b].InitVelocityConstraints(a);for(b=0;b<a.velocityIterations;++b){d.SolveVelocityConstraints();for(c=0;c<this.m_joints.length;++c)this.m_joints[c].SolveVelocityConstraints(a)}for(b=0;b<this.m_nonStaticBodies.length;++b){var c=this.m_nonStaticBodies[b],e=a.dt*c.m_linearVelocity.x,f=a.dt*
c.m_linearVelocity.y;e*e+f*f>Box2D.Common.b2Settings.b2_maxTranslationSquared&&(c.m_linearVelocity.Normalize(),c.m_linearVelocity.x*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt,c.m_linearVelocity.y*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt);e=a.dt*c.m_angularVelocity;if(e*e>Box2D.Common.b2Settings.b2_maxRotationSquared)c.m_angularVelocity=c.m_angularVelocity<0?-Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt:Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt;c.m_sweep.c0.SetV(c.m_sweep.c);
c.m_sweep.a0=c.m_sweep.a;c.m_sweep.c.x+=a.dt*c.m_linearVelocity.x;c.m_sweep.c.y+=a.dt*c.m_linearVelocity.y;c.m_sweep.a+=a.dt*c.m_angularVelocity;c.SynchronizeTransform()}for(b=0;b<a.positionIterations;++b){e=d.SolvePositionConstraints(0.75);f=!0;for(c=0;c<this.m_joints.length;++c)var g=this.m_joints[c].SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte),f=f&&g;if(e&&f)break}this.Report(d.m_constraints)};
Box2D.Dynamics.b2Island.prototype.Report=function(a){if(this.m_listener!=null)for(var b=0;b<this.m_contacts.length;++b){var c=this.m_contacts[b],d=a[b];this.impulse.Reset();for(var e=0;e<d.pointCount;++e)this.impulse.normalImpulses[e]=d.points[e].normalImpulse,this.impulse.tangentImpulses[e]=d.points[e].tangentImpulse;this.m_listener.PostSolve(c,this.impulse)}};
Box2D.Dynamics.b2Island.prototype.AddBody=function(a){this.m_bodies.push(a);a.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&(this.m_nonStaticBodies.push(a),a.GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&this.m_dynamicBodies.push(a))};Box2D.Dynamics.b2Island.prototype.AddContact=function(a){this.m_contacts.push(a)};Box2D.Dynamics.b2Island.prototype.AddJoint=function(a){this.m_joints.push(a)};Box2D.Dynamics.Contacts.b2ContactRegister=function(){this.pool=null;this.poolCount=0};Box2D.Collision.b2DynamicTreePair=function(a,b){UsageTracker.get("Box2D.Collision.b2DynamicTreePair").trackCreate();this.fixtureA=a;this.fixtureB=b};Box2D.Collision.b2DynamicTreePair._freeCache=[];
Box2D.Collision.b2DynamicTreePair.Get=function(a,b){UsageTracker.get("Box2D.Collision.b2DynamicTreePair").trackGet();if(Box2D.Collision.b2DynamicTreePair._freeCache.length>0){var c=Box2D.Collision.b2DynamicTreePair._freeCache.pop();c.fixtureA=a;c.fixtureB=b;return c}return new Box2D.Collision.b2DynamicTreePair(a,b)};Box2D.Collision.b2DynamicTreePair.Free=function(a){a!=null&&(UsageTracker.get("Box2D.Collision.b2DynamicTreePair").trackFree(),Box2D.Collision.b2DynamicTreePair._freeCache.push(a))};Box2D.Dynamics.b2DebugDraw=function(){UsageTracker.get("Box2D.Dynamics.b2DebugDraw").trackCreate();this.m_xformScale=this.m_fillAlpha=this.m_alpha=this.m_lineThickness=this.m_drawScale=1;this.m_drawFlags=0;this.m_ctx=null};Box2D.Dynamics.b2DebugDraw.prototype.Clear=function(){this.m_ctx.clearRect(0,0,this.m_ctx.canvas.width,this.m_ctx.canvas.height)};Box2D.Dynamics.b2DebugDraw.prototype._color=function(a,b){return"rgba("+((a&16711680)>>16)+","+((a&65280)>>8)+","+(a&255)+","+b+")"};
Box2D.Dynamics.b2DebugDraw.prototype.SetFlags=function(a){this.m_drawFlags=a};Box2D.Dynamics.b2DebugDraw.prototype.GetFlags=function(){return this.m_drawFlags};Box2D.Dynamics.b2DebugDraw.prototype.AppendFlags=function(a){this.m_drawFlags|=a};Box2D.Dynamics.b2DebugDraw.prototype.ClearFlags=function(a){this.m_drawFlags&=~a};Box2D.Dynamics.b2DebugDraw.prototype.SetSprite=function(a){this.m_ctx=a};Box2D.Dynamics.b2DebugDraw.prototype.GetSprite=function(){return this.m_ctx};
Box2D.Dynamics.b2DebugDraw.prototype.SetDrawScale=function(a){this.m_drawScale=a};Box2D.Dynamics.b2DebugDraw.prototype.GetDrawScale=function(){return this.m_drawScale};Box2D.Dynamics.b2DebugDraw.prototype.SetLineThickness=function(a){this.m_lineThickness=a;this.m_ctx.strokeWidth=a};Box2D.Dynamics.b2DebugDraw.prototype.GetLineThickness=function(){return this.m_lineThickness};Box2D.Dynamics.b2DebugDraw.prototype.SetAlpha=function(a){this.m_alpha=a};Box2D.Dynamics.b2DebugDraw.prototype.GetAlpha=function(){return this.m_alpha};
Box2D.Dynamics.b2DebugDraw.prototype.SetFillAlpha=function(a){this.m_fillAlpha=a};Box2D.Dynamics.b2DebugDraw.prototype.GetFillAlpha=function(){return this.m_fillAlpha};Box2D.Dynamics.b2DebugDraw.prototype.SetXFormScale=function(a){this.m_xformScale=a};Box2D.Dynamics.b2DebugDraw.prototype.GetXFormScale=function(){return this.m_xformScale};
(function(a){a.prototype.DrawPolygon=function(a,c,d){if(c){var e=this.m_ctx,f=this.m_drawScale;e.beginPath();e.strokeStyle=this._color(d.GetColor(),this.m_alpha);e.moveTo(a[0].x*f,a[0].y*f);for(d=1;d<c;d++)e.lineTo(a[d].x*f,a[d].y*f);e.lineTo(a[0].x*f,a[0].y*f);e.closePath();e.stroke()}};a.prototype.DrawSolidPolygon=function(a,c,d){if(c){var e=this.m_ctx,f=this.m_drawScale;e.beginPath();e.strokeStyle=this._color(d.GetColor(),this.m_alpha);e.fillStyle=this._color(d.GetColor(),this.m_fillAlpha);e.moveTo(a[0].x*
f,a[0].y*f);for(d=1;d<c;d++)e.lineTo(a[d].x*f,a[d].y*f);e.lineTo(a[0].x*f,a[0].y*f);e.closePath();e.fill();e.stroke()}};a.prototype.DrawCircle=function(a,c,d){if(c){var e=this.m_ctx,f=this.m_drawScale;e.beginPath();e.strokeStyle=this._color(d.GetColor(),this.m_alpha);e.arc(a.x*f,a.y*f,c*f,0,Math.PI*2,!0);e.closePath();e.stroke()}};a.prototype.DrawSolidCircle=function(a,c,d,e){if(c){var f=this.m_ctx,g=this.m_drawScale,h=a.x*g,i=a.y*g;f.moveTo(0,0);f.beginPath();f.strokeStyle=this._color(e.GetColor(),
this.m_alpha);f.fillStyle=this._color(e.GetColor(),this.m_fillAlpha);f.arc(h,i,c*g,0,Math.PI*2,!0);f.moveTo(h,i);f.lineTo((a.x+d.x*c)*g,(a.y+d.y*c)*g);f.closePath();f.fill();f.stroke()}};a.prototype.DrawSegment=function(a,c,d){var e=this.m_ctx,f=this.m_drawScale;e.strokeStyle=this._color(d.GetColor(),this.m_alpha);e.beginPath();e.moveTo(a.x*f,a.y*f);e.lineTo(c.x*f,c.y*f);e.closePath();e.stroke()};a.prototype.DrawTransform=function(a){var c=this.m_ctx,d=this.m_drawScale;c.beginPath();c.strokeStyle=
this._color(16711680,this.m_alpha);c.moveTo(a.position.x*d,a.position.y*d);c.lineTo((a.position.x+this.m_xformScale*a.R.col1.x)*d,(a.position.y+this.m_xformScale*a.R.col1.y)*d);c.strokeStyle=this._color(65280,this.m_alpha);c.moveTo(a.position.x*d,a.position.y*d);c.lineTo((a.position.x+this.m_xformScale*a.R.col2.x)*d,(a.position.y+this.m_xformScale*a.R.col2.y)*d);c.closePath();c.stroke()}})(Box2D.Dynamics.b2DebugDraw);Box2D.Dynamics.b2DebugDraw.e_shapeBit=1;Box2D.Dynamics.b2DebugDraw.e_jointBit=2;
Box2D.Dynamics.b2DebugDraw.e_aabbBit=4;Box2D.Dynamics.b2DebugDraw.e_pairBit=8;Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit=16;Box2D.Dynamics.b2DebugDraw.e_controllerBit=32;Box2D.Collision.b2RayCastOutput=function(){UsageTracker.get("Box2D.Collision.b2RayCastOutput").trackCreate();this.normal=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Dynamics.iContactFilter=function(){};Box2D.Dynamics.iContactFilter.prototype.ShouldCollide=function(){};Box2D.Dynamics.b2ContactFilter=function(){UsageTracker.get("Box2D.Dynamics.b2ContactFilter").trackCreate()};Box2D.Dynamics.b2ContactFilter.prototype.ShouldCollide=function(a,b){var c=a.GetFilterData(),d=b.GetFilterData();return c.groupIndex==d.groupIndex&&c.groupIndex!=0?c.groupIndex>0:(c.maskBits&d.categoryBits)!=0&&(c.categoryBits&d.maskBits)!=0};Box2D.Dynamics.b2ContactFilter.b2_defaultFilter=new Box2D.Dynamics.b2ContactFilter;Box2D.Dynamics.Joints.b2MouseJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.target=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_mouseJoint;this.maxForce=0;this.frequencyHz=5;this.dampingRatio=0.7};goog.inherits(Box2D.Dynamics.Joints.b2MouseJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2MouseJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2MouseJoint(this)};Box2D.Dynamics.Contacts.b2ContactFactory=function(){this.m_registers={};this.m_freeContacts={};this.AddType(Box2D.Dynamics.Contacts.b2CircleContact,Box2D.Collision.Shapes.b2CircleShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolyAndCircleContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolygonContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2PolygonShape.NAME);
this.AddType(Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,Box2D.Collision.Shapes.b2EdgeShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2EdgeShape.NAME)};
Box2D.Dynamics.Contacts.b2ContactFactory.prototype.AddType=function(a,b,c){this.m_freeContacts[b]=this.m_freeContacts[b]||{};this.m_freeContacts[b][c]=this.m_freeContacts[b][c]||[];this.m_registers[b]=this.m_registers[b]||{};this.m_registers[b][c]=new Box2D.Dynamics.Contacts.b2ContactRegister;this.m_registers[b][c].ctor=a;this.m_registers[b][c].primary=!0;if(b!=c)this.m_registers[c]=this.m_registers[c]||{},this.m_registers[c][b]=new Box2D.Dynamics.Contacts.b2ContactRegister,this.m_registers[c][b].ctor=
a,this.m_registers[c][b].primary=!1};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.Create=function(a,b){UsageTracker.get("Box2D.Dynamics.Contacts.b2Contact").trackGet();var c=a.GetShape().GetTypeName(),d=b.GetShape().GetTypeName(),e=this.m_registers[c][d],f=e.ctor;return f!=null?e.primary?this.m_freeContacts[c][d].length>0?(c=this.m_freeContacts[c][d].pop(),c.Reset(a,b),c):new f(a,b):this.m_freeContacts[d][c].length>0?(c=this.m_freeContacts[d][c].pop(),c.Reset(b,a),c):new f(b,a):null};
Box2D.Dynamics.Contacts.b2ContactFactory.prototype.Destroy=function(a){UsageTracker.get("Box2D.Dynamics.Contacts.b2Contact").trackFree();var b=a.GetFixtureA().GetShape().GetTypeName(),c=a.GetFixtureB().GetShape().GetTypeName();this.m_freeContacts[b][c].push(a)};Box2D.Dynamics.b2ContactListener=function(){UsageTracker.get("Box2D.Dynamics.b2DebugDraw").trackCreate()};Box2D.Dynamics.b2ContactListener.prototype.BeginContact=function(){};Box2D.Dynamics.b2ContactListener.prototype.EndContact=function(){};Box2D.Dynamics.b2ContactListener.prototype.PreSolve=function(){};Box2D.Dynamics.b2ContactListener.prototype.PostSolve=function(){};Box2D.Dynamics.b2ContactListener.b2_defaultListener=new Box2D.Dynamics.b2ContactListener;Box2D.Collision.b2ContactPoint=function(){UsageTracker.get("Box2D.Collision.b2ContactPoint").trackCreate();this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.velocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.id=new Box2D.Collision.b2ContactID};Box2D.Collision.b2DynamicTreeBroadPhase=function(){UsageTracker.get("Box2D.Collision.b2DynamicTreeBroadPhase").trackCreate();this.m_tree=new Box2D.Collision.b2DynamicTree;this.m_moveBuffer=[];this.queryProxy=this.updatePairsCallback=this.lastQueryFixtureB=this.lastQueryFixtureA=null};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.CreateProxy=function(a,b){var c=this.m_tree.CreateProxy(a,b);this.BufferMove(c);return c};
Box2D.Collision.b2DynamicTreeBroadPhase.prototype.DestroyProxy=function(a){this.UnBufferMove(a);this.m_tree.DestroyProxy(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.MoveProxy=function(a,b,c){this.m_tree.MoveProxy(a,b,c)&&this.BufferMove(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.TestOverlap=function(a,b){var c=this.m_tree.GetFatAABB(a),d=this.m_tree.GetFatAABB(b);return c.TestOverlap(d)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.GetFatAABB=function(a){return this.m_tree.GetFatAABB(a)};
Box2D.Collision.b2DynamicTreeBroadPhase.prototype.UpdatePairs=function(a){this.lastQueryFixtureB=this.lastQueryFixtureA=null;for(this.updatePairsCallback=a;this.m_moveBuffer.length>0;)this.queryProxy=this.m_moveBuffer.pop(),this.m_tree.Query(this.QueryCallback,this.m_tree.GetFatAABB(this.queryProxy),this);this.queryProxy=this.updatePairsCallback=this.lastQueryFixtureB=this.lastQueryFixtureA=null};
Box2D.Collision.b2DynamicTreeBroadPhase.prototype.QueryCallback=function(a){if(a!=this.queryProxy.fixture&&!(this.queryProxy.fixture==this.lastQueryFixtureA&&a==this.lastQueryFixtureB)&&!(this.queryProxy.fixture==this.lastQueryFixtureB&&a==this.lastQueryFixtureA))this.updatePairsCallback(this.queryProxy.fixture,a),this.lastQueryFixtureA=this.queryProxy.fixture,this.lastQueryFixtureB=a;return!0};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.Query=function(a,b){this.m_tree.Query(a,b)};
Box2D.Collision.b2DynamicTreeBroadPhase.prototype.RayCast=function(a,b){this.m_tree.RayCast(a,b)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.Rebalance=function(a){this.m_tree.Rebalance(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.BufferMove=function(a){this.m_moveBuffer.push(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.UnBufferMove=function(a){goog.array.remove(this.m_moveBuffer,a)};Box2D.Collision.b2DynamicTreeBroadPhase.__implements={};
Box2D.Collision.b2DynamicTreeBroadPhase.__implements[Box2D.Collision.IBroadPhase]=!0;Box2D.Dynamics.b2ContactManager=function(a){UsageTracker.get("Box2D.Dynamics.b2ContactManager").trackCreate();this.m_world=a;this.m_contactFilter=Box2D.Dynamics.b2ContactFilter.b2_defaultFilter;this.m_contactListener=Box2D.Dynamics.b2ContactListener.b2_defaultListener;this.m_contactFactory=new Box2D.Dynamics.Contacts.b2ContactFactory;this.m_broadPhase=new Box2D.Collision.b2DynamicTreeBroadPhase};
Box2D.Dynamics.b2ContactManager.prototype.AddPair=function(a,b){var c=a.GetBody(),d=b.GetBody();if(c!=d&&d.ShouldCollide(c)&&this.m_contactFilter.ShouldCollide(a,b)){var e=!1;d.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(c){var d=c.GetFixtureA();if(d==a){if(c=c.GetFixtureB(),c==b)return e=!0}else if(d==b&&(c=c.GetFixtureB(),c==a))return e=!0});e||this.m_contactFactory.Create(a,b)}};
Box2D.Dynamics.b2ContactManager.prototype.FindNewContacts=function(){var a=this;this.m_broadPhase.UpdatePairs(function(b,c){a.AddPair(b,c)})};Box2D.Dynamics.b2ContactManager.prototype.Destroy=function(a){var b=a.GetFixtureA(),c=a.GetFixtureB(),b=b.GetBody(),c=c.GetBody();a.IsTouching()&&this.m_contactListener.EndContact(a);a.m_manifold.m_pointCount>0&&(b.SetAwake(!0),c.SetAwake(!0));a.RemoveFromLists();this.m_contactFactory.Destroy(a)};
Box2D.Dynamics.b2ContactManager.prototype.Collide=function(){var a=this;this.m_world.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(b){var c=b.GetFixtureA(),d=b.GetFixtureB(),e=c.GetBody(),f=d.GetBody();if(e.IsAwake()||f.IsAwake()){if(b.IsFiltering()){if(!f.ShouldCollide(e)){a.Destroy(b);return}if(!a.m_contactFilter.ShouldCollide(c,d)){a.Destroy(b);return}b.ClearFiltering()}a.m_broadPhase.TestOverlap(c.m_proxy,d.m_proxy)?b.Update(a.m_contactListener):a.Destroy(b)}})};
Box2D.Dynamics.b2ContactManager.s_evalCP=new Box2D.Collision.b2ContactPoint;Box2D.Dynamics.Joints.b2DistanceJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_length=a.length;this.m_frequencyHz=a.frequencyHz;this.m_dampingRatio=a.dampingRatio;this.m_bias=this.m_gamma=this.m_impulse=0};
goog.inherits(Box2D.Dynamics.Joints.b2DistanceJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetReactionForce=function(a){return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_u.x,a*this.m_impulse*this.m_u.y)};
Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetReactionTorque=function(){return 0};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetLength=function(){return this.m_length};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetLength=function(a){this.m_length=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetFrequency=function(){return this.m_frequencyHz};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetFrequency=function(a){this.m_frequencyHz=a};
Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetDampingRatio=function(){return this.m_dampingRatio};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetDampingRatio=function(a){this.m_dampingRatio=a};
Box2D.Dynamics.Joints.b2DistanceJoint.prototype.InitVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB;b=d.m_xf.R;var f=this.m_localAnchor1.x-d.m_sweep.localCenter.x,g=this.m_localAnchor1.y-d.m_sweep.localCenter.y,c=b.col1.x*f+b.col2.x*g,g=b.col1.y*f+b.col2.y*g,f=c;b=e.m_xf.R;var h=this.m_localAnchor2.x-e.m_sweep.localCenter.x,i=this.m_localAnchor2.y-e.m_sweep.localCenter.y,c=b.col1.x*h+b.col2.x*i,i=b.col1.y*h+b.col2.y*i,h=c;this.m_u.x=e.m_sweep.c.x+h-d.m_sweep.c.x-f;this.m_u.y=
e.m_sweep.c.y+i-d.m_sweep.c.y-g;c=Math.sqrt(this.m_u.x*this.m_u.x+this.m_u.y*this.m_u.y);c>Box2D.Common.b2Settings.b2_linearSlop?this.m_u.Multiply(1/c):this.m_u.SetZero();b=f*this.m_u.y-g*this.m_u.x;var j=h*this.m_u.y-i*this.m_u.x;b=d.m_invMass+d.m_invI*b*b+e.m_invMass+e.m_invI*j*j;this.m_mass=b!=0?1/b:0;if(this.m_frequencyHz>0){c-=this.m_length;var j=2*Math.PI*this.m_frequencyHz,k=this.m_mass*j*j;this.m_gamma=a.dt*(2*this.m_mass*this.m_dampingRatio*j+a.dt*k);this.m_gamma=this.m_gamma!=0?1/this.m_gamma:
0;this.m_bias=c*a.dt*k*this.m_gamma;this.m_mass=b+this.m_gamma;this.m_mass=this.m_mass!=0?1/this.m_mass:0}a.warmStarting?(this.m_impulse*=a.dtRatio,a=this.m_impulse*this.m_u.x,b=this.m_impulse*this.m_u.y,d.m_linearVelocity.x-=d.m_invMass*a,d.m_linearVelocity.y-=d.m_invMass*b,d.m_angularVelocity-=d.m_invI*(f*b-g*a),e.m_linearVelocity.x+=e.m_invMass*a,e.m_linearVelocity.y+=e.m_invMass*b,e.m_angularVelocity+=e.m_invI*(h*b-i*a)):this.m_impulse=0};
Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SolveVelocityConstraints=function(){var a=this.m_localAnchor1.x-this.m_bodyA.m_sweep.localCenter.x,b=this.m_localAnchor1.y-this.m_bodyA.m_sweep.localCenter.y,c=this.m_bodyA.m_xf.R.col1.x*a+this.m_bodyA.m_xf.R.col2.x*b,b=this.m_bodyA.m_xf.R.col1.y*a+this.m_bodyA.m_xf.R.col2.y*b,a=c,d=this.m_localAnchor2.x-this.m_bodyB.m_sweep.localCenter.x,e=this.m_localAnchor2.y-this.m_bodyB.m_sweep.localCenter.y,c=this.m_bodyB.m_xf.R.col1.x*d+this.m_bodyB.m_xf.R.col2.x*
e,e=this.m_bodyB.m_xf.R.col1.y*d+this.m_bodyB.m_xf.R.col2.y*e,d=c,f=-this.m_mass*(this.m_u.x*(this.m_bodyB.m_linearVelocity.x-this.m_bodyB.m_angularVelocity*e-(this.m_bodyA.m_linearVelocity.x-this.m_bodyA.m_angularVelocity*b))+this.m_u.y*(this.m_bodyB.m_linearVelocity.y+this.m_bodyB.m_angularVelocity*d-(this.m_bodyA.m_linearVelocity.y+this.m_bodyA.m_angularVelocity*a))+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=f;c=f*this.m_u.x;f*=this.m_u.y;this.m_bodyA.m_linearVelocity.x-=this.m_bodyA.m_invMass*
c;this.m_bodyA.m_linearVelocity.y-=this.m_bodyA.m_invMass*f;this.m_bodyA.m_angularVelocity-=this.m_bodyA.m_invI*(a*f-b*c);this.m_bodyB.m_linearVelocity.x+=this.m_bodyB.m_invMass*c;this.m_bodyB.m_linearVelocity.y+=this.m_bodyB.m_invMass*f;this.m_bodyB.m_angularVelocity+=this.m_bodyB.m_invI*(d*f-e*c)};
Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SolvePositionConstraints=function(){if(this.m_frequencyHz>0)return!0;var a=this.m_localAnchor1.x-this.m_bodyA.m_sweep.localCenter.x,b=this.m_localAnchor1.y-this.m_bodyA.m_sweep.localCenter.y,c=this.m_bodyA.m_xf.R.col1.x*a+this.m_bodyA.m_xf.R.col2.x*b,b=this.m_bodyA.m_xf.R.col1.y*a+this.m_bodyA.m_xf.R.col2.y*b,a=c,d=this.m_localAnchor2.x-this.m_bodyB.m_sweep.localCenter.x,e=this.m_localAnchor2.y-this.m_bodyB.m_sweep.localCenter.y,c=this.m_bodyB.m_xf.R.col1.x*
d+this.m_bodyB.m_xf.R.col2.x*e,e=this.m_bodyB.m_xf.R.col1.y*d+this.m_bodyB.m_xf.R.col2.y*e,d=c,f=this.m_bodyB.m_sweep.c.x+d-this.m_bodyA.m_sweep.c.x-a,g=this.m_bodyB.m_sweep.c.y+e-this.m_bodyA.m_sweep.c.y-b,c=Math.sqrt(f*f+g*g);f/=c;g/=c;var c=Box2D.Common.Math.b2Math.Clamp(c-this.m_length,-Box2D.Common.b2Settings.b2_maxLinearCorrection,Box2D.Common.b2Settings.b2_maxLinearCorrection),h=-this.m_mass*c;this.m_u.Set(f,g);f=h*this.m_u.x;g=h*this.m_u.y;this.m_bodyA.m_sweep.c.x-=this.m_bodyA.m_invMass*
f;this.m_bodyA.m_sweep.c.y-=this.m_bodyA.m_invMass*g;this.m_bodyA.m_sweep.a-=this.m_bodyA.m_invI*(a*g-b*f);this.m_bodyB.m_sweep.c.x+=this.m_bodyB.m_invMass*f;this.m_bodyB.m_sweep.c.y+=this.m_bodyB.m_invMass*g;this.m_bodyB.m_sweep.a+=this.m_bodyB.m_invI*(d*g-e*f);this.m_bodyA.SynchronizeTransform();this.m_bodyB.SynchronizeTransform();return Math.abs(c)<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2DistanceJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_distanceJoint;this.length=1;this.dampingRatio=this.frequencyHz=0};goog.inherits(Box2D.Dynamics.Joints.b2DistanceJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2DistanceJointDef.prototype.Initialize=function(a,b,c,d){this.bodyA=a;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(d));a=d.x-c.x;c=d.y-c.y;this.length=Math.sqrt(a*a+c*c);this.dampingRatio=this.frequencyHz=0};Box2D.Dynamics.Joints.b2DistanceJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2DistanceJoint(this)};Box2D.Dynamics.Controllers.b2BuoyancyController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.normal=Box2D.Common.Math.b2Vec2.Get(0,-1);this.density=this.offset=0;this.velocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearDrag=2;this.angularDrag=1;this.useDensity=!1;this.useWorldGravity=!0;this.gravity=null};goog.inherits(Box2D.Dynamics.Controllers.b2BuoyancyController,Box2D.Dynamics.Controllers.b2Controller);
Box2D.Dynamics.Controllers.b2BuoyancyController.prototype.Step=function(){if(this.useWorldGravity)this.gravity=this.m_world.GetGravity();for(var a=Box2D.Common.Math.b2Vec2.Get(0,0),b=Box2D.Common.Math.b2Vec2.Get(0,0),c=Box2D.Common.Math.b2Vec2.Get(0,0),d=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);d;d=d.GetNextNode()){b.Set(0,0);a.Set(0,0);for(var e=d.body,f=0,g=0,h=e.GetFixtureList().GetFirstNode();h;h=h.GetNextNode()){c.Set(0,0);var i=h.fixture.GetShape().ComputeSubmergedArea(this.normal,
this.offset,e.GetTransform(),c);f+=i;a.x+=i*c.x;a.y+=i*c.y;var j=0,j=1;g+=i*j;b.x+=i*c.x*j;b.y+=i*c.y*j}f<Number.MIN_VALUE||(a.x/=f,a.y/=f,b.x/=g,b.y/=g,g=this.gravity.GetNegative(),g.Multiply(this.density*f),e.ApplyForce(g,b),Box2D.Common.Math.b2Vec2.Free(g),g=e.GetLinearVelocityFromWorldPoint(a),g.Subtract(this.velocity),g.Multiply(-this.linearDrag*f),e.ApplyForce(g,a),Box2D.Common.Math.b2Vec2.Free(g),e.ApplyTorque(-e.GetInertia()/e.GetMass()*f*e.GetAngularVelocity()*this.angularDrag))}Box2D.Common.Math.b2Vec2.Free(c);
Box2D.Common.Math.b2Vec2.Free(b);Box2D.Common.Math.b2Vec2.Free(a)};Box2D.Dynamics.Controllers.b2BuoyancyController.prototype.Draw=function(a){var b=Box2D.Common.Math.b2Vec2.Get(this.normal.x*this.offset+this.normal.y*1E3,this.normal.y*this.offset-this.normal.x*1E3),c=Box2D.Common.Math.b2Vec2.Get(this.normal.x*this.offset-this.normal.y*1E3,this.normal.y*this.offset+this.normal.x*1E3);a.DrawSegment(b,c,Box2D.Dynamics.Controllers.b2BuoyancyController.color);Box2D.Common.Math.b2Vec2.Free(b);Box2D.Common.Math.b2Vec2.Free(c)};
Box2D.Dynamics.Controllers.b2BuoyancyController.color=new Box2D.Common.b2Color(0,0,1);Box2D.Dynamics.Controllers.b2GravityController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.G=1;this.invSqr=!0};goog.inherits(Box2D.Dynamics.Controllers.b2GravityController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2GravityController.prototype.Step=function(){this.invSqr?this._StepInvSq():this._Step()};
Box2D.Dynamics.Controllers.b2GravityController.prototype._StepInvSq=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);a;a=a.GetNextNode())for(var b=a.body,c=b.GetWorldCenter(),d=b.GetMass(),e=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);e;e=e.GetNextNode()){var f=e.body;if(b.IsAwake()||f.IsAwake()){var g=f.GetWorldCenter(),h=g.x-c.x,i=g.y-c.y,j=h*h+i*i;j<Number.MIN_VALUE||(h=Box2D.Common.Math.b2Vec2.Get(h,i),h.Multiply(this.G/j/Math.sqrt(j)*
d*f.GetMass()),b.IsAwake()&&b.ApplyForce(h,c),h.Multiply(-1),f.IsAwake()&&f.ApplyForce(h,g),Box2D.Common.Math.b2Vec2.Free(h))}}};
Box2D.Dynamics.Controllers.b2GravityController.prototype._Step=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);a;a=a.GetNextNode())for(var b=a.body,c=b.GetWorldCenter(),d=b.GetMass(),e=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);e;e=e.GetNextNode()){var f=e.body;if(b.IsAwake()||f.IsAwake()){var g=f.GetWorldCenter(),h=g.x-c.x,i=g.y-c.y,j=h*h+i*i;j<Number.MIN_VALUE||(h=Box2D.Common.Math.b2Vec2.Get(h,i),h.Multiply(this.G/j*d*f.GetMass()),
b.IsAwake()&&b.ApplyForce(h,c),h.Multiply(-1),f.IsAwake()&&f.ApplyForce(h,g),Box2D.Common.Math.b2Vec2.Free(h))}}};goog.structs={};goog.structs.Queue=function(){this.elements_=[]};goog.structs.Queue.prototype.head_=0;goog.structs.Queue.prototype.tail_=0;goog.structs.Queue.prototype.enqueue=function(a){this.elements_[this.tail_++]=a};goog.structs.Queue.prototype.dequeue=function(){if(this.head_!=this.tail_){var a=this.elements_[this.head_];delete this.elements_[this.head_];this.head_++;return a}};goog.structs.Queue.prototype.peek=function(){return this.head_==this.tail_?void 0:this.elements_[this.head_]};
goog.structs.Queue.prototype.getCount=function(){return this.tail_-this.head_};goog.structs.Queue.prototype.isEmpty=function(){return this.tail_-this.head_==0};goog.structs.Queue.prototype.clear=function(){this.tail_=this.head_=this.elements_.length=0};goog.structs.Queue.prototype.contains=function(a){return goog.array.contains(this.elements_,a)};
goog.structs.Queue.prototype.remove=function(a){a=goog.array.indexOf(this.elements_,a);if(a<0)return!1;a==this.head_?this.dequeue():(goog.array.removeAt(this.elements_,a),this.tail_--);return!0};goog.structs.Queue.prototype.getValues=function(){return this.elements_.slice(this.head_,this.tail_)};Box2D.Collision.b2WorldManifold=function(){UsageTracker.get("Box2D.Collision.b2WorldManifold").trackCreate();this.m_normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_points=[];for(var a=this.m_pointCount=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a]=Box2D.Common.Math.b2Vec2.Get(0,0)};
Box2D.Collision.b2WorldManifold.prototype.Initialize=function(a,b,c,d,e){if(a.m_pointCount!=0){var f=0,g,h,i=0,j=0,k=0,l=0,n=0;g=0;switch(a.m_type){case Box2D.Collision.b2Manifold.e_circles:h=b.R;g=a.m_localPoint;f=b.position.x+h.col1.x*g.x+h.col2.x*g.y;b=b.position.y+h.col1.y*g.x+h.col2.y*g.y;h=d.R;g=a.m_points[0].m_localPoint;a=d.position.x+h.col1.x*g.x+h.col2.x*g.y;d=d.position.y+h.col1.y*g.x+h.col2.y*g.y;g=a-f;h=d-b;i=g*g+h*h;i>Box2D.Common.b2Settings.MIN_VALUE_SQUARED?(i=Math.sqrt(i),this.m_normal.x=
g/i,this.m_normal.y=h/i):(this.m_normal.x=1,this.m_normal.y=0);g=b+c*this.m_normal.y;d-=e*this.m_normal.y;this.m_points[0].x=0.5*(f+c*this.m_normal.x+(a-e*this.m_normal.x));this.m_points[0].y=0.5*(g+d);break;case Box2D.Collision.b2Manifold.e_faceA:h=b.R;g=a.m_localPlaneNormal;i=h.col1.x*g.x+h.col2.x*g.y;j=h.col1.y*g.x+h.col2.y*g.y;h=b.R;g=a.m_localPoint;k=b.position.x+h.col1.x*g.x+h.col2.x*g.y;l=b.position.y+h.col1.y*g.x+h.col2.y*g.y;this.m_normal.x=i;this.m_normal.y=j;for(f=0;f<a.m_pointCount;f++)h=
d.R,g=a.m_points[f].m_localPoint,n=d.position.x+h.col1.x*g.x+h.col2.x*g.y,g=d.position.y+h.col1.y*g.x+h.col2.y*g.y,this.m_points[f].x=n+0.5*(c-(n-k)*i-(g-l)*j-e)*i,this.m_points[f].y=g+0.5*(c-(n-k)*i-(g-l)*j-e)*j;break;case Box2D.Collision.b2Manifold.e_faceB:h=d.R;g=a.m_localPlaneNormal;i=h.col1.x*g.x+h.col2.x*g.y;j=h.col1.y*g.x+h.col2.y*g.y;h=d.R;g=a.m_localPoint;k=d.position.x+h.col1.x*g.x+h.col2.x*g.y;l=d.position.y+h.col1.y*g.x+h.col2.y*g.y;this.m_normal.x=-i;this.m_normal.y=-j;for(f=0;f<a.m_pointCount;f++)h=
b.R,g=a.m_points[f].m_localPoint,n=b.position.x+h.col1.x*g.x+h.col2.x*g.y,g=b.position.y+h.col1.y*g.x+h.col2.y*g.y,this.m_points[f].x=n+0.5*(e-(n-k)*i-(g-l)*j-c)*i,this.m_points[f].y=g+0.5*(e-(n-k)*i-(g-l)*j-c)*j}}};Box2D.Dynamics.Contacts.b2ContactSolver=function(){this.m_constraints=[]};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.Initialize=function(a,b,c){for(this.m_constraintCount=c;this.m_constraints.length<this.m_constraintCount;)this.m_constraints[this.m_constraints.length]=new Box2D.Dynamics.Contacts.b2ContactConstraint;for(a=0;a<c;a++){var d=b[a],e=d.m_fixtureA,f=d.m_fixtureB,g=e.m_shape.m_radius,h=f.m_shape.m_radius,i=e.GetBody(),j=f.GetBody(),k=d.GetManifold(),l=Box2D.Common.b2Settings.b2MixFriction(e.GetFriction(),f.GetFriction()),n=Box2D.Common.b2Settings.b2MixRestitution(e.GetRestitution(),
f.GetRestitution()),m=i.m_linearVelocity.x,o=i.m_linearVelocity.y,p=j.m_linearVelocity.x,q=j.m_linearVelocity.y,r=i.m_angularVelocity,x=j.m_angularVelocity;Box2D.Common.b2Settings.b2Assert(k.m_pointCount>0);Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.Initialize(k,i.GetTransform(),g,j.GetTransform(),h);f=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_normal.x;d=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_normal.y;e=this.m_constraints[a];e.bodyA=i;e.bodyB=j;e.manifold=
k;e.normal.x=f;e.normal.y=d;e.pointCount=k.m_pointCount;e.friction=l;e.restitution=n;e.localPlaneNormal.x=k.m_localPlaneNormal.x;e.localPlaneNormal.y=k.m_localPlaneNormal.y;e.localPoint.x=k.m_localPoint.x;e.localPoint.y=k.m_localPoint.y;e.radius=g+h;e.type=k.m_type;for(g=0;g<e.pointCount;++g){l=k.m_points[g];h=e.points[g];h.normalImpulse=l.m_normalImpulse;h.tangentImpulse=l.m_tangentImpulse;h.localPoint.SetV(l.m_localPoint);var l=h.rA.x=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[g].x-
i.GetWorldCenter().x,n=h.rA.y=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[g].y-i.GetWorldCenter().y,v=h.rB.x=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[g].x-j.GetWorldCenter().x,w=h.rB.y=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[g].y-j.GetWorldCenter().y,t=l*d-n*f,s=v*d-w*f;t*=t;s*=s;var u=i.GetInverseMass()+j.GetInverseMass()+i.GetInverseInertia()*t+j.GetInverseInertia()*s;h.normalMass=1/u;u=i.m_mass*i.GetInverseMass()+j.m_mass*j.GetInverseMass();
u+=i.m_mass*i.GetInverseInertia()*t+j.m_mass*j.GetInverseInertia()*s;h.equalizedMass=1/u;s=d;u=-f;t=l*u-n*s;s=v*u-w*s;t*=t;s*=s;t=i.GetInverseMass()+j.GetInverseMass()+i.GetInverseInertia()*t+j.GetInverseInertia()*s;h.tangentMass=1/t;h.velocityBias=0;l=e.normal.x*(p+-x*w-m- -r*n)+e.normal.y*(q+x*v-o-r*l);l<-Box2D.Common.b2Settings.b2_velocityThreshold&&(h.velocityBias+=-e.restitution*l)}if(e.pointCount==2)q=e.points[0],p=e.points[1],k=i.GetInverseMass(),i=i.GetInverseInertia(),m=j.GetInverseMass(),
j=j.GetInverseInertia(),o=q.rA.x*d-q.rA.y*f,q=q.rB.x*d-q.rB.y*f,r=p.rA.x*d-p.rA.y*f,p=p.rB.x*d-p.rB.y*f,f=k+m+i*o*o+j*q*q,d=k+m+i*r*r+j*p*p,j=k+m+i*o*r+j*q*p,f*f<100*(f*d-j*j)?(e.K.col1.Set(f,j),e.K.col2.Set(j,d),e.K.GetInverse(e.normalMass)):e.pointCount=1}};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.InitVelocityConstraints=function(a){for(var b=0;b<this.m_constraintCount;++b){var c=this.m_constraints[b],d=c.bodyA,e=c.bodyB,f=d.GetInverseMass(),g=d.GetInverseInertia(),h=e.GetInverseMass(),i=e.GetInverseInertia(),j=c.normal.x,k=c.normal.y,l=k,n=-j,m=0,o=0;if(a.warmStarting){o=c.pointCount;for(m=0;m<o;++m){var p=c.points[m];p.normalImpulse*=a.dtRatio;p.tangentImpulse*=a.dtRatio;var q=p.normalImpulse*j+p.tangentImpulse*l,r=p.normalImpulse*k+p.tangentImpulse*
n;d.m_angularVelocity-=g*(p.rA.x*r-p.rA.y*q);d.m_linearVelocity.x-=f*q;d.m_linearVelocity.y-=f*r;e.m_angularVelocity+=i*(p.rB.x*r-p.rB.y*q);e.m_linearVelocity.x+=h*q;e.m_linearVelocity.y+=h*r}}else{o=c.pointCount;for(m=0;m<o;++m)d=c.points[m],d.normalImpulse=0,d.tangentImpulse=0}}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints=function(){for(var a=0;a<this.m_constraintCount;a++)this.SolveVelocityConstraints_Constraint(this.m_constraints[a])};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_Constraint=function(a){for(var b=a.normal.x,c=a.normal.y,d=0;d<a.pointCount;d++)Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPoint(a,a.points[d]);if(a.pointCount==1){var d=a.points[0],e=d.normalImpulse-d.normalMass*((a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*d.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*d.rA.y)*b+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*
d.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*d.rA.x)*c-d.velocityBias),e=e>0?e:0,f=e-d.normalImpulse,g=f*b;c*=f;a.bodyA.m_linearVelocity.x-=a.bodyA.GetInverseMass()*g;a.bodyA.m_linearVelocity.y-=a.bodyA.GetInverseMass()*c;a.bodyA.m_angularVelocity-=a.bodyA.GetInverseInertia()*(d.rA.x*c-d.rA.y*g);a.bodyB.m_linearVelocity.x+=a.bodyB.GetInverseMass()*g;a.bodyB.m_linearVelocity.y+=a.bodyB.GetInverseMass()*c;a.bodyB.m_angularVelocity+=a.bodyB.GetInverseInertia()*(d.rB.x*c-d.rB.y*g);d.normalImpulse=
e}else{var d=a.points[0],e=a.points[1],f=d.normalImpulse,g=e.normalImpulse,h=(a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*d.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*d.rA.y)*b+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*d.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*d.rA.x)*c-d.velocityBias,c=(a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*e.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*e.rA.y)*b+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*
e.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*e.rA.x)*c-e.velocityBias;h-=a.K.col1.x*f+a.K.col2.x*g;for(c-=a.K.col1.y*f+a.K.col2.y*g;;){b=-(a.normalMass.col1.x*h+a.normalMass.col2.x*c);if(b>=0){var i=-(a.normalMass.col1.y*h+a.normalMass.col2.y*c);if(i>=0){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,b-f,i-g);d.normalImpulse=b;e.normalImpulse=i;break}}b=-d.normalMass*h;if(b>=0&&a.K.col1.y*b+c>=0){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,b-f,-g);d.normalImpulse=
b;e.normalImpulse=0;break}b=-e.normalMass*c;if(b>=0&&a.K.col2.x*b+h>=0){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,-f,b-g);d.normalImpulse=0;e.normalImpulse=b;break}if(h>=0&&c>=0){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,-f,-g);d.normalImpulse=0;e.normalImpulse=0;break}break}}};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPoint=function(a,b){var c=a.normal.y,d=-a.normal.x,e=a.friction*b.normalImpulse,e=Box2D.Common.Math.b2Math.Clamp(b.tangentImpulse-b.tangentMass*((a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*b.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*b.rA.y)*c+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*b.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*b.rA.x)*d),-e,e),f=e-b.tangentImpulse;
c*=f;d*=f;a.bodyA.m_linearVelocity.x-=a.bodyA.GetInverseMass()*c;a.bodyA.m_linearVelocity.y-=a.bodyA.GetInverseMass()*d;a.bodyA.m_angularVelocity-=a.bodyA.GetInverseInertia()*(b.rA.x*d-b.rA.y*c);a.bodyB.m_linearVelocity.x+=a.bodyB.GetInverseMass()*c;a.bodyB.m_linearVelocity.y+=a.bodyB.GetInverseMass()*d;a.bodyB.m_angularVelocity+=a.bodyB.GetInverseInertia()*(b.rB.x*d-b.rB.y*c);b.tangentImpulse=e};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPointUpdate=function(a,b,c,d,e){var f=d*a.normal.x;d*=a.normal.y;var g=e*a.normal.x;e*=a.normal.y;a.bodyA.m_linearVelocity.x-=a.bodyA.GetInverseMass()*(f+g);a.bodyA.m_linearVelocity.y-=a.bodyA.GetInverseMass()*(d+e);a.bodyA.m_angularVelocity-=a.bodyA.GetInverseInertia()*(b.rA.x*d-b.rA.y*f+c.rA.x*e-c.rA.y*g);a.bodyB.m_linearVelocity.x+=a.bodyB.GetInverseMass()*(f+g);a.bodyB.m_linearVelocity.y+=a.bodyB.GetInverseMass()*
(d+e);a.bodyB.m_angularVelocity+=a.bodyB.GetInverseInertia()*(b.rB.x*d-b.rB.y*f+c.rB.x*e-c.rB.y*g);b.normalImpulse=0;c.normalImpulse=0};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.FinalizeVelocityConstraints=function(){for(var a=0;a<this.m_constraintCount;++a)for(var b=this.m_constraints[a],c=b.manifold,d=0;d<b.pointCount;++d){var e=c.m_points[d],f=b.points[d];e.m_normalImpulse=f.normalImpulse;e.m_tangentImpulse=f.tangentImpulse}};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolvePositionConstraints=function(a){a===void 0&&(a=0);for(var b=0,c=0;c<this.m_constraintCount;c++){var d=this.m_constraints[c],e=d.bodyA,f=d.bodyB,g=e.m_mass*e.GetInverseMass(),h=e.m_mass*e.GetInverseInertia(),i=f.m_mass*f.GetInverseMass(),j=f.m_mass*f.GetInverseInertia();Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.Initialize(d);for(var k=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_normal,l=0;l<d.pointCount;l++){var n=d.points[l],m=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_points[l],
o=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_separations[l],p=m.x-e.GetWorldCenter().x,q=m.y-e.GetWorldCenter().y,r=m.x-f.GetWorldCenter().x,m=m.y-f.GetWorldCenter().y,b=b<o?b:o,o=Box2D.Common.Math.b2Math.Clamp(a*(o+Box2D.Common.b2Settings.b2_linearSlop),-Box2D.Common.b2Settings.b2_maxLinearCorrection,0);o*=-n.equalizedMass;n=o*k.x;o*=k.y;e.GetWorldCenter().x-=g*n;e.GetWorldCenter().y-=g*o;e.SetCalculatedAngle(e.GetAngle()-h*(p*o-q*n));e.SynchronizeTransform();f.GetWorldCenter().x+=i*n;f.GetWorldCenter().y+=
i*o;f.SetCalculatedAngle(f.GetAngle()+j*(r*o-m*n));f.SynchronizeTransform()}}return b>-1.5*Box2D.Common.b2Settings.b2_linearSlop};
Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolvePositionConstraints_NEW=function(a){a===void 0&&(a=0);for(var b=0,c=0;c<this.m_constraintCount;c++){var d=this.m_constraints[c],e=d.bodyA,f=d.bodyB,g=e.m_mass*e.GetInverseMass(),h=e.m_mass*e.GetInverseInertia(),i=f.m_mass*f.GetInverseMass(),j=f.m_mass*f.GetInverseInertia();Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.Initialize(d);for(var k=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_normal,l=0;l<d.pointCount;l++){var n=d.points[l],m=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_points[l],
o=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_separations[l],p=m.x-e.GetWorldCenter().x,q=m.y-e.GetWorldCenter().y,r=m.x-f.GetWorldCenter().x,m=m.y-f.GetWorldCenter().y;o<b&&(b=o);a!=0&&Box2D.Common.Math.b2Math.Clamp(a*(o+Box2D.Common.b2Settings.b2_linearSlop),-Box2D.Common.b2Settings.b2_maxLinearCorrection,0);o=-n.equalizedMass*0;n=o*k.x;o*=k.y;e.GetWorldCenter().x-=g*n;e.GetWorldCenter().y-=g*o;e.SetAngle(e.GetAngle()-h*(p*o-q*n));e.SynchronizeTransform();f.GetWorldCenter().x+=i*n;f.GetWorldCenter().y+=
i*o;f.SetAngle(f.GetAngle()+j*(r*o-m*n));f.SynchronizeTransform()}}return b>-1.5*Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold=new Box2D.Collision.b2WorldManifold;Box2D.Dynamics.Contacts.b2ContactSolver.s_psm=new Box2D.Dynamics.Contacts.b2PositionSolverManifold;Box2D.Dynamics.Controllers.b2ControllerListNode=function(a){this.controller=a;this.previous=this.next=null};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.Controllers.b2ControllerList=function(){this.controllerLastNode=this.controllerFirstNode=null;this.controllerNodeLookup={};this.controllerCount=0};Box2D.Dynamics.Controllers.b2ControllerList.prototype.GetFirstNode=function(){return this.controllerFirstNode};
Box2D.Dynamics.Controllers.b2ControllerList.prototype.AddController=function(a){var b=a.ID;if(this.controllerNodeLookup[b]==null){var a=new Box2D.Dynamics.Controllers.b2ControllerListNode(a),c=this.controllerLastNode;c!=null?c.SetNextNode(a):this.controllerFirstNode=a;a.SetPreviousNode(c);this.controllerLastNode=a;this.controllerNodeLookup[b]=a;this.controllerCount++}};
Box2D.Dynamics.Controllers.b2ControllerList.prototype.RemoveController=function(a){var a=a.ID,b=this.controllerNodeLookup[a];if(b!=null){var c=b.GetPreviousNode(),b=b.GetNextNode();c==null?this.controllerFirstNode=b:c.SetNextNode(b);b==null?this.controllerLastNode=c:b.SetPreviousNode(c);delete this.controllerNodeLookup[a];this.controllerCount--}};Box2D.Dynamics.Controllers.b2ControllerList.prototype.GetControllerCount=function(){return this.controllerCount};Box2D.Dynamics.b2FixtureDef=function(){UsageTracker.get("Box2D.Dynamics.b2FixtureDef").trackCreate();this.filter=new Box2D.Dynamics.b2FilterData;this.filter.categoryBits=1;this.filter.maskBits=65535;this.filter.groupIndex=0;this.shape=null;this.friction=0.2;this.density=this.restitution=0;this.isSensor=!1};Box2D.Dynamics.b2Body=function(a,b){UsageTracker.get("Box2D.Dynamics.b2Body").trackCreate();this.ID="Body"+Box2D.Dynamics.b2Body.NEXT_ID++;this.m_xf=new Box2D.Common.Math.b2Transform;this.m_xf.position.SetV(a.position);this.m_xf.R.Set(a.angle);this.m_sweep=new Box2D.Common.Math.b2Sweep;this.m_sweep.localCenter.SetZero();this.m_sweep.t0=1;this.m_sweep.a0=this.m_sweep.a=a.angle;this.m_sweep.c.x=this.m_xf.R.col1.x*this.m_sweep.localCenter.x+this.m_xf.R.col2.x*this.m_sweep.localCenter.y;this.m_sweep.c.y=
this.m_xf.R.col1.y*this.m_sweep.localCenter.x+this.m_xf.R.col2.y*this.m_sweep.localCenter.y;this.m_sweep.c.x+=this.m_xf.position.x;this.m_sweep.c.y+=this.m_xf.position.y;this.m_sweep.c0.SetV(this.m_sweep.c);this.m_linearVelocity=a.linearVelocity.Copy();this.m_force=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_bullet=a.bullet;this.m_fixedRotation=a.fixedRotation;this.m_allowSleep=a.allowSleep;this.m_awake=a.awake;this.m_active=a.active;this.m_world=b;this.m_jointList=null;this.contactList=new Box2D.Dynamics.Contacts.b2ContactList;
this.controllerList=new Box2D.Dynamics.Controllers.b2ControllerList;this.m_controllerCount=0;this.m_angularVelocity=a.angularVelocity;this.m_linearDamping=a.linearDamping;this.m_angularDamping=a.angularDamping;this.m_sleepTime=this.m_torque=0;this.m_type=a.type;this.m_mass=this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?1:0;this.m_invMass=this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?1:0;this.m_invI=this.m_I=0;this.m_inertiaScale=a.inertiaScale;this.fixtureList=new Box2D.Dynamics.b2FixtureList;
this.m_lists=[]};Box2D.Dynamics.b2Body.prototype.CreateFixture=function(a){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());a=new Box2D.Dynamics.b2Fixture(this,this.m_xf,a);this.m_active&&a.CreateProxy(this.m_world.m_contactManager.m_broadPhase,this.m_xf);this.fixtureList.AddFixture(a);a.m_body=this;a.m_density>0&&this.ResetMassData();this.m_world.m_newFixture=!0;return a};
Box2D.Dynamics.b2Body.prototype.CreateFixture2=function(a,b){var c=new Box2D.Dynamics.b2FixtureDef;c.shape=a;c.density=b;return this.CreateFixture(c)};Box2D.Dynamics.b2Body.prototype.Destroy=function(){Box2D.Common.Math.b2Vec2.Free(this.m_linearVelocity);Box2D.Common.Math.b2Vec2.Free(this.m_force)};
Box2D.Dynamics.b2Body.prototype.DestroyFixture=function(a){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());this.fixtureList.RemoveFixture(a);var b=this;this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(c){(a==c.GetFixtureA()||a==c.GetFixtureB())&&b.m_world.m_contactManager.Destroy(c)});this.m_active&&a.DestroyProxy(this.m_world.m_contactManager.m_broadPhase);a.Destroy();this.ResetMassData()};
Box2D.Dynamics.b2Body.prototype.SetPositionAndAngle=function(a,b){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());this.m_xf.R.Set(b);this.m_xf.position.SetV(a);var c=this.m_xf.R,d=this.m_sweep.localCenter;this.m_sweep.c.x=c.col1.x*d.x+c.col2.x*d.y;this.m_sweep.c.y=c.col1.y*d.x+c.col2.y*d.y;this.m_sweep.c.x+=this.m_xf.position.x;this.m_sweep.c.y+=this.m_xf.position.y;this.m_sweep.c0.SetV(this.m_sweep.c);this.m_sweep.a0=this.m_sweep.a=b;c=this.m_world.m_contactManager.m_broadPhase;for(d=
this.fixtureList.GetFirstNode();d;d=d.GetNextNode())d.fixture.Synchronize(c,this.m_xf,this.m_xf);this.m_world.m_contactManager.FindNewContacts()};Box2D.Dynamics.b2Body.prototype.SetTransform=function(a){this.SetPositionAndAngle(a.position,a.GetAngle())};Box2D.Dynamics.b2Body.prototype.GetTransform=function(){return this.m_xf};Box2D.Dynamics.b2Body.prototype.GetPosition=function(){return this.m_xf.position};Box2D.Dynamics.b2Body.prototype.SetPosition=function(a){this.SetPositionAndAngle(a,this.GetAngle())};
Box2D.Dynamics.b2Body.prototype.GetAngle=function(){return this.m_sweep.a};Box2D.Dynamics.b2Body.prototype.SetCalculatedAngle=function(a){this.m_sweep.a=a};Box2D.Dynamics.b2Body.prototype.SetAngle=function(a){this.SetPositionAndAngle(this.GetPosition(),a)};Box2D.Dynamics.b2Body.prototype.GetWorldCenter=function(){return this.m_sweep.c};Box2D.Dynamics.b2Body.prototype.GetLocalCenter=function(){return this.m_sweep.localCenter};
Box2D.Dynamics.b2Body.prototype.SetLinearVelocity=function(a){this.m_type!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&this.m_linearVelocity.SetV(a)};Box2D.Dynamics.b2Body.prototype.GetLinearVelocity=function(){return this.m_linearVelocity};Box2D.Dynamics.b2Body.prototype.SetAngularVelocity=function(a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_staticBody)this.m_angularVelocity=a};Box2D.Dynamics.b2Body.prototype.GetAngularVelocity=function(){return this.m_angularVelocity};
Box2D.Dynamics.b2Body.prototype.GetDefinition=function(){var a=new Box2D.Dynamics.b2BodyDef;a.type=this.GetType();a.allowSleep=this.m_allowSleep;a.angle=this.GetAngle();a.angularDamping=this.m_angularDamping;a.angularVelocity=this.m_angularVelocity;a.fixedRotation=this.m_fixedRotation;a.bullet=this.m_bullet;a.active=this.m_active;a.awake=this.m_awake;a.linearDamping=this.m_linearDamping;a.linearVelocity.SetV(this.GetLinearVelocity());a.position.SetV(this.GetPosition());return a};
Box2D.Dynamics.b2Body.prototype.ApplyForce=function(a,b){this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(this.SetAwake(!0),this.m_force.x+=a.x,this.m_force.y+=a.y,this.m_torque+=(b.x-this.m_sweep.c.x)*a.y-(b.y-this.m_sweep.c.y)*a.x)};Box2D.Dynamics.b2Body.prototype.ApplyTorque=function(a){this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(this.SetAwake(!0),this.m_torque+=a)};
Box2D.Dynamics.b2Body.prototype.ApplyImpulse=function(a,b){this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(this.SetAwake(!0),this.m_linearVelocity.x+=this.m_invMass*a.x,this.m_linearVelocity.y+=this.m_invMass*a.y,this.m_angularVelocity+=this.m_invI*((b.x-this.m_sweep.c.x)*a.y-(b.y-this.m_sweep.c.y)*a.x))};
Box2D.Dynamics.b2Body.prototype.Split=function(a){for(var b=this.GetLinearVelocity().Copy(),c=this.GetAngularVelocity(),d=this.GetWorldCenter(),e=this.m_world.CreateBody(this.GetDefinition()),f=this.fixtureList.GetFirstNode();f;f=f.GetNextNode()){var g=f.fixture;a(g)&&(this.fixtureList.RemoveFixture(g),e.fixtureList.AddFixture(g))}this.ResetMassData();e.ResetMassData();f=this.GetWorldCenter();a=e.GetWorldCenter();g=Box2D.Common.Math.b2Math.SubtractVV(f,d);f=Box2D.Common.Math.b2Math.CrossFV(c,g);Box2D.Common.Math.b2Vec2.Free(g);
g=Box2D.Common.Math.b2Math.AddVV(b,f);Box2D.Common.Math.b2Vec2.Free(f);this.SetLinearVelocity(g);Box2D.Common.Math.b2Vec2.Free(g);a=Box2D.Common.Math.b2Math.SubtractVV(a,d);d=Box2D.Common.Math.b2Math.CrossFV(c,a);Box2D.Common.Math.b2Vec2.Free(a);a=Box2D.Common.Math.b2Math.AddVV(b,d);Box2D.Common.Math.b2Vec2.Free(d);e.SetLinearVelocity(a);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(b);this.SetAngularVelocity(c);e.SetAngularVelocity(c);this.SynchronizeFixtures();e.SynchronizeFixtures();
return e};Box2D.Dynamics.b2Body.prototype.Merge=function(a){for(var b=a.fixtureList.GetFirstNode();b;b=b.GetNextNode())this.fixtureList.AddFixture(b.fixture),a.fixtureList.RemoveFixture(b.fixture);a.ResetMassData();this.ResetMassData();this.SynchronizeFixtures()};Box2D.Dynamics.b2Body.prototype.GetMass=function(){return this.m_mass};Box2D.Dynamics.b2Body.prototype.GetInverseMass=function(){return this.m_invMass};Box2D.Dynamics.b2Body.prototype.GetInertia=function(){return this.m_I};
Box2D.Dynamics.b2Body.prototype.GetInverseInertia=function(){return this.m_invI};Box2D.Dynamics.b2Body.prototype.GetMassData=function(a){a||(a=Box2D.Collision.Shapes.b2MassData.Get());a.mass=this.m_mass;a.I=this.m_I;a.center.SetV(this.m_sweep.localCenter);return a};
Box2D.Dynamics.b2Body.prototype.SetMassData=function(a){Box2D.Common.b2Settings.b2Assert(!this.m_world.IsLocked());if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){this.m_invI=this.m_I=this.m_invMass=0;this.m_mass=a.mass;if(this.m_mass<=0)this.m_mass=1;this.m_invMass=1/this.m_mass;if(a.I>0&&!this.m_fixedRotation)this.m_I=a.I-this.m_mass*(a.center.x*a.center.x+a.center.y*a.center.y),this.m_invI=1/this.m_I;var b=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(a.center);this.m_sweep.c0.SetV(Box2D.Common.Math.b2Math.MulX(this.m_xf,
this.m_sweep.localCenter));this.m_sweep.c.SetV(this.m_sweep.c0);this.m_linearVelocity.x+=this.m_angularVelocity*-(this.m_sweep.c.y-b.y);this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-b.x);Box2D.Common.Math.b2Vec2.Free(b)}};
Box2D.Dynamics.b2Body.prototype.ResetMassData=function(){this.m_invI=this.m_I=this.m_invMass=this.m_mass=0;this.m_sweep.localCenter.SetZero();if(!(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody||this.m_type==Box2D.Dynamics.b2BodyDef.b2_kinematicBody)){for(var a=Box2D.Common.Math.b2Vec2.Get(0,0),b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode()){var c=b.fixture;c.m_density!=0&&(c=c.GetMassData(),this.m_mass+=c.mass,a.x+=c.center.x*c.mass,a.y+=c.center.y*c.mass,this.m_I+=c.I)}this.m_mass>0?
(this.m_invMass=1/this.m_mass,a.x*=this.m_invMass,a.y*=this.m_invMass):this.m_invMass=this.m_mass=1;this.m_I>0&&!this.m_fixedRotation?(this.m_I-=this.m_mass*(a.x*a.x+a.y*a.y),this.m_I*=this.m_inertiaScale,Box2D.Common.b2Settings.b2Assert(this.m_I>0),this.m_invI=1/this.m_I):this.m_invI=this.m_I=0;b=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(a);this.m_sweep.c0.SetV(Box2D.Common.Math.b2Math.MulX(this.m_xf,this.m_sweep.localCenter));this.m_sweep.c.SetV(this.m_sweep.c0);this.m_linearVelocity.x+=
this.m_angularVelocity*-(this.m_sweep.c.y-b.y);this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-b.x);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(b)}};Box2D.Dynamics.b2Body.prototype.GetWorldPoint=function(a){var b=this.m_xf.R,a=Box2D.Common.Math.b2Vec2.Get(b.col1.x*a.x+b.col2.x*a.y,b.col1.y*a.x+b.col2.y*a.y);a.x+=this.m_xf.position.x;a.y+=this.m_xf.position.y;return a};
Box2D.Dynamics.b2Body.prototype.GetWorldVector=function(a){return Box2D.Common.Math.b2Math.MulMV(this.m_xf.R,a)};Box2D.Dynamics.b2Body.prototype.GetLocalPoint=function(a){return Box2D.Common.Math.b2Math.MulXT(this.m_xf,a)};Box2D.Dynamics.b2Body.prototype.GetLocalVector=function(a){return Box2D.Common.Math.b2Math.MulTMV(this.m_xf.R,a)};
Box2D.Dynamics.b2Body.prototype.GetLinearVelocityFromWorldPoint=function(a){return Box2D.Common.Math.b2Vec2.Get(this.m_linearVelocity.x-this.m_angularVelocity*(a.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(a.x-this.m_sweep.c.x))};
Box2D.Dynamics.b2Body.prototype.GetLinearVelocityFromLocalPoint=function(a){var b=this.m_xf.R,a=Box2D.Common.Math.b2Vec2.Get(b.col1.x*a.x+b.col2.x*a.y,b.col1.y*a.x+b.col2.y*a.y);a.x+=this.m_xf.position.x;a.y+=this.m_xf.position.y;b=Box2D.Common.Math.b2Vec2.Get(this.m_linearVelocity.x-this.m_angularVelocity*(a.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(a.x-this.m_sweep.c.x));Box2D.Common.Math.b2Vec2.Free(a);return b};Box2D.Dynamics.b2Body.prototype.GetLinearDamping=function(){return this.m_linearDamping};
Box2D.Dynamics.b2Body.prototype.SetLinearDamping=function(a){this.m_linearDamping=a};Box2D.Dynamics.b2Body.prototype.GetAngularDamping=function(){return this.m_angularDamping};Box2D.Dynamics.b2Body.prototype.SetAngularDamping=function(a){this.m_angularDamping=a};
Box2D.Dynamics.b2Body.prototype.SetType=function(a){if(this.m_type!=a){this.m_type=a;this.ResetMassData();if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody)this.m_linearVelocity.SetZero(),this.m_angularVelocity=0;this.SetAwake(!0);this.m_force.SetZero();this.m_torque=0;this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){a.FlagForFiltering()});for(a=0;a<this.m_lists.length;a++)this.m_lists[a].UpdateBody(this)}};
Box2D.Dynamics.b2Body.prototype.GetType=function(){return this.m_type};Box2D.Dynamics.b2Body.prototype.SetBullet=function(a){this.m_bullet=a};Box2D.Dynamics.b2Body.prototype.IsBullet=function(){return this.m_bullet};Box2D.Dynamics.b2Body.prototype.SetSleepingAllowed=function(a){(this.m_allowSleep=a)||this.SetAwake(!0)};
Box2D.Dynamics.b2Body.prototype.SetAwake=function(a){if(this.m_awake!=a){this.m_awake=a;this.m_sleepTime=0;if(!a)this.m_linearVelocity.SetZero(),this.m_angularVelocity=0,this.m_force.SetZero(),this.m_torque=0;for(a=0;a<this.m_lists.length;a++)this.m_lists[a].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.IsAwake=function(){return this.m_awake};Box2D.Dynamics.b2Body.prototype.SetFixedRotation=function(a){this.m_fixedRotation=a;this.ResetMassData()};
Box2D.Dynamics.b2Body.prototype.IsFixedRotation=function(){return this.m_fixedRotation};
Box2D.Dynamics.b2Body.prototype.SetActive=function(a){if(a!=this.m_active){if(a){this.m_active=!0;for(var a=this.m_world.m_contactManager.m_broadPhase,b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode())b.fixture.CreateProxy(a,this.m_xf)}else{this.m_active=!1;a=this.m_world.m_contactManager.m_broadPhase;for(b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode())b.fixture.DestroyProxy(a);var c=this;this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){c.m_world.m_contactManager.Destroy(a)})}for(a=
0;a<this.m_lists.length;a++)this.m_lists[a].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.IsActive=function(){return this.m_active};Box2D.Dynamics.b2Body.prototype.IsSleepingAllowed=function(){return this.m_allowSleep};Box2D.Dynamics.b2Body.prototype.GetFixtureList=function(){return this.fixtureList};Box2D.Dynamics.b2Body.prototype.GetJointList=function(){return this.m_jointList};Box2D.Dynamics.b2Body.prototype.GetControllerList=function(){return this.controllerList};
Box2D.Dynamics.b2Body.prototype.AddController=function(a){this.controllerList.AddController(a)};Box2D.Dynamics.b2Body.prototype.RemoveController=function(a){this.controllerList.RemoveController(a)};Box2D.Dynamics.b2Body.prototype.GetContactList=function(){return this.contactList};Box2D.Dynamics.b2Body.prototype.GetWorld=function(){return this.m_world};
Box2D.Dynamics.b2Body.prototype.SynchronizeFixtures=function(){var a=Box2D.Dynamics.b2Body.s_xf1;a.R.Set(this.m_sweep.a0);var b=a.R,c=this.m_sweep.localCenter;a.position.x=this.m_sweep.c0.x-(b.col1.x*c.x+b.col2.x*c.y);a.position.y=this.m_sweep.c0.y-(b.col1.y*c.x+b.col2.y*c.y);b=this.m_world.m_contactManager.m_broadPhase;for(c=this.fixtureList.GetFirstNode();c;c=c.GetNextNode())c.fixture.Synchronize(b,a,this.m_xf)};
Box2D.Dynamics.b2Body.prototype.SynchronizeTransform=function(){this.m_xf.R.Set(this.m_sweep.a);var a=this.m_xf.R,b=this.m_sweep.localCenter;this.m_xf.position.x=this.m_sweep.c.x-(a.col1.x*b.x+a.col2.x*b.y);this.m_xf.position.y=this.m_sweep.c.y-(a.col1.y*b.x+a.col2.y*b.y)};
Box2D.Dynamics.b2Body.prototype.ShouldCollide=function(a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&a.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody)return!1;for(var b=this.m_jointList;b;b=b.next)if(b.other==a&&b.joint.m_collideConnected==!1)return!1;return!0};Box2D.Dynamics.b2Body.prototype.Advance=function(a){this.m_sweep.Advance(a);this.m_sweep.c.SetV(this.m_sweep.c0);this.m_sweep.a=this.m_sweep.a0;this.SynchronizeTransform()};Box2D.Dynamics.b2Body.NEXT_ID=0;
Box2D.Dynamics.b2Body.s_xf1=new Box2D.Common.Math.b2Transform;Box2D.Dynamics.b2World=function(a,b){this.m_contactManager=new Box2D.Dynamics.b2ContactManager(this);this.m_contactSolver=new Box2D.Dynamics.Contacts.b2ContactSolver;this.m_newFixture=this.m_isLocked=!1;this.m_debugDraw=this.m_destructionListener=null;this.bodyList=new Box2D.Dynamics.b2BodyList;this.contactList=new Box2D.Dynamics.Contacts.b2ContactList;this.m_jointList=null;this.controllerList=new Box2D.Dynamics.Controllers.b2ControllerList;this.m_jointCount=0;this.m_continuousPhysics=this.m_warmStarting=
!0;this.m_allowSleep=b;this.m_gravity=a;this.m_inv_dt0=0;this.m_groundBody=this.CreateBody(new Box2D.Dynamics.b2BodyDef);this.mainTimeStep=new Box2D.Dynamics.b2TimeStep(0,0,0,0,this.m_warmStarting);this.islandTimeStep=new Box2D.Dynamics.b2TimeStep(0,0,0,0,this.m_warmStarting);this.island=new Box2D.Dynamics.b2Island(this.m_contactManager.m_contactListener,this.m_contactSolver)};Box2D.Dynamics.b2World.MAX_TOI=1-100*Number.MIN_VALUE;
Box2D.Dynamics.b2World.prototype.SetDestructionListener=function(a){this.m_destructionListener=a};Box2D.Dynamics.b2World.prototype.SetContactFilter=function(a){this.m_contactManager.m_contactFilter=a};Box2D.Dynamics.b2World.prototype.SetContactListener=function(a){this.m_contactManager.m_contactListener=a};Box2D.Dynamics.b2World.prototype.SetDebugDraw=function(a){this.m_debugDraw=a};
Box2D.Dynamics.b2World.prototype.SetBroadPhase=function(a){var b=this.m_contactManager.m_broadPhase;this.m_contactManager.m_broadPhase=a;for(var c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode())for(var d=c.body.GetFixtureList().GetFirstNode();d;d=d.GetNextNode()){var e=d.fixture;e.m_proxy=a.CreateProxy(b.GetFatAABB(e.m_proxy),e)}};
Box2D.Dynamics.b2World.prototype.CreateBody=function(a){Box2D.Common.b2Settings.b2Assert(!this.IsLocked());a=new Box2D.Dynamics.b2Body(a,this);this.bodyList.AddBody(a);return a};
Box2D.Dynamics.b2World.prototype.DestroyBody=function(a){Box2D.Common.b2Settings.b2Assert(!this.IsLocked());for(var b=a.m_jointList;b;){var c=b,b=b.next;this.m_destructionListener&&this.m_destructionListener.SayGoodbyeJoint(c.joint);this.DestroyJoint(c.joint)}for(b=a.GetControllerList().GetFirstNode();b;b=b.GetNextNode())b.controller.RemoveBody(a);var d=this;a.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){d.m_contactManager.Destroy(a)});for(b=a.GetFixtureList().GetFirstNode();b;b=
b.GetNextNode())this.m_destructionListener&&this.m_destructionListener.SayGoodbyeFixture(b.fixture),a.DestroyFixture(b.fixture);a.Destroy();this.bodyList.RemoveBody(a)};
Box2D.Dynamics.b2World.prototype.CreateJoint=function(a){var b=Box2D.Dynamics.Joints.b2Joint.Create(a);b.m_prev=null;if(b.m_next=this.m_jointList)this.m_jointList.m_prev=b;this.m_jointList=b;this.m_jointCount++;b.m_edgeA.joint=b;b.m_edgeA.other=b.m_bodyB;b.m_edgeA.prev=null;if(b.m_edgeA.next=b.m_bodyA.m_jointList)b.m_bodyA.m_jointList.prev=b.m_edgeA;b.m_bodyA.m_jointList=b.m_edgeA;b.m_edgeB.joint=b;b.m_edgeB.other=b.m_bodyA;b.m_edgeB.prev=null;if(b.m_edgeB.next=b.m_bodyB.m_jointList)b.m_bodyB.m_jointList.prev=
b.m_edgeB;b.m_bodyB.m_jointList=b.m_edgeB;var c=a.bodyA,d=a.bodyB;a.collideConnected||d.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){a.GetOther(d)==c&&a.FlagForFiltering()});return b};
Box2D.Dynamics.b2World.prototype.DestroyJoint=function(a){var b=a.m_collideConnected;if(a.m_prev)a.m_prev.m_next=a.m_next;if(a.m_next)a.m_next.m_prev=a.m_prev;if(a==this.m_jointList)this.m_jointList=a.m_next;a.m_next=null;a.m_prev=null;var c=a.m_bodyA,d=a.m_bodyB;c.SetAwake(!0);d.SetAwake(!0);if(a.m_edgeA.prev)a.m_edgeA.prev.next=a.m_edgeA.next;if(a.m_edgeA.next)a.m_edgeA.next.prev=a.m_edgeA.prev;if(a.m_edgeA==c.m_jointList)c.m_jointList=a.m_edgeA.next;a.m_edgeA.prev=null;a.m_edgeA.next=null;if(a.m_edgeB.prev)a.m_edgeB.prev.next=
a.m_edgeB.next;if(a.m_edgeB.next)a.m_edgeB.next.prev=a.m_edgeB.prev;if(a.m_edgeB==d.m_jointList)d.m_jointList=a.m_edgeB.next;a.m_edgeB.prev=null;a.m_edgeB.next=null;this.m_jointCount--;b||d.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){a.GetOther(d)==c&&a.FlagForFiltering()})};Box2D.Dynamics.b2World.prototype.GetControllerList=function(){return this.controllerList};
Box2D.Dynamics.b2World.prototype.AddController=function(a){if(a.m_world!==null&&a.m_world!=this)throw Error("Controller can only be a member of one world");this.controllerList.AddController(a);a.m_world=this;return a};Box2D.Dynamics.b2World.prototype.RemoveController=function(a){this.controllerList.RemoveController(a);a.m_world=null;a.Clear()};Box2D.Dynamics.b2World.prototype.CreateController=function(a){return this.AddController(a)};Box2D.Dynamics.b2World.prototype.DestroyController=function(a){this.RemoveController(a)};
Box2D.Dynamics.b2World.prototype.SetWarmStarting=function(a){this.m_warmStarting=a};Box2D.Dynamics.b2World.prototype.SetContinuousPhysics=function(a){this.m_continuousPhysics=a};Box2D.Dynamics.b2World.prototype.GetBodyCount=function(){return this.bodyList.GetBodyCount()};Box2D.Dynamics.b2World.prototype.GetJointCount=function(){return this.m_jointCount};Box2D.Dynamics.b2World.prototype.GetContactCount=function(){return this.contactList.GetContactCount()};
Box2D.Dynamics.b2World.prototype.SetGravity=function(a){this.m_gravity=a};Box2D.Dynamics.b2World.prototype.GetGravity=function(){return this.m_gravity};Box2D.Dynamics.b2World.prototype.GetGroundBody=function(){return this.m_groundBody};
Box2D.Dynamics.b2World.prototype.Step=function(a,b,c){if(this.m_newFixture)this.m_contactManager.FindNewContacts(),this.m_newFixture=!1;this.m_isLocked=!0;this.mainTimeStep.Reset(a,this.m_inv_dt0*a,b,c,this.m_warmStarting);this.m_contactManager.Collide();if(this.mainTimeStep.dt>0)this.Solve(this.mainTimeStep),this.m_continuousPhysics&&this.SolveTOI(this.mainTimeStep),this.m_inv_dt0=this.mainTimeStep.inv_dt;this.m_isLocked=!1};
Box2D.Dynamics.b2World.prototype.ClearForces=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies);a;a=a.GetNextNode())a.body.m_force.SetZero(),a.body.m_torque=0};
Box2D.Dynamics.b2World.prototype.DrawDebugData=function(){if(this.m_debugDraw!==null){this.m_debugDraw.Clear();var a=this.m_debugDraw.GetFlags();if(a&Box2D.Dynamics.b2DebugDraw.e_shapeBit)for(var b=Box2D.Dynamics.b2World.s_color_inactive,c=Box2D.Dynamics.b2World.s_color_static,d=Box2D.Dynamics.b2World.s_color_kinematic,e=Box2D.Dynamics.b2World.s_color_dynamic_sleeping,f=Box2D.Dynamics.b2World.s_color_dynamic_awake,g=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);g;g=g.GetNextNode())for(var h=
g.body,i=h.GetFixtureList().GetFirstNode();i;i=i.GetNextNode()){var j=i.fixture,j=j.GetShape();h.IsActive()?h.GetType()==Box2D.Dynamics.b2BodyDef.b2_staticBody?this.DrawShape(j,h.m_xf,c):h.GetType()==Box2D.Dynamics.b2BodyDef.b2_kinematicBody?this.DrawShape(j,h.m_xf,d):h.IsAwake()?this.DrawShape(j,h.m_xf,f):this.DrawShape(j,h.m_xf,e):this.DrawShape(j,h.m_xf,b)}if(a&Box2D.Dynamics.b2DebugDraw.e_jointBit)for(g=this.m_jointList;g;g=g.m_next)this.DrawJoint(g);if(a&Box2D.Dynamics.b2DebugDraw.e_controllerBit)for(g=
this.controllerList.GetFirstNode();g;g=g.GetNextNode())g.controller.Draw(this.m_debugDraw);if(a&Box2D.Dynamics.b2DebugDraw.e_pairBit){var k=Box2D.Dynamics.b2World.s_pairColor,l=this;this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){var b=a.GetFixtureA(),a=a.GetFixtureB(),b=b.GetAABB().GetCenter(),a=a.GetAABB().GetCenter();l.m_debugDraw.DrawSegment(b,a,k);Box2D.Common.Math.b2Vec2.Free(b);Box2D.Common.Math.b2Vec2.Free(a)})}if(a&Box2D.Dynamics.b2DebugDraw.e_aabbBit){b=
Box2D.Dynamics.b2World.s_aabbColor;for(g=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.activeBodies);g;g=g.GetNextNode()){h=g.body;for(i=h.GetFixtureList().GetFirstNode();i;i=i.GetNextNode())j=i.fixture,h=this.m_contactManager.m_broadPhase.GetFatAABB(j.m_proxy),h=[Box2D.Common.Math.b2Vec2.Get(h.lowerBound.x,h.lowerBound.y),Box2D.Common.Math.b2Vec2.Get(h.upperBound.x,h.lowerBound.y),Box2D.Common.Math.b2Vec2.Get(h.upperBound.x,h.upperBound.y),Box2D.Common.Math.b2Vec2.Get(h.lowerBound.x,
h.upperBound.y)],this.m_debugDraw.DrawPolygon(h,4,b),Box2D.Common.Math.b2Vec2.Free(h[0]),Box2D.Common.Math.b2Vec2.Free(h[1]),Box2D.Common.Math.b2Vec2.Free(h[2]),Box2D.Common.Math.b2Vec2.Free(h[3])}}if(a&Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit)for(g=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);g;g=g.GetNextNode())h=g.body,Box2D.Dynamics.b2World.s_xf.R=h.m_xf.R,Box2D.Dynamics.b2World.s_xf.position=h.GetWorldCenter(),this.m_debugDraw.DrawTransform(Box2D.Dynamics.b2World.s_xf)}};
Box2D.Dynamics.b2World.prototype.QueryAABB=function(a,b){this.m_contactManager.m_broadPhase.Query(a,b)};Box2D.Dynamics.b2World.prototype.QueryPoint=function(a,b){var c=Box2D.Collision.b2AABB.Get();c.lowerBound.Set(b.x-Box2D.Common.b2Settings.b2_linearSlop,b.y-Box2D.Common.b2Settings.b2_linearSlop);c.upperBound.Set(b.x+Box2D.Common.b2Settings.b2_linearSlop,b.y+Box2D.Common.b2Settings.b2_linearSlop);this.m_contactManager.m_broadPhase.Query(function(c){return c.TestPoint(b)?a(c):!0},c);Box2D.Collision.b2AABB.Free(c)};
Box2D.Dynamics.b2World.prototype.RayCast=function(a,b,c){var d=this.m_contactManager.m_broadPhase,e=new Box2D.Collision.b2RayCastOutput,f=new Box2D.Collision.b2RayCastInput(b,c,1);d.RayCast(function(d,f){if(f.RayCast(e,d)){var i=1-e.fraction,i=Box2D.Common.Math.b2Vec2.Get(i*b.x+e.fraction*c.x,i*b.y+e.fraction*c.y),j=a(f,i,e.normal,e.fraction);Box2D.Common.Math.b2Vec2.Free(i);return j}else return d.maxFraction},f)};
Box2D.Dynamics.b2World.prototype.RayCastOne=function(a,b){var c=null;this.RayCast(function(a,b,f,g){c=a;return g},a,b);return c};Box2D.Dynamics.b2World.prototype.RayCastAll=function(a,b){var c=[];this.RayCast(function(a){c.push(a);return 1},a,b);return c};Box2D.Dynamics.b2World.prototype.GetBodyList=function(){return this.bodyList};Box2D.Dynamics.b2World.prototype.GetJointList=function(){return this.m_jointList};Box2D.Dynamics.b2World.prototype.GetContactList=function(){return this.contactList};
Box2D.Dynamics.b2World.prototype.IsLocked=function(){return this.m_isLocked};
Box2D.Dynamics.b2World.prototype.Solve=function(a){for(var b=this.controllerList.GetFirstNode();b;b=b.GetNextNode())b.controller.Step(a);var c=this.island;c.Reset(this.m_contactManager.m_contactListener,this.m_contactSolver);for(b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);b;b=b.GetNextNode())b.body.m_islandFlag=!1;this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){a.m_islandFlag=!1});for(b=this.m_jointList;b;b=b.m_next)b.m_islandFlag=
!1;for(b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);b;b=b.GetNextNode()){var d=b.body;if(!d.m_islandFlag){c.Clear();var e=[];e.push(d);for(d.m_islandFlag=!0;e.length>0;){var f=e.pop();c.AddBody(f);f.IsAwake()||f.SetAwake(!0);if(f.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody){f.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts,function(a){if(!a.m_islandFlag&&(c.AddContact(a),a.m_islandFlag=!0,a=a.GetOther(f),
!a.m_islandFlag))e.push(a),a.m_islandFlag=!0});for(d=f.m_jointList;d;d=d.next)if(!d.joint.m_islandFlag&&d.other.IsActive()&&(c.AddJoint(d.joint),d.joint.m_islandFlag=!0,!d.other.m_islandFlag))e.push(d.other),d.other.m_islandFlag=!0}}c.Solve(a,this.m_gravity,this.m_allowSleep)}}for(b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);b;b=b.GetNextNode())b.body.SynchronizeFixtures();this.m_contactManager.FindNewContacts()};
Box2D.Dynamics.b2World.prototype.SolveTOI=function(a){var b=this.island;b.Reset(this.m_contactManager.m_contactListener,this.m_contactSolver);for(var c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode()){var d=c.body;d.m_islandFlag=!1;d.m_sweep.t0=0}this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){a.m_islandFlag=!1;a.m_toi=null});for(c=this.m_jointList;c;c=c.m_next)c.m_islandFlag=!1;for(;;){var e=this._SolveTOI2(a),
c=e.minContact,f=e.minTOI;if(c===null||Box2D.Dynamics.b2World.MAX_TOI<f)break;var g=c.m_fixtureA.GetBody(),e=c.m_fixtureB.GetBody();Box2D.Dynamics.b2World.s_backupA.Set(g.m_sweep);Box2D.Dynamics.b2World.s_backupB.Set(e.m_sweep);g.Advance(f);e.Advance(f);c.Update(this.m_contactManager.m_contactListener);c.m_toi=null;if(c.IsSensor()||!c.IsEnabled())g.m_sweep.Set(Box2D.Dynamics.b2World.s_backupA),e.m_sweep.Set(Box2D.Dynamics.b2World.s_backupB),g.SynchronizeTransform(),e.SynchronizeTransform();else if(c.IsTouching()){c=
g;c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(c=e);b.Clear();var h=new goog.structs.Queue;h.enqueue(c);for(c.m_islandFlag=!0;h.size>0;)if(d=h.dequeue(),b.AddBody(d),d.IsAwake()||d.SetAwake(!0),d.GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){d.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts,function(a){if(b.m_contacts.length==Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland)return!0;if(!a.m_islandFlag&&(b.AddContact(a),a.m_islandFlag=
!0,a=a.GetOther(d),!a.m_islandFlag))a.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&(a.Advance(f),a.SetAwake(!0),h.enqueue(a)),a.m_islandFlag=!0});for(c=d.m_jointList;c;c=c.next)if(b.m_jointCount!=Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland&&!c.joint.m_islandFlag&&c.other.IsActive()&&(b.AddJoint(c.joint),c.joint.m_islandFlag=!0,!c.other.m_islandFlag))c.other.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&(c.other.Advance(f),c.other.SetAwake(!0),h.enqueue(c.other)),c.other.m_islandFlag=
!0}this.islandTimeStep.Reset((1-f)*a.dt,0,a.velocityIterations,a.positionIterations,!1);b.SolveTOI(this.islandTimeStep);for(c=0;c<b.m_bodies.length;c++)b.m_bodies[c].m_islandFlag=!1,b.m_bodies[c].IsAwake()&&b.m_bodies[c].GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(b.m_bodies[c].SynchronizeFixtures(),b.m_bodies[c].contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts,function(a){a.m_toi=null}));for(c=0;c<b.m_contactCount;c++)b.m_contacts[c].m_islandFlag=!1,b.m_contacts[c].m_toi=
null;for(c=0;c<b.m_jointCount;c++)b.m_joints[c].m_islandFlag=!1;this.m_contactManager.FindNewContacts()}}};
Box2D.Dynamics.b2World.prototype._SolveTOI2=function(a){var b=null,c=1,d=this;this.contactList.ForEachContact(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts,function(e){if(!d._SolveTOI2SkipContact(a,e)){var f=1;if(e.m_toi!=null)f=e.m_toi;else{if(e.IsTouching())f=1;else{var f=e.m_fixtureA.GetBody(),g=e.m_fixtureB.GetBody(),h=f.m_sweep.t0;if(f.m_sweep.t0<g.m_sweep.t0)h=g.m_sweep.t0,f.m_sweep.Advance(h);else if(g.m_sweep.t0<f.m_sweep.t0)h=f.m_sweep.t0,g.m_sweep.Advance(h);
f=e.ComputeTOI(f.m_sweep,g.m_sweep);Box2D.Common.b2Settings.b2Assert(0<=f&&f<=1);f>0&&f<1&&(f=(1-f)*h+f)}e.m_toi=f}Number.MIN_VALUE<f&&f<c&&(b=e,c=f)}});return{minContact:b,minTOI:c}};Box2D.Dynamics.b2World.prototype._SolveTOI2SkipContact=function(a,b){var c=b.m_fixtureA.GetBody(),d=b.m_fixtureB.GetBody();return(c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||!c.IsAwake())&&(d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||!d.IsAwake())?!0:!1};
Box2D.Dynamics.b2World.prototype.DrawJoint=function(a){if(a instanceof Box2D.Dynamics.Joints.b2DistanceJoint||a instanceof Box2D.Dynamics.Joints.b2MouseJoint){var b=a.GetAnchorA(),c=a.GetAnchorB();this.m_debugDraw.DrawSegment(b,c,Box2D.Dynamics.b2World.s_jointColor);Box2D.Common.Math.b2Vec2.Free(b);Box2D.Common.Math.b2Vec2.Free(c)}else if(a instanceof Box2D.Dynamics.Joints.b2PulleyJoint){var b=a.GetAnchorA(),c=a.GetAnchorB(),d=a.GetGroundAnchorA(),a=a.GetGroundAnchorB();this.m_debugDraw.DrawSegment(d,
b,Box2D.Dynamics.b2World.s_jointColor);this.m_debugDraw.DrawSegment(a,c,Box2D.Dynamics.b2World.s_jointColor);this.m_debugDraw.DrawSegment(d,a,Box2D.Dynamics.b2World.s_jointColor);Box2D.Common.Math.b2Vec2.Free(b);Box2D.Common.Math.b2Vec2.Free(c);Box2D.Common.Math.b2Vec2.Free(d);Box2D.Common.Math.b2Vec2.Free(a)}else b=a.GetAnchorA(),c=a.GetAnchorB(),a.GetBodyA()!=this.m_groundBody&&this.m_debugDraw.DrawSegment(a.GetBodyA().m_xf.position,b,Box2D.Dynamics.b2World.s_jointColor),this.m_debugDraw.DrawSegment(b,
c,Box2D.Dynamics.b2World.s_jointColor),a.GetBodyB()!=this.m_groundBody&&this.m_debugDraw.DrawSegment(a.GetBodyB().m_xf.position,c,Box2D.Dynamics.b2World.s_jointColor),Box2D.Common.Math.b2Vec2.Free(b),Box2D.Common.Math.b2Vec2.Free(c)};
Box2D.Dynamics.b2World.prototype.DrawShape=function(a,b,c){if(a instanceof Box2D.Collision.Shapes.b2CircleShape){var d=Box2D.Common.Math.b2Math.MulX(b,a.m_p);this.m_debugDraw.DrawSolidCircle(d,a.m_radius,b.R.col1,c);Box2D.Common.Math.b2Vec2.Free(d)}else if(a instanceof Box2D.Collision.Shapes.b2PolygonShape){for(var d=0,e=a.GetVertexCount(),a=a.GetVertices(),f=[],d=0;d<e;d++)f[d]=Box2D.Common.Math.b2Math.MulX(b,a[d]);this.m_debugDraw.DrawSolidPolygon(f,e,c);for(d=0;d<e;d++)Box2D.Common.Math.b2Vec2.Free(f[d])}else a instanceof
Box2D.Collision.Shapes.b2EdgeShape&&(d=Box2D.Common.Math.b2Math.MulX(b,a.GetVertex1()),b=Box2D.Common.Math.b2Math.MulX(b,a.GetVertex2()),this.m_debugDraw.DrawSegment(d,b,c),Box2D.Common.Math.b2Vec2.Free(d),Box2D.Common.Math.b2Vec2.Free(b))};Box2D.Dynamics.b2World.s_xf=new Box2D.Common.Math.b2Transform;Box2D.Dynamics.b2World.s_backupA=new Box2D.Common.Math.b2Sweep;Box2D.Dynamics.b2World.s_backupB=new Box2D.Common.Math.b2Sweep;Box2D.Dynamics.b2World.s_jointColor=new Box2D.Common.b2Color(0.5,0.8,0.8);
Box2D.Dynamics.b2World.s_color_inactive=new Box2D.Common.b2Color(0.5,0.5,0.3);Box2D.Dynamics.b2World.s_color_static=new Box2D.Common.b2Color(0.5,0.9,0.5);Box2D.Dynamics.b2World.s_color_kinematic=new Box2D.Common.b2Color(0.5,0.5,0.9);Box2D.Dynamics.b2World.s_color_dynamic_sleeping=new Box2D.Common.b2Color(0.6,0.6,0.6);Box2D.Dynamics.b2World.s_color_dynamic_awake=new Box2D.Common.b2Color(0.9,0.7,0.7);Box2D.Dynamics.b2World.s_pairColor=new Box2D.Common.b2Color(0.3,0.9,0.9);
Box2D.Dynamics.b2World.s_aabbColor=new Box2D.Common.b2Color(0,0,0.8);Box2D.generateCallback=function(a,b){return function(){b.apply(a,arguments)}};Box2D.Dynamics.Controllers.b2TensorDampingController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.T=Box2D.Common.Math.b2Mat22.Get();this.maxTimestep=0};goog.inherits(Box2D.Dynamics.Controllers.b2TensorDampingController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2TensorDampingController.prototype.SetAxisAligned=function(a,b){this.T.col1.x=-a;this.T.col1.y=0;this.T.col2.x=0;this.T.col2.y=-b;this.maxTimestep=a>0||b>0?1/Math.max(a,b):0};
Box2D.Dynamics.Controllers.b2TensorDampingController.prototype.Step=function(a){a=a.dt;if(!(a<=Number.MIN_VALUE)){if(a>this.maxTimestep&&this.maxTimestep>0)a=this.maxTimestep;for(var b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);b;b=b.GetNextNode()){var c=b.body,d=c.GetLocalVector(c.GetLinearVelocity()),e=Box2D.Common.Math.b2Math.MulMV(this.T,d);Box2D.Common.Math.b2Vec2.Free(d);d=c.GetWorldVector(e);Box2D.Common.Math.b2Vec2.Free(e);e=Box2D.Common.Math.b2Vec2.Get(c.GetLinearVelocity().x+
d.x*a,c.GetLinearVelocity().y+d.y*a);Box2D.Common.Math.b2Vec2.Free(d);c.SetLinearVelocity(e);Box2D.Common.Math.b2Vec2.Free(e)}}};Box2D.Collision.Shapes.b2EdgeChainDef=function(){UsageTracker.get("Box2D.Collision.Shapes.b2EdgeChainDef").trackCreate();this.vertexCount=0;this.isALoop=!0;this.vertices=[]};Box2D.Dynamics.Controllers.b2ConstantForceController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.F=Box2D.Common.Math.b2Vec2.Get(0,0)};goog.inherits(Box2D.Dynamics.Controllers.b2ConstantForceController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2ConstantForceController.prototype.Step=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);a;a=a.GetNextNode()){var b=a.body;b.ApplyForce(this.F,b.GetWorldCenter())}};Box2D.Dynamics.Joints.b2PulleyJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.groundAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.groundAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint;this.groundAnchorA.Set(-1,1);this.groundAnchorB.Set(1,1);this.localAnchorA.Set(-1,0);this.localAnchorB.Set(1,0);this.maxLengthB=this.lengthB=this.maxLengthA=
this.lengthA=0;this.ratio=1;this.collideConnected=!0};goog.inherits(Box2D.Dynamics.Joints.b2PulleyJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2PulleyJointDef.prototype.Initialize=function(a,b,c,d,e,f,g){g===void 0&&(g=0);this.bodyA=a;this.bodyB=b;this.groundAnchorA.SetV(c);this.groundAnchorB.SetV(d);this.localAnchorA=this.bodyA.GetLocalPoint(e);this.localAnchorB=this.bodyB.GetLocalPoint(f);a=e.x-c.x;c=e.y-c.y;this.lengthA=Math.sqrt(a*a+c*c);c=f.x-d.x;d=f.y-d.y;this.lengthB=Math.sqrt(c*c+d*d);this.ratio=g;g=this.lengthA+this.ratio*this.lengthB;this.maxLengthA=g-this.ratio*Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength;
this.maxLengthB=(g-Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength)/this.ratio};Box2D.Dynamics.Joints.b2PulleyJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2PulleyJoint(this)};Box2D.ALL={};