https://github.com/modulovalue/abstract_lerp
A package that gives you interpolation on Fields from abstract_dart
https://github.com/modulovalue/abstract_lerp
Last synced: 3 months ago
JSON representation
A package that gives you interpolation on Fields from abstract_dart
- Host: GitHub
- URL: https://github.com/modulovalue/abstract_lerp
- Owner: modulovalue
- License: mit
- Created: 2019-11-03T20:02:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-03T20:26:28.000Z (over 6 years ago)
- Last Synced: 2026-01-03T01:05:15.573Z (7 months ago)
- Language: Dart
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# abstract_lerp
[](https://pub.dev/packages/extra_pedantic) [](https://travis-ci.com/modulovalue/abstract_lerp) [](https://codecov.io/gh/modulovalue/abstract_lerp) [](https://github.com/modulovalue/abstract_lerp/blob/master/LICENSE) [](https://pub.dartlang.org/packages/abstract_lerp) [](https://github.com/modulovalue/abstract_lerp) [](https://twitter.com/modulovalue) [](https://github.com/modulovalue)
Lerping for [abstract_dart](https://github.com/modulovalue/abstract_dart) Fields.
```dart
/// A double lerp.
final Lerp _double = DoubleLerp(10.0, 20.0);
/// A num lerp.
final Lerp _num = NumLerp(10.0, 20.0);
/// A decimal lerp.
final Lerp _decimal =
DecimalLerp(Decimal.fromInt(10), Decimal.fromInt(20));
/// A custom lerp.
///
/// Multiplication, division, addition and subtraction are needed for a lerp.
/// A Field provides all of that.
final FieldLerp _customLerp = FieldLerp(
/// from
10.0,
/// to
20.0,
Field_.create(
/// addition
Group_.create(() => 0.0, (a, b) => a + b, (a, b) => a - b),
/// multiplication
Group_.create(() => 1.0, (a, b) => a * b, (a, b) => a / b),
),
);
print(_double.lerp(0.7)); // 17.0;
print(_double.reLerp(17.0)); // 0.7;
print(_num.lerp(0.7)); // 17.0;
print(_num.reLerp(17.0)); // 0.7;
print(_decimal.lerp(Decimal.parse("0.7"))); // 17.0;
print(_decimal.reLerp(Decimal.parse("17"))); // 0.7;
print(_customLerp.lerp(0.7)); // 17.0;
print(_customLerp.reLerp(17.0)); // 0.7;
final fromZero = _customLerp.copyWith(from: 0.0);
print(fromZero.lerp(0.7)); // 14.0;
print(_customLerp.reLerp(14.0)); // 0.7;
```