Unverified Commit 382704ca authored by Dan Field's avatar Dan Field Committed by GitHub

Use precisionErrorTolerance (#32499)

parent 38f408f0
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
// Android MotionEvent actions for which a pointer index is encoded in the // Android MotionEvent actions for which a pointer index is encoded in the
// unmasked action code. // unmasked action code.
...@@ -13,7 +14,7 @@ const List<int> kPointerActions = <int>[ ...@@ -13,7 +14,7 @@ const List<int> kPointerActions = <int>[
6, // POINTER_UP 6, // POINTER_UP
]; ];
const double kDoubleErrorMargin = 0.0001; const double kDoubleErrorMargin = precisionErrorTolerance;
String diffMotionEvents( String diffMotionEvents(
Map<String, dynamic> originalEvent, Map<String, dynamic> originalEvent,
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math'; import 'dart:math';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:vitool/vitool.dart'; import 'package:vitool/vitool.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
...@@ -146,7 +147,7 @@ void main() { ...@@ -146,7 +147,7 @@ void main() {
SvgPathCommand('M', <Point<double>>[Point<double>(19.0, 0.0)]), SvgPathCommand('M', <Point<double>>[Point<double>(19.0, 0.0)]),
SvgPathCommand('Z', <Point<double>>[]), SvgPathCommand('Z', <Point<double>>[]),
]), ]),
margin: 0.000000001 margin: precisionErrorTolerance,
) )
]); ]);
}); });
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/foundation.dart';
// TODO(abarth): Consider using vector_math. // TODO(abarth): Consider using vector_math.
class _Vector { class _Vector {
_Vector(int size) _Vector(int size)
...@@ -128,7 +130,7 @@ class LeastSquaresSolver { ...@@ -128,7 +130,7 @@ class LeastSquaresSolver {
} }
final double norm = q.getRow(j).norm(); final double norm = q.getRow(j).norm();
if (norm < 0.000001) { if (norm < precisionErrorTolerance) {
// Vectors are linearly dependent or zero so no solution. // Vectors are linearly dependent or zero so no solution.
return null; return null;
} }
...@@ -176,7 +178,7 @@ class LeastSquaresSolver { ...@@ -176,7 +178,7 @@ class LeastSquaresSolver {
sumSquaredTotal += w[h] * w[h] * v * v; sumSquaredTotal += w[h] * w[h] * v * v;
} }
result.confidence = sumSquaredTotal <= 0.000001 ? 1.0 : result.confidence = sumSquaredTotal <= precisionErrorTolerance ? 1.0 :
1.0 - (sumSquaredError / sumSquaredTotal); 1.0 - (sumSquaredError / sumSquaredTotal);
return result; return result;
......
...@@ -918,7 +918,7 @@ class RenderTable extends RenderBox { ...@@ -918,7 +918,7 @@ class RenderTable extends RenderBox {
int availableColumns = columns; int availableColumns = columns;
// Handle double precision errors which causes this loop to become // Handle double precision errors which causes this loop to become
// stuck in certain configurations. // stuck in certain configurations.
const double minimumDeficit = 0.00000001; const double minimumDeficit = precisionErrorTolerance;
while (deficit > minimumDeficit && totalFlex > minimumDeficit) { while (deficit > minimumDeficit && totalFlex > minimumDeficit) {
double newTotalFlex = 0.0; double newTotalFlex = 0.0;
for (int x = 0; x < columns; x += 1) { for (int x = 0; x < columns; x += 1) {
......
...@@ -654,13 +654,10 @@ void main() { ...@@ -654,13 +654,10 @@ void main() {
expect(option1ButtonBox.size.width, actionsSectionBox.size.width); expect(option1ButtonBox.size.width, actionsSectionBox.size.width);
// Expected Height = button 1 + divider + 1/2 button 2 = 67.83333333333334 // 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 const double expectedHeight = 67.83333333333334;
// Dart precision issue. I ran the subtraction directly in dartpad and still
// got 67.83333333333337.
const double expectedHeight = 67.83333333333337;
expect( expect(
actionsSectionBox.size.height, actionsSectionBox.size.height,
expectedHeight, moreOrLessEquals(expectedHeight),
); );
}); });
......
...@@ -119,7 +119,7 @@ void checkOpacity(WidgetTester tester, Finder finder, double opacity) { ...@@ -119,7 +119,7 @@ void checkOpacity(WidgetTester tester, Finder finder, double opacity) {
matching: find.byType(FadeTransition), matching: find.byType(FadeTransition),
), ),
).opacity.value, ).opacity.value,
moreOrLessEquals(opacity, epsilon: 0.000000001), moreOrLessEquals(opacity),
); );
} }
......
...@@ -9,8 +9,8 @@ void main() { ...@@ -9,8 +9,8 @@ void main() {
test('ClampingScrollSimulation has a stable initial conditions', () { test('ClampingScrollSimulation has a stable initial conditions', () {
void checkInitialConditions(double position, double velocity) { void checkInitialConditions(double position, double velocity) {
final ClampingScrollSimulation simulation = ClampingScrollSimulation(position: position, velocity: velocity); final ClampingScrollSimulation simulation = ClampingScrollSimulation(position: position, velocity: velocity);
expect(simulation.x(0.0), closeTo(position, 0.00001)); expect(simulation.x(0.0), moreOrLessEquals(position));
expect(simulation.dx(0.0), closeTo(velocity, 0.00001)); expect(simulation.dx(0.0), moreOrLessEquals(velocity));
} }
checkInitialConditions(51.0, 2866.91537); checkInitialConditions(51.0, 2866.91537);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment