From b872ed1ec7e88f35559e2afac1e9c2223c8c19e8 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 1 Mar 2022 16:06:31 -0800 Subject: [PATCH] Format, update rules, jonah review --- .../vector_graphics_compiler/lib/src/geometry/matrix.dart | 5 +++-- .../vector_graphics_compiler/lib/src/geometry/path.dart | 5 +++-- .../vector_graphics_compiler/test/basic_types_test.dart | 7 ++++--- packages/vector_graphics_compiler/test/matrix_test.dart | 8 ++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/vector_graphics_compiler/lib/src/geometry/matrix.dart b/packages/vector_graphics_compiler/lib/src/geometry/matrix.dart index f97f4332676e..e70b186cf790 100644 --- a/packages/vector_graphics_compiler/lib/src/geometry/matrix.dart +++ b/packages/vector_graphics_compiler/lib/src/geometry/matrix.dart @@ -172,7 +172,7 @@ class AffineMatrix { } @override - int get hashCode => Object.hash(a, b, c, d, e, f); + int get hashCode => Object.hash(a, b, c, d, e, f, _m4_10); @override bool operator ==(Object other) { @@ -180,7 +180,8 @@ class AffineMatrix { other.a == a && other.b == b && other.d == d && - other.e == e; + other.e == e && + other._m4_10 == _m4_10; } @override diff --git a/packages/vector_graphics_compiler/lib/src/geometry/path.dart b/packages/vector_graphics_compiler/lib/src/geometry/path.dart index 411563a0bfd7..e61c09b27533 100644 --- a/packages/vector_graphics_compiler/lib/src/geometry/path.dart +++ b/packages/vector_graphics_compiler/lib/src/geometry/path.dart @@ -1,5 +1,3 @@ -import 'dart:math' as math; - import 'package:meta/meta.dart'; import 'package:path_parsing/path_parsing.dart'; @@ -7,6 +5,9 @@ import 'basic_types.dart'; import 'matrix.dart'; import '../util.dart'; +// This is a magic number used by impeller for radius approximation: +// https://github.com/flutter/impeller/blob/a2478aa4939a9a08c6c3810f72e0db42e7383a07/geometry/path_builder.cc#L9 +// See https://spencermortensen.com/articles/bezier-circle/ for more information. const double _kArcApproximationMagic = 0.551915024494; /// Specifies the winding rule that decies how the interior of a [Path] is diff --git a/packages/vector_graphics_compiler/test/basic_types_test.dart b/packages/vector_graphics_compiler/test/basic_types_test.dart index adce8c5edd75..6e29041a8ceb 100644 --- a/packages/vector_graphics_compiler/test/basic_types_test.dart +++ b/packages/vector_graphics_compiler/test/basic_types_test.dart @@ -3,7 +3,7 @@ import 'package:vector_graphics_compiler/vector_graphics_compiler.dart'; import 'package:test/test.dart'; void main() { - test('Point tests', () { + test('Point tests', () { expect(Point.zero.x, 0); expect(Point.zero.y, 0); @@ -18,8 +18,9 @@ void main() { expect(Rect.zero.bottom, 0); expect( - const Rect.fromLTRB(1, 2, 3, 4).expanded(const Rect.fromLTRB(0, 0, 10, 10)), - const Rect.fromLTRB(0, 0, 10 ,10), + const Rect.fromLTRB(1, 2, 3, 4) + .expanded(const Rect.fromLTRB(0, 0, 10, 10)), + const Rect.fromLTRB(0, 0, 10, 10), ); expect( diff --git a/packages/vector_graphics_compiler/test/matrix_test.dart b/packages/vector_graphics_compiler/test/matrix_test.dart index 9187f80c9e6d..71c660a7d1ba 100644 --- a/packages/vector_graphics_compiler/test/matrix_test.dart +++ b/packages/vector_graphics_compiler/test/matrix_test.dart @@ -96,4 +96,12 @@ void main() { expect(rotatedRect.right + 20, lessThan(epsillon)); expect(rotatedRect.bottom - 30, lessThan(epsillon)); }); + + test('== and hashCode account for hidden field', () { + const AffineMatrix matrixA = AffineMatrix.identity; + const AffineMatrix matrixB = AffineMatrix(1, 0, 0, 1, 0, 0, 0); + + expect(matrixA != matrixB, true); + expect(matrixA.hashCode != matrixB.hashCode, true); + }); }