Documentation
¶
Overview ¶
Package physics provides the simulations used by scrolling and animation, such as springs, friction and clamping.
Flutter: package:flutter/physics.dart.
Index ¶
- Constants
- Variables
- func NearEqual(a, b, epsilon float64) bool
- func NearEqualOpt(a, b foundation.Opt[float64], epsilon float64) bool
- func NearZero(a, epsilon float64) bool
- type BouncingScrollSimulation
- func (b *BouncingScrollSimulation) Dx(time float64) float64
- func (b *BouncingScrollSimulation) IsDone(time float64) bool
- func (b *BouncingScrollSimulation) LeadingExtent() float64
- func (b *BouncingScrollSimulation) Spring() SpringDescription
- func (b *BouncingScrollSimulation) String() string
- func (b *BouncingScrollSimulation) TrailingExtent() float64
- func (b *BouncingScrollSimulation) X(time float64) float64
- type BouncingScrollSimulationOpts
- type BoundedFrictionSimulation
- type ClampedSimulation
- type ClampedSimulationOpts
- type ClampingScrollSimulation
- func (c *ClampingScrollSimulation) Dx(time float64) float64
- func (c *ClampingScrollSimulation) Friction() float64
- func (c *ClampingScrollSimulation) IsDone(time float64) bool
- func (c *ClampingScrollSimulation) Position() float64
- func (c *ClampingScrollSimulation) Velocity() float64
- func (c *ClampingScrollSimulation) X(time float64) float64
- type ClampingScrollSimulationOpts
- type FrictionSimulation
- func (f *FrictionSimulation) Dx(time float64) float64
- func (f *FrictionSimulation) FinalX() float64
- func (f *FrictionSimulation) IsDone(time float64) bool
- func (f *FrictionSimulation) String() string
- func (f *FrictionSimulation) TimeAtX(x float64) float64
- func (f *FrictionSimulation) X(time float64) float64
- type FrictionSimulationOpts
- type GravitySimulation
- type ScrollSpringSimulation
- type Simulation
- type SimulationBase
- type SpringDescription
- func NewSpringDescription(mass, stiffness, damping float64) SpringDescription
- func NewSpringDescriptionWithDampingRatio(mass, stiffness float64, opts ...SpringDescriptionWithDampingRatioOpts) SpringDescription
- func NewSpringDescriptionWithDurationAndBounce(opts ...SpringDescriptionWithDurationAndBounceOpts) SpringDescription
- type SpringDescriptionWithDampingRatioOpts
- type SpringDescriptionWithDurationAndBounceOpts
- type SpringSimulation
- type SpringSimulationOpts
- type SpringType
- type Tolerance
- type ToleranceOpts
Constants ¶
const BouncingScrollSimulationMaxSpringTransferVelocity = 5000.0
BouncingScrollSimulationMaxSpringTransferVelocity is the largest velocity, in pixels per second, that the friction part hands over to the spring part when it reaches an extent.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.maxSpringTransferVelocity
Variables ¶
var ToleranceDefault = NewTolerance()
ToleranceDefault is a tolerance with every field 1e-3. It never changes.
Flutter: physics/tolerance.dart Tolerance.defaultTolerance
Functions ¶
func NearEqual ¶
NearEqual reports whether a and b are within epsilon of each other. Equal infinities are near equal. A negative epsilon panics with the tag EpsilonNegative in debug builds.
Flutter: physics/utils.dart nearEqual
func NearEqualOpt ¶
func NearEqualOpt(a, b foundation.Opt[float64], epsilon float64) bool
NearEqualOpt is NearEqual for values that may be missing: two missing values are near equal, and a missing value is never near a present one.
Flutter: physics/utils.dart nearEqual
Types ¶
type BouncingScrollSimulation ¶
type BouncingScrollSimulation struct {
SimulationBase
// contains filtered or unexported fields
}
BouncingScrollSimulation is a simulation of scrolling with the physics of iOS and macOS: friction while the content is inside its extents, and a spring that pulls it back when it goes beyond them (overscroll).
Deviation: Flutter has it in widgets/scroll_simulation.dart; SPEC §11.1 lists it with the physics (SPEC §12.10).
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation
func NewBouncingScrollSimulation ¶
func NewBouncingScrollSimulation(position, velocity, leadingExtent, trailingExtent float64, spring SpringDescription, opts ...BouncingScrollSimulationOpts) *BouncingScrollSimulation
NewBouncingScrollSimulation creates the simulation of a scroll at position with the velocity, between leadingExtent and trailingExtent, with the spring for the overscroll. A leading extent past the trailing one panics with the tag ScrollExtentsInvalid in debug builds.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.new
func (*BouncingScrollSimulation) Dx ¶
func (b *BouncingScrollSimulation) Dx(time float64) float64
Dx is the scroll velocity at the time.
func (*BouncingScrollSimulation) IsDone ¶
func (b *BouncingScrollSimulation) IsDone(time float64) bool
IsDone is whether the scroll has settled.
func (*BouncingScrollSimulation) LeadingExtent ¶
func (b *BouncingScrollSimulation) LeadingExtent() float64
LeadingExtent is where the scrollable content starts.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.leadingExtent
func (*BouncingScrollSimulation) Spring ¶
func (b *BouncingScrollSimulation) Spring() SpringDescription
Spring is the spring that pulls an overscroll back.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.spring
func (*BouncingScrollSimulation) String ¶
func (b *BouncingScrollSimulation) String() string
String describes the simulation.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.toString
func (*BouncingScrollSimulation) TrailingExtent ¶
func (b *BouncingScrollSimulation) TrailingExtent() float64
TrailingExtent is where the scrollable content ends.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.trailingExtent
func (*BouncingScrollSimulation) X ¶
func (b *BouncingScrollSimulation) X(time float64) float64
X is the scroll position at the time.
type BouncingScrollSimulationOpts ¶
type BouncingScrollSimulationOpts struct {
// ConstantDeceleration is added to the friction; 0 by default.
ConstantDeceleration float64
// Tolerance decides when the simulation is done; the default tolerance if
// not set.
Tolerance foundation.Opt[Tolerance]
}
BouncingScrollSimulationOpts are the optional parameters of NewBouncingScrollSimulation.
Flutter: widgets/scroll_simulation.dart BouncingScrollSimulation.new
type BoundedFrictionSimulation ¶
type BoundedFrictionSimulation struct {
*FrictionSimulation
// contains filtered or unexported fields
}
BoundedFrictionSimulation is a FrictionSimulation whose position stays between two bounds, and which is done when it reaches one.
Flutter: physics/friction_simulation.dart BoundedFrictionSimulation
func NewBoundedFrictionSimulation ¶
func NewBoundedFrictionSimulation(drag, position, velocity, minX, maxX float64) *BoundedFrictionSimulation
NewBoundedFrictionSimulation creates a friction simulation that cannot leave minX..maxX. A position outside the bounds panics with the tag FrictionPositionOutOfBounds in debug builds.
Flutter: physics/friction_simulation.dart BoundedFrictionSimulation.new
func (*BoundedFrictionSimulation) FinalX ¶
func (b *BoundedFrictionSimulation) FinalX() float64
FinalX is the position where the particle stops, kept between the bounds when there is a constant deceleration.
func (*BoundedFrictionSimulation) IsDone ¶
func (b *BoundedFrictionSimulation) IsDone(time float64) bool
IsDone is whether the velocity is below the tolerance, or the particle is at a bound.
func (*BoundedFrictionSimulation) String ¶
func (b *BoundedFrictionSimulation) String() string
String describes the simulation, such as "BoundedFrictionSimulation(cₓ: 1.0, x₀: -2.0, dx₀: 3.0, x: -4.0..5.0)".
Flutter: physics/friction_simulation.dart BoundedFrictionSimulation.toString
func (*BoundedFrictionSimulation) TimeAtX ¶
func (b *BoundedFrictionSimulation) TimeAtX(x float64) float64
TimeAtX is the time at which the particle is at x, or positive infinity.
func (*BoundedFrictionSimulation) X ¶
func (b *BoundedFrictionSimulation) X(time float64) float64
X is the position at the time, kept between the bounds.
type ClampedSimulation ¶
type ClampedSimulation struct {
SimulationBase
// contains filtered or unexported fields
}
ClampedSimulation is a simulation that restricts the position and velocity of another simulation to a range.
Flutter: physics/clamped_simulation.dart ClampedSimulation
func NewClampedSimulation ¶
func NewClampedSimulation(simulation Simulation, opts ...ClampedSimulationOpts) *ClampedSimulation
NewClampedSimulation creates a simulation that gives the values of simulation, clamped to the ranges. A range whose maximum is below its minimum panics with the tag ClampedRangeInvalid in debug builds.
Flutter: physics/clamped_simulation.dart ClampedSimulation.new
func (*ClampedSimulation) Dx ¶
func (c *ClampedSimulation) Dx(time float64) float64
Dx is the velocity of the simulation, clamped.
func (*ClampedSimulation) IsDone ¶
func (c *ClampedSimulation) IsDone(time float64) bool
IsDone is whether the simulation is done.
func (*ClampedSimulation) Simulation ¶
func (c *ClampedSimulation) Simulation() Simulation
Simulation is the simulation being clamped.
Flutter: physics/clamped_simulation.dart ClampedSimulation.simulation
func (*ClampedSimulation) String ¶
func (c *ClampedSimulation) String() string
String describes the simulation, such as "ClampedSimulation(simulation: Foo, x: -1.0..2.0, dx: -3.0..4.0)".
Flutter: physics/clamped_simulation.dart ClampedSimulation.toString
func (*ClampedSimulation) X ¶
func (c *ClampedSimulation) X(time float64) float64
X is the position of the simulation, clamped.
type ClampedSimulationOpts ¶
type ClampedSimulationOpts struct {
// XMin is the lowest position; negative infinity by default.
XMin foundation.Opt[float64]
// XMax is the highest position; infinity by default.
XMax foundation.Opt[float64]
// DxMin is the lowest velocity; negative infinity by default.
DxMin foundation.Opt[float64]
// DxMax is the highest velocity; infinity by default.
DxMax foundation.Opt[float64]
}
ClampedSimulationOpts are the optional parameters of NewClampedSimulation. A bound that is not set is infinite.
Flutter: physics/clamped_simulation.dart ClampedSimulation.new
type ClampingScrollSimulation ¶
type ClampingScrollSimulation struct {
SimulationBase
// contains filtered or unexported fields
}
ClampingScrollSimulation is a simulation of scrolling with the physics of Android: a fling that slows down along a curve and stops at its end. It does not know about the extents of the content; the scroll position clamps.
It is based on SplineOverScroller in Android's OverScroller.java.
Deviation: Flutter has it in widgets/scroll_simulation.dart; SPEC §11.1 lists it with the physics (SPEC §12.10).
Flutter: widgets/scroll_simulation.dart ClampingScrollSimulation
func NewClampingScrollSimulation ¶
func NewClampingScrollSimulation(position, velocity float64, opts ...ClampingScrollSimulationOpts) *ClampingScrollSimulation
NewClampingScrollSimulation creates the simulation of a fling that starts at position with the velocity.
Flutter: widgets/scroll_simulation.dart ClampingScrollSimulation.new
func (*ClampingScrollSimulation) Dx ¶
func (c *ClampingScrollSimulation) Dx(time float64) float64
Dx is the velocity at the time.
func (*ClampingScrollSimulation) Friction ¶
func (c *ClampingScrollSimulation) Friction() float64
Friction is the fling friction.
Flutter: widgets/scroll_simulation.dart ClampingScrollSimulation.friction
func (*ClampingScrollSimulation) IsDone ¶
func (c *ClampingScrollSimulation) IsDone(time float64) bool
IsDone is whether the fling has run its duration.
func (*ClampingScrollSimulation) Position ¶
func (c *ClampingScrollSimulation) Position() float64
Position is where the fling starts.
Flutter: widgets/scroll_simulation.dart ClampingScrollSimulation.position
func (*ClampingScrollSimulation) Velocity ¶
func (c *ClampingScrollSimulation) Velocity() float64
Velocity is the velocity at the start.
Flutter: widgets/scroll_simulation.dart ClampingScrollSimulation.velocity
func (*ClampingScrollSimulation) X ¶
func (c *ClampingScrollSimulation) X(time float64) float64
X is the position at the time.
type ClampingScrollSimulationOpts ¶
type ClampingScrollSimulationOpts struct {
// Friction is the fling friction (mFlingFriction); 0.015 by default.
Friction foundation.Opt[float64]
// Tolerance decides when the simulation is done; the default tolerance if
// not set.
Tolerance foundation.Opt[Tolerance]
}
ClampingScrollSimulationOpts are the optional parameters of NewClampingScrollSimulation.
Flutter: widgets/scroll_simulation.dart ClampingScrollSimulation.new
type FrictionSimulation ¶
type FrictionSimulation struct {
SimulationBase
// contains filtered or unexported fields
}
FrictionSimulation is a simulation of a particle that slows down under friction (drag) and, optionally, a constant deceleration.
Flutter: physics/friction_simulation.dart FrictionSimulation
func NewFrictionSimulation ¶
func NewFrictionSimulation(drag, position, velocity float64, opts ...FrictionSimulationOpts) *FrictionSimulation
NewFrictionSimulation creates a simulation of a particle at position with the velocity, slowed by drag, which is the fraction of the velocity that is left after one second (a value between 0 and 1).
Flutter: physics/friction_simulation.dart FrictionSimulation.new
func NewFrictionSimulationThrough ¶
func NewFrictionSimulationThrough(startPosition, endPosition, startVelocity, endVelocity float64) *FrictionSimulation
NewFrictionSimulationThrough creates a simulation whose position and velocity at some time pass through endPosition and endVelocity, having started from startPosition with startVelocity: the drag is found from the four values, and the simulation is done when the velocity reaches endVelocity. The velocities must have the same direction (or one is zero), the start velocity must be at least as fast as the end velocity, and the end position must lie in the direction of the start velocity; otherwise it panics with the tag FrictionThroughInvalid in debug builds.
Flutter: physics/friction_simulation.dart FrictionSimulation.through
func (*FrictionSimulation) Dx ¶
func (f *FrictionSimulation) Dx(time float64) float64
Dx is the velocity at the time.
func (*FrictionSimulation) FinalX ¶
func (f *FrictionSimulation) FinalX() float64
FinalX is the value X approaches: where the particle stops.
Flutter: physics/friction_simulation.dart FrictionSimulation.finalX
func (*FrictionSimulation) IsDone ¶
func (f *FrictionSimulation) IsDone(time float64) bool
IsDone is whether the velocity is below the velocity tolerance.
func (*FrictionSimulation) String ¶
func (f *FrictionSimulation) String() string
String describes the simulation, such as "FrictionSimulation(cₓ: 1.0, x₀: -2.0, dx₀: 3.0)".
Flutter: physics/friction_simulation.dart FrictionSimulation.toString
func (*FrictionSimulation) TimeAtX ¶
func (f *FrictionSimulation) TimeAtX(x float64) float64
TimeAtX is the time at which the particle is at x, or positive infinity if it never is. Time 0 is the start.
Flutter: physics/friction_simulation.dart FrictionSimulation.timeAtX
func (*FrictionSimulation) X ¶
func (f *FrictionSimulation) X(time float64) float64
X is the position at the time.
type FrictionSimulationOpts ¶
type FrictionSimulationOpts struct {
// Tolerance decides when the simulation is done; the default tolerance if
// not set.
Tolerance foundation.Opt[Tolerance]
// ConstantDeceleration is a deceleration that is added to the friction, in
// the opposite direction to the velocity; 0 by default.
ConstantDeceleration float64
}
FrictionSimulationOpts are the optional parameters of NewFrictionSimulation.
Flutter: physics/friction_simulation.dart FrictionSimulation.new
type GravitySimulation ¶
type GravitySimulation struct {
SimulationBase
// contains filtered or unexported fields
}
GravitySimulation is a simulation of a particle with constant acceleration, such as a falling object.
Flutter: physics/gravity_simulation.dart GravitySimulation
func NewGravitySimulation ¶
func NewGravitySimulation(acceleration, distance, endDistance, velocity float64) *GravitySimulation
NewGravitySimulation creates a simulation of an object that starts at distance with the velocity, accelerated by acceleration, and is done when it is endDistance or more away from zero. An endDistance below zero panics with the tag GravityEndDistanceNegative in debug builds.
Flutter: physics/gravity_simulation.dart GravitySimulation.new
func (*GravitySimulation) Dx ¶
func (g *GravitySimulation) Dx(time float64) float64
Dx is the velocity at the time.
func (*GravitySimulation) IsDone ¶
func (g *GravitySimulation) IsDone(time float64) bool
IsDone is whether the object is endDistance away from zero.
func (*GravitySimulation) String ¶
func (g *GravitySimulation) String() string
String describes the simulation, such as "GravitySimulation(g: 1.0, x₀: -2.0, dx₀: -4.0, xₘₐₓ: ±3.0)".
Flutter: physics/gravity_simulation.dart GravitySimulation.toString
func (*GravitySimulation) X ¶
func (g *GravitySimulation) X(time float64) float64
X is the position at the time.
type ScrollSpringSimulation ¶
type ScrollSpringSimulation struct {
*SpringSimulation
}
ScrollSpringSimulation is a SpringSimulation that, when it is done, is exactly at its end position. Scrolling uses it so that a scroll position settles on the edge.
Flutter: physics/spring_simulation.dart ScrollSpringSimulation
func NewScrollSpringSimulation ¶
func NewScrollSpringSimulation(spring SpringDescription, start, end, velocity float64, opts ...SpringSimulationOpts) *ScrollSpringSimulation
NewScrollSpringSimulation creates a scroll spring simulation. The options are those of NewSpringSimulation, and SnapToEnd has no effect.
Flutter: physics/spring_simulation.dart ScrollSpringSimulation.new
func (*ScrollSpringSimulation) X ¶
func (s *ScrollSpringSimulation) X(time float64) float64
X is the position at the time, exactly the end once done.
type Simulation ¶
type Simulation interface {
// X is the position of the object in the simulation at the given time.
//
// Flutter: physics/simulation.dart Simulation.x
X(time float64) float64
// Dx is the velocity of the object in the simulation at the given time.
//
// Flutter: physics/simulation.dart Simulation.dx
Dx(time float64) float64
// IsDone reports whether the simulation is "done" at the given time.
//
// Flutter: physics/simulation.dart Simulation.isDone
IsDone(time float64) bool
// Tolerance is how close a position, velocity or time must be to count as
// the end of the simulation.
//
// Flutter: physics/simulation.dart Simulation.tolerance
Tolerance() Tolerance
// SetTolerance changes the tolerance.
//
// Flutter: physics/simulation.dart Simulation.tolerance=
SetTolerance(Tolerance)
}
Simulation is the base interface for a physics simulation that works in terms of a one dimensional position and velocity as functions of time, in seconds.
A simulation of your own embeds SimulationBase for the tolerance, and implements X, Dx and IsDone.
Flutter: physics/simulation.dart Simulation
type SimulationBase ¶
type SimulationBase struct {
// contains filtered or unexported fields
}
SimulationBase holds the tolerance of a Simulation. Embed it.
Flutter: physics/simulation.dart Simulation
func NewSimulationBase ¶
func NewSimulationBase(tolerance foundation.Opt[Tolerance]) SimulationBase
NewSimulationBase creates the base with a tolerance, or the default one for None.
Flutter: physics/simulation.dart Simulation.new
func (*SimulationBase) SetTolerance ¶
func (s *SimulationBase) SetTolerance(t Tolerance)
SetTolerance changes the tolerance.
func (*SimulationBase) Tolerance ¶
func (s *SimulationBase) Tolerance() Tolerance
Tolerance returns the tolerance, ToleranceDefault until it is set.
type SpringDescription ¶
type SpringDescription struct {
// Mass is the mass of the spring (m).
//
// Flutter: physics/spring_simulation.dart SpringDescription.mass
Mass float64
// Stiffness is the spring constant (k): the force per unit of stretch.
//
// Flutter: physics/spring_simulation.dart SpringDescription.stiffness
Stiffness float64
// Damping is the coefficient of the force that slows the spring (c).
//
// Flutter: physics/spring_simulation.dart SpringDescription.damping
Damping float64
}
SpringDescription is the mass, stiffness and damping of a spring.
Flutter: physics/spring_simulation.dart SpringDescription
func NewSpringDescription ¶
func NewSpringDescription(mass, stiffness, damping float64) SpringDescription
NewSpringDescription creates a spring description from its three values.
Flutter: physics/spring_simulation.dart SpringDescription.new
func NewSpringDescriptionWithDampingRatio ¶
func NewSpringDescriptionWithDampingRatio(mass, stiffness float64, opts ...SpringDescriptionWithDampingRatioOpts) SpringDescription
NewSpringDescriptionWithDampingRatio creates a spring description from the mass, the stiffness and a damping ratio; the damping is ratio * 2 * sqrt(mass * stiffness).
Flutter: physics/spring_simulation.dart SpringDescription.withDampingRatio
func NewSpringDescriptionWithDurationAndBounce ¶
func NewSpringDescriptionWithDurationAndBounce(opts ...SpringDescriptionWithDurationAndBounceOpts) SpringDescription
NewSpringDescriptionWithDurationAndBounce creates a spring description from how long it takes and how much it bounces, with a mass of 1.
Flutter: physics/spring_simulation.dart SpringDescription.withDurationAndBounce
func (SpringDescription) Bounce ¶
func (s SpringDescription) Bounce() float64
Bounce is how bouncy the spring is: positive when underdamped, 0 when critically damped and negative when overdamped.
Flutter: physics/spring_simulation.dart SpringDescription.bounce
func (SpringDescription) Duration ¶
func (s SpringDescription) Duration() time.Duration
Duration is the perceptual duration of the spring, rounded to milliseconds.
Flutter: physics/spring_simulation.dart SpringDescription.duration
func (SpringDescription) String ¶
func (s SpringDescription) String() string
String describes the spring, such as "SpringDescription(mass: 1.0, stiffness: -2.0, damping: 3.0)".
Flutter: physics/spring_simulation.dart SpringDescription.toString
type SpringDescriptionWithDampingRatioOpts ¶
type SpringDescriptionWithDampingRatioOpts struct {
// Ratio is the damping ratio: 1 is critically damped (the default), below
// 1 is underdamped and above 1 is overdamped.
Ratio foundation.Opt[float64]
}
SpringDescriptionWithDampingRatioOpts are the optional parameters of NewSpringDescriptionWithDampingRatio.
Flutter: physics/spring_simulation.dart SpringDescription.withDampingRatio
type SpringDescriptionWithDurationAndBounceOpts ¶
type SpringDescriptionWithDurationAndBounceOpts struct {
// Duration is the perceptual duration of the spring, the time it takes to
// do one oscillation without damping; 500 ms by default. It must be longer
// than a millisecond, or the constructor panics with the tag
// SpringDurationInvalid in debug builds.
Duration foundation.Opt[time.Duration]
// Bounce is how bouncy the spring is: 0 is critically damped (no bounce),
// positive values bounce, negative values are overdamped. 0 by default.
Bounce float64
}
SpringDescriptionWithDurationAndBounceOpts are the optional parameters of NewSpringDescriptionWithDurationAndBounce.
Flutter: physics/spring_simulation.dart SpringDescription.withDurationAndBounce
type SpringSimulation ¶
type SpringSimulation struct {
SimulationBase
// contains filtered or unexported fields
}
SpringSimulation is a spring that pulls a particle to its end position: the particle starts at start with a velocity and settles at end.
Flutter: physics/spring_simulation.dart SpringSimulation
func NewSpringSimulation ¶
func NewSpringSimulation(spring SpringDescription, start, end, velocity float64, opts ...SpringSimulationOpts) *SpringSimulation
NewSpringSimulation creates a spring simulation of a particle that starts at start with the velocity and is pulled to end by the spring.
Flutter: physics/spring_simulation.dart SpringSimulation.new
func (*SpringSimulation) Dx ¶
func (s *SpringSimulation) Dx(time float64) float64
Dx is the velocity at the time.
func (*SpringSimulation) IsDone ¶
func (s *SpringSimulation) IsDone(time float64) bool
IsDone is whether the particle is at its end, at rest, within the tolerance.
func (*SpringSimulation) String ¶
func (s *SpringSimulation) String() string
String describes the simulation, such as "SpringSimulation(end: 1.0, SpringType.overDamped)".
Flutter: physics/spring_simulation.dart SpringSimulation.toString
func (*SpringSimulation) Type ¶
func (s *SpringSimulation) Type() SpringType
Type is how the spring settles.
Flutter: physics/spring_simulation.dart SpringSimulation.type
func (*SpringSimulation) X ¶
func (s *SpringSimulation) X(time float64) float64
X is the position at the time.
type SpringSimulationOpts ¶
type SpringSimulationOpts struct {
// SnapToEnd makes X and Dx return exactly the end position and zero once
// the simulation is done, instead of values within the tolerance.
SnapToEnd bool
// Tolerance decides when the simulation is done; the default tolerance if
// not set.
Tolerance foundation.Opt[Tolerance]
}
SpringSimulationOpts are the optional parameters of NewSpringSimulation.
Flutter: physics/spring_simulation.dart SpringSimulation.new
type SpringType ¶
type SpringType int
SpringType is how a spring settles, which its damping decides. The zero value is SpringTypeUnspecified.
Flutter: physics/spring_simulation.dart SpringType
const ( // SpringTypeUnspecified is the zero value. // // Flutter: no counterpart SpringTypeUnspecified SpringType = iota // SpringTypeCriticallyDamped is a spring that reaches its end as fast as // possible without overshooting. // // Flutter: physics/spring_simulation.dart SpringType.criticallyDamped SpringTypeCriticallyDamped // SpringTypeUnderDamped is a spring that overshoots its end and oscillates // around it. // // Flutter: physics/spring_simulation.dart SpringType.underDamped SpringTypeUnderDamped // SpringTypeOverDamped is a spring that reaches its end slowly, without // overshooting. // // Flutter: physics/spring_simulation.dart SpringType.overDamped SpringTypeOverDamped )
The values of SpringType follow Flutter's declaration order.
func (SpringType) Name ¶
func (t SpringType) Name() string
Name returns the name Dart's Enum.name gives the value, such as "underDamped".
func (SpringType) String ¶
func (t SpringType) String() string
String returns the name Dart prints for the value, such as "SpringType.underDamped".
type Tolerance ¶
type Tolerance struct {
// Distance is the magnitude of the maximum distance between two points for
// them to be considered within tolerance. The units for the distance
// tolerance must be the same as the units used for the distances that are
// to be compared to this tolerance.
//
// Flutter: physics/tolerance.dart Tolerance.distance
Distance float64
// Time is the magnitude of the maximum duration between two times for them
// to be considered within tolerance, in seconds.
//
// Flutter: physics/tolerance.dart Tolerance.time
Time float64
// Velocity is the magnitude of the maximum difference between two
// velocities for them to be considered within tolerance. The units for the
// velocity tolerance must be the same as the units used for the velocities
// that are to be compared to this tolerance.
//
// Flutter: physics/tolerance.dart Tolerance.velocity
Velocity float64
}
Tolerance structure for specifying an acceptable margin of error for simulations: how close to the end a value must be, how close in time, and how slow, to count as done.
Use NewTolerance to get the default 1e-3 for the fields you leave out; the zero value has all fields 0.
Flutter: physics/tolerance.dart Tolerance
func NewTolerance ¶
func NewTolerance(opts ...ToleranceOpts) Tolerance
NewTolerance creates a tolerance; the fields that opts leave out are 1e-3.
Flutter: physics/tolerance.dart Tolerance.new
type ToleranceOpts ¶
type ToleranceOpts struct {
// Distance is the tolerance of positions.
Distance foundation.Opt[float64]
// Time is the tolerance of times, in seconds.
Time foundation.Opt[float64]
// Velocity is the tolerance of velocities.
Velocity foundation.Opt[float64]
}
ToleranceOpts are the optional parameters of NewTolerance. Each field that is not set is 1e-3.
Flutter: physics/tolerance.dart Tolerance.new