mirror of
https://github.com/flutter/flutter
synced 2024-09-19 08:11:56 +00:00
Add a matcher for Matrix4 that includes epsilon (#107326)
This commit is contained in:
parent
acb0a47616
commit
f980d6654e
|
@ -266,6 +266,18 @@ Matcher rectMoreOrLessEquals(Rect value, { double epsilon = precisionErrorTolera
|
|||
return _IsWithinDistance<Rect>(_rectDistance, value, epsilon);
|
||||
}
|
||||
|
||||
/// Asserts that two [Matrix4]s are equal, within some tolerated error.
|
||||
///
|
||||
/// {@macro flutter.flutter_test.moreOrLessEquals}
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [moreOrLessEquals], which is for [double]s.
|
||||
/// * [offsetMoreOrLessEquals], which is for [Offset]s.
|
||||
Matcher matrixMoreOrLessEquals(Matrix4 value, { double epsilon = precisionErrorTolerance }) {
|
||||
return _IsWithinDistance<Matrix4>(_matrixDistance, value, epsilon);
|
||||
}
|
||||
|
||||
/// Asserts that two [Offset]s are equal, within some tolerated error.
|
||||
///
|
||||
/// {@macro flutter.flutter_test.moreOrLessEquals}
|
||||
|
@ -1144,6 +1156,14 @@ double _rectDistance(Rect a, Rect b) {
|
|||
return delta;
|
||||
}
|
||||
|
||||
double _matrixDistance(Matrix4 a, Matrix4 b) {
|
||||
double delta = 0.0;
|
||||
for (int i = 0; i < 16; i += 1) {
|
||||
delta = math.max<double>((a[i] - b[i]).abs(), delta);
|
||||
}
|
||||
return delta;
|
||||
}
|
||||
|
||||
double _sizeDistance(Size a, Size b) {
|
||||
// TODO(a14n): remove ignore when lint is updated, https://github.com/dart-lang/linter/issues/1843
|
||||
// ignore: unnecessary_parenthesis
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
// flutter_ignore_for_file: golden_tag (see analyze.dart)
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
@ -197,6 +198,38 @@ void main() {
|
|||
expect(-11.0, moreOrLessEquals(11.0, epsilon: 100.0));
|
||||
});
|
||||
|
||||
test('matrixMoreOrLessEquals', () {
|
||||
expect(
|
||||
Matrix4.rotationZ(math.pi),
|
||||
matrixMoreOrLessEquals(Matrix4.fromList(<double>[
|
||||
-1, 0, 0, 0,
|
||||
0, -1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
]))
|
||||
);
|
||||
|
||||
expect(
|
||||
Matrix4.rotationZ(math.pi),
|
||||
matrixMoreOrLessEquals(Matrix4.fromList(<double>[
|
||||
-2, 0, 0, 0,
|
||||
0, -2, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
]), epsilon: 2)
|
||||
);
|
||||
|
||||
expect(
|
||||
Matrix4.rotationZ(math.pi),
|
||||
isNot(matrixMoreOrLessEquals(Matrix4.fromList(<double>[
|
||||
-2, 0, 0, 0,
|
||||
0, -2, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1,
|
||||
])))
|
||||
);
|
||||
});
|
||||
|
||||
test('rectMoreOrLessEquals', () {
|
||||
expect(
|
||||
const Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
|
||||
|
|
Loading…
Reference in a new issue