segment

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: 1 Imported by: 0

Documentation

Overview

Package segment solves one-dimensional stretchable segment layout.

Build a partial order of "segment A lies wholly before segment B", then propagate positions in topological order using actual measured extents rather than declared ones.

The engine uses it vertically, for floating elements: a floating element sits below whatever lies above it, and how far below is its declared gap to the nearest predecessor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Precedes

func Precedes(earlier, seg Segment) bool

Precedes reports whether earlier lies wholly before seg: earlier's far edge is at or before seg's near edge.

func Reduce

func Reduce(deps [][]int) [][]int

Reduce removes edges that transitivity already implies, leaving the minimal partial order: if C follows both A and B and B follows A, C follows B alone.

Types

type Layout

type Layout struct {
	// contains filtered or unexported fields
}

Layout is a solved partial order, reusable across measurements.

func New

func New(segments []Segment, deps [][]int) *Layout

New builds the layout.

deps maps each segment to the segments it depends on -- those that must be placed first. It must be acyclic and hold an entry for every segment.

func (*Layout) Solve

func (layout *Layout) Solve(extents []float64) []float64

Solve returns each segment's actual start, given its actual extent.

A segment with no dependencies keeps its declared start. One with dependencies begins after the last of them ends, plus its gap -- and the gap applies only when the segment has an extent of its own, so a collapsed segment neither occupies space nor reserves any.

type Segment

type Segment struct {
	Start  float64
	Extent float64
}

Segment is one participant, identified by its index in the caller's slice.

Start and Extent are the declared geometry, which is what the partial order and the gaps are computed from. The measured extent is supplied separately, so the same order holds for every record.

Jump to

Keyboard shortcuts

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