Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c613a85c
Commit
c613a85c
authored
Jan 05, 2017
by
Hans Muller
Committed by
GitHub
Jan 05, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Invalid Curve transform parameter should assert (#7340)
parent
1146587c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
curves.dart
packages/flutter/lib/src/animation/curves.dart
+13
-1
curves_test.dart
packages/flutter/test/animation/curves_test.dart
+33
-0
No files found.
packages/flutter/lib/src/animation/curves.dart
View file @
c613a85c
...
...
@@ -16,7 +16,8 @@ abstract class Curve {
/// Returns the value of the curve at point `t`.
///
/// The value of `t` must be between 0.0 and 1.0, inclusive.
/// The value of `t` must be between 0.0 and 1.0, inclusive. Subclasses should
/// assert that this is true.
double
transform
(
double
t
);
/// Returns a new curve that is the reversed inversion of this one.
...
...
@@ -54,6 +55,7 @@ class SawTooth extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
if
(
t
==
1.0
)
return
1.0
;
t
*=
count
;
...
...
@@ -84,6 +86,7 @@ class Interval extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
assert
(
begin
>=
0.0
);
assert
(
begin
<=
1.0
);
assert
(
end
>=
0.0
);
...
...
@@ -119,6 +122,7 @@ class Threshold extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
assert
(
threshold
>=
0.0
);
assert
(
threshold
<=
1.0
);
if
(
t
==
0.0
||
t
==
1.0
)
...
...
@@ -180,6 +184,7 @@ class Cubic extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
double
start
=
0.0
;
double
end
=
1.0
;
while
(
true
)
{
...
...
@@ -235,6 +240,7 @@ class _DecelerateCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
// Intended to match the behavior of:
// https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/view/animation/DecelerateInterpolator.java
// ...as of December 2016.
...
...
@@ -268,6 +274,7 @@ class _BounceInCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
return
1.0
-
_bounce
(
1.0
-
t
);
}
}
...
...
@@ -280,6 +287,7 @@ class _BounceOutCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
return
_bounce
(
t
);
}
}
...
...
@@ -292,6 +300,7 @@ class _BounceInOutCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
if
(
t
<
0.5
)
return
(
1.0
-
_bounce
(
1.0
-
t
))
*
0.5
;
else
...
...
@@ -314,6 +323,7 @@ class ElasticInCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
double
s
=
period
/
4.0
;
t
=
t
-
1.0
;
return
-
math
.
pow
(
2.0
,
10.0
*
t
)
*
math
.
sin
((
t
-
s
)
*
(
math
.
PI
*
2.0
)
/
period
);
...
...
@@ -337,6 +347,7 @@ class ElasticOutCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
double
s
=
period
/
4.0
;
return
math
.
pow
(
2.0
,
-
10
*
t
)
*
math
.
sin
((
t
-
s
)
*
(
math
.
PI
*
2.0
)
/
period
)
+
1.0
;
}
...
...
@@ -359,6 +370,7 @@ class ElasticInOutCurve extends Curve {
@override
double
transform
(
double
t
)
{
assert
(
t
>=
0.0
&&
t
<=
1.0
);
double
s
=
period
/
4.0
;
t
=
2.0
*
t
-
1.0
;
if
(
t
<
0.0
)
...
...
packages/flutter/test/animation/curves_test.dart
View file @
c613a85c
...
...
@@ -103,4 +103,37 @@ void main() {
double
d2
=
Curves
.
decelerate
.
transform
(
1.0
)
-
Curves
.
decelerate
.
transform
(
0.8
);
expect
(
d2
,
lessThan
(
d1
));
});
test
(
'Invalid transform parameter should assert'
,
()
{
expect
(()
=>
const
SawTooth
(
2
).
transform
(-
0.0001
),
throws
);
expect
(()
=>
const
SawTooth
(
2
).
transform
(
1.0001
),
throws
);
expect
(()
=>
const
Interval
(
0.0
,
1.0
).
transform
(-
0.0001
),
throws
);
expect
(()
=>
const
Interval
(
0.0
,
1.0
).
transform
(
1.0001
),
throws
);
expect
(()
=>
const
Threshold
(
0.5
).
transform
(-
0.0001
),
throws
);
expect
(()
=>
const
Threshold
(
0.5
).
transform
(
1.0001
),
throws
);
expect
(()
=>
const
ElasticInCurve
().
transform
(-
0.0001
),
throws
);
expect
(()
=>
const
ElasticInCurve
().
transform
(
1.0001
),
throws
);
expect
(()
=>
const
ElasticOutCurve
().
transform
(-
0.0001
),
throws
);
expect
(()
=>
const
ElasticOutCurve
().
transform
(
1.0001
),
throws
);
expect
(()
=>
const
Cubic
(
0.42
,
0.0
,
0.58
,
1.0
).
transform
(-
0.0001
),
throws
);
expect
(()
=>
const
Cubic
(
0.42
,
0.0
,
0.58
,
1.0
).
transform
(
1.0001
),
throws
);
expect
(()
=>
Curves
.
decelerate
.
transform
(-
0.0001
),
throws
);
expect
(()
=>
Curves
.
decelerate
.
transform
(
1.0001
),
throws
);
expect
(()
=>
Curves
.
bounceIn
.
transform
(-
0.0001
),
throws
);
expect
(()
=>
Curves
.
bounceIn
.
transform
(
1.0001
),
throws
);
expect
(()
=>
Curves
.
bounceOut
.
transform
(-
0.0001
),
throws
);
expect
(()
=>
Curves
.
bounceOut
.
transform
(
1.0001
),
throws
);
expect
(()
=>
Curves
.
bounceInOut
.
transform
(-
0.0001
),
throws
);
expect
(()
=>
Curves
.
bounceInOut
.
transform
(
1.0001
),
throws
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment