lib/shape/CollidePolygon.js
function FindMaxSeparation(poly1, xf1, poly2, xf2) {
  var count1 = poly1.m_count;
  var count2 = poly2.m_count;
  var n1s = poly1.m_normals;
  var v1s = poly1.m_vertices;
  var v2s = poly2.m_vertices;
  var xf = Transform.mulTXf(xf2, xf1);

  var bestIndex = 0;
  var maxSeparation = -Infinity;
  for (var i = 0; i < count1; ++i) {
    // Get poly1 normal in frame2.
    var n = Rot.mulVec2(xf.q, n1s[i]);
    var v1 = Transform.mulVec2(xf, v1s[i]);

    // Find deepest point for normal i.
    var si = Infinity;
    for (var j = 0; j < count2; ++j) {
      var sij = Vec2.dot(n, v2s[j]) - Vec2.dot(n, v1);
      if (sij < si) {
        si = sij;
      }
    }

    if (si > maxSeparation) {
      maxSeparation = si;
      bestIndex = i;
    }
  }

  // used to keep last FindMaxSeparation call values
  FindMaxSeparation._maxSeparation = maxSeparation;
  FindMaxSeparation._bestIndex = bestIndex;
}
function FindMaxSeparation(poly1, xf1, poly2, xf2) {
  var count1 = poly1.m_count;
  var count2 = poly2.m_count;
  var n1s = poly1.m_normals;
  var v1s = poly1.m_vertices;
  var v2s = poly2.m_vertices;
  var xf = Transform.mulTXf(xf2, xf1);

  var bestIndex = 0;
  var maxSeparation = -Infinity;
  for (var i = 0; i < count1; ++i) {
    // Get poly1 normal in frame2.
    var n = Rot.mulVec2(xf.q, n1s[i]);
    var v1 = Transform.mulVec2(xf, v1s[i]);

    // Find deepest point for normal i.
    var si = Infinity;
    for (var j = 0; j < count2; ++j) {
      var sij = Vec2.dot(n, v2s[j]) - Vec2.dot(n, v1);
      if (sij < si) {
        si = sij;
      }
    }

    if (si > maxSeparation) {
      maxSeparation = si;
      bestIndex = i;
    }
  }

  // used to keep last FindMaxSeparation call values
  FindMaxSeparation._maxSeparation = maxSeparation;
  FindMaxSeparation._bestIndex = bestIndex;
}
function FindMaxSeparation ( poly1 , xf1 , poly2 , xf2 ) { var count1 = poly1 . m_count ; var count2 = poly2 . m_count ; var n1s = poly1 . m_normals ; var v1s = poly1 . m_vertices ; var v2s = poly2 . m_vertices ; var xf = Transform . mulTXf ( xf2 , xf1 ) ; var bestIndex = 0 ; var maxSeparation = - Infinity ; for ( var i = 0 ; i < count1 ; ++ i ) { // Get poly1 normal in frame2. var n = Rot . mulVec2 ( xf . q , n1s [ i ] ) ; var v1 = Transform . mulVec2 ( xf , v1s [ i ] ) ; // Find deepest point for normal i. var si = Infinity ; for ( var j = 0 ; j < count2 ; ++ j ) { var sij = Vec2 . dot ( n , v2s [ j ] ) - Vec2 . dot ( n , v1 ) ; if ( sij < si ) { si = sij ; } } if ( si > maxSeparation ) { maxSeparation = si ; bestIndex = i ; } } // used to keep last FindMaxSeparation call values FindMaxSeparation . _maxSeparation = maxSeparation ; FindMaxSeparation . _bestIndex = bestIndex ; }
Find the max separation between poly1 and poly2 using edge normals from
poly1.
Find the max separation between poly1 and poly2 using edge normals from poly1 .