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
d9061bc9
Commit
d9061bc9
authored
Mar 01, 2016
by
Adam Barth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch Newton over to using imports rather than parts
Fixes #1355
parent
f3561d80
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
153 additions
and
155 deletions
+153
-155
newton.dart
packages/newton/lib/newton.dart
+9
-13
clamped_simulation.dart
packages/newton/lib/src/clamped_simulation.dart
+1
-1
friction_simulation.dart
packages/newton/lib/src/friction_simulation.dart
+5
-2
gravity_simulation.dart
packages/newton/lib/src/gravity_simulation.dart
+2
-2
scroll_simulation.dart
packages/newton/lib/src/scroll_simulation.dart
+5
-2
simulation.dart
packages/newton/lib/src/simulation.dart
+2
-2
simulation_group.dart
packages/newton/lib/src/simulation_group.dart
+5
-3
spring_simulation.dart
packages/newton/lib/src/spring_simulation.dart
+120
-4
spring_solution.dart
packages/newton/lib/src/spring_solution.dart
+0
-118
tolerance.dart
packages/newton/lib/src/tolerance.dart
+1
-3
utils.dart
packages/newton/lib/src/utils.dart
+3
-5
No files found.
packages/newton/lib/newton.dart
View file @
d9061bc9
...
...
@@ -5,16 +5,12 @@
/// Simple Physics Simulations for Dart. Springs, friction, gravity, etc.
library
newton
;
import
'dart:math'
as
math
;
part
'src/simulation.dart'
;
part
'src/simulation_group.dart'
;
part
'src/tolerance.dart'
;
part
'src/utils.dart'
;
part
'src/clamped_simulation.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'
;
export
'src/clamped_simulation.dart'
;
export
'src/friction_simulation.dart'
;
export
'src/gravity_simulation.dart'
;
export
'src/scroll_simulation.dart'
;
export
'src/simulation_group.dart'
;
export
'src/simulation.dart'
;
export
'src/spring_simulation.dart'
;
export
'src/tolerance.dart'
;
export
'src/utils.dart'
;
packages/newton/lib/src/clamped_simulation.dart
View file @
d9061bc9
...
...
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'simulation.dart'
;
class
ClampedSimulation
extends
Simulation
{
ClampedSimulation
(
this
.
simulation
,
{
...
...
packages/newton/lib/src/friction_simulation.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'dart:math'
as
math
;
import
'simulation.dart'
;
import
'tolerance.dart'
;
class
FrictionSimulation
extends
Simulation
{
final
double
_drag
;
...
...
packages/newton/lib/src/gravity_simulation.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'simulation.dart'
;
class
GravitySimulation
extends
Simulation
{
final
double
_x
;
...
...
packages/newton/lib/src/scroll_simulation.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'friction_simulation.dart'
;
import
'simulation_group.dart'
;
import
'simulation.dart'
;
import
'spring_simulation.dart'
;
/// Simulates kinetic scrolling behavior between a leading and trailing
/// boundary. Friction is applied within the extends and a spring action applied
...
...
packages/newton/lib/src/simulation.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'tolerance.dart'
;
abstract
class
Simulatable
{
/// The current position of the object in the simulation
...
...
packages/newton/lib/src/simulation_group.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'simulation.dart'
;
import
'tolerance.dart'
;
import
'utils.dart'
;
/// The abstract base class for all composite simulations. Concrete subclasses
/// must implement the appropriate methods to select the appropriate simulation
...
...
@@ -46,7 +48,7 @@ abstract class SimulationGroup extends Simulation {
double
_lastStep
=
-
1.0
;
void
_stepIfNecessary
(
double
time
)
{
if
(
_
nearEqual
(
_lastStep
,
time
,
toleranceDefault
.
time
))
{
if
(
nearEqual
(
_lastStep
,
time
,
toleranceDefault
.
time
))
{
return
;
}
...
...
packages/newton/lib/src/spring_simulation.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
import
'dart:math'
as
math
;
import
'simulation.dart'
;
import
'utils.dart'
;
abstract
class
_SpringSolution
implements
Simulatable
{
factory
_SpringSolution
(
SpringDescription
desc
,
double
initialPosition
,
double
initialVelocity
)
{
double
cmk
=
desc
.
damping
*
desc
.
damping
-
4
*
desc
.
mass
*
desc
.
springConstant
;
if
(
cmk
==
0.0
)
{
return
new
_CriticalSolution
(
desc
,
initialPosition
,
initialVelocity
);
}
else
if
(
cmk
>
0.0
)
{
return
new
_OverdampedSolution
(
desc
,
initialPosition
,
initialVelocity
);
}
else
{
return
new
_UnderdampedSolution
(
desc
,
initialPosition
,
initialVelocity
);
}
return
null
;
}
SpringType
get
type
;
}
class
_CriticalSolution
implements
_SpringSolution
{
final
double
_r
,
_c1
,
_c2
;
factory
_CriticalSolution
(
SpringDescription
desc
,
double
distance
,
double
velocity
)
{
final
double
r
=
-
desc
.
damping
/
(
2.0
*
desc
.
mass
);
final
double
c1
=
distance
;
final
double
c2
=
velocity
/
(
r
*
distance
);
return
new
_CriticalSolution
.
withArgs
(
r
,
c1
,
c2
);
}
SpringType
get
type
=>
SpringType
.
criticallyDamped
;
_CriticalSolution
.
withArgs
(
double
r
,
double
c1
,
double
c2
)
:
_r
=
r
,
_c1
=
c1
,
_c2
=
c2
;
double
x
(
double
time
)
=>
(
_c1
+
_c2
*
time
)
*
math
.
pow
(
math
.
E
,
_r
*
time
);
double
dx
(
double
time
)
{
final
double
power
=
math
.
pow
(
math
.
E
,
_r
*
time
);
return
_r
*
(
_c1
+
_c2
*
time
)
*
power
+
_c2
*
power
;
}
}
class
_OverdampedSolution
implements
_SpringSolution
{
final
double
_r1
,
_r2
,
_c1
,
_c2
;
factory
_OverdampedSolution
(
SpringDescription
desc
,
double
distance
,
double
velocity
)
{
final
double
cmk
=
desc
.
damping
*
desc
.
damping
-
4
*
desc
.
mass
*
desc
.
springConstant
;
final
double
r1
=
(-
desc
.
damping
-
math
.
sqrt
(
cmk
))
/
(
2.0
*
desc
.
mass
);
final
double
r2
=
(-
desc
.
damping
+
math
.
sqrt
(
cmk
))
/
(
2.0
*
desc
.
mass
);
final
double
c2
=
(
velocity
-
r1
*
distance
)
/
(
r2
-
r1
);
final
double
c1
=
distance
-
c2
;
return
new
_OverdampedSolution
.
withArgs
(
r1
,
r2
,
c1
,
c2
);
}
_OverdampedSolution
.
withArgs
(
double
r1
,
double
r2
,
double
c1
,
double
c2
)
:
_r1
=
r1
,
_r2
=
r2
,
_c1
=
c1
,
_c2
=
c2
;
SpringType
get
type
=>
SpringType
.
overDamped
;
double
x
(
double
time
)
=>
(
_c1
*
math
.
pow
(
math
.
E
,
_r1
*
time
)
+
_c2
*
math
.
pow
(
math
.
E
,
_r2
*
time
));
double
dx
(
double
time
)
=>
(
_c1
*
_r1
*
math
.
pow
(
math
.
E
,
_r1
*
time
)
+
_c2
*
_r2
*
math
.
pow
(
math
.
E
,
_r2
*
time
));
}
class
_UnderdampedSolution
implements
_SpringSolution
{
final
double
_w
,
_r
,
_c1
,
_c2
;
factory
_UnderdampedSolution
(
SpringDescription
desc
,
double
distance
,
double
velocity
)
{
final
double
w
=
math
.
sqrt
(
4.0
*
desc
.
mass
*
desc
.
springConstant
-
desc
.
damping
*
desc
.
damping
)
/
(
2.0
*
desc
.
mass
);
final
double
r
=
-(
desc
.
damping
/
2.0
*
desc
.
mass
);
final
double
c1
=
distance
;
final
double
c2
=
(
velocity
-
r
*
distance
)
/
w
;
return
new
_UnderdampedSolution
.
withArgs
(
w
,
r
,
c1
,
c2
);
}
_UnderdampedSolution
.
withArgs
(
double
w
,
double
r
,
double
c1
,
double
c2
)
:
_w
=
w
,
_r
=
r
,
_c1
=
c1
,
_c2
=
c2
;
SpringType
get
type
=>
SpringType
.
underDamped
;
double
x
(
double
time
)
=>
math
.
pow
(
math
.
E
,
_r
*
time
)
*
(
_c1
*
math
.
cos
(
_w
*
time
)
+
_c2
*
math
.
sin
(
_w
*
time
));
double
dx
(
double
time
)
{
final
double
power
=
math
.
pow
(
math
.
E
,
_r
*
time
);
final
double
cosine
=
math
.
cos
(
_w
*
time
);
final
double
sine
=
math
.
sin
(
_w
*
time
);
return
power
*
(
_c2
*
_w
*
cosine
-
_c1
*
_w
*
sine
)
+
_r
*
power
*
(
_c2
*
sine
+
_c1
*
cosine
);
}
}
class
SpringDescription
{
/// The mass of the spring (m)
...
...
@@ -58,8 +174,8 @@ class SpringSimulation extends Simulation {
double
dx
(
double
time
)
=>
_solution
.
dx
(
time
);
bool
isDone
(
double
time
)
{
return
_
nearZero
(
_solution
.
x
(
time
),
tolerance
.
distance
)
&&
_
nearZero
(
_solution
.
dx
(
time
),
tolerance
.
velocity
);
return
nearZero
(
_solution
.
x
(
time
),
tolerance
.
distance
)
&&
nearZero
(
_solution
.
dx
(
time
),
tolerance
.
velocity
);
}
}
...
...
packages/newton/lib/src/spring_solution.dart
deleted
100644 → 0
View file @
f3561d80
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
abstract
class
_SpringSolution
implements
Simulatable
{
factory
_SpringSolution
(
SpringDescription
desc
,
double
initialPosition
,
double
initialVelocity
)
{
double
cmk
=
desc
.
damping
*
desc
.
damping
-
4
*
desc
.
mass
*
desc
.
springConstant
;
if
(
cmk
==
0.0
)
{
return
new
_CriticalSolution
(
desc
,
initialPosition
,
initialVelocity
);
}
else
if
(
cmk
>
0.0
)
{
return
new
_OverdampedSolution
(
desc
,
initialPosition
,
initialVelocity
);
}
else
{
return
new
_UnderdampedSolution
(
desc
,
initialPosition
,
initialVelocity
);
}
return
null
;
}
SpringType
get
type
;
}
class
_CriticalSolution
implements
_SpringSolution
{
final
double
_r
,
_c1
,
_c2
;
factory
_CriticalSolution
(
SpringDescription
desc
,
double
distance
,
double
velocity
)
{
final
double
r
=
-
desc
.
damping
/
(
2.0
*
desc
.
mass
);
final
double
c1
=
distance
;
final
double
c2
=
velocity
/
(
r
*
distance
);
return
new
_CriticalSolution
.
withArgs
(
r
,
c1
,
c2
);
}
SpringType
get
type
=>
SpringType
.
criticallyDamped
;
_CriticalSolution
.
withArgs
(
double
r
,
double
c1
,
double
c2
)
:
_r
=
r
,
_c1
=
c1
,
_c2
=
c2
;
double
x
(
double
time
)
=>
(
_c1
+
_c2
*
time
)
*
math
.
pow
(
math
.
E
,
_r
*
time
);
double
dx
(
double
time
)
{
final
double
power
=
math
.
pow
(
math
.
E
,
_r
*
time
);
return
_r
*
(
_c1
+
_c2
*
time
)
*
power
+
_c2
*
power
;
}
}
class
_OverdampedSolution
implements
_SpringSolution
{
final
double
_r1
,
_r2
,
_c1
,
_c2
;
factory
_OverdampedSolution
(
SpringDescription
desc
,
double
distance
,
double
velocity
)
{
final
double
cmk
=
desc
.
damping
*
desc
.
damping
-
4
*
desc
.
mass
*
desc
.
springConstant
;
final
double
r1
=
(-
desc
.
damping
-
math
.
sqrt
(
cmk
))
/
(
2.0
*
desc
.
mass
);
final
double
r2
=
(-
desc
.
damping
+
math
.
sqrt
(
cmk
))
/
(
2.0
*
desc
.
mass
);
final
double
c2
=
(
velocity
-
r1
*
distance
)
/
(
r2
-
r1
);
final
double
c1
=
distance
-
c2
;
return
new
_OverdampedSolution
.
withArgs
(
r1
,
r2
,
c1
,
c2
);
}
_OverdampedSolution
.
withArgs
(
double
r1
,
double
r2
,
double
c1
,
double
c2
)
:
_r1
=
r1
,
_r2
=
r2
,
_c1
=
c1
,
_c2
=
c2
;
SpringType
get
type
=>
SpringType
.
overDamped
;
double
x
(
double
time
)
=>
(
_c1
*
math
.
pow
(
math
.
E
,
_r1
*
time
)
+
_c2
*
math
.
pow
(
math
.
E
,
_r2
*
time
));
double
dx
(
double
time
)
=>
(
_c1
*
_r1
*
math
.
pow
(
math
.
E
,
_r1
*
time
)
+
_c2
*
_r2
*
math
.
pow
(
math
.
E
,
_r2
*
time
));
}
class
_UnderdampedSolution
implements
_SpringSolution
{
final
double
_w
,
_r
,
_c1
,
_c2
;
factory
_UnderdampedSolution
(
SpringDescription
desc
,
double
distance
,
double
velocity
)
{
final
double
w
=
math
.
sqrt
(
4.0
*
desc
.
mass
*
desc
.
springConstant
-
desc
.
damping
*
desc
.
damping
)
/
(
2.0
*
desc
.
mass
);
final
double
r
=
-(
desc
.
damping
/
2.0
*
desc
.
mass
);
final
double
c1
=
distance
;
final
double
c2
=
(
velocity
-
r
*
distance
)
/
w
;
return
new
_UnderdampedSolution
.
withArgs
(
w
,
r
,
c1
,
c2
);
}
_UnderdampedSolution
.
withArgs
(
double
w
,
double
r
,
double
c1
,
double
c2
)
:
_w
=
w
,
_r
=
r
,
_c1
=
c1
,
_c2
=
c2
;
SpringType
get
type
=>
SpringType
.
underDamped
;
double
x
(
double
time
)
=>
math
.
pow
(
math
.
E
,
_r
*
time
)
*
(
_c1
*
math
.
cos
(
_w
*
time
)
+
_c2
*
math
.
sin
(
_w
*
time
));
double
dx
(
double
time
)
{
final
double
power
=
math
.
pow
(
math
.
E
,
_r
*
time
);
final
double
cosine
=
math
.
cos
(
_w
*
time
);
final
double
sine
=
math
.
sin
(
_w
*
time
);
return
power
*
(
_c2
*
_w
*
cosine
-
_c1
*
_w
*
sine
)
+
_r
*
power
*
(
_c2
*
sine
+
_c1
*
cosine
);
}
}
packages/newton/lib/src/tolerance.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
class
Tolerance
{
final
double
distance
;
final
double
time
;
...
...
packages/newton/lib/src/utils.dart
View file @
d9061bc9
// Copyright
(c) 2015
The Chromium Authors. All rights reserved.
// Copyright
2016
The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
part of
newton
;
bool
_nearEqual
(
double
a
,
double
b
,
double
epsilon
)
=>
bool
nearEqual
(
double
a
,
double
b
,
double
epsilon
)
=>
(
a
>
(
b
-
epsilon
))
&&
(
a
<
(
b
+
epsilon
));
bool
_nearZero
(
double
a
,
double
epsilon
)
=>
_
nearEqual
(
a
,
0.0
,
epsilon
);
bool
nearZero
(
double
a
,
double
epsilon
)
=>
nearEqual
(
a
,
0.0
,
epsilon
);
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