Source File
len.go
Belonging Package
gonum.org/v1/plot/font
// Copyright ©2021 The Gonum Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package fontimport ()// Length is a unit-independent representation of length.// Internally, the length is stored in postscript points.type Length float64// Dots returns the length in dots for the given resolution.func ( Length) ( float64) float64 {return float64() / Inch.Points() *}// Points returns the length in postscript points.func ( Length) () float64 {return float64()}// Common lengths.const (Inch Length = 72Centimeter = Inch / 2.54Millimeter = Centimeter / 10)// Points returns a length for the given number of points.func ( float64) Length {return Length()}// ParseLength parses a Length string.// A Length string is a possible signed floating number with a unit.// e.g. "42cm" "2.4in" "66pt"// If no unit was given, ParseLength assumes it was (postscript) points.// Currently valid units are://// - mm (millimeter)// - cm (centimeter)// - in (inch)// - pt (point)func ( string) (Length, error) {var Length = 1switch {case strings.HasSuffix(, "in"):= [:len()-len("in")]= Inchcase strings.HasSuffix(, "cm"):= [:len()-len("cm")]= Centimetercase strings.HasSuffix(, "mm"):= [:len()-len("mm")]= Millimetercase strings.HasSuffix(, "pt"):= [:len()-len("pt")]= 1}, := strconv.ParseFloat(, 64)if != nil {return 0,}return Length() * , nil}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |