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
fc098d8c
Commit
fc098d8c
authored
Jul 06, 2015
by
Chinmay Garde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename concrete simulation subclasses
parent
9932e9f0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
32 deletions
+33
-32
newton.dart
packages/newton/lib/newton.dart
+4
-4
friction_simulation.dart
packages/newton/lib/src/friction_simulation.dart
+5
-5
gravity_simulation.dart
packages/newton/lib/src/gravity_simulation.dart
+2
-2
scroll_simulation.dart
packages/newton/lib/src/scroll_simulation.dart
+8
-8
spring_simulation.dart
packages/newton/lib/src/spring_simulation.dart
+2
-2
newton_test.dart
packages/newton/test/newton_test.dart
+12
-11
No files found.
packages/newton/lib/newton.dart
View file @
fc098d8c
...
...
@@ -10,8 +10,8 @@ part 'src/simulation.dart';
part
'src/simulation_group.dart'
;
part
'src/utils.dart'
;
part
'src/friction.dart'
;
part
'src/gravity.dart'
;
part
'src/scroll.dart'
;
part
'src/spring.dart'
;
part
'src/friction
_simulation
.dart'
;
part
'src/gravity
_simulation
.dart'
;
part
'src/scroll
_simulation
.dart'
;
part
'src/spring
_simulation
.dart'
;
part
'src/spring_solution.dart'
;
packages/newton/lib/src/friction.dart
→
packages/newton/lib/src/friction
_simulation
.dart
View file @
fc098d8c
...
...
@@ -4,20 +4,20 @@
part of
newton
;
class
Friction
extends
Simulation
{
class
Friction
Simulation
extends
Simulation
{
final
double
_drag
;
final
double
_drag
Natural
Log
;
final
double
_dragLog
;
final
double
_x
;
final
double
_v
;
Friction
(
double
drag
,
double
position
,
double
velocity
)
Friction
Simulation
(
double
drag
,
double
position
,
double
velocity
)
:
_drag
=
drag
,
_drag
Natural
Log
=
Math
.
log
(
drag
),
_dragLog
=
Math
.
log
(
drag
),
_x
=
position
,
_v
=
velocity
;
double
x
(
double
time
)
=>
_x
+
_v
*
Math
.
pow
(
_drag
,
time
)
/
_drag
NaturalLog
-
_v
/
_dragNatural
Log
;
_x
+
_v
*
Math
.
pow
(
_drag
,
time
)
/
_drag
Log
-
_v
/
_drag
Log
;
double
dx
(
double
time
)
=>
_v
*
Math
.
pow
(
_drag
,
time
);
...
...
packages/newton/lib/src/gravity.dart
→
packages/newton/lib/src/gravity
_simulation
.dart
View file @
fc098d8c
...
...
@@ -4,13 +4,13 @@
part of
newton
;
class
Gravity
extends
Simulation
{
class
Gravity
Simulation
extends
Simulation
{
final
double
_x
;
final
double
_v
;
final
double
_a
;
final
double
_end
;
Gravity
(
Gravity
Simulation
(
double
acceleration
,
double
distance
,
double
endDistance
,
double
velocity
)
:
_a
=
acceleration
,
_x
=
distance
,
...
...
packages/newton/lib/src/scroll.dart
→
packages/newton/lib/src/scroll
_simulation
.dart
View file @
fc098d8c
...
...
@@ -7,7 +7,7 @@ part of newton;
/// Simulates kinetic scrolling behavior between a leading and trailing
/// boundary. Friction is applied within the extends and a spring action applied
/// at the boundaries. This simulation can only step forward.
class
Scroll
extends
SimulationGroup
{
class
Scroll
Simulation
extends
SimulationGroup
{
final
double
_leadingExtent
;
final
double
_trailingExtent
;
final
SpringDesc
_springDesc
;
...
...
@@ -17,8 +17,8 @@ class Scroll extends SimulationGroup {
Simulation
_currentSimulation
;
double
_offset
=
0.0
;
Scroll
(
double
position
,
double
velocity
,
double
leading
,
double
trail
ing
,
SpringDesc
spring
,
double
drag
)
Scroll
Simulation
(
double
position
,
double
velocity
,
double
lead
ing
,
double
trailing
,
SpringDesc
spring
,
double
drag
)
:
_leadingExtent
=
leading
,
_trailingExtent
=
trailing
,
_springDesc
=
spring
,
...
...
@@ -45,20 +45,20 @@ class Scroll extends SimulationGroup {
if
(
position
>
_trailingExtent
)
{
_isSpringing
=
true
;
_offset
=
intervalOffset
;
_currentSimulation
=
new
Spring
(
_springDesc
,
position
,
_trailingExtent
,
velocity
);
_currentSimulation
=
new
SpringSimulation
(
_springDesc
,
position
,
_trailingExtent
,
velocity
);
return
;
}
else
if
(
position
<
_leadingExtent
)
{
_isSpringing
=
true
;
_offset
=
intervalOffset
;
_currentSimulation
=
new
Spring
(
_springDesc
,
position
,
_leadingExtent
,
velocity
);
_currentSimulation
=
new
SpringSimulation
(
_springDesc
,
position
,
_leadingExtent
,
velocity
);
return
;
}
}
if
(
_currentSimulation
==
null
)
{
_currentSimulation
=
new
Friction
(
_drag
,
position
,
velocity
);
_currentSimulation
=
new
Friction
Simulation
(
_drag
,
position
,
velocity
);
return
;
}
}
...
...
packages/newton/lib/src/spring.dart
→
packages/newton/lib/src/spring
_simulation
.dart
View file @
fc098d8c
...
...
@@ -32,14 +32,14 @@ enum SpringType { unknown, criticallyDamped, underDamped, overDamped, }
/// Creates a spring simulation. Depending on the spring description, a
/// critically, under or overdamped spring will be created.
class
Spring
extends
Simulation
{
class
Spring
Simulation
extends
Simulation
{
final
double
_endPosition
;
final
_SpringSolution
_solution
;
/// A spring description with the provided spring description, start distance,
/// end distance and velocity.
Spring
(
SpringDesc
desc
,
double
start
,
double
end
,
double
velocity
)
Spring
Simulation
(
SpringDesc
desc
,
double
start
,
double
end
,
double
velocity
)
:
this
.
_endPosition
=
end
,
_solution
=
new
_SpringSolution
(
desc
,
start
-
end
,
velocity
);
...
...
packages/newton/test/newton_test.dart
View file @
fc098d8c
...
...
@@ -10,7 +10,7 @@ import 'package:newton/newton.dart';
void
main
(
)
{
test
(
'test_friction'
,
()
{
var
friction
=
new
Friction
(
0.3
,
100.0
,
400.0
);
var
friction
=
new
Friction
Simulation
(
0.3
,
100.0
,
400.0
);
expect
(
friction
.
isDone
(
0.0
),
false
);
expect
(
friction
.
x
(
0.0
),
100
);
...
...
@@ -28,7 +28,7 @@ void main() {
});
test
(
'test_gravity'
,
()
{
var
gravity
=
new
Gravity
(
200.0
,
100.0
,
600.0
,
0.0
);
var
gravity
=
new
Gravity
Simulation
(
200.0
,
100.0
,
600.0
,
0.0
);
expect
(
gravity
.
isDone
(
0.0
),
false
);
expect
(
gravity
.
x
(
0.0
),
100.0
);
...
...
@@ -58,25 +58,26 @@ void main() {
});
test
(
'spring_types'
,
()
{
var
crit
=
new
Spring
(
var
crit
=
new
Spring
Simulation
(
new
SpringDesc
.
withDampingRatio
(
1.0
,
100.0
,
1.0
),
0.0
,
300.0
,
0.0
);
expect
(
crit
.
type
,
SpringType
.
criticallyDamped
);
var
under
=
new
Spring
(
var
under
=
new
Spring
Simulation
(
new
SpringDesc
.
withDampingRatio
(
1.0
,
100.0
,
0.75
),
0.0
,
300.0
,
0.0
);
expect
(
under
.
type
,
SpringType
.
underDamped
);
var
over
=
new
Spring
(
var
over
=
new
Spring
Simulation
(
new
SpringDesc
.
withDampingRatio
(
1.0
,
100.0
,
1.25
),
0.0
,
300.0
,
0.0
);
expect
(
over
.
type
,
SpringType
.
overDamped
);
// Just so we don't forget how to create a desc without the ratio.
var
other
=
new
Spring
(
new
SpringDesc
(
1.0
,
100.0
,
20.0
),
0.0
,
20.0
,
20.0
);
var
other
=
new
SpringSimulation
(
new
SpringDesc
(
1.0
,
100.0
,
20.0
),
0.0
,
20.0
,
20.0
);
expect
(
other
.
type
,
SpringType
.
criticallyDamped
);
});
test
(
'crit_spring'
,
()
{
var
crit
=
new
Spring
(
var
crit
=
new
Spring
Simulation
(
new
SpringDesc
.
withDampingRatio
(
1.0
,
100.0
,
1.0
),
0.0
,
500.0
,
0.0
);
expect
(
crit
.
type
,
SpringType
.
criticallyDamped
);
...
...
@@ -98,7 +99,7 @@ void main() {
});
test
(
'overdamped_spring'
,
()
{
var
over
=
new
Spring
(
var
over
=
new
Spring
Simulation
(
new
SpringDesc
.
withDampingRatio
(
1.0
,
100.0
,
1.25
),
0.0
,
500.0
,
0.0
);
expect
(
over
.
type
,
SpringType
.
overDamped
);
...
...
@@ -117,7 +118,7 @@ void main() {
});
test
(
'underdamped_spring'
,
()
{
var
under
=
new
Spring
(
var
under
=
new
Spring
Simulation
(
new
SpringDesc
.
withDampingRatio
(
1.0
,
100.0
,
0.25
),
0.0
,
300.0
,
0.0
);
expect
(
under
.
type
,
SpringType
.
underDamped
);
...
...
@@ -136,12 +137,12 @@ void main() {
test
(
'test_kinetic_scroll'
,
()
{
var
spring
=
new
SpringDesc
.
withDampingRatio
(
1.0
,
50.0
,
0.5
);
var
scroll
=
new
Scroll
(
100.0
,
800.0
,
0.0
,
300.0
,
spring
,
0.3
);
var
scroll
=
new
Scroll
Simulation
(
100.0
,
800.0
,
0.0
,
300.0
,
spring
,
0.3
);
expect
(
scroll
.
isDone
(
0.0
),
false
);
expect
(
scroll
.
isDone
(
3.5
),
true
);
var
scroll2
=
new
Scroll
(
100.0
,
-
800.0
,
0.0
,
300.0
,
spring
,
0.3
);
var
scroll2
=
new
Scroll
Simulation
(
100.0
,
-
800.0
,
0.0
,
300.0
,
spring
,
0.3
);
expect
(
scroll2
.
isDone
(
4.5
),
true
);
});
}
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