Repository: fujidaiti/smooth_sheets
Pull request #247 (2024-09-20 13:23:01)

Remove createSettlingSimulation and InterpolationSimulation
## Summary (check all that apply)

- [x] Modified / added code
- [x] Modified / added tests
- [ ] Modified / added examples
- [ ] Modified / added others (pubspec.yaml, workflows, etc...)
- [ ] Updated README
- [x] Contains breaking changes
  - [x] Created / updated migration guide
- [ ] Incremented version number
  - [ ] Updated CHANGELOG



Patch:
diff --git a/lib/src/foundation/foundation.dart b/lib/src/foundation/foundation.dart
index 858e0be..d88802b 100644
--- a/lib/src/foundation/foundation.dart
+++ b/lib/src/foundation/foundation.dart
@@ -41,7 +41,6 @@ export 'sheet_physics.dart'
         ClampingSheetPhysics,
         DirectionAwareBouncingBehavior,
         FixedBouncingBehavior,
-        InterpolationSimulation,
         SheetPhysics,
         SheetPhysicsMixin,
         SnapToNearest,
diff --git a/lib/src/foundation/sheet_physics.dart b/lib/src/foundation/sheet_physics.dart
index 66f9a8d..105919e 100644
--- a/lib/src/foundation/sheet_physics.dart
+++ b/lib/src/foundation/sheet_physics.dart
@@ -1,10 +1,8 @@
 import 'dart:io';
 import 'dart:math';
-import 'dart:ui';
 
 import 'package:collection/collection.dart';
 import 'package:flutter/gestures.dart';
-import 'package:flutter/physics.dart';
 import 'package:flutter/widgets.dart';
 
 import '../internal/double_utils.dart';
@@ -24,9 +22,6 @@ const kDefaultSheetSpring = SpringDescription(
   damping: 15.5563491861, // 1.1 * 2.0 * sqrt(0.5 * 100.0)
 );
 
-const _kMinSettlingDuration = Duration(milliseconds: 160);
-const _kDefaultSettlingSpeed = 600.0; // logical pixels per second
-
 /// The default [SheetPhysics] used by sheet widgets.
 const kDefaultSheetPhysics =
     BouncingSheetPhysics(parent: SnappingSheetPhysics());
@@ -72,10 +67,6 @@ abstract class SheetPhysics {
 
   Simulation? createBallisticSimulation(double velocity, SheetMetrics metrics);
 
-  // TODO: Remove this in favor of findNearestDetent().
-  @Deprecated('Use findSettledExtent instead.')
-  Simulation? createSettlingSimulation(SheetMetrics metrics);
-
   /// {@template SheetPhysics.findSettledExtent}
   /// Returns an extent to which a sheet should eventually settle
   /// based on the current [metrics] and the [velocity] of a sheet.
@@ -147,27 +138,6 @@ mixin SheetPhysicsMixin on SheetPhysics {
     return null;
   }
 
-  @override
-  Simulation? createSettlingSimulation(SheetMetrics metrics) {
-    if (parent case final parent?) {
-      return parent.createSettlingSimulation(metrics);
-    } else if (metrics.isPixelsInBounds) {
-      return null;
-    }
-    final settleTo =
-        metrics.pixels.nearest(metrics.minPixels, metrics.maxPixels);
-
-    return InterpolationSimulation(
-      start: metrics.pixels,
-      end: settleTo,
-      curve: Curves.easeInOut,
-      durationInSeconds: max(
-        (metrics.pixels - settleTo).abs() / _kDefaultSettlingSpeed,
-        _kMinSettlingDuration.inMicroseconds / Duration.microsecondsPerSecond,
-      ),
-    );
-  }
-
   /// Returns the closer of [SheetMetrics.minExtent] or [SheetMetrics.maxExtent]
   /// to the current sheet position if it is out of bounds, regardless of the
   /// [velocity]. Otherwise, it returns the current position.
@@ -191,52 +161,6 @@ mixin SheetPhysicsMixin on SheetPhysics {
   }
 }
 
