From 382704ca95aef810072eaebe693b7f7dec0d3e0c Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 10 May 2019 13:28:19 -0700 Subject: [PATCH] Use precisionErrorTolerance (#32499) --- .../android_views/lib/motion_event_diff.dart | 3 ++- dev/tools/vitool/test/vitool_test.dart | 3 ++- packages/flutter/lib/src/gestures/lsq_solver.dart | 6 ++++-- packages/flutter/lib/src/rendering/table.dart | 2 +- packages/flutter/test/cupertino/dialog_test.dart | 7 ++----- .../flutter/test/cupertino/nav_bar_transition_test.dart | 2 +- packages/flutter/test/widgets/scroll_simulation_test.dart | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/dev/integration_tests/android_views/lib/motion_event_diff.dart b/dev/integration_tests/android_views/lib/motion_event_diff.dart index 21f2bb54a1..e2f86a5dfa 100644 --- a/dev/integration_tests/android_views/lib/motion_event_diff.dart +++ b/dev/integration_tests/android_views/lib/motion_event_diff.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; // Android MotionEvent actions for which a pointer index is encoded in the // unmasked action code. @@ -13,7 +14,7 @@ const List kPointerActions = [ 6, // POINTER_UP ]; -const double kDoubleErrorMargin = 0.0001; +const double kDoubleErrorMargin = precisionErrorTolerance; String diffMotionEvents( Map originalEvent, diff --git a/dev/tools/vitool/test/vitool_test.dart b/dev/tools/vitool/test/vitool_test.dart index 4f3cfe695a..cd65312032 100644 --- a/dev/tools/vitool/test/vitool_test.dart +++ b/dev/tools/vitool/test/vitool_test.dart @@ -5,6 +5,7 @@ import 'dart:math'; import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:vitool/vitool.dart'; import 'package:path/path.dart' as path; @@ -146,7 +147,7 @@ void main() { SvgPathCommand('M', >[Point(19.0, 0.0)]), SvgPathCommand('Z', >[]), ]), - margin: 0.000000001 + margin: precisionErrorTolerance, ) ]); }); diff --git a/packages/flutter/lib/src/gestures/lsq_solver.dart b/packages/flutter/lib/src/gestures/lsq_solver.dart index 599aa6a531..9d861854c4 100644 --- a/packages/flutter/lib/src/gestures/lsq_solver.dart +++ b/packages/flutter/lib/src/gestures/lsq_solver.dart @@ -5,6 +5,8 @@ import 'dart:math' as math; import 'dart:typed_data'; +import 'package:flutter/foundation.dart'; + // TODO(abarth): Consider using vector_math. class _Vector { _Vector(int size) @@ -128,7 +130,7 @@ class LeastSquaresSolver { } final double norm = q.getRow(j).norm(); - if (norm < 0.000001) { + if (norm < precisionErrorTolerance) { // Vectors are linearly dependent or zero so no solution. return null; } @@ -176,7 +178,7 @@ class LeastSquaresSolver { sumSquaredTotal += w[h] * w[h] * v * v; } - result.confidence = sumSquaredTotal <= 0.000001 ? 1.0 : + result.confidence = sumSquaredTotal <= precisionErrorTolerance ? 1.0 : 1.0 - (sumSquaredError / sumSquaredTotal); return result; diff --git a/packages/flutter/lib/src/rendering/table.dart b/packages/flutter/lib/src/rendering/table.dart index b9ab83ba2c..1e15b26682 100644 --- a/packages/flutter/lib/src/rendering/table.dart +++ b/packages/flutter/lib/src/rendering/table.dart @@ -918,7 +918,7 @@ class RenderTable extends RenderBox { int availableColumns = columns; // Handle double precision errors which causes this loop to become // stuck in certain configurations. - const double minimumDeficit = 0.00000001; + const double minimumDeficit = precisionErrorTolerance; while (deficit > minimumDeficit && totalFlex > minimumDeficit) { double newTotalFlex = 0.0; for (int x = 0; x < columns; x += 1) { diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index 6a59aac101..daacb5726d 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -654,13 +654,10 @@ void main() { expect(option1ButtonBox.size.width, actionsSectionBox.size.width); // Expected Height = button 1 + divider + 1/2 button 2 = 67.83333333333334 - // Technically the following number is off by 0.00000000000003 but I think it's a - // Dart precision issue. I ran the subtraction directly in dartpad and still - // got 67.83333333333337. - const double expectedHeight = 67.83333333333337; + const double expectedHeight = 67.83333333333334; expect( actionsSectionBox.size.height, - expectedHeight, + moreOrLessEquals(expectedHeight), ); }); diff --git a/packages/flutter/test/cupertino/nav_bar_transition_test.dart b/packages/flutter/test/cupertino/nav_bar_transition_test.dart index 4b142d7484..c86855c768 100644 --- a/packages/flutter/test/cupertino/nav_bar_transition_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_transition_test.dart @@ -119,7 +119,7 @@ void checkOpacity(WidgetTester tester, Finder finder, double opacity) { matching: find.byType(FadeTransition), ), ).opacity.value, - moreOrLessEquals(opacity, epsilon: 0.000000001), + moreOrLessEquals(opacity), ); } diff --git a/packages/flutter/test/widgets/scroll_simulation_test.dart b/packages/flutter/test/widgets/scroll_simulation_test.dart index a47545d99c..d775aa692e 100644 --- a/packages/flutter/test/widgets/scroll_simulation_test.dart +++ b/packages/flutter/test/widgets/scroll_simulation_test.dart @@ -9,8 +9,8 @@ void main() { test('ClampingScrollSimulation has a stable initial conditions', () { void checkInitialConditions(double position, double velocity) { final ClampingScrollSimulation simulation = ClampingScrollSimulation(position: position, velocity: velocity); - expect(simulation.x(0.0), closeTo(position, 0.00001)); - expect(simulation.dx(0.0), closeTo(velocity, 0.00001)); + expect(simulation.x(0.0), moreOrLessEquals(position)); + expect(simulation.dx(0.0), moreOrLessEquals(velocity)); } checkInitialConditions(51.0, 2866.91537);