Documentation ¶
Overview ¶
Package unit provides primitives for modeling and converting between with physical units.
Index ¶
- Constants
- func GetFloatingPointCmpOpts() []cmp.Option
- type Acceleration
- type Angle
- func (a Angle) Degrees() float64
- func (a Angle) Get(as Angle) float64
- func (a *Angle) MarshalJSON() ([]byte, error)
- func (a Angle) Radians() float64
- func (a Angle) String() string
- func (a *Angle) UnmarshalJSON(data []byte) error
- func (a *Angle) UnmarshalString(s string) error
- func (a *Angle) UnmarshalText(text []byte) error
- func (a Angle) WrapMinusPiPi() Angle
- func (a Angle) WrapZeroTwoPi() Angle
- type AngularSpeed
- type Curvature
- type Distance
- type Force
- type Frequency
- type Jerk
- type Mass
- type Pressure
- type Sharpness
- type Speed
- type Torque
Constants ¶
const ( Kilo = 1e3 // k Centi = 1e-2 // c Milli = 1e-3 // m Micro = 1e-6 // µ Nano = 1e-9 // n )
SI prefixes.
const Degree = Radian / 180 * math.Pi
Degree is a measurement of a plane angle in which one full rotation is 360 degrees.
const DegreePerSecond = RadianPerSecond / 180 * math.Pi
DegreePerSecond is angular speed measured in degrees per second.
const Kilogram = Kilo * Gram
Kilogram is the SI unit for measuring Mass.
const KilometerPerHour = MeterPerSecond / 3.6
KilometerPerHour is a unit for measuring speed using Kilometer for distance and Hour for time.
const Mile = 1 / 0.621371192 * Kilo * Meter
Mile is a British imperial unit and US customary unit for measuring distance.
const RPM = RadianPerSecond * (2 * math.Pi) / 60
RPM is the number of revolutions in one minute.
const Tonne = 1e6 * Gram
Tonne is a thousand of the SI unit for measuring mass, the Kilogram.
Variables ¶
This section is empty.
Functions ¶
func GetFloatingPointCmpOpts ¶ added in v1.6.1
GetFloatingPointCmpOpts compares float unit types with floating point error tolerance. The function is useful when testing with conversions from unit types to/from float32 where precision is lost.
Example usage: ``` import "gotest.tools/v3/assert" [...] assert.DeepEqual(t, source, truncated, GetFloatingPointCmpOpts()...) ```.
Types ¶
type Acceleration ¶
type Acceleration float64
Acceleration is the rate of change of the velocity of an object with respect to time.
const MeterPerSecondSquared Acceleration = 1
MeterPerSecondSquared is SI unit for measuring Acceleration.
func (Acceleration) Get ¶
func (a Acceleration) Get(as Acceleration) float64
Get returns a with the unit of as.
func (Acceleration) MetersPerSecondSquared ¶
func (a Acceleration) MetersPerSecondSquared() float64
MetersPerSecondSquared returns a with the unit of m/s².
func (*Acceleration) UnmarshalString ¶
func (a *Acceleration) UnmarshalString(s string) error
UnmarshalString sets *a from s.
func (*Acceleration) UnmarshalText ¶
func (a *Acceleration) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type Angle ¶
type Angle float64
Angle is the measure of a plane angle or rotation.
const Radian Angle = 1.0
Radian is the SI unit for measuring an Angle.
func FromDegrees ¶ added in v1.10.0
FromDegrees returns an Angle from degrees as float64.
func FromRadians ¶ added in v1.4.1
FromRadians returns an Angle from radians as float64.
func (*Angle) MarshalJSON ¶ added in v1.11.0
func (*Angle) UnmarshalJSON ¶ added in v1.11.0
UnmarshalJSON implements JSON unmarshalling for the Angle type. The type is represented as radians in JSON.
func (*Angle) UnmarshalString ¶
UnmarshalString sets *a from s.
func (*Angle) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
func (Angle) WrapMinusPiPi ¶
WrapMinusPiPi wraps the current angle in the interval [-pi, pi[.
func (Angle) WrapZeroTwoPi ¶ added in v1.10.0
WrapZeroTwoPi wraps the current angle in the interval [0, 2*pi[.
type AngularSpeed ¶
type AngularSpeed float64
AngularSpeed is a measure of rotation rate.
const RadianPerSecond AngularSpeed = 1.0
RadianPerSecond is the SI unit for measuring AngularSpeed.
func (AngularSpeed) DegreesPerSecond ¶ added in v1.9.0
func (a AngularSpeed) DegreesPerSecond() float64
DegreesPerSecond returns a with the unit of °/s.
func (AngularSpeed) Get ¶
func (a AngularSpeed) Get(as AngularSpeed) float64
Get returns a with the unit of as.
func (AngularSpeed) RadiansPerSecond ¶
func (a AngularSpeed) RadiansPerSecond() float64
RadiansPerSecond returns a with the unit of rad/s.
func (*AngularSpeed) UnmarshalString ¶
func (a *AngularSpeed) UnmarshalString(s string) error
UnmarshalString sets *a from s.
func (*AngularSpeed) UnmarshalText ¶
func (a *AngularSpeed) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.
type Curvature ¶ added in v1.5.1
type Curvature float64
Curvature is a numerical measurement of inverse physical length.
const PerMeter Curvature = 1
PerMeter is the SI unit for measuring Curvature.
func (*Curvature) UnmarshalString ¶ added in v1.5.1
UnmarshalString sets *c from s.
func (*Curvature) UnmarshalText ¶ added in v1.5.1
UnmarshalText implements encoding.TextUnmarshaler.
type Distance ¶
type Distance float64
Distance is a numerical measurement of physical length.
const Meter Distance = 1
Meter is the SI unit for measuring Distance.
func (*Distance) UnmarshalString ¶
UnmarshalString sets *d from s.
func (*Distance) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Force ¶
type Force float64
Force is an influence that can change the motion of an object.
const Newton Force = 1.0
Newton is the SI unit for measuring Force.
func (*Force) UnmarshalString ¶
UnmarshalString sets *f from s.
func (*Force) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Frequency ¶
type Frequency float64
Frequency is the number of occurrences of a repeating event per unit of time.
const Hertz Frequency = 1.0
Hertz is the SI unit for measuring Frequency.
func (*Frequency) UnmarshalString ¶
UnmarshalString sets *f from s.
func (*Frequency) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Jerk ¶
type Jerk float64
Jerk is the rate at which an object's acceleration changes with respect to time.
const MeterPerSecondCubed Jerk = 1.0
MeterPerSecondCubed is the SI unit for measuring Jerk.
func (Jerk) MetersPerSecondCubed ¶
MetersPerSecondCubed returns j with the unit of m/s³.
func (*Jerk) UnmarshalString ¶
UnmarshalString sets *j from s.
func (*Jerk) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Mass ¶
type Mass float64
Mass is the quantity of matter in a physical body.
const Gram Mass = 1.0
Gram is one thousandth of the SI unit for measuring mass, the Kilogram.
func (*Mass) UnmarshalString ¶
UnmarshalString sets *m from s.
func (*Mass) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Pressure ¶ added in v1.8.0
type Pressure float64
Pressure is the force applied perpendicular to the surface of an object per unit area over which that force is distributed.
const Pascal Pressure = 1
Pascal is the SI unit for measuring Pressure.
func (Pressure) KiloPascal ¶ added in v1.8.0
KiloPascal returns p with the unit of kPa.
func (*Pressure) UnmarshalString ¶ added in v1.8.0
UnmarshalString sets *p from s.
func (*Pressure) UnmarshalText ¶ added in v1.8.0
UnmarshalText implements encoding.TextUnmarshaler.
type Sharpness ¶ added in v1.7.3
type Sharpness float64
Sharpness is a numerical measurement of angular change per physical length. And example is the sharpness of a curve.
const RadianPerMeter Sharpness = 1
RadianPerMeter is the SI unit for measuring Sharpness.
func (Sharpness) RadianPerMeter ¶ added in v1.7.3
RadianPerMeter returns sharpness as a float64 with the unit of rad/m.
func (*Sharpness) UnmarshalString ¶ added in v1.7.3
UnmarshalString sets *c from s.
func (*Sharpness) UnmarshalText ¶ added in v1.7.3
UnmarshalText implements encoding.TextUnmarshaler.
type Speed ¶
type Speed float64
Speed is the rate of change of an object of its position with time.
const MeterPerSecond Speed = 1.0
MeterPerSecond is the SI unit for measuring Speed.
func (Speed) MetersPerSecond ¶
MetersPerSecond returns s with the unit of m/s.
func (*Speed) UnmarshalString ¶
UnmarshalString sets *s from str.
func (*Speed) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Torque ¶
type Torque float64
Torque is the rotational equivalent of linear Force.
const NewtonMeter Torque = 1.0
NewtonMeter is the SI unit for measuring Torque.
func (Torque) NewtonMeters ¶
NewtonMeters returns t with the unit of Nm.
func (*Torque) UnmarshalString ¶
UnmarshalString sets *t from s.
func (*Torque) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.