updateGravity method
Reject freefall, nonfinite data and strong linear acceleration. This is only a plausibility gate, not proof that acceleration is pure gravity.
Implementation
bool updateGravity(double x, double y, double z) {
final magnitude2 = x * x + y * y + z * z;
if (!magnitude2.isFinite ||
magnitude2 < 49 ||
magnitude2 > 156.25 ||
x * x + z * z < 4) {
return false;
}
gravityPitch = atan2(z, x).clamp(-1.45, 1.45);
return true;
}