-/// A [Simulation] that interpolates between two values over a given duration.
-class InterpolationSimulation extends Simulation {
-  /// Creates a [Simulation] that interpolates between two values
-  /// over a given duration.
-  ///
-  /// Make sure that [start] and [end] are not equal, and the
-  /// [durationInSeconds] must be greater than 0.
-  InterpolationSimulation({
-    required this.start,
-    required this.end,
-    required this.curve,
-    required this.durationInSeconds,
-    super.tolerance,
-  })  : assert(start != end),
-        assert(durationInSeconds > 0);
-
-  /// The start value of the interpolation.
-  final double start;
-
-  /// The end value of the interpolation.
-  final double end;
-
-  /// The curve to use for the interpolation.
-  final Curve curve;
-
-  /// The duration of the interpolation in seconds.
-  late final double durationInSeconds;
-
-  @override
-  double dx(double time) {
-    final epsilon = tolerance.time;
-    return (x(time + epsilon) - x(time - epsilon)) / (2 * epsilon);
-  }
-
-  @override
-  double x(double time) {
-    final t = curve.transform((time / durationInSeconds).clamp(0, 1));
-    return lerpDouble(start, end, t)!;
-  }
-
-  @override
-  bool isDone(double time) {
-    return nearEqual(x(time), end, tolerance.distance);
-  }
-}
-
 abstract interface class SnappingSheetBehavior {
   /// {@macro SheetPhysics.findSettledExtent}
   ///
diff --git a/migrations/migration-guide-0.10.x.md b/migrations/migration-guide-0.10.x.md
index 0ede370..68ffd40 100644
--- a/migrations/migration-guide-0.10.x.md
+++ b/migrations/migration-guide-0.10.x.md
@@ -1,9 +1,15 @@
-# Migration guide to 0.10.x from 0.9.x
+# Migration Guide: 0.10.x from 0.9.x
 
-## Breaking changes in SheetMetrics
+The changes in v0.10.0 are summarized as follows. Breaking changes are marked with :boom:.
 
-`double? minPixels` and `double? maxPixels` parameters of the constructor and `copyWith` method have been replaced with `Extent? minExtent` and `Extent? maxExtent` respectively. The `minPixels` and `maxPixels` getters are still available in the new version.
+## Changes in `SheetMetrics` :boom:
 
-## Breaking change in SnappingSheetBehavior
+The `double? minPixels` and `double? maxPixels` parameters in the constructor and `copyWith` method have been replaced with `Extent? minExtent` and `Extent? maxExtent`, respectively. However, the `minPixels` and `maxPixels` getters are still available in this version.
 
-`findSnapPixels` method has been removed. Use `findSnapExtent` instead.
+## Change in `SnappingSheetBehavior` :boom:
+
+The `findSnapPixels` method has been removed. Use `findSnapExtent` instead.
+
+## Change in `SheetPhysics` :boom:
+
+The `createSettlingSimulation` method has been removed in favor of the `findSettledExtent` method. As a result, `InterpolationSimulation` has also been removed since it is no longer used and is not a core feature of the package.
\ No newline at end of file


Test patch:
diff --git a/test/foundation/physics_test.dart b/test/foundation/physics_test.dart
index c8fd0f3..fa850ee 100644
--- a/test/foundation/physics_test.dart
+++ b/test/foundation/physics_test.dart
@@ -161,58 +161,6 @@ void main() {
       );
     });
 
-    test('creates no settling simulation if the position is in bounds', () {
-      expect(
-        physicsUnderTest.createSettlingSimulation(_positionAtMiddle),
-        isNull,
-      );
-      expect(
-        physicsUnderTest.createSettlingSimulation(_positionAtTopEdge),
-        isNull,
-      );
-      expect(
-        physicsUnderTest.createSettlingSimulation(_positionAtBottomEdge),
-        isNull,
-      );
-    });
-
-    test('creates settling simulation which ends at nearest edge', () {
-      final moreOverDraggedPosition = _referenceSheetMetrics.copyWith(
-        pixels: _referenceSheetMetrics.maxPixels + 200,
-      );
-      final lessOverDraggedPosition = _referenceSheetMetrics.copyWith(
-        pixels: _referenceSheetMetrics.maxPixels + 10,
-      );
-      final moreOverDragSimulation =
-          physicsUnderTest.createSettlingSimulation(moreOverDraggedPosition);
-      final lessOverDragSimulation =
-          physicsUnderTest.createSettlingSimulation(lessOverDraggedPosition);
-
-      // The settling simulation runs with the average velocity of 600px/s
-      // if the starting position is far enough from the edge.
-      expect(moreOverDragSimulation, isNotNull);
-      expect(
-        moreOverDragSimulation!.x(0.170), // 170ms passed
-        greaterThan(_referenceSheetMetrics.maxPixels),
-      );
-      expect(
-        moreOverDragSimulation.x(0.334), // 334ms passed (≈ 200px / 600px/s)
-        moreOrLessEquals(_referenceSheetMetrics.maxPixels),
-      );
-
-      // The default behavior ensures that the settling simulation runs for
-      // at least 160ms even if the starting position is too close to the edge.
-      expect(lessOverDragSimulation, isNotNull);
-      expect(
-        lessOverDragSimulation!.x(0.08), // 80ms passed
-        greaterThan(_referenceSheetMetrics.maxPixels),
-      );
-      expect(
-        lessOverDragSimulation.x(0.16), // 160ms passed
-        moreOrLessEquals(_referenceSheetMetrics.maxPixels),
-      );
-    });
-
     test('findSettledExtent', () {
       expect(
         physicsUnderTest.findSettledExtent(0, _positionAtMiddle),