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
e5a96aca
Commit
e5a96aca
authored
Oct 14, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ScrollSpringSimulation
SimulationGroup isDone() now uses currentIntervalOffset
parent
09099a17
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
7 deletions
+47
-7
scroll_simulation.dart
packages/newton/lib/src/scroll_simulation.dart
+2
-2
simulation_group.dart
packages/newton/lib/src/simulation_group.dart
+1
-1
spring_simulation.dart
packages/newton/lib/src/spring_simulation.dart
+20
-0
newton_test.dart
packages/newton/test/newton_test.dart
+24
-4
No files found.
packages/newton/lib/src/scroll_simulation.dart
View file @
e5a96aca
...
...
@@ -47,12 +47,12 @@ class ScrollSimulation extends SimulationGroup {
if
(
position
>
_trailingExtent
)
{
_isSpringing
=
true
;
_offset
=
intervalOffset
;
_currentSimulation
=
new
SpringSimulation
(
_spring
,
position
,
_trailingExtent
,
velocity
);
_currentSimulation
=
new
S
crollS
pringSimulation
(
_spring
,
position
,
_trailingExtent
,
velocity
);
return
true
;
}
else
if
(
position
<
_leadingExtent
)
{
_isSpringing
=
true
;
_offset
=
intervalOffset
;
_currentSimulation
=
new
SpringSimulation
(
_spring
,
position
,
_leadingExtent
,
velocity
);
_currentSimulation
=
new
S
crollS
pringSimulation
(
_spring
,
position
,
_leadingExtent
,
velocity
);
return
true
;
}
}
...
...
packages/newton/lib/src/simulation_group.dart
View file @
e5a96aca
...
...
@@ -41,7 +41,7 @@ abstract class SimulationGroup extends Simulation {
@override
bool
isDone
(
double
time
)
{
_stepIfNecessary
(
time
);
return
currentSimulation
.
isDone
(
time
);
return
currentSimulation
.
isDone
(
time
-
currentIntervalOffset
);
}
double
_lastStep
=
-
1.0
;
...
...
packages/newton/lib/src/spring_simulation.dart
View file @
e5a96aca
...
...
@@ -61,3 +61,23 @@ class SpringSimulation extends Simulation {
_nearEqual
(
x
(
time
),
_endPosition
,
this
.
tolerance
.
distance
)
&&
_nearZero
(
dx
(
time
),
this
.
tolerance
.
velocity
);
}
/// A SpringSimulation where the value of x() is guaranteed to have exactly the
/// end value when the simulation isDone().
class
ScrollSpringSimulation
extends
SpringSimulation
{
ScrollSpringSimulation
(
SpringDescription
desc
,
double
start
,
double
end
,
double
velocity
)
:
super
(
desc
,
start
,
end
,
velocity
);
bool
_isDone
(
double
position
,
double
velocity
)
{
return
_nearEqual
(
position
,
_endPosition
,
tolerance
.
distance
)
&&
_nearZero
(
velocity
,
tolerance
.
velocity
);
}
@override
double
x
(
double
time
)
{
double
xAtTime
=
super
.
x
(
time
);
return
_isDone
(
xAtTime
,
dx
(
time
))
?
_endPosition
:
xAtTime
;
}
@override
bool
isDone
(
double
time
)
=>
_isDone
(
x
(
time
),
dx
(
time
));
}
packages/newton/test/newton_test.dart
View file @
e5a96aca
...
...
@@ -194,14 +194,16 @@ void main() {
mass:
1.0
,
springConstant:
50.0
,
ratio:
0.5
);
var
scroll
=
new
ScrollSimulation
(
100.0
,
800.0
,
0.0
,
300.0
,
spring
,
0.3
);
scroll
.
tolerance
=
const
Tolerance
(
velocity:
0.01
,
distance:
0.01
);
scroll
.
tolerance
=
const
Tolerance
(
velocity:
0.5
,
distance:
0.1
);
expect
(
scroll
.
isDone
(
0.0
),
false
);
expect
(
scroll
.
isDone
(
0.5
),
false
);
// switch from friction to spring
expect
(
scroll
.
isDone
(
3.5
),
true
);
var
scroll2
=
new
ScrollSimulation
(
100.0
,
-
800.0
,
0.0
,
300.0
,
spring
,
0.3
);
expect
(
scroll2
.
isDone
(
4.5
),
true
);
scroll2
.
tolerance
=
const
Tolerance
(
velocity:
0.5
,
distance:
0.1
);
expect
(
scroll2
.
isDone
(
0.0
),
false
);
expect
(
scroll2
.
isDone
(
0.5
),
false
);
// switch from friction to spring
expect
(
scroll2
.
isDone
(
3.5
),
true
);
});
test
(
'scroll_with_inf_edge_ends'
,
()
{
...
...
@@ -229,4 +231,22 @@ void main() {
// We should never switch
expect
(
scroll
.
currentIntervalOffset
,
0.0
);
});
test
(
'over/under scroll spring'
,
()
{
var
spring
=
new
SpringDescription
.
withDampingRatio
(
mass:
1.0
,
springConstant:
170.0
,
ratio:
1.1
);
var
scroll
=
new
ScrollSimulation
(
500.0
,
-
7500.0
,
0.0
,
1000.0
,
spring
,
0.025
);
scroll
.
tolerance
=
new
Tolerance
(
velocity:
45.0
,
distance:
1.5
);
expect
(
scroll
.
isDone
(
0.0
),
false
);
expect
(
scroll
.
x
(
0.0
),
closeTo
(
500.0
,
.
0001
));
expect
(
scroll
.
dx
(
0.0
),
closeTo
(-
7500.0
,
.
0001
));
expect
(
scroll
.
isDone
(
0.025
),
false
);
expect
(
scroll
.
x
(
0.025
),
closeTo
(
320.0
,
1.0
));
expect
(
scroll
.
dx
(
0.25
),
closeTo
(-
2982
,
1.0
));
expect
(
scroll
.
isDone
(
2.0
),
true
);
expect
(
scroll
.
x
(
2.0
),
0.0
);
expect
(
scroll
.
dx
(
2.0
),
closeTo
(
0.0
,
45.0
));
});
}
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