testPoint method
Test a point for containment in this shape. This only works for convex shapes.
xf
should be the shape world transform.
point
should be in world coordinates.
Implementation
@override
bool testPoint(Transform xf, Vector2 p) {
final xfq = xf.q;
var tempX = p.x - xf.p.x;
var tempY = p.y - xf.p.y;
final pLocalX = xfq.cos * tempX + xfq.sin * tempY;
final pLocalY = -xfq.sin * tempX + xfq.cos * tempY;
for (var i = 0; i < vertices.length; ++i) {
final vertex = vertices[i];
final normal = normals[i];
tempX = pLocalX - vertex.x;
tempY = pLocalY - vertex.y;
final dot = normal.x * tempX + normal.y * tempY;
if (dot > 0.0) {
return false;
}
}
return true;
}