length

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2019 License: GPL-3.0 Imports: 2 Imported by: 0

README

Length

CircleCI GoDoc Go Report Card

What is length?

Length is a go library for displaying and measuring length

Installation

Length can be installed via the go get tool

$ go get -u github.com/penguingovernor

Documentation

For all documentation related to this library, refer to the godoc linked at the top of this README.

Examples are also available under the examples directory.

Documentation

Overview

Package length provides functionality for measuring and displaying lengths.

Index

Constants

View Source
const (
	Nanometer  Distance = 1
	Micrometer          = 1e3 * Nanometer
	Millimeter          = 1e3 * Micrometer
	Centimeter          = 10 * Millimeter
	Meter               = 1e3 * Millimeter
	Kilometer           = 1e3 * Meter
	Inch                = 2.54 * Centimeter
	Feet                = 304.8 * Millimeter
	Yard                = 3 * Feet
	Mile                = 5280 * Feet
	Lightyear           = 9.461e12 * Kilometer
)

Common distances.

To count the number of units in a Distance, divide:

meter := length.Meter
fmt.Print(float64(meter/length.Millimeter)) // prints 1000

To convert an integer number of units to a Distance, multiply:

meters := 10
fmt.Print(length.Distance(meters)*length.Meter) // prints 10m

Variables

This section is empty.

Functions

func ToggleUnits

func ToggleUnits()

ToggleUnits toggles the units (metric <=> imperial) that are printed whenever the String function is called (as is the case in family of printing functions in the fmt package). By default the metric system is used.

func UseImperial

func UseImperial()

UseImperial toggles the units to use the imperial system. See ToggleUnits for more information.

func UseMetric

func UseMetric()

UseMetric toggles the units to use the metric system. See ToggleUnits for more information.

Types

type Distance

type Distance float64

A Distance represents a physical distance as a float64 nanometer count. The representation limits the largest representable duration to approximately 1.900163142869793e283 light years ≈ diameter of the observable universe (≈ 93 billion ly )

func ParseDistance

func ParseDistance(s string) (Distance, error)

ParseDistance parses a distance string. A distance string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300m" or "-1.5ly" Valid distance units are "nm", "um" (or "µm"), "mm", "m", "km", "in", "ft", "yd", "mi", "ly".

func (Distance) String

func (d Distance) String() string

String returns a string representing the distance in the form "10m" or "10yd". The unit that is used is based on the state of the ToggleUnit function. As a special case, distances less than one meter (or yard) use a smaller unit to ensure that the leading digit is non-zero. The zero duration formats as 0m or 0yd.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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