bag

package
v0.0.0-...-3435f2a Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2023 License: BSD-3-Clause Imports: 9 Imported by: 4

Documentation

Index

Constants

MaxSP is the largest dimension. Approx. 50,000,000 km on 64bit architecture. On 32bit architecture still about 11.5 meters.

Variables

View Source
var (

	// ErrConversion signals an error in unit conversion
	ErrConversion = errors.New("Conversion error")
	// Logger is initialized to write to io.Discard and the default log level is
	// math.MaxInt, so it should never write anything. To set, use the
	// SetLogger() function.
	Logger *slog.Logger
)

Functions

func SetLogger

func SetLogger(l *slog.Logger)

SetLogger sets the logger for the boxes and glue backend and for the libraries it loads.

Types

type ScaledPoint

type ScaledPoint int

A ScaledPoint is a 65535th of a DTP point

const Factor ScaledPoint = 0xffff

Factor is the multiplier to get DTP points from scaled points.

func Max

func Max(a, b ScaledPoint) ScaledPoint

Max returns the maximum of the two scaled points.

func Min

func Min(a, b ScaledPoint) ScaledPoint

Min returns the minimum of the two scaled points.

func MultiplyFloat

func MultiplyFloat(a ScaledPoint, f float64) ScaledPoint

MultiplyFloat returns a multiplied by f.

func MustSp

func MustSp(unit string) ScaledPoint

MustSp converts the unit to ScaledPoints. In case of an error, the function panics.

func ScaledPointFromFloat

func ScaledPointFromFloat(f float64) ScaledPoint

ScaledPointFromFloat converts the DTP point f to a ScaledPoint

func Sp

func Sp(unit string) (ScaledPoint, error)

Sp return the unit converted to ScaledPoint. Unit can be a string like "1cm" or "12.5in". The units which are interpreted are pt, in, mm, cm, m, px and pc. A (wrapped) ErrConversion is returned in case of an error.

func (ScaledPoint) String

func (s ScaledPoint) String() string

String converts the scaled point into a string, like Sprintf("%.3f") but with trailing zeroes (and possibly ".") removed.

func (ScaledPoint) ToPT

func (s ScaledPoint) ToPT() float64

ToPT returns the unit as a float64 DTP point. 2 * 0xffff returns 2.0

func (ScaledPoint) ToUnit

func (s ScaledPoint) ToUnit(unit string) (float64, error)

ToUnit returns the scaled points converted to the given unit. It raises an ErrConversion in case it cannot convert to the given unit.

Jump to

Keyboard shortcuts

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