transform

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package transform provides SVG transform parsing, matrix operations, and decomposition, ported from SVGO's plugins/_transforms.js.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcosDeg

func AcosDeg(val float64, floatPrecision int) float64

AcosDeg returns acos in degrees, rounded to floatPrecision.

func AsinDeg

func AsinDeg(val float64, floatPrecision int) float64

AsinDeg returns asin in degrees, rounded to floatPrecision.

func AtanDeg

func AtanDeg(val float64, floatPrecision int) float64

AtanDeg returns atan in degrees, rounded to floatPrecision.

func JS2Transform

func JS2Transform(transforms []TransformItem, params *TransformParams) string

JS2Transform converts transforms to an SVG transform attribute string.

func MultiplyTransformMatrices

func MultiplyTransformMatrices(a, b []float64) []float64

MultiplyTransformMatrices multiplies two 2D affine transformation matrices. Each matrix is [a, b, c, d, e, f].

func RoundTransform

func RoundTransform(t *TransformItem, params *TransformParams)

RoundTransform rounds transform data based on the params.

func TransformArc

func TransformArc(cursor [2]float64, arc []float64, transform []float64) []float64

TransformArc applies a transformation matrix to an elliptical arc. cursor is [x, y], arc is [rx, ry, angle, large-arc, sweep, x, y]. transform is [a, b, c, d, e, f].

Types

type TransformItem

type TransformItem struct {
	Name string
	Data []float64
}

TransformItem represents a single transform function with its parameters.

func MatrixToTransform

func MatrixToTransform(origMatrix *TransformItem, params *TransformParams) []TransformItem

MatrixToTransform decomposes a matrix into simple transforms and optimizes.

func Transform2JS

func Transform2JS(transformString string) []TransformItem

Transform2JS converts a transform attribute string to a slice of TransformItems. Returns nil if the string is malformed.

func TransformsMultiply

func TransformsMultiply(transforms []TransformItem) TransformItem

TransformsMultiply multiplies multiple transforms into a single matrix.

type TransformParams

type TransformParams struct {
	ConvertToShorts    bool
	DegPrecision       *int // nil means not set
	FloatPrecision     int
	TransformPrecision int
	MatrixToTransform  bool
	ShortTranslate     bool
	ShortScale         bool
	ShortRotate        bool
	RemoveUseless      bool
	CollapseIntoOne    bool
	LeadingZero        bool
	NegativeExtraSpace bool
	NoSpaceAfterFlags  bool
}

TransformParams controls transform optimization and output formatting.

Jump to

Keyboard shortcuts

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