measure

package
v5.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllLengthUnits holds all possible values.
	AllLengthUnits = []LengthUnits{
		FeetAndInches,
		Inch,
		Feet,
		Yard,
		Mile,
		Centimeter,
		Kilometer,
		Meter,
	}
)
View Source
var (
	// AllWeightUnits holds all possible values.
	AllWeightUnits = []WeightUnits{
		Pound,
		PoundAlt,
		Ounce,
		Ton,
		TonAlt,
		Kilogram,
		Gram,
	}
)

Functions

This section is empty.

Types

type Length

type Length fxp.Int

Length contains a fixed-point value in inches. Conversions to/from metric are done using the simplified Length metric conversion of 1 yd = 1 meter. For consistency, all metric lengths are converted to meters, then to yards, rather than the variations at different lengths that the Length rules suggest.

func LengthFromInteger

func LengthFromInteger[T constraints.Integer](value T, unit LengthUnits) Length

LengthFromInteger creates a new Length.

func LengthFromString

func LengthFromString(text string, defaultUnits LengthUnits) (Length, error)

LengthFromString creates a new Length. May have any of the known Units suffixes, a feet and inches format (e.g. 6'2"), or no notation at all, in which case defaultUnits is used.

func LengthFromStringForced

func LengthFromStringForced(text string, defaultUnits LengthUnits) Length

LengthFromStringForced creates a new Length. May have any of the known Units suffixes, a feet and inches format (e.g. 6'2"), or no notation at all, in which case defaultUnits is used.

func (Length) MarshalJSON

func (l Length) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Length) String

func (l Length) String() string

func (*Length) UnmarshalJSON

func (l *Length) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

type LengthUnits

type LengthUnits byte

LengthUnits holds the length unit type. Note that conversions to/from metric are done using the simplified GURPS metric conversion of 1 yd = 1 meter. For consistency, all metric lengths are converted to meters, then to yards, rather than the variations at different lengths that the GURPS rules suggest.

const (
	FeetAndInches LengthUnits = iota
	Inch
	Feet
	Yard
	Mile
	Centimeter
	Kilometer
	Meter
	LastLengthUnits = Meter
)

Possible values.

func ExtractLengthUnits

func ExtractLengthUnits(str string) LengthUnits

ExtractLengthUnits extracts the value from a string.

func (LengthUnits) EnsureValid

func (enum LengthUnits) EnsureValid() LengthUnits

EnsureValid ensures this is of a known value.

func (LengthUnits) Format

func (enum LengthUnits) Format(length Length) string

Format the length for this LengthUnits.

func (LengthUnits) Key

func (enum LengthUnits) Key() string

Key returns the key used in serialization.

func (LengthUnits) MarshalText

func (enum LengthUnits) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (LengthUnits) String

func (enum LengthUnits) String() string

String implements fmt.Stringer.

func (LengthUnits) ToInches

func (enum LengthUnits) ToInches(length fxp.Int) fxp.Int

ToInches converts the length in this LengthUnits to inches.

func (*LengthUnits) UnmarshalText

func (enum *LengthUnits) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Weight

type Weight fxp.Int

Weight contains a fixed-point value in pounds.

func WeightFromInteger

func WeightFromInteger[T constraints.Integer](value T, unit WeightUnits) Weight

WeightFromInteger creates a new Weight.

func WeightFromString

func WeightFromString(text string, defaultUnits WeightUnits) (Weight, error)

WeightFromString creates a new Weight. May have any of the known Weight suffixes or no notation at all, in which case defaultUnits is used.

func WeightFromStringForced

func WeightFromStringForced(text string, defaultUnits WeightUnits) Weight

WeightFromStringForced creates a new Weight. May have any of the known Weight suffixes or no notation at all, in which case defaultUnits is used.

func (Weight) MarshalJSON

func (w Weight) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Weight) String

func (w Weight) String() string

func (*Weight) UnmarshalJSON

func (w *Weight) UnmarshalJSON(in []byte) error

UnmarshalJSON implements json.Unmarshaler.

type WeightUnits

type WeightUnits byte

WeightUnits holds the weight unit type. Note that conversions to/from metric are done using the simplified GURPS metric conversion of 1 lb = 0.5kg. For consistency, all metric weights are converted to kilograms, then to pounds, rather than the variations at different weights that the GURPS rules suggest.

const (
	Pound WeightUnits = iota
	PoundAlt
	Ounce
	Ton
	TonAlt
	Kilogram
	Gram
	LastWeightUnits = Gram
)

Possible values.

func ExtractWeightUnits

func ExtractWeightUnits(str string) WeightUnits

ExtractWeightUnits extracts the value from a string.

func TrailingWeightUnitsFromString

func TrailingWeightUnitsFromString(s string, defUnits WeightUnits) WeightUnits

TrailingWeightUnitsFromString extracts a trailing WeightUnits from a string.

func (WeightUnits) EnsureValid

func (enum WeightUnits) EnsureValid() WeightUnits

EnsureValid ensures this is of a known value.

func (WeightUnits) Format

func (enum WeightUnits) Format(weight Weight) string

Format the weight for this WeightUnits.

func (WeightUnits) Key

func (enum WeightUnits) Key() string

Key returns the key used in serialization.

func (WeightUnits) MarshalText

func (enum WeightUnits) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface.

func (WeightUnits) String

func (enum WeightUnits) String() string

String implements fmt.Stringer.

func (WeightUnits) ToPounds

func (enum WeightUnits) ToPounds(weight fxp.Int) fxp.Int

ToPounds the weight for this WeightUnits.

func (*WeightUnits) UnmarshalText

func (enum *WeightUnits) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL