render

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 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 render turns the geometry sidecar (agni.v1.geom) into drawable output. It is core, runtime-agnostic Go (CONSTRAINTS C1), taking the geom proto and returning bytes or strings with no syscall/js, no file paths, and no DB handles. The same code backs the SVG dumper, the netlist-vs-geometry oracle, and the WebGL vertex packer (pack.go). Placement transform math lives in internal/geomath, shared with the readers that compute pin world positions (C17).

Index

Constants

View Source
const DefaultHighlightColor = "#ed1cb8"

DefaultHighlightColor is the color of a highlight spec that names none. It is a saturated magenta that stands out against the schematic palette. It lives here so every drawable color is in one file (C12), and the web mirror is DEFAULT_HIGHLIGHT_COLOR in web/src/highlights.ts.

View Source
const HoleCutMm = 1.0

HoleCutMm is the narrowest drill the stack view cuts out of the board, in millimetres. A mounting hole is 2 mm or more and a via well under 1 mm, so the cut shows the holes a reader looks for and keeps Jetson's thousands of vias out of the triangulation.

View Source
const HoleDrillMm = 2.0

HoleDrillMm is the narrowest drill a hole part has, in millimetres. A mounting hole is M2 or wider, and a through-hole test point's drill is about 1 mm.

View Source
const SchematicFontStack = "Arial, 'Liberation Sans', Helvetica, sans-serif"

SchematicFontStack is the default font-family for schematic text, a CSS fallback chain the viewer resolves locally. This engine reads files from authoring tools that print in Arial, so Arial leads. Liberation Sans is metric-compatible with Arial, so a machine without Arial lays text out at identical advance widths. See docsite/content/architecture/geometry-and-rendering.md#the-font-is-a-name-never-a-file.

Family names are SINGLE-quoted because svg.Attr writes its value verbatim inside double quotes, so a double-quoted name would emit invalid XML on the SVG root element.

View Source
const TypicalBodyMm = 1.0

TypicalBodyMm is the height a part whose file states none draws at, in millimetres (agni issue 1352). BoardPartBody.height_defaulted marks such a part, so a client can draw it apart.

Variables

View Source
var DarkStyle = Style{
	Wire:         "#4ade80",
	Bus:          "#60a5fa",
	Symbol:       "#e5e5e5",
	Pin:          "#f87171",
	Frame:        "#b0895a",
	Free:         "#bbbbbb",
	DNP:          "#f87171",
	Field:        "#7aa2f7",
	Label:        "#aaaaaa",
	Annotation:   "#dddddd",
	Ruler:        "#b0895a",
	PinName:      "#5eead4",
	ShapeFill:    "#1a1a1a",
	Page:         "#111111",
	BoardOutline: "#b0895a",
	CopperFront:  "#c83434",
	CopperBack:   "#4d7fc4",
	CopperInner:  "#9aa0a6",
	CopperInners: [30]string{
		"#7fc87f", "#ce7d2c", "#4fcbcb", "#db628b", "#a7a5c6", "#28ccd9", "#e8b2a7", "#f2eda1",
		"#8dcb81", "#ed7c33", "#5bc3eb", "#f76f8e", "#a7a5c6", "#28ccd9", "#e8b2a7", "#f2eda1",
		"#ed7c33", "#5bc3eb", "#f76f8e", "#a7a5c6", "#28ccd9", "#e8b2a7", "#f2eda1", "#ed7c33",
		"#5bc3eb", "#f76f8e", "#a7a5c6", "#28ccd9", "#e8b2a7", "#f2eda1",
	},
	Via:             "#c0c6cc",
	SilkFront:       "#f2eda1",
	SilkBack:        "#e8b2a7",
	FabFront:        "#afafaf",
	FabBack:         "#585d84",
	CourtyardFront:  "#ff26e2",
	CourtyardBack:   "#26e9ff",
	Dielectric:      "#c9ae6e",
	SolderMask:      "#3f9a4c",
	PartBody:        "#5b616b",
	PartBodyDefault: "#8b919a",
	PartClass:       partClassColors,
	BoardMask:       "#1f5131",
	MaskOverCopper:  "#3b7d4e",
	PadFinish:       "#d4af4c",
	BoardSilk:       "#f2f2ee",
	TitleBlockFill:  "#1a1a1a",
	Font:            SchematicFontStack,
}

DarkStyle is a dark-background preset. A WithStyle override recolors every surface (SVG, WebGL geometry and the text overlay) from one palette.

View Source
var DefaultStyle = Style{
	Wire:         "#0a7d2c",
	Bus:          "#1a4de0",
	Symbol:       "#222222",
	Pin:          "#dd1111",
	Frame:        "#8a6d3b",
	Field:        "#1560bd",
	Label:        "#555555",
	Annotation:   "#333333",
	Ruler:        "#8a6d3b",
	PinName:      "#2a7d5a",
	Free:         "#333333",
	DNP:          "#d42020",
	ShapeFill:    "#fdf6d0",
	Page:         "#fdfdfb",
	BoardOutline: "#8a6d3b",
	CopperFront:  "#c83434",
	CopperBack:   "#4d7fc4",
	CopperInner:  "#8a8a8a",
	CopperInners: [30]string{
		"#7fc87f", "#ce7d2c", "#4fcbcb", "#db628b", "#a7a5c6", "#28ccd9", "#e8b2a7", "#c1b61b",
		"#8dcb81", "#ed7c33", "#5bc3eb", "#f76f8e", "#a7a5c6", "#28ccd9", "#e8b2a7", "#c1b61b",
		"#ed7c33", "#5bc3eb", "#f76f8e", "#a7a5c6", "#28ccd9", "#e8b2a7", "#c1b61b", "#ed7c33",
		"#5bc3eb", "#f76f8e", "#a7a5c6", "#28ccd9", "#e8b2a7", "#c1b61b",
	},
	Via:             "#9aa0a6",
	SilkFront:       "#c1b61b",
	SilkBack:        "#e8b2a7",
	FabFront:        "#afafaf",
	FabBack:         "#585d84",
	CourtyardFront:  "#ff26e2",
	CourtyardBack:   "#00c7de",
	Dielectric:      "#b59a5b",
	SolderMask:      "#2f7d3b",
	PartBody:        "#4a4f57",
	PartBodyDefault: "#a7adb5",
	PartClass:       partClassColors,
	BoardMask:       "#1f5131",
	MaskOverCopper:  "#3b7d4e",
	PadFinish:       "#d4af4c",
	BoardSilk:       "#f2f2ee",
	TitleBlockFill:  "#fffef8",
	Font:            SchematicFontStack,
}

DefaultStyle is the built-in palette and font. Override per render call with WithStyle.

View Source
var Themes = map[string]Style{"default": DefaultStyle, "dark": DarkStyle}

Themes maps a theme name to its Style, for the `agni serve --theme` knob.

View Source
var TypicalMm = map[string]float64{"copper": 0.035, "dielectric": 0.1, "mask": 0.01, "paste": 0, "silk": 0}

TypicalMm is the thickness a stack row of each kind draws at when the file gives none, in millimetres (agni issues 1593 and 1635). BoardStackRow.thickness_defaulted marks such a row. Silkscreen and paste draw on the surface, at 0, since a board's stated thickness leaves them out. A kind not listed draws at 0. KiCad gives silk and paste no thickness, and the Jetson cut's 28 rows then sum to its stated 1.711 mm.

Functions

func BoardLayers added in v0.6.0

func BoardLayers(b *geom.BoardGeometry, opts ...Option) []*geom.BoardLayerRow

BoardLayers lists a board's layer rows, in the order the viewer's Sheets panel shows them. Each row carries the selector and the packed groups that hide it in BoardSVG's and PackBoard's output under the same style. A row the board's stack names also carries its thickness (agni 1603).

func BoardSVG

func BoardSVG(b *geom.BoardGeometry, opts ...Option) string

BoardSVG renders a board to a standalone SVG document. The board is the WS1-006 geometry sidecar, and BoardSVG is the board analogue of SheetSVG. WS7-035 is the packed/WebGL tier. Copper draws per layer back-to-front so the front side reads on top. Every stratum goes into a classed <g> (edge, copper-front, copper-back, copper-inner, through, zones-*, silk, labels), so client-side CSS sets layer visibility with no re-render. HighlightBoardSVG overlays share the same frame.

Coordinates are the sidecar's, in nanometers and Y-up, because the reader flips them. Rotations arrive already in the Y-up frame (see padWorld), and BoardSVG negates them only for the SVG transform. Pad positions are footprint-local per the proto contract.

func BoardStack added in v0.7.0

func BoardStack(b *geom.BoardGeometry, opts ...Option) *geom.BoardStackView

BoardStack is the board's physical layer stack as the viewer's layer list shows it (agni 1603). It returns nil for a board whose file states no stack, so the list shows no stack section. The rows take their colours from the style in opts.

func HasHighlights

func HasHighlights(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, specs []*geom.HighlightSpec) bool

HasHighlights reports whether any spec matches at least one entity drawn on this sheet. A caller rendering per sheet can then skip a sheet that no finding touches, instead of writing an unannotated copy. A review report does this, and annotates only the sheets that show its findings. HasHighlights reuses collectEntities, so "would highlight" agrees with what SheetSVGHighlighted draws.

func HighlightBoardSVG

func HighlightBoardSVG(b *geom.BoardGeometry, specs []*geom.HighlightSpec, opts ...Option) string

HighlightBoardSVG resolves highlight specs against a board and returns a transparent SVG overlay framed like BoardSVG (both use frameBoard), which a client stacks above the base document. It is the board face of the WS9-016 highlight contract. A listed NET repaints its routed copper (segments re-stroked a little wider, vias and every pad on it filled, pours tinted) at boardNetAlpha (agni issue 1543), a listed COMPONENT matches all its pads plus a marker ring at the placement origin, and a listed pin matches that (ref_des, pad number). A spec with a bounding shape frames each listed component and pin instead, as HighlightSVG does on a sheet (agni issue 1536). A net listed by id matches through the render's WithNetIDs, since the board names its nets and holds no schematic ids. Specs paint in order, later wins.

func HighlightPacked

func HighlightPacked(sheet *geom.PackedSheet, specs []*geom.HighlightSpec) *geom.PackedHighlight

HighlightPacked resolves highlight specs against one packed sheet. For each spec, in the same order, it returns the indices of the primitives the spec selects plus the spec's style. The caller redraws those primitives above the base geometry. No vertices are duplicated, because the group joins PackedSheet.vertices/primitives by index. An element matched by several specs belongs to each matching group. The renderer owns paint order, where a later spec wins.

func HighlightSVG

func HighlightSVG(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, specs []*geom.HighlightSpec) string

HighlightSVG resolves highlight specs against one tier-1 sheet and returns a standalone transparent SVG overlay with the exact size, viewBox, and world->pixel mapping of SheetSVG (both use frameSheet), so it stacks or composites onto the base document. Specs paint in order, so a later spec wins where selections overlap. Each spec's shape picks the strategy that draws its entities (outline when unset).

func PackBoard

func PackBoard(b *geom.BoardGeometry, opts ...Option) *geom.PackedSheet

PackBoard projects the board sidecar into the tier-2 packed form (WS7-035), the board analogue of PackSheet in the same envelope. Copper is keyed by net and pads by (ref_des, pad number, net), so HighlightPacked and the web's resolveHighlights join unchanged. The front/back/inner strata are distinct groups, so a renderer hides a layer by skipping its group. See docsite/content/architecture/geometry-and-rendering.md#board-geometry-sidecar.

func PackSheet

func PackSheet(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, opts ...Option) *geom.PackedSheet

PackSheet projects one tier-1 sheet into the tier-2 PackedSheet columnar form. That form holds rebased int32 vertices, a fixed-width primitives table, and PrimitiveKeys back to ref_des/net for picking. The vertices are relative to the sheet's min corner, so GLSL ES's 32-bit attributes are exact. This is a derived projection of the sidecar, computed on demand, not stored.

func PackedKeys added in v0.6.10

func PackedKeys(sheet *geom.PackedSheet) []*geom.PrimitiveKey

PackedKeys decodes a packed sheet's key columns into one PrimitiveKey per keyed primitive, in primitive order. A sheet with no key columns has no keys. A string index past the table reads as "", and a trailing partial record is ignored, so a malformed sheet loses keys rather than panics.

func PackedLabels added in v0.6.10

func PackedLabels(sheet *geom.PackedSheet) []*geom.PackedLabel

PackedLabels decodes a packed sheet's label columns into one PackedLabel per text, in draw order, with each label's markup runs. It reads a malformed sheet as PackedKeys does.

func PickSheet

func PickSheet(g *geom.SchematicGeometry, sel string) (*geom.SheetGeometry, error)

PickSheet resolves a sheet selector (a numeric index, a sheet id or a sheet name) against a schematic's sheets. An id or name match wins over an index, so a single-sheet format that ids its page "1" is still selectable by that id. It does no I/O, and both the CLI render command and the web design service call it.

func SheetIndex

