computePolygonSeparation method

void computePolygonSeparation(
  1. EPAxis axis
)

Implementation

void computePolygonSeparation(EPAxis axis) {
  axis.type = EPAxisType.unknown;
  axis.index = -1;
  axis.separation = -double.maxFinite;

  _perp.x = -normal.y;
  _perp.y = normal.x;

  for (var i = 0; i < polygonB.count; ++i) {
    final normalB = polygonB.normals[i];
    final vB = polygonB.vertices[i];
    _n.x = -normalB.x;
    _n.y = -normalB.y;

    // double s1 = Vec2.dot(n, temp.set(vB).subLocal(v1));
    // double s2 = Vec2.dot(n, temp.set(vB).subLocal(v2));
    var tempX = vB.x - v1.x;
    var tempY = vB.y - v1.y;
    final s1 = _n.x * tempX + _n.y * tempY;
    tempX = vB.x - v2.x;
    tempY = vB.y - v2.y;
    final s2 = _n.x * tempX + _n.y * tempY;
    final s = min(s1, s2);

    if (s > radius) {
      // No collision
      axis.type = EPAxisType.edgeB;
      axis.index = i;
      axis.separation = s;
      return;
    }

    // Adjacency
    if (_n.x * _perp.x + _n.y * _perp.y >= 0.0) {
      if ((_temp
                ..setFrom(_n)
                ..sub(upperLimit))
              .dot(normal) <
          -settings.angularSlop) {
        continue;
      }
    } else {
      if ((_temp
                ..setFrom(_n)
                ..sub(lowerLimit))
              .dot(normal) <
          -settings.angularSlop) {
        continue;
      }
    }

    if (s > axis.separation) {
      axis.type = EPAxisType.edgeB;
      axis.index = i;
      axis.separation = s;
    }
  }
}