-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: use easier to control easing function #16
Conversation
import 'dart:math'; | ||
|
||
class StrokeEasings { | ||
/// Identity function. | ||
/// Returns the input value. | ||
/// Previously used as the default ease in [getStrokeRadius]. | ||
@Deprecated('Use easeMiddle or define your own easing function') | ||
static double identity(double t) => t; | ||
|
||
/// Ease-in-out function. | ||
/// Used for the taper start. | ||
/// This function is actually an ease-out function. | ||
/// Previously used for the taper start. | ||
@Deprecated('Use easeMiddle or define your own easing function') | ||
static double easeInOut(double t) => t * (2 - t); | ||
|
||
/// Ease-out-cubic function. | ||
/// Used for the taper end. | ||
/// This function does not output a value between 0 and 1. | ||
/// Previously used for the taper end. | ||
@Deprecated('Use easeMiddle or define your own easing function') | ||
static double easeOutCubic(double t) => --t * t * t + 1; | ||
|
||
/// Easing function that slows down around the middle. | ||
static double easeMiddle(double t) { | ||
// Take average of t and cubic ease of t to smooth out the curve. | ||
return (t + _easeMiddleCubic(t)) / 2; | ||
} | ||
|
||
static double _easeMiddleCubic(double t) { | ||
return 4 * pow(t - 0.5, 3) + 0.5; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why we wouldn't easeMiddle as an additional easing here, rather than deprecate the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it would be better for devs to define the functions in their own code, rather than in this project where they might be removed in the future since we're not using them
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'dart:ui/lerp.dart': Failed assertion: line 19 pos 10: '<optimized out>': Cannot interpolate between finite and non-finite values #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61) #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5) #2 lerpDouble (dart:ui/lerp.dart:19:10) #3 PointVector.lerp (package:perfect_freehand/src/types/point_vector.dart:54:7) #4 getStrokeOutlinePoints (package:perfect_freehand/src/get_stroke_outline_points.dart:238:31) #5 getStroke (package:perfect_freehand/src/get_stroke.dart:19:10) #6 Stroke._getPolygon (package:saber/components/canvas/_stroke.dart:200:21) #7 Stroke._updatePolygon (package:saber/components/canvas/_stroke.dart:48:16) #8 Stroke.polygon (package:saber/components/canvas/_stroke.dart:38:32) #9 Stroke.toSvgPath (package:saber/components/canvas/_stroke.dart:247:9) #10 EditorExporter.generatePdf.<anonymous closure>.<anonymous closure> (package:saber/data/editor/editor_exporter.dart:111:52) #11 CustomPaint.paint (package:pdf/src/widgets/basic.dart:623:25) #12 SingleChildWidget.paintChild (package:pdf/src/widgets/widget.dart:320:14) #13 ConstrainedBox.paint (package:pdf/src/widgets/basic.dart:449:5) #14 StatelessWidget.paint (package:pdf/src/widgets/widget.dart:260:15) #15 Page.paint (package:pdf/src/widgets/page.dart:246:13) #16 Page.postProcess (package:pdf/src/widgets/page.dart:179:5) #17 Document.save (package:pdf/src/widgets/document.dart:130:14) #18 EditorState.exportAsPdf (package:saber/pages/editor/editor.dart:1213:72) <asynchronous suspension> #19 _ExportBarState._onPressed.<anonymous closure>.<anonymous closure> (package:saber/components/toolbar/export_bar.dart:38:29) <asynchronous suspension>
The default easing function is now
StrokeEasings.easeMiddle
instead of a linear function. This makes strokes' pressure easier to control as the pressure stays around the middle for longer. You can still use the linear easing function by settingStrokeOptions.easing
andStrokeEndOptions.easing
.