js mode box2d example (now really) and cp5 clone example

This commit is contained in:
fjenett
2011-06-13 18:09:04 +00:00
parent 0f5544dcc5
commit f8a5f70479
6 changed files with 1162 additions and 0 deletions
@@ -0,0 +1,204 @@
window.onload = function () {
tryFindSketch();
}
function tryFindSketch () {
var sketch = Processing.instances[0];
if ( sketch == undefined ) return setTimeout(tryFindSketch, 200);
var controller = new Controller(sketch,"form-form");
sketch.setController(controller);
}
var Controller = (function(){
function Controller () {
var sketch = arguments[0];
var form = document.getElementById(arguments[1]);
form.onsubmit = function () {return false};
var inputs = {};
this.createInputElement = function ( id, type, labelStr ) {
var input = document.createElement('input');
input.id = id;
input.name = id;
input.type = type;
if ( labelStr !== undefined && labelStr !== '' )
{
var label = document.createElement('label');
label['for'] = id;
label.id = id+'-label';
label.innerHTML = labelStr;
form.appendChild(label);
}
form.appendChild(input);
return input;
}
this.addInputField = function ( l, t ) {
var id = createIdFromLabel(l);
if ( inputs[id] == undefined ) {
inputs[id] = this.createInputElement(id, t, l);
inputs[id].onchange = function(){
changeFunc()(sketch, id, this.value);
return false;
}
}
return inputs[id];
}
this.addRange = function ( l, c, mi, mx ) {
var input = this.addInputField( l, "range" );
input.value = c;
input.min = mi;
input.max = mx;
return input;
}
this.addPassword = function ( l ) {
var input = this.addInputField ( l, "password" );
return input;
}
this.addEmail = function ( l ) {
var input = this.addInputField ( l, "email" );
return input;
}
this.addSearch = function ( l, c ) {
var input = this.addInputField ( l, "search" );
input.value = c;
return input;
}
this.addNumber = function ( l, c ) {
var input = this.addInputField ( l, "number" );
input.value = c;
return input;
}
this.addTelephone = function ( l, c ) {
var input = this.addInputField ( l, "tel" );
input.value = c;
return input;
}
this.addUrl = function ( l, c ) {
var input = this.addInputField ( l, "url" );
input.value = c;
return input;
}
this.addDate = function ( l, c ) {
var input = this.addInputField ( l, "date" );
input.value = c;
return input;
}
this.addCheckbox = function ( l, c ) {
var id = createIdFromLabel(l);
if ( inputs[id] == undefined ) {
inputs[id] = this.createInputElement(id, "checkbox", l);
inputs[id].onchange = function(){
changeFunc()(sketch, id, this.checked);
return false;
}
}
inputs[id].checked = c ? 'checked' : '';
return inputs[id];
}
this.addTextfield = function ( l, c ) {
var id = createIdFromLabel(l);
if ( inputs[id] == undefined ) {
inputs[id] = this.createInputElement(id, "text", l);
inputs[id].onchange = function(){
changeFunc()(sketch, id, this.value);
return false;
}
}
inputs[id].value = c;
return inputs[id];
}
this.addTextarea = function ( l, c ) {
var id = createIdFromLabel(l);
if ( inputs[id] == undefined ) {
var label = document.createElement('label');
label['for'] = id;
label.id = id+'-label';
label.innerHTML = l;
form.appendChild(label);
inputs[id] = document.createElement('textarea');
inputs[id].id = id;
inputs[id].name = id;
inputs[id].innerHTML = c;
inputs[id].onchange = function(){
changeFunc()(sketch, id, this.value);
return false;
}
form.appendChild(inputs[id]);
}
inputs[id].value = c;
return inputs[id];
}
this.addSelection = function ( l, o ) {
var id = createIdFromLabel(l);
if ( inputs[id] == undefined ) {
var label = document.createElement('label');
label['for'] = id;
label.id = id+'-label';
label.innerHTML = l;
form.appendChild(label);
var select = document.createElement('select');
select.id = id;
select.name = id;
if ( o !== undefined && o.length && o.length > 0 ) {
for ( var i = 0; i < o.length; i++ ) {
var value = o[i].length > 1 ? o[i][1] : i;
var option = document.createElement('option');
option.innerHTML = o[i][0];
option.value = value;
select.appendChild(option);
}
}
select.onchange = function( event ){
changeFunc()(sketch, id, this.value);
return false;
}
inputs[id] = select;
form.appendChild(inputs[id]);
}
return inputs[id];
}
this.addMenu = this.addSelection;
this.setElementLabel = function ( element, labelStr ) {
var label = document.getElementById(element.id+'-label');
if ( label && label.childNodes && label.childNodes.length > 0 ) {
label.childNodes[0].textContent = labelStr;
} else {
//console.log([element, label]);
}
}
}
var changeFunc = function () {
return function ( sketch, id, value ) {
try {
sketch[id](value);
} catch (e) {
//console.log(e);
sketch.println( "Function \"void "+id+"(value)\" is not defined in your sketch.");
}
}
}
var createIdFromLabel = function ( l ) {
return l.replace(/^[^-_a-z]/i,'_').replace(/[^-_a-z0-9]/gi,'');
}
return Controller;
})();
@@ -0,0 +1,190 @@
/**
* This examples shows you how to interact with diverse HTML inputs. It follows
* roughly the way that <a href="http://www.sojamo.de/libraries/controlP5/">ControlP5</a>
* works for standard Processing. <br />
*
* <form id="form-form"><!-- empty --></form>
* <!-- the following css adds a tiny bit of layout -->
* <style>textarea,input,label,select{display:block;width:95%}select{width:97.5%}
* input[type=checkbox],input[type=radio]{width: auto}textarea{height:5em}</style>
*/
String[] menuItems;
int currentShape = 2;
float currentX = 0;
boolean hasStroke = true;
float hueValue = 0;
String fieldString = "Fancy Corp. Co.";
String areaString = "We are the fresh new company with "+
"activities ranging from A to Z and from "+
"alpha to omega.";
PFont fontLarge, fontSmall;
void setup ()
{
size(300,200);
colorMode(HSB);
currentX = 50;
menuItems = new String[] {
new String[] {"Rectangle"}, new String[] {"Ellipse"},
new String[] {"Star"}, new String[] {"Spirograph"}
};
textFont(createFont("Arial", 16));
}
int bg = 200; void setBG ( int b ) { bg = b; }
void draw ()
{
background( bg );
strokeWeight(4);
if ( hasStroke ) stroke( hueValue, 150, 95 );
else noStroke();
fill( hueValue, 200, 150 );
pushMatrix();
switch ( currentShape ) {
case 0:
rectMode(CENTER);
rect(currentX, height/4, 50, 50);
break;
case 1:
ellipse(currentX, height/4, 55, 55);
break;
case 2:
star(currentX, height/4, 17, 30);
break;
case 3:
spiro(currentX, height/4, 20);
break;
}
popMatrix();
fill( 0 );
textSize(16);
textAlign( CENTER );
float tWidth = textWidth(fieldString);
float tX = currentX;
if ( currentX-tWidth/2 < 25 )
{
textAlign( LEFT );
tX = currentX-25;
}
else if ( currentX+tWidth/2 > width-25 )
{
textAlign( RIGHT );
tX = currentX+25;
}
text( fieldString, tX, height/4+50 );
textSize(11.5);
textAlign( currentX > width/2 ? RIGHT : LEFT );
int l, w;
if ( currentX <= width/2 )
{
l = currentX-50+25;
w = width-l-25;
}
else
{
l = 25;
w = currentX+50-25-25;
}
text( areaString, l, height/4+70, w, height/2 );
}
void star ( float x, float y, float inner, float outer )
{
beginShape();
for ( int i = 0; i < 360; i+=36 )
{
float r = radians(i + sin(frameCount/90.0)*25);
vertex( x + cos(r)*outer, y + sin(r)*outer );
r = radians(i+(36/2));
vertex( x + cos(r)*inner, y + sin(r)*inner );
}
endShape(CLOSE);
}
void spiro ( float x, float y, float rad )
{
beginShape();
for ( int i = 0; i < 360; i+=2 )
{
float r = radians(i);
float r2 = radians(i*(sin(frameCount/240.0)+2)*2);
vertex( x + (cos(r)+cos(r2)/2)*rad, y + (sin(r)+sin(r2)/2)*rad );
}
endShape();
}
/* these are callbacks */
void setController ( Controller ctlr )
{
// labels are supposed to be existing function names
InterfaceElement element = ctlr.addRange( "rangeCallback", currentX, 0, 100 );
ctlr.setElementLabel( element, "Example range input field" );
element = ctlr.addCheckbox( "textBoxCallback", hasStroke );
ctlr.setElementLabel( element, "A checkbox here" );
element = ctlr.addTextfield( "textFieldChanged", fieldString );
ctlr.setElementLabel( element, "... and this is a textfield" );
element = ctlr.addTextarea( "calledByTextarea", areaString );
ctlr.setElementLabel( element, "Ta-dah: a textarea" );
element = ctlr.addMenu( "theMenu", menuItems );
ctlr.setElementLabel( element, "LBNL a select menu" );
}
void rangeCallback ( float value )
{
currentX = map( value, 0, 100, 50, width-50 );
}
void textBoxCallback ( boolean value )
{
hasStroke = value;
}
void textFieldChanged ( String value )
{
fieldString = value;
}
void calledByTextarea ( String value )
{
areaString = value;
}
void theMenu ( String value )
{
currentShape = int(value);
}
/* and the interfaces */
/* explain inputs to Processing */
interface InputElement
{
String type;
String id;
Object value;
}
/* explain Controller to Processing */
interface Controller
{
InputElement addRange ( String label, float initialValue, float minValue, float maxValue );
void setLabel ( InputElement element, String label );
}
@@ -0,0 +1,306 @@
// See: http://box2d-js.sourceforge.net/
/*
* Copyright (c) 2006-2007 Erin Catto http:
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked, and must not be
* misrepresented the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
var b2Settings=Class.create();b2Settings.prototype={initialize:function(){}};b2Settings.USHRT_MAX=65535;b2Settings.b2_pi=Math.PI;b2Settings.b2_massUnitsPerKilogram=1;b2Settings.b2_timeUnitsPerSecond=1;b2Settings.b2_lengthUnitsPerMeter=30;b2Settings.b2_maxManifoldPoints=2;b2Settings.b2_maxShapesPerBody=64;b2Settings.b2_maxPolyVertices=8;b2Settings.b2_maxProxies=1024;b2Settings.b2_maxPairs=8*b2Settings.b2_maxProxies;b2Settings.b2_linearSlop=0.0050*b2Settings.b2_lengthUnitsPerMeter;
b2Settings.b2_angularSlop=2/180*b2Settings.b2_pi;b2Settings.b2_velocityThreshold=1*b2Settings.b2_lengthUnitsPerMeter/b2Settings.b2_timeUnitsPerSecond;b2Settings.b2_maxLinearCorrection=0.2*b2Settings.b2_lengthUnitsPerMeter;b2Settings.b2_maxAngularCorrection=8/180*b2Settings.b2_pi;b2Settings.b2_contactBaumgarte=0.2;b2Settings.b2_timeToSleep=0.5*b2Settings.b2_timeUnitsPerSecond;b2Settings.b2_linearSleepTolerance=0.01*b2Settings.b2_lengthUnitsPerMeter/b2Settings.b2_timeUnitsPerSecond;
b2Settings.b2_angularSleepTolerance=2/180/b2Settings.b2_timeUnitsPerSecond;b2Settings.b2Assert=function(a){a||(void 0).x++};var b2Vec2=Class.create();
b2Vec2.prototype={initialize:function(a,c){this.x=a;this.y=c},SetZero:function(){this.y=this.x=0},Set:function(a,c){this.x=a;this.y=c},SetV:function(a){this.x=a.x;this.y=a.y},Negative:function(){return new b2Vec2(-this.x,-this.y)},Copy:function(){return new b2Vec2(this.x,this.y)},Add:function(a){this.x+=a.x;this.y+=a.y},Subtract:function(a){this.x-=a.x;this.y-=a.y},Multiply:function(a){this.x*=a;this.y*=a},MulM:function(a){var c=this.x;this.x=a.col1.x*c+a.col2.x*this.y;this.y=a.col1.y*c+a.col2.y*
this.y},MulTM:function(a){var c=b2Math.b2Dot(this,a.col1);this.y=b2Math.b2Dot(this,a.col2);this.x=c},CrossVF:function(a){var c=this.x;this.x=a*this.y;this.y=-a*c},CrossFV:function(a){var c=this.x;this.x=-a*this.y;this.y=a*c},MinV:function(a){this.x=this.x<a.x?this.x:a.x;this.y=this.y<a.y?this.y:a.y},MaxV:function(a){this.x=this.x>a.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},Abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y)},Length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},
Normalize:function(){var a=this.Length();if(a<Number.MIN_VALUE)return 0;var c=1/a;this.x*=c;this.y*=c;return a},IsValid:function(){return b2Math.b2IsValid(this.x)&&b2Math.b2IsValid(this.y)},x:null,y:null};b2Vec2.Make=function(a,c){return new b2Vec2(a,c)};var b2Mat22=Class.create();
b2Mat22.prototype={initialize:function(a,c,b){a==null&&(a=0);this.col1=new b2Vec2;this.col2=new b2Vec2;c!=null&&b!=null?(this.col1.SetV(c),this.col2.SetV(b)):(c=Math.cos(a),a=Math.sin(a),this.col1.x=c,this.col2.x=-a,this.col1.y=a,this.col2.y=c)},Set:function(a){var c=Math.cos(a),a=Math.sin(a);this.col1.x=c;this.col2.x=-a;this.col1.y=a;this.col2.y=c},SetVV:function(a,c){this.col1.SetV(a);this.col2.SetV(c)},Copy:function(){return new b2Mat22(0,this.col1,this.col2)},SetM:function(a){this.col1.SetV(a.col1);
this.col2.SetV(a.col2)},AddM:function(a){this.col1.x+=a.col1.x;this.col1.y+=a.col1.y;this.col2.x+=a.col2.x;this.col2.y+=a.col2.y},SetIdentity:function(){this.col1.x=1;this.col2.x=0;this.col1.y=0;this.col2.y=1},SetZero:function(){this.col1.x=0;this.col2.x=0;this.col1.y=0;this.col2.y=0},Invert:function(a){var c=this.col1.x,b=this.col2.x,e=this.col1.y,f=this.col2.y,g;g=1/(c*f-b*e);a.col1.x=g*f;a.col2.x=-g*b;a.col1.y=-g*e;a.col2.y=g*c;return a},Solve:function(a,c,b){var e=this.col1.x,f=this.col2.x,g=
this.col1.y,h=this.col2.y,i;i=1/(e*h-f*g);a.x=i*(h*c-f*b);a.y=i*(e*b-g*c);return a},Abs:function(){this.col1.Abs();this.col2.Abs()},col1:new b2Vec2,col2:new b2Vec2};var b2Math=Class.create();b2Math.prototype={initialize:function(){}};b2Math.b2IsValid=function(a){return isFinite(a)};b2Math.b2Dot=function(a,c){return a.x*c.x+a.y*c.y};b2Math.b2CrossVV=function(a,c){return a.x*c.y-a.y*c.x};b2Math.b2CrossVF=function(a,c){return new b2Vec2(c*a.y,-c*a.x)};
b2Math.b2CrossFV=function(a,c){return new b2Vec2(-a*c.y,a*c.x)};b2Math.b2MulMV=function(a,c){return new b2Vec2(a.col1.x*c.x+a.col2.x*c.y,a.col1.y*c.x+a.col2.y*c.y)};b2Math.b2MulTMV=function(a,c){return new b2Vec2(b2Math.b2Dot(c,a.col1),b2Math.b2Dot(c,a.col2))};b2Math.AddVV=function(a,c){return new b2Vec2(a.x+c.x,a.y+c.y)};b2Math.SubtractVV=function(a,c){return new b2Vec2(a.x-c.x,a.y-c.y)};b2Math.MulFV=function(a,c){return new b2Vec2(a*c.x,a*c.y)};
b2Math.AddMM=function(a,c){return new b2Mat22(0,b2Math.AddVV(a.col1,c.col1),b2Math.AddVV(a.col2,c.col2))};b2Math.b2MulMM=function(a,c){return new b2Mat22(0,b2Math.b2MulMV(a,c.col1),b2Math.b2MulMV(a,c.col2))};b2Math.b2MulTMM=function(a,c){var b=new b2Vec2(b2Math.b2Dot(a.col1,c.col1),b2Math.b2Dot(a.col2,c.col1)),e=new b2Vec2(b2Math.b2Dot(a.col1,c.col2),b2Math.b2Dot(a.col2,c.col2));return new b2Mat22(0,b,e)};b2Math.b2Abs=function(a){return a>0?a:-a};
b2Math.b2AbsV=function(a){return new b2Vec2(b2Math.b2Abs(a.x),b2Math.b2Abs(a.y))};b2Math.b2AbsM=function(a){return new b2Mat22(0,b2Math.b2AbsV(a.col1),b2Math.b2AbsV(a.col2))};b2Math.b2Min=function(a,c){return a<c?a:c};b2Math.b2MinV=function(a,c){return new b2Vec2(b2Math.b2Min(a.x,c.x),b2Math.b2Min(a.y,c.y))};b2Math.b2Max=function(a,c){return a>c?a:c};b2Math.b2MaxV=function(a,c){return new b2Vec2(b2Math.b2Max(a.x,c.x),b2Math.b2Max(a.y,c.y))};
b2Math.b2Clamp=function(a,c,b){return b2Math.b2Max(c,b2Math.b2Min(a,b))};b2Math.b2ClampV=function(a,c,b){return b2Math.b2MaxV(c,b2Math.b2MinV(a,b))};b2Math.b2Swap=function(a,c){var b=a[0];a[0]=c[0];c[0]=b};b2Math.b2Random=function(){return Math.random()*2-1};b2Math.b2NextPowerOfTwo=function(a){a|=a>>1&2147483647;a|=a>>2&1073741823;a|=a>>4&268435455;a|=a>>8&16777215;a|=a>>16&65535;return a+1};b2Math.b2IsPowerOfTwo=function(a){return a>0&&(a&a-1)==0};b2Math.tempVec2=new b2Vec2;b2Math.tempVec3=new b2Vec2;
b2Math.tempVec4=new b2Vec2;b2Math.tempVec5=new b2Vec2;b2Math.tempMat=new b2Mat22;var b2AABB=Class.create();b2AABB.prototype={IsValid:function(){var a=this.maxVertex.x,c=this.maxVertex.y,a=this.maxVertex.x,c=this.maxVertex.y;a-=this.minVertex.x;c-=this.minVertex.y;return a=a>=0&&c>=0&&this.minVertex.IsValid()&&this.maxVertex.IsValid()},minVertex:new b2Vec2,maxVertex:new b2Vec2,initialize:function(){this.minVertex=new b2Vec2;this.maxVertex=new b2Vec2}};var b2Bound=Class.create();
b2Bound.prototype={IsLower:function(){return(this.value&1)==0},IsUpper:function(){return(this.value&1)==1},Swap:function(a){var c=this.value,b=this.proxyId,e=this.stabbingCount;this.value=a.value;this.proxyId=a.proxyId;this.stabbingCount=a.stabbingCount;a.value=c;a.proxyId=b;a.stabbingCount=e},value:0,proxyId:0,stabbingCount:0,initialize:function(){}};var b2BoundValues=Class.create();
b2BoundValues.prototype={lowerValues:[0,0],upperValues:[0,0],initialize:function(){this.lowerValues=[0,0];this.upperValues=[0,0]}};var b2Pair=Class.create();
b2Pair.prototype={SetBuffered:function(){this.status|=b2Pair.e_pairBuffered},ClearBuffered:function(){this.status&=~b2Pair.e_pairBuffered},IsBuffered:function(){return(this.status&b2Pair.e_pairBuffered)==b2Pair.e_pairBuffered},SetRemoved:function(){this.status|=b2Pair.e_pairRemoved},ClearRemoved:function(){this.status&=~b2Pair.e_pairRemoved},IsRemoved:function(){return(this.status&b2Pair.e_pairRemoved)==b2Pair.e_pairRemoved},SetFinal:function(){this.status|=b2Pair.e_pairFinal},IsFinal:function(){return(this.status&
b2Pair.e_pairFinal)==b2Pair.e_pairFinal},userData:null,proxyId1:0,proxyId2:0,next:0,status:0,initialize:function(){}};b2Pair.b2_nullPair=b2Settings.USHRT_MAX;b2Pair.b2_nullProxy=b2Settings.USHRT_MAX;b2Pair.b2_tableCapacity=b2Settings.b2_maxPairs;b2Pair.b2_tableMask=b2Pair.b2_tableCapacity-1;b2Pair.e_pairBuffered=1;b2Pair.e_pairRemoved=2;b2Pair.e_pairFinal=4;var b2PairCallback=Class.create();b2PairCallback.prototype={PairAdded:function(){return null},PairRemoved:function(){},initialize:function(){}};
var b2BufferedPair=Class.create();b2BufferedPair.prototype={proxyId1:0,proxyId2:0,initialize:function(){}};var b2PairManager=Class.create();
b2PairManager.prototype={initialize:function(){var a=0;this.m_hashTable=Array(b2Pair.b2_tableCapacity);for(a=0;a<b2Pair.b2_tableCapacity;++a)this.m_hashTable[a]=b2Pair.b2_nullPair;this.m_pairs=Array(b2Settings.b2_maxPairs);for(a=0;a<b2Settings.b2_maxPairs;++a)this.m_pairs[a]=new b2Pair;this.m_pairBuffer=Array(b2Settings.b2_maxPairs);for(a=0;a<b2Settings.b2_maxPairs;++a)this.m_pairBuffer[a]=new b2BufferedPair;for(a=0;a<b2Settings.b2_maxPairs;++a)this.m_pairs[a].proxyId1=b2Pair.b2_nullProxy,this.m_pairs[a].proxyId2=
b2Pair.b2_nullProxy,this.m_pairs[a].userData=null,this.m_pairs[a].status=0,this.m_pairs[a].next=a+1;this.m_pairs[b2Settings.b2_maxPairs-1].next=b2Pair.b2_nullPair;this.m_pairCount=0},Initialize:function(a,c){this.m_broadPhase=a;this.m_callback=c},AddBufferedPair:function(a,c){var b=this.AddPair(a,c);if(b.IsBuffered()==!1)b.SetBuffered(),this.m_pairBuffer[this.m_pairBufferCount].proxyId1=b.proxyId1,this.m_pairBuffer[this.m_pairBufferCount].proxyId2=b.proxyId2,++this.m_pairBufferCount;b.ClearRemoved();
b2BroadPhase.s_validate&&this.ValidateBuffer()},RemoveBufferedPair:function(a,c){var b=this.Find(a,c);if(b!=null){if(b.IsBuffered()==!1)b.SetBuffered(),this.m_pairBuffer[this.m_pairBufferCount].proxyId1=b.proxyId1,this.m_pairBuffer[this.m_pairBufferCount].proxyId2=b.proxyId2,++this.m_pairBufferCount;b.SetRemoved();b2BroadPhase.s_validate&&this.ValidateBuffer()}},Commit:function(){for(var a=0,c=0,b=this.m_broadPhase.m_proxyPool,a=0;a<this.m_pairBufferCount;++a){var e=this.Find(this.m_pairBuffer[a].proxyId1,
this.m_pairBuffer[a].proxyId2);e.ClearBuffered();var f=b[e.proxyId1],g=b[e.proxyId2];if(e.IsRemoved())e.IsFinal()==!0&&this.m_callback.PairRemoved(f.userData,g.userData,e.userData),this.m_pairBuffer[c].proxyId1=e.proxyId1,this.m_pairBuffer[c].proxyId2=e.proxyId2,++c;else if(e.IsFinal()==!1)e.userData=this.m_callback.PairAdded(f.userData,g.userData),e.SetFinal()}for(a=0;a<c;++a)this.RemovePair(this.m_pairBuffer[a].proxyId1,this.m_pairBuffer[a].proxyId2);this.m_pairBufferCount=0;b2BroadPhase.s_validate&&
this.ValidateTable()},AddPair:function(a,c){if(a>c)var b=a,a=c,c=b;var b=b2PairManager.Hash(a,c)&b2Pair.b2_tableMask,e=e=this.FindHash(a,c,b);if(e!=null)return e;var f=this.m_freePair,e=this.m_pairs[f];this.m_freePair=e.next;e.proxyId1=a;e.proxyId2=c;e.status=0;e.userData=null;e.next=this.m_hashTable[b];this.m_hashTable[b]=f;++this.m_pairCount;return e},RemovePair:function(a,c){if(a>c)var b=a,a=c,c=b;for(var e=b2PairManager.Hash(a,c)&b2Pair.b2_tableMask,f=this.m_hashTable[e],g=null;f!=b2Pair.b2_nullPair;)if(b2PairManager.Equals(this.m_pairs[f],
a,c))return b=f,g?g.next=this.m_pairs[f].next:this.m_hashTable[e]=this.m_pairs[f].next,e=this.m_pairs[b],f=e.userData,e.next=this.m_freePair,e.proxyId1=b2Pair.b2_nullProxy,e.proxyId2=b2Pair.b2_nullProxy,e.userData=null,e.status=0,this.m_freePair=b,--this.m_pairCount,f;else g=this.m_pairs[f],f=g.next;return null},Find:function(a,c){if(a>c)var b=a,a=c,c=b;b=b2PairManager.Hash(a,c)&b2Pair.b2_tableMask;return this.FindHash(a,c,b)},FindHash:function(a,c,b){for(b=this.m_hashTable[b];b!=b2Pair.b2_nullPair&&
b2PairManager.Equals(this.m_pairs[b],a,c)==!1;)b=this.m_pairs[b].next;if(b==b2Pair.b2_nullPair)return null;return this.m_pairs[b]},ValidateBuffer:function(){},ValidateTable:function(){},m_broadPhase:null,m_callback:null,m_pairs:null,m_freePair:0,m_pairCount:0,m_pairBuffer:null,m_pairBufferCount:0,m_hashTable:null};b2PairManager.Hash=function(a,c){var b=c<<16&4294901760|a,b=~b+(b<<15&4294934528);b^=b>>12&1048575;b+=b<<2&4294967292;b^=b>>4&268435455;b*=2057;b^=b>>16&65535;return b};
b2PairManager.Equals=function(a,c,b){return a.proxyId1==c&&a.proxyId2==b};b2PairManager.EqualsPair=function(a,c){return a.proxyId1==c.proxyId1&&a.proxyId2==c.proxyId2};var b2BroadPhase=Class.create();
b2BroadPhase.prototype={initialize:function(a,c){this.m_pairManager=new b2PairManager;this.m_proxyPool=Array(b2Settings.b2_maxPairs);this.m_bounds=Array(2*b2Settings.b2_maxProxies);this.m_queryResults=Array(b2Settings.b2_maxProxies);this.m_quantizationFactor=new b2Vec2;var b=0;this.m_pairManager.Initialize(this,c);this.m_worldAABB=a;for(b=this.m_proxyCount=0;b<b2Settings.b2_maxProxies;b++)this.m_queryResults[b]=0;this.m_bounds=Array(2);for(b=0;b<2;b++){this.m_bounds[b]=Array(2*b2Settings.b2_maxProxies);
for(var e=0;e<2*b2Settings.b2_maxProxies;e++)this.m_bounds[b][e]=new b2Bound}b=a.maxVertex.x;e=a.maxVertex.y;b-=a.minVertex.x;e-=a.minVertex.y;this.m_quantizationFactor.x=b2Settings.USHRT_MAX/b;this.m_quantizationFactor.y=b2Settings.USHRT_MAX/e;for(b=0;b<b2Settings.b2_maxProxies-1;++b)e=new b2Proxy,this.m_proxyPool[b]=e,e.SetNext(b+1),e.timeStamp=0,e.overlapCount=b2BroadPhase.b2_invalid,e.userData=null;e=new b2Proxy;this.m_proxyPool[b2Settings.b2_maxProxies-1]=e;e.SetNext(b2Pair.b2_nullProxy);e.timeStamp=
0;e.overlapCount=b2BroadPhase.b2_invalid;e.userData=null;this.m_freeProxy=0;this.m_timeStamp=1;this.m_queryResultCount=0},InRange:function(a){var c,b,e,f;c=a.minVertex.x;b=a.minVertex.y;c-=this.m_worldAABB.maxVertex.x;b-=this.m_worldAABB.maxVertex.y;e=this.m_worldAABB.minVertex.x;f=this.m_worldAABB.minVertex.y;e-=a.maxVertex.x;f-=a.maxVertex.y;c=b2Math.b2Max(c,e);b=b2Math.b2Max(b,f);return b2Math.b2Max(c,b)<0},GetProxy:function(a){if(a==b2Pair.b2_nullProxy||this.m_proxyPool[a].IsValid()==!1)return null;
return this.m_proxyPool[a]},CreateProxy:function(a,c){var b=0,e,f=this.m_freeProxy;e=this.m_proxyPool[f];this.m_freeProxy=e.GetNext();e.overlapCount=0;e.userData=c;e=2*this.m_proxyCount;var g=[],h=[];this.ComputeBounds(g,h,a);for(var i=0;i<2;++i){var k=this.m_bounds[i],j=0,l=0,j=[j],l=[l];this.Query(j,l,g[i],h[i],k,e,i);for(var j=j[0],l=l[0],b=[],m=0,n=e-l,o,p,m=0;m<n;m++)b[m]=new b2Bound,o=b[m],p=k[l+m],o.value=p.value,o.proxyId=p.proxyId,o.stabbingCount=p.stabbingCount;for(var n=b.length,q=l+2,
m=0;m<n;m++)p=b[m],o=k[q+m],o.value=p.value,o.proxyId=p.proxyId,o.stabbingCount=p.stabbingCount;b=[];n=l-j;for(m=0;m<n;m++)b[m]=new b2Bound,o=b[m],p=k[j+m],o.value=p.value,o.proxyId=p.proxyId,o.stabbingCount=p.stabbingCount;n=b.length;q=j+1;for(m=0;m<n;m++)p=b[m],o=k[q+m],o.value=p.value,o.proxyId=p.proxyId,o.stabbingCount=p.stabbingCount;++l;k[j].value=g[i];k[j].proxyId=f;k[l].value=h[i];k[l].proxyId=f;k[j].stabbingCount=j==0?0:k[j-1].stabbingCount;k[l].stabbingCount=k[l-1].stabbingCount;for(b=j;b<
l;++b)k[b].stabbingCount++;for(b=j;b<e+2;++b)j=this.m_proxyPool[k[b].proxyId],k[b].IsLower()?j.lowerBounds[i]=b:j.upperBounds[i]=b}++this.m_proxyCount;for(e=0;e<this.m_queryResultCount;++e)this.m_pairManager.AddBufferedPair(f,this.m_queryResults[e]);this.m_pairManager.Commit();this.m_queryResultCount=0;this.IncrementTimeStamp();return f},DestroyProxy:function(a){for(var c=this.m_proxyPool[a],b=2*this.m_proxyCount,e=0;e<2;++e){for(var f=this.m_bounds[e],g=c.lowerBounds[e],h=c.upperBounds[e],i=f[g].value,
k=f[h].value,j=[],l=0,m=h-g-1,n,o,l=0;l<m;l++)j[l]=new b2Bound,n=j[l],o=f[g+1+l],n.value=o.value,n.proxyId=o.proxyId,n.stabbingCount=o.stabbingCount;for(var m=j.length,p=g,l=0;l<m;l++)o=j[l],n=f[p+l],n.value=o.value,n.proxyId=o.proxyId,n.stabbingCount=o.stabbingCount;j=[];m=b-h-1;for(l=0;l<m;l++)j[l]=new b2Bound,n=j[l],o=f[h+1+l],n.value=o.value,n.proxyId=o.proxyId,n.stabbingCount=o.stabbingCount;m=j.length;p=h-1;for(l=0;l<m;l++)o=j[l],n=f[p+l],n.value=o.value,n.proxyId=o.proxyId,n.stabbingCount=
o.stabbingCount;m=b-2;for(j=g;j<m;++j)l=this.m_proxyPool[f[j].proxyId],f[j].IsLower()?l.lowerBounds[e]=j:l.upperBounds[e]=j;for(m=h-1;g<m;++g)f[g].stabbingCount--;this.Query([0],[0],i,k,f,b-2,e)}for(b=0;b<this.m_queryResultCount;++b)this.m_pairManager.RemoveBufferedPair(a,this.m_queryResults[b]);this.m_pairManager.Commit();this.m_queryResultCount=0;this.IncrementTimeStamp();c.userData=null;c.overlapCount=b2BroadPhase.b2_invalid;c.lowerBounds[0]=b2BroadPhase.b2_invalid;c.lowerBounds[1]=b2BroadPhase.b2_invalid;
c.upperBounds[0]=b2BroadPhase.b2_invalid;c.upperBounds[1]=b2BroadPhase.b2_invalid;c.SetNext(this.m_freeProxy);this.m_freeProxy=a;--this.m_proxyCount},MoveProxy:function(a,c){var b=0,e=0,f,g,h=0,i;if(!(a==b2Pair.b2_nullProxy||b2Settings.b2_maxProxies<=a)&&c.IsValid()!=!1){var k=2*this.m_proxyCount,j=this.m_proxyPool[a],l=new b2BoundValues;this.ComputeBounds(l.lowerValues,l.upperValues,c);for(var m=new b2BoundValues,b=0;b<2;++b)m.lowerValues[b]=this.m_bounds[b][j.lowerBounds[b]].value,m.upperValues[b]=
this.m_bounds[b][j.upperBounds[b]].value;for(b=0;b<2;++b){var n=this.m_bounds[b],o=j.lowerBounds[b],p=j.upperBounds[b],q=l.lowerValues[b],s=l.upperValues[b],r=q-n[o].value,u=s-n[p].value;n[o].value=q;n[p].value=s;if(r<0)for(e=o;e>0&&q<n[e-1].value;)f=n[e],g=n[e-1],h=g.proxyId,i=this.m_proxyPool[g.proxyId],g.stabbingCount++,g.IsUpper()==!0?(this.TestOverlap(l,i)&&this.m_pairManager.AddBufferedPair(a,h),i.upperBounds[b]++,f.stabbingCount++):(i.lowerBounds[b]++,f.stabbingCount--),j.lowerBounds[b]--,
f.Swap(g),--e;if(u>0)for(e=p;e<k-1&&n[e+1].value<=s;)f=n[e],g=n[e+1],h=g.proxyId,i=this.m_proxyPool[h],g.stabbingCount++,g.IsLower()==!0?(this.TestOverlap(l,i)&&this.m_pairManager.AddBufferedPair(a,h),i.lowerBounds[b]--,f.stabbingCount++):(i.upperBounds[b]--,f.stabbingCount--),j.upperBounds[b]++,f.Swap(g),e++;if(r>0)for(e=o;e<k-1&&n[e+1].value<=q;)f=n[e],g=n[e+1],h=g.proxyId,i=this.m_proxyPool[h],g.stabbingCount--,g.IsUpper()?(this.TestOverlap(m,i)&&this.m_pairManager.RemoveBufferedPair(a,h),i.upperBounds[b]--,
f.stabbingCount--):(i.lowerBounds[b]--,f.stabbingCount++),j.lowerBounds[b]++,f.Swap(g),e++;if(u<0)for(e=p;e>0&&s<n[e-1].value;)f=n[e],g=n[e-1],h=g.proxyId,i=this.m_proxyPool[h],g.stabbingCount--,g.IsLower()==!0?(this.TestOverlap(m,i)&&this.m_pairManager.RemoveBufferedPair(a,h),i.lowerBounds[b]++,f.stabbingCount--):(i.upperBounds[b]++,f.stabbingCount++),j.upperBounds[b]--,f.Swap(g),e--}}},Commit:function(){this.m_pairManager.Commit()},QueryAABB:function(a,c,b){var e=[],f=[];this.ComputeBounds(e,f,
a);var a=[0],g=[0];this.Query(a,g,e[0],f[0],this.m_bounds[0],2*this.m_proxyCount,0);this.Query(a,g,e[1],f[1],this.m_bounds[1],2*this.m_proxyCount,1);for(f=e=0;f<this.m_queryResultCount&&e<b;++f,++e)c[f]=this.m_proxyPool[this.m_queryResults[f]].userData;this.m_queryResultCount=0;this.IncrementTimeStamp();return e},Validate:function(){for(var a=0;a<2;++a)for(var c=this.m_bounds[a],b=2*this.m_proxyCount,e=0,f=0;f<b;++f)c[f].IsLower()==!0?e++:e--},ComputeBounds:function(a,c,b){var e=b.minVertex.x,f=b.minVertex.y,
e=b2Math.b2Min(e,this.m_worldAABB.maxVertex.x),f=b2Math.b2Min(f,this.m_worldAABB.maxVertex.y),e=b2Math.b2Max(e,this.m_worldAABB.minVertex.x),f=b2Math.b2Max(f,this.m_worldAABB.minVertex.y),g=b.maxVertex.x,b=b.maxVertex.y,g=b2Math.b2Min(g,this.m_worldAABB.maxVertex.x),b=b2Math.b2Min(b,this.m_worldAABB.maxVertex.y),g=b2Math.b2Max(g,this.m_worldAABB.minVertex.x),b=b2Math.b2Max(b,this.m_worldAABB.minVertex.y);a[0]=this.m_quantizationFactor.x*(e-this.m_worldAABB.minVertex.x)&b2Settings.USHRT_MAX-1;c[0]=
this.m_quantizationFactor.x*(g-this.m_worldAABB.minVertex.x)&65535|1;a[1]=this.m_quantizationFactor.y*(f-this.m_worldAABB.minVertex.y)&b2Settings.USHRT_MAX-1;c[1]=this.m_quantizationFactor.y*(b-this.m_worldAABB.minVertex.y)&65535|1},TestOverlapValidate:function(a,c){for(var b=0;b<2;++b){var e=this.m_bounds[b];if(e[a.lowerBounds[b]].value>e[c.upperBounds[b]].value)return!1;if(e[a.upperBounds[b]].value<e[c.lowerBounds[b]].value)return!1}return!0},TestOverlap:function(a,c){for(var b=0;b<2;++b){var e=
this.m_bounds[b];if(a.lowerValues[b]>e[c.upperBounds[b]].value)return!1;if(a.upperValues[b]<e[c.lowerBounds[b]].value)return!1}return!0},Query:function(a,c,b,e,f,g,h){b=b2BroadPhase.BinarySearch(f,g,b);e=b2BroadPhase.BinarySearch(f,g,e);for(g=b;g<e;++g)f[g].IsLower()&&this.IncrementOverlapCount(f[g].proxyId);if(b>0)for(var g=b-1,i=f[g].stabbingCount;i;)f[g].IsLower()&&b<=this.m_proxyPool[f[g].proxyId].upperBounds[h]&&(this.IncrementOverlapCount(f[g].proxyId),--i),--g;a[0]=b;c[0]=e},IncrementOverlapCount:function(a){var c=
this.m_proxyPool[a];c.timeStamp<this.m_timeStamp?(c.timeStamp=this.m_timeStamp,c.overlapCount=1):(c.overlapCount=2,this.m_queryResults[this.m_queryResultCount]=a,++this.m_queryResultCount)},IncrementTimeStamp:function(){if(this.m_timeStamp==b2Settings.USHRT_MAX){for(var a=0;a<b2Settings.b2_maxProxies;++a)this.m_proxyPool[a].timeStamp=0;this.m_timeStamp=1}else++this.m_timeStamp},m_pairManager:new b2PairManager,m_proxyPool:Array(b2Settings.b2_maxPairs),m_freeProxy:0,m_bounds:Array(2*b2Settings.b2_maxProxies),
m_queryResults:Array(b2Settings.b2_maxProxies),m_queryResultCount:0,m_worldAABB:null,m_quantizationFactor:new b2Vec2,m_proxyCount:0,m_timeStamp:0};b2BroadPhase.s_validate=!1;b2BroadPhase.b2_invalid=b2Settings.USHRT_MAX;b2BroadPhase.b2_nullEdge=b2Settings.USHRT_MAX;b2BroadPhase.BinarySearch=function(a,c,b){var e=0;for(c-=1;e<=c;){var f=Math.floor((e+c)/2);if(a[f].value>b)c=f-1;else if(a[f].value<b)e=f+1;else return f}return e};var b2Collision=Class.create();b2Collision.prototype={initialize:function(){}};
b2Collision.b2_nullFeature=255;b2Collision.ClipSegmentToLine=function(a,c,b,e){var f=0,g=c[0].v,h=c[1].v,i=b2Math.b2Dot(b,c[0].v)-e,b=b2Math.b2Dot(b,c[1].v)-e;i<=0&&(a[f++]=c[0]);b<=0&&(a[f++]=c[1]);if(i*b<0)b=i/(i-b),e=a[f].v,e.x=g.x+b*(h.x-g.x),e.y=g.y+b*(h.y-g.y),a[f].id=i>0?c[0].id:c[1].id,++f;return f};
b2Collision.EdgeSeparation=function(a,c,b){for(var e=a.m_vertices,f=b.m_vertexCount,g=b.m_vertices,h=a.m_normals[c].x,i=a.m_normals[c].y,k=h,j=a.m_R,h=j.col1.x*k+j.col2.x*i,i=j.col1.y*k+j.col2.y*i,l=h,m=i,j=b.m_R,k=l*j.col1.x+m*j.col1.y,m=l*j.col2.x+m*j.col2.y,l=k,k=0,j=Number.MAX_VALUE,n=0;n<f;++n){var o=g[n],o=o.x*l+o.y*m;o<j&&(j=o,k=n)}j=a.m_R;f=a.m_position.x+(j.col1.x*e[c].x+j.col2.x*e[c].y);a=a.m_position.y+(j.col1.y*e[c].x+j.col2.y*e[c].y);j=b.m_R;c=b.m_position.x+(j.col1.x*g[k].x+j.col2.x*
g[k].y);b=b.m_position.y+(j.col1.y*g[k].x+j.col2.y*g[k].y);c-=f;b-=a;return c*h+b*i};
b2Collision.FindMaxSeparation=function(a,c,b,e){for(var f=c.m_vertexCount,g=b.m_position.x-c.m_position.x,h=b.m_position.y-c.m_position.y,i=g*c.m_R.col1.x+h*c.m_R.col1.y,h=g*c.m_R.col2.x+h*c.m_R.col2.y,g=0,k=-Number.MAX_VALUE,j=0;j<f;++j){var l=c.m_normals[j].x*i+c.m_normals[j].y*h;l>k&&(k=l,g=j)}i=b2Collision.EdgeSeparation(c,g,b);if(i>0&&e==!1)return i;j=g-1>=0?g-1:f-1;l=b2Collision.EdgeSeparation(c,j,b);if(l>0&&e==!1)return l;var m=g+1<f?g+1:0,n=b2Collision.EdgeSeparation(c,m,b);if(n>0&&e==!1)return n;
k=h=0;if(l>i&&l>n)k=-1,h=j,j=l;else if(n>i)k=1,h=m,j=n;else return a[0]=g,i;for(;;){g=k==-1?h-1>=0?h-1:f-1:h+1<f?h+1:0;i=b2Collision.EdgeSeparation(c,g,b);if(i>0&&e==!1)return i;if(i>j)h=g,j=i;else break}a[0]=h;return j};
b2Collision.FindIncidentEdge=function(a,c,b,e){var f=c.m_vertices,g=e.m_vertexCount,h=e.m_vertices,i=f[b+1==c.m_vertexCount?0:b+1],k=i.x,j=i.y,i=f[b];k-=i.x;j-=i.y;i=k;k=j;j=-i;i=1/Math.sqrt(k*k+j*j);k*=i;j*=i;for(var i=k,f=c.m_R,c=f.col1.x*i+f.col2.x*j,k=j=f.col1.y*i+f.col2.y*j,f=e.m_R,i=c*f.col1.x+k*f.col1.y,k=c*f.col2.x+k*f.col2.y,c=i,f=j=0,l=Number.MAX_VALUE,m=0;m<g;++m){var n=m,o=m+1<g?m+1:0,i=h[o],p=i.x,q=i.y,i=h[n];p-=i.x;q-=i.y;i=p;p=q;q=-i;i=1/Math.sqrt(p*p+q*q);p*=i;q*=i;i=p*c+q*k;i<l&&
(l=i,j=n,f=o)}g=a[0];i=g.v;i.SetV(h[j]);i.MulM(e.m_R);i.Add(e.m_position);g.id.features.referenceFace=b;g.id.features.incidentEdge=j;g.id.features.incidentVertex=j;g=a[1];i=g.v;i.SetV(h[f]);i.MulM(e.m_R);i.Add(e.m_position);g.id.features.referenceFace=b;g.id.features.incidentEdge=j;g.id.features.incidentVertex=f};b2Collision.b2CollidePolyTempVec=new b2Vec2;
b2Collision.b2CollidePoly=function(a,c,b,e){a.pointCount=0;var f,g=[0],h=b2Collision.FindMaxSeparation(g,c,b,e);f=g[0];if(!(h>0&&e==!1)){var i,g=[0],k=b2Collision.FindMaxSeparation(g,b,c,e);i=g[0];if(!(k>0&&e==!1)){var j=0,g=0;k>0.98*h+0.0010?(h=b,j=i,g=1):(h=c,c=b,j=f,g=0);b=[new ClipVertex,new ClipVertex];b2Collision.FindIncidentEdge(b,h,j,c);var c=h.m_vertices,l=c[j],m=j+1<h.m_vertexCount?c[j+1]:c[0];f=m.x-l.x;i=m.y-l.y;var n=f,o=h.m_R;f=o.col1.x*n+o.col2.x*i;i=o.col1.y*n+o.col2.y*i;j=1/Math.sqrt(f*
f+i*i);f*=j;i*=j;var n=f,j=i,c=-n,k=l.x,p=l.y,n=k,o=h.m_R,k=o.col1.x*n+o.col2.x*p,p=o.col1.y*n+o.col2.y*p;k+=h.m_position.x;p+=h.m_position.y;l=m.x;m=m.y;n=l;o=h.m_R;l=o.col1.x*n+o.col2.x*m;m=o.col1.y*n+o.col2.y*m;l+=h.m_position.x;m+=h.m_position.y;h=j*k+c*p;n=-(f*k+i*p);l=f*l+i*m;m=[new ClipVertex,new ClipVertex];k=[new ClipVertex,new ClipVertex];o=0;b2Collision.b2CollidePolyTempVec.Set(-f,-i);o=b2Collision.ClipSegmentToLine(m,b,b2Collision.b2CollidePolyTempVec,n);if(!(o<2)&&(b2Collision.b2CollidePolyTempVec.Set(f,
i),o=b2Collision.ClipSegmentToLine(k,m,b2Collision.b2CollidePolyTempVec,l),!(o<2))){g?a.normal.Set(-j,-c):a.normal.Set(j,c);for(f=b=0;f<b2Settings.b2_maxManifoldPoints;++f)if(i=k[f].v,i=j*i.x+c*i.y-h,i<=0||e==!0)l=a.points[b],l.separation=i,l.position.SetV(k[f].v),l.id.Set(k[f].id),l.id.features.flip=g,++b;a.pointCount=b}}}};
b2Collision.b2CollideCircle=function(a,c,b,e){a.pointCount=0;var f=b.m_position.x-c.m_position.x,g=b.m_position.y-c.m_position.y,h=f*f+g*g,c=c.m_radius+b.m_radius;if(!(h>c*c&&e==!1))h<Number.MIN_VALUE?(e=-c,a.normal.Set(0,1)):(h=Math.sqrt(h),e=h-c,h=1/h,a.normal.x=h*f,a.normal.y=h*g),a.pointCount=1,f=a.points[0],f.id.set_key(0),f.separation=e,f.position.x=b.m_position.x-b.m_radius*a.normal.x,f.position.y=b.m_position.y-b.m_radius*a.normal.y};
b2Collision.b2CollidePolyAndCircle=function(a,c,b){a.pointCount=0;var e,f,g;f=b.m_position.x-c.m_position.x;g=b.m_position.y-c.m_position.y;var h=c.m_R,i=f*h.col1.x+g*h.col1.y;g=f*h.col2.x+g*h.col2.y;f=i;var k=0,j=-Number.MAX_VALUE,i=b.m_radius;for(e=0;e<c.m_vertexCount;++e){var l=c.m_normals[e].x*(f-c.m_vertices[e].x)+c.m_normals[e].y*(g-c.m_vertices[e].y);if(l>i)return;l>j&&(j=l,k=e)}if(j<Number.MIN_VALUE)a.pointCount=1,g=c.m_normals[k],a.normal.x=h.col1.x*g.x+h.col2.x*g.y,a.normal.y=h.col1.y*g.x+
h.col2.y*g.y,e=a.points[0],e.id.features.incidentEdge=k,e.id.features.incidentVertex=b2Collision.b2_nullFeature,e.id.features.referenceFace=b2Collision.b2_nullFeature,e.id.features.flip=0,e.position.x=b.m_position.x-i*a.normal.x,e.position.y=b.m_position.y-i*a.normal.y,e.separation=j-i;else{var j=k+1<c.m_vertexCount?k+1:0,m=c.m_vertices[j].x-c.m_vertices[k].x,l=c.m_vertices[j].y-c.m_vertices[k].y,n=Math.sqrt(m*m+l*l);m/=n;l/=n;if(n<Number.MIN_VALUE){if(f-=c.m_vertices[k].x,g-=c.m_vertices[k].y,c=
Math.sqrt(f*f+g*g),f/=c,g/=c,!(c>i))a.pointCount=1,a.normal.Set(h.col1.x*f+h.col2.x*g,h.col1.y*f+h.col2.y*g),e=a.points[0],e.id.features.incidentEdge=b2Collision.b2_nullFeature,e.id.features.incidentVertex=k,e.id.features.referenceFace=b2Collision.b2_nullFeature,e.id.features.flip=0,e.position.x=b.m_position.x-i*a.normal.x,e.position.y=b.m_position.y-i*a.normal.y,e.separation=c-i}else{var o=(f-c.m_vertices[k].x)*m+(g-c.m_vertices[k].y)*l;e=a.points[0];e.id.features.incidentEdge=b2Collision.b2_nullFeature;
e.id.features.incidentVertex=b2Collision.b2_nullFeature;e.id.features.referenceFace=b2Collision.b2_nullFeature;e.id.features.flip=0;o<=0?(m=c.m_vertices[k].x,c=c.m_vertices[k].y,e.id.features.incidentVertex=k):o>=n?(m=c.m_vertices[j].x,c=c.m_vertices[j].y,e.id.features.incidentVertex=j):(m=m*o+c.m_vertices[k].x,c=l*o+c.m_vertices[k].y,e.id.features.incidentEdge=k);f-=m;g-=c;c=Math.sqrt(f*f+g*g);f/=c;g/=c;if(!(c>i))a.pointCount=1,a.normal.Set(h.col1.x*f+h.col2.x*g,h.col1.y*f+h.col2.y*g),e.position.x=
b.m_position.x-i*a.normal.x,e.position.y=b.m_position.y-i*a.normal.y,e.separation=c-i}}};b2Collision.b2TestOverlap=function(a,c){var b=c.minVertex,e=a.maxVertex,f=b.x-e.x,g=b.y-e.y,b=a.minVertex,e=c.maxVertex,h=b.y-e.y;if(f>0||g>0)return!1;if(b.x-e.x>0||h>0)return!1;return!0};var Features=Class.create();
Features.prototype={set_referenceFace:function(a){this._referenceFace=a;this._m_id._key=this._m_id._key&4294967040|this._referenceFace&255},get_referenceFace:function(){return this._referenceFace},_referenceFace:0,set_incidentEdge:function(a){this._incidentEdge=a;this._m_id._key=this._m_id._key&4294902015|this._incidentEdge<<8&65280},get_incidentEdge:function(){return this._incidentEdge},_incidentEdge:0,set_incidentVertex:function(a){this._incidentVertex=a;this._m_id._key=this._m_id._key&4278255615|
this._incidentVertex<<16&16711680},get_incidentVertex:function(){return this._incidentVertex},_incidentVertex:0,set_flip:function(a){this._flip=a;this._m_id._key=this._m_id._key&16777215|this._flip<<24&4278190080},get_flip:function(){return this._flip},_flip:0,_m_id:null,initialize:function(){}};var b2ContactID=Class.create();
b2ContactID.prototype={initialize:function(){this.features=new Features;this.features._m_id=this},Set:function(a){this.set_key(a._key)},Copy:function(){var a=new b2ContactID;a.set_key(this._key);return a},get_key:function(){return this._key},set_key:function(a){this._key=a;this.features._referenceFace=this._key&255;this.features._incidentEdge=(this._key&65280)>>8&255;this.features._incidentVertex=(this._key&16711680)>>16&255;this.features._flip=(this._key&4278190080)>>24&255},features:new Features,
_key:0};var b2ContactPoint=Class.create();b2ContactPoint.prototype={position:new b2Vec2,separation:null,normalImpulse:null,tangentImpulse:null,id:new b2ContactID,initialize:function(){this.position=new b2Vec2;this.id=new b2ContactID}};var b2Distance=Class.create();b2Distance.prototype={initialize:function(){}};
b2Distance.ProcessTwo=function(a,c,b,e,f){var g=-f[1].x,h=-f[1].y,i=f[0].x-f[1].x,k=f[0].y-f[1].y,j=Math.sqrt(i*i+k*k);i/=j;k/=j;g=g*i+h*k;if(g<=0||j<Number.MIN_VALUE)return a.SetV(b[1]),c.SetV(e[1]),b[0].SetV(b[1]),e[0].SetV(e[1]),f[0].SetV(f[1]),1;g/=j;a.x=b[1].x+g*(b[0].x-b[1].x);a.y=b[1].y+g*(b[0].y-b[1].y);c.x=e[1].x+g*(e[0].x-e[1].x);c.y=e[1].y+g*(e[0].y-e[1].y);return 2};
b2Distance.ProcessThree=function(a,c,b,e,f){var g=f[0].x,h=f[0].y,i=f[1].x,k=f[1].y,j=f[2].x,l=f[2].y,m=i-g,n=k-h,o=j-g,p=l-h,q=j-i,s=l-k,r=-(g*o+h*p),u=j*o+l*p,z=-(i*q+k*s),q=j*q+l*s;if(u<=0&&q<=0)return a.SetV(b[2]),c.SetV(e[2]),b[0].SetV(b[2]),e[0].SetV(e[2]),f[0].SetV(f[2]),1;n=m*p-n*o;m=n*(g*k-h*i);i=n*(i*l-k*j);if(i<=0&&z>=0&&q>=0)return r=z/(z+q),a.x=b[1].x+r*(b[2].x-b[1].x),a.y=b[1].y+r*(b[2].y-b[1].y),c.x=e[1].x+r*(e[2].x-e[1].x),c.y=e[1].y+r*(e[2].y-e[1].y),b[0].SetV(b[2]),e[0].SetV(e[2]),
f[0].SetV(f[2]),2;g=n*(j*h-l*g);if(g<=0&&r>=0&&u>=0)return r/=r+u,a.x=b[0].x+r*(b[2].x-b[0].x),a.y=b[0].y+r*(b[2].y-b[0].y),c.x=e[0].x+r*(e[2].x-e[0].x),c.y=e[0].y+r*(e[2].y-e[0].y),b[1].SetV(b[2]),e[1].SetV(e[2]),f[1].SetV(f[2]),2;r=1/(i+g+m);f=i*r;r*=g;u=1-f-r;a.x=f*b[0].x+r*b[1].x+u*b[2].x;a.y=f*b[0].y+r*b[1].y+u*b[2].y;c.x=f*e[0].x+r*e[1].x+u*e[2].x;c.y=f*e[0].y+r*e[1].y+u*e[2].y;return 3};b2Distance.InPoinsts=function(a,c,b){for(var e=0;e<b;++e)if(a.x==c[e].x&&a.y==c[e].y)return!0;return!1};
b2Distance.Distance=function(a,c,b,e){var f=Array(3),g=Array(3),h=Array(3),i=0;a.SetV(b.m_position);c.SetV(e.m_position);for(var k=0,j=0;j<20;++j){var l=c.x-a.x,m=c.y-a.y,n=b.Support(l,m),o=e.Support(-l,-m),k=l*l+m*m,p=o.x-n.x,q=o.y-n.y;if(k-b2Dot(l*p+m*q)<=0.01*k)return i==0&&(a.SetV(n),c.SetV(o)),b2Distance.g_GJK_Iterations=j,Math.sqrt(k);switch(i){case 0:f[0].SetV(n);g[0].SetV(o);h[0]=w;a.SetV(f[0]);c.SetV(g[0]);++i;break;case 1:f[1].SetV(n);g[1].SetV(o);h[1].x=p;h[1].y=q;i=b2Distance.ProcessTwo(a,
c,f,g,h);break;case 2:f[2].SetV(n),g[2].SetV(o),h[2].x=p,h[2].y=q,i=b2Distance.ProcessThree(a,c,f,g,h)}if(i==3)return b2Distance.g_GJK_Iterations=j,0;l=-Number.MAX_VALUE;for(m=0;m<i;++m)l=b2Math.b2Max(l,h[m].x*h[m].x+h[m].y*h[m].y);if(i==3||k<=100*Number.MIN_VALUE*l)return b2Distance.g_GJK_Iterations=j,Math.sqrt(k)}b2Distance.g_GJK_Iterations=20;return Math.sqrt(k)};b2Distance.g_GJK_Iterations=0;var b2Manifold=Class.create();
b2Manifold.prototype={initialize:function(){this.points=Array(b2Settings.b2_maxManifoldPoints);for(var a=0;a<b2Settings.b2_maxManifoldPoints;a++)this.points[a]=new b2ContactPoint;this.normal=new b2Vec2},points:null,normal:null,pointCount:0};var b2OBB=Class.create();b2OBB.prototype={R:new b2Mat22,center:new b2Vec2,extents:new b2Vec2,initialize:function(){this.R=new b2Mat22;this.center=new b2Vec2;this.extents=new b2Vec2}};var b2Proxy=Class.create();
b2Proxy.prototype={GetNext:function(){return this.lowerBounds[0]},SetNext:function(a){this.lowerBounds[0]=a},IsValid:function(){return this.overlapCount!=b2BroadPhase.b2_invalid},lowerBounds:[0,0],upperBounds:[0,0],overlapCount:0,timeStamp:0,userData:null,initialize:function(){this.lowerBounds=[0,0];this.upperBounds=[0,0]}};var ClipVertex=Class.create();ClipVertex.prototype={v:new b2Vec2,id:new b2ContactID,initialize:function(){this.v=new b2Vec2;this.id=new b2ContactID}};var b2Shape=Class.create();
b2Shape.prototype={TestPoint:function(){return!1},GetUserData:function(){return this.m_userData},GetType:function(){return this.m_type},GetBody:function(){return this.m_body},GetPosition:function(){return this.m_position},GetRotationMatrix:function(){return this.m_R},ResetProxy:function(){},GetNext:function(){return this.m_next},initialize:function(a,c){this.m_R=new b2Mat22;this.m_position=new b2Vec2;this.m_userData=a.userData;this.m_friction=a.friction;this.m_restitution=a.restitution;this.m_body=
c;this.m_proxyId=b2Pair.b2_nullProxy;this.m_maxRadius=0;this.m_categoryBits=a.categoryBits;this.m_maskBits=a.maskBits;this.m_groupIndex=a.groupIndex},DestroyProxy:function(){if(this.m_proxyId!=b2Pair.b2_nullProxy)this.m_body.m_world.m_broadPhase.DestroyProxy(this.m_proxyId),this.m_proxyId=b2Pair.b2_nullProxy},Synchronize:function(){},QuickSync:function(){},Support:function(){},GetMaxRadius:function(){return this.m_maxRadius},m_next:null,m_R:new b2Mat22,m_position:new b2Vec2,m_type:0,m_userData:null,
m_body:null,m_friction:null,m_restitution:null,m_maxRadius:null,m_proxyId:0,m_categoryBits:0,m_maskBits:0,m_groupIndex:0};b2Shape.Create=function(a,c,b){switch(a.type){case b2Shape.e_circleShape:return new b2CircleShape(a,c,b);case b2Shape.e_boxShape:case b2Shape.e_polyShape:return new b2PolyShape(a,c,b)}return null};b2Shape.Destroy=function(a){a.m_proxyId!=b2Pair.b2_nullProxy&&a.m_body.m_world.m_broadPhase.DestroyProxy(a.m_proxyId)};b2Shape.e_unknownShape=-1;b2Shape.e_circleShape=0;
b2Shape.e_boxShape=1;b2Shape.e_polyShape=2;b2Shape.e_meshShape=3;b2Shape.e_shapeTypeCount=4;
b2Shape.PolyMass=function(a,c,b,e){var f=new b2Vec2;f.SetZero();for(var g=0,h=0,i=new b2Vec2(0,0),k=1/3,j=0;j<b;++j){var l=i,m=c[j],n=j+1<b?c[j+1]:c[0],o=b2Math.SubtractVV(m,l),p=b2Math.SubtractVV(n,l),q=b2Math.b2CrossVV(o,p),s=0.5*q;g+=s;var r=new b2Vec2;r.SetV(l);r.Add(m);r.Add(n);r.Multiply(k*s);f.Add(r);m=l.x;l=l.y;n=o.x;o=o.y;s=p.x;p=p.y;h+=q*(k*(0.25*(n*n+s*n+s*s)+(m*n+m*s))+0.5*m*m+(k*(0.25*(o*o+p*o+p*p)+(l*o+l*p))+0.5*l*l))}a.mass=e*g;f.Multiply(1/g);a.center=f;h=e*(h-g*b2Math.b2Dot(f,f));
a.I=h};b2Shape.PolyCentroid=function(a,c,b){for(var e=0,f=0,g=0,h=1/3,i=0;i<c;++i){var k=a[i].x,j=a[i].y,l=i+1<c?a[i+1].x:a[0].x,m=i+1<c?a[i+1].y:a[0].y,n=0.5*((k-0)*(m-0)-(j-0)*(l-0));g+=n;e+=n*h*(0+k+l);f+=n*h*(0+j+m)}e*=1/g;f*=1/g;b.Set(e,f)};var b2ShapeDef=Class.create();
b2ShapeDef.prototype={initialize:function(){this.type=b2Shape.e_unknownShape;this.userData=null;this.localPosition=new b2Vec2(0,0);this.localRotation=0;this.friction=0.2;this.density=this.restitution=0;this.categoryBits=1;this.maskBits=65535;this.groupIndex=0},ComputeMass:function(a){a.center=new b2Vec2(0,0);if(this.density==0)a.mass=0,a.center.Set(0,0),a.I=0;switch(this.type){case b2Shape.e_circleShape:a.mass=this.density*b2Settings.b2_pi*this.radius*this.radius;a.center.Set(0,0);a.I=0.5*a.mass*
this.radius*this.radius;break;case b2Shape.e_boxShape:a.mass=4*this.density*this.extents.x*this.extents.y;a.center.Set(0,0);a.I=a.mass/3*b2Math.b2Dot(this.extents,this.extents);break;case b2Shape.e_polyShape:b2Shape.PolyMass(a,this.vertices,this.vertexCount,this.density);break;default:a.mass=0,a.center.Set(0,0),a.I=0}},type:0,userData:null,localPosition:null,localRotation:null,friction:null,restitution:null,density:null,categoryBits:0,maskBits:0,groupIndex:0};var b2BoxDef=Class.create();
Object.extend(b2BoxDef.prototype,b2ShapeDef.prototype);Object.extend(b2BoxDef.prototype,{initialize:function(){this.type=b2Shape.e_unknownShape;this.userData=null;this.localPosition=new b2Vec2(0,0);this.localRotation=0;this.friction=0.2;this.density=this.restitution=0;this.categoryBits=1;this.maskBits=65535;this.groupIndex=0;this.type=b2Shape.e_boxShape;this.extents=new b2Vec2(1,1)},extents:null});var b2CircleDef=Class.create();Object.extend(b2CircleDef.prototype,b2ShapeDef.prototype);
Object.extend(b2CircleDef.prototype,{initialize:function(){this.type=b2Shape.e_unknownShape;this.userData=null;this.localPosition=new b2Vec2(0,0);this.localRotation=0;this.friction=0.2;this.density=this.restitution=0;this.categoryBits=1;this.maskBits=65535;this.groupIndex=0;this.type=b2Shape.e_circleShape;this.radius=1},radius:null});var b2CircleShape=Class.create();Object.extend(b2CircleShape.prototype,b2Shape.prototype);
Object.extend(b2CircleShape.prototype,{TestPoint:function(a){var c=new b2Vec2;c.SetV(a);c.Subtract(this.m_position);return b2Math.b2Dot(c,c)<=this.m_radius*this.m_radius},initialize:function(a,c,b){this.m_R=new b2Mat22;this.m_position=new b2Vec2;this.m_userData=a.userData;this.m_friction=a.friction;this.m_restitution=a.restitution;this.m_body=c;this.m_proxyId=b2Pair.b2_nullProxy;this.m_maxRadius=0;this.m_categoryBits=a.categoryBits;this.m_maskBits=a.maskBits;this.m_groupIndex=a.groupIndex;this.m_localPosition=
new b2Vec2;this.m_localPosition.Set(a.localPosition.x-b.x,a.localPosition.y-b.y);this.m_type=b2Shape.e_circleShape;this.m_radius=a.radius;this.m_R.SetM(this.m_body.m_R);a=this.m_R.col1.x*this.m_localPosition.x+this.m_R.col2.x*this.m_localPosition.y;c=this.m_R.col1.y*this.m_localPosition.x+this.m_R.col2.y*this.m_localPosition.y;this.m_position.x=this.m_body.m_position.x+a;this.m_position.y=this.m_body.m_position.y+c;this.m_maxRadius=Math.sqrt(a*a+c*c)+this.m_radius;a=new b2AABB;a.minVertex.Set(this.m_position.x-
this.m_radius,this.m_position.y-this.m_radius);a.maxVertex.Set(this.m_position.x+this.m_radius,this.m_position.y+this.m_radius);c=this.m_body.m_world.m_broadPhase;this.m_proxyId=c.InRange(a)?c.CreateProxy(a,this):b2Pair.b2_nullProxy;this.m_proxyId==b2Pair.b2_nullProxy&&this.m_body.Freeze()},Synchronize:function(a,c,b,e){this.m_R.SetM(e);this.m_position.x=e.col1.x*this.m_localPosition.x+e.col2.x*this.m_localPosition.y+b.x;this.m_position.y=e.col1.y*this.m_localPosition.x+e.col2.y*this.m_localPosition.y+
b.y;if(this.m_proxyId!=b2Pair.b2_nullProxy){var b=a.x+(c.col1.x*this.m_localPosition.x+c.col2.x*this.m_localPosition.y),e=a.y+(c.col1.y*this.m_localPosition.x+c.col2.y*this.m_localPosition.y),a=Math.min(b,this.m_position.x),c=Math.min(e,this.m_position.y),b=Math.max(b,this.m_position.x),f=Math.max(e,this.m_position.y),e=new b2AABB;e.minVertex.Set(a-this.m_radius,c-this.m_radius);e.maxVertex.Set(b+this.m_radius,f+this.m_radius);a=this.m_body.m_world.m_broadPhase;a.InRange(e)?a.MoveProxy(this.m_proxyId,
e):this.m_body.Freeze()}},QuickSync:function(a,c){this.m_R.SetM(c);this.m_position.x=c.col1.x*this.m_localPosition.x+c.col2.x*this.m_localPosition.y+a.x;this.m_position.y=c.col1.y*this.m_localPosition.x+c.col2.y*this.m_localPosition.y+a.y},ResetProxy:function(a){if(this.m_proxyId!=b2Pair.b2_nullProxy){a.GetProxy(this.m_proxyId);a.DestroyProxy(this.m_proxyId);var c=new b2AABB;c.minVertex.Set(this.m_position.x-this.m_radius,this.m_position.y-this.m_radius);c.maxVertex.Set(this.m_position.x+this.m_radius,
this.m_position.y+this.m_radius);this.m_proxyId=a.InRange(c)?a.CreateProxy(c,this):b2Pair.b2_nullProxy;this.m_proxyId==b2Pair.b2_nullProxy&&this.m_body.Freeze()}},Support:function(a,c,b){var e=Math.sqrt(a*a+c*c);a/=e;c/=e;b.Set(this.m_position.x+this.m_radius*a,this.m_position.y+this.m_radius*c)},m_localPosition:new b2Vec2,m_radius:null});var b2MassData=Class.create();b2MassData.prototype={mass:0,center:new b2Vec2(0,0),I:0,initialize:function(){this.center=new b2Vec2(0,0)}};var b2PolyDef=Class.create();
Object.extend(b2PolyDef.prototype,b2ShapeDef.prototype);
Object.extend(b2PolyDef.prototype,{initialize:function(){this.type=b2Shape.e_unknownShape;this.userData=null;this.localPosition=new b2Vec2(0,0);this.localRotation=0;this.friction=0.2;this.density=this.restitution=0;this.categoryBits=1;this.maskBits=65535;this.groupIndex=0;this.vertices=Array(b2Settings.b2_maxPolyVertices);this.type=b2Shape.e_polyShape;for(var a=this.vertexCount=0;a<b2Settings.b2_maxPolyVertices;a++)this.vertices[a]=new b2Vec2},vertices:Array(b2Settings.b2_maxPolyVertices),vertexCount:0});
var b2PolyShape=Class.create();Object.extend(b2PolyShape.prototype,b2Shape.prototype);
Object.extend(b2PolyShape.prototype,{TestPoint:function(a){var c=new b2Vec2;c.SetV(a);c.Subtract(this.m_position);c.MulTM(this.m_R);for(a=0;a<this.m_vertexCount;++a){var b=new b2Vec2;b.SetV(c);b.Subtract(this.m_vertices[a]);if(b2Math.b2Dot(this.m_normals[a],b)>0)return!1}return!0},initialize:function(a,c,b){this.m_R=new b2Mat22;this.m_position=new b2Vec2;this.m_userData=a.userData;this.m_friction=a.friction;this.m_restitution=a.restitution;this.m_body=c;this.m_proxyId=b2Pair.b2_nullProxy;this.m_maxRadius=
0;this.m_categoryBits=a.categoryBits;this.m_maskBits=a.maskBits;this.m_groupIndex=a.groupIndex;this.syncAABB=new b2AABB;this.syncMat=new b2Mat22;this.m_localCentroid=new b2Vec2;this.m_localOBB=new b2OBB;var e=0,f,c=new b2AABB;this.m_vertices=Array(b2Settings.b2_maxPolyVertices);this.m_coreVertices=Array(b2Settings.b2_maxPolyVertices);this.m_normals=Array(b2Settings.b2_maxPolyVertices);this.m_type=b2Shape.e_polyShape;var g=new b2Mat22(a.localRotation);if(a.type==b2Shape.e_boxShape){this.m_localCentroid.x=
a.localPosition.x-b.x;this.m_localCentroid.y=a.localPosition.y-b.y;this.m_vertexCount=4;b=a.extents.x;f=a.extents.y;var a=Math.max(0,b-2*b2Settings.b2_linearSlop),h=Math.max(0,f-2*b2Settings.b2_linearSlop),e=this.m_vertices[0]=new b2Vec2;e.x=g.col1.x*b+g.col2.x*f;e.y=g.col1.y*b+g.col2.y*f;e=this.m_vertices[1]=new b2Vec2;e.x=g.col1.x*-b+g.col2.x*f;e.y=g.col1.y*-b+g.col2.y*f;e=this.m_vertices[2]=new b2Vec2;e.x=g.col1.x*-b+g.col2.x*-f;e.y=g.col1.y*-b+g.col2.y*-f;e=this.m_vertices[3]=new b2Vec2;e.x=g.col1.x*
b+g.col2.x*-f;e.y=g.col1.y*b+g.col2.y*-f;e=this.m_coreVertices[0]=new b2Vec2;e.x=g.col1.x*a+g.col2.x*h;e.y=g.col1.y*a+g.col2.y*h;e=this.m_coreVertices[1]=new b2Vec2;e.x=g.col1.x*-a+g.col2.x*h;e.y=g.col1.y*-a+g.col2.y*h;e=this.m_coreVertices[2]=new b2Vec2;e.x=g.col1.x*-a+g.col2.x*-h;e.y=g.col1.y*-a+g.col2.y*-h;e=this.m_coreVertices[3]=new b2Vec2;e.x=g.col1.x*a+g.col2.x*-h;e.y=g.col1.y*a+g.col2.y*-h}else{this.m_vertexCount=a.vertexCount;b2Shape.PolyCentroid(a.vertices,a.vertexCount,b2PolyShape.tempVec);
var h=b2PolyShape.tempVec.x,i=b2PolyShape.tempVec.y;this.m_localCentroid.x=a.localPosition.x+(g.col1.x*h+g.col2.x*i)-b.x;this.m_localCentroid.y=a.localPosition.y+(g.col1.y*h+g.col2.y*i)-b.y;for(e=0;e<this.m_vertexCount;++e){this.m_vertices[e]=new b2Vec2;this.m_coreVertices[e]=new b2Vec2;b=a.vertices[e].x-h;f=a.vertices[e].y-i;this.m_vertices[e].x=g.col1.x*b+g.col2.x*f;this.m_vertices[e].y=g.col1.y*b+g.col2.y*f;b=this.m_vertices[e].x;f=this.m_vertices[e].y;var k=Math.sqrt(b*b+f*f);k>Number.MIN_VALUE&&
(b*=1/k,f*=1/k);this.m_coreVertices[e].x=this.m_vertices[e].x-2*b2Settings.b2_linearSlop*b;this.m_coreVertices[e].y=this.m_vertices[e].y-2*b2Settings.b2_linearSlop*f}}a=g=Number.MAX_VALUE;b=-Number.MAX_VALUE;f=-Number.MAX_VALUE;for(e=this.m_maxRadius=0;e<this.m_vertexCount;++e)h=this.m_vertices[e],g=Math.min(g,h.x),a=Math.min(a,h.y),b=Math.max(b,h.x),f=Math.max(f,h.y),this.m_maxRadius=Math.max(this.m_maxRadius,h.Length());this.m_localOBB.R.SetIdentity();this.m_localOBB.center.Set((g+b)*0.5,(a+f)*
0.5);this.m_localOBB.extents.Set((b-g)*0.5,(f-a)*0.5);for(e=a=g=0;e<this.m_vertexCount;++e)this.m_normals[e]=new b2Vec2,g=e,a=e+1<this.m_vertexCount?e+1:0,this.m_normals[e].x=this.m_vertices[a].y-this.m_vertices[g].y,this.m_normals[e].y=-(this.m_vertices[a].x-this.m_vertices[g].x),this.m_normals[e].Normalize();for(e=0;e<this.m_vertexCount;++e);this.m_R.SetM(this.m_body.m_R);this.m_position.x=this.m_body.m_position.x+(this.m_R.col1.x*this.m_localCentroid.x+this.m_R.col2.x*this.m_localCentroid.y);this.m_position.y=
this.m_body.m_position.y+(this.m_R.col1.y*this.m_localCentroid.x+this.m_R.col2.y*this.m_localCentroid.y);b2PolyShape.tAbsR.col1.x=this.m_R.col1.x*this.m_localOBB.R.col1.x+this.m_R.col2.x*this.m_localOBB.R.col1.y;b2PolyShape.tAbsR.col1.y=this.m_R.col1.y*this.m_localOBB.R.col1.x+this.m_R.col2.y*this.m_localOBB.R.col1.y;b2PolyShape.tAbsR.col2.x=this.m_R.col1.x*this.m_localOBB.R.col2.x+this.m_R.col2.x*this.m_localOBB.R.col2.y;b2PolyShape.tAbsR.col2.y=this.m_R.col1.y*this.m_localOBB.R.col2.x+this.m_R.col2.y*
this.m_localOBB.R.col2.y;b2PolyShape.tAbsR.Abs();b=b2PolyShape.tAbsR.col1.x*this.m_localOBB.extents.x+b2PolyShape.tAbsR.col2.x*this.m_localOBB.extents.y;f=b2PolyShape.tAbsR.col1.y*this.m_localOBB.extents.x+b2PolyShape.tAbsR.col2.y*this.m_localOBB.extents.y;e=this.m_position.x+(this.m_R.col1.x*this.m_localOBB.center.x+this.m_R.col2.x*this.m_localOBB.center.y);g=this.m_position.y+(this.m_R.col1.y*this.m_localOBB.center.x+this.m_R.col2.y*this.m_localOBB.center.y);c.minVertex.x=e-b;c.minVertex.y=g-f;
c.maxVertex.x=e+b;c.maxVertex.y=g+f;e=this.m_body.m_world.m_broadPhase;this.m_proxyId=e.InRange(c)?e.CreateProxy(c,this):b2Pair.b2_nullProxy;this.m_proxyId==b2Pair.b2_nullProxy&&this.m_body.Freeze()},syncAABB:new b2AABB,syncMat:new b2Mat22,Synchronize:function(a,c,b,e){this.m_R.SetM(e);this.m_position.x=this.m_body.m_position.x+(e.col1.x*this.m_localCentroid.x+e.col2.x*this.m_localCentroid.y);this.m_position.y=this.m_body.m_position.y+(e.col1.y*this.m_localCentroid.x+e.col2.y*this.m_localCentroid.y);
if(this.m_proxyId!=b2Pair.b2_nullProxy){var f,g;f=c.col1;g=c.col2;var h=this.m_localOBB.R.col1,i=this.m_localOBB.R.col2;this.syncMat.col1.x=f.x*h.x+g.x*h.y;this.syncMat.col1.y=f.y*h.x+g.y*h.y;this.syncMat.col2.x=f.x*i.x+g.x*i.y;this.syncMat.col2.y=f.y*i.x+g.y*i.y;this.syncMat.Abs();f=this.m_localCentroid.x+this.m_localOBB.center.x;g=this.m_localCentroid.y+this.m_localOBB.center.y;h=a.x+(c.col1.x*f+c.col2.x*g);a=a.y+(c.col1.y*f+c.col2.y*g);f=this.syncMat.col1.x*this.m_localOBB.extents.x+this.syncMat.col2.x*
this.m_localOBB.extents.y;g=this.syncMat.col1.y*this.m_localOBB.extents.x+this.syncMat.col2.y*this.m_localOBB.extents.y;this.syncAABB.minVertex.x=h-f;this.syncAABB.minVertex.y=a-g;this.syncAABB.maxVertex.x=h+f;this.syncAABB.maxVertex.y=a+g;f=e.col1;g=e.col2;h=this.m_localOBB.R.col1;i=this.m_localOBB.R.col2;this.syncMat.col1.x=f.x*h.x+g.x*h.y;this.syncMat.col1.y=f.y*h.x+g.y*h.y;this.syncMat.col2.x=f.x*i.x+g.x*i.y;this.syncMat.col2.y=f.y*i.x+g.y*i.y;this.syncMat.Abs();f=this.m_localCentroid.x+this.m_localOBB.center.x;
g=this.m_localCentroid.y+this.m_localOBB.center.y;h=b.x+(e.col1.x*f+e.col2.x*g);a=b.y+(e.col1.y*f+e.col2.y*g);f=this.syncMat.col1.x*this.m_localOBB.extents.x+this.syncMat.col2.x*this.m_localOBB.extents.y;g=this.syncMat.col1.y*this.m_localOBB.extents.x+this.syncMat.col2.y*this.m_localOBB.extents.y;this.syncAABB.minVertex.x=Math.min(this.syncAABB.minVertex.x,h-f);this.syncAABB.minVertex.y=Math.min(this.syncAABB.minVertex.y,a-g);this.syncAABB.maxVertex.x=Math.max(this.syncAABB.maxVertex.x,h+f);this.syncAABB.maxVertex.y=
Math.max(this.syncAABB.maxVertex.y,a+g);b=this.m_body.m_world.m_broadPhase;b.InRange(this.syncAABB)?b.MoveProxy(this.m_proxyId,this.syncAABB):this.m_body.Freeze()}},QuickSync:function(a,c){this.m_R.SetM(c);this.m_position.x=a.x+(c.col1.x*this.m_localCentroid.x+c.col2.x*this.m_localCentroid.y);this.m_position.y=a.y+(c.col1.y*this.m_localCentroid.x+c.col2.y*this.m_localCentroid.y)},ResetProxy:function(a){if(this.m_proxyId!=b2Pair.b2_nullProxy){a.GetProxy(this.m_proxyId);a.DestroyProxy(this.m_proxyId);
var c=b2Math.b2MulMM(this.m_R,this.m_localOBB.R),c=b2Math.b2AbsM(c),c=b2Math.b2MulMV(c,this.m_localOBB.extents),b=b2Math.b2MulMV(this.m_R,this.m_localOBB.center);b.Add(this.m_position);var e=new b2AABB;e.minVertex.SetV(b);e.minVertex.Subtract(c);e.maxVertex.SetV(b);e.maxVertex.Add(c);this.m_proxyId=a.InRange(e)?a.CreateProxy(e,this):b2Pair.b2_nullProxy;this.m_proxyId==b2Pair.b2_nullProxy&&this.m_body.Freeze()}},Support:function(a,c,b){for(var e=a*this.m_R.col1.x+c*this.m_R.col1.y,a=a*this.m_R.col2.x+
c*this.m_R.col2.y,c=0,f=this.m_coreVertices[0].x*e+this.m_coreVertices[0].y*a,g=1;g<this.m_vertexCount;++g){var h=this.m_coreVertices[g].x*e+this.m_coreVertices[g].y*a;h>f&&(c=g,f=h)}b.Set(this.m_position.x+(this.m_R.col1.x*this.m_coreVertices[c].x+this.m_R.col2.x*this.m_coreVertices[c].y),this.m_position.y+(this.m_R.col1.y*this.m_coreVertices[c].x+this.m_R.col2.y*this.m_coreVertices[c].y))},m_localCentroid:new b2Vec2,m_localOBB:new b2OBB,m_vertices:null,m_coreVertices:null,m_vertexCount:0,m_normals:null});
b2PolyShape.tempVec=new b2Vec2;b2PolyShape.tAbsR=new b2Mat22;var b2Body=Class.create();
b2Body.prototype={SetOriginPosition:function(a,c){if(!this.IsFrozen()){this.m_rotation=c;this.m_R.Set(this.m_rotation);this.m_position=b2Math.AddVV(a,b2Math.b2MulMV(this.m_R,this.m_center));this.m_position0.SetV(this.m_position);this.m_rotation0=this.m_rotation;for(var b=this.m_shapeList;b!=null;b=b.m_next)b.Synchronize(this.m_position,this.m_R,this.m_position,this.m_R);this.m_world.m_broadPhase.Commit()}},GetOriginPosition:function(){return b2Math.SubtractVV(this.m_position,b2Math.b2MulMV(this.m_R,
this.m_center))},SetCenterPosition:function(a,c){if(!this.IsFrozen()){this.m_rotation=c;this.m_R.Set(this.m_rotation);this.m_position.SetV(a);this.m_position0.SetV(this.m_position);this.m_rotation0=this.m_rotation;for(var b=this.m_shapeList;b!=null;b=b.m_next)b.Synchronize(this.m_position,this.m_R,this.m_position,this.m_R);this.m_world.m_broadPhase.Commit()}},GetCenterPosition:function(){return this.m_position},GetRotation:function(){return this.m_rotation},GetRotationMatrix:function(){return this.m_R},
SetLinearVelocity:function(a){this.m_linearVelocity.SetV(a)},GetLinearVelocity:function(){return this.m_linearVelocity},SetAngularVelocity:function(a){this.m_angularVelocity=a},GetAngularVelocity:function(){return this.m_angularVelocity},ApplyForce:function(a,c){this.IsSleeping()==!1&&(this.m_force.Add(a),this.m_torque+=b2Math.b2CrossVV(b2Math.SubtractVV(c,this.m_position),a))},ApplyTorque:function(a){this.IsSleeping()==!1&&(this.m_torque+=a)},ApplyImpulse:function(a,c){this.IsSleeping()==!1&&(this.m_linearVelocity.Add(b2Math.MulFV(this.m_invMass,
a)),this.m_angularVelocity+=this.m_invI*b2Math.b2CrossVV(b2Math.SubtractVV(c,this.m_position),a))},GetMass:function(){return this.m_mass},GetInertia:function(){return this.m_I},GetWorldPoint:function(a){return b2Math.AddVV(this.m_position,b2Math.b2MulMV(this.m_R,a))},GetWorldVector:function(a){return b2Math.b2MulMV(this.m_R,a)},GetLocalPoint:function(a){return b2Math.b2MulTMV(this.m_R,b2Math.SubtractVV(a,this.m_position))},GetLocalVector:function(a){return b2Math.b2MulTMV(this.m_R,a)},IsStatic:function(){return(this.m_flags&
b2Body.e_staticFlag)==b2Body.e_staticFlag},IsFrozen:function(){return(this.m_flags&b2Body.e_frozenFlag)==b2Body.e_frozenFlag},IsSleeping:function(){return(this.m_flags&b2Body.e_sleepFlag)==b2Body.e_sleepFlag},AllowSleeping:function(a){a?this.m_flags|=b2Body.e_allowSleepFlag:(this.m_flags&=~b2Body.e_allowSleepFlag,this.WakeUp())},WakeUp:function(){this.m_flags&=~b2Body.e_sleepFlag;this.m_sleepTime=0},GetShapeList:function(){return this.m_shapeList},GetContactList:function(){return this.m_contactList},
GetJointList:function(){return this.m_jointList},GetNext:function(){return this.m_next},GetUserData:function(){return this.m_userData},initialize:function(a,c){this.sMat0=new b2Mat22;this.m_position=new b2Vec2;this.m_R=new b2Mat22(0);this.m_position0=new b2Vec2;var b=0,e,f;this.m_flags=0;this.m_position.SetV(a.position);this.m_rotation=a.rotation;this.m_R.Set(this.m_rotation);this.m_position0.SetV(this.m_position);this.m_rotation0=this.m_rotation;this.m_world=c;this.m_linearDamping=b2Math.b2Clamp(1-
a.linearDamping,0,1);this.m_angularDamping=b2Math.b2Clamp(1-a.angularDamping,0,1);this.m_force=new b2Vec2(0,0);this.m_mass=this.m_torque=0;for(var g=Array(b2Settings.b2_maxShapesPerBody),b=0;b<b2Settings.b2_maxShapesPerBody;b++)g[b]=new b2MassData;this.m_shapeCount=0;this.m_center=new b2Vec2(0,0);for(b=0;b<b2Settings.b2_maxShapesPerBody;++b){e=a.shapes[b];if(e==null)break;f=g[b];e.ComputeMass(f);this.m_mass+=f.mass;this.m_center.x+=f.mass*(e.localPosition.x+f.center.x);this.m_center.y+=f.mass*(e.localPosition.y+
f.center.y);++this.m_shapeCount}this.m_mass>0?(this.m_center.Multiply(1/this.m_mass),this.m_position.Add(b2Math.b2MulMV(this.m_R,this.m_center))):this.m_flags|=b2Body.e_staticFlag;for(b=this.m_I=0;b<this.m_shapeCount;++b)e=a.shapes[b],f=g[b],this.m_I+=f.I,e=b2Math.SubtractVV(b2Math.AddVV(e.localPosition,f.center),this.m_center),this.m_I+=f.mass*b2Math.b2Dot(e,e);this.m_invMass=this.m_mass>0?1/this.m_mass:0;this.m_invI=this.m_I>0&&a.preventRotation==!1?1/this.m_I:this.m_I=0;this.m_linearVelocity=b2Math.AddVV(a.linearVelocity,
b2Math.b2CrossFV(a.angularVelocity,this.m_center));this.m_angularVelocity=a.angularVelocity;this.m_shapeList=this.m_next=this.m_prev=this.m_contactList=this.m_jointList=null;for(b=0;b<this.m_shapeCount;++b)e=a.shapes[b],f=b2Shape.Create(e,this,this.m_center),f.m_next=this.m_shapeList,this.m_shapeList=f;this.m_sleepTime=0;a.allowSleep&&(this.m_flags|=b2Body.e_allowSleepFlag);a.isSleeping&&(this.m_flags|=b2Body.e_sleepFlag);if(this.m_flags&b2Body.e_sleepFlag||this.m_invMass==0)this.m_linearVelocity.Set(0,
0),this.m_angularVelocity=0;this.m_userData=a.userData},Destroy:function(){for(var a=this.m_shapeList;a;){var c=a,a=a.m_next;b2Shape.Destroy(c)}},sMat0:new b2Mat22,SynchronizeShapes:function(){this.sMat0.Set(this.m_rotation0);for(var a=this.m_shapeList;a!=null;a=a.m_next)a.Synchronize(this.m_position0,this.sMat0,this.m_position,this.m_R)},QuickSyncShapes:function(){for(var a=this.m_shapeList;a!=null;a=a.m_next)a.QuickSync(this.m_position,this.m_R)},IsConnected:function(a){for(var c=this.m_jointList;c!=
null;c=c.next)if(c.other==a)return c.joint.m_collideConnected==!1;return!1},Freeze:function(){this.m_flags|=b2Body.e_frozenFlag;this.m_linearVelocity.SetZero();this.m_angularVelocity=0;for(var a=this.m_shapeList;a!=null;a=a.m_next)a.DestroyProxy()},m_flags:0,m_position:new b2Vec2,m_rotation:null,m_R:new b2Mat22(0),m_position0:new b2Vec2,m_rotation0:null,m_linearVelocity:null,m_angularVelocity:null,m_force:null,m_torque:null,m_center:null,m_world:null,m_prev:null,m_next:null,m_shapeList:null,m_shapeCount:0,
m_jointList:null,m_contactList:null,m_mass:null,m_invMass:null,m_I:null,m_invI:null,m_linearDamping:null,m_angularDamping:null,m_sleepTime:null,m_userData:null};b2Body.e_staticFlag=1;b2Body.e_frozenFlag=2;b2Body.e_islandFlag=4;b2Body.e_sleepFlag=8;b2Body.e_allowSleepFlag=16;b2Body.e_destroyFlag=32;var b2BodyDef=Class.create();
b2BodyDef.prototype={initialize:function(){this.shapes=[];this.userData=null;for(var a=0;a<b2Settings.b2_maxShapesPerBody;a++)this.shapes[a]=null;this.position=new b2Vec2(0,0);this.rotation=0;this.linearVelocity=new b2Vec2(0,0);this.angularDamping=this.linearDamping=this.angularVelocity=0;this.allowSleep=!0;this.preventRotation=this.isSleeping=!1},userData:null,shapes:[],position:null,rotation:null,linearVelocity:null,angularVelocity:null,linearDamping:null,angularDamping:null,allowSleep:null,isSleeping:null,
preventRotation:null,AddShape:function(a){for(var c=0;c<b2Settings.b2_maxShapesPerBody;++c)if(this.shapes[c]==null){this.shapes[c]=a;break}}};var b2CollisionFilter=Class.create();b2CollisionFilter.prototype={ShouldCollide:function(a,c){if(a.m_groupIndex==c.m_groupIndex&&a.m_groupIndex!=0)return a.m_groupIndex>0;return(a.m_maskBits&c.m_categoryBits)!=0&&(a.m_categoryBits&c.m_maskBits)!=0},initialize:function(){}};b2CollisionFilter.b2_defaultFilter=new b2CollisionFilter;var b2Island=Class.create();
b2Island.prototype={initialize:function(a,c,b,e){var f=0;this.m_bodyCapacity=a;this.m_contactCapacity=c;this.m_jointCapacity=b;this.m_jointCount=this.m_contactCount=this.m_bodyCount=0;this.m_bodies=Array(a);for(f=0;f<a;f++)this.m_bodies[f]=null;this.m_contacts=Array(c);for(f=0;f<c;f++)this.m_contacts[f]=null;this.m_joints=Array(b);for(f=0;f<b;f++)this.m_joints[f]=null;this.m_allocator=e},Clear:function(){this.m_jointCount=this.m_contactCount=this.m_bodyCount=0},Solve:function(a,c){for(var b=0,e,b=
0;b<this.m_bodyCount;++b)if(e=this.m_bodies[b],e.m_invMass!=0)e.m_linearVelocity.Add(b2Math.MulFV(a.dt,b2Math.AddVV(c,b2Math.MulFV(e.m_invMass,e.m_force)))),e.m_angularVelocity+=a.dt*e.m_invI*e.m_torque,e.m_linearVelocity.Multiply(e.m_linearDamping),e.m_angularVelocity*=e.m_angularDamping,e.m_position0.SetV(e.m_position),e.m_rotation0=e.m_rotation;var f=new b2ContactSolver(this.m_contacts,this.m_contactCount,this.m_allocator);f.PreSolve();for(b=0;b<this.m_jointCount;++b)this.m_joints[b].PrepareVelocitySolver();
for(b=0;b<a.iterations;++b){f.SolveVelocityConstraints();for(e=0;e<this.m_jointCount;++e)this.m_joints[e].SolveVelocityConstraints(a)}for(b=0;b<this.m_bodyCount;++b)e=this.m_bodies[b],e.m_invMass!=0&&(e.m_position.x+=a.dt*e.m_linearVelocity.x,e.m_position.y+=a.dt*e.m_linearVelocity.y,e.m_rotation+=a.dt*e.m_angularVelocity,e.m_R.Set(e.m_rotation));for(b=0;b<this.m_jointCount;++b)this.m_joints[b].PreparePositionSolver();if(b2World.s_enablePositionCorrection)for(b2Island.m_positionIterationCount=0;b2Island.m_positionIterationCount<
a.iterations;++b2Island.m_positionIterationCount){e=f.SolvePositionConstraints(b2Settings.b2_contactBaumgarte);for(var g=!0,b=0;b<this.m_jointCount;++b)var h=this.m_joints[b].SolvePositionConstraints(),g=g&&h;if(e&&g)break}f.PostSolve();for(b=0;b<this.m_bodyCount;++b)if(e=this.m_bodies[b],e.m_invMass!=0)e.m_R.Set(e.m_rotation),e.SynchronizeShapes(),e.m_force.Set(0,0),e.m_torque=0},UpdateSleep:function(a){for(var c=0,b,e=Number.MAX_VALUE,f=b2Settings.b2_linearSleepTolerance*b2Settings.b2_linearSleepTolerance,
g=b2Settings.b2_angularSleepTolerance*b2Settings.b2_angularSleepTolerance,c=0;c<this.m_bodyCount;++c)if(b=this.m_bodies[c],b.m_invMass!=0){if((b.m_flags&b2Body.e_allowSleepFlag)==0)e=b.m_sleepTime=0;(b.m_flags&b2Body.e_allowSleepFlag)==0||b.m_angularVelocity*b.m_angularVelocity>g||b2Math.b2Dot(b.m_linearVelocity,b.m_linearVelocity)>f?e=b.m_sleepTime=0:(b.m_sleepTime+=a,e=b2Math.b2Min(e,b.m_sleepTime))}if(e>=b2Settings.b2_timeToSleep)for(c=0;c<this.m_bodyCount;++c)b=this.m_bodies[c],b.m_flags|=b2Body.e_sleepFlag},
AddBody:function(a){this.m_bodies[this.m_bodyCount++]=a},AddContact:function(a){this.m_contacts[this.m_contactCount++]=a},AddJoint:function(a){this.m_joints[this.m_jointCount++]=a},m_allocator:null,m_bodies:null,m_contacts:null,m_joints:null,m_bodyCount:0,m_jointCount:0,m_contactCount:0,m_bodyCapacity:0,m_contactCapacity:0,m_jointCapacity:0,m_positionError:null};b2Island.m_positionIterationCount=0;var b2TimeStep=Class.create();b2TimeStep.prototype={dt:null,inv_dt:null,iterations:0,initialize:function(){}};
var b2ContactNode=Class.create();b2ContactNode.prototype={other:null,contact:null,prev:null,next:null,initialize:function(){}};var b2Contact=Class.create();
b2Contact.prototype={GetManifolds:function(){return null},GetManifoldCount:function(){return this.m_manifoldCount},GetNext:function(){return this.m_next},GetShape1:function(){return this.m_shape1},GetShape2:function(){return this.m_shape2},initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),
this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=null,this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null)},Evaluate:function(){},m_flags:0,m_prev:null,m_next:null,m_node1:new b2ContactNode,m_node2:new b2ContactNode,m_shape1:null,m_shape2:null,m_manifoldCount:0,m_friction:null,m_restitution:null};
b2Contact.e_islandFlag=1;b2Contact.e_destroyFlag=2;b2Contact.AddType=function(a,c,b,e){b2Contact.s_registers[b][e].createFcn=a;b2Contact.s_registers[b][e].destroyFcn=c;b2Contact.s_registers[b][e].primary=!0;if(b!=e)b2Contact.s_registers[e][b].createFcn=a,b2Contact.s_registers[e][b].destroyFcn=c,b2Contact.s_registers[e][b].primary=!1};
b2Contact.InitializeRegisters=function(){b2Contact.s_registers=Array(b2Shape.e_shapeTypeCount);for(var a=0;a<b2Shape.e_shapeTypeCount;a++){b2Contact.s_registers[a]=Array(b2Shape.e_shapeTypeCount);for(var c=0;c<b2Shape.e_shapeTypeCount;c++)b2Contact.s_registers[a][c]=new b2ContactRegister}b2Contact.AddType(b2CircleContact.Create,b2CircleContact.Destroy,b2Shape.e_circleShape,b2Shape.e_circleShape);b2Contact.AddType(b2PolyAndCircleContact.Create,b2PolyAndCircleContact.Destroy,b2Shape.e_polyShape,b2Shape.e_circleShape);
b2Contact.AddType(b2PolyContact.Create,b2PolyContact.Destroy,b2Shape.e_polyShape,b2Shape.e_polyShape)};b2Contact.Create=function(a,c,b){if(b2Contact.s_initialized==!1)b2Contact.InitializeRegisters(),b2Contact.s_initialized=!0;var e=a.m_type,f=c.m_type,g=b2Contact.s_registers[e][f].createFcn;if(g)if(b2Contact.s_registers[e][f].primary)return g(a,c,b);else{a=g(c,a,b);for(c=0;c<a.GetManifoldCount();++c)b=a.GetManifolds()[c],b.normal=b.normal.Negative();return a}else return null};
b2Contact.Destroy=function(a,c){a.GetManifoldCount()>0&&(a.m_shape1.m_body.WakeUp(),a.m_shape2.m_body.WakeUp());var b=b2Contact.s_registers[a.m_shape1.m_type][a.m_shape2.m_type].destroyFcn;b(a,c)};b2Contact.s_registers=null;b2Contact.s_initialized=!1;var b2ContactConstraint=Class.create();
b2ContactConstraint.prototype={initialize:function(){this.normal=new b2Vec2;this.points=Array(b2Settings.b2_maxManifoldPoints);for(var a=0;a<b2Settings.b2_maxManifoldPoints;a++)this.points[a]=new b2ContactConstraintPoint},points:null,normal:new b2Vec2,manifold:null,body1:null,body2:null,friction:null,restitution:null,pointCount:0};var b2ContactConstraintPoint=Class.create();
b2ContactConstraintPoint.prototype={localAnchor1:new b2Vec2,localAnchor2:new b2Vec2,normalImpulse:null,tangentImpulse:null,positionImpulse:null,normalMass:null,tangentMass:null,separation:null,velocityBias:null,initialize:function(){this.localAnchor1=new b2Vec2;this.localAnchor2=new b2Vec2}};var b2ContactRegister=Class.create();b2ContactRegister.prototype={createFcn:null,destroyFcn:null,primary:null,initialize:function(){}};var b2ContactSolver=Class.create();
b2ContactSolver.prototype={initialize:function(a,c,b){this.m_constraints=[];this.m_allocator=b;for(var b=0,e,f,b=this.m_constraintCount=0;b<c;++b)this.m_constraintCount+=a[b].GetManifoldCount();for(b=0;b<this.m_constraintCount;b++)this.m_constraints[b]=new b2ContactConstraint;for(var g=0,b=0;b<c;++b)for(var h=a[b],i=h.m_shape1.m_body,k=h.m_shape2.m_body,j=h.GetManifoldCount(),l=h.GetManifolds(),m=h.m_friction,h=h.m_restitution,n=i.m_linearVelocity.x,o=i.m_linearVelocity.y,p=k.m_linearVelocity.x,q=
k.m_linearVelocity.y,s=i.m_angularVelocity,r=k.m_angularVelocity,u=0;u<j;++u){var z=l[u],x=z.normal.x,B=z.normal.y,y=this.m_constraints[g];y.body1=i;y.body2=k;y.manifold=z;y.normal.x=x;y.normal.y=B;y.pointCount=z.pointCount;y.friction=m;y.restitution=h;for(var C=0;C<y.pointCount;++C){var t=z.points[C],v=y.points[C];v.normalImpulse=t.normalImpulse;v.tangentImpulse=t.tangentImpulse;v.separation=t.separation;var A=t.position.x-i.m_position.x,D=t.position.y-i.m_position.y,F=t.position.x-k.m_position.x,
t=t.position.y-k.m_position.y;e=v.localAnchor1;f=i.m_R;e.x=A*f.col1.x+D*f.col1.y;e.y=A*f.col2.x+D*f.col2.y;e=v.localAnchor2;f=k.m_R;e.x=F*f.col1.x+t*f.col1.y;e.y=F*f.col2.x+t*f.col2.y;e=A*A+D*D;f=F*F+t*t;var E=A*x+D*B,G=F*x+t*B,H=i.m_invMass+k.m_invMass;H+=i.m_invI*(e-E*E)+k.m_invI*(f-G*G);v.normalMass=1/H;G=B;H=-x;E=A*G+D*H;G=F*G+t*H;H=i.m_invMass+k.m_invMass;H+=i.m_invI*(e-E*E)+k.m_invI*(f-G*G);v.tangentMass=1/H;v.velocityBias=0;if(v.separation>0)v.velocityBias=-60*v.separation;A=y.normal.x*(p+
-r*t-n- -s*D)+y.normal.y*(q+r*F-o-s*A);A<-b2Settings.b2_velocityThreshold&&(v.velocityBias+=-y.restitution*A)}++g}},PreSolve:function(){for(var a,c,b=0;b<this.m_constraintCount;++b){var e=this.m_constraints[b],f=e.body1,g=e.body2,h=f.m_invMass,i=f.m_invI,k=g.m_invMass,j=g.m_invI,l=e.normal.x,m=e.normal.y,n=m,o=-l,p=0,q=0;if(b2World.s_enableWarmStarting){q=e.pointCount;for(p=0;p<q;++p){var s=e.points[p],r=s.normalImpulse*l+s.tangentImpulse*n,u=s.normalImpulse*m+s.tangentImpulse*o;c=f.m_R;a=s.localAnchor1;
var z=c.col1.x*a.x+c.col2.x*a.y,x=c.col1.y*a.x+c.col2.y*a.y;c=g.m_R;a=s.localAnchor2;var B=c.col1.x*a.x+c.col2.x*a.y;a=c.col1.y*a.x+c.col2.y*a.y;f.m_angularVelocity-=i*(z*u-x*r);f.m_linearVelocity.x-=h*r;f.m_linearVelocity.y-=h*u;g.m_angularVelocity+=j*(B*u-a*r);g.m_linearVelocity.x+=k*r;g.m_linearVelocity.y+=k*u;s.positionImpulse=0}}else{q=e.pointCount;for(p=0;p<q;++p)f=e.points[p],f.normalImpulse=0,f.tangentImpulse=0,f.positionImpulse=0}}},SolveVelocityConstraints:function(){for(var a=0,c,b,e,f,
g,h,i,k,j=0;j<this.m_constraintCount;++j){for(var l=this.m_constraints[j],m=l.body1,n=l.body2,o=m.m_angularVelocity,p=m.m_linearVelocity,q=n.m_angularVelocity,s=n.m_linearVelocity,r=m.m_invMass,u=m.m_invI,z=n.m_invMass,x=n.m_invI,B=l.normal.x,y=l.normal.y,C=y,t=-B,v=l.pointCount,a=0;a<v;++a)c=l.points[a],g=m.m_R,h=c.localAnchor1,b=g.col1.x*h.x+g.col2.x*h.y,e=g.col1.y*h.x+g.col2.y*h.y,g=n.m_R,h=c.localAnchor2,f=g.col1.x*h.x+g.col2.x*h.y,g=g.col1.y*h.x+g.col2.y*h.y,h=s.x+-q*g-p.x- -o*e,i=s.y+q*f-p.y-
o*b,h=-c.normalMass*(h*B+i*y-c.velocityBias),i=b2Math.b2Max(c.normalImpulse+h,0),h=i-c.normalImpulse,k=h*B,h*=y,p.x-=r*k,p.y-=r*h,o-=u*(b*h-e*k),s.x+=z*k,s.y+=z*h,q+=x*(f*h-g*k),c.normalImpulse=i,h=s.x+-q*g-p.x- -o*e,i=s.y+q*f-p.y-o*b,h=c.tangentMass*-(h*C+i*t),i=l.friction*c.normalImpulse,i=b2Math.b2Clamp(c.tangentImpulse+h,-i,i),h=i-c.tangentImpulse,k=h*C,h*=t,p.x-=r*k,p.y-=r*h,o-=u*(b*h-e*k),s.x+=z*k,s.y+=z*h,q+=x*(f*h-g*k),c.tangentImpulse=i;m.m_angularVelocity=o;n.m_angularVelocity=q}},SolvePositionConstraints:function(a){for(var c=
0,b,e,f=0;f<this.m_constraintCount;++f){for(var g=this.m_constraints[f],h=g.body1,i=g.body2,k=h.m_position,j=h.m_rotation,l=i.m_position,m=i.m_rotation,n=h.m_invMass,o=h.m_invI,p=i.m_invMass,q=i.m_invI,s=g.normal.x,r=g.normal.y,u=g.pointCount,z=0;z<u;++z){var x=g.points[z];b=h.m_R;e=x.localAnchor1;var B=b.col1.x*e.x+b.col2.x*e.y,y=b.col1.y*e.x+b.col2.y*e.y;b=i.m_R;e=x.localAnchor2;var C=b.col1.x*e.x+b.col2.x*e.y;b=b.col1.y*e.x+b.col2.y*e.y;e=(l.x+C-(k.x+B))*s+(l.y+b-(k.y+y))*r+x.separation;c=b2Math.b2Min(c,
e);e=a*b2Math.b2Clamp(e+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0);e*=-x.normalMass;var t=x.positionImpulse;x.positionImpulse=b2Math.b2Max(t+e,0);e=x.positionImpulse-t;x=e*s;e*=r;k.x-=n*x;k.y-=n*e;j-=o*(B*e-y*x);h.m_R.Set(j);l.x+=p*x;l.y+=p*e;m+=q*(C*e-b*x);i.m_R.Set(m)}h.m_rotation=j;i.m_rotation=m}return c>=-b2Settings.b2_linearSlop},PostSolve:function(){for(var a=0;a<this.m_constraintCount;++a)for(var c=this.m_constraints[a],b=c.manifold,e=0;e<c.pointCount;++e){var f=b.points[e],
g=c.points[e];f.normalImpulse=g.normalImpulse;f.tangentImpulse=g.tangentImpulse}},m_allocator:null,m_constraints:[],m_constraintCount:0};var b2CircleContact=Class.create();Object.extend(b2CircleContact.prototype,b2Contact.prototype);
Object.extend(b2CircleContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=
null,this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null,this.m_manifold=[new b2Manifold],this.m_manifold[0].pointCount=0,this.m_manifold[0].points[0].normalImpulse=0,this.m_manifold[0].points[0].tangentImpulse=0)},Evaluate:function(){b2Collision.b2CollideCircle(this.m_manifold[0],this.m_shape1,this.m_shape2,!1);this.m_manifoldCount=this.m_manifold[0].pointCount>0?1:0},GetManifolds:function(){return this.m_manifold},m_manifold:[new b2Manifold]});
b2CircleContact.Create=function(a,c){return new b2CircleContact(a,c)};b2CircleContact.Destroy=function(){};var b2Conservative=Class.create();b2Conservative.prototype={initialize:function(){}};b2Conservative.R1=new b2Mat22;b2Conservative.R2=new b2Mat22;b2Conservative.x1=new b2Vec2;b2Conservative.x2=new b2Vec2;
b2Conservative.Conservative=function(a,c){var b=a.GetBody(),e=c.GetBody(),f=b.m_position.x-b.m_position0.x,g=b.m_position.y-b.m_position0.y,h=b.m_rotation-b.m_rotation0,i=e.m_position.x-e.m_position0.x,k=e.m_position.y-e.m_position0.y,j=e.m_rotation-e.m_rotation0,l=a.GetMaxRadius(),m=c.GetMaxRadius(),n=b.m_position0.x,o=b.m_position0.y,p=b.m_rotation0,q=e.m_position0.x,s=e.m_position0.y,r=e.m_rotation0,u=n,z=o,x=p,B=q,y=s,C=r;b2Conservative.R1.Set(x);b2Conservative.R2.Set(C);a.QuickSync(p1,b2Conservative.R1);
c.QuickSync(p2,b2Conservative.R2);var t=0,v,A;v=0;for(var D=!0,F=0;F<10;++F){var E=b2Distance.Distance(b2Conservative.x1,b2Conservative.x2,a,c);if(E<b2Settings.b2_linearSlop){D=F==0?!1:!0;break}if(F==0){v=b2Conservative.x2.x-b2Conservative.x1.x;A=b2Conservative.x2.y-b2Conservative.x1.y;v=v*(f-i)+A*(g-k)+Math.abs(h)*l+Math.abs(j)*m;if(Math.abs(v)<Number.MIN_VALUE){D=!1;break}v=1/v}E=t+E*v;if(E<0||1<E){D=!1;break}if(E<(1+100*Number.MIN_VALUE)*t){D=!0;break}t=E;u=n+t*v1.x;z=o+t*v1.y;x=p+t*h;B=q+t*v2.x;
y=s+t*v2.y;C=r+t*j;b2Conservative.R1.Set(x);b2Conservative.R2.Set(C);a.QuickSync(p1,b2Conservative.R1);c.QuickSync(p2,b2Conservative.R2)}if(D)return v=b2Conservative.x2.x-b2Conservative.x1.x,A=b2Conservative.x2.y-b2Conservative.x1.y,f=Math.sqrt(v*v+A*A),f>FLT_EPSILON&&(d*=b2_linearSlop/f),b.IsStatic()?(b.m_position.x=u,b.m_position.y=z):(b.m_position.x=u-v,b.m_position.y=z-A),b.m_rotation=x,b.m_R.Set(x),b.QuickSyncShapes(),e.IsStatic()?(e.m_position.x=B,e.m_position.y=y):(e.m_position.x=B+v,e.m_position.y=
y+A),e.m_position.x=B+v,e.m_position.y=y+A,e.m_rotation=C,e.m_R.Set(C),e.QuickSyncShapes(),!0;a.QuickSync(b.m_position,b.m_R);c.QuickSync(e.m_position,e.m_R);return!1};var b2NullContact=Class.create();Object.extend(b2NullContact.prototype,b2Contact.prototype);
Object.extend(b2NullContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=null,
this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null)},Evaluate:function(){},GetManifolds:function(){return null}});var b2PolyAndCircleContact=Class.create();Object.extend(b2PolyAndCircleContact.prototype,b2Contact.prototype);
Object.extend(b2PolyAndCircleContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=
null,this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null,this.m_manifold=[new b2Manifold],b2Settings.b2Assert(this.m_shape1.m_type==b2Shape.e_polyShape),b2Settings.b2Assert(this.m_shape2.m_type==b2Shape.e_circleShape),this.m_manifold[0].pointCount=0,this.m_manifold[0].points[0].normalImpulse=0,this.m_manifold[0].points[0].tangentImpulse=0)},Evaluate:function(){b2Collision.b2CollidePolyAndCircle(this.m_manifold[0],this.m_shape1,this.m_shape2,
!1);this.m_manifoldCount=this.m_manifold[0].pointCount>0?1:0},GetManifolds:function(){return this.m_manifold},m_manifold:[new b2Manifold]});b2PolyAndCircleContact.Create=function(a,c){return new b2PolyAndCircleContact(a,c)};b2PolyAndCircleContact.Destroy=function(){};var b2PolyContact=Class.create();Object.extend(b2PolyContact.prototype,b2Contact.prototype);
Object.extend(b2PolyContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=null,
this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null,this.m0=new b2Manifold,this.m_manifold=[new b2Manifold],this.m_manifold[0].pointCount=0)},m0:new b2Manifold,Evaluate:function(){for(var a=this.m_manifold[0],c=this.m0.points,b=0;b<a.pointCount;b++){var e=c[b],f=a.points[b];e.normalImpulse=f.normalImpulse;e.tangentImpulse=f.tangentImpulse;e.id=f.id.Copy()}this.m0.pointCount=a.pointCount;b2Collision.b2CollidePoly(a,this.m_shape1,this.m_shape2,
!1);if(a.pointCount>0){c=[!1,!1];for(b=0;b<a.pointCount;++b){e=a.points[b];e.normalImpulse=0;e.tangentImpulse=0;for(var f=e.id.key,g=0;g<this.m0.pointCount;++g)if(c[g]!=!0){var h=this.m0.points[g];if(h.id.key==f){c[g]=!0;e.normalImpulse=h.normalImpulse;e.tangentImpulse=h.tangentImpulse;break}}}this.m_manifoldCount=1}else this.m_manifoldCount=0},GetManifolds:function(){return this.m_manifold},m_manifold:[new b2Manifold]});b2PolyContact.Create=function(a,c){return new b2PolyContact(a,c)};
b2PolyContact.Destroy=function(){};var b2ContactManager=Class.create();Object.extend(b2ContactManager.prototype,b2PairCallback.prototype);
Object.extend(b2ContactManager.prototype,{initialize:function(){this.m_nullContact=new b2NullContact;this.m_world=null;this.m_destroyImmediate=!1},PairAdded:function(a,c){var b=a,e=c,f=b.m_body,g=e.m_body;if(f.IsStatic()&&g.IsStatic())return this.m_nullContact;if(b.m_body==e.m_body)return this.m_nullContact;if(g.IsConnected(f))return this.m_nullContact;if(this.m_world.m_filter!=null&&this.m_world.m_filter.ShouldCollide(b,e)==!1)return this.m_nullContact;g.m_invMass==0&&(f=b,b=e,e=f);b=b2Contact.Create(b,
e,this.m_world.m_blockAllocator);if(b==null)return this.m_nullContact;else{b.m_prev=null;b.m_next=this.m_world.m_contactList;if(this.m_world.m_contactList!=null)this.m_world.m_contactList.m_prev=b;this.m_world.m_contactList=b;this.m_world.m_contactCount++}return b},PairRemoved:function(a,c,b){b!=null&&b!=this.m_nullContact&&(this.m_destroyImmediate==!0?this.DestroyContact(b):b.m_flags|=b2Contact.e_destroyFlag)},DestroyContact:function(a){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_world.m_contactList)this.m_world.m_contactList=a.m_next;if(a.GetManifoldCount()>0){var c=a.m_shape1.m_body,b=a.m_shape2.m_body,e=a.m_node1,f=a.m_node2;c.WakeUp();b.WakeUp();if(e.prev)e.prev.next=e.next;if(e.next)e.next.prev=e.prev;if(e==c.m_contactList)c.m_contactList=e.next;e.prev=null;e.next=null;if(f.prev)f.prev.next=f.next;if(f.next)f.next.prev=f.prev;if(f==b.m_contactList)b.m_contactList=f.next;f.prev=null;f.next=null}b2Contact.Destroy(a,this.m_world.m_blockAllocator);--this.m_world.m_contactCount},
CleanContactList:function(){for(var a=this.m_world.m_contactList;a!=null;){var c=a,a=a.m_next;c.m_flags&b2Contact.e_destroyFlag&&this.DestroyContact(c)}},Collide:function(){for(var a,c,b,e,f=this.m_world.m_contactList;f!=null;f=f.m_next)if(!f.m_shape1.m_body.IsSleeping()||!f.m_shape2.m_body.IsSleeping())if(a=f.GetManifoldCount(),f.Evaluate(),c=f.GetManifoldCount(),a==0&&c>0){a=f.m_shape1.m_body;c=f.m_shape2.m_body;b=f.m_node1;e=f.m_node2;b.contact=f;b.other=c;b.prev=null;b.next=a.m_contactList;if(b.next!=
null)b.next.prev=f.m_node1;a.m_contactList=f.m_node1;e.contact=f;e.other=a;e.prev=null;e.next=c.m_contactList;if(e.next!=null)e.next.prev=e;c.m_contactList=e}else if(a>0&&c==0){a=f.m_shape1.m_body;c=f.m_shape2.m_body;b=f.m_node1;e=f.m_node2;if(b.prev)b.prev.next=b.next;if(b.next)b.next.prev=b.prev;if(b==a.m_contactList)a.m_contactList=b.next;b.prev=null;b.next=null;if(e.prev)e.prev.next=e.next;if(e.next)e.next.prev=e.prev;if(e==c.m_contactList)c.m_contactList=e.next;e.prev=null;e.next=null}},m_world:null,
m_nullContact:new b2NullContact,m_destroyImmediate:null});var b2World=Class.create();
b2World.prototype={initialize:function(a,c,b){this.step=new b2TimeStep;this.m_contactManager=new b2ContactManager;this.m_listener=null;this.m_filter=b2CollisionFilter.b2_defaultFilter;this.m_jointList=this.m_contactList=this.m_bodyList=null;this.m_jointCount=this.m_contactCount=this.m_bodyCount=0;this.m_bodyDestroyList=null;this.m_allowSleep=b;this.m_gravity=c;this.m_contactManager.m_world=this;this.m_broadPhase=new b2BroadPhase(a,this.m_contactManager);this.m_groundBody=this.CreateBody(new b2BodyDef)},
SetListener:function(a){this.m_listener=a},SetFilter:function(a){this.m_filter=a},CreateBody:function(a){a=new b2Body(a,this);a.m_prev=null;if(a.m_next=this.m_bodyList)this.m_bodyList.m_prev=a;this.m_bodyList=a;++this.m_bodyCount;return a},DestroyBody:function(a){if(!(a.m_flags&b2Body.e_destroyFlag)){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_bodyList)this.m_bodyList=a.m_next;a.m_flags|=b2Body.e_destroyFlag;--this.m_bodyCount;a.m_prev=null;a.m_next=this.m_bodyDestroyList;
this.m_bodyDestroyList=a}},CleanBodyList:function(){this.m_contactManager.m_destroyImmediate=!0;for(var a=this.m_bodyDestroyList;a;){for(var c=a,a=a.m_next,b=c.m_jointList;b;){var e=b,b=b.next;this.m_listener&&this.m_listener.NotifyJointDestroyed(e.joint);this.DestroyJoint(e.joint)}c.Destroy()}this.m_bodyDestroyList=null;this.m_contactManager.m_destroyImmediate=!1},CreateJoint:function(a){var c=b2Joint.Create(a,this.m_blockAllocator);c.m_prev=null;if(c.m_next=this.m_jointList)this.m_jointList.m_prev=
c;this.m_jointList=c;++this.m_jointCount;c.m_node1.joint=c;c.m_node1.other=c.m_body2;c.m_node1.prev=null;if(c.m_node1.next=c.m_body1.m_jointList)c.m_body1.m_jointList.prev=c.m_node1;c.m_body1.m_jointList=c.m_node1;c.m_node2.joint=c;c.m_node2.other=c.m_body1;c.m_node2.prev=null;if(c.m_node2.next=c.m_body2.m_jointList)c.m_body2.m_jointList.prev=c.m_node2;c.m_body2.m_jointList=c.m_node2;if(a.collideConnected==!1)for(a=(a.body1.m_shapeCount<a.body2.m_shapeCount?a.body1:a.body2).m_shapeList;a;a=a.m_next)a.ResetProxy(this.m_broadPhase);
return c},DestroyJoint:function(a){var c=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;var b=a.m_body1,e=a.m_body2;b.WakeUp();e.WakeUp();if(a.m_node1.prev)a.m_node1.prev.next=a.m_node1.next;if(a.m_node1.next)a.m_node1.next.prev=a.m_node1.prev;if(a.m_node1==b.m_jointList)b.m_jointList=a.m_node1.next;a.m_node1.prev=null;a.m_node1.next=null;if(a.m_node2.prev)a.m_node2.prev.next=a.m_node2.next;if(a.m_node2.next)a.m_node2.next.prev=
a.m_node2.prev;if(a.m_node2==e.m_jointList)e.m_jointList=a.m_node2.next;a.m_node2.prev=null;a.m_node2.next=null;b2Joint.Destroy(a,this.m_blockAllocator);--this.m_jointCount;if(c==!1)for(a=(b.m_shapeCount<e.m_shapeCount?b:e).m_shapeList;a;a=a.m_next)a.ResetProxy(this.m_broadPhase)},GetGroundBody:function(){return this.m_groundBody},step:new b2TimeStep,Step:function(a,c){var b,e;this.step.dt=a;this.step.iterations=c;this.step.inv_dt=a>0?1/a:0;this.m_positionIterationCount=0;this.m_contactManager.CleanContactList();
this.CleanBodyList();this.m_contactManager.Collide();var f=new b2Island(this.m_bodyCount,this.m_contactCount,this.m_jointCount,this.m_stackAllocator);for(b=this.m_bodyList;b!=null;b=b.m_next)b.m_flags&=~b2Body.e_islandFlag;for(var g=this.m_contactList;g!=null;g=g.m_next)g.m_flags&=~b2Contact.e_islandFlag;for(g=this.m_jointList;g!=null;g=g.m_next)g.m_islandFlag=!1;for(var g=Array(this.m_bodyCount),h=0;h<this.m_bodyCount;h++)g[h]=null;for(h=this.m_bodyList;h!=null;h=h.m_next)if(!(h.m_flags&(b2Body.e_staticFlag|
b2Body.e_islandFlag|b2Body.e_sleepFlag|b2Body.e_frozenFlag))){f.Clear();var i=0;g[i++]=h;for(h.m_flags|=b2Body.e_islandFlag;i>0;)if(b=g[--i],f.AddBody(b),b.m_flags&=~b2Body.e_sleepFlag,!(b.m_flags&b2Body.e_staticFlag)){for(var k=b.m_contactList;k!=null;k=k.next)if(!(k.contact.m_flags&b2Contact.e_islandFlag))f.AddContact(k.contact),k.contact.m_flags|=b2Contact.e_islandFlag,e=k.other,e.m_flags&b2Body.e_islandFlag||(g[i++]=e,e.m_flags|=b2Body.e_islandFlag);for(b=b.m_jointList;b!=null;b=b.next)if(b.joint.m_islandFlag!=
!0)f.AddJoint(b.joint),b.joint.m_islandFlag=!0,e=b.other,e.m_flags&b2Body.e_islandFlag||(g[i++]=e,e.m_flags|=b2Body.e_islandFlag)}f.Solve(this.step,this.m_gravity);this.m_positionIterationCount=b2Math.b2Max(this.m_positionIterationCount,b2Island.m_positionIterationCount);this.m_allowSleep&&f.UpdateSleep(a);for(e=0;e<f.m_bodyCount;++e)b=f.m_bodies[e],b.m_flags&b2Body.e_staticFlag&&(b.m_flags&=~b2Body.e_islandFlag),b.IsFrozen()&&this.m_listener&&this.m_listener.NotifyBoundaryViolated(b)==b2WorldListener.b2_destroyBody&&
(this.DestroyBody(b),f.m_bodies[e]=null)}this.m_broadPhase.Commit()},Query:function(a,c,b){for(var e=[],a=this.m_broadPhase.QueryAABB(a,e,b),b=0;b<a;++b)c[b]=e[b];return a},GetBodyList:function(){return this.m_bodyList},GetJointList:function(){return this.m_jointList},GetContactList:function(){return this.m_contactList},m_blockAllocator:null,m_stackAllocator:null,m_broadPhase:null,m_contactManager:new b2ContactManager,m_bodyList:null,m_contactList:null,m_jointList:null,m_bodyCount:0,m_contactCount:0,
m_jointCount:0,m_bodyDestroyList:null,m_gravity:null,m_allowSleep:null,m_groundBody:null,m_listener:null,m_filter:null,m_positionIterationCount:0};b2World.s_enablePositionCorrection=1;b2World.s_enableWarmStarting=1;var b2WorldListener=Class.create();b2WorldListener.prototype={NotifyJointDestroyed:function(){},NotifyBoundaryViolated:function(){return b2WorldListener.b2_freezeBody},initialize:function(){}};b2WorldListener.b2_freezeBody=0;b2WorldListener.b2_destroyBody=1;var b2JointNode=Class.create();
b2JointNode.prototype={other:null,joint:null,prev:null,next:null,initialize:function(){}};var b2Joint=Class.create();
b2Joint.prototype={GetType:function(){return this.m_type},GetAnchor1:function(){return null},GetAnchor2:function(){return null},GetReactionForce:function(){return null},GetReactionTorque:function(){return 0},GetBody1:function(){return this.m_body1},GetBody2:function(){return this.m_body2},GetNext:function(){return this.m_next},GetUserData:function(){return this.m_userData},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;
this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData},PrepareVelocitySolver:function(){},SolveVelocityConstraints:function(){},PreparePositionSolver:function(){},SolvePositionConstraints:function(){return!1},m_type:0,m_prev:null,m_next:null,m_node1:new b2JointNode,m_node2:new b2JointNode,m_body1:null,m_body2:null,m_islandFlag:null,m_collideConnected:null,m_userData:null};
b2Joint.Create=function(a){var c=null;switch(a.type){case b2Joint.e_distanceJoint:c=new b2DistanceJoint(a);break;case b2Joint.e_mouseJoint:c=new b2MouseJoint(a);break;case b2Joint.e_prismaticJoint:c=new b2PrismaticJoint(a);break;case b2Joint.e_revoluteJoint:c=new b2RevoluteJoint(a);break;case b2Joint.e_pulleyJoint:c=new b2PulleyJoint(a);break;case b2Joint.e_gearJoint:c=new b2GearJoint(a)}return c};b2Joint.Destroy=function(){};b2Joint.e_unknownJoint=0;b2Joint.e_revoluteJoint=1;
b2Joint.e_prismaticJoint=2;b2Joint.e_distanceJoint=3;b2Joint.e_pulleyJoint=4;b2Joint.e_mouseJoint=5;b2Joint.e_gearJoint=6;b2Joint.e_inactiveLimit=0;b2Joint.e_atLowerLimit=1;b2Joint.e_atUpperLimit=2;b2Joint.e_equalLimits=3;var b2JointDef=Class.create();b2JointDef.prototype={initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1},type:0,userData:null,body1:null,body2:null,collideConnected:null};var b2DistanceJoint=Class.create();
Object.extend(b2DistanceJoint.prototype,b2Joint.prototype);
Object.extend(b2DistanceJoint.prototype,{initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.m_localAnchor1=new b2Vec2;this.m_localAnchor2=new b2Vec2;this.m_u=new b2Vec2;var c,b,e;c=this.m_body1.m_R;b=a.anchorPoint1.x-this.m_body1.m_position.x;e=a.anchorPoint1.y-this.m_body1.m_position.y;
this.m_localAnchor1.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor1.y=b*c.col2.x+e*c.col2.y;c=this.m_body2.m_R;b=a.anchorPoint2.x-this.m_body2.m_position.x;e=a.anchorPoint2.y-this.m_body2.m_position.y;this.m_localAnchor2.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor2.y=b*c.col2.x+e*c.col2.y;b=a.anchorPoint2.x-a.anchorPoint1.x;e=a.anchorPoint2.y-a.anchorPoint1.y;this.m_length=Math.sqrt(b*b+e*e);this.m_impulse=0},PrepareVelocitySolver:function(){var a;a=this.m_body1.m_R;var c=a.col1.x*this.m_localAnchor1.x+
a.col2.x*this.m_localAnchor1.y,b=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=this.m_body2.m_R;var e=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+a.col2.y*this.m_localAnchor2.y;this.m_u.x=this.m_body2.m_position.x+e-this.m_body1.m_position.x-c;this.m_u.y=this.m_body2.m_position.y+a-this.m_body1.m_position.y-b;var f=Math.sqrt(this.m_u.x*this.m_u.x+this.m_u.y*this.m_u.y);f>b2Settings.b2_linearSlop?this.m_u.Multiply(1/f):this.m_u.SetZero();
var f=c*this.m_u.y-b*this.m_u.x,g=e*this.m_u.y-a*this.m_u.x;this.m_mass=this.m_body1.m_invMass+this.m_body1.m_invI*f*f+this.m_body2.m_invMass+this.m_body2.m_invI*g*g;this.m_mass=1/this.m_mass;b2World.s_enableWarmStarting?(f=this.m_impulse*this.m_u.x,g=this.m_impulse*this.m_u.y,this.m_body1.m_linearVelocity.x-=this.m_body1.m_invMass*f,this.m_body1.m_linearVelocity.y-=this.m_body1.m_invMass*g,this.m_body1.m_angularVelocity-=this.m_body1.m_invI*(c*g-b*f),this.m_body2.m_linearVelocity.x+=this.m_body2.m_invMass*
f,this.m_body2.m_linearVelocity.y+=this.m_body2.m_invMass*g,this.m_body2.m_angularVelocity+=this.m_body2.m_invI*(e*g-a*f)):this.m_impulse=0},SolveVelocityConstraints:function(){var a;a=this.m_body1.m_R;var c=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y,b=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=this.m_body2.m_R;var e=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+a.col2.y*this.m_localAnchor2.y;var f=-this.m_mass*
(this.m_u.x*(this.m_body2.m_linearVelocity.x+-this.m_body2.m_angularVelocity*a-(this.m_body1.m_linearVelocity.x+-this.m_body1.m_angularVelocity*b))+this.m_u.y*(this.m_body2.m_linearVelocity.y+this.m_body2.m_angularVelocity*e-(this.m_body1.m_linearVelocity.y+this.m_body1.m_angularVelocity*c)));this.m_impulse+=f;var g=f*this.m_u.x;f*=this.m_u.y;this.m_body1.m_linearVelocity.x-=this.m_body1.m_invMass*g;this.m_body1.m_linearVelocity.y-=this.m_body1.m_invMass*f;this.m_body1.m_angularVelocity-=this.m_body1.m_invI*
(c*f-b*g);this.m_body2.m_linearVelocity.x+=this.m_body2.m_invMass*g;this.m_body2.m_linearVelocity.y+=this.m_body2.m_invMass*f;this.m_body2.m_angularVelocity+=this.m_body2.m_invI*(e*f-a*g)},SolvePositionConstraints:function(){var a;a=this.m_body1.m_R;var c=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y,b=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=this.m_body2.m_R;var e=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+
a.col2.y*this.m_localAnchor2.y;var f=this.m_body2.m_position.x+e-this.m_body1.m_position.x-c,g=this.m_body2.m_position.y+a-this.m_body1.m_position.y-b,h=Math.sqrt(f*f+g*g);f/=h;g/=h;h-=this.m_length;var h=b2Math.b2Clamp(h,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection),i=-this.m_mass*h;this.m_u.Set(f,g);f=i*this.m_u.x;g=i*this.m_u.y;this.m_body1.m_position.x-=this.m_body1.m_invMass*f;this.m_body1.m_position.y-=this.m_body1.m_invMass*g;this.m_body1.m_rotation-=this.m_body1.m_invI*
(c*g-b*f);this.m_body2.m_position.x+=this.m_body2.m_invMass*f;this.m_body2.m_position.y+=this.m_body2.m_invMass*g;this.m_body2.m_rotation+=this.m_body2.m_invI*(e*g-a*f);this.m_body1.m_R.Set(this.m_body1.m_rotation);this.m_body2.m_R.Set(this.m_body2.m_rotation);return b2Math.b2Abs(h)<b2Settings.b2_linearSlop},GetAnchor1:function(){return b2Math.AddVV(this.m_body1.m_position,b2Math.b2MulMV(this.m_body1.m_R,this.m_localAnchor1))},GetAnchor2:function(){return b2Math.AddVV(this.m_body2.m_position,b2Math.b2MulMV(this.m_body2.m_R,
this.m_localAnchor2))},GetReactionForce:function(a){var c=new b2Vec2;c.SetV(this.m_u);c.Multiply(this.m_impulse*a);return c},GetReactionTorque:function(){return 0},m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_u:new b2Vec2,m_impulse:null,m_mass:null,m_length:null});var b2DistanceJointDef=Class.create();Object.extend(b2DistanceJointDef.prototype,b2JointDef.prototype);
Object.extend(b2DistanceJointDef.prototype,{initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1;this.anchorPoint1=new b2Vec2;this.anchorPoint2=new b2Vec2;this.type=b2Joint.e_distanceJoint},anchorPoint1:new b2Vec2,anchorPoint2:new b2Vec2});var b2Jacobian=Class.create();
b2Jacobian.prototype={linear1:new b2Vec2,angular1:null,linear2:new b2Vec2,angular2:null,SetZero:function(){this.linear1.SetZero();this.angular1=0;this.linear2.SetZero();this.angular2=0},Set:function(a,c,b,e){this.linear1.SetV(a);this.angular1=c;this.linear2.SetV(b);this.angular2=e},Compute:function(a,c,b,e){return this.linear1.x*a.x+this.linear1.y*a.y+this.angular1*c+(this.linear2.x*b.x+this.linear2.y*b.y)+this.angular2*e},initialize:function(){this.linear1=new b2Vec2;this.linear2=new b2Vec2}};
var b2GearJoint=Class.create();Object.extend(b2GearJoint.prototype,b2Joint.prototype);
Object.extend(b2GearJoint.prototype,{GetAnchor1:function(){var a=this.m_body1.m_R;return new b2Vec2(this.m_body1.m_position.x+(a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y),this.m_body1.m_position.y+(a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y))},GetAnchor2:function(){var a=this.m_body2.m_R;return new b2Vec2(this.m_body2.m_position.x+(a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y),this.m_body2.m_position.y+(a.col1.y*this.m_localAnchor2.x+a.col2.y*
this.m_localAnchor2.y))},GetReactionForce:function(){return new b2Vec2},GetReactionTorque:function(){return 0},GetRatio:function(){return this.m_ratio},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.m_groundAnchor1=new b2Vec2;this.m_groundAnchor2=new b2Vec2;this.m_localAnchor1=new b2Vec2;
this.m_localAnchor2=new b2Vec2;this.m_J=new b2Jacobian;this.m_prismatic2=this.m_revolute2=this.m_prismatic1=this.m_revolute1=null;var c,b;this.m_ground1=a.joint1.m_body1;this.m_body1=a.joint1.m_body2;a.joint1.m_type==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),c=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),c=this.m_prismatic1.GetJointTranslation());this.m_ground2=a.joint2.m_body1;this.m_body2=a.joint2.m_body2;a.joint2.m_type==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),b=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),
b=this.m_prismatic2.GetJointTranslation());this.m_ratio=a.ratio;this.m_constant=c+this.m_ratio*b;this.m_impulse=0},PrepareVelocitySolver:function(){var a=this.m_ground1,c=this.m_ground2,b=this.m_body1,e=this.m_body2,f,g,h,i=0;this.m_J.SetZero();this.m_revolute1?(this.m_J.angular1=-1,i+=b.m_invI):(h=a.m_R,f=this.m_prismatic1.m_localXAxis1,a=h.col1.x*f.x+h.col2.x*f.y,f=h.col1.y*f.x+h.col2.y*f.y,h=b.m_R,g=h.col1.x*this.m_localAnchor1.x+h.col2.x*this.m_localAnchor1.y,h=h.col1.y*this.m_localAnchor1.x+
h.col2.y*this.m_localAnchor1.y,g=g*f-h*a,this.m_J.linear1.Set(-a,-f),this.m_J.angular1=-g,i+=b.m_invMass+b.m_invI*g*g);this.m_revolute2?(this.m_J.angular2=-this.m_ratio,i+=this.m_ratio*this.m_ratio*e.m_invI):(h=c.m_R,f=this.m_prismatic2.m_localXAxis1,a=h.col1.x*f.x+h.col2.x*f.y,f=h.col1.y*f.x+h.col2.y*f.y,h=e.m_R,g=h.col1.x*this.m_localAnchor2.x+h.col2.x*this.m_localAnchor2.y,h=h.col1.y*this.m_localAnchor2.x+h.col2.y*this.m_localAnchor2.y,g=g*f-h*a,this.m_J.linear2.Set(-this.m_ratio*a,-this.m_ratio*
f),this.m_J.angular2=-this.m_ratio*g,i+=this.m_ratio*this.m_ratio*(e.m_invMass+e.m_invI*g*g));this.m_mass=1/i;b.m_linearVelocity.x+=b.m_invMass*this.m_impulse*this.m_J.linear1.x;b.m_linearVelocity.y+=b.m_invMass*this.m_impulse*this.m_J.linear1.y;b.m_angularVelocity+=b.m_invI*this.m_impulse*this.m_J.angular1;e.m_linearVelocity.x+=e.m_invMass*this.m_impulse*this.m_J.linear2.x;e.m_linearVelocity.y+=e.m_invMass*this.m_impulse*this.m_J.linear2.y;e.m_angularVelocity+=e.m_invI*this.m_impulse*this.m_J.angular2},
SolveVelocityConstraints:function(){var a=this.m_body1,c=this.m_body2,b=-this.m_mass*this.m_J.Compute(a.m_linearVelocity,a.m_angularVelocity,c.m_linearVelocity,c.m_angularVelocity);this.m_impulse+=b;a.m_linearVelocity.x+=a.m_invMass*b*this.m_J.linear1.x;a.m_linearVelocity.y+=a.m_invMass*b*this.m_J.linear1.y;a.m_angularVelocity+=a.m_invI*b*this.m_J.angular1;c.m_linearVelocity.x+=c.m_invMass*b*this.m_J.linear2.x;c.m_linearVelocity.y+=c.m_invMass*b*this.m_J.linear2.y;c.m_angularVelocity+=c.m_invI*b*
this.m_J.angular2},SolvePositionConstraints:function(){var a=this.m_body1,c=this.m_body2,b,e;b=this.m_revolute1?this.m_revolute1.GetJointAngle():this.m_prismatic1.GetJointTranslation();e=this.m_revolute2?this.m_revolute2.GetJointAngle():this.m_prismatic2.GetJointTranslation();b=-this.m_mass*(this.m_constant-(b+this.m_ratio*e));a.m_position.x+=a.m_invMass*b*this.m_J.linear1.x;a.m_position.y+=a.m_invMass*b*this.m_J.linear1.y;a.m_rotation+=a.m_invI*b*this.m_J.angular1;c.m_position.x+=c.m_invMass*b*this.m_J.linear2.x;
c.m_position.y+=c.m_invMass*b*this.m_J.linear2.y;c.m_rotation+=c.m_invI*b*this.m_J.angular2;a.m_R.Set(a.m_rotation);c.m_R.Set(c.m_rotation);return 0<b2Settings.b2_linearSlop},m_ground1:null,m_ground2:null,m_revolute1:null,m_prismatic1:null,m_revolute2:null,m_prismatic2:null,m_groundAnchor1:new b2Vec2,m_groundAnchor2:new b2Vec2,m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_J:new b2Jacobian,m_constant:null,m_ratio:null,m_mass:null,m_impulse:null});var b2GearJointDef=Class.create();
Object.extend(b2GearJointDef.prototype,b2JointDef.prototype);Object.extend(b2GearJointDef.prototype,{initialize:function(){this.type=b2Joint.e_gearJoint;this.joint2=this.joint1=null;this.ratio=1},joint1:null,joint2:null,ratio:null});var b2MouseJoint=Class.create();Object.extend(b2MouseJoint.prototype,b2Joint.prototype);
Object.extend(b2MouseJoint.prototype,{GetAnchor1:function(){return this.m_target},GetAnchor2:function(){var a=b2Math.b2MulMV(this.m_body2.m_R,this.m_localAnchor);a.Add(this.m_body2.m_position);return a},GetReactionForce:function(a){var c=new b2Vec2;c.SetV(this.m_impulse);c.Multiply(a);return c},GetReactionTorque:function(){return 0},SetTarget:function(a){this.m_body2.WakeUp();this.m_target=a},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=
this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.K=new b2Mat22;this.K1=new b2Mat22;this.K2=new b2Mat22;this.m_localAnchor=new b2Vec2;this.m_target=new b2Vec2;this.m_impulse=new b2Vec2;this.m_ptpMass=new b2Mat22;this.m_C=new b2Vec2;this.m_target.SetV(a.target);var c=this.m_target.x-this.m_body2.m_position.x,b=this.m_target.y-this.m_body2.m_position.y;this.m_localAnchor.x=c*this.m_body2.m_R.col1.x+
b*this.m_body2.m_R.col1.y;this.m_localAnchor.y=c*this.m_body2.m_R.col2.x+b*this.m_body2.m_R.col2.y;this.m_maxForce=a.maxForce;this.m_impulse.SetZero();var b=this.m_body2.m_mass,e=2*b2Settings.b2_pi*a.frequencyHz,c=2*b*a.dampingRatio*e,b=b*e*e;this.m_gamma=1/(c+a.timeStep*b);this.m_beta=a.timeStep*b/(c+a.timeStep*b)},K:new b2Mat22,K1:new b2Mat22,K2:new b2Mat22,PrepareVelocitySolver:function(){var a=this.m_body2,c;c=a.m_R;var b=c.col1.x*this.m_localAnchor.x+c.col2.x*this.m_localAnchor.y;c=c.col1.y*
this.m_localAnchor.x+c.col2.y*this.m_localAnchor.y;var e=a.m_invMass,f=a.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*c*c;this.K2.col2.x=-f*b*c;this.K2.col1.y=-f*b*c;this.K2.col2.y=f*b*b;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.Invert(this.m_ptpMass);this.m_C.x=a.m_position.x+b-this.m_target.x;this.m_C.y=a.m_position.y+c-this.m_target.y;a.m_angularVelocity*=0.98;var g=this.m_impulse.x,h=
this.m_impulse.y;a.m_linearVelocity.x+=e*g;a.m_linearVelocity.y+=e*h;a.m_angularVelocity+=f*(b*h-c*g)},SolveVelocityConstraints:function(a){var c=this.m_body2,b;b=c.m_R;var e=b.col1.x*this.m_localAnchor.x+b.col2.x*this.m_localAnchor.y,f=b.col1.y*this.m_localAnchor.x+b.col2.y*this.m_localAnchor.y,g=c.m_linearVelocity.x+-c.m_angularVelocity*f,h=c.m_linearVelocity.y+c.m_angularVelocity*e;b=this.m_ptpMass;var g=g+this.m_beta*a.inv_dt*this.m_C.x+this.m_gamma*this.m_impulse.x,i=h+this.m_beta*a.inv_dt*this.m_C.y+
this.m_gamma*this.m_impulse.y,h=-(b.col1.x*g+b.col2.x*i),i=-(b.col1.y*g+b.col2.y*i);b=this.m_impulse.x;g=this.m_impulse.y;this.m_impulse.x+=h;this.m_impulse.y+=i;h=this.m_impulse.Length();h>a.dt*this.m_maxForce&&this.m_impulse.Multiply(a.dt*this.m_maxForce/h);h=this.m_impulse.x-b;i=this.m_impulse.y-g;c.m_linearVelocity.x+=c.m_invMass*h;c.m_linearVelocity.y+=c.m_invMass*i;c.m_angularVelocity+=c.m_invI*(e*i-f*h)},SolvePositionConstraints:function(){return!0},m_localAnchor:new b2Vec2,m_target:new b2Vec2,
m_impulse:new b2Vec2,m_ptpMass:new b2Mat22,m_C:new b2Vec2,m_maxForce:null,m_beta:null,m_gamma:null});var b2MouseJointDef=Class.create();Object.extend(b2MouseJointDef.prototype,b2JointDef.prototype);
Object.extend(b2MouseJointDef.prototype,{initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1;this.target=new b2Vec2;this.type=b2Joint.e_mouseJoint;this.maxForce=0;this.frequencyHz=5;this.dampingRatio=0.7;this.timeStep=1/60},target:new b2Vec2,maxForce:null,frequencyHz:null,dampingRatio:null,timeStep:null});var b2PrismaticJoint=Class.create();Object.extend(b2PrismaticJoint.prototype,b2Joint.prototype);
Object.extend(b2PrismaticJoint.prototype,{GetAnchor1:function(){var a=this.m_body1,c=new b2Vec2;c.SetV(this.m_localAnchor1);c.MulM(a.m_R);c.Add(a.m_position);return c},GetAnchor2:function(){var a=this.m_body2,c=new b2Vec2;c.SetV(this.m_localAnchor2);c.MulM(a.m_R);c.Add(a.m_position);return c},GetJointTranslation:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;
b=c.m_R;e=c.m_position.x+(b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y)-(a.m_position.x+e);c=c.m_position.y+(b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y)-(a.m_position.y+f);b=a.m_R;return(b.col1.x*this.m_localXAxis1.x+b.col2.x*this.m_localXAxis1.y)*e+(b.col1.y*this.m_localXAxis1.x+b.col2.y*this.m_localXAxis1.y)*c},GetJointSpeed:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+
b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y,h=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y,i=c.m_position.x+g-(a.m_position.x+e),k=c.m_position.y+h-(a.m_position.y+f);b=a.m_R;var j=b.col1.x*this.m_localXAxis1.x+b.col2.x*this.m_localXAxis1.y;b=b.col1.y*this.m_localXAxis1.x+b.col2.y*this.m_localXAxis1.y;var l=a.m_linearVelocity,m=c.m_linearVelocity,a=a.m_angularVelocity,c=c.m_angularVelocity;return i*-a*b+k*a*j+(j*(m.x+
-c*h-l.x- -a*f)+b*(m.y+c*g-l.y-a*e))},GetMotorForce:function(a){return a*this.m_motorImpulse},SetMotorSpeed:function(a){this.m_motorSpeed=a},SetMotorForce:function(a){this.m_maxMotorForce=a},GetReactionForce:function(a){a*=this.m_limitImpulse;var c;c=this.m_body1.m_R;return new b2Vec2(a*(c.col1.x*this.m_localXAxis1.x+c.col2.x*this.m_localXAxis1.y)+a*(c.col1.x*this.m_localYAxis1.x+c.col2.x*this.m_localYAxis1.y),a*(c.col1.y*this.m_localXAxis1.x+c.col2.y*this.m_localXAxis1.y)+a*(c.col1.y*this.m_localYAxis1.x+
c.col2.y*this.m_localYAxis1.y))},GetReactionTorque:function(a){return a*this.m_angularImpulse},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.m_localAnchor1=new b2Vec2;this.m_localAnchor2=new b2Vec2;this.m_localXAxis1=new b2Vec2;this.m_localYAxis1=new b2Vec2;this.m_linearJacobian=
new b2Jacobian;this.m_motorJacobian=new b2Jacobian;var c,b,e;c=this.m_body1.m_R;b=a.anchorPoint.x-this.m_body1.m_position.x;e=a.anchorPoint.y-this.m_body1.m_position.y;this.m_localAnchor1.Set(b*c.col1.x+e*c.col1.y,b*c.col2.x+e*c.col2.y);c=this.m_body2.m_R;b=a.anchorPoint.x-this.m_body2.m_position.x;e=a.anchorPoint.y-this.m_body2.m_position.y;this.m_localAnchor2.Set(b*c.col1.x+e*c.col1.y,b*c.col2.x+e*c.col2.y);c=this.m_body1.m_R;b=a.axis.x;e=a.axis.y;this.m_localXAxis1.Set(b*c.col1.x+e*c.col1.y,b*
c.col2.x+e*c.col2.y);this.m_localYAxis1.x=-this.m_localXAxis1.y;this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_initialAngle=this.m_body2.m_rotation-this.m_body1.m_rotation;this.m_linearJacobian.SetZero();this.m_angularImpulse=this.m_angularMass=this.m_linearImpulse=this.m_linearMass=0;this.m_motorJacobian.SetZero();this.m_limitPositionImpulse=this.m_limitImpulse=this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=
a.motorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor},PrepareVelocitySolver:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y,h=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y,i=a.m_invMass,k=c.m_invMass,j=a.m_invI,l=
c.m_invI;b=a.m_R;var m=b.col1.x*this.m_localYAxis1.x+b.col2.x*this.m_localYAxis1.y;b=b.col1.y*this.m_localYAxis1.x+b.col2.y*this.m_localYAxis1.y;var n=c.m_position.x+g-a.m_position.x,o=c.m_position.y+h-a.m_position.y;this.m_linearJacobian.linear1.x=-m;this.m_linearJacobian.linear1.y=-b;this.m_linearJacobian.linear2.x=m;this.m_linearJacobian.linear2.y=b;this.m_linearJacobian.angular1=-(n*b-o*m);this.m_linearJacobian.angular2=g*b-h*m;this.m_linearMass=i+j*this.m_linearJacobian.angular1*this.m_linearJacobian.angular1+
k+l*this.m_linearJacobian.angular2*this.m_linearJacobian.angular2;this.m_linearMass=1/this.m_linearMass;this.m_angularMass=1/(j+l);if(this.m_enableLimit||this.m_enableMotor)if(b=a.m_R,m=b.col1.x*this.m_localXAxis1.x+b.col2.x*this.m_localXAxis1.y,b=b.col1.y*this.m_localXAxis1.x+b.col2.y*this.m_localXAxis1.y,this.m_motorJacobian.linear1.x=-m,this.m_motorJacobian.linear1.y=-b,this.m_motorJacobian.linear2.x=m,this.m_motorJacobian.linear2.y=b,this.m_motorJacobian.angular1=-(n*b-o*m),this.m_motorJacobian.angular2=
g*b-h*m,this.m_motorMass=i+j*this.m_motorJacobian.angular1*this.m_motorJacobian.angular1+k+l*this.m_motorJacobian.angular2*this.m_motorJacobian.angular2,this.m_motorMass=1/this.m_motorMass,this.m_enableLimit)if(e=m*(n-e)+b*(o-f),b2Math.b2Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*b2Settings.b2_linearSlop)this.m_limitState=b2Joint.e_equalLimits;else if(e<=this.m_lowerTranslation){if(this.m_limitState!=b2Joint.e_atLowerLimit)this.m_limitImpulse=0;this.m_limitState=b2Joint.e_atLowerLimit}else if(e>=
this.m_upperTranslation){if(this.m_limitState!=b2Joint.e_atUpperLimit)this.m_limitImpulse=0;this.m_limitState=b2Joint.e_atUpperLimit}else this.m_limitState=b2Joint.e_inactiveLimit,this.m_limitImpulse=0;if(this.m_enableMotor==!1)this.m_motorImpulse=0;if(this.m_enableLimit==!1)this.m_limitImpulse=0;b2World.s_enableWarmStarting?(e=this.m_linearImpulse*this.m_linearJacobian.linear1.y+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear1.y,f=this.m_linearImpulse*this.m_linearJacobian.linear2.x+
(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear2.x,g=this.m_linearImpulse*this.m_linearJacobian.linear2.y+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear2.y,h=this.m_linearImpulse*this.m_linearJacobian.angular1-this.m_angularImpulse+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.angular1,n=this.m_linearImpulse*this.m_linearJacobian.angular2+this.m_angularImpulse+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.angular2,a.m_linearVelocity.x+=
i*(this.m_linearImpulse*this.m_linearJacobian.linear1.x+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear1.x),a.m_linearVelocity.y+=i*e,a.m_angularVelocity+=j*h,c.m_linearVelocity.x+=k*f,c.m_linearVelocity.y+=k*g,c.m_angularVelocity+=l*n):this.m_motorImpulse=this.m_limitImpulse=this.m_angularImpulse=this.m_linearImpulse=0;this.m_limitPositionImpulse=0},SolveVelocityConstraints:function(a){var c=this.m_body1,b=this.m_body2,e=c.m_invMass,f=b.m_invMass,g=c.m_invI,h=b.m_invI,i=-this.m_linearMass*
this.m_linearJacobian.Compute(c.m_linearVelocity,c.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity);this.m_linearImpulse+=i;c.m_linearVelocity.x+=e*i*this.m_linearJacobian.linear1.x;c.m_linearVelocity.y+=e*i*this.m_linearJacobian.linear1.y;c.m_angularVelocity+=g*i*this.m_linearJacobian.angular1;b.m_linearVelocity.x+=f*i*this.m_linearJacobian.linear2.x;b.m_linearVelocity.y+=f*i*this.m_linearJacobian.linear2.y;b.m_angularVelocity+=h*i*this.m_linearJacobian.angular2;i=-this.m_angularMass*(b.m_angularVelocity-
c.m_angularVelocity);this.m_angularImpulse+=i;c.m_angularVelocity-=g*i;b.m_angularVelocity+=h*i;if(this.m_enableMotor&&this.m_limitState!=b2Joint.e_equalLimits){var i=-this.m_motorMass*(this.m_motorJacobian.Compute(c.m_linearVelocity,c.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity)-this.m_motorSpeed),k=this.m_motorImpulse;this.m_motorImpulse=b2Math.b2Clamp(this.m_motorImpulse+i,-a.dt*this.m_maxMotorForce,a.dt*this.m_maxMotorForce);i=this.m_motorImpulse-k;c.m_linearVelocity.x+=e*i*this.m_motorJacobian.linear1.x;
c.m_linearVelocity.y+=e*i*this.m_motorJacobian.linear1.y;c.m_angularVelocity+=g*i*this.m_motorJacobian.angular1;b.m_linearVelocity.x+=f*i*this.m_motorJacobian.linear2.x;b.m_linearVelocity.y+=f*i*this.m_motorJacobian.linear2.y;b.m_angularVelocity+=h*i*this.m_motorJacobian.angular2}if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){i=-this.m_motorMass*this.m_motorJacobian.Compute(c.m_linearVelocity,c.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity);if(this.m_limitState==b2Joint.e_equalLimits)this.m_limitImpulse+=
i;else if(this.m_limitState==b2Joint.e_atLowerLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Max(this.m_limitImpulse+i,0),i=this.m_limitImpulse-a;else if(this.m_limitState==b2Joint.e_atUpperLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Min(this.m_limitImpulse+i,0),i=this.m_limitImpulse-a;c.m_linearVelocity.x+=e*i*this.m_motorJacobian.linear1.x;c.m_linearVelocity.y+=e*i*this.m_motorJacobian.linear1.y;c.m_angularVelocity+=g*i*this.m_motorJacobian.angular1;b.m_linearVelocity.x+=
f*i*this.m_motorJacobian.linear2.x;b.m_linearVelocity.y+=f*i*this.m_motorJacobian.linear2.y;b.m_angularVelocity+=h*i*this.m_motorJacobian.angular2}},SolvePositionConstraints:function(){var a,c,b=this.m_body1,e=this.m_body2,f=b.m_invMass,g=e.m_invMass,h=b.m_invI,i=e.m_invI;a=b.m_R;var k=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y,j=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=e.m_R;var l=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+
a.col2.y*this.m_localAnchor2.y;var k=b.m_position.x+k,j=b.m_position.y+j,l=e.m_position.x+l,m=e.m_position.y+a;a=b.m_R;var n=(a.col1.x*this.m_localYAxis1.x+a.col2.x*this.m_localYAxis1.y)*(l-k)+(a.col1.y*this.m_localYAxis1.x+a.col2.y*this.m_localYAxis1.y)*(m-j),n=b2Math.b2Clamp(n,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection);c=-this.m_linearMass*n;b.m_position.x+=f*c*this.m_linearJacobian.linear1.x;b.m_position.y+=f*c*this.m_linearJacobian.linear1.y;b.m_rotation+=h*c*this.m_linearJacobian.angular1;
e.m_position.x+=g*c*this.m_linearJacobian.linear2.x;e.m_position.y+=g*c*this.m_linearJacobian.linear2.y;e.m_rotation+=i*c*this.m_linearJacobian.angular2;n=b2Math.b2Abs(n);c=e.m_rotation-b.m_rotation-this.m_initialAngle;c=b2Math.b2Clamp(c,-b2Settings.b2_maxAngularCorrection,b2Settings.b2_maxAngularCorrection);var o=-this.m_angularMass*c;b.m_rotation-=b.m_invI*o;b.m_R.Set(b.m_rotation);e.m_rotation+=e.m_invI*o;e.m_R.Set(e.m_rotation);o=b2Math.b2Abs(c);if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){a=
b.m_R;k=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y;j=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=e.m_R;l=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+a.col2.y*this.m_localAnchor2.y;k=b.m_position.x+k;j=b.m_position.y+j;l=e.m_position.x+l;m=e.m_position.y+a;a=b.m_R;k=(a.col1.x*this.m_localXAxis1.x+a.col2.x*this.m_localXAxis1.y)*(l-k)+(a.col1.y*this.m_localXAxis1.x+a.col2.y*this.m_localXAxis1.y)*(m-j);a=0;if(this.m_limitState==
b2Joint.e_equalLimits)a=b2Math.b2Clamp(k,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection),a*=-this.m_motorMass,n=b2Math.b2Max(n,b2Math.b2Abs(c));else if(this.m_limitState==b2Joint.e_atLowerLimit)a=k-this.m_lowerTranslation,n=b2Math.b2Max(n,-a),a=b2Math.b2Clamp(a+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0),a*=-this.m_motorMass,c=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Max(this.m_limitPositionImpulse+a,0),a=this.m_limitPositionImpulse-
c;else if(this.m_limitState==b2Joint.e_atUpperLimit)a=k-this.m_upperTranslation,n=b2Math.b2Max(n,a),a=b2Math.b2Clamp(a-b2Settings.b2_linearSlop,0,b2Settings.b2_maxLinearCorrection),a*=-this.m_motorMass,c=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Min(this.m_limitPositionImpulse+a,0),a=this.m_limitPositionImpulse-c;b.m_position.x+=f*a*this.m_motorJacobian.linear1.x;b.m_position.y+=f*a*this.m_motorJacobian.linear1.y;b.m_rotation+=h*a*this.m_motorJacobian.angular1;b.m_R.Set(b.m_rotation);
e.m_position.x+=g*a*this.m_motorJacobian.linear2.x;e.m_position.y+=g*a*this.m_motorJacobian.linear2.y;e.m_rotation+=i*a*this.m_motorJacobian.angular2;e.m_R.Set(e.m_rotation)}return n<=b2Settings.b2_linearSlop&&o<=b2Settings.b2_angularSlop},m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_localXAxis1:new b2Vec2,m_localYAxis1:new b2Vec2,m_initialAngle:null,m_linearJacobian:new b2Jacobian,m_linearMass:null,m_linearImpulse:null,m_angularMass:null,m_angularImpulse:null,m_motorJacobian:new b2Jacobian,
m_motorMass:null,m_motorImpulse:null,m_limitImpulse:null,m_limitPositionImpulse:null,m_lowerTranslation:null,m_upperTranslation:null,m_maxMotorForce:null,m_motorSpeed:null,m_enableLimit:null,m_enableMotor:null,m_limitState:0});var b2PrismaticJointDef=Class.create();Object.extend(b2PrismaticJointDef.prototype,b2JointDef.prototype);
Object.extend(b2PrismaticJointDef.prototype,{initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1;this.type=b2Joint.e_prismaticJoint;this.anchorPoint=new b2Vec2(0,0);this.axis=new b2Vec2(0,0);this.motorSpeed=this.motorForce=this.upperTranslation=this.lowerTranslation=0;this.enableMotor=this.enableLimit=!1},anchorPoint:null,axis:null,lowerTranslation:null,upperTranslation:null,motorForce:null,motorSpeed:null,enableLimit:null,enableMotor:null});
var b2PulleyJoint=Class.create();Object.extend(b2PulleyJoint.prototype,b2Joint.prototype);
Object.extend(b2PulleyJoint.prototype,{GetAnchor1:function(){var a=this.m_body1.m_R;return new b2Vec2(this.m_body1.m_position.x+(a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y),this.m_body1.m_position.y+(a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y))},GetAnchor2:function(){var a=this.m_body2.m_R;return new b2Vec2(this.m_body2.m_position.x+(a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y),this.m_body2.m_position.y+(a.col1.y*this.m_localAnchor2.x+a.col2.y*
this.m_localAnchor2.y))},GetGroundPoint1:function(){return new b2Vec2(this.m_ground.m_position.x+this.m_groundAnchor1.x,this.m_ground.m_position.y+this.m_groundAnchor1.y)},GetGroundPoint2:function(){return new b2Vec2(this.m_ground.m_position.x+this.m_groundAnchor2.x,this.m_ground.m_position.y+this.m_groundAnchor2.y)},GetReactionForce:function(){return new b2Vec2},GetReactionTorque:function(){return 0},GetLength1:function(){var a;a=this.m_body1.m_R;var c=this.m_body1.m_position.x+(a.col1.x*this.m_localAnchor1.x+
a.col2.x*this.m_localAnchor1.y)-(this.m_ground.m_position.x+this.m_groundAnchor1.x);a=this.m_body1.m_position.y+(a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y)-(this.m_ground.m_position.y+this.m_groundAnchor1.y);return Math.sqrt(c*c+a*a)},GetLength2:function(){var a;a=this.m_body2.m_R;var c=this.m_body2.m_position.x+(a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y)-(this.m_ground.m_position.x+this.m_groundAnchor2.x);a=this.m_body2.m_position.y+(a.col1.y*this.m_localAnchor2.x+
a.col2.y*this.m_localAnchor2.y)-(this.m_ground.m_position.y+this.m_groundAnchor2.y);return Math.sqrt(c*c+a*a)},GetRatio:function(){return this.m_ratio},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.m_groundAnchor1=new b2Vec2;this.m_groundAnchor2=new b2Vec2;this.m_localAnchor1=new b2Vec2;
this.m_localAnchor2=new b2Vec2;this.m_u1=new b2Vec2;this.m_u2=new b2Vec2;var c,b,e;this.m_ground=this.m_body1.m_world.m_groundBody;this.m_groundAnchor1.x=a.groundPoint1.x-this.m_ground.m_position.x;this.m_groundAnchor1.y=a.groundPoint1.y-this.m_ground.m_position.y;this.m_groundAnchor2.x=a.groundPoint2.x-this.m_ground.m_position.x;this.m_groundAnchor2.y=a.groundPoint2.y-this.m_ground.m_position.y;c=this.m_body1.m_R;b=a.anchorPoint1.x-this.m_body1.m_position.x;e=a.anchorPoint1.y-this.m_body1.m_position.y;
this.m_localAnchor1.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor1.y=b*c.col2.x+e*c.col2.y;c=this.m_body2.m_R;b=a.anchorPoint2.x-this.m_body2.m_position.x;e=a.anchorPoint2.y-this.m_body2.m_position.y;this.m_localAnchor2.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor2.y=b*c.col2.x+e*c.col2.y;this.m_ratio=a.ratio;b=a.groundPoint1.x-a.anchorPoint1.x;e=a.groundPoint1.y-a.anchorPoint1.y;c=Math.sqrt(b*b+e*e);b=a.groundPoint2.x-a.anchorPoint2.x;e=a.groundPoint2.y-a.anchorPoint2.y;b=Math.sqrt(b*b+e*e);e=b2Math.b2Max(0.5*
b2PulleyJoint.b2_minPulleyLength,c);b=b2Math.b2Max(0.5*b2PulleyJoint.b2_minPulleyLength,b);this.m_constant=e+this.m_ratio*b;this.m_maxLength1=b2Math.b2Clamp(a.maxLength1,e,this.m_constant-this.m_ratio*b2PulleyJoint.b2_minPulleyLength);this.m_maxLength2=b2Math.b2Clamp(a.maxLength2,b,(this.m_constant-b2PulleyJoint.b2_minPulleyLength)/this.m_ratio);this.m_limitImpulse2=this.m_limitImpulse1=this.m_pulleyImpulse=0},PrepareVelocitySolver:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*
this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y;b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y;var h=c.m_position.x+g,i=c.m_position.y+b,k=this.m_ground.m_position.x+this.m_groundAnchor2.x,j=this.m_ground.m_position.y+this.m_groundAnchor2.y;this.m_u1.Set(a.m_position.x+e-(this.m_ground.m_position.x+this.m_groundAnchor1.x),a.m_position.y+
f-(this.m_ground.m_position.y+this.m_groundAnchor1.y));this.m_u2.Set(h-k,i-j);h=this.m_u1.Length();i=this.m_u2.Length();h>b2Settings.b2_linearSlop?this.m_u1.Multiply(1/h):this.m_u1.SetZero();i>b2Settings.b2_linearSlop?this.m_u2.Multiply(1/i):this.m_u2.SetZero();h<this.m_maxLength1?(this.m_limitState1=b2Joint.e_inactiveLimit,this.m_limitImpulse1=0):(this.m_limitState1=b2Joint.e_atUpperLimit,this.m_limitPositionImpulse1=0);i<this.m_maxLength2?(this.m_limitState2=b2Joint.e_inactiveLimit,this.m_limitImpulse2=
0):(this.m_limitState2=b2Joint.e_atUpperLimit,this.m_limitPositionImpulse2=0);h=e*this.m_u1.y-f*this.m_u1.x;i=g*this.m_u2.y-b*this.m_u2.x;this.m_limitMass1=a.m_invMass+a.m_invI*h*h;this.m_limitMass2=c.m_invMass+c.m_invI*i*i;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;h=(-this.m_pulleyImpulse-this.m_limitImpulse1)*this.m_u1.x;i=(-this.m_pulleyImpulse-
this.m_limitImpulse1)*this.m_u1.y;k=(-this.m_ratio*this.m_pulleyImpulse-this.m_limitImpulse2)*this.m_u2.x;j=(-this.m_ratio*this.m_pulleyImpulse-this.m_limitImpulse2)*this.m_u2.y;a.m_linearVelocity.x+=a.m_invMass*h;a.m_linearVelocity.y+=a.m_invMass*i;a.m_angularVelocity+=a.m_invI*(e*i-f*h);c.m_linearVelocity.x+=c.m_invMass*k;c.m_linearVelocity.y+=c.m_invMass*j;c.m_angularVelocity+=c.m_invI*(g*j-b*k)},SolveVelocityConstraints:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+
b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y;b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y;var h,i,k,j;h=a.m_linearVelocity.x+-a.m_angularVelocity*f;i=a.m_linearVelocity.y+a.m_angularVelocity*e;k=c.m_linearVelocity.x+-c.m_angularVelocity*b;j=c.m_linearVelocity.y+c.m_angularVelocity*g;h=-(this.m_u1.x*h+this.m_u1.y*i)-this.m_ratio*(this.m_u2.x*k+this.m_u2.y*
j);j=-this.m_pulleyMass*h;this.m_pulleyImpulse+=j;h=-j*this.m_u1.x;i=-j*this.m_u1.y;k=-this.m_ratio*j*this.m_u2.x;j=-this.m_ratio*j*this.m_u2.y;a.m_linearVelocity.x+=a.m_invMass*h;a.m_linearVelocity.y+=a.m_invMass*i;a.m_angularVelocity+=a.m_invI*(e*i-f*h);c.m_linearVelocity.x+=c.m_invMass*k;c.m_linearVelocity.y+=c.m_invMass*j;c.m_angularVelocity+=c.m_invI*(g*j-b*k);if(this.m_limitState1==b2Joint.e_atUpperLimit)h=a.m_linearVelocity.x+-a.m_angularVelocity*f,i=a.m_linearVelocity.y+a.m_angularVelocity*
e,h=-(this.m_u1.x*h+this.m_u1.y*i),j=-this.m_limitMass1*h,h=this.m_limitImpulse1,this.m_limitImpulse1=b2Math.b2Max(0,this.m_limitImpulse1+j),j=this.m_limitImpulse1-h,h=-j*this.m_u1.x,i=-j*this.m_u1.y,a.m_linearVelocity.x+=a.m_invMass*h,a.m_linearVelocity.y+=a.m_invMass*i,a.m_angularVelocity+=a.m_invI*(e*i-f*h);if(this.m_limitState2==b2Joint.e_atUpperLimit)k=c.m_linearVelocity.x+-c.m_angularVelocity*b,j=c.m_linearVelocity.y+c.m_angularVelocity*g,h=-(this.m_u2.x*k+this.m_u2.y*j),j=-this.m_limitMass2*
h,h=this.m_limitImpulse2,this.m_limitImpulse2=b2Math.b2Max(0,this.m_limitImpulse2+j),j=this.m_limitImpulse2-h,k=-j*this.m_u2.x,j=-j*this.m_u2.y,c.m_linearVelocity.x+=c.m_invMass*k,c.m_linearVelocity.y+=c.m_invMass*j,c.m_angularVelocity+=c.m_invI*(g*j-b*k)},SolvePositionConstraints:function(){var a=this.m_body1,c=this.m_body2,b,e=this.m_ground.m_position.x+this.m_groundAnchor1.x,f=this.m_ground.m_position.y+this.m_groundAnchor1.y,g=this.m_ground.m_position.x+this.m_groundAnchor2.x,h=this.m_ground.m_position.y+
this.m_groundAnchor2.y,i,k,j,l,m,n,o,p=0;b=a.m_R;i=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y;k=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;j=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y;b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y;l=a.m_position.x+i;m=a.m_position.y+k;n=c.m_position.x+j;o=c.m_position.y+b;this.m_u1.Set(l-e,m-f);this.m_u2.Set(n-g,o-h);l=this.m_u1.Length();m=this.m_u2.Length();l>b2Settings.b2_linearSlop?
this.m_u1.Multiply(1/l):this.m_u1.SetZero();m>b2Settings.b2_linearSlop?this.m_u2.Multiply(1/m):this.m_u2.SetZero();l=this.m_constant-l-this.m_ratio*m;p=b2Math.b2Max(p,Math.abs(l));l=b2Math.b2Clamp(l,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection);o=-this.m_pulleyMass*l;l=-o*this.m_u1.x;m=-o*this.m_u1.y;n=-this.m_ratio*o*this.m_u2.x;o=-this.m_ratio*o*this.m_u2.y;a.m_position.x+=a.m_invMass*l;a.m_position.y+=a.m_invMass*m;a.m_rotation+=a.m_invI*(i*m-k*l);c.m_position.x+=c.m_invMass*
n;c.m_position.y+=c.m_invMass*o;c.m_rotation+=c.m_invI*(j*o-b*n);a.m_R.Set(a.m_rotation);c.m_R.Set(c.m_rotation);if(this.m_limitState1==b2Joint.e_atUpperLimit)b=a.m_R,i=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,k=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y,l=a.m_position.x+i,m=a.m_position.y+k,this.m_u1.Set(l-e,m-f),l=this.m_u1.Length(),l>b2Settings.b2_linearSlop?(this.m_u1.x*=1/l,this.m_u1.y*=1/l):this.m_u1.SetZero(),l=this.m_maxLength1-l,p=b2Math.b2Max(p,-l),
l=b2Math.b2Clamp(l+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0),o=-this.m_limitMass1*l,e=this.m_limitPositionImpulse1,this.m_limitPositionImpulse1=b2Math.b2Max(0,this.m_limitPositionImpulse1+o),o=this.m_limitPositionImpulse1-e,l=-o*this.m_u1.x,m=-o*this.m_u1.y,a.m_position.x+=a.m_invMass*l,a.m_position.y+=a.m_invMass*m,a.m_rotation+=a.m_invI*(i*m-k*l),a.m_R.Set(a.m_rotation);if(this.m_limitState2==b2Joint.e_atUpperLimit)b=c.m_R,j=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y,
b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y,n=c.m_position.x+j,o=c.m_position.y+b,this.m_u2.Set(n-g,o-h),m=this.m_u2.Length(),m>b2Settings.b2_linearSlop?(this.m_u2.x*=1/m,this.m_u2.y*=1/m):this.m_u2.SetZero(),l=this.m_maxLength2-m,p=b2Math.b2Max(p,-l),l=b2Math.b2Clamp(l+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0),o=-this.m_limitMass2*l,e=this.m_limitPositionImpulse2,this.m_limitPositionImpulse2=b2Math.b2Max(0,this.m_limitPositionImpulse2+o),o=this.m_limitPositionImpulse2-
e,n=-o*this.m_u2.x,o=-o*this.m_u2.y,c.m_position.x+=c.m_invMass*n,c.m_position.y+=c.m_invMass*o,c.m_rotation+=c.m_invI*(j*o-b*n),c.m_R.Set(c.m_rotation);return p<b2Settings.b2_linearSlop},m_ground:null,m_groundAnchor1:new b2Vec2,m_groundAnchor2:new b2Vec2,m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_u1:new b2Vec2,m_u2:new b2Vec2,m_constant:null,m_ratio:null,m_maxLength1:null,m_maxLength2:null,m_pulleyMass:null,m_limitMass1:null,m_limitMass2:null,m_pulleyImpulse:null,m_limitImpulse1:null,
m_limitImpulse2:null,m_limitPositionImpulse1:null,m_limitPositionImpulse2:null,m_limitState1:0,m_limitState2:0});b2PulleyJoint.b2_minPulleyLength=b2Settings.b2_lengthUnitsPerMeter;var b2PulleyJointDef=Class.create();Object.extend(b2PulleyJointDef.prototype,b2JointDef.prototype);
Object.extend(b2PulleyJointDef.prototype,{initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1;this.groundPoint1=new b2Vec2;this.groundPoint2=new b2Vec2;this.anchorPoint1=new b2Vec2;this.anchorPoint2=new b2Vec2;this.type=b2Joint.e_pulleyJoint;this.groundPoint1.Set(-1,1);this.groundPoint2.Set(1,1);this.anchorPoint1.Set(-1,0);this.anchorPoint2.Set(1,0);this.maxLength1=0.5*b2PulleyJoint.b2_minPulleyLength;this.maxLength2=0.5*b2PulleyJoint.b2_minPulleyLength;
this.ratio=1;this.collideConnected=!0},groundPoint1:new b2Vec2,groundPoint2:new b2Vec2,anchorPoint1:new b2Vec2,anchorPoint2:new b2Vec2,maxLength1:null,maxLength2:null,ratio:null});var b2RevoluteJoint=Class.create();Object.extend(b2RevoluteJoint.prototype,b2Joint.prototype);
Object.extend(b2RevoluteJoint.prototype,{GetAnchor1:function(){var a=this.m_body1.m_R;return new b2Vec2(this.m_body1.m_position.x+(a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y),this.m_body1.m_position.y+(a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y))},GetAnchor2:function(){var a=this.m_body2.m_R;return new b2Vec2(this.m_body2.m_position.x+(a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y),this.m_body2.m_position.y+(a.col1.y*this.m_localAnchor2.x+a.col2.y*
this.m_localAnchor2.y))},GetJointAngle:function(){return this.m_body2.m_rotation-this.m_body1.m_rotation},GetJointSpeed:function(){return this.m_body2.m_angularVelocity-this.m_body1.m_angularVelocity},GetMotorTorque:function(a){return a*this.m_motorImpulse},SetMotorSpeed:function(a){this.m_motorSpeed=a},SetMotorTorque:function(a){this.m_maxMotorTorque=a},GetReactionForce:function(a){var c=this.m_ptpImpulse.Copy();c.Multiply(a);return c},GetReactionTorque:function(a){return a*this.m_limitImpulse},
initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.K=new b2Mat22;this.K1=new b2Mat22;this.K2=new b2Mat22;this.K3=new b2Mat22;this.m_localAnchor1=new b2Vec2;this.m_localAnchor2=new b2Vec2;this.m_ptpImpulse=new b2Vec2;this.m_ptpMass=new b2Mat22;var c,b,e;c=this.m_body1.m_R;b=a.anchorPoint.x-
this.m_body1.m_position.x;e=a.anchorPoint.y-this.m_body1.m_position.y;this.m_localAnchor1.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor1.y=b*c.col2.x+e*c.col2.y;c=this.m_body2.m_R;b=a.anchorPoint.x-this.m_body2.m_position.x;e=a.anchorPoint.y-this.m_body2.m_position.y;this.m_localAnchor2.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor2.y=b*c.col2.x+e*c.col2.y;this.m_intialAngle=this.m_body2.m_rotation-this.m_body1.m_rotation;this.m_ptpImpulse.Set(0,0);this.m_limitPositionImpulse=this.m_limitImpulse=this.m_motorImpulse=
0;this.m_lowerAngle=a.lowerAngle;this.m_upperAngle=a.upperAngle;this.m_maxMotorTorque=a.motorTorque;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor},K:new b2Mat22,K1:new b2Mat22,K2:new b2Mat22,K3:new b2Mat22,PrepareVelocitySolver:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+
b.col2.x*this.m_localAnchor2.y;b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y;var h=a.m_invMass,i=c.m_invMass,k=a.m_invI,j=c.m_invI;this.K1.col1.x=h+i;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=h+i;this.K2.col1.x=k*f*f;this.K2.col2.x=-k*e*f;this.K2.col1.y=-k*e*f;this.K2.col2.y=k*e*e;this.K3.col1.x=j*b*b;this.K3.col2.x=-j*g*b;this.K3.col1.y=-j*g*b;this.K3.col2.y=j*g*g;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Invert(this.m_ptpMass);this.m_motorMass=
1/(k+j);if(this.m_enableMotor==!1)this.m_motorImpulse=0;if(this.m_enableLimit){var l=c.m_rotation-a.m_rotation-this.m_intialAngle;if(b2Math.b2Abs(this.m_upperAngle-this.m_lowerAngle)<2*b2Settings.b2_angularSlop)this.m_limitState=b2Joint.e_equalLimits;else if(l<=this.m_lowerAngle){if(this.m_limitState!=b2Joint.e_atLowerLimit)this.m_limitImpulse=0;this.m_limitState=b2Joint.e_atLowerLimit}else if(l>=this.m_upperAngle){if(this.m_limitState!=b2Joint.e_atUpperLimit)this.m_limitImpulse=0;this.m_limitState=
b2Joint.e_atUpperLimit}else this.m_limitState=b2Joint.e_inactiveLimit,this.m_limitImpulse=0}else this.m_limitImpulse=0;b2World.s_enableWarmStarting?(a.m_linearVelocity.x-=h*this.m_ptpImpulse.x,a.m_linearVelocity.y-=h*this.m_ptpImpulse.y,a.m_angularVelocity-=k*(e*this.m_ptpImpulse.y-f*this.m_ptpImpulse.x+this.m_motorImpulse+this.m_limitImpulse),c.m_linearVelocity.x+=i*this.m_ptpImpulse.x,c.m_linearVelocity.y+=i*this.m_ptpImpulse.y,c.m_angularVelocity+=j*(g*this.m_ptpImpulse.y-b*this.m_ptpImpulse.x+
this.m_motorImpulse+this.m_limitImpulse)):(this.m_ptpImpulse.SetZero(),this.m_limitImpulse=this.m_motorImpulse=0);this.m_limitPositionImpulse=0},SolveVelocityConstraints:function(a){var c=this.m_body1,b=this.m_body2,e;e=c.m_R;var f=e.col1.x*this.m_localAnchor1.x+e.col2.x*this.m_localAnchor1.y,g=e.col1.y*this.m_localAnchor1.x+e.col2.y*this.m_localAnchor1.y;e=b.m_R;var h=e.col1.x*this.m_localAnchor2.x+e.col2.x*this.m_localAnchor2.y;e=e.col1.y*this.m_localAnchor2.x+e.col2.y*this.m_localAnchor2.y;var i=
b.m_linearVelocity.x+-b.m_angularVelocity*e-c.m_linearVelocity.x- -c.m_angularVelocity*g,k=b.m_linearVelocity.y+b.m_angularVelocity*h-c.m_linearVelocity.y-c.m_angularVelocity*f,j=-(this.m_ptpMass.col1.x*i+this.m_ptpMass.col2.x*k),i=-(this.m_ptpMass.col1.y*i+this.m_ptpMass.col2.y*k);this.m_ptpImpulse.x+=j;this.m_ptpImpulse.y+=i;c.m_linearVelocity.x-=c.m_invMass*j;c.m_linearVelocity.y-=c.m_invMass*i;c.m_angularVelocity-=c.m_invI*(f*i-g*j);b.m_linearVelocity.x+=b.m_invMass*j;b.m_linearVelocity.y+=b.m_invMass*
i;b.m_angularVelocity+=b.m_invI*(h*i-e*j);if(this.m_enableMotor&&this.m_limitState!=b2Joint.e_equalLimits)f=-this.m_motorMass*(b.m_angularVelocity-c.m_angularVelocity-this.m_motorSpeed),g=this.m_motorImpulse,this.m_motorImpulse=b2Math.b2Clamp(this.m_motorImpulse+f,-a.dt*this.m_maxMotorTorque,a.dt*this.m_maxMotorTorque),f=this.m_motorImpulse-g,c.m_angularVelocity-=c.m_invI*f,b.m_angularVelocity+=b.m_invI*f;if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){f=-this.m_motorMass*(b.m_angularVelocity-
c.m_angularVelocity);if(this.m_limitState==b2Joint.e_equalLimits)this.m_limitImpulse+=f;else if(this.m_limitState==b2Joint.e_atLowerLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Max(this.m_limitImpulse+f,0),f=this.m_limitImpulse-a;else if(this.m_limitState==b2Joint.e_atUpperLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Min(this.m_limitImpulse+f,0),f=this.m_limitImpulse-a;c.m_angularVelocity-=c.m_invI*f;b.m_angularVelocity+=b.m_invI*f}},SolvePositionConstraints:function(){var a,
c=this.m_body1,b=this.m_body2,e=0,e=c.m_R,f=e.col1.x*this.m_localAnchor1.x+e.col2.x*this.m_localAnchor1.y,g=e.col1.y*this.m_localAnchor1.x+e.col2.y*this.m_localAnchor1.y,e=b.m_R;a=e.col1.x*this.m_localAnchor2.x+e.col2.x*this.m_localAnchor2.y;var h=e.col1.y*this.m_localAnchor2.x+e.col2.y*this.m_localAnchor2.y,i=b.m_position.x+a-(c.m_position.x+f),k=b.m_position.y+h-(c.m_position.y+g),e=Math.sqrt(i*i+k*k),j=c.m_invMass,l=b.m_invMass,m=c.m_invI,n=b.m_invI;this.K1.col1.x=j+l;this.K1.col2.x=0;this.K1.col1.y=
0;this.K1.col2.y=j+l;this.K2.col1.x=m*g*g;this.K2.col2.x=-m*f*g;this.K2.col1.y=-m*f*g;this.K2.col2.y=m*f*f;this.K3.col1.x=n*h*h;this.K3.col2.x=-n*a*h;this.K3.col1.y=-n*a*h;this.K3.col2.y=n*a*a;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Solve(b2RevoluteJoint.tImpulse,-i,-k);i=b2RevoluteJoint.tImpulse.x;k=b2RevoluteJoint.tImpulse.y;c.m_position.x-=c.m_invMass*i;c.m_position.y-=c.m_invMass*k;c.m_rotation-=c.m_invI*(f*k-g*i);c.m_R.Set(c.m_rotation);b.m_position.x+=b.m_invMass*
i;b.m_position.y+=b.m_invMass*k;b.m_rotation+=b.m_invI*(a*k-h*i);b.m_R.Set(b.m_rotation);f=0;if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){a=b.m_rotation-c.m_rotation-this.m_intialAngle;g=0;if(this.m_limitState==b2Joint.e_equalLimits)a=b2Math.b2Clamp(a,-b2Settings.b2_maxAngularCorrection,b2Settings.b2_maxAngularCorrection),g=-this.m_motorMass*a,f=b2Math.b2Abs(a);else if(this.m_limitState==b2Joint.e_atLowerLimit)a-=this.m_lowerAngle,f=b2Math.b2Max(0,-a),a=b2Math.b2Clamp(a+b2Settings.b2_angularSlop,
-b2Settings.b2_maxAngularCorrection,0),g=-this.m_motorMass*a,a=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Max(this.m_limitPositionImpulse+g,0),g=this.m_limitPositionImpulse-a;else if(this.m_limitState==b2Joint.e_atUpperLimit)a-=this.m_upperAngle,f=b2Math.b2Max(0,a),a=b2Math.b2Clamp(a-b2Settings.b2_angularSlop,0,b2Settings.b2_maxAngularCorrection),g=-this.m_motorMass*a,a=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Min(this.m_limitPositionImpulse+g,0),g=this.m_limitPositionImpulse-
a;c.m_rotation-=c.m_invI*g;c.m_R.Set(c.m_rotation);b.m_rotation+=b.m_invI*g;b.m_R.Set(b.m_rotation)}return e<=b2Settings.b2_linearSlop&&f<=b2Settings.b2_angularSlop},m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_ptpImpulse:new b2Vec2,m_motorImpulse:null,m_limitImpulse:null,m_limitPositionImpulse:null,m_ptpMass:new b2Mat22,m_motorMass:null,m_intialAngle:null,m_lowerAngle:null,m_upperAngle:null,m_maxMotorTorque:null,m_motorSpeed:null,m_enableLimit:null,m_enableMotor:null,m_limitState:0});
b2RevoluteJoint.tImpulse=new b2Vec2;
@@ -0,0 +1,167 @@
/* Prototype JavaScript framework, version 1.6.0.2
* (c) 2005-2008 Sam Stephenson
*
* Prototype is freely distributable under the terms of an MIT-style license.
* For details, see the Prototype web site: http://www.prototypejs.org/
*
*--------------------------------------------------------------------------*/
var Prototype={Version:"1.6.0.2",Browser:{IE:!(!window.attachEvent||window.opera),Opera:!!window.opera,WebKit:navigator.userAgent.indexOf("AppleWebKit/")>-1,Gecko:navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1,MobileSafari:!!navigator.userAgent.match(/Apple.*Mobile.*Safari/)},BrowserFeatures:{XPath:!!document.evaluate,ElementExtensions:!!window.HTMLElement,SpecificElementExtensions:document.createElement("div").__proto__&&document.createElement("div").__proto__!==
document.createElement("form").__proto__},ScriptFragment:"<script[^>]*>([\\S\\s]*?)<\/script>",JSONFilter:/^\/\*-secure-([\s\S]*)\*\/\s*$/,emptyFunction:function(){},K:function(a){return a}};if(Prototype.Browser.MobileSafari)Prototype.BrowserFeatures.SpecificElementExtensions=!1;
var Class={create:function(){function a(){this.initialize.apply(this,arguments)}var b=null,c=$A(arguments);Object.isFunction(c[0])&&(b=c.shift());Object.extend(a,Class.Methods);a.superclass=b;a.subclasses=[];if(b){var d=function(){};d.prototype=b.prototype;a.prototype=new d;b.subclasses.push(a)}for(b=0;b<c.length;b++)a.addMethods(c[b]);if(!a.prototype.initialize)a.prototype.initialize=Prototype.emptyFunction;return a.prototype.constructor=a},Methods:{addMethods:function(a){var b=this.superclass&&
this.superclass.prototype,c=Object.keys(a);Object.keys({toString:!0}).length||c.push("toString","valueOf");for(var d=0,e=c.length;d<e;d++){var f=c[d],g=a[f];if(b&&Object.isFunction(g)&&g.argumentNames().first()=="$super")var h=g,g=Object.extend(function(a){return function(){return b[a].apply(this,arguments)}}(f).wrap(h),{valueOf:function(){return h},toString:function(){return h.toString()}});this.prototype[f]=g}return this}}},Abstract={};Object.extend=function(a,b){for(var c in b)a[c]=b[c];return a};
Object.extend(Object,{inspect:function(a){try{if(Object.isUndefined(a))return"undefined";if(a===null)return"null";return a.inspect?a.inspect():String(a)}catch(b){if(b instanceof RangeError)return"...";throw b;}},toJSON:function(a){switch(typeof a){case "undefined":case "function":case "unknown":return;case "boolean":return a.toString()}if(a===null)return"null";if(a.toJSON)return a.toJSON();if(!Object.isElement(a)){var b=[],c;for(c in a){var d=Object.toJSON(a[c]);Object.isUndefined(d)||b.push(c.toJSON()+
": "+d)}return"{"+b.join(", ")+"}"}},toQueryString:function(a){return $H(a).toQueryString()},toHTML:function(a){return a&&a.toHTML?a.toHTML():String.interpret(a)},keys:function(a){var b=[],c;for(c in a)b.push(c);return b},values:function(a){var b=[],c;for(c in a)b.push(a[c]);return b},clone:function(a){return Object.extend({},a)},isElement:function(a){return a&&a.nodeType==1},isArray:function(a){return a!=null&&typeof a=="object"&&"splice"in a&&"join"in a},isHash:function(a){return a instanceof Hash},
isFunction:function(a){return typeof a=="function"},isString:function(a){return typeof a=="string"},isNumber:function(a){return typeof a=="number"},isUndefined:function(a){return typeof a=="undefined"}});
Object.extend(Function.prototype,{argumentNames:function(){var a=this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");return a.length==1&&!a[0]?[]:a},bind:function(){if(arguments.length<2&&Object.isUndefined(arguments[0]))return this;var a=this,b=$A(arguments),c=b.shift();return function(){return a.apply(c,b.concat($A(arguments)))}},bindAsEventListener:function(){var a=this,b=$A(arguments),c=b.shift();return function(d){return a.apply(c,[d||window.event].concat(b))}},
curry:function(){if(!arguments.length)return this;var a=this,b=$A(arguments);return function(){return a.apply(this,b.concat($A(arguments)))}},delay:function(){var a=this,b=$A(arguments),c=b.shift()*1E3;return window.setTimeout(function(){return a.apply(a,b)},c)},wrap:function(a){var b=this;return function(){return a.apply(this,[b.bind(this)].concat($A(arguments)))}},methodize:function(){if(this._methodized)return this._methodized;var a=this;return this._methodized=function(){return a.apply(null,[this].concat($A(arguments)))}}});
Function.prototype.defer=Function.prototype.delay.curry(0.01);Date.prototype.toJSON=function(){return'"'+this.getUTCFullYear()+"-"+(this.getUTCMonth()+1).toPaddedString(2)+"-"+this.getUTCDate().toPaddedString(2)+"T"+this.getUTCHours().toPaddedString(2)+":"+this.getUTCMinutes().toPaddedString(2)+":"+this.getUTCSeconds().toPaddedString(2)+'Z"'};var Try={these:function(){for(var a,b=0,c=arguments.length;b<c;b++){var d=arguments[b];try{a=d();break}catch(e){}}return a}};RegExp.prototype.match=RegExp.prototype.test;
RegExp.escape=function(a){return String(a).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")};
var PeriodicalExecuter=Class.create({initialize:function(a,b){this.callback=a;this.frequency=b;this.currentlyExecuting=!1;this.registerCallback()},registerCallback:function(){this.timer=setInterval(this.onTimerEvent.bind(this),this.frequency*1E3)},execute:function(){this.callback(this)},stop:function(){if(this.timer)clearInterval(this.timer),this.timer=null},onTimerEvent:function(){if(!this.currentlyExecuting)try{this.currentlyExecuting=!0,this.execute()}finally{this.currentlyExecuting=!1}}});
Object.extend(String,{interpret:function(a){return a==null?"":String(a)},specialChar:{"\u0008":"\\b","\t":"\\t","\n":"\\n","\u000c":"\\f","\r":"\\r","\\":"\\\\"}});
Object.extend(String.prototype,{gsub:function(a,b){for(var c="",d=this,e,b=arguments.callee.prepareReplacement(b);d.length>0;)(e=d.match(a))?(c+=d.slice(0,e.index),c+=String.interpret(b(e)),d=d.slice(e.index+e[0].length)):(c+=d,d="");return c},sub:function(a,b,c){b=this.gsub.prepareReplacement(b);c=Object.isUndefined(c)?1:c;return this.gsub(a,function(a){if(--c<0)return a[0];return b(a)})},scan:function(a,b){this.gsub(a,b);return String(this)},truncate:function(a,b){a=a||30;b=Object.isUndefined(b)?
"...":b;return this.length>a?this.slice(0,a-b.length)+b:String(this)},strip:function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,"")},stripScripts:function(){return this.replace(RegExp(Prototype.ScriptFragment,"img"),"")},extractScripts:function(){var a=RegExp(Prototype.ScriptFragment,"im");return(this.match(RegExp(Prototype.ScriptFragment,"img"))||[]).map(function(b){return(b.match(a)||["",""])[1]})},evalScripts:function(){return this.extractScripts().map(function(a){return eval(a)})},
escapeHTML:function(){var a=arguments.callee;a.text.data=this;return a.div.innerHTML},unescapeHTML:function(){var a=new Element("div");a.innerHTML=this.stripTags();return a.childNodes[0]?a.childNodes.length>1?$A(a.childNodes).inject("",function(a,c){return a+c.nodeValue}):a.childNodes[0].nodeValue:""},toQueryParams:function(a){var b=this.strip().match(/([^?#]*)(#.*)?$/);if(!b)return{};return b[1].split(a||"&").inject({},function(a,b){if((b=b.split("="))[0]){var e=decodeURIComponent(b.shift()),f=b.length>
1?b.join("="):b[0];f!=void 0&&(f=decodeURIComponent(f));e in a?(Object.isArray(a[e])||(a[e]=[a[e]]),a[e].push(f)):a[e]=f}return a})},toArray:function(){return this.split("")},succ:function(){return this.slice(0,this.length-1)+String.fromCharCode(this.charCodeAt(this.length-1)+1)},times:function(a){return a<1?"":Array(a+1).join(this)},camelize:function(){var a=this.split("-"),b=a.length;if(b==1)return a[0];for(var c=this.charAt(0)=="-"?a[0].charAt(0).toUpperCase()+a[0].substring(1):a[0],d=1;d<b;d++)c+=
a[d].charAt(0).toUpperCase()+a[d].substring(1);return c},capitalize:function(){return this.charAt(0).toUpperCase()+this.substring(1).toLowerCase()},underscore:function(){return this.gsub(/::/,"/").gsub(/([A-Z]+)([A-Z][a-z])/,"#{1}_#{2}").gsub(/([a-z\d])([A-Z])/,"#{1}_#{2}").gsub(/-/,"_").toLowerCase()},dasherize:function(){return this.gsub(/_/,"-")},inspect:function(a){var b=this.gsub(/[\x00-\x1f\\]/,function(a){var b=String.specialChar[a[0]];return b?b:"\\u00"+a[0].charCodeAt().toPaddedString(2,
16)});if(a)return'"'+b.replace(/"/g,'\\"')+'"';return"'"+b.replace(/'/g,"\\'")+"'"},toJSON:function(){return this.inspect(!0)},unfilterJSON:function(a){return this.sub(a||Prototype.JSONFilter,"#{1}")},isJSON:function(){var a;if(this.blank())return!1;a=this.replace(/\\./g,"@").replace(/"[^"\\\n\r]*"/g,"");return/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(a)},evalJSON:function(a){var b=this.unfilterJSON();try{if(!a||b.isJSON())return eval("("+b+")")}catch(c){}throw new SyntaxError("Badly formed JSON string: "+
this.inspect());},include:function(a){return this.indexOf(a)>-1},startsWith:function(a){return this.indexOf(a)===0},endsWith:function(a){var b=this.length-a.length;return b>=0&&this.lastIndexOf(a)===b},empty:function(){return this==""},blank:function(){return/^\s*$/.test(this)},interpolate:function(a,b){return(new Template(this,b)).evaluate(a)}});
(Prototype.Browser.WebKit||Prototype.Browser.IE)&&Object.extend(String.prototype,{escapeHTML:function(){return this.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")},unescapeHTML:function(){return this.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">")}});String.prototype.gsub.prepareReplacement=function(a){if(Object.isFunction(a))return a;var b=new Template(a);return function(a){return b.evaluate(a)}};String.prototype.parseQuery=String.prototype.toQueryParams;
Object.extend(String.prototype.escapeHTML,{div:document.createElement("div"),text:document.createTextNode("")});with(String.prototype.escapeHTML)div.appendChild(text);
var Template=Class.create({initialize:function(a,b){this.template=a.toString();this.pattern=b||Template.Pattern},evaluate:function(a){Object.isFunction(a.toTemplateReplacements)&&(a=a.toTemplateReplacements());return this.template.gsub(this.pattern,function(b){if(a==null)return"";var c=b[1]||"";if(c=="\\")return b[2];var d=a,e=b[3],f=/^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/,b=f.exec(e);if(b==null)return c;for(;b!=null;){var g=b[1].startsWith("[")?b[2].gsub("\\\\]","]"):b[1],d=d[g];if(null==d||""==
b[3])break;e=e.substring("["==b[3]?b[1].length:b[0].length);b=f.exec(e)}return c+String.interpret(d)})}});Template.Pattern=/(^|.|\r|\n)(#\{(.*?)\})/;
var $break={},Enumerable={each:function(a,b){var c=0,a=a.bind(b);try{this._each(function(b){a(b,c++)})}catch(d){if(d!=$break)throw d;}return this},eachSlice:function(a,b,c){for(var b=b?b.bind(c):Prototype.K,d=-a,e=[],f=this.toArray();(d+=a)<f.length;)e.push(f.slice(d,d+a));return e.collect(b,c)},all:function(a,b){var a=a?a.bind(b):Prototype.K,c=!0;this.each(function(b,e){c=c&&!!a(b,e);if(!c)throw $break;});return c},any:function(a,b){var a=a?a.bind(b):Prototype.K,c=!1;this.each(function(b,e){if(c=
!!a(b,e))throw $break;});return c},collect:function(a,b){var a=a?a.bind(b):Prototype.K,c=[];this.each(function(b,e){c.push(a(b,e))});return c},detect:function(a,b){var a=a.bind(b),c;this.each(function(b,e){if(a(b,e))throw c=b,$break;});return c},findAll:function(a,b){var a=a.bind(b),c=[];this.each(function(b,e){a(b,e)&&c.push(b)});return c},grep:function(a,b,c){var b=b?b.bind(c):Prototype.K,d=[];Object.isString(a)&&(a=RegExp(a));this.each(function(c,f){a.match(c)&&d.push(b(c,f))});return d},include:function(a){if(Object.isFunction(this.indexOf)&&
this.indexOf(a)!=-1)return!0;var b=!1;this.each(function(c){if(c==a)throw b=!0,$break;});return b},inGroupsOf:function(a,b){b=Object.isUndefined(b)?null:b;return this.eachSlice(a,function(c){for(;c.length<a;)c.push(b);return c})},inject:function(a,b,c){b=b.bind(c);this.each(function(c,e){a=b(a,c,e)});return a},invoke:function(a){var b=$A(arguments).slice(1);return this.map(function(c){return c[a].apply(c,b)})},max:function(a,b){var a=a?a.bind(b):Prototype.K,c;this.each(function(b,e){b=a(b,e);if(c==
null||b>=c)c=b});return c},min:function(a,b){var a=a?a.bind(b):Prototype.K,c;this.each(function(b,e){b=a(b,e);if(c==null||b<c)c=b});return c},partition:function(a,b){var a=a?a.bind(b):Prototype.K,c=[],d=[];this.each(function(b,f){(a(b,f)?c:d).push(b)});return[c,d]},pluck:function(a){var b=[];this.each(function(c){b.push(c[a])});return b},reject:function(a,b){var a=a.bind(b),c=[];this.each(function(b,e){a(b,e)||c.push(b)});return c},sortBy:function(a,b){a=a.bind(b);return this.map(function(b,d){return{value:b,
criteria:a(b,d)}}).sort(function(a,b){var e=a.criteria,f=b.criteria;return e<f?-1:e>f?1:0}).pluck("value")},toArray:function(){return this.map()},zip:function(){var a=Prototype.K,b=$A(arguments);Object.isFunction(b.last())&&(a=b.pop());var c=[this].concat(b).map($A);return this.map(function(b,e){return a(c.pluck(e))})},size:function(){return this.toArray().length},inspect:function(){return"#<Enumerable:"+this.toArray().inspect()+">"}};
Object.extend(Enumerable,{map:Enumerable.collect,find:Enumerable.detect,select:Enumerable.findAll,filter:Enumerable.findAll,member:Enumerable.include,entries:Enumerable.toArray,every:Enumerable.all,some:Enumerable.any});function $A(a){if(!a)return[];if(a.toArray)return a.toArray();for(var b=a.length||0,c=Array(b);b--;)c[b]=a[b];return c}
Prototype.Browser.WebKit&&($A=function(a){if(!a)return[];if(!(Object.isFunction(a)&&a=="[object NodeList]")&&a.toArray)return a.toArray();for(var b=a.length||0,c=Array(b);b--;)c[b]=a[b];return c});Array.from=$A;Object.extend(Array.prototype,Enumerable);if(!Array.prototype._reverse)Array.prototype._reverse=Array.prototype.reverse;
Object.extend(Array.prototype,{_each:function(a){for(var b=0,c=this.length;b<c;b++)a(this[b])},clear:function(){this.length=0;return this},first:function(){return this[0]},last:function(){return this[this.length-1]},compact:function(){return this.select(function(a){return a!=null})},flatten:function(){return this.inject([],function(a,b){return a.concat(Object.isArray(b)?b.flatten():[b])})},without:function(){var a=$A(arguments);return this.select(function(b){return!a.include(b)})},reverse:function(a){return(a!==
!1?this:this.toArray())._reverse()},reduce:function(){return this.length>1?this:this[0]},uniq:function(a){return this.inject([],function(b,c,d){(0==d||(a?b.last()!=c:!b.include(c)))&&b.push(c);return b})},intersect:function(a){return this.uniq().findAll(function(b){return a.detect(function(a){return b===a})})},clone:function(){return[].concat(this)},size:function(){return this.length},inspect:function(){return"["+this.map(Object.inspect).join(", ")+"]"},toJSON:function(){var a=[];this.each(function(b){b=
Object.toJSON(b);Object.isUndefined(b)||a.push(b)});return"["+a.join(", ")+"]"}});if(Object.isFunction(Array.prototype.forEach))Array.prototype._each=Array.prototype.forEach;if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a,b){b||(b=0);var c=this.length;for(b<0&&(b=c+b);b<c;b++)if(this[b]===a)return b;return-1};
if(!Array.prototype.lastIndexOf)Array.prototype.lastIndexOf=function(a,b){var b=isNaN(b)?this.length:(b<0?this.length+b:b)+1,c=this.slice(0,b).reverse().indexOf(a);return c<0?c:b-c-1};Array.prototype.toArray=Array.prototype.clone;function $w(a){if(!Object.isString(a))return[];return(a=a.strip())?a.split(/\s+/):[]}
if(Prototype.Browser.Opera)Array.prototype.concat=function(){for(var a=[],b=0,c=this.length;b<c;b++)a.push(this[b]);b=0;for(c=arguments.length;b<c;b++)if(Object.isArray(arguments[b]))for(var d=0,e=arguments[b].length;d<e;d++)a.push(arguments[b][d]);else a.push(arguments[b]);return a};
Object.extend(Number.prototype,{toColorPart:function(){return this.toPaddedString(2,16)},succ:function(){return this+1},times:function(a){$R(0,this,!0).each(a);return this},toPaddedString:function(a,b){var c=this.toString(b||10);return"0".times(a-c.length)+c},toJSON:function(){return isFinite(this)?this.toString():"null"}});$w("abs round ceil floor").each(function(a){Number.prototype[a]=Math[a].methodize()});function $H(a){return new Hash(a)}
var Hash=Class.create(Enumerable,function(){function a(a,c){if(Object.isUndefined(c))return a;return a+"="+encodeURIComponent(String.interpret(c))}return{initialize:function(a){this._object=Object.isHash(a)?a.toObject():Object.clone(a)},_each:function(a){for(var c in this._object){var d=this._object[c],e=[c,d];e.key=c;e.value=d;a(e)}},set:function(a,c){return this._object[a]=c},get:function(a){return this._object[a]},unset:function(a){var c=this._object[a];delete this._object[a];return c},toObject:function(){return Object.clone(this._object)},
keys:function(){return this.pluck("key")},values:function(){return this.pluck("value")},index:function(a){var c=this.detect(function(c){return c.value===a});return c&&c.key},merge:function(a){return this.clone().update(a)},update:function(a){return(new Hash(a)).inject(this,function(a,b){a.set(b.key,b.value);return a})},toQueryString:function(){return this.map(function(b){var c=encodeURIComponent(b.key);if((b=b.value)&&typeof b=="object"&&Object.isArray(b))return b.map(a.curry(c)).join("&");return a(c,
b)}).join("&")},inspect:function(){return"#<Hash:{"+this.map(function(a){return a.map(Object.inspect).join(": ")}).join(", ")+"}>"},toJSON:function(){return Object.toJSON(this.toObject())},clone:function(){return new Hash(this)}}}());Hash.prototype.toTemplateReplacements=Hash.prototype.toObject;Hash.from=$H;
var ObjectRange=Class.create(Enumerable,{initialize:function(a,b,c){this.start=a;this.end=b;this.exclusive=c},_each:function(a){for(var b=this.start;this.include(b);)a(b),b=b.succ()},include:function(a){if(a<this.start)return!1;if(this.exclusive)return a<this.end;return a<=this.end}}),$R=function(a,b,c){return new ObjectRange(a,b,c)},Ajax={getTransport:function(){return Try.these(function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")})||
!1},activeRequestCount:0,Responders:{responders:[],_each:function(a){this.responders._each(a)},register:function(a){this.include(a)||this.responders.push(a)},unregister:function(a){this.responders=this.responders.without(a)},dispatch:function(a,b,c,d){this.each(function(e){if(Object.isFunction(e[a]))try{e[a].apply(e,[b,c,d])}catch(f){}})}}};Object.extend(Ajax.Responders,Enumerable);Ajax.Responders.register({onCreate:function(){Ajax.activeRequestCount++},onComplete:function(){Ajax.activeRequestCount--}});
Ajax.Base=Class.create({initialize:function(a){this.options={method:"post",asynchronous:!0,contentType:"application/x-www-form-urlencoded",encoding:"UTF-8",parameters:"",evalJSON:!0,evalJS:!0};Object.extend(this.options,a||{});this.options.method=this.options.method.toLowerCase();if(Object.isString(this.options.parameters))this.options.parameters=this.options.parameters.toQueryParams();else if(Object.isHash(this.options.parameters))this.options.parameters=this.options.parameters.toObject()}});
Ajax.Request=Class.create(Ajax.Base,{_complete:!1,initialize:function($super,b,c){$super(c);this.transport=Ajax.getTransport();this.request(b)},request:function(a){this.url=a;this.method=this.options.method;a=Object.clone(this.options.parameters);if(!["get","post"].include(this.method))a._method=this.method,this.method="post";this.parameters=a;if(a=Object.toQueryString(a))this.method=="get"?this.url+=(this.url.include("?")?"&":"?")+a:/Konqueror|Safari|KHTML/.test(navigator.userAgent)&&(a+="&_=");
try{var b=new Ajax.Response(this);if(this.options.onCreate)this.options.onCreate(b);Ajax.Responders.dispatch("onCreate",this,b);this.transport.open(this.method.toUpperCase(),this.url,this.options.asynchronous);this.options.asynchronous&&this.respondToReadyState.bind(this).defer(1);this.transport.onreadystatechange=this.onStateChange.bind(this);this.setRequestHeaders();this.body=this.method=="post"?this.options.postBody||a:null;this.transport.send(this.body);if(!this.options.asynchronous&&this.transport.overrideMimeType)this.onStateChange()}catch(c){this.dispatchException(c)}},
onStateChange:function(){var a=this.transport.readyState;a>1&&!(a==4&&this._complete)&&this.respondToReadyState(this.transport.readyState)},setRequestHeaders:function(){var a={"X-Requested-With":"XMLHttpRequest","X-Prototype-Version":Prototype.Version,Accept:"text/javascript, text/html, application/xml, text/xml, */*"};if(this.method=="post"&&(a["Content-type"]=this.options.contentType+(this.options.encoding?"; charset="+this.options.encoding:""),this.transport.overrideMimeType&&(navigator.userAgent.match(/Gecko\/(\d{4})/)||
[0,2005])[1]<2005))a.Connection="close";if(typeof this.options.requestHeaders=="object"){var b=this.options.requestHeaders;if(Object.isFunction(b.push))for(var c=0,d=b.length;c<d;c+=2)a[b[c]]=b[c+1];else $H(b).each(function(b){a[b.key]=b.value})}for(var e in a)this.transport.setRequestHeader(e,a[e])},success:function(){var a=this.getStatus();return!a||a>=200&&a<300},getStatus:function(){try{return this.transport.status||0}catch(a){return 0}},respondToReadyState:function(a){var a=Ajax.Request.Events[a],
b=new Ajax.Response(this);if(a=="Complete"){try{this._complete=!0,(this.options["on"+b.status]||this.options["on"+(this.success()?"Success":"Failure")]||Prototype.emptyFunction)(b,b.headerJSON)}catch(c){this.dispatchException(c)}var d=b.getHeader("Content-type");(this.options.evalJS=="force"||this.options.evalJS&&this.isSameOrigin()&&d&&d.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i))&&this.evalResponse()}try{(this.options["on"+a]||Prototype.emptyFunction)(b,b.headerJSON),Ajax.Responders.dispatch("on"+
a,this,b,b.headerJSON)}catch(e){this.dispatchException(e)}if(a=="Complete")this.transport.onreadystatechange=Prototype.emptyFunction},isSameOrigin:function(){var a=this.url.match(/^\s*https?:\/\/[^\/]*/);return!a||a[0]=="#{protocol}//#{domain}#{port}".interpolate({protocol:location.protocol,domain:document.domain,port:location.port?":"+location.port:""})},getHeader:function(a){try{return this.transport.getResponseHeader(a)||null}catch(b){return null}},evalResponse:function(){try{return eval((this.transport.responseText||
"").unfilterJSON())}catch(a){this.dispatchException(a)}},dispatchException:function(a){(this.options.onException||Prototype.emptyFunction)(this,a);Ajax.Responders.dispatch("onException",this,a)}});Ajax.Request.Events=["Uninitialized","Loading","Loaded","Interactive","Complete"];
Ajax.Response=Class.create({initialize:function(a){this.request=a;var a=this.transport=a.transport,b=this.readyState=a.readyState;if(b>2&&!Prototype.Browser.IE||b==4)this.status=this.getStatus(),this.statusText=this.getStatusText(),this.responseText=String.interpret(a.responseText),this.headerJSON=this._getHeaderJSON();if(b==4)a=a.responseXML,this.responseXML=Object.isUndefined(a)?null:a,this.responseJSON=this._getResponseJSON()},status:0,statusText:"",getStatus:Ajax.Request.prototype.getStatus,getStatusText:function(){try{return this.transport.statusText||
""}catch(a){return""}},getHeader:Ajax.Request.prototype.getHeader,getAllHeaders:function(){try{return this.getAllResponseHeaders()}catch(a){return null}},getResponseHeader:function(a){return this.transport.getResponseHeader(a)},getAllResponseHeaders:function(){return this.transport.getAllResponseHeaders()},_getHeaderJSON:function(){var a=this.getHeader("X-JSON");if(!a)return null;a=decodeURIComponent(escape(a));try{return a.evalJSON(this.request.options.sanitizeJSON||!this.request.isSameOrigin())}catch(b){this.request.dispatchException(b)}},
_getResponseJSON:function(){var a=this.request.options;if(!a.evalJSON||a.evalJSON!="force"&&!(this.getHeader("Content-type")||"").include("application/json")||this.responseText.blank())return null;try{return this.responseText.evalJSON(a.sanitizeJSON||!this.request.isSameOrigin())}catch(b){this.request.dispatchException(b)}}});
Ajax.Updater=Class.create(Ajax.Request,{initialize:function($super,b,c,d){this.container={success:b.success||b,failure:b.failure||(b.success?null:b)};var d=Object.clone(d),e=d.onComplete;d.onComplete=function(b,c){this.updateContent(b.responseText);Object.isFunction(e)&&e(b,c)}.bind(this);$super(c,d)},updateContent:function(a){var b=this.container[this.success()?"success":"failure"],c=this.options;c.evalScripts||(a=a.stripScripts());if(b=$(b))if(c.insertion)if(Object.isString(c.insertion)){var d=
{};d[c.insertion]=a;b.insert(d)}else c.insertion(b,a);else b.update(a)}});
Ajax.PeriodicalUpdater=Class.create(Ajax.Base,{initialize:function($super,b,c,d){$super(d);this.onComplete=this.options.onComplete;this.frequency=this.options.frequency||2;this.decay=this.options.decay||1;this.updater={};this.container=b;this.url=c;this.start()},start:function(){this.options.onComplete=this.updateComplete.bind(this);this.onTimerEvent()},stop:function(){this.updater.options.onComplete=void 0;clearTimeout(this.timer);(this.onComplete||Prototype.emptyFunction).apply(this,arguments)},
updateComplete:function(a){if(this.options.decay)this.decay=a.responseText==this.lastText?this.decay*this.options.decay:1,this.lastText=a.responseText;this.timer=this.onTimerEvent.bind(this).delay(this.decay*this.frequency)},onTimerEvent:function(){this.updater=new Ajax.Updater(this.container,this.url,this.options)}});
function $(a){if(arguments.length>1){for(var b=0,c=[],d=arguments.length;b<d;b++)c.push($(arguments[b]));return c}Object.isString(a)&&(a=document.getElementById(a));return Element.extend(a)}if(Prototype.BrowserFeatures.XPath)document._getElementsByXPath=function(a,b){for(var c=[],d=document.evaluate(a,$(b)||document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),e=0,f=d.snapshotLength;e<f;e++)c.push(Element.extend(d.snapshotItem(e)));return c};if(!window.Node)var Node={};
Node.ELEMENT_NODE||Object.extend(Node,{ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12});
(function(){var a=this.Element;this.Element=function(a,c){var c=c||{},a=a.toLowerCase(),d=Element.cache;if(Prototype.Browser.IE&&c.name)return a="<"+a+' name="'+c.name+'">',delete c.name,Element.writeAttribute(document.createElement(a),c);d[a]||(d[a]=Element.extend(document.createElement(a)));return Element.writeAttribute(d[a].cloneNode(!1),c)};Object.extend(this.Element,a||{})}).call(window);Element.cache={};
Element.Methods={visible:function(a){return $(a).style.display!="none"},toggle:function(a){a=$(a);Element[Element.visible(a)?"hide":"show"](a);return a},hide:function(a){$(a).style.display="none";return a},show:function(a){$(a).style.display="";return a},remove:function(a){a=$(a);a.parentNode.removeChild(a);return a},update:function(a,b){a=$(a);b&&b.toElement&&(b=b.toElement());if(Object.isElement(b))return a.update().insert(b);b=Object.toHTML(b);a.innerHTML=b.stripScripts();b.evalScripts.bind(b).defer();
return a},replace:function(a,b){a=$(a);if(b&&b.toElement)b=b.toElement();else if(!Object.isElement(b)){var b=Object.toHTML(b),c=a.ownerDocument.createRange();c.selectNode(a);b.evalScripts.bind(b).defer();b=c.createContextualFragment(b.stripScripts())}a.parentNode.replaceChild(b,a);return a},insert:function(a,b){a=$(a);if(Object.isString(b)||Object.isNumber(b)||Object.isElement(b)||b&&(b.toElement||b.toHTML))b={bottom:b};var c,d,e,f;for(f in b)c=b[f],f=f.toLowerCase(),d=Element._insertionTranslations[f],
c&&c.toElement&&(c=c.toElement()),Object.isElement(c)?d(a,c):(c=Object.toHTML(c),e=(f=="before"||f=="after"?a.parentNode:a).tagName.toUpperCase(),e=Element._getContentFromAnonymousElement(e,c.stripScripts()),(f=="top"||f=="after")&&e.reverse(),e.each(d.curry(a)),c.evalScripts.bind(c).defer());return a},wrap:function(a,b,c){a=$(a);Object.isElement(b)?$(b).writeAttribute(c||{}):b=Object.isString(b)?new Element(b,c):new Element("div",b);a.parentNode&&a.parentNode.replaceChild(b,a);b.appendChild(a);return b},
inspect:function(a){var a=$(a),b="<"+a.tagName.toLowerCase();$H({id:"id",className:"class"}).each(function(c){var d=c.first(),c=c.last();(d=(a[d]||"").toString())&&(b+=" "+c+"="+d.inspect(!0))});return b+">"},recursivelyCollect:function(a,b){for(var a=$(a),c=[];a=a[b];)a.nodeType==1&&c.push(Element.extend(a));return c},ancestors:function(a){return $(a).recursivelyCollect("parentNode")},descendants:function(a){return $(a).select("*")},firstDescendant:function(a){for(a=$(a).firstChild;a&&a.nodeType!=
1;)a=a.nextSibling;return $(a)},immediateDescendants:function(a){if(!(a=$(a).firstChild))return[];for(;a&&a.nodeType!=1;)a=a.nextSibling;if(a)return[a].concat($(a).nextSiblings());return[]},previousSiblings:function(a){return $(a).recursivelyCollect("previousSibling")},nextSiblings:function(a){return $(a).recursivelyCollect("nextSibling")},siblings:function(a){a=$(a);return a.previousSiblings().reverse().concat(a.nextSiblings())},match:function(a,b){Object.isString(b)&&(b=new Selector(b));return b.match($(a))},
up:function(a,b,c){a=$(a);if(arguments.length==1)return $(a.parentNode);var d=a.ancestors();return Object.isNumber(b)?d[b]:Selector.findElement(d,b,c)},down:function(a,b,c){a=$(a);if(arguments.length==1)return a.firstDescendant();return Object.isNumber(b)?a.descendants()[b]:a.select(b)[c||0]},previous:function(a,b,c){a=$(a);if(arguments.length==1)return $(Selector.handlers.previousElementSibling(a));var d=a.previousSiblings();return Object.isNumber(b)?d[b]:Selector.findElement(d,b,c)},next:function(a,
b,c){a=$(a);if(arguments.length==1)return $(Selector.handlers.nextElementSibling(a));var d=a.nextSiblings();return Object.isNumber(b)?d[b]:Selector.findElement(d,b,c)},select:function(){var a=$A(arguments),b=$(a.shift());return Selector.findChildElements(b,a)},adjacent:function(){var a=$A(arguments),b=$(a.shift());return Selector.findChildElements(b.parentNode,a).without(b)},identify:function(a){var a=$(a),b=a.readAttribute("id"),c=arguments.callee;if(b)return b;do b="anonymous_element_"+c.counter++;
while($(b));a.writeAttribute("id",b);return b},readAttribute:function(a,b){a=$(a);if(Prototype.Browser.IE){var c=Element._attributeTranslations.read;if(c.values[b])return c.values[b](a,b);c.names[b]&&(b=c.names[b]);if(b.include(":"))return!a.attributes||!a.attributes[b]?null:a.attributes[b].value}return a.getAttribute(b)},writeAttribute:function(a,b,c){var a=$(a),d={},e=Element._attributeTranslations.write;typeof b=="object"?d=b:d[b]=Object.isUndefined(c)?!0:c;for(var f in d)b=e.names[f]||f,c=d[f],
e.values[f]&&(b=e.values[f](a,c)),c===!1||c===null?a.removeAttribute(b):c===!0?a.setAttribute(b,b):a.setAttribute(b,c);return a},getHeight:function(a){return $(a).getDimensions().height},getWidth:function(a){return $(a).getDimensions().width},classNames:function(a){return new Element.ClassNames(a)},hasClassName:function(a,b){if(a=$(a)){var c=a.className;return c.length>0&&(c==b||RegExp("(^|\\s)"+b+"(\\s|$)").test(c))}},addClassName:function(a,b){if(a=$(a))return a.hasClassName(b)||(a.className+=(a.className?
" ":"")+b),a},removeClassName:function(a,b){if(a=$(a))return a.className=a.className.replace(RegExp("(^|\\s+)"+b+"(\\s+|$)")," ").strip(),a},toggleClassName:function(a,b){if(a=$(a))return a[a.hasClassName(b)?"removeClassName":"addClassName"](b)},cleanWhitespace:function(a){for(var a=$(a),b=a.firstChild;b;){var c=b.nextSibling;b.nodeType==3&&!/\S/.test(b.nodeValue)&&a.removeChild(b);b=c}return a},empty:function(a){return $(a).innerHTML.blank()},descendantOf:function(a,b){var a=$(a),c=b=$(b);if(a.compareDocumentPosition)return(a.compareDocumentPosition(b)&
8)===8;if(a.sourceIndex&&!Prototype.Browser.Opera){var d=a.sourceIndex,e=b.sourceIndex,f=b.nextSibling;if(!f){do b=b.parentNode;while(!(f=b.nextSibling)&&b.parentNode)}if(f&&f.sourceIndex)return d>e&&d<f.sourceIndex}for(;a=a.parentNode;)if(a==c)return!0;return!1},scrollTo:function(a){var a=$(a),b=a.cumulativeOffset();window.scrollTo(b[0],b[1]);return a},getStyle:function(a,b){var a=$(a),b=b=="float"?"cssFloat":b.camelize(),c=a.style[b];c||(c=(c=document.defaultView.getComputedStyle(a,null))?c[b]:
null);if(b=="opacity")return c?parseFloat(c):1;return c=="auto"?null:c},getOpacity:function(a){return $(a).getStyle("opacity")},setStyle:function(a,b){var a=$(a),c=a.style;if(Object.isString(b))return a.style.cssText+=";"+b,b.include("opacity")?a.setOpacity(b.match(/opacity:\s*(\d?\.?\d*)/)[1]):a;for(var d in b)d=="opacity"?a.setOpacity(b[d]):c[d=="float"||d=="cssFloat"?Object.isUndefined(c.styleFloat)?"cssFloat":"styleFloat":d]=b[d];return a},setOpacity:function(a,b){a=$(a);a.style.opacity=b==1||
b===""?"":b<1.0E-5?0:b;return a},getDimensions:function(a){var a=$(a),b=$(a).getStyle("display");if(b!="none"&&b!=null)return{width:a.offsetWidth,height:a.offsetHeight};var b=a.style,c=b.visibility,d=b.position,e=b.display;b.visibility="hidden";b.position="absolute";b.display="block";var f=a.clientWidth,a=a.clientHeight;b.display=e;b.position=d;b.visibility=c;return{width:f,height:a}},makePositioned:function(a){var a=$(a),b=Element.getStyle(a,"position");if(b=="static"||!b)if(a._madePositioned=!0,
a.style.position="relative",window.opera)a.style.top=0,a.style.left=0;return a},undoPositioned:function(a){a=$(a);if(a._madePositioned)a._madePositioned=void 0,a.style.position=a.style.top=a.style.left=a.style.bottom=a.style.right="";return a},makeClipping:function(a){a=$(a);if(a._overflow)return a;a._overflow=Element.getStyle(a,"overflow")||"auto";if(a._overflow!=="hidden")a.style.overflow="hidden";return a},undoClipping:function(a){a=$(a);if(!a._overflow)return a;a.style.overflow=a._overflow=="auto"?
"":a._overflow;a._overflow=null;return a},cumulativeOffset:function(a){var b=0,c=0;do b+=a.offsetTop||0,c+=a.offsetLeft||0,a=a.offsetParent;while(a);return Element._returnOffset(c,b)},positionedOffset:function(a){var b=0,c=0;do if(b+=a.offsetTop||0,c+=a.offsetLeft||0,a=a.offsetParent){if(a.tagName=="BODY")break;if(Element.getStyle(a,"position")!=="static")break}while(a);return Element._returnOffset(c,b)},absolutize:function(a){a=$(a);if(a.getStyle("position")!="absolute"){var b=a.positionedOffset(),
c=b[1],b=b[0],d=a.clientWidth,e=a.clientHeight;a._originalLeft=b-parseFloat(a.style.left||0);a._originalTop=c-parseFloat(a.style.top||0);a._originalWidth=a.style.width;a._originalHeight=a.style.height;a.style.position="absolute";a.style.top=c+"px";a.style.left=b+"px";a.style.width=d+"px";a.style.height=e+"px";return a}},relativize:function(a){a=$(a);if(a.getStyle("position")!="relative"){a.style.position="relative";var b=parseFloat(a.style.top||0)-(a._originalTop||0),c=parseFloat(a.style.left||0)-
(a._originalLeft||0);a.style.top=b+"px";a.style.left=c+"px";a.style.height=a._originalHeight;a.style.width=a._originalWidth;return a}},cumulativeScrollOffset:function(a){var b=0,c=0;do b+=a.scrollTop||0,c+=a.scrollLeft||0,a=a.parentNode;while(a);return Element._returnOffset(c,b)},getOffsetParent:function(a){if(a.offsetParent)return $(a.offsetParent);if(a==document.body)return $(a);for(;(a=a.parentNode)&&a!=document.body;)if(Element.getStyle(a,"position")!="static")return $(a);return $(document.body)},
viewportOffset:function(a){var b=0,c=0,d=a;do if(b+=d.offsetTop||0,c+=d.offsetLeft||0,d.offsetParent==document.body&&Element.getStyle(d,"position")=="absolute")break;while(d=d.offsetParent);d=a;do if(!Prototype.Browser.Opera||d.tagName=="BODY")b-=d.scrollTop||0,c-=d.scrollLeft||0;while(d=d.parentNode);return Element._returnOffset(c,b)},clonePosition:function(a,b,c){var c=Object.extend({setLeft:!0,setTop:!0,setWidth:!0,setHeight:!0,offsetTop:0,offsetLeft:0},c||{}),b=$(b),d=b.viewportOffset(),a=$(a),
e=[0,0],f=null;Element.getStyle(a,"position")=="absolute"&&(f=a.getOffsetParent(),e=f.viewportOffset());f==document.body&&(e[0]-=document.body.offsetLeft,e[1]-=document.body.offsetTop);if(c.setLeft)a.style.left=d[0]-e[0]+c.offsetLeft+"px";if(c.setTop)a.style.top=d[1]-e[1]+c.offsetTop+"px";if(c.setWidth)a.style.width=b.offsetWidth+"px";if(c.setHeight)a.style.height=b.offsetHeight+"px";return a}};Element.Methods.identify.counter=1;
Object.extend(Element.Methods,{getElementsBySelector:Element.Methods.select,childElements:Element.Methods.immediateDescendants});Element._attributeTranslations={write:{names:{className:"class",htmlFor:"for"},values:{}}};
if(Prototype.Browser.Opera)Element.Methods.getStyle=Element.Methods.getStyle.wrap(function(a,b,c){switch(c){case "left":case "top":case "right":case "bottom":if(a(b,"position")==="static")return null;case "height":case "width":if(!Element.visible(b))return null;var d=parseInt(a(b,c),10);if(d!==b["offset"+c.capitalize()])return d+"px";return(c==="height"?["border-top-width","padding-top","padding-bottom","border-bottom-width"]:["border-left-width","padding-left","padding-right","border-right-width"]).inject(d,
function(c,d){var g=a(b,d);return g===null?c:c-parseInt(g,10)})+"px";default:return a(b,c)}}),Element.Methods.readAttribute=Element.Methods.readAttribute.wrap(function(a,b,c){if(c==="title")return b.title;return a(b,c)});else if(Prototype.Browser.IE)Element.Methods.getOffsetParent=Element.Methods.getOffsetParent.wrap(function(a,b){var b=$(b),c=b.getStyle("position");if(c!=="static")return a(b);b.setStyle({position:"relative"});var d=a(b);b.setStyle({position:c});return d}),$w("positionedOffset viewportOffset").each(function(a){Element.Methods[a]=
Element.Methods[a].wrap(function(a,c){var c=$(c),d=c.getStyle("position");if(d!=="static")return a(c);var e=c.getOffsetParent();e&&e.getStyle("position")==="fixed"&&e.setStyle({zoom:1});c.setStyle({position:"relative"});e=a(c);c.setStyle({position:d});return e})}),Element.Methods.getStyle=function(a,b){var a=$(a),b=b=="float"||b=="cssFloat"?"styleFloat":b.camelize(),c=a.style[b];!c&&a.currentStyle&&(c=a.currentStyle[b]);if(b=="opacity"){if((c=(a.getStyle("filter")||"").match(/alpha\(opacity=(.*)\)/))&&
c[1])return parseFloat(c[1])/100;return 1}if(c=="auto"){if((b=="width"||b=="height")&&a.getStyle("display")!="none")return a["offset"+b.capitalize()]+"px";return null}return c},Element.Methods.setOpacity=function(a,b){var a=$(a),c=a.currentStyle;if(c&&!c.hasLayout||!c&&a.style.zoom=="normal")a.style.zoom=1;var c=a.getStyle("filter"),d=a.style;if(b==1||b==="")return(c=c.replace(/alpha\([^\)]*\)/gi,""))?d.filter=c:d.removeAttribute("filter"),a;else b<1.0E-5&&(b=0);d.filter=c.replace(/alpha\([^\)]*\)/gi,
"")+"alpha(opacity="+b*100+")";return a},Element._attributeTranslations={read:{names:{"class":"className","for":"htmlFor"},values:{_getAttr:function(a,b){return a.getAttribute(b,2)},_getAttrNode:function(a,b){var c=a.getAttributeNode(b);return c?c.value:""},_getEv:function(a,b){return(b=a.getAttribute(b))?b.toString().slice(23,-2):null},_flag:function(a,b){return $(a).hasAttribute(b)?b:null},style:function(a){return a.style.cssText.toLowerCase()},title:function(a){return a.title}}}},Element._attributeTranslations.write=
{names:Object.extend({cellpadding:"cellPadding",cellspacing:"cellSpacing"},Element._attributeTranslations.read.names),values:{checked:function(a,b){a.checked=!!b},style:function(a,b){a.style.cssText=b?b:""}}},Element._attributeTranslations.has={},$w("colSpan rowSpan vAlign dateTime accessKey tabIndex encType maxLength readOnly longDesc").each(function(a){Element._attributeTranslations.write.names[a.toLowerCase()]=a;Element._attributeTranslations.has[a.toLowerCase()]=a}),function(a){Object.extend(a,
{href:a._getAttr,src:a._getAttr,type:a._getAttr,action:a._getAttrNode,disabled:a._flag,checked:a._flag,readonly:a._flag,multiple:a._flag,onload:a._getEv,onunload:a._getEv,onclick:a._getEv,ondblclick:a._getEv,onmousedown:a._getEv,onmouseup:a._getEv,onmouseover:a._getEv,onmousemove:a._getEv,onmouseout:a._getEv,onfocus:a._getEv,onblur:a._getEv,onkeypress:a._getEv,onkeydown:a._getEv,onkeyup:a._getEv,onsubmit:a._getEv,onreset:a._getEv,onselect:a._getEv,onchange:a._getEv})}(Element._attributeTranslations.read.values);
else if(Prototype.Browser.Gecko&&/rv:1\.8\.0/.test(navigator.userAgent))Element.Methods.setOpacity=function(a,b){a=$(a);a.style.opacity=b==1?0.999999:b===""?"":b<1.0E-5?0:b;return a};else if(Prototype.Browser.WebKit)Element.Methods.setOpacity=function(a,b){a=$(a);a.style.opacity=b==1||b===""?"":b<1.0E-5?0:b;if(b==1)if(a.tagName=="IMG"&&a.width)a.width++,a.width--;else try{var c=document.createTextNode(" ");a.appendChild(c);a.removeChild(c)}catch(d){}return a},Element.Methods.cumulativeOffset=function(a){var b=
0,c=0;do{b+=a.offsetTop||0;c+=a.offsetLeft||0;if(a.offsetParent==document.body&&Element.getStyle(a,"position")=="absolute")break;a=a.offsetParent}while(a);return Element._returnOffset(c,b)};
if(Prototype.Browser.IE||Prototype.Browser.Opera)Element.Methods.update=function(a,b){a=$(a);b&&b.toElement&&(b=b.toElement());if(Object.isElement(b))return a.update().insert(b);var b=Object.toHTML(b),c=a.tagName.toUpperCase();c in Element._insertionTranslations.tags?($A(a.childNodes).each(function(b){a.removeChild(b)}),Element._getContentFromAnonymousElement(c,b.stripScripts()).each(function(b){a.appendChild(b)})):a.innerHTML=b.stripScripts();b.evalScripts.bind(b).defer();return a};
if("outerHTML"in document.createElement("div"))Element.Methods.replace=function(a,b){a=$(a);b&&b.toElement&&(b=b.toElement());if(Object.isElement(b))return a.parentNode.replaceChild(b,a),a;var b=Object.toHTML(b),c=a.parentNode,d=c.tagName.toUpperCase();if(Element._insertionTranslations.tags[d]){var e=a.next(),d=Element._getContentFromAnonymousElement(d,b.stripScripts());c.removeChild(a);e?d.each(function(a){c.insertBefore(a,e)}):d.each(function(a){c.appendChild(a)})}else a.outerHTML=b.stripScripts();
b.evalScripts.bind(b).defer();return a};Element._returnOffset=function(a,b){var c=[a,b];c.left=a;c.top=b;return c};Element._getContentFromAnonymousElement=function(a,b){var c=new Element("div"),d=Element._insertionTranslations.tags[a];d?(c.innerHTML=d[0]+b+d[1],d[2].times(function(){c=c.firstChild})):c.innerHTML=b;return $A(c.childNodes)};
Element._insertionTranslations={before:function(a,b){a.parentNode.insertBefore(b,a)},top:function(a,b){a.insertBefore(b,a.firstChild)},bottom:function(a,b){a.appendChild(b)},after:function(a,b){a.parentNode.insertBefore(b,a.nextSibling)},tags:{TABLE:["<table>","</table>",1],TBODY:["<table><tbody>","</tbody></table>",2],TR:["<table><tbody><tr>","</tr></tbody></table>",3],TD:["<table><tbody><tr><td>","</td></tr></tbody></table>",4],SELECT:["<select>","</select>",1]}};
(function(){Object.extend(this.tags,{THEAD:this.tags.TBODY,TFOOT:this.tags.TBODY,TH:this.tags.TD})}).call(Element._insertionTranslations);Element.Methods.Simulated={hasAttribute:function(a,b){var b=Element._attributeTranslations.has[b]||b,c=$(a).getAttributeNode(b);return c&&c.specified}};Element.Methods.ByTag={};Object.extend(Element,Element.Methods);
if(!Prototype.BrowserFeatures.ElementExtensions&&document.createElement("div").__proto__)window.HTMLElement={},window.HTMLElement.prototype=document.createElement("div").__proto__,Prototype.BrowserFeatures.ElementExtensions=!0;
Element.extend=function(){if(Prototype.BrowserFeatures.SpecificElementExtensions)return Prototype.K;var a={},b=Element.Methods.ByTag,c=Object.extend(function(c){if(!c||c._extendedByPrototype||c.nodeType!=1||c==window)return c;var e=Object.clone(a),f=c.tagName,g;b[f]&&Object.extend(e,b[f]);for(g in e)f=e[g],Object.isFunction(f)&&!(g in c)&&(c[g]=f.methodize());c._extendedByPrototype=Prototype.emptyFunction;return c},{refresh:function(){Prototype.BrowserFeatures.ElementExtensions||(Object.extend(a,
Element.Methods),Object.extend(a,Element.Methods.Simulated))}});c.refresh();return c}();Element.hasAttribute=function(a,b){if(a.hasAttribute)return a.hasAttribute(b);return Element.Methods.Simulated.hasAttribute(a,b)};
Element.addMethods=function(a){function b(b){b=b.toUpperCase();Element.Methods.ByTag[b]||(Element.Methods.ByTag[b]={});Object.extend(Element.Methods.ByTag[b],a)}function c(a,b,c){var c=c||!1,d;for(d in a){var e=a[d];if(Object.isFunction(e)&&(!c||!(d in b)))b[d]=e.methodize()}}function d(a){var b,c={OPTGROUP:"OptGroup",TEXTAREA:"TextArea",P:"Paragraph",FIELDSET:"FieldSet",UL:"UList",OL:"OList",DL:"DList",DIR:"Directory",H1:"Heading",H2:"Heading",H3:"Heading",H4:"Heading",H5:"Heading",H6:"Heading",
Q:"Quote",INS:"Mod",DEL:"Mod",A:"Anchor",IMG:"Image",CAPTION:"TableCaption",COL:"TableCol",COLGROUP:"TableCol",THEAD:"TableSection",TFOOT:"TableSection",TBODY:"TableSection",TR:"TableRow",TH:"TableCell",TD:"TableCell",FRAMESET:"FrameSet",IFRAME:"IFrame"};c[a]&&(b="HTML"+c[a]+"Element");if(window[b])return window[b];b="HTML"+a+"Element";if(window[b])return window[b];b="HTML"+a.capitalize()+"Element";if(window[b])return window[b];window[b]={};window[b].prototype=document.createElement(a).__proto__;
return window[b]}var e=Prototype.BrowserFeatures,f=Element.Methods.ByTag;a||(Object.extend(Form,Form.Methods),Object.extend(Form.Element,Form.Element.Methods),Object.extend(Element.Methods.ByTag,{FORM:Object.clone(Form.Methods),INPUT:Object.clone(Form.Element.Methods),SELECT:Object.clone(Form.Element.Methods),TEXTAREA:Object.clone(Form.Element.Methods)}));if(arguments.length==2)var g=a,a=arguments[1];g?Object.isArray(g)?g.each(b):b(g):Object.extend(Element.Methods,a||{});e.ElementExtensions&&(c(Element.Methods,
HTMLElement.prototype),c(Element.Methods.Simulated,HTMLElement.prototype,!0));if(e.SpecificElementExtensions)for(var h in Element.Methods.ByTag)e=d(h),Object.isUndefined(e)||c(f[h],e.prototype);Object.extend(Element,Element.Methods);delete Element.ByTag;Element.extend.refresh&&Element.extend.refresh();Element.cache={}};
document.viewport={getDimensions:function(){var a={},b=Prototype.Browser;$w("width height").each(function(c){var d=c.capitalize();a[c]=b.WebKit&&!document.evaluate?self["inner"+d]:b.Opera?document.body["client"+d]:document.documentElement["client"+d]});return a},getWidth:function(){return this.getDimensions().width},getHeight:function(){return this.getDimensions().height},getScrollOffsets:function(){return Element._returnOffset(window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft,
window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop)}};
var Selector=Class.create({initialize:function(a){this.expression=a.strip();this.compileMatcher()},shouldUseXPath:function(){if(!Prototype.BrowserFeatures.XPath)return!1;var a=this.expression;if(Prototype.Browser.WebKit&&(a.include("-of-type")||a.include(":empty")))return!1;if(/(\[[\w-]*?:|:checked)/.test(this.expression))return!1;return!0},compileMatcher:function(){if(this.shouldUseXPath())return this.compileXPathMatcher();var a=this.expression,b=Selector.patterns,c=Selector.criteria,d,e;if(Selector._cache[a])this.matcher=
Selector._cache[a];else{for(this.matcher=["this.matcher = function(root) {","var r = root, h = Selector.handlers, c = false, n;"];a&&d!=a&&/\S/.test(a);){d=a;for(var f in b)if(e=b[f],e=a.match(e)){this.matcher.push(Object.isFunction(c[f])?c[f](e):(new Template(c[f])).evaluate(e));a=a.replace(e[0],"");break}}this.matcher.push("return h.unique(n);\n}");eval(this.matcher.join("\n"));Selector._cache[this.expression]=this.matcher}},compileXPathMatcher:function(){var a=this.expression,b=Selector.patterns,
c=Selector.xpath,d,e;if(Selector._cache[a])this.xpath=Selector._cache[a];else{for(this.matcher=[".//*"];a&&d!=a&&/\S/.test(a);){d=a;for(var f in b)if(e=a.match(b[f])){this.matcher.push(Object.isFunction(c[f])?c[f](e):(new Template(c[f])).evaluate(e));a=a.replace(e[0],"");break}}this.xpath=this.matcher.join("");Selector._cache[this.expression]=this.xpath}},findElements:function(a){a=a||document;if(this.xpath)return document._getElementsByXPath(this.xpath,a);return this.matcher(a)},match:function(a){this.tokens=
[];for(var b=this.expression,c=Selector.patterns,d=Selector.assertions,e,f;b&&e!==b&&/\S/.test(b);){e=b;for(var g in c)if(f=c[g],f=b.match(f))if(d[g])this.tokens.push([g,Object.clone(f)]),b=b.replace(f[0],"");else return this.findElements(document).include(a)}b=!0;for(g=0;d=this.tokens[g];g++)if(c=d[0],d=d[1],!Selector.assertions[c](a,d)){b=!1;break}return b},toString:function(){return this.expression},inspect:function(){return"#<Selector:"+this.expression.inspect()+">"}});
Object.extend(Selector,{_cache:{},xpath:{descendant:"//*",child:"/*",adjacent:"/following-sibling::*[1]",laterSibling:"/following-sibling::*",tagName:function(a){if(a[1]=="*")return"";return"[local-name()='"+a[1].toLowerCase()+"' or local-name()='"+a[1].toUpperCase()+"']"},className:"[contains(concat(' ', @class, ' '), ' #{1} ')]",id:"[@id='#{1}']",attrPresence:function(a){a[1]=a[1].toLowerCase();return(new Template("[@#{1}]")).evaluate(a)},attr:function(a){a[1]=a[1].toLowerCase();a[3]=a[5]||a[6];
return(new Template(Selector.xpath.operators[a[2]])).evaluate(a)},pseudo:function(a){var b=Selector.xpath.pseudos[a[1]];if(!b)return"";if(Object.isFunction(b))return b(a);return(new Template(Selector.xpath.pseudos[a[1]])).evaluate(a)},operators:{"=":"[@#{1}='#{3}']","!=":"[@#{1}!='#{3}']","^=":"[starts-with(@#{1}, '#{3}')]","$=":"[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']","*=":"[contains(@#{1}, '#{3}')]","~=":"[contains(concat(' ', @#{1}, ' '), ' #{3} ')]","|=":"[contains(concat('-', @#{1}, '-'), '-#{3}-')]"},
pseudos:{"first-child":"[not(preceding-sibling::*)]","last-child":"[not(following-sibling::*)]","only-child":"[not(preceding-sibling::* or following-sibling::*)]",empty:"[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",checked:"[@checked]",disabled:"[@disabled]",enabled:"[not(@disabled)]",not:function(a){for(var b=a[6],c=Selector.patterns,d=Selector.xpath,e,f,g=[];b&&e!=b&&/\S/.test(b);){e=b;for(var h in c)if(a=b.match(c[h])){f=Object.isFunction(d[h])?d[h](a):(new Template(d[h])).evaluate(a);
g.push("("+f.substring(1,f.length-1)+")");b=b.replace(a[0],"");break}}return"[not("+g.join(" and ")+")]"},"nth-child":function(a){return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ",a)},"nth-last-child":function(a){return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ",a)},"nth-of-type":function(a){return Selector.xpath.pseudos.nth("position() ",a)},"nth-last-of-type":function(a){return Selector.xpath.pseudos.nth("(last() + 1 - position()) ",a)},"first-of-type":function(a){a[6]=
"1";return Selector.xpath.pseudos["nth-of-type"](a)},"last-of-type":function(a){a[6]="1";return Selector.xpath.pseudos["nth-last-of-type"](a)},"only-of-type":function(a){var b=Selector.xpath.pseudos;return b["first-of-type"](a)+b["last-of-type"](a)},nth:function(a,b){var c,d=b[6];d=="even"&&(d="2n+0");d=="odd"&&(d="2n+1");if(c=d.match(/^(\d+)$/))return"["+a+"= "+c[1]+"]";if(c=d.match(/^(-?\d*)?n(([+-])(\d+))?/))return c[1]=="-"&&(c[1]=-1),d=c[1]?Number(c[1]):1,c=c[2]?Number(c[2]):0,(new Template("[((#{fragment} - #{b}) mod #{a} = 0) and ((#{fragment} - #{b}) div #{a} >= 0)]")).evaluate({fragment:a,
a:d,b:c})}}},criteria:{tagName:'n = h.tagName(n, r, "#{1}", c); c = false;',className:'n = h.className(n, r, "#{1}", c); c = false;',id:'n = h.id(n, r, "#{1}", c); c = false;',attrPresence:'n = h.attrPresence(n, r, "#{1}", c); c = false;',attr:function(a){a[3]=a[5]||a[6];return(new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;')).evaluate(a)},pseudo:function(a){a[6]&&(a[6]=a[6].replace(/"/g,'\\"'));return(new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;')).evaluate(a)},
descendant:'c = "descendant";',child:'c = "child";',adjacent:'c = "adjacent";',laterSibling:'c = "laterSibling";'},patterns:{laterSibling:/^\s*~\s*/,child:/^\s*>\s*/,adjacent:/^\s*\+\s*/,descendant:/^\s/,tagName:/^\s*(\*|[\w\-]+)(\b|$)?/,id:/^#([\w\-\*]+)(\b|$)/,className:/^\.([\w\-\*]+)(\b|$)/,pseudo:/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,attrPresence:/^\[([\w]+)\]/,attr:/\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/},
assertions:{tagName:function(a,b){return b[1].toUpperCase()==a.tagName.toUpperCase()},className:function(a,b){return Element.hasClassName(a,b[1])},id:function(a,b){return a.id===b[1]},attrPresence:function(a,b){return Element.hasAttribute(a,b[1])},attr:function(a,b){var c=Element.readAttribute(a,b[1]);return c&&Selector.operators[b[2]](c,b[5]||b[6])}},handlers:{concat:function(a,b){for(var c=0,d;d=b[c];c++)a.push(d);return a},mark:function(a){for(var b=Prototype.emptyFunction,c=0,d;d=a[c];c++)d._countedByPrototype=
b;return a},unmark:function(a){for(var b=0,c;c=a[b];b++)c._countedByPrototype=void 0;return a},index:function(a,b,c){a._countedByPrototype=Prototype.emptyFunction;if(b)for(var a=a.childNodes,b=a.length-1,d=1;b>=0;b--){var e=a[b];if(e.nodeType==1&&(!c||e._countedByPrototype))e.nodeIndex=d++}else{b=0;d=1;for(a=a.childNodes;e=a[b];b++)if(e.nodeType==1&&(!c||e._countedByPrototype))e.nodeIndex=d++}},unique:function(a){if(a.length==0)return a;for(var b=[],c,d=0,e=a.length;d<e;d++)if(!(c=a[d])._countedByPrototype)c._countedByPrototype=
Prototype.emptyFunction,b.push(Element.extend(c));return Selector.handlers.unmark(b)},descendant:function(a){for(var b=Selector.handlers,c=0,d=[],e;e=a[c];c++)b.concat(d,e.getElementsByTagName("*"));return d},child:function(a){for(var b=0,c=[],d;d=a[b];b++)for(var e=0,f;f=d.childNodes[e];e++)f.nodeType==1&&f.tagName!="!"&&c.push(f);return c},adjacent:function(a){for(var b=0,c=[],d;d=a[b];b++)(d=this.nextElementSibling(d))&&c.push(d);return c},laterSibling:function(a){for(var b=Selector.handlers,c=
0,d=[],e;e=a[c];c++)b.concat(d,Element.nextSiblings(e));return d},nextElementSibling:function(a){for(;a=a.nextSibling;)if(a.nodeType==1)return a;return null},previousElementSibling:function(a){for(;a=a.previousSibling;)if(a.nodeType==1)return a;return null},tagName:function(a,b,c,d){var e=c.toUpperCase(),f=[],g=Selector.handlers;if(a){if(d){if(d=="descendant"){for(b=0;d=a[b];b++)g.concat(f,d.getElementsByTagName(c));return f}else a=this[d](a);if(c=="*")return a}for(b=0;d=a[b];b++)d.tagName.toUpperCase()===
e&&f.push(d);return f}else return b.getElementsByTagName(c)},id:function(a,b,c,d){var c=$(c),e=Selector.handlers;if(!c)return[];if(!a&&b==document)return[c];if(a){if(d)if(d=="child")for(b=0;d=a[b];b++){if(c.parentNode==d)return[c]}else if(d=="descendant")for(b=0;d=a[b];b++){if(Element.descendantOf(c,d))return[c]}else if(d=="adjacent")for(b=0;d=a[b];b++){if(Selector.handlers.previousElementSibling(c)==d)return[c]}else a=e[d](a);for(b=0;d=a[b];b++)if(d==c)return[c];return[]}return c&&Element.descendantOf(c,
b)?[c]:[]},className:function(a,b,c,d){a&&d&&(a=this[d](a));return Selector.handlers.byClassName(a,b,c)},byClassName:function(a,b,c){a||(a=Selector.handlers.descendant([b]));for(var b=" "+c+" ",d=0,e=[],f,g;f=a[d];d++)g=f.className,g.length!=0&&(g==c||(" "+g+" ").include(b))&&e.push(f);return e},attrPresence:function(a,b,c,d){a||(a=b.getElementsByTagName("*"));a&&d&&(a=this[d](a));for(var b=[],d=0,e;e=a[d];d++)Element.hasAttribute(e,c)&&b.push(e);return b},attr:function(a,b,c,d,e,f){a||(a=b.getElementsByTagName("*"));
a&&f&&(a=this[f](a));for(var b=Selector.operators[e],e=[],f=0,g;g=a[f];f++){var h=Element.readAttribute(g,c);h!==null&&b(h,d)&&e.push(g)}return e},pseudo:function(a,b,c,d,e){a&&e&&(a=this[e](a));a||(a=d.getElementsByTagName("*"));return Selector.pseudos[b](a,c,d)}},pseudos:{"first-child":function(a){for(var b=0,c=[],d;d=a[b];b++)Selector.handlers.previousElementSibling(d)||c.push(d);return c},"last-child":function(a){for(var b=0,c=[],d;d=a[b];b++)Selector.handlers.nextElementSibling(d)||c.push(d);
return c},"only-child":function(a){for(var b=Selector.handlers,c=0,d=[],e;e=a[c];c++)!b.previousElementSibling(e)&&!b.nextElementSibling(e)&&d.push(e);return d},"nth-child":function(a,b,c){return Selector.pseudos.nth(a,b,c)},"nth-last-child":function(a,b,c){return Selector.pseudos.nth(a,b,c,!0)},"nth-of-type":function(a,b,c){return Selector.pseudos.nth(a,b,c,!1,!0)},"nth-last-of-type":function(a,b,c){return Selector.pseudos.nth(a,b,c,!0,!0)},"first-of-type":function(a,b,c){return Selector.pseudos.nth(a,
"1",c,!1,!0)},"last-of-type":function(a,b,c){return Selector.pseudos.nth(a,"1",c,!0,!0)},"only-of-type":function(a,b,c){var d=Selector.pseudos;return d["last-of-type"](d["first-of-type"](a,b,c),b,c)},getIndices:function(a,b,c){if(a==0)return b>0?[b]:[];return $R(1,c).inject([],function(c,e){0==(e-b)%a&&(e-b)/a>=0&&c.push(e);return c})},nth:function(a,b,c,d,e){if(a.length==0)return[];b=="even"&&(b="2n+0");b=="odd"&&(b="2n+1");var c=Selector.handlers,f=[],g=[],h;c.mark(a);h=0;for(var i;i=a[h];h++)i.parentNode._countedByPrototype||
(c.index(i.parentNode,d,e),g.push(i.parentNode));if(b.match(/^\d+$/)){b=Number(b);for(h=0;i=a[h];h++)i.nodeIndex==b&&f.push(i)}else if(h=b.match(/^(-?\d*)?n(([+-])(\d+))?/)){h[1]=="-"&&(h[1]=-1);b=Selector.pseudos.getIndices(h[1]?Number(h[1]):1,h[2]?Number(h[2]):0,a.length);h=0;for(d=b.length;i=a[h];h++)for(e=0;e<d;e++)i.nodeIndex==b[e]&&f.push(i)}c.unmark(a);c.unmark(g);return f},empty:function(a){for(var b=0,c=[],d;d=a[b];b++)d.tagName=="!"||d.firstChild&&!d.innerHTML.match(/^\s*$/)||c.push(d);
return c},not:function(a,b,c){var d=Selector.handlers,b=(new Selector(b)).findElements(c);d.mark(b);for(var c=0,e=[],f;f=a[c];c++)f._countedByPrototype||e.push(f);d.unmark(b);return e},enabled:function(a){for(var b=0,c=[],d;d=a[b];b++)d.disabled||c.push(d);return c},disabled:function(a){for(var b=0,c=[],d;d=a[b];b++)d.disabled&&c.push(d);return c},checked:function(a){for(var b=0,c=[],d;d=a[b];b++)d.checked&&c.push(d);return c}},operators:{"=":function(a,b){return a==b},"!=":function(a,b){return a!=
b},"^=":function(a,b){return a.startsWith(b)},"$=":function(a,b){return a.endsWith(b)},"*=":function(a,b){return a.include(b)},"~=":function(a,b){return(" "+a+" ").include(" "+b+" ")},"|=":function(a,b){return("-"+a.toUpperCase()+"-").include("-"+b.toUpperCase()+"-")}},split:function(a){var b=[];a.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/,function(a){b.push(a[1].strip())});return b},matchElements:function(a,b){var c=$$(b),d=Selector.handlers;d.mark(c);for(var e=0,f=[],g;g=a[e];e++)g._countedByPrototype&&
f.push(g);d.unmark(c);return f},findElement:function(a,b,c){Object.isNumber(b)&&(c=b,b=!1);return Selector.matchElements(a,b||"*")[c||0]},findChildElements:function(a,b){for(var b=Selector.split(b.join(",")),c=[],d=Selector.handlers,e=0,f=b.length,g;e<f;e++)g=new Selector(b[e].strip()),d.concat(c,g.findElements(a));return f>1?d.unique(c):c}});
Prototype.Browser.IE&&Object.extend(Selector.handlers,{concat:function(a,b){for(var c=0,d;d=b[c];c++)d.tagName!=="!"&&a.push(d);return a},unmark:function(a){for(var b=0,c;c=a[b];b++)c.removeAttribute("_countedByPrototype");return a}});function $$(){return Selector.findChildElements(document,$A(arguments))}
var Form={reset:function(a){$(a).reset();return a},serializeElements:function(a,b){if(typeof b!="object")b={hash:!!b};else if(Object.isUndefined(b.hash))b.hash=!0;var c,d,e=!1,f=b.submit,g=a.inject({},function(a,b){if(!b.disabled&&b.name&&(c=b.name,d=$(b).getValue(),d!=null&&(b.type!="submit"||!e&&f!==!1&&(!f||c==f)&&(e=!0))))c in a?(Object.isArray(a[c])||(a[c]=[a[c]]),a[c].push(d)):a[c]=d;return a});return b.hash?g:Object.toQueryString(g)}};
Form.Methods={serialize:function(a,b){return Form.serializeElements(Form.getElements(a),b)},getElements:function(a){return $A($(a).getElementsByTagName("*")).inject([],function(a,c){Form.Element.Serializers[c.tagName.toLowerCase()]&&a.push(Element.extend(c));return a})},getInputs:function(a,b,c){a=$(a);a=a.getElementsByTagName("input");if(!b&&!c)return $A(a).map(Element.extend);for(var d=0,e=[],f=a.length;d<f;d++){var g=a[d];b&&g.type!=b||c&&g.name!=c||e.push(Element.extend(g))}return e},disable:function(a){a=
$(a);Form.getElements(a).invoke("disable");return a},enable:function(a){a=$(a);Form.getElements(a).invoke("enable");return a},findFirstElement:function(a){var a=$(a).getElements().findAll(function(a){return"hidden"!=a.type&&!a.disabled}),b=a.findAll(function(a){return a.hasAttribute("tabIndex")&&a.tabIndex>=0}).sortBy(function(a){return a.tabIndex}).first();return b?b:a.find(function(a){return["input","select","textarea"].include(a.tagName.toLowerCase())})},focusFirstElement:function(a){a=$(a);a.findFirstElement().activate();
return a},request:function(a,b){var a=$(a),b=Object.clone(b||{}),c=b.parameters,d=a.readAttribute("action")||"";if(d.blank())d=window.location.href;b.parameters=a.serialize(!0);c&&(Object.isString(c)&&(c=c.toQueryParams()),Object.extend(b.parameters,c));if(a.hasAttribute("method")&&!b.method)b.method=a.method;return new Ajax.Request(d,b)}};Form.Element={focus:function(a){$(a).focus();return a},select:function(a){$(a).select();return a}};
Form.Element.Methods={serialize:function(a){a=$(a);if(!a.disabled&&a.name){var b=a.getValue();if(b!=void 0){var c={};c[a.name]=b;return Object.toQueryString(c)}}return""},getValue:function(a){var a=$(a),b=a.tagName.toLowerCase();return Form.Element.Serializers[b](a)},setValue:function(a,b){var a=$(a),c=a.tagName.toLowerCase();Form.Element.Serializers[c](a,b);return a},clear:function(a){$(a).value="";return a},present:function(a){return $(a).value!=""},activate:function(a){a=$(a);try{a.focus(),a.select&&
(a.tagName.toLowerCase()!="input"||!["button","reset","submit"].include(a.type))&&a.select()}catch(b){}return a},disable:function(a){a=$(a);a.blur();a.disabled=!0;return a},enable:function(a){a=$(a);a.disabled=!1;return a}};var Field=Form.Element,$F=Form.Element.Methods.getValue;
Form.Element.Serializers={input:function(a,b){switch(a.type.toLowerCase()){case "checkbox":case "radio":return Form.Element.Serializers.inputSelector(a,b);default:return Form.Element.Serializers.textarea(a,b)}},inputSelector:function(a,b){if(Object.isUndefined(b))return a.checked?a.value:null;else a.checked=!!b},textarea:function(a,b){if(Object.isUndefined(b))return a.value;else a.value=b},select:function(a,b){if(Object.isUndefined(b))return this[a.type=="select-one"?"selectOne":"selectMany"](a);
else for(var c,d,e=!Object.isArray(b),f=0,g=a.length;f<g;f++)if(c=a.options[f],d=this.optionValue(c),e){if(d==b){c.selected=!0;break}}else c.selected=b.include(d)},selectOne:function(a){var b=a.selectedIndex;return b>=0?this.optionValue(a.options[b]):null},selectMany:function(a){var b,c=a.length;if(!c)return null;var d=0;for(b=[];d<c;d++){var e=a.options[d];e.selected&&b.push(this.optionValue(e))}return b},optionValue:function(a){return Element.extend(a).hasAttribute("value")?a.value:a.text}};
Abstract.TimedObserver=Class.create(PeriodicalExecuter,{initialize:function($super,b,c,d){$super(d,c);this.element=$(b);this.lastValue=this.getValue()},execute:function(){var a=this.getValue();if(Object.isString(this.lastValue)&&Object.isString(a)?this.lastValue!=a:String(this.lastValue)!=String(a))this.callback(this.element,a),this.lastValue=a}});Form.Element.Observer=Class.create(Abstract.TimedObserver,{getValue:function(){return Form.Element.getValue(this.element)}});
Form.Observer=Class.create(Abstract.TimedObserver,{getValue:function(){return Form.serialize(this.element)}});
Abstract.EventObserver=Class.create({initialize:function(a,b){this.element=$(a);this.callback=b;this.lastValue=this.getValue();this.element.tagName.toLowerCase()=="form"?this.registerFormCallbacks():this.registerCallback(this.element)},onElementEvent:function(){var a=this.getValue();if(this.lastValue!=a)this.callback(this.element,a),this.lastValue=a},registerFormCallbacks:function(){Form.getElements(this.element).each(this.registerCallback,this)},registerCallback:function(a){if(a.type)switch(a.type.toLowerCase()){case "checkbox":case "radio":Event.observe(a,
"click",this.onElementEvent.bind(this));break;default:Event.observe(a,"change",this.onElementEvent.bind(this))}}});Form.Element.EventObserver=Class.create(Abstract.EventObserver,{getValue:function(){return Form.Element.getValue(this.element)}});Form.EventObserver=Class.create(Abstract.EventObserver,{getValue:function(){return Form.serialize(this.element)}});if(!window.Event)var Event={};
Object.extend(Event,{KEY_BACKSPACE:8,KEY_TAB:9,KEY_RETURN:13,KEY_ESC:27,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_DELETE:46,KEY_HOME:36,KEY_END:35,KEY_PAGEUP:33,KEY_PAGEDOWN:34,KEY_INSERT:45,cache:{},relatedTarget:function(a){switch(a.type){case "mouseover":a=a.fromElement;break;case "mouseout":a=a.toElement;break;default:return null}return Element.extend(a)}});
Event.Methods=function(){var a;if(Prototype.Browser.IE){var b={0:1,1:4,2:2};a=function(a,d){return a.button==b[d]}}else a=Prototype.Browser.WebKit?function(a,b){switch(b){case 0:return a.which==1&&!a.metaKey;case 1:return a.which==1&&a.metaKey;default:return!1}}:function(a,b){return a.which?a.which===b+1:a.button===b};return{isLeftClick:function(b){return a(b,0)},isMiddleClick:function(b){return a(b,1)},isRightClick:function(b){return a(b,2)},element:function(a){a=Event.extend(a).target;return Element.extend(a.nodeType==
Node.TEXT_NODE?a.parentNode:a)},findElement:function(a,b){var e=Event.element(a);if(!b)return e;e=[e].concat(e.ancestors());return Selector.findElement(e,b,0)},pointer:function(a){return{x:a.pageX||a.clientX+(document.documentElement.scrollLeft||document.body.scrollLeft),y:a.pageY||a.clientY+(document.documentElement.scrollTop||document.body.scrollTop)}},pointerX:function(a){return Event.pointer(a).x},pointerY:function(a){return Event.pointer(a).y},stop:function(a){Event.extend(a);a.preventDefault();
a.stopPropagation();a.stopped=!0}}}();
Event.extend=function(){var a=Object.keys(Event.Methods).inject({},function(a,c){a[c]=Event.Methods[c].methodize();return a});return Prototype.Browser.IE?(Object.extend(a,{stopPropagation:function(){this.cancelBubble=!0},preventDefault:function(){this.returnValue=!1},inspect:function(){return"[object Event]"}}),function(b){if(!b)return!1;if(b._extendedByPrototype)return b;b._extendedByPrototype=Prototype.emptyFunction;var c=Event.pointer(b);Object.extend(b,{target:b.srcElement,relatedTarget:Event.relatedTarget(b),
pageX:c.x,pageY:c.y});return Object.extend(b,a)}):(Event.prototype=Event.prototype||document.createEvent("HTMLEvents").__proto__,Object.extend(Event.prototype,a),Prototype.K)}();
Object.extend(Event,function(){function a(a){if(a._prototypeEventID)return a._prototypeEventID[0];arguments.callee.id=arguments.callee.id||1;return a._prototypeEventID=[++arguments.callee.id]}function b(a){if(a&&a.include(":"))return"dataavailable";return a}function c(a,b){var c=h[a]=h[a]||{};return c[b]=c[b]||[]}function d(b,d,e){var f=a(b),f=c(f,d);if(f.pluck("handler").include(e))return!1;var g=function(a){if(!Event||!Event.extend||a.eventName&&a.eventName!=d)return!1;Event.extend(a);e.call(b,
a)};g.handler=e;f.push(g);return g}function e(a,b,d){return c(a,b).find(function(a){return a.handler==d})}function f(a,b,c){var d=h[a]=h[a]||{};if(!d[b])return!1;d[b]=d[b].without(e(a,b,c))}function g(){for(var a in h)for(var b in h[a])h[a][b]=null}var h=Event.cache;window.attachEvent&&window.attachEvent("onunload",g);return{observe:function(a,c,e){var a=$(a),f=b(c),c=d(a,c,e);if(!c)return a;a.addEventListener?a.addEventListener(f,c,!1):a.attachEvent("on"+f,c);return a},stopObserving:function(d,g,
l){var d=$(d),j=a(d),n=b(g);if(!l&&g)return c(j,g).each(function(a){d.stopObserving(g,a.handler)}),d;else if(!g)return Object.keys(h[j]=h[j]||{}).each(function(a){d.stopObserving(a)}),d;var m=e(j,g,l);if(!m)return d;d.removeEventListener?d.removeEventListener(n,m,!1):d.detachEvent("on"+n,m);f(j,g,l);return d},fire:function(a,b,c){a=$(a);if(a==document&&document.createEvent&&!a.dispatchEvent)a=document.documentElement;var d;document.createEvent?(d=document.createEvent("HTMLEvents"),d.initEvent("dataavailable",
!0,!0)):(d=document.createEventObject(),d.eventType="ondataavailable");d.eventName=b;d.memo=c||{};document.createEvent?a.dispatchEvent(d):a.fireEvent(d.eventType,d);return Event.extend(d)}}}());Object.extend(Event,Event.Methods);Element.addMethods({fire:Event.fire,observe:Event.observe,stopObserving:Event.stopObserving});Object.extend(document,{fire:Element.Methods.fire.methodize(),observe:Element.Methods.observe.methodize(),stopObserving:Element.Methods.stopObserving.methodize(),loaded:!1});
(function(){function a(){if(!document.loaded)b&&window.clearInterval(b),document.fire("dom:loaded"),document.loaded=!0}var b;document.addEventListener?Prototype.Browser.WebKit?(b=window.setInterval(function(){/loaded|complete/.test(document.readyState)&&a()},0),Event.observe(window,"load",a)):document.addEventListener("DOMContentLoaded",a,!1):(document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>"),$("__onDOMContentLoaded").onreadystatechange=function(){if(this.readyState=="complete")this.onreadystatechange=
null,a()})})();Hash.toQueryString=Object.toQueryString;var Toggle={display:Element.toggle};Element.Methods.childOf=Element.Methods.descendantOf;
var Insertion={Before:function(a,b){return Element.insert(a,{before:b})},Top:function(a,b){return Element.insert(a,{top:b})},Bottom:function(a,b){return Element.insert(a,{bottom:b})},After:function(a,b){return Element.insert(a,{after:b})}},$continue=Error('"throw $continue" is deprecated, use "return" instead'),Position={includeScrollOffsets:!1,prepare:function(){this.deltaX=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;this.deltaY=window.pageYOffset||document.documentElement.scrollTop||
document.body.scrollTop||0},within:function(a,b,c){if(this.includeScrollOffsets)return this.withinIncludingScrolloffsets(a,b,c);this.xcomp=b;this.ycomp=c;this.offset=Element.cumulativeOffset(a);return c>=this.offset[1]&&c<this.offset[1]+a.offsetHeight&&b>=this.offset[0]&&b<this.offset[0]+a.offsetWidth},withinIncludingScrolloffsets:function(a,b,c){var d=Element.cumulativeScrollOffset(a);this.xcomp=b+d[0]-this.deltaX;this.ycomp=c+d[1]-this.deltaY;this.offset=Element.cumulativeOffset(a);return this.ycomp>=
this.offset[1]&&this.ycomp<this.offset[1]+a.offsetHeight&&this.xcomp>=this.offset[0]&&this.xcomp<this.offset[0]+a.offsetWidth},overlap:function(a,b){if(!a)return 0;if(a=="vertical")return(this.offset[1]+b.offsetHeight-this.ycomp)/b.offsetHeight;if(a=="horizontal")return(this.offset[0]+b.offsetWidth-this.xcomp)/b.offsetWidth},cumulativeOffset:Element.Methods.cumulativeOffset,positionedOffset:Element.Methods.positionedOffset,absolutize:function(a){Position.prepare();return Element.absolutize(a)},relativize:function(a){Position.prepare();
return Element.relativize(a)},realOffset:Element.Methods.cumulativeScrollOffset,offsetParent:Element.Methods.getOffsetParent,page:Element.Methods.viewportOffset,clone:function(a,b,c){c=c||{};return Element.clonePosition(b,a,c)}};
if(!document.getElementsByClassName)document.getElementsByClassName=function(a){function b(a){return a.blank()?null:"[contains(concat(' ', @class, ' '), ' "+a+" ')]"}a.getElementsByClassName=Prototype.BrowserFeatures.XPath?function(a,d){var d=d.toString().strip(),e=/\s/.test(d)?$w(d).map(b).join(""):b(d);return e?document._getElementsByXPath(".//*"+e,a):[]}:function(a,b){var b=b.toString().strip(),e=[],f=/\s/.test(b)?$w(b):null;if(!f&&!b)return e;for(var g=$(a).getElementsByTagName("*"),b=" "+b+" ",
h=0,i,k;i=g[h];h++)i.className&&(k=" "+i.className+" ")&&(k.include(b)||f&&f.all(function(a){return!a.toString().blank()&&k.include(" "+a+" ")}))&&e.push(Element.extend(i));return e};return function(a,b){return $(b||document.body).getElementsByClassName(a)}}(Element.Methods);Element.ClassNames=Class.create();
Element.ClassNames.prototype={initialize:function(a){this.element=$(a)},_each:function(a){this.element.className.split(/\s+/).select(function(a){return a.length>0})._each(a)},set:function(a){this.element.className=a},add:function(a){this.include(a)||this.set($A(this).concat(a).join(" "))},remove:function(a){this.include(a)&&this.set($A(this).without(a).join(" "))},toString:function(){return $A(this).join(" ")}};Object.extend(Element.ClassNames.prototype,Enumerable);Element.addMethods();
@@ -0,0 +1,167 @@
// add Prototype.js library
document.write("<script src=\"prototype-min.js\" type=\"text/javascript\"></script>");
// add Box2D.js library
document.write("<script src=\"box2d-min.js\" type=\"text/javascript\"></script>");
// event handler called once document has loaded ..
window.onload = function () {
tryFindSketch();
}
// try to get the sketch instance from Processing.js
function tryFindSketch () {
var sketch = Processing.instances[0];
if ( sketch == undefined )
return setTimeout( tryFindSketch, 200 ); // retry
var inter = new Box2DJSInterface(sketch);
sketch.setBox2DInterface(inter);
}
/**
* This is just a tiny simple wrapper to get you started ...
* ... or spawn an idea.
*
* Based on Ando Yasushi example code.
*/
var Box2DJSInterface = (function() {
function Box2DJSInterface () {
if ( arguments.length <= 0 || typeof arguments[0] !== 'object' ) {
alert('You need to pass a Processing instance in here!');
return undefined;
}
var world = createWorld();
createGround(world);
createBox(world, null, -10, 125, 10, 250 );
createBox(world, null, 510, 125, 10, 250 );
var sketch = arguments[0];
this.update = function () {
world.Step( 1/60.0, 1.0 );
}
this.draw = function () {
this.drawJoints();
this.drawShapes();
}
this.drawJoints = function () {
for (var j = world.m_jointList; j; j = j.m_next) {
var b1 = j.m_body1;
var b2 = j.m_body2;
var x1 = b1.m_position;
var x2 = b2.m_position;
var p1 = j.GetAnchor1();
var p2 = j.GetAnchor2();
switch (j.m_type) {
case b2Joint.e_distanceJoint:
sketch.drawJoint(p1.x, p1.y, p2.x, p2.y);
break;
case b2Joint.e_pulleyJoint:
// TODO
break;
default:
if (b1 == world.m_groundBody) {
sketch.drawJoint([p1.x, p1.y, x2.x, x2.y]);
}
else if (b2 == world.m_groundBody) {
sketch.drawJoint([p1.x, p1.y, x1.x, x1.y]);
}
else {
sketch.drawJoint([x1.x, x1.y, p1.x, p1.y, x2.x, x2.y, p2.x, p2.y]);
}
break;
}
}
}
this.drawShapes = function () {
for (var b = world.m_bodyList; b; b = b.m_next) {
for (var s = b.GetShapeList(); s != null; s = s.GetNext()) {
switch (s.m_type) {
case b2Shape.e_circleShape:
var pos = s.m_position;
var r = s.m_radius;
sketch.drawCircle(s.GetUserData(),pos.x,pos.y,r);
break;
case b2Shape.e_polyShape:
var tV = b2Math.AddVV( s.m_position,
b2Math.b2MulMV( s.m_R, s.m_vertices[0] ) );
var points = [tV.x, tV.y];
for (var i = 0; i < s.m_vertexCount; i++) {
var v = b2Math.AddVV( s.m_position, b2Math.b2MulMV( s.m_R, s.m_vertices[i] ) );
points[points.length] = v.x;
points[points.length] = v.y;
}
points[points.length] = tV.x;
points[points.length] = tV.y;
sketch.drawPolygon(s.GetUserData(),points);
break;
}
}
}
}
this.createBall = function ( c, x, y, r ) {
createBall( world, c, x, y, r );
}
this.createBox = function ( c, x, y, w, h ) {
createBox( world, c, x, y, w, h, false );
}
}
var createWorld = function () {
var worldAABB = new b2AABB();
worldAABB.minVertex.Set(-1000, -1000);
worldAABB.maxVertex.Set(1000, 1000);
var gravity = new b2Vec2(0, 300);
var doSleep = true;
var world = new b2World(worldAABB, gravity, doSleep);
return world;
}
var createGround = function (world) {
var groundSd = new b2BoxDef();
groundSd.extents.Set(1000, 50);
groundSd.restitution = 0.2;
var groundBd = new b2BodyDef();
groundBd.AddShape(groundSd);
groundBd.position.Set(-500, 350);
return world.CreateBody(groundBd);
}
var createBall = function (world, c, x, y, r) {
var ballSd = new b2CircleDef();
ballSd.density = 2.0;
ballSd.radius = r;
ballSd.restitution = 1.0;
ballSd.friction = 2.0;
ballSd.userData = c;
var ballBd = new b2BodyDef();
ballBd.AddShape(ballSd);
ballBd.position.Set(x, y);
return world.CreateBody(ballBd);
}
var createBox = function (world, c, x, y, width, height, fixed) {
if (typeof(fixed) == 'undefined') fixed = true;
var boxSd = new b2BoxDef();
boxSd.userData = c;
if (!fixed) boxSd.density = 1.0;
boxSd.extents.Set(width, height);
var boxBd = new b2BodyDef();
boxBd.AddShape(boxSd);
boxBd.position.Set(x, y);
return world.CreateBody(boxBd);
}
return Box2DJSInterface;
})();
@@ -0,0 +1,128 @@
/**
* A Box2D (by Erin Catto) example based on a port and examples by Ando Yasushi. <br />
* Click & drag to create balls, hold alt/option to create boxes. <br />
*
* <ul>
* <li>Erin Catto http://code.google.com/p/box2d/</li>
* <li>Ando Yasushi http://box2d-js.sourceforge.net/</li>
* </ul>
*/
/**
* Note that this uses a rather old port of a (ActionScript) Box2D library.
*/
Box2DInterface b2d;
void setup ()
{
size( 500, 300 );
colorMode(HSB);
}
void draw ()
{
background( 100 );
if ( isDragged )
{
if ( !keyPressed )
{
float d = dist(mouseX,mouseY,pressedX,pressedY)*2;
fill(120);
ellipse( pressedX, pressedY, d, d );
}
else if ( key == CODED && keyCode == ALT )
{
float w = mouseX-pressedX;
float h = mouseY-pressedY;
rect( pressedX-w, pressedY-h, w*2, h*2 );
}
}
if ( b2d != null )
{
b2d.update();
b2d.draw();
}
}
float pressedX, pressedY;
boolean isDragged = false;
void mousePressed ()
{
pressedX = mouseX; pressedY = mouseY;
isDragged = false;
}
void mouseDragged ()
{
isDragged = true;
}
void mouseReleased ()
{
color rc = color(random(255), 190, 140);
if ( !keyPressed )
{
if ( !isDragged )
b2d.createBall( rc, mouseX, mouseY, 20 );
else
b2d.createBall( rc, pressedX,pressedY, dist(mouseX,mouseY,pressedX,pressedY) );
}
else if ( key == CODED && keyCode == ALT )
{
if ( !isDragged )
b2d.createBox( rc, mouseX-20, mouseY-20, 40, 40 );
else
{
b2d.createBox( rc, pressedX,pressedY, mouseX-pressedX, mouseY-pressedY );
}
}
isDragged = false;
}
// these three drawing functions are being called by the
// Box2D interface in the .js tab
void drawJoints ( float[] points )
{
for ( int i = 0; i < points.length-2; i+=2 )
line( points[i], points[i+1], points[i+2], points[i+3] );
}
void drawPolygon ( color c, float[] points )
{
fill( c == null ? 255 : c );
noStroke();
beginShape();
for ( int i = 0; i < points.length; i+=2 )
vertex( points[i], points[i+1] );
endShape();
}
void drawCircle ( color c, float x, float y, float r )
{
fill( c == null ? 255 : c );
noStroke();
ellipse( x, y, r*2, r*2 );
}
// this is being called from JavaScript to set the Box2D interface
void setBox2DInterface ( Box2DInterface b )
{
b2d = b;
}
// explain Processing how the interface is set up
interface Box2DInterface
{
void createBall( color c, float x, float y, float r );
void createBox( color c, float x, float y, float w, float h );
void update();
void draw();
}