svgdiff

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package svgdiff compares two SVG documents as drawings rather than as bytes.

Why this exists

refract's SVG emitter is deterministic: fixed attribute order, fixed number formatting, no maps iterated, no timestamps. Two runs on one machine produce identical bytes. Across machines they do not, and cannot be made to.

Go permits an implementation to contract `a*b + c` into a fused multiply-add, and arm64 does while amd64 does not. An FMA keeps the full intermediate product instead of rounding it, so the two architectures can disagree in the last bit of a float32 — which is exactly the shape of the expressions that produce chart coordinates: Catmull-Rom control points, a scale's `lo + t*(hi-lo)`, a layout's accumulated margins. One bit of disagreement lands on a rounding boundary often enough to change the printed third decimal, and a byte comparison then fails on a chart that is visually identical.

Chasing the contraction out of every arithmetic site — the language spec says an explicit float32 conversion forbids it — would work until the next expression someone writes. Comparing numerically instead is both robust and more honest about what the golden files are actually asserting: that the same drawing comes out, not that the same floating-point rounding happened.

Everything that is not a number is still compared exactly. Element order, attribute order, ids, colours, path verbs and text content must all match byte for byte, so the tests keep their teeth: this tolerates the last bit of a coordinate and nothing else.

Index

Constants

View Source
const DefaultTolerance = 0.01

DefaultTolerance is the permitted difference between two coordinates, in the document's own units — device pixels, for refract's output.

A hundredth of a pixel is two orders of magnitude below anything visible and four above the one-ULP disagreement this exists to absorb. Any real change to layout, scales or geometry moves things by far more.

Variables

This section is empty.

Functions

func Equal

func Equal(got, want []byte, tol float64) (bool, string)

Equal reports whether got and want describe the same drawing, allowing numbers to differ by at most tol. When they differ, the returned string explains where and how.

Types

This section is empty.

Jump to

Keyboard shortcuts

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