func SheetIndex(g *geom.SchematicGeometry, sheet *geom.SheetGeometry) int

SheetIndex returns the 0-based position of sheet in the geometry's sheet list, or 0 if not found. It maps a selected sheet to a tool's 1-based page order (the native renderer).

func SheetSVG

func SheetSVG(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, opts ...Option) string

SheetSVG renders one schematic sheet to a standalone SVG document, resolving each placement against the design's symbol library. SheetSVG and the WebGL2 path (WS7-001) are both backends over the same render layer, so nothing here is WebGL- or format-bound. Coordinates are framed by frameSheet, which normalizes them to pixels and flips Y.

func SheetSVGHighlighted

func SheetSVGHighlighted(g *geom.SchematicGeometry, sheet *geom.SheetGeometry, specs []*geom.HighlightSpec, opts ...Option) string

SheetSVGHighlighted renders one sheet and BAKES the highlight specs into a single SVG document. A static render, such as a report image or a shared file, then holds its annotations with no separate overlay. SheetSVGHighlighted runs the base render (drawSheetContent) and then drawHighlights, the projection the HighlightSheet rpc serves as an overlay. Both share frameSheet, so they draw on one canvas. Highlights draw LAST, above the schematic, so the marked entity reads through the translucent shapes.

Types

type BoardNet added in v0.6.1

type BoardNet struct {
	Name string
	Pins [][2]string
}

BoardNet is one board net as a NetIDFunc sees it. Name is the net's name on the board. Pins lists every pad on the net as (ref-des, pad number), sorted, so a resolver can join the net by its connections when the name does not join it.

type NetIDFunc added in v0.6.1

type NetIDFunc func(BoardNet) string

NetIDFunc answers the schematic net id (ir.Net.id) of one board net, or "" when it cannot say which net that is. A board file names its nets and carries no schematic id, so a board render asks the caller, which holds the design (agni issue 1440). A net answered "" keeps its name as its only key, as before.

type Option

type Option func(*Style)

Option configures one render call. With no options a render uses DefaultStyle.

func WithNetIDs added in v0.6.1

func WithNetIDs(f NetIDFunc) Option

WithNetIDs has a board render ask f for each net's schematic net id, and key the net's copper and pads with it (see NetIDFunc).

func WithPartClasses added in v0.8.0

func WithPartClasses(f PartClassFunc) Option

WithPartClasses has the stack view colour each part's body by its classes (agni 1653).

func WithPickTargets added in v0.2.0

func WithPickTargets() Option

WithPickTargets emits the invisible per-pin pick targets (see Style.PickTargets). The served viewer asks for them; a render destined for a file or a report does not.

func WithPinDots

func WithPinDots() Option

WithPinDots turns the per-pin verification dots on for one render call (see Style.PinDots).

func WithStyle

func WithStyle(s Style) Option

WithStyle overrides the palette and font for one render call. It keeps the switches an earlier option turned on (PinDots, PickTargets, the net-id lookup), so options combine in any order (agni issue 765). Before, it replaced the whole Style and erased them.

type PartClassColors added in v0.8.0

type PartClassColors struct {
	Resistor, Capacitor, Inductor, Diode, LED, IC, Connector, Transistor, Clock, TestPoint, Fuse string
}

PartClassColors is the colour of a part's body by its class (agni 1653). Each field is one class family, and a class id outside them has no colour. It is a struct rather than a map so Style stays comparable and prints the same way every time, which the packed board's cache key relies on.

type PartClassFunc added in v0.8.0

type PartClassFunc func(ref string) []string

PartClassFunc answers a placed part's classes by its ref-des, most specific first, as classify.BySpecificity orders a component's device_classes. It answers nil for a part the design does not classify.

type Style

