geom

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package geom implements the geometry model of doc/template.md#geometry: dimensions with units, the three-decimal rounding rule, boxes, the any-two-of-three edge resolution, and content alignment.

Index

Constants

View Source
const Tolerance = 0.001

Tolerance is the slack allowed when comparing a length against a frame boundary, per doc/layout.md#coordinates-and-rounding. A band whose height matches the remaining space exactly fits rather than ejecting.

Variables

View Source
var ErrOverSpecified = fmt.Errorf("all three of near edge, far edge and size specified")

ErrOverSpecified reports an axis with all three of near, far and size given. Templates are rejected for this at load; Resolve guards against it too.

Functions

func AlignH

func AlignH(outerStart, outer, inner float64, align HAlign) float64

AlignH places content of width inner inside a box at outerStart of width outer, and returns the content's start coordinate.

func AlignV

func AlignV(outerStart, outer, inner float64, align VAlign) float64

AlignV places content of height inner inside a box at outerStart of height outer, and returns the content's start coordinate.

func Fits

func Fits(want, have float64) bool

Fits reports whether want fits in have, within Tolerance.

func ParseDim

func ParseDim(spec string) (float64, error)

ParseDim parses a dimension: a bare number in PostScript points, or a number with one of the unit suffixes pt, mil, mm, cm, in.

func Round

func Round(value float64) float64

Round rounds a length to three decimal places.

The rule is normative rather than cosmetic: it decides whether a band fits, so an implementation that rounds only at output time disagrees about page breaks. Every computed coordinate and extent passes through here immediately after the computation that produces it.

Types

type Box

type Box struct {
	Left, Top, Width, Height float64
}

Box is an absolute rectangle. Y grows downward from the top-left of the page.

func (Box) Bottom

func (box Box) Bottom() float64

Bottom returns the box's bottom edge.

func (Box) Right

func (box Box) Right() float64

Right returns the box's right edge.

type Extent

type Extent struct {
	Near, Far, Size Opt
	Max             Opt
}

Extent is one axis of a declared box: the near edge (left or top), the far edge (right or bottom, measured inward from the container's far edge), and the size. Max is the maxwidth or maxheight clamp, which is not part of the two-of-three count.

func (Extent) Count

func (ext Extent) Count() int

Count returns how many of Near, Far and Size are specified.

func (Extent) Resolve

func (ext Extent) Resolve(start, size float64) (pos, extent float64, err error)

Resolve places the extent within a container running from start for size units, per the fill order in doc/template.md#position-and-size-any-two-of-three: missing values are filled in the order near, then far, until two of the three are known, and the third is derived.

A derived size may come out negative when the two declared edges cross; it is clamped to zero, since a printout box has non-negative extents.

type HAlign

type HAlign int

HAlign is horizontal alignment of content within its box.

const (
	HLeft HAlign = iota
	HCenter
	HRight
)

Horizontal alignments.

func ParseHAlign

func ParseHAlign(text string) (HAlign, error)

ParseHAlign parses a halign enumeration value.

type Opt

type Opt struct {
	Value float64
	Set   bool
}

Opt is an optionally-specified length.

func Unset

func Unset() Opt

Unset returns an unset Opt.

func Val

func Val(value float64) Opt

Val returns a set Opt.

func (Opt) Count

func (opt Opt) Count(rest ...Opt) int

Count is a helper for Resolve: how many of the receiver and the two arguments are set.

type PageSize

type PageSize struct {
	Width, Height float64
}

PageSize is a page's portrait width and height in points.

func LookupPageSize

func LookupPageSize(name string) (PageSize, error)

LookupPageSize returns the named page size in portrait orientation.

type VAlign

type VAlign int

VAlign is vertical alignment of content within its box.

const (
	VTop VAlign = iota
	VCenter
	VBottom
)

Vertical alignments.

func ParseVAlign

func ParseVAlign(text string) (VAlign, error)

ParseVAlign parses a valign enumeration value.

Jump to

Keyboard shortcuts

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