closeTo method
Check whether this transform is equal to other
, up to the given
tolerance
. Setting tolerance to zero will check for exact equality.
Transforms are considered equal if their rotation angles are the same
or differ by a multiple of 2π, and if all other transform parameters:
translation, scale, and offset are the same.
The tolerance
parameter is in absolute units, not relative.
Implementation
bool closeTo(Transform2D other, {double tolerance = 1e-10}) {
final deltaAngle = (angle - other.angle) % geometry.tau;
assert(deltaAngle >= 0);
return (deltaAngle <= tolerance ||
deltaAngle >= geometry.tau - tolerance) &&
(position.x - other.position.x).abs() <= tolerance &&
(position.y - other.position.y).abs() <= tolerance &&
(scale.x - other.scale.x).abs() <= tolerance &&
(scale.y - other.scale.y).abs() <= tolerance &&
(offset.x - other.offset.x).abs() <= tolerance &&
(offset.y - other.offset.y).abs() <= tolerance;
}