geometry

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0, MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package geometry defines deterministic geometric primitives.

Index

Constants

View Source
const (
	// EmScale is the number of fixed-point subunits in one em.
	EmScale int64 = 1 << 16
	// DipScale is the number of fixed-point subunits in one host DIP.
	DipScale int64 = 1 << 10
	// MaxDimension is the largest absolute coordinate accepted by public
	// constructors. Ir.Limits carries the same default and may apply a smaller
	// policy limit at a higher layer.
	MaxDimension int64 = 1 << 40
	MaxEm              = Em(MaxDimension * EmScale)
	MaxDip             = Dip(MaxDimension * DipScale)
)

Variables

View Source
var (
	ErrOverflow     = errors.New("geometry: overflow")
	ErrInvalidScale = errors.New("geometry: invalid scale")
	ErrInvalidFloat = errors.New("geometry: invalid floating-point value")
	ErrDimension    = errors.New("geometry: dimension out of range")
)

Functions

This section is empty.

Types

type Dip

type Dip int64

Dip is a signed fixed-point length in 1/DipScale host DIP.

func DipFromFloat

func DipFromFloat(v float64) (Dip, error)

DipFromFloat converts a finite, representable host-unit value to fixed-point DIP. Rounding is to nearest, with ties away from zero.

func EmToDip

func EmToDip(em Em, emSize Dip) (Dip, error)

EmToDip scales a fixed-point em value by the root em size.

func (Dip) Float

func (d Dip) Float() float64

Float returns the value in DIPs.

func (Dip) Float32

func (d Dip) Float32() float32

Float32 returns the value in DIPs as a host-friendly float32.

type Em

type Em int64

Em is a signed fixed-point length in 1/EmScale em.

func EmFromParts

func EmFromParts(numerator, denominator int64) (Em, error)

EmFromParts returns a value equal to numerator/denominator em.

func FontUnitsToEm

func FontUnitsToEm(value int64, unitsPerEm int64) (Em, error)

FontUnitsToEm converts integer font design units to fixed-point em.

func (Em) Abs

func (a Em) Abs() (Em, error)

Abs returns the absolute value of a, reporting overflow for MinInt64.

func (Em) Add

func (a Em) Add(b Em) (Em, error)

Add returns a+b, reporting overflow.

func (Em) Float

func (a Em) Float() float64

Float returns the value in ems.

func (Em) MulDiv

func (a Em) MulDiv(num, den int64) (Em, error)

MulDiv returns a*num/den rounded to nearest, ties away from zero.

type Path

type Path []Segment

Path is a sequence of fillable path segments in host units.

type Point

type Point struct {
	X float32
	Y float32
}

Point is a two-dimensional point in final host units.

type Rect

type Rect struct {
	X      float32
	Y      float32
	Width  float32
	Height float32
}

Rect is an axis-aligned rectangle in final host units.

type SegOp

type SegOp uint8

SegOp is a path segment operation.

const (
	SegMoveTo SegOp = iota
	SegLineTo
	SegQuadTo
	SegCubeTo
	SegClose
)

type Segment

type Segment struct {
	Op     SegOp
	Points [3]Point
}

Segment is one path command. The number of meaningful control points depends on Op: MoveTo/LineTo use one, QuadTo two, CubeTo three, and Close none.

Jump to

Keyboard shortcuts

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