PageRenderTime 920ms CodeModel.GetById 85ms app.highlight 754ms RepoModel.GetById 1ms app.codeStats 4ms

/js/DemoBox2D/lib/box2d.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 11391 lines | 11391 code | 0 blank | 0 comment | 1150 complexity | cedefc0fd03aee7b397915de02ca05e6 MD5 | raw file
    1function extend(a, b) {
    2  for(var c in b) {
    3    a[c] = b[c]
    4  }
    5}
    6function isInstanceOf(obj, _constructor) {
    7  while(typeof obj === "object") {
    8    if(obj.constructor === _constructor) {
    9      return true
   10    }
   11    obj = obj._super
   12  }
   13  return false
   14}
   15;var b2BoundValues = function() {
   16  this.__varz();
   17  this.__constructor.apply(this, arguments)
   18};
   19b2BoundValues.prototype.__constructor = function() {
   20  this.lowerValues = new Array;
   21  this.lowerValues[0] = 0;
   22  this.lowerValues[1] = 0;
   23  this.upperValues = new Array;
   24  this.upperValues[0] = 0;
   25  this.upperValues[1] = 0
   26};
   27b2BoundValues.prototype.__varz = function() {
   28};
   29b2BoundValues.prototype.lowerValues = null;
   30b2BoundValues.prototype.upperValues = null;var b2PairManager = function() {
   31  this.__varz();
   32  this.__constructor.apply(this, arguments)
   33};
   34b2PairManager.prototype.__constructor = function() {
   35  this.m_pairs = new Array;
   36  this.m_pairBuffer = new Array;
   37  this.m_pairCount = 0;
   38  this.m_pairBufferCount = 0;
   39  this.m_freePair = null
   40};
   41b2PairManager.prototype.__varz = function() {
   42};
   43b2PairManager.prototype.AddPair = function(proxy1, proxy2) {
   44  var pair = proxy1.pairs[proxy2];
   45  if(pair != null) {
   46    return pair
   47  }
   48  if(this.m_freePair == null) {
   49    this.m_freePair = new b2Pair;
   50    this.m_pairs.push(this.m_freePair)
   51  }
   52  pair = this.m_freePair;
   53  this.m_freePair = pair.next;
   54  pair.proxy1 = proxy1;
   55  pair.proxy2 = proxy2;
   56  pair.status = 0;
   57  pair.userData = null;
   58  pair.next = null;
   59  proxy1.pairs[proxy2] = pair;
   60  proxy2.pairs[proxy1] = pair;
   61  ++this.m_pairCount;
   62  return pair
   63};
   64b2PairManager.prototype.RemovePair = function(proxy1, proxy2) {
   65  var pair = proxy1.pairs[proxy2];
   66  if(pair == null) {
   67    return null
   68  }
   69  var userData = pair.userData;
   70  delete proxy1.pairs[proxy2];
   71  delete proxy2.pairs[proxy1];
   72  pair.next = this.m_freePair;
   73  pair.proxy1 = null;
   74  pair.proxy2 = null;
   75  pair.userData = null;
   76  pair.status = 0;
   77  this.m_freePair = pair;
   78  --this.m_pairCount;
   79  return userData
   80};
   81b2PairManager.prototype.Find = function(proxy1, proxy2) {
   82  return proxy1.pairs[proxy2]
   83};
   84b2PairManager.prototype.ValidateBuffer = function() {
   85};
   86b2PairManager.prototype.ValidateTable = function() {
   87};
   88b2PairManager.prototype.Initialize = function(broadPhase) {
   89  this.m_broadPhase = broadPhase
   90};
   91b2PairManager.prototype.AddBufferedPair = function(proxy1, proxy2) {
   92  var pair = this.AddPair(proxy1, proxy2);
   93  if(pair.IsBuffered() == false) {
   94    pair.SetBuffered();
   95    this.m_pairBuffer[this.m_pairBufferCount] = pair;
   96    ++this.m_pairBufferCount
   97  }
   98  pair.ClearRemoved();
   99  if(b2BroadPhase.s_validate) {
  100    this.ValidateBuffer()
  101  }
  102};
  103b2PairManager.prototype.RemoveBufferedPair = function(proxy1, proxy2) {
  104  var pair = this.Find(proxy1, proxy2);
  105  if(pair == null) {
  106    return
  107  }
  108  if(pair.IsBuffered() == false) {
  109    pair.SetBuffered();
  110    this.m_pairBuffer[this.m_pairBufferCount] = pair;
  111    ++this.m_pairBufferCount
  112  }
  113  pair.SetRemoved();
  114  if(b2BroadPhase.s_validate) {
  115    this.ValidateBuffer()
  116  }
  117};
  118b2PairManager.prototype.Commit = function(callback) {
  119  var i = 0;
  120  var removeCount = 0;
  121  for(i = 0;i < this.m_pairBufferCount;++i) {
  122    var pair = this.m_pairBuffer[i];
  123    pair.ClearBuffered();
  124    var proxy1 = pair.proxy1;
  125    var proxy2 = pair.proxy2;
  126    if(pair.IsRemoved()) {
  127    }else {
  128      if(pair.IsFinal() == false) {
  129        callback(proxy1.userData, proxy2.userData)
  130      }
  131    }
  132  }
  133  this.m_pairBufferCount = 0;
  134  if(b2BroadPhase.s_validate) {
  135    this.ValidateTable()
  136  }
  137};
  138b2PairManager.prototype.m_broadPhase = null;
  139b2PairManager.prototype.m_pairs = null;
  140b2PairManager.prototype.m_freePair = null;
  141b2PairManager.prototype.m_pairCount = 0;
  142b2PairManager.prototype.m_pairBuffer = null;
  143b2PairManager.prototype.m_pairBufferCount = 0;var b2TimeStep = function() {
  144  this.__varz();
  145  this.__constructor.apply(this, arguments)
  146};
  147b2TimeStep.prototype.__constructor = function() {
  148};
  149b2TimeStep.prototype.__varz = function() {
  150};
  151b2TimeStep.prototype.Set = function(step) {
  152  this.dt = step.dt;
  153  this.inv_dt = step.inv_dt;
  154  this.positionIterations = step.positionIterations;
  155  this.velocityIterations = step.velocityIterations;
  156  this.warmStarting = step.warmStarting
  157};
  158b2TimeStep.prototype.dt = null;
  159b2TimeStep.prototype.inv_dt = null;
  160b2TimeStep.prototype.dtRatio = null;
  161b2TimeStep.prototype.velocityIterations = 0;
  162b2TimeStep.prototype.positionIterations = 0;
  163b2TimeStep.prototype.warmStarting = null;var b2Controller = function() {
  164  this.__varz();
  165  this.__constructor.apply(this, arguments)
  166};
  167b2Controller.prototype.__constructor = function() {
  168};
  169b2Controller.prototype.__varz = function() {
  170};
  171b2Controller.prototype.Step = function(step) {
  172};
  173b2Controller.prototype.Draw = function(debugDraw) {
  174};
  175b2Controller.prototype.AddBody = function(body) {
  176  var edge = new b2ControllerEdge;
  177  edge.controller = this;
  178  edge.body = body;
  179  edge.nextBody = m_bodyList;
  180  edge.prevBody = null;
  181  m_bodyList = edge;
  182  if(edge.nextBody) {
  183    edge.nextBody.prevBody = edge
  184  }
  185  m_bodyCount++;
  186  edge.nextController = body.m_controllerList;
  187  edge.prevController = null;
  188  body.m_controllerList = edge;
  189  if(edge.nextController) {
  190    edge.nextController.prevController = edge
  191  }
  192  body.m_controllerCount++
  193};
  194b2Controller.prototype.RemoveBody = function(body) {
  195  var edge = body.m_controllerList;
  196  while(edge && edge.controller != this) {
  197    edge = edge.nextController
  198  }
  199  if(edge.prevBody) {
  200    edge.prevBody.nextBody = edge.nextBody
  201  }
  202  if(edge.nextBody) {
  203    edge.nextBody.prevBody = edge.prevBody
  204  }
  205  if(edge.nextController) {
  206    edge.nextController.prevController = edge.prevController
  207  }
  208  if(edge.prevController) {
  209    edge.prevController.nextController = edge.nextController
  210  }
  211  if(m_bodyList == edge) {
  212    m_bodyList = edge.nextBody
  213  }
  214  if(body.m_controllerList == edge) {
  215    body.m_controllerList = edge.nextController
  216  }
  217  body.m_controllerCount--;
  218  m_bodyCount--
  219};
  220b2Controller.prototype.Clear = function() {
  221  while(m_bodyList) {
  222    this.RemoveBody(m_bodyList.body)
  223  }
  224};
  225b2Controller.prototype.GetNext = function() {
  226  return this.m_next
  227};
  228b2Controller.prototype.GetWorld = function() {
  229  return this.m_world
  230};
  231b2Controller.prototype.GetBodyList = function() {
  232  return m_bodyList
  233};
  234b2Controller.prototype.m_next = null;
  235b2Controller.prototype.m_prev = null;
  236b2Controller.prototype.m_world = null;var b2GravityController = function() {
  237  b2Controller.prototype.__varz.call(this);
  238  this.__varz();
  239  this.__constructor.apply(this, arguments)
  240};
  241extend(b2GravityController.prototype, b2Controller.prototype);
  242b2GravityController.prototype._super = b2Controller.prototype;
  243b2GravityController.prototype.__constructor = function() {
  244  this._super.__constructor.apply(this, arguments)
  245};
  246b2GravityController.prototype.__varz = function() {
  247};
  248b2GravityController.prototype.Step = function(step) {
  249  var i = null;
  250  var body1 = null;
  251  var p1 = null;
  252  var mass1 = 0;
  253  var j = null;
  254  var body2 = null;
  255  var p2 = null;
  256  var dx = 0;
  257  var dy = 0;
  258  var r2 = 0;
  259  var f = null;
  260  if(this.invSqr) {
  261    for(i = m_bodyList;i;i = i.nextBody) {
  262      body1 = i.body;
  263      p1 = body1.GetWorldCenter();
  264      mass1 = body1.GetMass();
  265      for(j = m_bodyList;j != i;j = j.nextBody) {
  266        body2 = j.body;
  267        p2 = body2.GetWorldCenter();
  268        dx = p2.x - p1.x;
  269        dy = p2.y - p1.y;
  270        r2 = dx * dx + dy * dy;
  271        if(r2 < Number.MIN_VALUE) {
  272          continue
  273        }
  274        f = new b2Vec2(dx, dy);
  275        f.Multiply(this.G / r2 / Math.sqrt(r2) * mass1 * body2.GetMass());
  276        if(body1.IsAwake()) {
  277          body1.ApplyForce(f, p1)
  278        }
  279        f.Multiply(-1);
  280        if(body2.IsAwake()) {
  281          body2.ApplyForce(f, p2)
  282        }
  283      }
  284    }
  285  }else {
  286    for(i = m_bodyList;i;i = i.nextBody) {
  287      body1 = i.body;
  288      p1 = body1.GetWorldCenter();
  289      mass1 = body1.GetMass();
  290      for(j = m_bodyList;j != i;j = j.nextBody) {
  291        body2 = j.body;
  292        p2 = body2.GetWorldCenter();
  293        dx = p2.x - p1.x;
  294        dy = p2.y - p1.y;
  295        r2 = dx * dx + dy * dy;
  296        if(r2 < Number.MIN_VALUE) {
  297          continue
  298        }
  299        f = new b2Vec2(dx, dy);
  300        f.Multiply(this.G / r2 * mass1 * body2.GetMass());
  301        if(body1.IsAwake()) {
  302          body1.ApplyForce(f, p1)
  303        }
  304        f.Multiply(-1);
  305        if(body2.IsAwake()) {
  306          body2.ApplyForce(f, p2)
  307        }
  308      }
  309    }
  310  }
  311};
  312b2GravityController.prototype.G = 1;
  313b2GravityController.prototype.invSqr = true;var b2DestructionListener = function() {
  314  this.__varz();
  315  this.__constructor.apply(this, arguments)
  316};
  317b2DestructionListener.prototype.__constructor = function() {
  318};
  319b2DestructionListener.prototype.__varz = function() {
  320};
  321b2DestructionListener.prototype.SayGoodbyeJoint = function(joint) {
  322};
  323b2DestructionListener.prototype.SayGoodbyeFixture = function(fixture) {
  324};var b2ContactEdge = function() {
  325  this.__varz();
  326  this.__constructor.apply(this, arguments)
  327};
  328b2ContactEdge.prototype.__constructor = function() {
  329};
  330b2ContactEdge.prototype.__varz = function() {
  331};
  332b2ContactEdge.prototype.other = null;
  333b2ContactEdge.prototype.contact = null;
  334b2ContactEdge.prototype.prev = null;
  335b2ContactEdge.prototype.next = null;var b2EdgeChainDef = function() {
  336  this.__varz();
  337  this.__constructor.apply(this, arguments)
  338};
  339b2EdgeChainDef.prototype.__constructor = function() {
  340  this.vertexCount = 0;
  341  this.isALoop = true;
  342  this.vertices = []
  343};
  344b2EdgeChainDef.prototype.__varz = function() {
  345};
  346b2EdgeChainDef.prototype.vertices = null;
  347b2EdgeChainDef.prototype.vertexCount = null;
  348b2EdgeChainDef.prototype.isALoop = null;var b2Vec2 = function(x_, y_) {
  349  if(arguments.length == 2) {
  350    this.x = x_;
  351    this.y = y_
  352  }
  353};
  354b2Vec2.Make = function(x_, y_) {
  355  return new b2Vec2(x_, y_)
  356};
  357b2Vec2.prototype.SetZero = function() {
  358  this.x = 0;
  359  this.y = 0
  360};
  361b2Vec2.prototype.Set = function(x_, y_) {
  362  this.x = x_;
  363  this.y = y_
  364};
  365b2Vec2.prototype.SetV = function(v) {
  366  this.x = v.x;
  367  this.y = v.y
  368};
  369b2Vec2.prototype.GetNegative = function() {
  370  return new b2Vec2(-this.x, -this.y)
  371};
  372b2Vec2.prototype.NegativeSelf = function() {
  373  this.x = -this.x;
  374  this.y = -this.y
  375};
  376b2Vec2.prototype.Copy = function() {
  377  return new b2Vec2(this.x, this.y)
  378};
  379b2Vec2.prototype.Add = function(v) {
  380  this.x += v.x;
  381  this.y += v.y
  382};
  383b2Vec2.prototype.Subtract = function(v) {
  384  this.x -= v.x;
  385  this.y -= v.y
  386};
  387b2Vec2.prototype.Multiply = function(a) {
  388  this.x *= a;
  389  this.y *= a
  390};
  391b2Vec2.prototype.MulM = function(A) {
  392  var tX = this.x;
  393  this.x = A.col1.x * tX + A.col2.x * this.y;
  394  this.y = A.col1.y * tX + A.col2.y * this.y
  395};
  396b2Vec2.prototype.MulTM = function(A) {
  397  var tX = b2Math.Dot(this, A.col1);
  398  this.y = b2Math.Dot(this, A.col2);
  399  this.x = tX
  400};
  401b2Vec2.prototype.CrossVF = function(s) {
  402  var tX = this.x;
  403  this.x = s * this.y;
  404  this.y = -s * tX
  405};
  406b2Vec2.prototype.CrossFV = function(s) {
  407  var tX = this.x;
  408  this.x = -s * this.y;
  409  this.y = s * tX
  410};
  411b2Vec2.prototype.MinV = function(b) {
  412  this.x = this.x < b.x ? this.x : b.x;
  413  this.y = this.y < b.y ? this.y : b.y
  414};
  415b2Vec2.prototype.MaxV = function(b) {
  416  this.x = this.x > b.x ? this.x : b.x;
  417  this.y = this.y > b.y ? this.y : b.y
  418};
  419b2Vec2.prototype.Abs = function() {
  420  if(this.x < 0) {
  421    this.x = -this.x
  422  }
  423  if(this.y < 0) {
  424    this.y = -this.y
  425  }
  426};
  427b2Vec2.prototype.Length = function() {
  428  return Math.sqrt(this.x * this.x + this.y * this.y)
  429};
  430b2Vec2.prototype.LengthSquared = function() {
  431  return this.x * this.x + this.y * this.y
  432};
  433b2Vec2.prototype.Normalize = function() {
  434  var length = Math.sqrt(this.x * this.x + this.y * this.y);
  435  if(length < Number.MIN_VALUE) {
  436    return 0
  437  }
  438  var invLength = 1 / length;
  439  this.x *= invLength;
  440  this.y *= invLength;
  441  return length
  442};
  443b2Vec2.prototype.IsValid = function() {
  444  return b2Math.IsValid(this.x) && b2Math.IsValid(this.y)
  445};
  446b2Vec2.prototype.x = 0;
  447b2Vec2.prototype.y = 0;var b2Vec3 = function(x, y, z) {
  448  if(arguments.length == 3) {
  449    this.x = x;
  450    this.y = y;
  451    this.z = z
  452  }
  453};
  454b2Vec3.prototype.SetZero = function() {
  455  this.x = this.y = this.z = 0
  456};
  457b2Vec3.prototype.Set = function(x, y, z) {
  458  this.x = x;
  459  this.y = y;
  460  this.z = z
  461};
  462b2Vec3.prototype.SetV = function(v) {
  463  this.x = v.x;
  464  this.y = v.y;
  465  this.z = v.z
  466};
  467b2Vec3.prototype.GetNegative = function() {
  468  return new b2Vec3(-this.x, -this.y, -this.z)
  469};
  470b2Vec3.prototype.NegativeSelf = function() {
  471  this.x = -this.x;
  472  this.y = -this.y;
  473  this.z = -this.z
  474};
  475b2Vec3.prototype.Copy = function() {
  476  return new b2Vec3(this.x, this.y, this.z)
  477};
  478b2Vec3.prototype.Add = function(v) {
  479  this.x += v.x;
  480  this.y += v.y;
  481  this.z += v.z
  482};
  483b2Vec3.prototype.Subtract = function(v) {
  484  this.x -= v.x;
  485  this.y -= v.y;
  486  this.z -= v.z
  487};
  488b2Vec3.prototype.Multiply = function(a) {
  489  this.x *= a;
  490  this.y *= a;
  491  this.z *= a
  492};
  493b2Vec3.prototype.x = 0;
  494b2Vec3.prototype.y = 0;
  495b2Vec3.prototype.z = 0;var b2DistanceProxy = function() {
  496  this.__varz();
  497  this.__constructor.apply(this, arguments)
  498};
  499b2DistanceProxy.prototype.__constructor = function() {
  500};
  501b2DistanceProxy.prototype.__varz = function() {
  502};
  503b2DistanceProxy.prototype.Set = function(shape) {
  504  switch(shape.GetType()) {
  505    case b2Shape.e_circleShape:
  506      var circle = shape;
  507      this.m_vertices = new Array(1);
  508      this.m_vertices[0] = circle.m_p;
  509      this.m_count = 1;
  510      this.m_radius = circle.m_radius;
  511      break;
  512    case b2Shape.e_polygonShape:
  513      var polygon = shape;
  514      this.m_vertices = polygon.m_vertices;
  515      this.m_count = polygon.m_vertexCount;
  516      this.m_radius = polygon.m_radius;
  517      break;
  518    default:
  519      b2Settings.b2Assert(false)
  520  }
  521};
  522b2DistanceProxy.prototype.GetSupport = function(d) {
  523  var bestIndex = 0;
  524  var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
  525  for(var i = 1;i < this.m_count;++i) {
  526    var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
  527    if(value > bestValue) {
  528      bestIndex = i;
  529      bestValue = value
  530    }
  531  }
  532  return bestIndex
  533};
  534b2DistanceProxy.prototype.GetSupportVertex = function(d) {
  535  var bestIndex = 0;
  536  var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
  537  for(var i = 1;i < this.m_count;++i) {
  538    var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
  539    if(value > bestValue) {
  540      bestIndex = i;
  541      bestValue = value
  542    }
  543  }
  544  return this.m_vertices[bestIndex]
  545};
  546b2DistanceProxy.prototype.GetVertexCount = function() {
  547  return this.m_count
  548};
  549b2DistanceProxy.prototype.GetVertex = function(index) {
  550  b2Settings.b2Assert(0 <= index && index < this.m_count);
  551  return this.m_vertices[index]
  552};
  553b2DistanceProxy.prototype.m_vertices = null;
  554b2DistanceProxy.prototype.m_count = 0;
  555b2DistanceProxy.prototype.m_radius = null;var b2ContactFactory = function() {
  556  this.__varz();
  557  this.__constructor.apply(this, arguments)
  558};
  559b2ContactFactory.prototype.__constructor = function() {
  560};
  561b2ContactFactory.prototype.__varz = function() {
  562  this.InitializeRegisters()
  563};
  564b2ContactFactory.prototype.AddType = function(createFcn, destroyFcn, type1, type2) {
  565  this.m_registers[type1][type2].createFcn = createFcn;
  566  this.m_registers[type1][type2].destroyFcn = destroyFcn;
  567  this.m_registers[type1][type2].primary = true;
  568  if(type1 != type2) {
  569    this.m_registers[type2][type1].createFcn = createFcn;
  570    this.m_registers[type2][type1].destroyFcn = destroyFcn;
  571    this.m_registers[type2][type1].primary = false
  572  }
  573};
  574b2ContactFactory.prototype.InitializeRegisters = function() {
  575  this.m_registers = new Array(b2Shape.e_shapeTypeCount);
  576  for(var i = 0;i < b2Shape.e_shapeTypeCount;i++) {
  577    this.m_registers[i] = new Array(b2Shape.e_shapeTypeCount);
  578    for(var j = 0;j < b2Shape.e_shapeTypeCount;j++) {
  579      this.m_registers[i][j] = new b2ContactRegister
  580    }
  581  }
  582  this.AddType(b2CircleContact.Create, b2CircleContact.Destroy, b2Shape.e_circleShape, b2Shape.e_circleShape);
  583  this.AddType(b2PolyAndCircleContact.Create, b2PolyAndCircleContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_circleShape);
  584  this.AddType(b2PolygonContact.Create, b2PolygonContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_polygonShape);
  585  this.AddType(b2EdgeAndCircleContact.Create, b2EdgeAndCircleContact.Destroy, b2Shape.e_edgeShape, b2Shape.e_circleShape);
  586  this.AddType(b2PolyAndEdgeContact.Create, b2PolyAndEdgeContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_edgeShape)
  587};
  588b2ContactFactory.prototype.Create = function(fixtureA, fixtureB) {
  589  var type1 = fixtureA.GetType();
  590  var type2 = fixtureB.GetType();
  591  var reg = this.m_registers[type1][type2];
  592  var c;
  593  if(reg.pool) {
  594    c = reg.pool;
  595    reg.pool = c.m_next;
  596    reg.poolCount--;
  597    c.Reset(fixtureA, fixtureB);
  598    return c
  599  }
  600  var createFcn = reg.createFcn;
  601  if(createFcn != null) {
  602    if(reg.primary) {
  603      c = createFcn(this.m_allocator);
  604      c.Reset(fixtureA, fixtureB);
  605      return c
  606    }else {
  607      c = createFcn(this.m_allocator);
  608      c.Reset(fixtureB, fixtureA);
  609      return c
  610    }
  611  }else {
  612    return null
  613  }
  614};
  615b2ContactFactory.prototype.Destroy = function(contact) {
  616  if(contact.m_manifold.m_pointCount > 0) {
  617    contact.m_fixtureA.m_body.SetAwake(true);
  618    contact.m_fixtureB.m_body.SetAwake(true)
  619  }
  620  var type1 = contact.m_fixtureA.GetType();
  621  var type2 = contact.m_fixtureB.GetType();
  622  var reg = this.m_registers[type1][type2];
  623  if(true) {
  624    reg.poolCount++;
  625    contact.m_next = reg.pool;
  626    reg.pool = contact
  627  }
  628  var destroyFcn = reg.destroyFcn;
  629  destroyFcn(contact, this.m_allocator)
  630};
  631b2ContactFactory.prototype.m_registers = null;
  632b2ContactFactory.prototype.m_allocator = null;var b2ConstantAccelController = function() {
  633  b2Controller.prototype.__varz.call(this);
  634  this.__varz();
  635  this.__constructor.apply(this, arguments)
  636};
  637extend(b2ConstantAccelController.prototype, b2Controller.prototype);
  638b2ConstantAccelController.prototype._super = b2Controller.prototype;
  639b2ConstantAccelController.prototype.__constructor = function() {
  640  this._super.__constructor.apply(this, arguments)
  641};
  642b2ConstantAccelController.prototype.__varz = function() {
  643  this.A = new b2Vec2(0, 0)
  644};
  645b2ConstantAccelController.prototype.Step = function(step) {
  646  var smallA = new b2Vec2(this.A.x * step.dt, this.A.y * step.dt);
  647  for(var i = m_bodyList;i;i = i.nextBody) {
  648    var body = i.body;
  649    if(!body.IsAwake()) {
  650      continue
  651    }
  652    body.SetLinearVelocity(new b2Vec2(body.GetLinearVelocity().x + smallA.x, body.GetLinearVelocity().y + smallA.y))
  653  }
  654};
  655b2ConstantAccelController.prototype.A = new b2Vec2(0, 0);var b2SeparationFunction = function() {
  656  this.__varz();
  657  this.__constructor.apply(this, arguments)
  658};
  659b2SeparationFunction.prototype.__constructor = function() {
  660};
  661b2SeparationFunction.prototype.__varz = function() {
  662  this.m_localPoint = new b2Vec2;
  663  this.m_axis = new b2Vec2
  664};
  665b2SeparationFunction.e_points = 1;
  666b2SeparationFunction.e_faceA = 2;
  667b2SeparationFunction.e_faceB = 4;
  668b2SeparationFunction.prototype.Initialize = function(cache, proxyA, transformA, proxyB, transformB) {
  669  this.m_proxyA = proxyA;
  670  this.m_proxyB = proxyB;
  671  var count = cache.count;
  672  b2Settings.b2Assert(0 < count && count < 3);
  673  var localPointA;
  674  var localPointA1;
  675  var localPointA2;
  676  var localPointB;
  677  var localPointB1;
  678  var localPointB2;
  679  var pointAX;
  680  var pointAY;
  681  var pointBX;
  682  var pointBY;
  683  var normalX;
  684  var normalY;
  685  var tMat;
  686  var tVec;
  687  var s;
  688  var sgn;
  689  if(count == 1) {
  690    this.m_type = b2SeparationFunction.e_points;
  691    localPointA = this.m_proxyA.GetVertex(cache.indexA[0]);
  692    localPointB = this.m_proxyB.GetVertex(cache.indexB[0]);
  693    tVec = localPointA;
  694    tMat = transformA.R;
  695    pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  696    pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  697    tVec = localPointB;
  698    tMat = transformB.R;
  699    pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  700    pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  701    this.m_axis.x = pointBX - pointAX;
  702    this.m_axis.y = pointBY - pointAY;
  703    this.m_axis.Normalize()
  704  }else {
  705    if(cache.indexB[0] == cache.indexB[1]) {
  706      this.m_type = b2SeparationFunction.e_faceA;
  707      localPointA1 = this.m_proxyA.GetVertex(cache.indexA[0]);
  708      localPointA2 = this.m_proxyA.GetVertex(cache.indexA[1]);
  709      localPointB = this.m_proxyB.GetVertex(cache.indexB[0]);
  710      this.m_localPoint.x = 0.5 * (localPointA1.x + localPointA2.x);
  711      this.m_localPoint.y = 0.5 * (localPointA1.y + localPointA2.y);
  712      this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointA2, localPointA1), 1);
  713      this.m_axis.Normalize();
  714      tVec = this.m_axis;
  715      tMat = transformA.R;
  716      normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
  717      normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
  718      tVec = this.m_localPoint;
  719      tMat = transformA.R;
  720      pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  721      pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  722      tVec = localPointB;
  723      tMat = transformB.R;
  724      pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  725      pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  726      s = (pointBX - pointAX) * normalX + (pointBY - pointAY) * normalY;
  727      if(s < 0) {
  728        this.m_axis.NegativeSelf()
  729      }
  730    }else {
  731      if(cache.indexA[0] == cache.indexA[0]) {
  732        this.m_type = b2SeparationFunction.e_faceB;
  733        localPointB1 = this.m_proxyB.GetVertex(cache.indexB[0]);
  734        localPointB2 = this.m_proxyB.GetVertex(cache.indexB[1]);
  735        localPointA = this.m_proxyA.GetVertex(cache.indexA[0]);
  736        this.m_localPoint.x = 0.5 * (localPointB1.x + localPointB2.x);
  737        this.m_localPoint.y = 0.5 * (localPointB1.y + localPointB2.y);
  738        this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointB2, localPointB1), 1);
  739        this.m_axis.Normalize();
  740        tVec = this.m_axis;
  741        tMat = transformB.R;
  742        normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
  743        normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
  744        tVec = this.m_localPoint;
  745        tMat = transformB.R;
  746        pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  747        pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  748        tVec = localPointA;
  749        tMat = transformA.R;
  750        pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  751        pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  752        s = (pointAX - pointBX) * normalX + (pointAY - pointBY) * normalY;
  753        if(s < 0) {
  754          this.m_axis.NegativeSelf()
  755        }
  756      }else {
  757        localPointA1 = this.m_proxyA.GetVertex(cache.indexA[0]);
  758        localPointA2 = this.m_proxyA.GetVertex(cache.indexA[1]);
  759        localPointB1 = this.m_proxyB.GetVertex(cache.indexB[0]);
  760        localPointB2 = this.m_proxyB.GetVertex(cache.indexB[1]);
  761        var pA = b2Math.MulX(transformA, localPointA);
  762        var dA = b2Math.MulMV(transformA.R, b2Math.SubtractVV(localPointA2, localPointA1));
  763        var pB = b2Math.MulX(transformB, localPointB);
  764        var dB = b2Math.MulMV(transformB.R, b2Math.SubtractVV(localPointB2, localPointB1));
  765        var a = dA.x * dA.x + dA.y * dA.y;
  766        var e = dB.x * dB.x + dB.y * dB.y;
  767        var r = b2Math.SubtractVV(dB, dA);
  768        var c = dA.x * r.x + dA.y * r.y;
  769        var f = dB.x * r.x + dB.y * r.y;
  770        var b = dA.x * dB.x + dA.y * dB.y;
  771        var denom = a * e - b * b;
  772        s = 0;
  773        if(denom != 0) {
  774          s = b2Math.Clamp((b * f - c * e) / denom, 0, 1)
  775        }
  776        var t = (b * s + f) / e;
  777        if(t < 0) {
  778          t = 0;
  779          s = b2Math.Clamp((b - c) / a, 0, 1)
  780        }
  781        localPointA = new b2Vec2;
  782        localPointA.x = localPointA1.x + s * (localPointA2.x - localPointA1.x);
  783        localPointA.y = localPointA1.y + s * (localPointA2.y - localPointA1.y);
  784        localPointB = new b2Vec2;
  785        localPointB.x = localPointB1.x + s * (localPointB2.x - localPointB1.x);
  786        localPointB.y = localPointB1.y + s * (localPointB2.y - localPointB1.y);
  787        if(s == 0 || s == 1) {
  788          this.m_type = b2SeparationFunction.e_faceB;
  789          this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointB2, localPointB1), 1);
  790          this.m_axis.Normalize();
  791          this.m_localPoint = localPointB;
  792          tVec = this.m_axis;
  793          tMat = transformB.R;
  794          normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
  795          normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
  796          tVec = this.m_localPoint;
  797          tMat = transformB.R;
  798          pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  799          pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  800          tVec = localPointA;
  801          tMat = transformA.R;
  802          pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  803          pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  804          sgn = (pointAX - pointBX) * normalX + (pointAY - pointBY) * normalY;
  805          if(s < 0) {
  806            this.m_axis.NegativeSelf()
  807          }
  808        }else {
  809          this.m_type = b2SeparationFunction.e_faceA;
  810          this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointA2, localPointA1), 1);
  811          this.m_localPoint = localPointA;
  812          tVec = this.m_axis;
  813          tMat = transformA.R;
  814          normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
  815          normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
  816          tVec = this.m_localPoint;
  817          tMat = transformA.R;
  818          pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  819          pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  820          tVec = localPointB;
  821          tMat = transformB.R;
  822          pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
  823          pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
  824          sgn = (pointBX - pointAX) * normalX + (pointBY - pointAY) * normalY;
  825          if(s < 0) {
  826            this.m_axis.NegativeSelf()
  827          }
  828        }
  829      }
  830    }
  831  }
  832};
  833b2SeparationFunction.prototype.Evaluate = function(transformA, transformB) {
  834  var axisA;
  835  var axisB;
  836  var localPointA;
  837  var localPointB;
  838  var pointA;
  839  var pointB;
  840  var seperation;
  841  var normal;
  842  switch(this.m_type) {
  843    case b2SeparationFunction.e_points:
  844      axisA = b2Math.MulTMV(transformA.R, this.m_axis);
  845      axisB = b2Math.MulTMV(transformB.R, this.m_axis.GetNegative());
  846      localPointA = this.m_proxyA.GetSupportVertex(axisA);
  847      localPointB = this.m_proxyB.GetSupportVertex(axisB);
  848      pointA = b2Math.MulX(transformA, localPointA);
  849      pointB = b2Math.MulX(transformB, localPointB);
  850      seperation = (pointB.x - pointA.x) * this.m_axis.x + (pointB.y - pointA.y) * this.m_axis.y;
  851      return seperation;
  852    case b2SeparationFunction.e_faceA:
  853      normal = b2Math.MulMV(transformA.R, this.m_axis);
  854      pointA = b2Math.MulX(transformA, this.m_localPoint);
  855      axisB = b2Math.MulTMV(transformB.R, normal.GetNegative());
  856      localPointB = this.m_proxyB.GetSupportVertex(axisB);
  857      pointB = b2Math.MulX(transformB, localPointB);
  858      seperation = (pointB.x - pointA.x) * normal.x + (pointB.y - pointA.y) * normal.y;
  859      return seperation;
  860    case b2SeparationFunction.e_faceB:
  861      normal = b2Math.MulMV(transformB.R, this.m_axis);
  862      pointB = b2Math.MulX(transformB, this.m_localPoint);
  863      axisA = b2Math.MulTMV(transformA.R, normal.GetNegative());
  864      localPointA = this.m_proxyA.GetSupportVertex(axisA);
  865      pointA = b2Math.MulX(transformA, localPointA);
  866      seperation = (pointA.x - pointB.x) * normal.x + (pointA.y - pointB.y) * normal.y;
  867      return seperation;
  868    default:
  869      b2Settings.b2Assert(false);
  870      return 0
  871  }
  872};
  873b2SeparationFunction.prototype.m_proxyA = null;
  874b2SeparationFunction.prototype.m_proxyB = null;
  875b2SeparationFunction.prototype.m_type = 0;
  876b2SeparationFunction.prototype.m_localPoint = new b2Vec2;
  877b2SeparationFunction.prototype.m_axis = new b2Vec2;var b2DynamicTreePair = function() {
  878  this.__varz();
  879  this.__constructor.apply(this, arguments)
  880};
  881b2DynamicTreePair.prototype.__constructor = function() {
  882};
  883b2DynamicTreePair.prototype.__varz = function() {
  884};
  885b2DynamicTreePair.prototype.proxyA = null;
  886b2DynamicTreePair.prototype.proxyB = null;var b2ContactConstraintPoint = function() {
  887  this.__varz();
  888  this.__constructor.apply(this, arguments)
  889};
  890b2ContactConstraintPoint.prototype.__constructor = function() {
  891};
  892b2ContactConstraintPoint.prototype.__varz = function() {
  893  this.localPoint = new b2Vec2;
  894  this.rA = new b2Vec2;
  895  this.rB = new b2Vec2
  896};
  897b2ContactConstraintPoint.prototype.localPoint = new b2Vec2;
  898b2ContactConstraintPoint.prototype.rA = new b2Vec2;
  899b2ContactConstraintPoint.prototype.rB = new b2Vec2;
  900b2ContactConstraintPoint.prototype.normalImpulse = null;
  901b2ContactConstraintPoint.prototype.tangentImpulse = null;
  902b2ContactConstraintPoint.prototype.normalMass = null;
  903b2ContactConstraintPoint.prototype.tangentMass = null;
  904b2ContactConstraintPoint.prototype.equalizedMass = null;
  905b2ContactConstraintPoint.prototype.velocityBias = null;var b2ControllerEdge = function() {
  906  this.__varz();
  907  this.__constructor.apply(this, arguments)
  908};
  909b2ControllerEdge.prototype.__constructor = function() {
  910};
  911b2ControllerEdge.prototype.__varz = function() {
  912};
  913b2ControllerEdge.prototype.controller = null;
  914b2ControllerEdge.prototype.body = null;
  915b2ControllerEdge.prototype.prevBody = null;
  916b2ControllerEdge.prototype.nextBody = null;
  917b2ControllerEdge.prototype.prevController = null;
  918b2ControllerEdge.prototype.nextController = null;var b2DistanceInput = function() {
  919  this.__varz();
  920  this.__constructor.apply(this, arguments)
  921};
  922b2DistanceInput.prototype.__constructor = function() {
  923};
  924b2DistanceInput.prototype.__varz = function() {
  925};
  926b2DistanceInput.prototype.proxyA = null;
  927b2DistanceInput.prototype.proxyB = null;
  928b2DistanceInput.prototype.transformA = null;
  929b2DistanceInput.prototype.transformB = null;
  930b2DistanceInput.prototype.useRadii = null;var b2Settings = function() {
  931  this.__varz();
  932  this.__constructor.apply(this, arguments)
  933};
  934b2Settings.prototype.__constructor = function() {
  935};
  936b2Settings.prototype.__varz = function() {
  937};
  938b2Settings.b2MixFriction = function(friction1, friction2) {
  939  return Math.sqrt(friction1 * friction2)
  940};
  941b2Settings.b2MixRestitution = function(restitution1, restitution2) {
  942  return restitution1 > restitution2 ? restitution1 : restitution2
  943};
  944b2Settings.b2Assert = function(a) {
  945  if(!a) {
  946    throw"Assertion Failed";
  947  }
  948};
  949b2Settings.VERSION = "2.1alpha";
  950b2Settings.USHRT_MAX = 65535;
  951b2Settings.b2_pi = Math.PI;
  952b2Settings.b2_maxManifoldPoints = 2;
  953b2Settings.b2_aabbExtension = 0.1;
  954b2Settings.b2_aabbMultiplier = 2;
  955b2Settings.b2_polygonRadius = 2 * b2Settings.b2_linearSlop;
  956b2Settings.b2_linearSlop = 0.0050;
  957b2Settings.b2_angularSlop = 2 / 180 * b2Settings.b2_pi;
  958b2Settings.b2_toiSlop = 8 * b2Settings.b2_linearSlop;
  959b2Settings.b2_maxTOIContactsPerIsland = 32;
  960b2Settings.b2_maxTOIJointsPerIsland = 32;
  961b2Settings.b2_velocityThreshold = 1;
  962b2Settings.b2_maxLinearCorrection = 0.2;
  963b2Settings.b2_maxAngularCorrection = 8 / 180 * b2Settings.b2_pi;
  964b2Settings.b2_maxTranslation = 2;
  965b2Settings.b2_maxTranslationSquared = b2Settings.b2_maxTranslation * b2Settings.b2_maxTranslation;
  966b2Settings.b2_maxRotation = 0.5 * b2Settings.b2_pi;
  967b2Settings.b2_maxRotationSquared = b2Settings.b2_maxRotation * b2Settings.b2_maxRotation;
  968b2Settings.b2_contactBaumgarte = 0.2;
  969b2Settings.b2_timeToSleep = 0.5;
  970b2Settings.b2_linearSleepTolerance = 0.01;
  971b2Settings.b2_angularSleepTolerance = 2 / 180 * b2Settings.b2_pi;var b2Proxy = function() {
  972  this.__varz();
  973  this.__constructor.apply(this, arguments)
  974};
  975b2Proxy.prototype.__constructor = function() {
  976};
  977b2Proxy.prototype.__varz = function() {
  978  this.lowerBounds = new Array(2);
  979  this.upperBounds = new Array(2);
  980  this.pairs = new Object
  981};
  982b2Proxy.prototype.IsValid = function() {
  983  return this.overlapCount != b2BroadPhase.b2_invalid
  984};
  985b2Proxy.prototype.lowerBounds = new Array(2);
  986b2Proxy.prototype.upperBounds = new Array(2);
  987b2Proxy.prototype.overlapCount = 0;
  988b2Proxy.prototype.timeStamp = 0;
  989b2Proxy.prototype.pairs = new Object;
  990b2Proxy.prototype.next = null;
  991b2Proxy.prototype.userData = null;var b2Point = function() {
  992  this.__varz();
  993  this.__constructor.apply(this, arguments)
  994};
  995b2Point.prototype.__constructor = function() {
  996};
  997b2Point.prototype.__varz = function() {
  998  this.p = new b2Vec2
  999};
 1000b2Point.prototype.Support = function(xf, vX, vY) {
 1001  return this.p
 1002};
 1003b2Point.prototype.GetFirstVertex = function(xf) {
 1004  return this.p
 1005};
 1006b2Point.prototype.p = new b2Vec2;var b2WorldManifold = function() {
 1007  this.__varz();
 1008  this.__constructor.apply(this, arguments)
 1009};
 1010b2WorldManifold.prototype.__constructor = function() {
 1011  this.m_points = new Array(b2Settings.b2_maxManifoldPoints);
 1012  for(var i = 0;i < b2Settings.b2_maxManifoldPoints;i++) {
 1013    this.m_points[i] = new b2Vec2
 1014  }
 1015};
 1016b2WorldManifold.prototype.__varz = function() {
 1017  this.m_normal = new b2Vec2
 1018};
 1019b2WorldManifold.prototype.Initialize = function(manifold, xfA, radiusA, xfB, radiusB) {
 1020  if(manifold.m_pointCount == 0) {
 1021    return
 1022  }
 1023  var i = 0;
 1024  var tVec;
 1025  var tMat;
 1026  var normalX;
 1027  var normalY;
 1028  var planePointX;
 1029  var planePointY;
 1030  var clipPointX;
 1031  var clipPointY;
 1032  switch(manifold.m_type) {
 1033    case b2Manifold.e_circles:
 1034      tMat = xfA.R;
 1035      tVec = manifold.m_localPoint;
 1036      var pointAX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1037      var pointAY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1038      tMat = xfB.R;
 1039      tVec = manifold.m_points[0].m_localPoint;
 1040      var pointBX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1041      var pointBY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1042      var dX = pointBX - pointAX;
 1043      var dY = pointBY - pointAY;
 1044      var d2 = dX * dX + dY * dY;
 1045      if(d2 > Number.MIN_VALUE * Number.MIN_VALUE) {
 1046        var d = Math.sqrt(d2);
 1047        this.m_normal.x = dX / d;
 1048        this.m_normal.y = dY / d
 1049      }else {
 1050        this.m_normal.x = 1;
 1051        this.m_normal.y = 0
 1052      }
 1053      var cAX = pointAX + radiusA * this.m_normal.x;
 1054      var cAY = pointAY + radiusA * this.m_normal.y;
 1055      var cBX = pointBX - radiusB * this.m_normal.x;
 1056      var cBY = pointBY - radiusB * this.m_normal.y;
 1057      this.m_points[0].x = 0.5 * (cAX + cBX);
 1058      this.m_points[0].y = 0.5 * (cAY + cBY);
 1059      break;
 1060    case b2Manifold.e_faceA:
 1061      tMat = xfA.R;
 1062      tVec = manifold.m_localPlaneNormal;
 1063      normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1064      normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1065      tMat = xfA.R;
 1066      tVec = manifold.m_localPoint;
 1067      planePointX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1068      planePointY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1069      this.m_normal.x = normalX;
 1070      this.m_normal.y = normalY;
 1071      for(i = 0;i < manifold.m_pointCount;i++) {
 1072        tMat = xfB.R;
 1073        tVec = manifold.m_points[i].m_localPoint;
 1074        clipPointX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1075        clipPointY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1076        this.m_points[i].x = clipPointX + 0.5 * (radiusA - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusB) * normalX;
 1077        this.m_points[i].y = clipPointY + 0.5 * (radiusA - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusB) * normalY
 1078      }
 1079      break;
 1080    case b2Manifold.e_faceB:
 1081      tMat = xfB.R;
 1082      tVec = manifold.m_localPlaneNormal;
 1083      normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1084      normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1085      tMat = xfB.R;
 1086      tVec = manifold.m_localPoint;
 1087      planePointX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1088      planePointY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1089      this.m_normal.x = -normalX;
 1090      this.m_normal.y = -normalY;
 1091      for(i = 0;i < manifold.m_pointCount;i++) {
 1092        tMat = xfA.R;
 1093        tVec = manifold.m_points[i].m_localPoint;
 1094        clipPointX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 1095        clipPointY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 1096        this.m_points[i].x = clipPointX + 0.5 * (radiusB - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusA) * normalX;
 1097        this.m_points[i].y = clipPointY + 0.5 * (radiusB - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusA) * normalY
 1098      }
 1099      break
 1100  }
 1101};
 1102b2WorldManifold.prototype.m_normal = new b2Vec2;
 1103b2WorldManifold.prototype.m_points = null;var b2RayCastOutput = function() {
 1104  this.__varz();
 1105  this.__constructor.apply(this, arguments)
 1106};
 1107b2RayCastOutput.prototype.__constructor = function() {
 1108};
 1109b2RayCastOutput.prototype.__varz = function() {
 1110  this.normal = new b2Vec2
 1111};
 1112b2RayCastOutput.prototype.normal = new b2Vec2;
 1113b2RayCastOutput.prototype.fraction = null;var b2ConstantForceController = function() {
 1114  b2Controller.prototype.__varz.call(this);
 1115  this.__varz();
 1116  this.__constructor.apply(this, arguments)
 1117};
 1118extend(b2ConstantForceController.prototype, b2Controller.prototype);
 1119b2ConstantForceController.prototype._super = b2Controller.prototype;
 1120b2ConstantForceController.prototype.__constructor = function() {
 1121  this._super.__constructor.apply(this, arguments)
 1122};
 1123b2ConstantForceController.prototype.__varz = function() {
 1124  this.F = new b2Vec2(0, 0)
 1125};
 1126b2ConstantForceController.prototype.Step = function(step) {
 1127  for(var i = m_bodyList;i;i = i.nextBody) {
 1128    var body = i.body;
 1129    if(!body.IsAwake()) {
 1130      continue
 1131    }
 1132    body.ApplyForce(this.F, body.GetWorldCenter())
 1133  }
 1134};
 1135b2ConstantForceController.prototype.F = new b2Vec2(0, 0);var b2MassData = function() {
 1136  this.__varz();
 1137  this.__constructor.apply(this, arguments)
 1138};
 1139b2MassData.prototype.__constructor = function() {
 1140};
 1141b2MassData.prototype.__varz = function() {
 1142  this.center = new b2Vec2(0, 0)
 1143};
 1144b2MassData.prototype.mass = 0;
 1145b2MassData.prototype.center = new b2Vec2(0, 0);
 1146b2MassData.prototype.I = 0;var b2DynamicTree = function() {
 1147  this.__varz();
 1148  this.__constructor.apply(this, arguments)
 1149};
 1150b2DynamicTree.prototype.__constructor = function() {
 1151  this.m_root = null;
 1152  this.m_freeList = null;
 1153  this.m_path = 0;
 1154  this.m_insertionCount = 0
 1155};
 1156b2DynamicTree.prototype.__varz = function() {
 1157};
 1158b2DynamicTree.prototype.AllocateNode = function() {
 1159  if(this.m_freeList) {
 1160    var node = this.m_freeList;
 1161    this.m_freeList = node.parent;
 1162    node.parent = null;
 1163    node.child1 = null;
 1164    node.child2 = null;
 1165    return node
 1166  }
 1167  return new b2DynamicTreeNode
 1168};
 1169b2DynamicTree.prototype.FreeNode = function(node) {
 1170  node.parent = this.m_freeList;
 1171  this.m_freeList = node
 1172};
 1173b2DynamicTree.prototype.InsertLeaf = function(leaf) {
 1174  ++this.m_insertionCount;
 1175  if(this.m_root == null) {
 1176    this.m_root = leaf;
 1177    this.m_root.parent = null;
 1178    return
 1179  }
 1180  var center = leaf.aabb.GetCenter();
 1181  var sibling = this.m_root;
 1182  if(sibling.IsLeaf() == false) {
 1183    do {
 1184      var child1 = sibling.child1;
 1185      var child2 = sibling.child2;
 1186      var norm1 = Math.abs((child1.aabb.lowerBound.x + child1.aabb.upperBound.x) / 2 - center.x) + Math.abs((child1.aabb.lowerBound.y + child1.aabb.upperBound.y) / 2 - center.y);
 1187      var norm2 = Math.abs((child2.aabb.lowerBound.x + child2.aabb.upperBound.x) / 2 - center.x) + Math.abs((child2.aabb.lowerBound.y + child2.aabb.upperBound.y) / 2 - center.y);
 1188      if(norm1 < norm2) {
 1189        sibling = child1
 1190      }else {
 1191        sibling = child2
 1192      }
 1193    }while(sibling.IsLeaf() == false)
 1194  }
 1195  var node1 = sibling.parent;
 1196  var node2 = this.AllocateNode();
 1197  node2.parent = node1;
 1198  node2.userData = null;
 1199  node2.aabb.Combine(leaf.aabb, sibling.aabb);
 1200  if(node1) {
 1201    if(sibling.parent.child1 == sibling) {
 1202      node1.child1 = node2
 1203    }else {
 1204      node1.child2 = node2
 1205    }
 1206    node2.child1 = sibling;
 1207    node2.child2 = leaf;
 1208    sibling.parent = node2;
 1209    leaf.parent = node2;
 1210    do {
 1211      if(node1.aabb.Contains(node2.aabb)) {
 1212        break
 1213      }
 1214      node1.aabb.Combine(node1.child1.aabb, node1.child2.aabb);
 1215      node2 = node1;
 1216      node1 = node1.parent
 1217    }while(node1)
 1218  }else {
 1219    node2.child1 = sibling;
 1220    node2.child2 = leaf;
 1221    sibling.parent = node2;
 1222    leaf.parent = node2;
 1223    this.m_root = node2
 1224  }
 1225};
 1226b2DynamicTree.prototype.RemoveLeaf = function(leaf) {
 1227  if(leaf == this.m_root) {
 1228    this.m_root = null;
 1229    return
 1230  }
 1231  var node2 = leaf.parent;
 1232  var node1 = node2.parent;
 1233  var sibling;
 1234  if(node2.child1 == leaf) {
 1235    sibling = node2.child2
 1236  }else {
 1237    sibling = node2.child1
 1238  }
 1239  if(node1) {
 1240    if(node1.child1 == node2) {
 1241      node1.child1 = sibling
 1242    }else {
 1243      node1.child2 = sibling
 1244    }
 1245    sibling.parent = node1;
 1246    this.FreeNode(node2);
 1247    while(node1) {
 1248      var oldAABB = node1.aabb;
 1249      node1.aabb = b2AABB.Combine(node1.child1.aabb, node1.child2.aabb);
 1250      if(oldAABB.Contains(node1.aabb)) {
 1251        break
 1252      }
 1253      node1 = node1.parent
 1254    }
 1255  }else {
 1256    this.m_root = sibling;
 1257    sibling.parent = null;
 1258    this.FreeNode(node2)
 1259  }
 1260};
 1261b2DynamicTree.prototype.CreateProxy = function(aabb, userData) {
 1262  var node = this.AllocateNode();
 1263  var extendX = b2Settings.b2_aabbExtension;
 1264  var extendY = b2Settings.b2_aabbExtension;
 1265  node.aabb.lowerBound.x = aabb.lowerBound.x - extendX;
 1266  node.aabb.lowerBound.y = aabb.lowerBound.y - extendY;
 1267  node.aabb.upperBound.x = aabb.upperBound.x + extendX;
 1268  node.aabb.upperBound.y = aabb.upperBound.y + extendY;
 1269  node.userData = userData;
 1270  this.InsertLeaf(node);
 1271  return node
 1272};
 1273b2DynamicTree.prototype.DestroyProxy = function(proxy) {
 1274  this.RemoveLeaf(proxy);
 1275  this.FreeNode(proxy)
 1276};
 1277b2DynamicTree.prototype.MoveProxy = function(proxy, aabb, displacement) {
 1278  b2Settings.b2Assert(proxy.IsLeaf());
 1279  if(proxy.aabb.Contains(aabb)) {
 1280    return false
 1281  }
 1282  this.RemoveLeaf(proxy);
 1283  var extendX = b2Settings.b2_aabbExtension + b2Settings.b2_aabbMultiplier * (displacement.x > 0 ? displacement.x : -displacement.x);
 1284  var extendY = b2Settings.b2_aabbExtension + b2Settings.b2_aabbMultiplier * (displacement.y > 0 ? displacement.y : -displacement.y);
 1285  proxy.aabb.lowerBound.x = aabb.lowerBound.x - extendX;
 1286  proxy.aabb.lowerBound.y = aabb.lowerBound.y - extendY;
 1287  proxy.aabb.upperBound.x = aabb.upperBound.x + extendX;
 1288  proxy.aabb.upperBound.y = aabb.upperBound.y + extendY;
 1289  this.InsertLeaf(proxy);
 1290  return true
 1291};
 1292b2DynamicTree.prototype.Rebalance = function(iterations) {
 1293  if(this.m_root == null) {
 1294    return
 1295  }
 1296  for(var i = 0;i < iterations;i++) {
 1297    var node = this.m_root;
 1298    var bit = 0;
 1299    while(node.IsLeaf() == false) {
 1300      node = this.m_path >> bit & 1 ? node.child2 : node.child1;
 1301      bit = bit + 1 & 31
 1302    }
 1303    ++this.m_path;
 1304    this.RemoveLeaf(node);
 1305    this.InsertLeaf(node)
 1306  }
 1307};
 1308b2DynamicTree.prototype.GetFatAABB = function(proxy) {
 1309  return proxy.aabb
 1310};
 1311b2DynamicTree.prototype.GetUserData = function(proxy) {
 1312  return proxy.userData
 1313};
 1314b2DynamicTree.prototype.Query = function(callback, aabb) {
 1315  if(this.m_root == null) {
 1316    return
 1317  }
 1318  var stack = new Array;
 1319  var count = 0;
 1320  stack[count++] = this.m_root;
 1321  while(count > 0) {
 1322    var node = stack[--count];
 1323    if(node.aabb.TestOverlap(aabb)) {
 1324      if(node.IsLeaf()) {
 1325        var proceed = callback(node);
 1326        if(!proceed) {
 1327          return
 1328        }
 1329      }else {
 1330        stack[count++] = node.child1;
 1331        stack[count++] = node.child2
 1332      }
 1333    }
 1334  }
 1335};
 1336b2DynamicTree.prototype.RayCast = function(callback, input) {
 1337  if(this.m_root == null) {
 1338    return
 1339  }
 1340  var p1 = input.p1;
 1341  var p2 = input.p2;
 1342  var r = b2Math.SubtractVV(p1, p2);
 1343  r.Normalize();
 1344  var v = b2Math.CrossFV(1, r);
 1345  var abs_v = b2Math.AbsV(v);
 1346  var maxFraction = input.maxFraction;
 1347  var segmentAABB = new b2AABB;
 1348  var tX;
 1349  var tY;
 1350  tX = p1.x + maxFraction * (p2.x - p1.x);
 1351  tY = p1.y + maxFraction * (p2.y - p1.y);
 1352  segmentAABB.lowerBound.x = Math.min(p1.x, tX);
 1353  segmentAABB.lowerBound.y = Math.min(p1.y, tY);
 1354  segmentAABB.upperBound.x = Math.max(p1.x, tX);
 1355  segmentAABB.upperBound.y = Math.max(p1.y, tY);
 1356  var stack = new Array;
 1357  var count = 0;
 1358  stack[count++] = this.m_root;
 1359  while(count > 0) {
 1360    var node = stack[--count];
 1361    if(node.aabb.TestOverlap(segmentAABB) == false) {
 1362      continue
 1363    }
 1364    var c = node.aabb.GetCenter();
 1365    var h = node.aabb.GetExtents();
 1366    var separation = Math.abs(v.x * (p1.x - c.x) + v.y * (p1.y - c.y)) - abs_v.x * h.x - abs_v.y * h.y;
 1367    if(separation > 0) {
 1368      continue
 1369    }
 1370    if(node.IsLeaf()) {
 1371      var subInput = new b2RayCastInput;
 1372      subInput.p1 = input.p1;
 1373      subInput.p2 = input.p2;
 1374      subInput.maxFraction = input.maxFraction;
 1375      maxFraction = callback(subInput, node);
 1376      if(maxFraction == 0) {
 1377        return
 1378      }
 1379      tX = p1.x + maxFraction * (p2.x - p1.x);
 1380      tY = p1.y + maxFraction * (p2.y - p1.y);
 1381      segmentAABB.lowerBound.x = Math.min(p1.x, tX);
 1382      segmentAABB.lowerBound.y = Math.min(p1.y, tY);
 1383      segmentAABB.upperBound.x = Math.max(p1.x, tX);
 1384      segmentAABB.upperBound.y = Math.max(p1.y, tY)
 1385    }else {
 1386      stack[count++] = node.child1;
 1387      stack[count++] = node.child2
 1388    }
 1389  }
 1390};
 1391b2DynamicTree.prototype.m_root = null;
 1392b2DynamicTree.prototype.m_freeList = null;
 1393b2DynamicTree.prototype.m_path = 0;
 1394b2DynamicTree.prototype.m_insertionCount = 0;var b2JointEdge = function() {
 1395  this.__varz();
 1396  this.__constructor.apply(this, arguments)
 1397};
 1398b2JointEdge.prototype.__constructor = function() {
 1399};
 1400b2JointEdge.prototype.__varz = function() {
 1401};
 1402b2JointEdge.prototype.other = null;
 1403b2JointEdge.prototype.joint = null;
 1404b2JointEdge.prototype.prev = null;
 1405b2JointEdge.prototype.next = null;var b2RayCastInput = function() {
 1406  this.__varz();
 1407  this.__constructor.apply(this, arguments)
 1408};
 1409b2RayCastInput.prototype.__constructor = function() {
 1410};
 1411b2RayCastInput.prototype.__varz = function() {
 1412  this.p1 = new b2Vec2;
 1413  this.p2 = new b2Vec2
 1414};
 1415b2RayCastInput.prototype.p1 = new b2Vec2;
 1416b2RayCastInput.prototype.p2 = new b2Vec2;
 1417b2RayCastInput.prototype.maxFraction = null;var Features = function() {
 1418  this.__varz();
 1419  this.__constructor.apply(this, arguments)
 1420};
 1421Features.prototype.__constructor = function() {
 1422};
 1423Features.prototype.__varz = function() {
 1424};
 1425Features.prototype.__defineGetter__("referenceEdge", function() {
 1426  return this._referenceEdge
 1427});
 1428Features.prototype.__defineSetter__("referenceEdge", function(value) {
 1429  this._referenceEdge = value;
 1430  this._m_id._key = this._m_id._key & 4294967040 | this._referenceEdge & 255
 1431});
 1432Features.prototype.__defineGetter__("incidentEdge", function() {
 1433  return this._incidentEdge
 1434});
 1435Features.prototype.__defineSetter__("incidentEdge", function(value) {
 1436  this._incidentEdge = value;
 1437  this._m_id._key = this._m_id._key & 4294902015 | this._incidentEdge << 8 & 65280
 1438});
 1439Features.prototype.__defineGetter__("incidentVertex", function() {
 1440  return this._incidentVertex
 1441});
 1442Features.prototype.__defineSetter__("incidentVertex", function(value) {
 1443  this._incidentVertex = value;
 1444  this._m_id._key = this._m_id._key & 4278255615 | this._incidentVertex << 16 & 16711680
 1445});
 1446Features.prototype.__defineGetter__("flip", function() {
 1447  return this._flip
 1448});
 1449Features.prototype.__defineSetter__("flip", function(value) {
 1450  this._flip = value;
 1451  this._m_id._key = this._m_id._key & 16777215 | this._flip << 24 & 4278190080
 1452});
 1453Features.prototype._referenceEdge = 0;
 1454Features.prototype._incidentEdge = 0;
 1455Features.prototype._incidentVertex = 0;
 1456Features.prototype._flip = 0;
 1457Features.prototype._m_id = null;var b2FilterData = function() {
 1458  this.__varz();
 1459  this.__constructor.apply(this, arguments)
 1460};
 1461b2FilterData.prototype.__constructor = function() {
 1462};
 1463b2FilterData.prototype.__varz = function() {
 1464  this.categoryBits = 1;
 1465  this.maskBits = 65535
 1466};
 1467b2FilterData.prototype.Copy = function() {
 1468  var copy = new b2FilterData;
 1469  copy.categoryBits = this.categoryBits;
 1470  copy.maskBits = this.maskBits;
 1471  copy.groupIndex = this.groupIndex;
 1472  return copy
 1473};
 1474b2FilterData.prototype.categoryBits = 1;
 1475b2FilterData.prototype.maskBits = 65535;
 1476b2FilterData.prototype.groupIndex = 0;var b2AABB = function() {
 1477  this.__varz();
 1478  this.__constructor.apply(this, arguments)
 1479};
 1480b2AABB.prototype.__constructor = function() {
 1481};
 1482b2AABB.prototype.__varz = function() {
 1483  this.lowerBound = new b2Vec2;
 1484  this.upperBound = new b2Vec2
 1485};
 1486b2AABB.Combine = function(aabb1, aabb2) {
 1487  var aabb = new b2AABB;
 1488  aabb.Combine(aabb1, aabb2);
 1489  return aabb
 1490};
 1491b2AABB.prototype.IsValid = function() {
 1492  var dX = this.upperBound.x - this.lowerBound.x;
 1493  var dY = this.upperBound.y - this.lowerBound.y;
 1494  var valid = dX >= 0 && dY >= 0;
 1495  valid = valid && this.lowerBound.IsValid() && this.upperBound.IsValid();
 1496  return valid
 1497};
 1498b2AABB.prototype.GetCenter = function() {
 1499  return new b2Vec2((this.lowerBound.x + this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2)
 1500};
 1501b2AABB.prototype.GetExtents = function() {
 1502  return new b2Vec2((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2)
 1503};
 1504b2AABB.prototype.Contains = function(aabb) {
 1505  var result = true && this.lowerBound.x <= aabb.lowerBound.x && this.lowerBound.y <= aabb.lowerBound.y && aabb.upperBound.x <= this.upperBound.x && aabb.upperBound.y <= this.upperBound.y;
 1506  return result
 1507};
 1508b2AABB.prototype.RayCast = function(output, input) {
 1509  var tmin = -Number.MAX_VALUE;
 1510  var tmax = Number.MAX_VALUE;
 1511  var pX = input.p1.x;
 1512  var pY = input.p1.y;
 1513  var dX = input.p2.x - input.p1.x;
 1514  var dY = input.p2.y - input.p1.y;
 1515  var absDX = Math.abs(dX);
 1516  var absDY = Math.abs(dY);
 1517  var normal = output.normal;
 1518  var inv_d;
 1519  var t1;
 1520  var t2;
 1521  var t3;
 1522  var s;
 1523  if(absDX < Number.MIN_VALUE) {
 1524    if(pX < this.lowerBound.x || this.upperBound.x < pX) {
 1525      return false
 1526    }
 1527  }else {
 1528    inv_d = 1 / dX;
 1529    t1 = (this.lowerBound.x - pX) * inv_d;
 1530    t2 = (this.upperBound.x - pX) * inv_d;
 1531    s = -1;
 1532    if(t1 > t2) {
 1533      t3 = t1;
 1534      t1 = t2;
 1535      t2 = t3;
 1536      s = 1
 1537    }
 1538    if(t1 > tmin) {
 1539      normal.x = s;
 1540      normal.y = 0;
 1541      tmin = t1
 1542    }
 1543    tmax = Math.min(tmax, t2);
 1544    if(tmin > tmax) {
 1545      return false
 1546    }
 1547  }
 1548  if(absDY < Number.MIN_VALUE) {
 1549    if(pY < this.lowerBound.y || this.upperBound.y < pY) {
 1550      return false
 1551    }
 1552  }else {
 1553    inv_d = 1 / dY;
 1554    t1 = (this.lowerBound.y - pY) * inv_d;
 1555    t2 = (this.upperBound.y - pY) * inv_d;
 1556    s = -1;
 1557    if(t1 > t2) {
 1558      t3 = t1;
 1559      t1 = t2;
 1560      t2 = t3;
 1561      s = 1
 1562    }
 1563    if(t1 > tmin) {
 1564      normal.y = s;
 1565      normal.x = 0;
 1566      tmin = t1
 1567    }
 1568    tmax = Math.min(tmax, t2);
 1569    if(tmin > tmax) {
 1570      return false
 1571    }
 1572  }
 1573  output.fraction = tmin;
 1574  return true
 1575};
 1576b2AABB.prototype.TestOverlap = function(other) {
 1577  var d1X = other.lowerBound.x - this.upperBound.x;
 1578  var d1Y = other.lowerBound.y - this.upperBound.y;
 1579  var d2X = this.lowerBound.x - other.upperBound.x;
 1580  var d2Y = this.lowerBound.y - other.upperBound.y;
 1581  if(d1X > 0 || d1Y > 0) {
 1582    return false
 1583  }
 1584  if(d2X > 0 || d2Y > 0) {
 1585    return false
 1586  }
 1587  return true
 1588};
 1589b2AABB.prototype.Combine = function(aabb1, aabb2) {
 1590  this.lowerBound.x = Math.min(aabb1.lowerBound.x, aabb2.lowerBound.x);
 1591  this.lowerBound.y = Math.min(aabb1.lowerBound.y, aabb2.lowerBound.y);
 1592  this.upperBound.x = Math.max(aabb1.upperBound.x, aabb2.upperBound.x);
 1593  this.upperBound.y = Math.max(aabb1.upperBound.y, aabb2.upperBound.y)
 1594};
 1595b2AABB.prototype.lowerBound = new b2Vec2;
 1596b2AABB.prototype.upperBound = new b2Vec2;var b2Jacobian = function() {
 1597  this.__varz();
 1598  this.__constructor.apply(this, arguments)
 1599};
 1600b2Jacobian.prototype.__constructor = function() {
 1601};
 1602b2Jacobian.prototype.__varz = function() {
 1603  this.linearA = new b2Vec2;
 1604  this.linearB = new b2Vec2
 1605};
 1606b2Jacobian.prototype.SetZero = function() {
 1607  this.linearA.SetZero();
 1608  this.angularA = 0;
 1609  this.linearB.SetZero();
 1610  this.angularB = 0
 1611};
 1612b2Jacobian.prototype.Set = function(x1, a1, x2, a2) {
 1613  this.linearA.SetV(x1);
 1614  this.angularA = a1;
 1615  this.linearB.SetV(x2);
 1616  this.angularB = a2
 1617};
 1618b2Jacobian.prototype.Compute = function(x1, a1, x2, a2) {
 1619  return this.linearA.x * x1.x + this.linearA.y * x1.y + this.angularA * a1 + (this.linearB.x * x2.x + this.linearB.y * x2.y) + this.angularB * a2
 1620};
 1621b2Jacobian.prototype.linearA = new b2Vec2;
 1622b2Jacobian.prototype.angularA = null;
 1623b2Jacobian.prototype.linearB = new b2Vec2;
 1624b2Jacobian.prototype.angularB = null;var b2Bound = function() {
 1625  this.__varz();
 1626  this.__constructor.apply(this, arguments)
 1627};
 1628b2Bound.prototype.__constructor = function() {
 1629};
 1630b2Bound.prototype.__varz = function() {
 1631};
 1632b2Bound.prototype.IsLower = function() {
 1633  return(this.value & 1) == 0
 1634};
 1635b2Bound.prototype.IsUpper = function() {
 1636  return(this.value & 1) == 1
 1637};
 1638b2Bound.prototype.Swap = function(b) {
 1639  var tempValue = this.value;
 1640  var tempProxy = this.proxy;
 1641  var tempStabbingCount = this.stabbingCount;
 1642  this.value = b.value;
 1643  this.proxy = b.proxy;
 1644  this.stabbingCount = b.stabbingCount;
 1645  b.value = tempValue;
 1646  b.proxy = tempProxy;
 1647  b.stabbingCount = tempStabbingCount
 1648};
 1649b2Bound.prototype.value = 0;
 1650b2Bound.prototype.proxy = null;
 1651b2Bound.prototype.stabbingCount = 0;var b2SimplexVertex = function() {
 1652  this.__varz();
 1653  this.__constructor.apply(this, arguments)
 1654};
 1655b2SimplexVertex.prototype.__constructor = function() {
 1656};
 1657b2SimplexVertex.prototype.__varz = function() {
 1658};
 1659b2SimplexVertex.prototype.Set = function(other) {
 1660  this.wA.SetV(other.wA);
 1661  this.wB.SetV(other.wB);
 1662  this.w.SetV(other.w);
 1663  this.a = other.a;
 1664  this.indexA = other.indexA;
 1665  this.indexB = other.indexB
 1666};
 1667b2SimplexVertex.prototype.wA = null;
 1668b2SimplexVertex.prototype.wB = null;
 1669b2SimplexVertex.prototype.w = null;
 1670b2SimplexVertex.prototype.a = null;
 1671b2SimplexVertex.prototype.indexA = 0;
 1672b2SimplexVertex.prototype.indexB = 0;var b2Mat22 = function() {
 1673  this.__varz();
 1674  this.__constructor.apply(this, arguments)
 1675};
 1676b2Mat22.prototype.__constructor = function() {
 1677  this.col1.x = this.col2.y = 1
 1678};
 1679b2Mat22.prototype.__varz = function() {
 1680  this.col1 = new b2Vec2;
 1681  this.col2 = new b2Vec2
 1682};
 1683b2Mat22.FromAngle = function(angle) {
 1684  var mat = new b2Mat22;
 1685  mat.Set(angle);
 1686  return mat
 1687};
 1688b2Mat22.FromVV = function(c1, c2) {
 1689  var mat = new b2Mat22;
 1690  mat.SetVV(c1, c2);
 1691  return mat
 1692};
 1693b2Mat22.prototype.Set = function(angle) {
 1694  var c = Math.cos(angle);
 1695  var s = Math.sin(angle);
 1696  this.col1.x = c;
 1697  this.col2.x = -s;
 1698  this.col1.y = s;
 1699  this.col2.y = c
 1700};
 1701b2Mat22.prototype.SetVV = function(c1, c2) {
 1702  this.col1.SetV(c1);
 1703  this.col2.SetV(c2)
 1704};
 1705b2Mat22.prototype.Copy = function() {
 1706  var mat = new b2Mat22;
 1707  mat.SetM(this);
 1708  return mat
 1709};
 1710b2Mat22.prototype.SetM = function(m) {
 1711  this.col1.SetV(m.col1);
 1712  this.col2.SetV(m.col2)
 1713};
 1714b2Mat22.prototype.AddM = function(m) {
 1715  this.col1.x += m.col1.x;
 1716  this.col1.y += m.col1.y;
 1717  this.col2.x += m.col2.x;
 1718  this.col2.y += m.col2.y
 1719};
 1720b2Mat22.prototype.SetIdentity = function() {
 1721  this.col1.x = 1;
 1722  this.col2.x = 0;
 1723  this.col1.y = 0;
 1724  this.col2.y = 1
 1725};
 1726b2Mat22.prototype.SetZero = function() {
 1727  this.col1.x = 0;
 1728  this.col2.x = 0;
 1729  this.col1.y = 0;
 1730  this.col2.y = 0
 1731};
 1732b2Mat22.prototype.GetAngle = function() {
 1733  return Math.atan2(this.col1.y, this.col1.x)
 1734};
 1735b2Mat22.prototype.GetInverse = function(out) {
 1736  var a = this.col1.x;
 1737  var b = this.col2.x;
 1738  var c = this.col1.y;
 1739  var d = this.col2.y;
 1740  var det = a * d - b * c;
 1741  if(det != 0) {
 1742    det = 1 / det
 1743  }
 1744  out.col1.x = det * d;
 1745  out.col2.x = -det * b;
 1746  out.col1.y = -det * c;
 1747  out.col2.y = det * a;
 1748  return out
 1749};
 1750b2Mat22.prototype.Solve = function(out, bX, bY) {
 1751  var a11 = this.col1.x;
 1752  var a12 = this.col2.x;
 1753  var a21 = this.col1.y;
 1754  var a22 = this.col2.y;
 1755  var det = a11 * a22 - a12 * a21;
 1756  if(det != 0) {
 1757    det = 1 / det
 1758  }
 1759  out.x = det * (a22 * bX - a12 * bY);
 1760  out.y = det * (a11 * bY - a21 * bX);
 1761  return out
 1762};
 1763b2Mat22.prototype.Abs = function() {
 1764  this.col1.Abs();
 1765  this.col2.Abs()
 1766};
 1767b2Mat22.prototype.col1 = new b2Vec2;
 1768b2Mat22.prototype.col2 = new b2Vec2;var b2SimplexCache = function() {
 1769  this.__varz();
 1770  this.__constructor.apply(this, arguments)
 1771};
 1772b2SimplexCache.prototype.__constructor = function() {
 1773};
 1774b2SimplexCache.prototype.__varz = function() {
 1775  this.indexA = new Array(3);
 1776  this.indexB = new Array(3)
 1777};
 1778b2SimplexCache.prototype.metric = null;
 1779b2SimplexCache.prototype.count = 0;
 1780b2SimplexCache.prototype.indexA = new Array(3);
 1781b2SimplexCache.prototype.indexB = new Array(3);var b2Shape = function() {
 1782  this.__varz();
 1783  this.__constructor.apply(this, arguments)
 1784};
 1785b2Shape.prototype.__constructor = function() {
 1786  this.m_type = b2Shape.e_unknownShape;
 1787  this.m_radius = b2Settings.b2_linearSlop
 1788};
 1789b2Shape.prototype.__varz = function() {
 1790};
 1791b2Shape.TestOverlap = function(shape1, transform1, shape2, transform2) {
 1792  var input = new b2DistanceInput;
 1793  input.proxyA = new b2DistanceProxy;
 1794  input.proxyA.Set(shape1);
 1795  input.proxyB = new b2DistanceProxy;
 1796  input.proxyB.Set(shape2);
 1797  input.transformA = transform1;
 1798  input.transformB = transform2;
 1799  input.useRadii = true;
 1800  var simplexCache = new b2SimplexCache;
 1801  simplexCache.count = 0;
 1802  var output = new b2DistanceOutput;
 1803  b2Distance.Distance(output, simplexCache, input);
 1804  return output.distance < 10 * Number.MIN_VALUE
 1805};
 1806b2Shape.e_hitCollide = 1;
 1807b2Shape.e_missCollide = 0;
 1808b2Shape.e_startsInsideCollide = -1;
 1809b2Shape.e_unknownShape = -1;
 1810b2Shape.e_circleShape = 0;
 1811b2Shape.e_polygonShape = 1;
 1812b2Shape.e_edgeShape = 2;
 1813b2Shape.e_shapeTypeCount = 3;
 1814b2Shape.prototype.Copy = function() {
 1815  return null
 1816};
 1817b2Shape.prototype.Set = function(other) {
 1818  this.m_radius = other.m_radius
 1819};
 1820b2Shape.prototype.GetType = function() {
 1821  return this.m_type
 1822};
 1823b2Shape.prototype.TestPoint = function(xf, p) {
 1824  return false
 1825};
 1826b2Shape.prototype.RayCast = function(output, input, transform) {
 1827  return false
 1828};
 1829b2Shape.prototype.ComputeAABB = function(aabb, xf) {
 1830};
 1831b2Shape.prototype.ComputeMass = function(massData, density) {
 1832};
 1833b2Shape.prototype.ComputeSubmergedArea = function(normal, offset, xf, c) {
 1834  return 0
 1835};
 1836b2Shape.prototype.m_type = 0;
 1837b2Shape.prototype.m_radius = null;var b2Segment = function() {
 1838  this.__varz();
 1839  this.__constructor.apply(this, arguments)
 1840};
 1841b2Segment.prototype.__constructor = function() {
 1842};
 1843b2Segment.prototype.__varz = function() {
 1844  this.p1 = new b2Vec2;
 1845  this.p2 = new b2Vec2
 1846};
 1847b2Segment.prototype.TestSegment = function(lambda, normal, segment, maxLambda) {
 1848  var s = segment.p1;
 1849  var rX = segment.p2.x - s.x;
 1850  var rY = segment.p2.y - s.y;
 1851  var dX = this.p2.x - this.p1.x;
 1852  var dY = this.p2.y - this.p1.y;
 1853  var nX = dY;
 1854  var nY = -dX;
 1855  var k_slop = 100 * Number.MIN_VALUE;
 1856  var denom = -(rX * nX + rY * nY);
 1857  if(denom > k_slop) {
 1858    var bX = s.x - this.p1.x;
 1859    var bY = s.y - this.p1.y;
 1860    var a = bX * nX + bY * nY;
 1861    if(0 <= a && a <= maxLambda * denom) {
 1862      var mu2 = -rX * bY + rY * bX;
 1863      if(-k_slop * denom <= mu2 && mu2 <= denom * (1 + k_slop)) {
 1864        a /= denom;
 1865        var nLen = Math.sqrt(nX * nX + nY * nY);
 1866        nX /= nLen;
 1867        nY /= nLen;
 1868        lambda[0] = a;
 1869        normal.Set(nX, nY);
 1870        return true
 1871      }
 1872    }
 1873  }
 1874  return false
 1875};
 1876b2Segment.prototype.Extend = function(aabb) {
 1877  this.ExtendForward(aabb);
 1878  this.ExtendBackward(aabb)
 1879};
 1880b2Segment.prototype.ExtendForward = function(aabb) {
 1881  var dX = this.p2.x - this.p1.x;
 1882  var dY = this.p2.y - this.p1.y;
 1883  var lambda = Math.min(dX > 0 ? (aabb.upperBound.x - this.p1.x) / dX : dX < 0 ? (aabb.lowerBound.x - this.p1.x) / dX : Number.POSITIVE_INFINITY, dY > 0 ? (aabb.upperBound.y - this.p1.y) / dY : dY < 0 ? (aabb.lowerBound.y - this.p1.y) / dY : Number.POSITIVE_INFINITY);
 1884  this.p2.x = this.p1.x + dX * lambda;
 1885  this.p2.y = this.p1.y + dY * lambda
 1886};
 1887b2Segment.prototype.ExtendBackward = function(aabb) {
 1888  var dX = -this.p2.x + this.p1.x;
 1889  var dY = -this.p2.y + this.p1.y;
 1890  var lambda = Math.min(dX > 0 ? (aabb.upperBound.x - this.p2.x) / dX : dX < 0 ? (aabb.lowerBound.x - this.p2.x) / dX : Number.POSITIVE_INFINITY, dY > 0 ? (aabb.upperBound.y - this.p2.y) / dY : dY < 0 ? (aabb.lowerBound.y - this.p2.y) / dY : Number.POSITIVE_INFINITY);
 1891  this.p1.x = this.p2.x + dX * lambda;
 1892  this.p1.y = this.p2.y + dY * lambda
 1893};
 1894b2Segment.prototype.p1 = new b2Vec2;
 1895b2Segment.prototype.p2 = new b2Vec2;var b2ContactRegister = function() {
 1896  this.__varz();
 1897  this.__constructor.apply(this, arguments)
 1898};
 1899b2ContactRegister.prototype.__constructor = function() {
 1900};
 1901b2ContactRegister.prototype.__varz = function() {
 1902};
 1903b2ContactRegister.prototype.createFcn = null;
 1904b2ContactRegister.prototype.destroyFcn = null;
 1905b2ContactRegister.prototype.primary = null;
 1906b2ContactRegister.prototype.pool = null;
 1907b2ContactRegister.prototype.poolCount = 0;var b2DebugDraw = function() {
 1908  this.__varz();
 1909  this.__constructor.apply(this, arguments)
 1910};
 1911b2DebugDraw.prototype.__constructor = function() {
 1912  this.m_drawFlags = 0
 1913};
 1914b2DebugDraw.prototype.__varz = function() {
 1915};
 1916b2DebugDraw.e_shapeBit = 1;
 1917b2DebugDraw.e_jointBit = 2;
 1918b2DebugDraw.e_aabbBit = 4;
 1919b2DebugDraw.e_pairBit = 8;
 1920b2DebugDraw.e_centerOfMassBit = 16;
 1921b2DebugDraw.e_controllerBit = 32;
 1922b2DebugDraw.prototype.SetFlags = function(flags) {
 1923  this.m_drawFlags = flags
 1924};
 1925b2DebugDraw.prototype.GetFlags = function() {
 1926  return this.m_drawFlags
 1927};
 1928b2DebugDraw.prototype.AppendFlags = function(flags) {
 1929  this.m_drawFlags |= flags
 1930};
 1931b2DebugDraw.prototype.ClearFlags = function(flags) {
 1932  this.m_drawFlags &= ~flags
 1933};
 1934b2DebugDraw.prototype.SetSprite = function(sprite) {
 1935  this.m_sprite = sprite
 1936};
 1937b2DebugDraw.prototype.GetSprite = function() {
 1938  return this.m_sprite
 1939};
 1940b2DebugDraw.prototype.SetDrawScale = function(drawScale) {
 1941  this.m_drawScale = drawScale
 1942};
 1943b2DebugDraw.prototype.GetDrawScale = function() {
 1944  return this.m_drawScale
 1945};
 1946b2DebugDraw.prototype.SetLineThickness = function(lineThickness) {
 1947  this.m_lineThickness = lineThickness
 1948};
 1949b2DebugDraw.prototype.GetLineThickness = function() {
 1950  return this.m_lineThickness
 1951};
 1952b2DebugDraw.prototype.SetAlpha = function(alpha) {
 1953  this.m_alpha = alpha
 1954};
 1955b2DebugDraw.prototype.GetAlpha = function() {
 1956  return this.m_alpha
 1957};
 1958b2DebugDraw.prototype.SetFillAlpha = function(alpha) {
 1959  this.m_fillAlpha = alpha
 1960};
 1961b2DebugDraw.prototype.GetFillAlpha = function() {
 1962  return this.m_fillAlpha
 1963};
 1964b2DebugDraw.prototype.SetXFormScale = function(xformScale) {
 1965  this.m_xformScale = xformScale
 1966};
 1967b2DebugDraw.prototype.GetXFormScale = function() {
 1968  return this.m_xformScale
 1969};
 1970b2DebugDraw.prototype.Clear = function() {
 1971  this.m_sprite.clearRect(0, 0, this.m_sprite.canvas.width, this.m_sprite.canvas.height)
 1972};
 1973b2DebugDraw.prototype.Y = function(y) {
 1974  return this.m_sprite.canvas.height - y
 1975};
 1976b2DebugDraw.prototype.ToWorldPoint = function(localPoint) {
 1977  return new b2Vec2(localPoint.x / this.m_drawScale, this.Y(localPoint.y) / this.m_drawScale)
 1978};
 1979b2DebugDraw.prototype.ColorStyle = function(color, alpha) {
 1980  return"rgba(" + color.r + ", " + color.g + ", " + color.b + ", " + alpha + ")"
 1981};
 1982b2DebugDraw.prototype.DrawPolygon = function(vertices, vertexCount, color) {
 1983  this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
 1984  this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale);
 1985  for(var i = 1;i < vertexCount;i++) {
 1986    this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale)
 1987  }
 1988  this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale)
 1989};
 1990b2DebugDraw.prototype.DrawSolidPolygon = function(vertices, vertexCount, color) {
 1991  this.m_sprite.strokeSyle = this.ColorStyle(color, this.m_alpha);
 1992  this.m_sprite.lineWidth = this.m_lineThickness;
 1993  this.m_sprite.fillStyle = this.ColorStyle(color, this.m_fillAlpha);
 1994  this.m_sprite.beginPath();
 1995  this.m_sprite.moveTo(vertices[0].x * this.m_drawScale, this.Y(vertices[0].y * this.m_drawScale));
 1996  for(var i = 1;i < vertexCount;i++) {
 1997    this.m_sprite.lineTo(vertices[i].x * this.m_drawScale, this.Y(vertices[i].y * this.m_drawScale))
 1998  }
 1999  this.m_sprite.lineTo(vertices[0].x * this.m_drawScale, this.Y(vertices[0].y * this.m_drawScale));
 2000  this.m_sprite.fill();
 2001  this.m_sprite.stroke();
 2002  this.m_sprite.closePath()
 2003};
 2004b2DebugDraw.prototype.DrawCircle = function(center, radius, color) {
 2005  this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
 2006  this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale)
 2007};
 2008b2DebugDraw.prototype.DrawSolidCircle = function(center, radius, axis, color) {
 2009  this.m_sprite.strokeSyle = this.ColorStyle(color, this.m_alpha);
 2010  this.m_sprite.lineWidth = this.m_lineThickness;
 2011  this.m_sprite.fillStyle = this.ColorStyle(color, this.m_fillAlpha);
 2012  this.m_sprite.beginPath();
 2013  this.m_sprite.arc(center.x * this.m_drawScale, this.Y(center.y * this.m_drawScale), radius * this.m_drawScale, 0, Math.PI * 2, true);
 2014  this.m_sprite.fill();
 2015  this.m_sprite.stroke();
 2016  this.m_sprite.closePath()
 2017};
 2018b2DebugDraw.prototype.DrawSegment = function(p1, p2, color) {
 2019  this.m_sprite.lineWidth = this.m_lineThickness;
 2020  this.m_sprite.strokeSyle = this.ColorStyle(color, this.m_alpha);
 2021  this.m_sprite.beginPath();
 2022  this.m_sprite.moveTo(p1.x * this.m_drawScale, this.Y(p1.y * this.m_drawScale));
 2023  this.m_sprite.lineTo(p2.x * this.m_drawScale, this.Y(p2.y * this.m_drawScale));
 2024  this.m_sprite.stroke();
 2025  this.m_sprite.closePath()
 2026};
 2027b2DebugDraw.prototype.DrawTransform = function(xf) {
 2028  this.m_sprite.lineWidth = this.m_lineThickness;
 2029  this.m_sprite.strokeSyle = this.ColorStyle(new b2Color(255, 0, 0), this.m_alpha);
 2030  this.m_sprite.beginPath();
 2031  this.m_sprite.moveTo(xf.position.x * this.m_drawScale, this.Y(xf.position.y * this.m_drawScale));
 2032  this.m_sprite.lineTo((xf.position.x + this.m_xformScale * xf.R.col1.x) * this.m_drawScale, this.Y((xf.position.y + this.m_xformScale * xf.R.col1.y) * this.m_drawScale));
 2033  this.m_sprite.stroke();
 2034  this.m_sprite.closePath();
 2035  this.m_sprite.strokeSyle = this.ColorStyle(new b2Color(0, 255, 0), this.m_alpha);
 2036  this.m_sprite.beginPath();
 2037  this.m_sprite.moveTo(xf.position.x * this.m_drawScale, this.Y(xf.position.y * this.m_drawScale));
 2038  this.m_sprite.lineTo((xf.position.x + this.m_xformScale * xf.R.col2.x) * this.m_drawScale, this.Y((xf.position.y + this.m_xformScale * xf.R.col2.y) * this.m_drawScale));
 2039  this.m_sprite.stroke();
 2040  this.m_sprite.closePath()
 2041};
 2042b2DebugDraw.prototype.m_drawFlags = 0;
 2043b2DebugDraw.prototype.m_sprite = null;
 2044b2DebugDraw.prototype.m_drawScale = 1;
 2045b2DebugDraw.prototype.m_lineThickness = 1;
 2046b2DebugDraw.prototype.m_alpha = 1;
 2047b2DebugDraw.prototype.m_fillAlpha = 1;
 2048b2DebugDraw.prototype.m_xformScale = 1;var b2Sweep = function() {
 2049  this.__varz();
 2050  this.__constructor.apply(this, arguments)
 2051};
 2052b2Sweep.prototype.__constructor = function() {
 2053};
 2054b2Sweep.prototype.__varz = function() {
 2055  this.localCenter = new b2Vec2;
 2056  this.c0 = new b2Vec2;
 2057  this.c = new b2Vec2
 2058};
 2059b2Sweep.prototype.Set = function(other) {
 2060  this.localCenter.SetV(other.localCenter);
 2061  this.c0.SetV(other.c0);
 2062  this.c.SetV(other.c);
 2063  this.a0 = other.a0;
 2064  this.a = other.a;
 2065  this.t0 = other.t0
 2066};
 2067b2Sweep.prototype.Copy = function() {
 2068  var copy = new b2Sweep;
 2069  copy.localCenter.SetV(this.localCenter);
 2070  copy.c0.SetV(this.c0);
 2071  copy.c.SetV(this.c);
 2072  copy.a0 = this.a0;
 2073  copy.a = this.a;
 2074  copy.t0 = this.t0;
 2075  return copy
 2076};
 2077b2Sweep.prototype.GetTransform = function(xf, alpha) {
 2078  xf.position.x = (1 - alpha) * this.c0.x + alpha * this.c.x;
 2079  xf.position.y = (1 - alpha) * this.c0.y + alpha * this.c.y;
 2080  var angle = (1 - alpha) * this.a0 + alpha * this.a;
 2081  xf.R.Set(angle);
 2082  var tMat = xf.R;
 2083  xf.position.x -= tMat.col1.x * this.localCenter.x + tMat.col2.x * this.localCenter.y;
 2084  xf.position.y -= tMat.col1.y * this.localCenter.x + tMat.col2.y * this.localCenter.y
 2085};
 2086b2Sweep.prototype.Advance = function(t) {
 2087  if(this.t0 < t && 1 - this.t0 > Number.MIN_VALUE) {
 2088    var alpha = (t - this.t0) / (1 - this.t0);
 2089    this.c0.x = (1 - alpha) * this.c0.x + alpha * this.c.x;
 2090    this.c0.y = (1 - alpha) * this.c0.y + alpha * this.c.y;
 2091    this.a0 = (1 - alpha) * this.a0 + alpha * this.a;
 2092    this.t0 = t
 2093  }
 2094};
 2095b2Sweep.prototype.localCenter = new b2Vec2;
 2096b2Sweep.prototype.c0 = new b2Vec2;
 2097b2Sweep.prototype.c = new b2Vec2;
 2098b2Sweep.prototype.a0 = null;
 2099b2Sweep.prototype.a = null;
 2100b2Sweep.prototype.t0 = null;var b2DistanceOutput = function() {
 2101  this.__varz();
 2102  this.__constructor.apply(this, arguments)
 2103};
 2104b2DistanceOutput.prototype.__constructor = function() {
 2105};
 2106b2DistanceOutput.prototype.__varz = function() {
 2107  this.pointA = new b2Vec2;
 2108  this.pointB = new b2Vec2
 2109};
 2110b2DistanceOutput.prototype.pointA = new b2Vec2;
 2111b2DistanceOutput.prototype.pointB = new b2Vec2;
 2112b2DistanceOutput.prototype.distance = null;
 2113b2DistanceOutput.prototype.iterations = 0;var b2Mat33 = function() {
 2114  this.__varz();
 2115  this.__constructor.apply(this, arguments)
 2116};
 2117b2Mat33.prototype.__constructor = function(c1, c2, c3) {
 2118  if(!c1 && !c2 && !c3) {
 2119    this.col1.SetZero();
 2120    this.col2.SetZero();
 2121    this.col3.SetZero()
 2122  }else {
 2123    this.col1.SetV(c1);
 2124    this.col2.SetV(c2);
 2125    this.col3.SetV(c3)
 2126  }
 2127};
 2128b2Mat33.prototype.__varz = function() {
 2129  this.col1 = new b2Vec3;
 2130  this.col2 = new b2Vec3;
 2131  this.col3 = new b2Vec3
 2132};
 2133b2Mat33.prototype.SetVVV = function(c1, c2, c3) {
 2134  this.col1.SetV(c1);
 2135  this.col2.SetV(c2);
 2136  this.col3.SetV(c3)
 2137};
 2138b2Mat33.prototype.Copy = function() {
 2139  return new b2Mat33(this.col1, this.col2, this.col3)
 2140};
 2141b2Mat33.prototype.SetM = function(m) {
 2142  this.col1.SetV(m.col1);
 2143  this.col2.SetV(m.col2);
 2144  this.col3.SetV(m.col3)
 2145};
 2146b2Mat33.prototype.AddM = function(m) {
 2147  this.col1.x += m.col1.x;
 2148  this.col1.y += m.col1.y;
 2149  this.col1.z += m.col1.z;
 2150  this.col2.x += m.col2.x;
 2151  this.col2.y += m.col2.y;
 2152  this.col2.z += m.col2.z;
 2153  this.col3.x += m.col3.x;
 2154  this.col3.y += m.col3.y;
 2155  this.col3.z += m.col3.z
 2156};
 2157b2Mat33.prototype.SetIdentity = function() {
 2158  this.col1.x = 1;
 2159  this.col2.x = 0;
 2160  this.col3.x = 0;
 2161  this.col1.y = 0;
 2162  this.col2.y = 1;
 2163  this.col3.y = 0;
 2164  this.col1.z = 0;
 2165  this.col2.z = 0;
 2166  this.col3.z = 1
 2167};
 2168b2Mat33.prototype.SetZero = function() {
 2169  this.col1.x = 0;
 2170  this.col2.x = 0;
 2171  this.col3.x = 0;
 2172  this.col1.y = 0;
 2173  this.col2.y = 0;
 2174  this.col3.y = 0;
 2175  this.col1.z = 0;
 2176  this.col2.z = 0;
 2177  this.col3.z = 0
 2178};
 2179b2Mat33.prototype.Solve22 = function(out, bX, bY) {
 2180  var a11 = this.col1.x;
 2181  var a12 = this.col2.x;
 2182  var a21 = this.col1.y;
 2183  var a22 = this.col2.y;
 2184  var det = a11 * a22 - a12 * a21;
 2185  if(det != 0) {
 2186    det = 1 / det
 2187  }
 2188  out.x = det * (a22 * bX - a12 * bY);
 2189  out.y = det * (a11 * bY - a21 * bX);
 2190  return out
 2191};
 2192b2Mat33.prototype.Solve33 = function(out, bX, bY, bZ) {
 2193  var a11 = this.col1.x;
 2194  var a21 = this.col1.y;
 2195  var a31 = this.col1.z;
 2196  var a12 = this.col2.x;
 2197  var a22 = this.col2.y;
 2198  var a32 = this.col2.z;
 2199  var a13 = this.col3.x;
 2200  var a23 = this.col3.y;
 2201  var a33 = this.col3.z;
 2202  var det = a11 * (a22 * a33 - a32 * a23) + a21 * (a32 * a13 - a12 * a33) + a31 * (a12 * a23 - a22 * a13);
 2203  if(det != 0) {
 2204    det = 1 / det
 2205  }
 2206  out.x = det * (bX * (a22 * a33 - a32 * a23) + bY * (a32 * a13 - a12 * a33) + bZ * (a12 * a23 - a22 * a13));
 2207  out.y = det * (a11 * (bY * a33 - bZ * a23) + a21 * (bZ * a13 - bX * a33) + a31 * (bX * a23 - bY * a13));
 2208  out.z = det * (a11 * (a22 * bZ - a32 * bY) + a21 * (a32 * bX - a12 * bZ) + a31 * (a12 * bY - a22 * bX));
 2209  return out
 2210};
 2211b2Mat33.prototype.col1 = new b2Vec3;
 2212b2Mat33.prototype.col2 = new b2Vec3;
 2213b2Mat33.prototype.col3 = new b2Vec3;var b2PositionSolverManifold = function() {
 2214  this.__varz();
 2215  this.__constructor.apply(this, arguments)
 2216};
 2217b2PositionSolverManifold.prototype.__constructor = function() {
 2218  this.m_normal = new b2Vec2;
 2219  this.m_separations = new Array(b2Settings.b2_maxManifoldPoints);
 2220  this.m_points = new Array(b2Settings.b2_maxManifoldPoints);
 2221  for(var i = 0;i < b2Settings.b2_maxManifoldPoints;i++) {
 2222    this.m_points[i] = new b2Vec2
 2223  }
 2224};
 2225b2PositionSolverManifold.prototype.__varz = function() {
 2226};
 2227b2PositionSolverManifold.circlePointA = new b2Vec2;
 2228b2PositionSolverManifold.circlePointB = new b2Vec2;
 2229b2PositionSolverManifold.prototype.Initialize = function(cc) {
 2230  b2Settings.b2Assert(cc.pointCount > 0);
 2231  var i = 0;
 2232  var clipPointX;
 2233  var clipPointY;
 2234  var tMat;
 2235  var tVec;
 2236  var planePointX;
 2237  var planePointY;
 2238  switch(cc.type) {
 2239    case b2Manifold.e_circles:
 2240      tMat = cc.bodyA.m_xf.R;
 2241      tVec = cc.localPoint;
 2242      var pointAX = cc.bodyA.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2243      var pointAY = cc.bodyA.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2244      tMat = cc.bodyB.m_xf.R;
 2245      tVec = cc.points[0].localPoint;
 2246      var pointBX = cc.bodyB.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2247      var pointBY = cc.bodyB.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2248      var dX = pointBX - pointAX;
 2249      var dY = pointBY - pointAY;
 2250      var d2 = dX * dX + dY * dY;
 2251      if(d2 > Number.MIN_VALUE * Number.MIN_VALUE) {
 2252        var d = Math.sqrt(d2);
 2253        this.m_normal.x = dX / d;
 2254        this.m_normal.y = dY / d
 2255      }else {
 2256        this.m_normal.x = 1;
 2257        this.m_normal.y = 0
 2258      }
 2259      this.m_points[0].x = 0.5 * (pointAX + pointBX);
 2260      this.m_points[0].y = 0.5 * (pointAY + pointBY);
 2261      this.m_separations[0] = dX * this.m_normal.x + dY * this.m_normal.y - cc.radius;
 2262      break;
 2263    case b2Manifold.e_faceA:
 2264      tMat = cc.bodyA.m_xf.R;
 2265      tVec = cc.localPlaneNormal;
 2266      this.m_normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 2267      this.m_normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 2268      tMat = cc.bodyA.m_xf.R;
 2269      tVec = cc.localPoint;
 2270      planePointX = cc.bodyA.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2271      planePointY = cc.bodyA.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2272      tMat = cc.bodyB.m_xf.R;
 2273      for(i = 0;i < cc.pointCount;++i) {
 2274        tVec = cc.points[i].localPoint;
 2275        clipPointX = cc.bodyB.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2276        clipPointY = cc.bodyB.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2277        this.m_separations[i] = (clipPointX - planePointX) * this.m_normal.x + (clipPointY - planePointY) * this.m_normal.y - cc.radius;
 2278        this.m_points[i].x = clipPointX;
 2279        this.m_points[i].y = clipPointY
 2280      }
 2281      break;
 2282    case b2Manifold.e_faceB:
 2283      tMat = cc.bodyB.m_xf.R;
 2284      tVec = cc.localPlaneNormal;
 2285      this.m_normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 2286      this.m_normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 2287      tMat = cc.bodyB.m_xf.R;
 2288      tVec = cc.localPoint;
 2289      planePointX = cc.bodyB.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2290      planePointY = cc.bodyB.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2291      tMat = cc.bodyA.m_xf.R;
 2292      for(i = 0;i < cc.pointCount;++i) {
 2293        tVec = cc.points[i].localPoint;
 2294        clipPointX = cc.bodyA.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2295        clipPointY = cc.bodyA.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2296        this.m_separations[i] = (clipPointX - planePointX) * this.m_normal.x + (clipPointY - planePointY) * this.m_normal.y - cc.radius;
 2297        this.m_points[i].Set(clipPointX, clipPointY)
 2298      }
 2299      this.m_normal.x *= -1;
 2300      this.m_normal.y *= -1;
 2301      break
 2302  }
 2303};
 2304b2PositionSolverManifold.prototype.m_normal = null;
 2305b2PositionSolverManifold.prototype.m_points = null;
 2306b2PositionSolverManifold.prototype.m_separations = null;var b2OBB = function() {
 2307  this.__varz();
 2308  this.__constructor.apply(this, arguments)
 2309};
 2310b2OBB.prototype.__constructor = function() {
 2311};
 2312b2OBB.prototype.__varz = function() {
 2313  this.R = new b2Mat22;
 2314  this.center = new b2Vec2;
 2315  this.extents = new b2Vec2
 2316};
 2317b2OBB.prototype.R = new b2Mat22;
 2318b2OBB.prototype.center = new b2Vec2;
 2319b2OBB.prototype.extents = new b2Vec2;var b2Pair = function() {
 2320  this.__varz();
 2321  this.__constructor.apply(this, arguments)
 2322};
 2323b2Pair.prototype.__constructor = function() {
 2324};
 2325b2Pair.prototype.__varz = function() {
 2326};
 2327b2Pair.b2_nullProxy = b2Settings.USHRT_MAX;
 2328b2Pair.e_pairBuffered = 1;
 2329b2Pair.e_pairRemoved = 2;
 2330b2Pair.e_pairFinal = 4;
 2331b2Pair.prototype.SetBuffered = function() {
 2332  this.status |= b2Pair.e_pairBuffered
 2333};
 2334b2Pair.prototype.ClearBuffered = function() {
 2335  this.status &= ~b2Pair.e_pairBuffered
 2336};
 2337b2Pair.prototype.IsBuffered = function() {
 2338  return(this.status & b2Pair.e_pairBuffered) == b2Pair.e_pairBuffered
 2339};
 2340b2Pair.prototype.SetRemoved = function() {
 2341  this.status |= b2Pair.e_pairRemoved
 2342};
 2343b2Pair.prototype.ClearRemoved = function() {
 2344  this.status &= ~b2Pair.e_pairRemoved
 2345};
 2346b2Pair.prototype.IsRemoved = function() {
 2347  return(this.status & b2Pair.e_pairRemoved) == b2Pair.e_pairRemoved
 2348};
 2349b2Pair.prototype.SetFinal = function() {
 2350  this.status |= b2Pair.e_pairFinal
 2351};
 2352b2Pair.prototype.IsFinal = function() {
 2353  return(this.status & b2Pair.e_pairFinal) == b2Pair.e_pairFinal
 2354};
 2355b2Pair.prototype.userData = null;
 2356b2Pair.prototype.proxy1 = null;
 2357b2Pair.prototype.proxy2 = null;
 2358b2Pair.prototype.next = null;
 2359b2Pair.prototype.status = 0;var b2FixtureDef = function() {
 2360  this.__varz();
 2361  this.__constructor.apply(this, arguments)
 2362};
 2363b2FixtureDef.prototype.__constructor = function() {
 2364  this.shape = null;
 2365  this.userData = null;
 2366  this.friction = 0.2;
 2367  this.restitution = 0;
 2368  this.density = 0;
 2369  this.filter.categoryBits = 1;
 2370  this.filter.maskBits = 65535;
 2371  this.filter.groupIndex = 0;
 2372  this.isSensor = false
 2373};
 2374b2FixtureDef.prototype.__varz = function() {
 2375  this.filter = new b2FilterData
 2376};
 2377b2FixtureDef.prototype.shape = null;
 2378b2FixtureDef.prototype.userData = null;
 2379b2FixtureDef.prototype.friction = null;
 2380b2FixtureDef.prototype.restitution = null;
 2381b2FixtureDef.prototype.density = null;
 2382b2FixtureDef.prototype.isSensor = null;
 2383b2FixtureDef.prototype.filter = new b2FilterData;var b2ContactID = function() {
 2384  this.__varz();
 2385  this.__constructor.apply(this, arguments)
 2386};
 2387b2ContactID.prototype.__constructor = function() {
 2388  this.features._m_id = this
 2389};
 2390b2ContactID.prototype.__varz = function() {
 2391  this.features = new Features
 2392};
 2393b2ContactID.prototype.Set = function(id) {
 2394  key = id._key
 2395};
 2396b2ContactID.prototype.Copy = function() {
 2397  var id = new b2ContactID;
 2398  id.key = key;
 2399  return id
 2400};
 2401b2ContactID.prototype.__defineSetter__("key", function() {
 2402  return this._key
 2403});
 2404b2ContactID.prototype.__defineSetter__("key", function(value) {
 2405  this._key = value;
 2406  this.features._referenceEdge = this._key & 255;
 2407  this.features._incidentEdge = (this._key & 65280) >> 8 & 255;
 2408  this.features._incidentVertex = (this._key & 16711680) >> 16 & 255;
 2409  this.features._flip = (this._key & 4278190080) >> 24 & 255
 2410});
 2411b2ContactID.prototype._key = 0;
 2412b2ContactID.prototype.features = new Features;var b2Transform = function() {
 2413  this.__varz();
 2414  this.__constructor.apply(this, arguments)
 2415};
 2416b2Transform.prototype.__constructor = function(pos, r) {
 2417  if(pos) {
 2418    this.position.SetV(pos);
 2419    this.R.SetM(r)
 2420  }
 2421};
 2422b2Transform.prototype.__varz = function() {
 2423  this.position = new b2Vec2;
 2424  this.R = new b2Mat22
 2425};
 2426b2Transform.prototype.Initialize = function(pos, r) {
 2427  this.position.SetV(pos);
 2428  this.R.SetM(r)
 2429};
 2430b2Transform.prototype.SetIdentity = function() {
 2431  this.position.SetZero();
 2432  this.R.SetIdentity()
 2433};
 2434b2Transform.prototype.Set = function(x) {
 2435  this.position.SetV(x.position);
 2436  this.R.SetM(x.R)
 2437};
 2438b2Transform.prototype.GetAngle = function() {
 2439  return Math.atan2(this.R.col1.y, this.R.col1.x)
 2440};
 2441b2Transform.prototype.position = new b2Vec2;
 2442b2Transform.prototype.R = new b2Mat22;var b2EdgeShape = function() {
 2443  b2Shape.prototype.__varz.call(this);
 2444  this.__varz();
 2445  this.__constructor.apply(this, arguments)
 2446};
 2447extend(b2EdgeShape.prototype, b2Shape.prototype);
 2448b2EdgeShape.prototype._super = b2Shape.prototype;
 2449b2EdgeShape.prototype.__constructor = function(v1, v2) {
 2450  this._super.__constructor.apply(this, []);
 2451  this.m_type = b2Shape.e_edgeShape;
 2452  this.m_prevEdge = null;
 2453  this.m_nextEdge = null;
 2454  this.m_v1 = v1;
 2455  this.m_v2 = v2;
 2456  this.m_direction.Set(this.m_v2.x - this.m_v1.x, this.m_v2.y - this.m_v1.y);
 2457  this.m_length = this.m_direction.Normalize();
 2458  this.m_normal.Set(this.m_direction.y, -this.m_direction.x);
 2459  this.m_coreV1.Set(-b2Settings.b2_toiSlop * (this.m_normal.x - this.m_direction.x) + this.m_v1.x, -b2Settings.b2_toiSlop * (this.m_normal.y - this.m_direction.y) + this.m_v1.y);
 2460  this.m_coreV2.Set(-b2Settings.b2_toiSlop * (this.m_normal.x + this.m_direction.x) + this.m_v2.x, -b2Settings.b2_toiSlop * (this.m_normal.y + this.m_direction.y) + this.m_v2.y);
 2461  this.m_cornerDir1 = this.m_normal;
 2462  this.m_cornerDir2.Set(-this.m_normal.x, -this.m_normal.y)
 2463};
 2464b2EdgeShape.prototype.__varz = function() {
 2465  this.s_supportVec = new b2Vec2;
 2466  this.m_v1 = new b2Vec2;
 2467  this.m_v2 = new b2Vec2;
 2468  this.m_coreV1 = new b2Vec2;
 2469  this.m_coreV2 = new b2Vec2;
 2470  this.m_normal = new b2Vec2;
 2471  this.m_direction = new b2Vec2;
 2472  this.m_cornerDir1 = new b2Vec2;
 2473  this.m_cornerDir2 = new b2Vec2
 2474};
 2475b2EdgeShape.prototype.SetPrevEdge = function(edge, core, cornerDir, convex) {
 2476  this.m_prevEdge = edge;
 2477  this.m_coreV1 = core;
 2478  this.m_cornerDir1 = cornerDir;
 2479  this.m_cornerConvex1 = convex
 2480};
 2481b2EdgeShape.prototype.SetNextEdge = function(edge, core, cornerDir, convex) {
 2482  this.m_nextEdge = edge;
 2483  this.m_coreV2 = core;
 2484  this.m_cornerDir2 = cornerDir;
 2485  this.m_cornerConvex2 = convex
 2486};
 2487b2EdgeShape.prototype.TestPoint = function(transform, p) {
 2488  return false
 2489};
 2490b2EdgeShape.prototype.RayCast = function(output, input, transform) {
 2491  var tMat;
 2492  var rX = input.p2.x - input.p1.x;
 2493  var rY = input.p2.y - input.p1.y;
 2494  tMat = transform.R;
 2495  var v1X = transform.position.x + (tMat.col1.x * this.m_v1.x + tMat.col2.x * this.m_v1.y);
 2496  var v1Y = transform.position.y + (tMat.col1.y * this.m_v1.x + tMat.col2.y * this.m_v1.y);
 2497  var nX = transform.position.y + (tMat.col1.y * this.m_v2.x + tMat.col2.y * this.m_v2.y) - v1Y;
 2498  var nY = -(transform.position.x + (tMat.col1.x * this.m_v2.x + tMat.col2.x * this.m_v2.y) - v1X);
 2499  var k_slop = 100 * Number.MIN_VALUE;
 2500  var denom = -(rX * nX + rY * nY);
 2501  if(denom > k_slop) {
 2502    var bX = input.p1.x - v1X;
 2503    var bY = input.p1.y - v1Y;
 2504    var a = bX * nX + bY * nY;
 2505    if(0 <= a && a <= input.maxFraction * denom) {
 2506      var mu2 = -rX * bY + rY * bX;
 2507      if(-k_slop * denom <= mu2 && mu2 <= denom * (1 + k_slop)) {
 2508        a /= denom;
 2509        output.fraction = a;
 2510        var nLen = Math.sqrt(nX * nX + nY * nY);
 2511        output.normal.x = nX / nLen;
 2512        output.normal.y = nY / nLen;
 2513        return true
 2514      }
 2515    }
 2516  }
 2517  return false
 2518};
 2519b2EdgeShape.prototype.ComputeAABB = function(aabb, transform) {
 2520  var tMat = transform.R;
 2521  var v1X = transform.position.x + (tMat.col1.x * this.m_v1.x + tMat.col2.x * this.m_v1.y);
 2522  var v1Y = transform.position.y + (tMat.col1.y * this.m_v1.x + tMat.col2.y * this.m_v1.y);
 2523  var v2X = transform.position.x + (tMat.col1.x * this.m_v2.x + tMat.col2.x * this.m_v2.y);
 2524  var v2Y = transform.position.y + (tMat.col1.y * this.m_v2.x + tMat.col2.y * this.m_v2.y);
 2525  if(v1X < v2X) {
 2526    aabb.lowerBound.x = v1X;
 2527    aabb.upperBound.x = v2X
 2528  }else {
 2529    aabb.lowerBound.x = v2X;
 2530    aabb.upperBound.x = v1X
 2531  }
 2532  if(v1Y < v2Y) {
 2533    aabb.lowerBound.y = v1Y;
 2534    aabb.upperBound.y = v2Y
 2535  }else {
 2536    aabb.lowerBound.y = v2Y;
 2537    aabb.upperBound.y = v1Y
 2538  }
 2539};
 2540b2EdgeShape.prototype.ComputeMass = function(massData, density) {
 2541  massData.mass = 0;
 2542  massData.center.SetV(this.m_v1);
 2543  massData.I = 0
 2544};
 2545b2EdgeShape.prototype.ComputeSubmergedArea = function(normal, offset, xf, c) {
 2546  var v0 = new b2Vec2(normal.x * offset, normal.y * offset);
 2547  var v1 = b2Math.MulX(xf, this.m_v1);
 2548  var v2 = b2Math.MulX(xf, this.m_v2);
 2549  var d1 = b2Math.Dot(normal, v1) - offset;
 2550  var d2 = b2Math.Dot(normal, v2) - offset;
 2551  if(d1 > 0) {
 2552    if(d2 > 0) {
 2553      return 0
 2554    }else {
 2555      v1.x = -d2 / (d1 - d2) * v1.x + d1 / (d1 - d2) * v2.x;
 2556      v1.y = -d2 / (d1 - d2) * v1.y + d1 / (d1 - d2) * v2.y
 2557    }
 2558  }else {
 2559    if(d2 > 0) {
 2560      v2.x = -d2 / (d1 - d2) * v1.x + d1 / (d1 - d2) * v2.x;
 2561      v2.y = -d2 / (d1 - d2) * v1.y + d1 / (d1 - d2) * v2.y
 2562    }else {
 2563    }
 2564  }
 2565  c.x = (v0.x + v1.x + v2.x) / 3;
 2566  c.y = (v0.y + v1.y + v2.y) / 3;
 2567  return 0.5 * ((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x))
 2568};
 2569b2EdgeShape.prototype.GetLength = function() {
 2570  return this.m_length
 2571};
 2572b2EdgeShape.prototype.GetVertex1 = function() {
 2573  return this.m_v1
 2574};
 2575b2EdgeShape.prototype.GetVertex2 = function() {
 2576  return this.m_v2
 2577};
 2578b2EdgeShape.prototype.GetCoreVertex1 = function() {
 2579  return this.m_coreV1
 2580};
 2581b2EdgeShape.prototype.GetCoreVertex2 = function() {
 2582  return this.m_coreV2
 2583};
 2584b2EdgeShape.prototype.GetNormalVector = function() {
 2585  return this.m_normal
 2586};
 2587b2EdgeShape.prototype.GetDirectionVector = function() {
 2588  return this.m_direction
 2589};
 2590b2EdgeShape.prototype.GetCorner1Vector = function() {
 2591  return this.m_cornerDir1
 2592};
 2593b2EdgeShape.prototype.GetCorner2Vector = function() {
 2594  return this.m_cornerDir2
 2595};
 2596b2EdgeShape.prototype.Corner1IsConvex = function() {
 2597  return this.m_cornerConvex1
 2598};
 2599b2EdgeShape.prototype.Corner2IsConvex = function() {
 2600  return this.m_cornerConvex2
 2601};
 2602b2EdgeShape.prototype.GetFirstVertex = function(xf) {
 2603  var tMat = xf.R;
 2604  return new b2Vec2(xf.position.x + (tMat.col1.x * this.m_coreV1.x + tMat.col2.x * this.m_coreV1.y), xf.position.y + (tMat.col1.y * this.m_coreV1.x + tMat.col2.y * this.m_coreV1.y))
 2605};
 2606b2EdgeShape.prototype.GetNextEdge = function() {
 2607  return this.m_nextEdge
 2608};
 2609b2EdgeShape.prototype.GetPrevEdge = function() {
 2610  return this.m_prevEdge
 2611};
 2612b2EdgeShape.prototype.Support = function(xf, dX, dY) {
 2613  var tMat = xf.R;
 2614  var v1X = xf.position.x + (tMat.col1.x * this.m_coreV1.x + tMat.col2.x * this.m_coreV1.y);
 2615  var v1Y = xf.position.y + (tMat.col1.y * this.m_coreV1.x + tMat.col2.y * this.m_coreV1.y);
 2616  var v2X = xf.position.x + (tMat.col1.x * this.m_coreV2.x + tMat.col2.x * this.m_coreV2.y);
 2617  var v2Y = xf.position.y + (tMat.col1.y * this.m_coreV2.x + tMat.col2.y * this.m_coreV2.y);
 2618  if(v1X * dX + v1Y * dY > v2X * dX + v2Y * dY) {
 2619    this.s_supportVec.x = v1X;
 2620    this.s_supportVec.y = v1Y
 2621  }else {
 2622    this.s_supportVec.x = v2X;
 2623    this.s_supportVec.y = v2Y
 2624  }
 2625  return this.s_supportVec
 2626};
 2627b2EdgeShape.prototype.s_supportVec = new b2Vec2;
 2628b2EdgeShape.prototype.m_v1 = new b2Vec2;
 2629b2EdgeShape.prototype.m_v2 = new b2Vec2;
 2630b2EdgeShape.prototype.m_coreV1 = new b2Vec2;
 2631b2EdgeShape.prototype.m_coreV2 = new b2Vec2;
 2632b2EdgeShape.prototype.m_length = null;
 2633b2EdgeShape.prototype.m_normal = new b2Vec2;
 2634b2EdgeShape.prototype.m_direction = new b2Vec2;
 2635b2EdgeShape.prototype.m_cornerDir1 = new b2Vec2;
 2636b2EdgeShape.prototype.m_cornerDir2 = new b2Vec2;
 2637b2EdgeShape.prototype.m_cornerConvex1 = null;
 2638b2EdgeShape.prototype.m_cornerConvex2 = null;
 2639b2EdgeShape.prototype.m_nextEdge = null;
 2640b2EdgeShape.prototype.m_prevEdge = null;var b2BuoyancyController = function() {
 2641  b2Controller.prototype.__varz.call(this);
 2642  this.__varz();
 2643  this.__constructor.apply(this, arguments)
 2644};
 2645extend(b2BuoyancyController.prototype, b2Controller.prototype);
 2646b2BuoyancyController.prototype._super = b2Controller.prototype;
 2647b2BuoyancyController.prototype.__constructor = function() {
 2648  this._super.__constructor.apply(this, arguments)
 2649};
 2650b2BuoyancyController.prototype.__varz = function() {
 2651  this.normal = new b2Vec2(0, -1);
 2652  this.velocity = new b2Vec2(0, 0)
 2653};
 2654b2BuoyancyController.prototype.Step = function(step) {
 2655  if(!m_bodyList) {
 2656    return
 2657  }
 2658  if(this.useWorldGravity) {
 2659    this.gravity = this.GetWorld().GetGravity().Copy()
 2660  }
 2661  for(var i = m_bodyList;i;i = i.nextBody) {
 2662    var body = i.body;
 2663    if(body.IsAwake() == false) {
 2664      continue
 2665    }
 2666    var areac = new b2Vec2;
 2667    var massc = new b2Vec2;
 2668    var area = 0;
 2669    var mass = 0;
 2670    for(var fixture = body.GetFixtureList();fixture;fixture = fixture.GetNext()) {
 2671      var sc = new b2Vec2;
 2672      var sarea = fixture.GetShape().ComputeSubmergedArea(this.normal, this.offset, body.GetTransform(), sc);
 2673      area += sarea;
 2674      areac.x += sarea * sc.x;
 2675      areac.y += sarea * sc.y;
 2676      var shapeDensity;
 2677      if(this.useDensity) {
 2678        shapeDensity = 1
 2679      }else {
 2680        shapeDensity = 1
 2681      }
 2682      mass += sarea * shapeDensity;
 2683      massc.x += sarea * sc.x * shapeDensity;
 2684      massc.y += sarea * sc.y * shapeDensity
 2685    }
 2686    areac.x /= area;
 2687    areac.y /= area;
 2688    massc.x /= mass;
 2689    massc.y /= mass;
 2690    if(area < Number.MIN_VALUE) {
 2691      continue
 2692    }
 2693    var buoyancyForce = this.gravity.GetNegative();
 2694    buoyancyForce.Multiply(this.density * area);
 2695    body.ApplyForce(buoyancyForce, massc);
 2696    var dragForce = body.GetLinearVelocityFromWorldPoint(areac);
 2697    dragForce.Subtract(this.velocity);
 2698    dragForce.Multiply(-this.linearDrag * area);
 2699    body.ApplyForce(dragForce, areac);
 2700    body.ApplyTorque(-body.GetInertia() / body.GetMass() * area * body.GetAngularVelocity() * this.angularDrag)
 2701  }
 2702};
 2703b2BuoyancyController.prototype.Draw = function(debugDraw) {
 2704  var r = 1E3;
 2705  var p1 = new b2Vec2;
 2706  var p2 = new b2Vec2;
 2707  p1.x = this.normal.x * this.offset + this.normal.y * r;
 2708  p1.y = this.normal.y * this.offset - this.normal.x * r;
 2709  p2.x = this.normal.x * this.offset - this.normal.y * r;
 2710  p2.y = this.normal.y * this.offset + this.normal.x * r;
 2711  var color = new b2Color(0, 0, 1);
 2712  debugDraw.DrawSegment(p1, p2, color)
 2713};
 2714b2BuoyancyController.prototype.normal = new b2Vec2(0, -1);
 2715b2BuoyancyController.prototype.offset = 0;
 2716b2BuoyancyController.prototype.density = 0;
 2717b2BuoyancyController.prototype.velocity = new b2Vec2(0, 0);
 2718b2BuoyancyController.prototype.linearDrag = 2;
 2719b2BuoyancyController.prototype.angularDrag = 1;
 2720b2BuoyancyController.prototype.useDensity = false;
 2721b2BuoyancyController.prototype.useWorldGravity = true;
 2722b2BuoyancyController.prototype.gravity = null;var b2Body = function() {
 2723  this.__varz();
 2724  this.__constructor.apply(this, arguments)
 2725};
 2726b2Body.prototype.__constructor = function(bd, world) {
 2727  this.m_flags = 0;
 2728  if(bd.bullet) {
 2729    this.m_flags |= b2Body.e_bulletFlag
 2730  }
 2731  if(bd.fixedRotation) {
 2732    this.m_flags |= b2Body.e_fixedRotationFlag
 2733  }
 2734  if(bd.allowSleep) {
 2735    this.m_flags |= b2Body.e_allowSleepFlag
 2736  }
 2737  if(bd.awake) {
 2738    this.m_flags |= b2Body.e_awakeFlag
 2739  }
 2740  if(bd.active) {
 2741    this.m_flags |= b2Body.e_activeFlag
 2742  }
 2743  this.m_world = world;
 2744  this.m_xf.position.SetV(bd.position);
 2745  this.m_xf.R.Set(bd.angle);
 2746  this.m_sweep.localCenter.SetZero();
 2747  this.m_sweep.t0 = 1;
 2748  this.m_sweep.a0 = this.m_sweep.a = bd.angle;
 2749  var tMat = this.m_xf.R;
 2750  var tVec = this.m_sweep.localCenter;
 2751  this.m_sweep.c.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 2752  this.m_sweep.c.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 2753  this.m_sweep.c.x += this.m_xf.position.x;
 2754  this.m_sweep.c.y += this.m_xf.position.y;
 2755  this.m_sweep.c0.SetV(this.m_sweep.c);
 2756  this.m_jointList = null;
 2757  this.m_controllerList = null;
 2758  this.m_contactList = null;
 2759  this.m_controllerCount = 0;
 2760  this.m_prev = null;
 2761  this.m_next = null;
 2762  this.m_linearVelocity.SetV(bd.linearVelocity);
 2763  this.m_angularVelocity = bd.angularVelocity;
 2764  this.m_linearDamping = bd.linearDamping;
 2765  this.m_angularDamping = bd.angularDamping;
 2766  this.m_force.Set(0, 0);
 2767  this.m_torque = 0;
 2768  this.m_sleepTime = 0;
 2769  this.m_type = bd.type;
 2770  if(this.m_type == b2Body.b2_dynamicBody) {
 2771    this.m_mass = 1;
 2772    this.m_invMass = 1
 2773  }else {
 2774    this.m_mass = 0;
 2775    this.m_invMass = 0
 2776  }
 2777  this.m_I = 0;
 2778  this.m_invI = 0;
 2779  this.m_inertiaScale = bd.inertiaScale;
 2780  this.m_userData = bd.userData;
 2781  this.m_fixtureList = null;
 2782  this.m_fixtureCount = 0
 2783};
 2784b2Body.prototype.__varz = function() {
 2785  this.m_xf = new b2Transform;
 2786  this.m_sweep = new b2Sweep;
 2787  this.m_linearVelocity = new b2Vec2;
 2788  this.m_force = new b2Vec2
 2789};
 2790b2Body.b2_staticBody = 0;
 2791b2Body.b2_kinematicBody = 1;
 2792b2Body.b2_dynamicBody = 2;
 2793b2Body.s_xf1 = new b2Transform;
 2794b2Body.e_islandFlag = 1;
 2795b2Body.e_awakeFlag = 2;
 2796b2Body.e_allowSleepFlag = 4;
 2797b2Body.e_bulletFlag = 8;
 2798b2Body.e_fixedRotationFlag = 16;
 2799b2Body.e_activeFlag = 32;
 2800b2Body.prototype.connectEdges = function(s1, s2, angle1) {
 2801  var angle2 = Math.atan2(s2.GetDirectionVector().y, s2.GetDirectionVector().x);
 2802  var coreOffset = Math.tan((angle2 - angle1) * 0.5);
 2803  var core = b2Math.MulFV(coreOffset, s2.GetDirectionVector());
 2804  core = b2Math.SubtractVV(core, s2.GetNormalVector());
 2805  core = b2Math.MulFV(b2Settings.b2_toiSlop, core);
 2806  core = b2Math.AddVV(core, s2.GetVertex1());
 2807  var cornerDir = b2Math.AddVV(s1.GetDirectionVector(), s2.GetDirectionVector());
 2808  cornerDir.Normalize();
 2809  var convex = b2Math.Dot(s1.GetDirectionVector(), s2.GetNormalVector()) > 0;
 2810  s1.SetNextEdge(s2, core, cornerDir, convex);
 2811  s2.SetPrevEdge(s1, core, cornerDir, convex);
 2812  return angle2
 2813};
 2814b2Body.prototype.SynchronizeFixtures = function() {
 2815  var xf1 = b2Body.s_xf1;
 2816  xf1.R.Set(this.m_sweep.a0);
 2817  var tMat = xf1.R;
 2818  var tVec = this.m_sweep.localCenter;
 2819  xf1.position.x = this.m_sweep.c0.x - (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2820  xf1.position.y = this.m_sweep.c0.y - (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 2821  var f;
 2822  var broadPhase = this.m_world.m_contactManager.m_broadPhase;
 2823  for(f = this.m_fixtureList;f;f = f.m_next) {
 2824    f.Synchronize(broadPhase, xf1, this.m_xf)
 2825  }
 2826};
 2827b2Body.prototype.SynchronizeTransform = function() {
 2828  this.m_xf.R.Set(this.m_sweep.a);
 2829  var tMat = this.m_xf.R;
 2830  var tVec = this.m_sweep.localCenter;
 2831  this.m_xf.position.x = this.m_sweep.c.x - (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 2832  this.m_xf.position.y = this.m_sweep.c.y - (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y)
 2833};
 2834b2Body.prototype.ShouldCollide = function(other) {
 2835  if(this.m_type != b2Body.b2_dynamicBody && other.m_type != b2Body.b2_dynamicBody) {
 2836    return false
 2837  }
 2838  for(var jn = this.m_jointList;jn;jn = jn.next) {
 2839    if(jn.other == other) {
 2840      if(jn.joint.m_collideConnected == false) {
 2841        return false
 2842      }
 2843    }
 2844  }
 2845  return true
 2846};
 2847b2Body.prototype.Advance = function(t) {
 2848  this.m_sweep.Advance(t);
 2849  this.m_sweep.c.SetV(this.m_sweep.c0);
 2850  this.m_sweep.a = this.m_sweep.a0;
 2851  this.SynchronizeTransform()
 2852};
 2853b2Body.prototype.CreateFixture = function(def) {
 2854  if(this.m_world.IsLocked() == true) {
 2855    return null
 2856  }
 2857  var fixture = new b2Fixture;
 2858  fixture.Create(this, this.m_xf, def);
 2859  if(this.m_flags & b2Body.e_activeFlag) {
 2860    var broadPhase = this.m_world.m_contactManager.m_broadPhase;
 2861    fixture.CreateProxy(broadPhase, this.m_xf)
 2862  }
 2863  fixture.m_next = this.m_fixtureList;
 2864  this.m_fixtureList = fixture;
 2865  ++this.m_fixtureCount;
 2866  fixture.m_body = this;
 2867  if(fixture.m_density > 0) {
 2868    this.ResetMassData()
 2869  }
 2870  this.m_world.m_flags |= b2World.e_newFixture;
 2871  return fixture
 2872};
 2873b2Body.prototype.CreateFixture2 = function(shape, density) {
 2874  var def = new b2FixtureDef;
 2875  def.shape = shape;
 2876  def.density = density;
 2877  return this.CreateFixture(def)
 2878};
 2879b2Body.prototype.DestroyFixture = function(fixture) {
 2880  if(this.m_world.IsLocked() == true) {
 2881    return
 2882  }
 2883  var node = this.m_fixtureList;
 2884  var ppF = null;
 2885  var found = false;
 2886  while(node != null) {
 2887    if(node == fixture) {
 2888      if(ppF) {
 2889        ppF.m_next = fixture.m_next
 2890      }else {
 2891        this.m_fixtureList = fixture.m_next
 2892      }
 2893      found = true;
 2894      break
 2895    }
 2896    ppF = node;
 2897    node = node.m_next
 2898  }
 2899  var edge = this.m_contactList;
 2900  while(edge) {
 2901    var c = edge.contact;
 2902    edge = edge.next;
 2903    var fixtureA = c.GetFixtureA();
 2904    var fixtureB = c.GetFixtureB();
 2905    if(fixture == fixtureA || fixture == fixtureB) {
 2906      this.m_world.m_contactManager.Destroy(c)
 2907    }
 2908  }
 2909  if(this.m_flags & b2Body.e_activeFlag) {
 2910    var broadPhase = this.m_world.m_contactManager.m_broadPhase;
 2911    fixture.DestroyProxy(broadPhase)
 2912  }else {
 2913  }
 2914  fixture.Destroy();
 2915  fixture.m_body = null;
 2916  fixture.m_next = null;
 2917  --this.m_fixtureCount;
 2918  this.ResetMassData()
 2919};
 2920b2Body.prototype.SetPositionAndAngle = function(position, angle) {
 2921  var f;
 2922  if(this.m_world.IsLocked() == true) {
 2923    return
 2924  }
 2925  this.m_xf.R.Set(angle);
 2926  this.m_xf.position.SetV(position);
 2927  var tMat = this.m_xf.R;
 2928  var tVec = this.m_sweep.localCenter;
 2929  this.m_sweep.c.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 2930  this.m_sweep.c.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 2931  this.m_sweep.c.x += this.m_xf.position.x;
 2932  this.m_sweep.c.y += this.m_xf.position.y;
 2933  this.m_sweep.c0.SetV(this.m_sweep.c);
 2934  this.m_sweep.a0 = this.m_sweep.a = angle;
 2935  var broadPhase = this.m_world.m_contactManager.m_broadPhase;
 2936  for(f = this.m_fixtureList;f;f = f.m_next) {
 2937    f.Synchronize(broadPhase, this.m_xf, this.m_xf)
 2938  }
 2939  this.m_world.m_contactManager.FindNewContacts()
 2940};
 2941b2Body.prototype.SetTransform = function(xf) {
 2942  this.SetPositionAndAngle(xf.position, xf.GetAngle())
 2943};
 2944b2Body.prototype.GetTransform = function() {
 2945  return this.m_xf
 2946};
 2947b2Body.prototype.GetPosition = function() {
 2948  return this.m_xf.position
 2949};
 2950b2Body.prototype.SetPosition = function(position) {
 2951  this.SetPositionAndAngle(position, this.GetAngle())
 2952};
 2953b2Body.prototype.GetAngle = function() {
 2954  return this.m_sweep.a
 2955};
 2956b2Body.prototype.SetAngle = function(angle) {
 2957  this.SetPositionAndAngle(this.GetPosition(), angle)
 2958};
 2959b2Body.prototype.GetWorldCenter = function() {
 2960  return this.m_sweep.c
 2961};
 2962b2Body.prototype.GetLocalCenter = function() {
 2963  return this.m_sweep.localCenter
 2964};
 2965b2Body.prototype.SetLinearVelocity = function(v) {
 2966  if(this.m_type == b2Body.b2_staticBody) {
 2967    return
 2968  }
 2969  this.m_linearVelocity.SetV(v)
 2970};
 2971b2Body.prototype.GetLinearVelocity = function() {
 2972  return this.m_linearVelocity
 2973};
 2974b2Body.prototype.SetAngularVelocity = function(omega) {
 2975  if(this.m_type == b2Body.b2_staticBody) {
 2976    return
 2977  }
 2978  this.m_angularVelocity = omega
 2979};
 2980b2Body.prototype.GetAngularVelocity = function() {
 2981  return this.m_angularVelocity
 2982};
 2983b2Body.prototype.GetDefinition = function() {
 2984  var bd = new b2BodyDef;
 2985  bd.type = this.GetType();
 2986  bd.allowSleep = (this.m_flags & b2Body.e_allowSleepFlag) == b2Body.e_allowSleepFlag;
 2987  bd.angle = this.GetAngle();
 2988  bd.angularDamping = this.m_angularDamping;
 2989  bd.angularVelocity = this.m_angularVelocity;
 2990  bd.fixedRotation = (this.m_flags & b2Body.e_fixedRotationFlag) == b2Body.e_fixedRotationFlag;
 2991  bd.bullet = (this.m_flags & b2Body.e_bulletFlag) == b2Body.e_bulletFlag;
 2992  bd.awake = (this.m_flags & b2Body.e_awakeFlag) == b2Body.e_awakeFlag;
 2993  bd.linearDamping = this.m_linearDamping;
 2994  bd.linearVelocity.SetV(this.GetLinearVelocity());
 2995  bd.position = this.GetPosition();
 2996  bd.userData = this.GetUserData();
 2997  return bd
 2998};
 2999b2Body.prototype.ApplyForce = function(force, point) {
 3000  if(this.m_type != b2Body.b2_dynamicBody) {
 3001    return
 3002  }
 3003  if(this.IsAwake() == false) {
 3004    this.SetAwake(true)
 3005  }
 3006  this.m_force.x += force.x;
 3007  this.m_force.y += force.y;
 3008  this.m_torque += (point.x - this.m_sweep.c.x) * force.y - (point.y - this.m_sweep.c.y) * force.x
 3009};
 3010b2Body.prototype.ApplyTorque = function(torque) {
 3011  if(this.m_type != b2Body.b2_dynamicBody) {
 3012    return
 3013  }
 3014  if(this.IsAwake() == false) {
 3015    this.SetAwake(true)
 3016  }
 3017  this.m_torque += torque
 3018};
 3019b2Body.prototype.ApplyImpulse = function(impulse, point) {
 3020  if(this.m_type != b2Body.b2_dynamicBody) {
 3021    return
 3022  }
 3023  if(this.IsAwake() == false) {
 3024    this.SetAwake(true)
 3025  }
 3026  this.m_linearVelocity.x += this.m_invMass * impulse.x;
 3027  this.m_linearVelocity.y += this.m_invMass * impulse.y;
 3028  this.m_angularVelocity += this.m_invI * ((point.x - this.m_sweep.c.x) * impulse.y - (point.y - this.m_sweep.c.y) * impulse.x)
 3029};
 3030b2Body.prototype.Split = function(callback) {
 3031  var linearVelocity = this.GetLinearVelocity().Copy();
 3032  var angularVelocity = this.GetAngularVelocity();
 3033  var center = this.GetWorldCenter();
 3034  var body1 = this;
 3035  var body2 = this.m_world.CreateBody(this.GetDefinition());
 3036  var prev;
 3037  for(var f = body1.m_fixtureList;f;) {
 3038    if(callback(f)) {
 3039      var next = f.m_next;
 3040      if(prev) {
 3041        prev.m_next = next
 3042      }else {
 3043        body1.m_fixtureList = next
 3044      }
 3045      body1.m_fixtureCount--;
 3046      f.m_next = body2.m_fixtureList;
 3047      body2.m_fixtureList = f;
 3048      body2.m_fixtureCount++;
 3049      f.m_body = body2;
 3050      f = next
 3051    }else {
 3052      prev = f;
 3053      f = f.m_next
 3054    }
 3055  }
 3056  body1.ResetMassData();
 3057  body2.ResetMassData();
 3058  var center1 = body1.GetWorldCenter();
 3059  var center2 = body2.GetWorldCenter();
 3060  var velocity1 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center1, center)));
 3061  var velocity2 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center2, center)));
 3062  body1.SetLinearVelocity(velocity1);
 3063  body2.SetLinearVelocity(velocity2);
 3064  body1.SetAngularVelocity(angularVelocity);
 3065  body2.SetAngularVelocity(angularVelocity);
 3066  body1.SynchronizeFixtures();
 3067  body2.SynchronizeFixtures();
 3068  return body2
 3069};
 3070b2Body.prototype.Merge = function(other) {
 3071  var f;
 3072  for(f = other.m_fixtureList;f;) {
 3073    var next = f.m_next;
 3074    other.m_fixtureCount--;
 3075    f.m_next = this.m_fixtureList;
 3076    this.m_fixtureList = f;
 3077    this.m_fixtureCount++;
 3078    f.m_body = body2;
 3079    f = next
 3080  }
 3081  body1.m_fixtureCount = 0;
 3082  var body1 = this;
 3083  var body2 = other;
 3084  var center1 = body1.GetWorldCenter();
 3085  var center2 = body2.GetWorldCenter();
 3086  var velocity1 = body1.GetLinearVelocity().Copy();
 3087  var velocity2 = body2.GetLinearVelocity().Copy();
 3088  var angular1 = body1.GetAngularVelocity();
 3089  var angular = body2.GetAngularVelocity();
 3090  body1.ResetMassData();
 3091  this.SynchronizeFixtures()
 3092};
 3093b2Body.prototype.GetMass = function() {
 3094  return this.m_mass
 3095};
 3096b2Body.prototype.GetInertia = function() {
 3097  return this.m_I
 3098};
 3099b2Body.prototype.GetMassData = function(data) {
 3100  data.mass = this.m_mass;
 3101  data.I = this.m_I;
 3102  data.center.SetV(this.m_sweep.localCenter)
 3103};
 3104b2Body.prototype.SetMassData = function(massData) {
 3105  b2Settings.b2Assert(this.m_world.IsLocked() == false);
 3106  if(this.m_world.IsLocked() == true) {
 3107    return
 3108  }
 3109  if(this.m_type != b2Body.b2_dynamicBody) {
 3110    return
 3111  }
 3112  this.m_invMass = 0;
 3113  this.m_I = 0;
 3114  this.m_invI = 0;
 3115  this.m_mass = massData.mass;
 3116  if(this.m_mass <= 0) {
 3117    this.m_mass = 1
 3118  }
 3119  this.m_invMass = 1 / this.m_mass;
 3120  if(massData.I > 0 && (this.m_flags & b2Body.e_fixedRotationFlag) == 0) {
 3121    this.m_I = massData.I - this.m_mass * (massData.center.x * massData.center.x + massData.center.y * massData.center.y);
 3122    this.m_invI = 1 / this.m_I
 3123  }
 3124  var oldCenter = this.m_sweep.c.Copy();
 3125  this.m_sweep.localCenter.SetV(massData.center);
 3126  this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter));
 3127  this.m_sweep.c.SetV(this.m_sweep.c0);
 3128  this.m_linearVelocity.x += this.m_angularVelocity * -(this.m_sweep.c.y - oldCenter.y);
 3129  this.m_linearVelocity.y += this.m_angularVelocity * +(this.m_sweep.c.x - oldCenter.x)
 3130};
 3131b2Body.prototype.ResetMassData = function() {
 3132  this.m_mass = 0;
 3133  this.m_invMass = 0;
 3134  this.m_I = 0;
 3135  this.m_invI = 0;
 3136  this.m_sweep.localCenter.SetZero();
 3137  if(this.m_type == b2Body.b2_staticBody || this.m_type == b2Body.b2_kinematicBody) {
 3138    return
 3139  }
 3140  var center = b2Vec2.Make(0, 0);
 3141  for(var f = this.m_fixtureList;f;f = f.m_next) {
 3142    if(f.m_density == 0) {
 3143      continue
 3144    }
 3145    var massData = f.GetMassData();
 3146    this.m_mass += massData.mass;
 3147    center.x += massData.center.x * massData.mass;
 3148    center.y += massData.center.y * massData.mass;
 3149    this.m_I += massData.I
 3150  }
 3151  if(this.m_mass > 0) {
 3152    this.m_invMass = 1 / this.m_mass;
 3153    center.x *= this.m_invMass;
 3154    center.y *= this.m_invMass
 3155  }else {
 3156    this.m_mass = 1;
 3157    this.m_invMass = 1
 3158  }
 3159  if(this.m_I > 0 && (this.m_flags & b2Body.e_fixedRotationFlag) == 0) {
 3160    this.m_I -= this.m_mass * (center.x * center.x + center.y * center.y);
 3161    this.m_I *= this.m_inertiaScale;
 3162    b2Settings.b2Assert(this.m_I > 0);
 3163    this.m_invI = 1 / this.m_I
 3164  }else {
 3165    this.m_I = 0;
 3166    this.m_invI = 0
 3167  }
 3168  var oldCenter = this.m_sweep.c.Copy();
 3169  this.m_sweep.localCenter.SetV(center);
 3170  this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter));
 3171  this.m_sweep.c.SetV(this.m_sweep.c0);
 3172  this.m_linearVelocity.x += this.m_angularVelocity * -(this.m_sweep.c.y - oldCenter.y);
 3173  this.m_linearVelocity.y += this.m_angularVelocity * +(this.m_sweep.c.x - oldCenter.x)
 3174};
 3175b2Body.prototype.GetWorldPoint = function(localPoint) {
 3176  var A = this.m_xf.R;
 3177  var u = new b2Vec2(A.col1.x * localPoint.x + A.col2.x * localPoint.y, A.col1.y * localPoint.x + A.col2.y * localPoint.y);
 3178  u.x += this.m_xf.position.x;
 3179  u.y += this.m_xf.position.y;
 3180  return u
 3181};
 3182b2Body.prototype.GetWorldVector = function(localVector) {
 3183  return b2Math.MulMV(this.m_xf.R, localVector)
 3184};
 3185b2Body.prototype.GetLocalPoint = function(worldPoint) {
 3186  return b2Math.MulXT(this.m_xf, worldPoint)
 3187};
 3188b2Body.prototype.GetLocalVector = function(worldVector) {
 3189  return b2Math.MulTMV(this.m_xf.R, worldVector)
 3190};
 3191b2Body.prototype.GetLinearVelocityFromWorldPoint = function(worldPoint) {
 3192  return new b2Vec2(this.m_linearVelocity.x - this.m_angularVelocity * (worldPoint.y - this.m_sweep.c.y), this.m_linearVelocity.y + this.m_angularVelocity * (worldPoint.x - this.m_sweep.c.x))
 3193};
 3194b2Body.prototype.GetLinearVelocityFromLocalPoint = function(localPoint) {
 3195  var A = this.m_xf.R;
 3196  var worldPoint = new b2Vec2(A.col1.x * localPoint.x + A.col2.x * localPoint.y, A.col1.y * localPoint.x + A.col2.y * localPoint.y);
 3197  worldPoint.x += this.m_xf.position.x;
 3198  worldPoint.y += this.m_xf.position.y;
 3199  return new b2Vec2(this.m_linearVelocity.x - this.m_angularVelocity * (worldPoint.y - this.m_sweep.c.y), this.m_linearVelocity.y + this.m_angularVelocity * (worldPoint.x - this.m_sweep.c.x))
 3200};
 3201b2Body.prototype.GetLinearDamping = function() {
 3202  return this.m_linearDamping
 3203};
 3204b2Body.prototype.SetLinearDamping = function(linearDamping) {
 3205  this.m_linearDamping = linearDamping
 3206};
 3207b2Body.prototype.GetAngularDamping = function() {
 3208  return this.m_angularDamping
 3209};
 3210b2Body.prototype.SetAngularDamping = function(angularDamping) {
 3211  this.m_angularDamping = angularDamping
 3212};
 3213b2Body.prototype.SetType = function(type) {
 3214  if(this.m_type == type) {
 3215    return
 3216  }
 3217  this.m_type = type;
 3218  this.ResetMassData();
 3219  if(this.m_type == b2Body.b2_staticBody) {
 3220    this.m_linearVelocity.SetZero();
 3221    this.m_angularVelocity = 0
 3222  }
 3223  this.SetAwake(true);
 3224  this.m_force.SetZero();
 3225  this.m_torque = 0;
 3226  for(var ce = this.m_contactList;ce;ce = ce.next) {
 3227    ce.contact.FlagForFiltering()
 3228  }
 3229};
 3230b2Body.prototype.GetType = function() {
 3231  return this.m_type
 3232};
 3233b2Body.prototype.SetBullet = function(flag) {
 3234  if(flag) {
 3235    this.m_flags |= b2Body.e_bulletFlag
 3236  }else {
 3237    this.m_flags &= ~b2Body.e_bulletFlag
 3238  }
 3239};
 3240b2Body.prototype.IsBullet = function() {
 3241  return(this.m_flags & b2Body.e_bulletFlag) == b2Body.e_bulletFlag
 3242};
 3243b2Body.prototype.SetSleepingAllowed = function(flag) {
 3244  if(flag) {
 3245    this.m_flags |= b2Body.e_allowSleepFlag
 3246  }else {
 3247    this.m_flags &= ~b2Body.e_allowSleepFlag;
 3248    this.SetAwake(true)
 3249  }
 3250};
 3251b2Body.prototype.SetAwake = function(flag) {
 3252  if(flag) {
 3253    this.m_flags |= b2Body.e_awakeFlag;
 3254    this.m_sleepTime = 0
 3255  }else {
 3256    this.m_flags &= ~b2Body.e_awakeFlag;
 3257    this.m_sleepTime = 0;
 3258    this.m_linearVelocity.SetZero();
 3259    this.m_angularVelocity = 0;
 3260    this.m_force.SetZero();
 3261    this.m_torque = 0
 3262  }
 3263};
 3264b2Body.prototype.IsAwake = function() {
 3265  return(this.m_flags & b2Body.e_awakeFlag) == b2Body.e_awakeFlag
 3266};
 3267b2Body.prototype.SetFixedRotation = function(fixed) {
 3268  if(fixed) {
 3269    this.m_flags |= b2Body.e_fixedRotationFlag
 3270  }else {
 3271    this.m_flags &= ~b2Body.e_fixedRotationFlag
 3272  }
 3273  this.ResetMassData()
 3274};
 3275b2Body.prototype.IsFixedRotation = function() {
 3276  return(this.m_flags & b2Body.e_fixedRotationFlag) == b2Body.e_fixedRotationFlag
 3277};
 3278b2Body.prototype.SetActive = function(flag) {
 3279  if(flag == this.IsActive()) {
 3280    return
 3281  }
 3282  var broadPhase;
 3283  var f;
 3284  if(flag) {
 3285    this.m_flags |= b2Body.e_activeFlag;
 3286    broadPhase = this.m_world.m_contactManager.m_broadPhase;
 3287    for(f = this.m_fixtureList;f;f = f.m_next) {
 3288      f.CreateProxy(broadPhase, this.m_xf)
 3289    }
 3290  }else {
 3291    this.m_flags &= ~b2Body.e_activeFlag;
 3292    broadPhase = this.m_world.m_contactManager.m_broadPhase;
 3293    for(f = this.m_fixtureList;f;f = f.m_next) {
 3294      f.DestroyProxy(broadPhase)
 3295    }
 3296    var ce = this.m_contactList;
 3297    while(ce) {
 3298      var ce0 = ce;
 3299      ce = ce.next;
 3300      this.m_world.m_contactManager.Destroy(ce0.contact)
 3301    }
 3302    this.m_contactList = null
 3303  }
 3304};
 3305b2Body.prototype.IsActive = function() {
 3306  return(this.m_flags & b2Body.e_activeFlag) == b2Body.e_activeFlag
 3307};
 3308b2Body.prototype.IsSleepingAllowed = function() {
 3309  return(this.m_flags & b2Body.e_allowSleepFlag) == b2Body.e_allowSleepFlag
 3310};
 3311b2Body.prototype.GetFixtureList = function() {
 3312  return this.m_fixtureList
 3313};
 3314b2Body.prototype.GetJointList = function() {
 3315  return this.m_jointList
 3316};
 3317b2Body.prototype.GetControllerList = function() {
 3318  return this.m_controllerList
 3319};
 3320b2Body.prototype.GetContactList = function() {
 3321  return this.m_contactList
 3322};
 3323b2Body.prototype.GetNext = function() {
 3324  return this.m_next
 3325};
 3326b2Body.prototype.GetUserData = function() {
 3327  return this.m_userData
 3328};
 3329b2Body.prototype.SetUserData = function(data) {
 3330  this.m_userData = data
 3331};
 3332b2Body.prototype.GetWorld = function() {
 3333  return this.m_world
 3334};
 3335b2Body.prototype.m_flags = 0;
 3336b2Body.prototype.m_type = 0;
 3337b2Body.prototype.m_islandIndex = 0;
 3338b2Body.prototype.m_xf = new b2Transform;
 3339b2Body.prototype.m_sweep = new b2Sweep;
 3340b2Body.prototype.m_linearVelocity = new b2Vec2;
 3341b2Body.prototype.m_angularVelocity = null;
 3342b2Body.prototype.m_force = new b2Vec2;
 3343b2Body.prototype.m_torque = null;
 3344b2Body.prototype.m_world = null;
 3345b2Body.prototype.m_prev = null;
 3346b2Body.prototype.m_next = null;
 3347b2Body.prototype.m_fixtureList = null;
 3348b2Body.prototype.m_fixtureCount = 0;
 3349b2Body.prototype.m_controllerList = null;
 3350b2Body.prototype.m_controllerCount = 0;
 3351b2Body.prototype.m_jointList = null;
 3352b2Body.prototype.m_contactList = null;
 3353b2Body.prototype.m_mass = null;
 3354b2Body.prototype.m_invMass = null;
 3355b2Body.prototype.m_I = null;
 3356b2Body.prototype.m_invI = null;
 3357b2Body.prototype.m_inertiaScale = null;
 3358b2Body.prototype.m_linearDamping = null;
 3359b2Body.prototype.m_angularDamping = null;
 3360b2Body.prototype.m_sleepTime = null;
 3361b2Body.prototype.m_userData = null;var b2ContactImpulse = function() {
 3362  this.__varz();
 3363  this.__constructor.apply(this, arguments)
 3364};
 3365b2ContactImpulse.prototype.__constructor = function() {
 3366};
 3367b2ContactImpulse.prototype.__varz = function() {
 3368  this.normalImpulses = new Array(b2Settings.b2_maxManifoldPoints);
 3369  this.tangentImpulses = new Array(b2Settings.b2_maxManifoldPoints)
 3370};
 3371b2ContactImpulse.prototype.normalImpulses = new Array(b2Settings.b2_maxManifoldPoints);
 3372b2ContactImpulse.prototype.tangentImpulses = new Array(b2Settings.b2_maxManifoldPoints);var b2TensorDampingController = function() {
 3373  b2Controller.prototype.__varz.call(this);
 3374  this.__varz();
 3375  this.__constructor.apply(this, arguments)
 3376};
 3377extend(b2TensorDampingController.prototype, b2Controller.prototype);
 3378b2TensorDampingController.prototype._super = b2Controller.prototype;
 3379b2TensorDampingController.prototype.__constructor = function() {
 3380  this._super.__constructor.apply(this, arguments)
 3381};
 3382b2TensorDampingController.prototype.__varz = function() {
 3383  this.T = new b2Mat22
 3384};
 3385b2TensorDampingController.prototype.SetAxisAligned = function(xDamping, yDamping) {
 3386  this.T.col1.x = -xDamping;
 3387  this.T.col1.y = 0;
 3388  this.T.col2.x = 0;
 3389  this.T.col2.y = -yDamping;
 3390  if(xDamping > 0 || yDamping > 0) {
 3391    this.maxTimestep = 1 / Math.max(xDamping, yDamping)
 3392  }else {
 3393    this.maxTimestep = 0
 3394  }
 3395};
 3396b2TensorDampingController.prototype.Step = function(step) {
 3397  var timestep = step.dt;
 3398  if(timestep <= Number.MIN_VALUE) {
 3399    return
 3400  }
 3401  if(timestep > this.maxTimestep && this.maxTimestep > 0) {
 3402    timestep = this.maxTimestep
 3403  }
 3404  for(var i = m_bodyList;i;i = i.nextBody) {
 3405    var body = i.body;
 3406    if(!body.IsAwake()) {
 3407      continue
 3408    }
 3409    var damping = body.GetWorldVector(b2Math.MulMV(this.T, body.GetLocalVector(body.GetLinearVelocity())));
 3410    body.SetLinearVelocity(new b2Vec2(body.GetLinearVelocity().x + damping.x * timestep, body.GetLinearVelocity().y + damping.y * timestep))
 3411  }
 3412};
 3413b2TensorDampingController.prototype.T = new b2Mat22;
 3414b2TensorDampingController.prototype.maxTimestep = 0;var b2ManifoldPoint = function() {
 3415  this.__varz();
 3416  this.__constructor.apply(this, arguments)
 3417};
 3418b2ManifoldPoint.prototype.__constructor = function() {
 3419  this.Reset()
 3420};
 3421b2ManifoldPoint.prototype.__varz = function() {
 3422  this.m_localPoint = new b2Vec2;
 3423  this.m_id = new b2ContactID
 3424};
 3425b2ManifoldPoint.prototype.Reset = function() {
 3426  this.m_localPoint.SetZero();
 3427  this.m_normalImpulse = 0;
 3428  this.m_tangentImpulse = 0;
 3429  this.m_id.key = 0
 3430};
 3431b2ManifoldPoint.prototype.Set = function(m) {
 3432  this.m_localPoint.SetV(m.m_localPoint);
 3433  this.m_normalImpulse = m.m_normalImpulse;
 3434  this.m_tangentImpulse = m.m_tangentImpulse;
 3435  this.m_id.Set(m.m_id)
 3436};
 3437b2ManifoldPoint.prototype.m_localPoint = new b2Vec2;
 3438b2ManifoldPoint.prototype.m_normalImpulse = null;
 3439b2ManifoldPoint.prototype.m_tangentImpulse = null;
 3440b2ManifoldPoint.prototype.m_id = new b2ContactID;var b2PolygonShape = function() {
 3441  b2Shape.prototype.__varz.call(this);
 3442  this.__varz();
 3443  this.__constructor.apply(this, arguments)
 3444};
 3445extend(b2PolygonShape.prototype, b2Shape.prototype);
 3446b2PolygonShape.prototype._super = b2Shape.prototype;
 3447b2PolygonShape.prototype.__constructor = function() {
 3448  this._super.__constructor.apply(this, arguments);
 3449  this.m_type = b2Shape.e_polygonShape;
 3450  this.m_centroid = new b2Vec2;
 3451  this.m_vertices = new Array;
 3452  this.m_normals = new Array
 3453};
 3454b2PolygonShape.prototype.__varz = function() {
 3455};
 3456b2PolygonShape.AsArray = function(vertices, vertexCount) {
 3457  var polygonShape = new b2PolygonShape;
 3458  polygonShape.SetAsArray(vertices, vertexCount);
 3459  return polygonShape
 3460};
 3461b2PolygonShape.AsVector = function(vertices, vertexCount) {
 3462  var polygonShape = new b2PolygonShape;
 3463  polygonShape.SetAsVector(vertices, vertexCount);
 3464  return polygonShape
 3465};
 3466b2PolygonShape.AsBox = function(hx, hy) {
 3467  var polygonShape = new b2PolygonShape;
 3468  polygonShape.SetAsBox(hx, hy);
 3469  return polygonShape
 3470};
 3471b2PolygonShape.AsOrientedBox = function(hx, hy, center, angle) {
 3472  var polygonShape = new b2PolygonShape;
 3473  polygonShape.SetAsOrientedBox(hx, hy, center, angle);
 3474  return polygonShape
 3475};
 3476b2PolygonShape.AsEdge = function(v1, v2) {
 3477  var polygonShape = new b2PolygonShape;
 3478  polygonShape.SetAsEdge(v1, v2);
 3479  return polygonShape
 3480};
 3481b2PolygonShape.ComputeCentroid = function(vs, count) {
 3482  var c = new b2Vec2;
 3483  var area = 0;
 3484  var p1X = 0;
 3485  var p1Y = 0;
 3486  var inv3 = 1 / 3;
 3487  for(var i = 0;i < count;++i) {
 3488    var p2 = vs[i];
 3489    var p3 = i + 1 < count ? vs[parseInt(i + 1)] : vs[0];
 3490    var e1X = p2.x - p1X;
 3491    var e1Y = p2.y - p1Y;
 3492    var e2X = p3.x - p1X;
 3493    var e2Y = p3.y - p1Y;
 3494    var D = e1X * e2Y - e1Y * e2X;
 3495    var triangleArea = 0.5 * D;
 3496    area += triangleArea;
 3497    c.x += triangleArea * inv3 * (p1X + p2.x + p3.x);
 3498    c.y += triangleArea * inv3 * (p1Y + p2.y + p3.y)
 3499  }
 3500  c.x *= 1 / area;
 3501  c.y *= 1 / area;
 3502  return c
 3503};
 3504b2PolygonShape.ComputeOBB = function(obb, vs, count) {
 3505  var i = 0;
 3506  var p = new Array(count + 1);
 3507  for(i = 0;i < count;++i) {
 3508    p[i] = vs[i]
 3509  }
 3510  p[count] = p[0];
 3511  var minArea = Number.MAX_VALUE;
 3512  for(i = 1;i <= count;++i) {
 3513    var root = p[parseInt(i - 1)];
 3514    var uxX = p[i].x - root.x;
 3515    var uxY = p[i].y - root.y;
 3516    var length = Math.sqrt(uxX * uxX + uxY * uxY);
 3517    uxX /= length;
 3518    uxY /= length;
 3519    var uyX = -uxY;
 3520    var uyY = uxX;
 3521    var lowerX = Number.MAX_VALUE;
 3522    var lowerY = Number.MAX_VALUE;
 3523    var upperX = -Number.MAX_VALUE;
 3524    var upperY = -Number.MAX_VALUE;
 3525    for(var j = 0;j < count;++j) {
 3526      var dX = p[j].x - root.x;
 3527      var dY = p[j].y - root.y;
 3528      var rX = uxX * dX + uxY * dY;
 3529      var rY = uyX * dX + uyY * dY;
 3530      if(rX < lowerX) {
 3531        lowerX = rX
 3532      }
 3533      if(rY < lowerY) {
 3534        lowerY = rY
 3535      }
 3536      if(rX > upperX) {
 3537        upperX = rX
 3538      }
 3539      if(rY > upperY) {
 3540        upperY = rY
 3541      }
 3542    }
 3543    var area = (upperX - lowerX) * (upperY - lowerY);
 3544    if(area < 0.95 * minArea) {
 3545      minArea = area;
 3546      obb.R.col1.x = uxX;
 3547      obb.R.col1.y = uxY;
 3548      obb.R.col2.x = uyX;
 3549      obb.R.col2.y = uyY;
 3550      var centerX = 0.5 * (lowerX + upperX);
 3551      var centerY = 0.5 * (lowerY + upperY);
 3552      var tMat = obb.R;
 3553      obb.center.x = root.x + (tMat.col1.x * centerX + tMat.col2.x * centerY);
 3554      obb.center.y = root.y + (tMat.col1.y * centerX + tMat.col2.y * centerY);
 3555      obb.extents.x = 0.5 * (upperX - lowerX);
 3556      obb.extents.y = 0.5 * (upperY - lowerY)
 3557    }
 3558  }
 3559};
 3560b2PolygonShape.s_mat = new b2Mat22;
 3561b2PolygonShape.prototype.Validate = function() {
 3562  return false
 3563};
 3564b2PolygonShape.prototype.Reserve = function(count) {
 3565  for(var i = this.m_vertices.length;i < count;i++) {
 3566    this.m_vertices[i] = new b2Vec2;
 3567    this.m_normals[i] = new b2Vec2
 3568  }
 3569};
 3570b2PolygonShape.prototype.Copy = function() {
 3571  var s = new b2PolygonShape;
 3572  s.Set(this);
 3573  return s
 3574};
 3575b2PolygonShape.prototype.Set = function(other) {
 3576  this._super.Set.apply(this, [other]);
 3577  if(isInstanceOf(other, b2PolygonShape)) {
 3578    var other2 = other;
 3579    this.m_centroid.SetV(other2.m_centroid);
 3580    this.m_vertexCount = other2.m_vertexCount;
 3581    this.Reserve(this.m_vertexCount);
 3582    for(var i = 0;i < this.m_vertexCount;i++) {
 3583      this.m_vertices[i].SetV(other2.m_vertices[i]);
 3584      this.m_normals[i].SetV(other2.m_normals[i])
 3585    }
 3586  }
 3587};
 3588b2PolygonShape.prototype.SetAsArray = function(vertices, vertexCount) {
 3589  var v = new Array;
 3590  for(var i = 0, tVec = null;i < vertices.length, tVec = vertices[i];i++) {
 3591    v.push(tVec)
 3592  }
 3593  this.SetAsVector(v, vertexCount)
 3594};
 3595b2PolygonShape.prototype.SetAsVector = function(vertices, vertexCount) {
 3596  if(typeof vertexCount == "undefined") {
 3597    vertexCount = vertices.length
 3598  }
 3599  b2Settings.b2Assert(2 <= vertexCount);
 3600  this.m_vertexCount = vertexCount;
 3601  this.Reserve(vertexCount);
 3602  var i = 0;
 3603  for(i = 0;i < this.m_vertexCount;i++) {
 3604    this.m_vertices[i].SetV(vertices[i])
 3605  }
 3606  for(i = 0;i < this.m_vertexCount;++i) {
 3607    var i1 = i;
 3608    var i2 = i + 1 < this.m_vertexCount ? i + 1 : 0;
 3609    var edge = b2Math.SubtractVV(this.m_vertices[i2], this.m_vertices[i1]);
 3610    b2Settings.b2Assert(edge.LengthSquared() > Number.MIN_VALUE);
 3611    this.m_normals[i].SetV(b2Math.CrossVF(edge, 1));
 3612    this.m_normals[i].Normalize()
 3613  }
 3614  this.m_centroid = b2PolygonShape.ComputeCentroid(this.m_vertices, this.m_vertexCount)
 3615};
 3616b2PolygonShape.prototype.SetAsBox = function(hx, hy) {
 3617  this.m_vertexCount = 4;
 3618  this.Reserve(4);
 3619  this.m_vertices[0].Set(-hx, -hy);
 3620  this.m_vertices[1].Set(hx, -hy);
 3621  this.m_vertices[2].Set(hx, hy);
 3622  this.m_vertices[3].Set(-hx, hy);
 3623  this.m_normals[0].Set(0, -1);
 3624  this.m_normals[1].Set(1, 0);
 3625  this.m_normals[2].Set(0, 1);
 3626  this.m_normals[3].Set(-1, 0);
 3627  this.m_centroid.SetZero()
 3628};
 3629b2PolygonShape.prototype.SetAsOrientedBox = function(hx, hy, center, angle) {
 3630  this.m_vertexCount = 4;
 3631  this.Reserve(4);
 3632  this.m_vertices[0].Set(-hx, -hy);
 3633  this.m_vertices[1].Set(hx, -hy);
 3634  this.m_vertices[2].Set(hx, hy);
 3635  this.m_vertices[3].Set(-hx, hy);
 3636  this.m_normals[0].Set(0, -1);
 3637  this.m_normals[1].Set(1, 0);
 3638  this.m_normals[2].Set(0, 1);
 3639  this.m_normals[3].Set(-1, 0);
 3640  this.m_centroid = center;
 3641  var xf = new b2Transform;
 3642  xf.position = center;
 3643  xf.R.Set(angle);
 3644  for(var i = 0;i < this.m_vertexCount;++i) {
 3645    this.m_vertices[i] = b2Math.MulX(xf, this.m_vertices[i]);
 3646    this.m_normals[i] = b2Math.MulMV(xf.R, this.m_normals[i])
 3647  }
 3648};
 3649b2PolygonShape.prototype.SetAsEdge = function(v1, v2) {
 3650  this.m_vertexCount = 2;
 3651  this.Reserve(2);
 3652  this.m_vertices[0].SetV(v1);
 3653  this.m_vertices[1].SetV(v2);
 3654  this.m_centroid.x = 0.5 * (v1.x + v2.x);
 3655  this.m_centroid.y = 0.5 * (v1.y + v2.y);
 3656  this.m_normals[0] = b2Math.CrossVF(b2Math.SubtractVV(v2, v1), 1);
 3657  this.m_normals[0].Normalize();
 3658  this.m_normals[1].x = -this.m_normals[0].x;
 3659  this.m_normals[1].y = -this.m_normals[0].y
 3660};
 3661b2PolygonShape.prototype.TestPoint = function(xf, p) {
 3662  var tVec;
 3663  var tMat = xf.R;
 3664  var tX = p.x - xf.position.x;
 3665  var tY = p.y - xf.position.y;
 3666  var pLocalX = tX * tMat.col1.x + tY * tMat.col1.y;
 3667  var pLocalY = tX * tMat.col2.x + tY * tMat.col2.y;
 3668  for(var i = 0;i < this.m_vertexCount;++i) {
 3669    tVec = this.m_vertices[i];
 3670    tX = pLocalX - tVec.x;
 3671    tY = pLocalY - tVec.y;
 3672    tVec = this.m_normals[i];
 3673    var dot = tVec.x * tX + tVec.y * tY;
 3674    if(dot > 0) {
 3675      return false
 3676    }
 3677  }
 3678  return true
 3679};
 3680b2PolygonShape.prototype.RayCast = function(output, input, transform) {
 3681  var lower = 0;
 3682  var upper = input.maxFraction;
 3683  var tX;
 3684  var tY;
 3685  var tMat;
 3686  var tVec;
 3687  tX = input.p1.x - transform.position.x;
 3688  tY = input.p1.y - transform.position.y;
 3689  tMat = transform.R;
 3690  var p1X = tX * tMat.col1.x + tY * tMat.col1.y;
 3691  var p1Y = tX * tMat.col2.x + tY * tMat.col2.y;
 3692  tX = input.p2.x - transform.position.x;
 3693  tY = input.p2.y - transform.position.y;
 3694  tMat = transform.R;
 3695  var p2X = tX * tMat.col1.x + tY * tMat.col1.y;
 3696  var p2Y = tX * tMat.col2.x + tY * tMat.col2.y;
 3697  var dX = p2X - p1X;
 3698  var dY = p2Y - p1Y;
 3699  var index = -1;
 3700  for(var i = 0;i < this.m_vertexCount;++i) {
 3701    tVec = this.m_vertices[i];
 3702    tX = tVec.x - p1X;
 3703    tY = tVec.y - p1Y;
 3704    tVec = this.m_normals[i];
 3705    var numerator = tVec.x * tX + tVec.y * tY;
 3706    var denominator = tVec.x * dX + tVec.y * dY;
 3707    if(denominator == 0) {
 3708      if(numerator < 0) {
 3709        return false
 3710      }
 3711    }else {
 3712      if(denominator < 0 && numerator < lower * denominator) {
 3713        lower = numerator / denominator;
 3714        index = i
 3715      }else {
 3716        if(denominator > 0 && numerator < upper * denominator) {
 3717          upper = numerator / denominator
 3718        }
 3719      }
 3720    }
 3721    if(upper < lower - Number.MIN_VALUE) {
 3722      return false
 3723    }
 3724  }
 3725  if(index >= 0) {
 3726    output.fraction = lower;
 3727    tMat = transform.R;
 3728    tVec = this.m_normals[index];
 3729    output.normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
 3730    output.normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
 3731    return true
 3732  }
 3733  return false
 3734};
 3735b2PolygonShape.prototype.ComputeAABB = function(aabb, xf) {
 3736  var tMat = xf.R;
 3737  var tVec = this.m_vertices[0];
 3738  var lowerX = xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 3739  var lowerY = xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 3740  var upperX = lowerX;
 3741  var upperY = lowerY;
 3742  for(var i = 1;i < this.m_vertexCount;++i) {
 3743    tVec = this.m_vertices[i];
 3744    var vX = xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
 3745    var vY = xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
 3746    lowerX = lowerX < vX ? lowerX : vX;
 3747    lowerY = lowerY < vY ? lowerY : vY;
 3748    upperX = upperX > vX ? upperX : vX;
 3749    upperY = upperY > vY ? upperY : vY
 3750  }
 3751  aabb.lowerBound.x = lowerX - this.m_radius;
 3752  aabb.lowerBound.y = lowerY - this.m_radius;
 3753  aabb.upperBound.x = upperX + this.m_radius;
 3754  aabb.upperBound.y = upperY + this.m_radius
 3755};
 3756b2PolygonShape.prototype.ComputeMass = function(massData, density) {
 3757  if(this.m_vertexCount == 2) {
 3758    massData.center.x = 0.5 * (this.m_vertices[0].x + this.m_vertices[1].x);
 3759    massData.center.y = 0.5 * (this.m_vertices[0].y + this.m_vertices[1].y);
 3760    massData.mass = 0;
 3761    massData.I = 0;
 3762    return
 3763  }
 3764  var centerX = 0;
 3765  var centerY = 0;
 3766  var area = 0;
 3767  var I = 0;
 3768  var p1X = 0;
 3769  var p1Y = 0;
 3770  var k_inv3 = 1 / 3;
 3771  for(var i = 0;i < this.m_vertexCount;++i) {
 3772    var p2 = this.m_vertices[i];
 3773    var p3 = i + 1 < this.m_vertexCount ? this.m_vertices[parseInt(i + 1)] : this.m_vertices[0];
 3774    var e1X = p2.x - p1X;
 3775    var e1Y = p2.y - p1Y;
 3776    var e2X = p3.x - p1X;
 3777    var e2Y = p3.y - p1Y;
 3778    var D = e1X * e2Y - e1Y * e2X;
 3779    var triangleArea = 0.5 * D;
 3780    area += triangleArea;
 3781    centerX += triangleArea * k_inv3 * (p1X + p2.x + p3.x);
 3782    centerY += triangleArea * k_inv3 * (p1Y + p2.y + p3.y);
 3783    var px = p1X;
 3784    var py = p1Y;
 3785    var ex1 = e1X;
 3786    var ey1 = e1Y;
 3787    var ex2 = e2X;
 3788    var ey2 = e2Y;
 3789    var intx2 = k_inv3 * (0.25 * (ex1 * ex1 + ex2 * ex1 + ex2 * ex2) + (px * ex1 + px * ex2)) + 0.5 * px * px;
 3790    var inty2 = k_inv3 * (0.25 * (ey1 * ey1 + ey2 * ey1 + ey2 * ey2) + (py * ey1 + py * ey2)) + 0.5 * py * py;
 3791    I += D * (intx2 + inty2)
 3792  }
 3793  massData.mass = density * area;
 3794  centerX *= 1 / area;
 3795  centerY *= 1 / area;
 3796  massData.center.Set(centerX, centerY);
 3797  massData.I = density * I
 3798};
 3799b2PolygonShape.prototype.ComputeSubmergedArea = function(normal, offset, xf, c) {
 3800  var normalL = b2Math.MulTMV(xf.R, normal);
 3801  var offsetL = offset - b2Math.Dot(normal, xf.position);
 3802  var depths = new Array;
 3803  var diveCount = 0;
 3804  var intoIndex = -1;
 3805  var outoIndex = -1;
 3806  var lastSubmerged = false;
 3807  var i = 0;
 3808  for(i = 0;i < this.m_vertexCount;++i) {
 3809    depths[i] = b2Math.Dot(normalL, this.m_vertices[i]) - offsetL;
 3810    var isSubmerged = depths[i] < -Number.MIN_VALUE;
 3811    if(i > 0) {
 3812      if(isSubmerged) {
 3813        if(!lastSubmerged) {
 3814          intoIndex = i - 1;
 3815          diveCount++
 3816        }
 3817      }else {
 3818        if(lastSubmerged) {
 3819          outoIndex = i - 1;
 3820          diveCount++
 3821        }
 3822      }
 3823    }
 3824    lastSubmerged = isSubmerged
 3825  }
 3826  switch(diveCount) {
 3827    case 0:
 3828      if(lastSubmerged) {
 3829        var md = new b2MassData;
 3830        this.ComputeMass(md, 1);
 3831        c.SetV(b2Math.MulX(xf, md.center));
 3832        return md.mass
 3833      }else {
 3834        return 0
 3835      }
 3836      break;
 3837    case 1:
 3838      if(intoIndex == -1) {
 3839        intoIndex = this.m_vertexCount - 1
 3840      }else {
 3841        outoIndex = this.m_vertexCount - 1
 3842      }
 3843      break
 3844  }
 3845  var intoIndex2 = (intoIndex + 1) % this.m_vertexCount;
 3846  var outoIndex2 = (outoIndex + 1) % this.m_vertexCount;
 3847  var intoLamdda = (0 - depths[intoIndex]) / (depths[intoIndex2] - depths[intoIndex]);
 3848  var outoLamdda = (0 - depths[outoIndex]) / (depths[outoIndex2] - depths[outoIndex]);
 3849  var intoVec = new b2Vec2(this.m_vertices[intoIndex].x * (1 - intoLamdda) + this.m_vertices[intoIndex2].x * intoLamdda, this.m_vertices[intoIndex].y * (1 - intoLamdda) + this.m_vertices[intoIndex2].y * intoLamdda);
 3850  var outoVec = new b2Vec2(this.m_vertices[outoIndex].x * (1 - outoLamdda) + this.m_vertices[outoIndex2].x * outoLamdda, this.m_vertices[outoIndex].y * (1 - outoLamdda) + this.m_vertices[outoIndex2].y * outoLamdda);
 3851  var area = 0;
 3852  var center = new b2Vec2;
 3853  var p2 = this.m_vertices[intoIndex2];
 3854  var p3;
 3855  i = intoIndex2;
 3856  while(i != outoIndex2) {
 3857    i = (i + 1) % this.m_vertexCount;
 3858    if(i == outoIndex2) {
 3859      p3 = outoVec
 3860    }else {
 3861      p3 = this.m_vertices[i]
 3862    }
 3863    var triangleArea = 0.5 * ((p2.x - intoVec.x) * (p3.y - intoVec.y) - (p2.y - intoVec.y) * (p3.x - intoVec.x));
 3864    area += triangleArea;
 3865    center.x += triangleArea * (intoVec.x + p2.x + p3.x) / 3;
 3866    center.y += triangleArea * (intoVec.y + p2.y + p3.y) / 3;
 3867    p2 = p3
 3868  }
 3869  center.Multiply(1 / area);
 3870  c.SetV(b2Math.MulX(xf, center));
 3871  return area
 3872};
 3873b2PolygonShape.prototype.GetVertexCount = function() {
 3874  return this.m_vertexCount
 3875};
 3876b2PolygonShape.prototype.GetVertices = function() {
 3877  return this.m_vertices
 3878};
 3879b2PolygonShape.prototype.GetNormals = function() {
 3880  return this.m_normals
 3881};
 3882b2PolygonShape.prototype.GetSupport = function(d) {
 3883  var bestIndex = 0;
 3884  var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
 3885  for(var i = 1;i < this.m_vertexCount;++i) {
 3886    var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
 3887    if(value > bestValue) {
 3888      bestIndex = i;
 3889      bestValue = value
 3890    }
 3891  }
 3892  return bestIndex
 3893};
 3894b2PolygonShape.prototype.GetSupportVertex = function(d) {
 3895  var bestIndex = 0;
 3896  var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;
 3897  for(var i = 1;i < this.m_vertexCount;++i) {
 3898    var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;
 3899    if(value > bestValue) {
 3900      bestIndex = i;
 3901      bestValue = value
 3902    }
 3903  }
 3904  return this.m_vertices[bestIndex]
 3905};
 3906b2PolygonShape.prototype.m_centroid = null;
 3907b2PolygonShape.prototype.m_vertices = null;
 3908b2PolygonShape.prototype.m_normals = null;
 3909b2PolygonShape.prototype.m_vertexCount = 0;var b2Fixture = function() {
 3910  this.__varz();
 3911  this.__constructor.apply(this, arguments)
 3912};
 3913b2Fixture.prototype.__constructor = function() {
 3914  this.m_aabb = new b2AABB;
 3915  this.m_userData = null;
 3916  this.m_body = null;
 3917  this.m_next = null;
 3918  this.m_shape = null;
 3919  this.m_density = 0;
 3920  this.m_friction = 0;