Documentation ¶
Index ¶
- Constants
- Variables
- func EquateLength() cmp.Option
- func EquateLengthApprox(margin Length) cmp.Option
- func VisitLengthUnits(visitor func(LengthUnit))
- type HorizontalDirection
- type Length
- func (l Length) Abs() Length
- func (l Length) AsProto(unit LengthUnit) *geometrypb.Length
- func (l Length) Cm() float64
- func (l Length) Inch() float64
- func (l Length) Max(other Length) Length
- func (l Length) Min(other Length) Length
- func (l Length) Mm() float64
- func (l Length) Mul(factor float64) Length
- func (l Length) Name() string
- func (l Length) Pt() float64
- func (l Length) Round(nearest Length) Length
- func (l Length) String() string
- func (l Length) UnitString(unit LengthUnit) string
- type LengthUnit
- type Point
- type Rect
- func (r Rect) AsProto(unit LengthUnit) *geometrypb.Rect
- func (r Rect) BottomLeft() Point
- func (r Rect) BottomRight() Point
- func (r Rect) Center() Point
- func (r Rect) Contains(other Rect) bool
- func (r Rect) Height() Length
- func (r Rect) Inside(other Rect) bool
- func (r Rect) IsEmpty() bool
- func (r Rect) Normalize() Rect
- func (r Rect) String() string
- func (r Rect) TopLeft() Point
- func (r Rect) TopRight() Point
- func (r Rect) Union(other Rect) Rect
- func (r Rect) Validate() error
- func (r Rect) Width() Length
- type RectCompareFunc
- type RoundedLength
- type Size
- type VerticalDirection
Constants ¶
const ( LeftToRight HorizontalDirection = iota RightToLeft TopToBottom VerticalDirection = iota BottomToTop )
const ( Pt Length = 1 Inch = 72 * Pt In = Inch Centimeter = Inch / 2.54 Cm = Centimeter Millimeter = Centimeter / 10 Mm = Millimeter )
Variables ¶
var DefaultLengthUnit = Cm
var ErrRectInvalid = errors.New("rectangle is invalid")
Functions ¶
func EquateLength ¶
EquateLength returns a cmp.Comparer option checking whether two distances have a margin of less than one millimeter.
func EquateLengthApprox ¶
EquateLengthApprox returns a cmp.Comparer option checking whether two distances are differ less than the specified margin.
func VisitLengthUnits ¶
func VisitLengthUnits(visitor func(LengthUnit))
Types ¶
type HorizontalDirection ¶
type HorizontalDirection int
type Length ¶
type Length float64
Length is a measure of distance in points (1/72th of an inch).
func LengthFromProto ¶
func LengthFromProto(l *geometrypb.Length) (Length, error)
LengthFromProto constructs a Length from a protobuf message. Nil messages are treated as lengths of zero.
func (Length) AsProto ¶
func (l Length) AsProto(unit LengthUnit) *geometrypb.Length
func (Length) Name ¶
Name returns the name of the length unit. Panics if the length is not a base value.
func (Length) String ¶
String returns a string representation of the length using the default unit set in DefaultLengthUnit.
func (Length) UnitString ¶
func (l Length) UnitString(unit LengthUnit) string
UnitString returns a string representation of the length using the given unit.
type LengthUnit ¶
type LengthUnit interface { Name() string // contains filtered or unexported methods }
type Point ¶
type Point struct {
// Coordinates
Left, Top Length
}
func PointFromProto ¶
func PointFromProto(pb *geometrypb.Point) (Point, error)
func (Point) AsProto ¶
func (p Point) AsProto(unit LengthUnit) *geometrypb.Point
type Rect ¶
type Rect struct { // X-coordinate of the upper-left corner. Left Length // Y-coordinate of the upper-left corner. Top Length // X-coordinate of the lower-right corner. Right Length // Y-coordinate of the lower-right corner. Bottom Length }
func RectFromCentimeters ¶
RectFromCentimeters constructs a rectangle from coordinates in centimeters.
func RectFromPoints ¶
RectFromPoints contructs a rectangle from coordinates in points.
func RectFromProto ¶
func RectFromProto(pb *geometrypb.Rect) (Rect, error)
func RectFromXYWH ¶
func (Rect) AsProto ¶
func (r Rect) AsProto(unit LengthUnit) *geometrypb.Rect
func (Rect) BottomLeft ¶
func (Rect) BottomRight ¶
type RectCompareFunc ¶
func MakeRectRowColumnCompare ¶
func MakeRectRowColumnCompare(v VerticalDirection, h HorizontalDirection) RectCompareFunc
MakeRectRowColumnCompare returns a function comparing the positions of two rectangles. Rectangles are organized into lines and columns with the orientations controlled by v and h. The comparer's return value is zero if the rectangles overlap at least 50% on one of the axes, -1 if a is to the left or above b, +1 for the opposite.
type RoundedLength ¶
type RoundedLength struct { // Unit for formatting values. Defaults to [Nearest] if unset. Unit LengthUnit // All values are rounded to the nearest multiple of this length. Nearest Length }
Unit rounding all length values for a friendlier presentation.
func (RoundedLength) Name ¶
func (r RoundedLength) Name() string
type Size ¶
type Size struct {
Width, Height Length
}
func SizeFromProto ¶
func SizeFromProto(pb *geometrypb.Size) (Size, error)
func (Size) AsProto ¶
func (s Size) AsProto(unit LengthUnit) *geometrypb.Size
type VerticalDirection ¶
type VerticalDirection int