From 590d584a2fcb36fa997dd190bd5adcd79a23207c Mon Sep 17 00:00:00 2001 From: Luigi Rosso Date: Thu, 26 May 2022 13:14:10 -0700 Subject: [PATCH] Fixes for nested state machines. --- lib/src/rive_core/math/hit_test.dart | 12 ++++++++++-- lib/src/rive_core/nested_animation.dart | 5 +++++ lib/src/rive_core/nested_artboard.dart | 1 - 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/src/rive_core/math/hit_test.dart b/lib/src/rive_core/math/hit_test.dart index 0fb97dd..27f37a1 100644 --- a/lib/src/rive_core/math/hit_test.dart +++ b/lib/src/rive_core/math/hit_test.dart @@ -67,11 +67,19 @@ class HitTester implements PathInterface { int winding = 1; if (y0 > y1) { winding = -1; + + // Swap our two points (is there a swap utility?) double tmp = y0; // ignore: parameter_assignments y0 = y1; // ignore: parameter_assignments y1 = tmp; + + tmp = x0; + // ignore: parameter_assignments + x0 = x1; + // ignore: parameter_assignments + x1 = tmp; } // now we're monotonic in Y: y0 <= y1 if (y1 <= 0 || y0 >= _height) { @@ -184,7 +192,7 @@ class HitTester implements PathInterface { // ... At^3 + Bt^2 + Ct + D // final aX = (x3 - _prevX) + 3 * (x1 - x2); - // final bX = 3 * ((x2 - x1) + (_prevX - x1)); + final bX = 3 * ((x2 - x1) + (_prevX - x1)); final cX = 3 * (x1 - _prevX); final dX = _prevX; @@ -198,7 +206,7 @@ class HitTester implements PathInterface { double py = _prevY; for (int i = 1; i < count - 1; ++i) { // Horner's method for evaluating the simple polynomial - final nx = ((aX * t + aX) * t + cX) * t + dX; + final nx = ((aX * t + bX) * t + cX) * t + dX; final ny = ((aY * t + bY) * t + cY) * t + dY; _clipLine(px, py, nx, ny); px = nx; diff --git a/lib/src/rive_core/nested_animation.dart b/lib/src/rive_core/nested_animation.dart index f8340a2..4dc76f3 100644 --- a/lib/src/rive_core/nested_animation.dart +++ b/lib/src/rive_core/nested_animation.dart @@ -14,6 +14,11 @@ abstract class NestedAnimation bool get isEnabled; + + /// Returns true when the NestedAnimation needs to keep advancing. Returning + /// false doesn't guarantee another advance won't be called, it just means + /// that it's no longer necessary to call advance again as the reesults will + /// be the same. bool advance(double elapsedSeconds, MountedArtboard mountedArtboard); @override diff --git a/lib/src/rive_core/nested_artboard.dart b/lib/src/rive_core/nested_artboard.dart index 056a28b..ee0ab40 100644 --- a/lib/src/rive_core/nested_artboard.dart +++ b/lib/src/rive_core/nested_artboard.dart @@ -19,7 +19,6 @@ export 'package:rive/src/generated/nested_artboard_base.dart'; /// the [NestedArtboard] component. abstract class MountedArtboard { void draw(Canvas canvas); - Mat2D get originTransform; Mat2D get worldTransform; set worldTransform(Mat2D value); AABB get bounds;