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
eaa72f6e
Commit
eaa72f6e
authored
Sep 22, 2015
by
Hans Muller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No new functionality, just some gratuitous changes.
parent
32ff3e59
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
20 deletions
+19
-20
README.md
packages/newton/README.md
+4
-0
scroll_simulation.dart
packages/newton/lib/src/scroll_simulation.dart
+15
-19
newton_test.dart
packages/newton/test/newton_test.dart
+0
-1
No files found.
packages/newton/README.md
View file @
eaa72f6e
...
...
@@ -3,3 +3,7 @@
[
![Coverage Status
](
https://coveralls.io/repos/domokit/newton/badge.svg?branch=master
)
](https://coveralls.io/r/domokit/newton?branch=master)
Simple Physics Simulations for Dart. Springs, friction, gravity, etc.
To run the tests:
pub get
dart test/newton_test.dart
packages/newton/lib/src/scroll_simulation.dart
View file @
eaa72f6e
...
...
@@ -8,24 +8,25 @@ part of newton;
/// boundary. Friction is applied within the extends and a spring action applied
/// at the boundaries. This simulation can only step forward.
class
ScrollSimulation
extends
SimulationGroup
{
ScrollSimulation
(
double
position
,
double
velocity
,
this
.
_leadingExtent
,
this
.
_trailingExtent
,
this
.
_spring
,
this
.
_drag
)
{
_chooseSimulation
(
position
,
velocity
,
0.0
);
}
final
double
_leadingExtent
;
final
double
_trailingExtent
;
final
SpringDescription
_spring
Desc
;
final
SpringDescription
_spring
;
final
double
_drag
;
bool
_isSpringing
=
false
;
Simulation
_currentSimulation
;
double
_offset
=
0.0
;
ScrollSimulation
(
double
position
,
double
velocity
,
double
leading
,
double
trailing
,
SpringDescription
spring
,
double
drag
)
:
_leadingExtent
=
leading
,
_trailingExtent
=
trailing
,
_springDesc
=
spring
,
_drag
=
drag
{
_chooseSimulation
(
position
,
velocity
,
0.0
);
}
@override
bool
step
(
double
time
)
=>
_chooseSimulation
(
_currentSimulation
.
x
(
time
-
_offset
),
...
...
@@ -37,11 +38,8 @@ class ScrollSimulation extends SimulationGroup {
@override
double
get
currentIntervalOffset
=>
_offset
;
bool
_chooseSimulation
(
double
position
,
double
velocity
,
double
intervalOffset
)
{
if
(
_springDesc
==
null
&&
(
position
>
_trailingExtent
||
position
<
_leadingExtent
))
bool
_chooseSimulation
(
double
position
,
double
velocity
,
double
intervalOffset
)
{
if
(
_spring
==
null
&&
(
position
>
_trailingExtent
||
position
<
_leadingExtent
))
return
false
;
/// This simulation can only step forward.
...
...
@@ -49,14 +47,12 @@ class ScrollSimulation extends SimulationGroup {
if
(
position
>
_trailingExtent
)
{
_isSpringing
=
true
;
_offset
=
intervalOffset
;
_currentSimulation
=
new
SpringSimulation
(
_springDesc
,
position
,
_trailingExtent
,
velocity
);
_currentSimulation
=
new
SpringSimulation
(
_spring
,
position
,
_trailingExtent
,
velocity
);
return
true
;
}
else
if
(
position
<
_leadingExtent
)
{
_isSpringing
=
true
;
_offset
=
intervalOffset
;
_currentSimulation
=
new
SpringSimulation
(
_springDesc
,
position
,
_leadingExtent
,
velocity
);
_currentSimulation
=
new
SpringSimulation
(
_spring
,
position
,
_leadingExtent
,
velocity
);
return
true
;
}
}
...
...
packages/newton/test/newton_test.dart
View file @
eaa72f6e
...
...
@@ -168,7 +168,6 @@ void main() {
var
scroll
=
new
ScrollSimulation
(
100.0
,
400.0
,
0.0
,
double
.
INFINITY
,
spring
,
0.3
);
scroll
.
tolerance
=
const
Tolerance
(
velocity:
1.0
);
expect
(
scroll
.
isDone
(
0.0
),
false
);
...
...
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