type Style struct {
	// Geometry line/stroke colors.
	Wire   string // wire polylines
	Bus    string // bus trunks / entries (WS7-042), drawn thicker than a wire
	Symbol string // symbol graphics stroke (and dots)
	Pin    string // pin connect dots
	Frame  string // worksheet frame + zone-ruler tick lines
	Free   string // sheet-level free graphics (junction dots, no-connects, notes)
	DNP    string // the cross over a do-not-populate part (agni 1344)

	// Text colors.
	Field      string // ref-des / value / custom placement fields
	Label      string // sheet labels (net labels, page text)
	Annotation string // symbol annotations and title-block field text
	Ruler      string // zone-ruler numbers/letters and pin numbers
	PinName    string // pin names

	// Fill colors.
	ShapeFill      string // default fill for a filled symbol shape
	Page           string // page background
	TitleBlockFill string // title-block box fill

	// Board colors (WS7-034). Copper takes the colours of KiCad's default theme, read off kicad-cli's
	// export. InN.Cu takes CopperInners[N-1], as KiCad colours an inner layer by its number, so a
	// board's In5 draws in In5's colour whichever inner layers it uses. An inner layer of another
	// name takes the colour of its place among the inner layers (agni issue 1401). CopperInner
	// colours a layer past the packed group limit, and an inner layer whose entry is blank. Via
	// colors the barrel ring and through-hole pad lands, and a drill hole is drawn in Page.
	// CopperInners is an array rather than a slice, so a Style still compares with ==.
	BoardOutline string     // Edge.Cuts outline
	CopperFront  string     // F.Cu segments, SMD pads on the front
	CopperBack   string     // B.Cu
	CopperInner  string     // an inner layer with no colour of its own
	CopperInners [30]string // In1.Cu to In30.Cu
	Via          string     // via rings + through-hole pad lands
	// Each side's silkscreen, fab and courtyard layers take their own colour, as KiCad's do, so the
	// back's legend reads apart from the front's. Both styles use the colours of KiCad's default
	// theme. DefaultStyle darkens the few that fall under 1.5:1 on its light page to 2:1, in the same
	// hue, since KiCad's pale front silk all but vanishes there.
	SilkFront      string // F.SilkS graphics and text, and a graphics layer of no known kind
	SilkBack       string // B.SilkS
	FabFront       string // F.Fab, such as body outlines and values (agni issue 1366)
	FabBack        string // B.Fab
	CourtyardFront string // F.CrtYd
	CourtyardBack  string // B.CrtYd
	// A board view drawn as its exploded stack fills each dielectric and solder mask as a translucent
	// slab in these (agni 1593). They travel as BoardStackRow.color.
	Dielectric string // a core or prepreg
	SolderMask string // a solder mask
	// A part stands on its side's face of the stack view as a solid in PartBody (agni 1352). A part
	// whose file states no height draws at a default height in PartBodyDefault, so it reads apart.
	PartBody        string
	PartBodyDefault string
	// A part's body takes its class's colour where PartClass gives one, so part types read apart in
	// the stack view (agni 1653). A part with no coloured class keeps PartBody.
	PartClass PartClassColors
	// The stack view's board look draws the board as it is made, in these (agni 1653). BoardMask is
	// the opaque solder mask, MaskOverCopper is outer copper seen through it, PadFinish is exposed
	// copper such as a pad, and BoardSilk is the silkscreen. They travel as BoardStackView.board_look.
	BoardMask      string
	MaskOverCopper string
	PadFinish      string
	BoardSilk      string

	// Font is the default font-family for all text, a CSS family list rather than one face
	// (see SchematicFontStack). There is no per-element font.
	Font string

	// PinDots draws a dot at every pin connect-point in the Pin color, a verification aid for
	// the pin-on-wire eyeball check. Off by default because Eeschema draws no such dots and a
	// hardware engineer reads them as noise (WS7-017). Real junction dots are sheet Shapes and
	// draw regardless.
	PinDots bool
	// PickTargets emits an invisible, keyed circle at every pin so a viewer can CLICK a pin,
	// plus a wide invisible companion stroke per wire. Off by default because a pin has no drawn
	// element of its own, so the targets are ADDED elements, one per pin, and on a large sheet
	// they are the biggest single contributor to document size. Only the served viewer asks for
	// them. On a board it keys every pad, track, via, zone and footprint graphic, and adds one
	// invisible rect per footprint (BoardSVG). See docsite/content/architecture/web-picking.md.
	PickTargets bool
	// contains filtered or unexported fields
}

Style is the render layer's color palette and default font. The SVG backend and the WebGL path both resolve colors from one Style, and a caller overrides the defaults (theming, dark mode, accessibility) with WithStyle. Colors are "#rrggbb" and Font is a CSS/SVG font-family.

func (Style) GroupColor

func (s Style) GroupColor(group uint8) string

GroupColor returns the geometry color for a schematic primitive group (groupSymbol through groupFrame, and groupBus). The SVG backend picks per shape and the packer sends the set to WebGL as PackedSheet.group_colors. Unknown groups, including the board strata, fall back to Symbol; boards use boardGroupColors.

Jump to

Keyboard shortcuts

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