transforms

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unknown = iota
	Smaller
	Larger
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Axis

type Axis int
const (
	Horizontal Axis = iota
	Vertical
)

type CleanupTransform

type CleanupTransform struct {
	Precision int
}

func (CleanupTransform) PathTransform

func (st CleanupTransform) PathTransform(p path.Path) (path.Path, error)

cleans up the path.

  1. make sure the first operation is a move
  2. Insert a Move if the segment Start is not the same as the segment end of the previous
  3. align start and end if they are not equal, but within precision
  4. Check for NaN

type DedupSegmentsTransform

type DedupSegmentsTransform struct {
	Precision int
}

func (DedupSegmentsTransform) PathTransform

func (st DedupSegmentsTransform) PathTransform(p path.Path) (path.Path, error)

this will remove any redundant operations. currently:

  1. collapse multiple MOVEs in a row
  2. Remove a MOVE to the current location
  3. if prev segment is the same as the reverse of the current segment, remove both TODO: should this be split into a its own transform? I wonder if this is ever the intent?

type HSliceTransform

type HSliceTransform struct {
	Y                float64
	SegmentOperators path.SegmentOperators
	Precision        int
}

Cut the path horizontally at the given Y coordinate, removes everything above Y

func (HSliceTransform) PathTransform

func (hs HSliceTransform) PathTransform(p path.Path) (path.Path, error)

type JoinTransform

type JoinTransform struct {
	Precision        int
	SegmentOperators path.SegmentOperators
	// should we close the path?
	ClosePath bool
}

connects any disjoint segments as smoothly as possible

func (JoinTransform) PathTransform

func (jt JoinTransform) PathTransform(pth path.Path) (path.Path, error)

type MatrixTransform

type MatrixTransform struct {
	A, B, C, D, E, F float64
	SegmentOperators path.SegmentOperators
}

A basic affine (matrix) transform see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform#General_Transformation

func (MatrixTransform) PathTransform

func (mt MatrixTransform) PathTransform(p path.Path) (path.Path, error)

func (MatrixTransform) TransformPoint

func (mt MatrixTransform) TransformPoint(p path.Point) path.Point

type MirrorTransform

type MirrorTransform struct {
	Axis             Axis
	Handle           path.PathAttr
	SegmentOperators path.SegmentOperators
}

This moves the path origin to the requested point

func (MirrorTransform) PathTransform

func (mt MirrorTransform) PathTransform(p path.Path) (path.Path, error)

type MoveTransform

type MoveTransform struct {
	Point path.Point
	// if a handle is specified, than this move operation will move the
	// handle to the requested point. by default the handle is the topleft
	Handle           path.PathAttr
	SegmentOperators path.SegmentOperators
}

This moves the path origin to the requested point

func (MoveTransform) PathTransform

func (mt MoveTransform) PathTransform(p path.Path) (path.Path, error)

type OffsetTransform

type OffsetTransform struct {
	Precision        int
	Distance         float64
	SegmentOperators path.SegmentOperators
	SizeShouldBe     SizeShouldBe
}

func (OffsetTransform) PathTransform

func (ofs OffsetTransform) PathTransform(p path.Path) (path.Path, error)

Transforms the path into an offset path at distance If distance is 0 than this transform does nothing.

type PathReverse

type PathReverse struct {
}

func (PathReverse) PathTransform

func (pr PathReverse) PathTransform(p path.Path) (path.Path, error)

type RebuildTransform

type RebuildTransform struct{}

func (RebuildTransform) PathTransform

func (st RebuildTransform) PathTransform(p path.Path) (path.Path, error)

Simple transform to rebuild the path. this dumps the path to a string and reparses mostly this is for cleaning datastructure problems from other transforms (I.E internal changes mean start and end points don't align)

type ReorderTransform

type ReorderTransform struct {
	Precision int
}

func (ReorderTransform) PathTransform

func (st ReorderTransform) PathTransform(p path.Path) (path.Path, error)

Transform that will reorder any sections that start and end at the same place

type RotateScaleTransform

type RotateScaleTransform struct {
	StartPoint path.Point
	EndPoint   path.Point
	// What point on the path should be considered origin?
	// defaults to path start
	PathStartPoint path.Point
	// What point on the path should be considered the end?
	// defaults to path end
	PathEndPoint     path.Point
	SegmentOperators path.SegmentOperators
}

Will rotate and scale the path so that the PathStartPoint and PathEndPoint equal StartPoint and EndPoint. This is useful for using svg to connect two points

func (RotateScaleTransform) PathTransform

func (rt RotateScaleTransform) PathTransform(p path.Path) (path.Path, error)

type RotateTransform

type RotateTransform struct {
	Degrees          float64
	Axis             path.PathAttr
	SegmentOperators path.SegmentOperators
}

func (RotateTransform) PathTransform

func (rt RotateTransform) PathTransform(p path.Path) (path.Path, error)

func (RotateTransform) PathTransformWithAxis

func (rt RotateTransform) PathTransformWithAxis(pth path.Path, axisPoint path.Point) (path.Path, error)

type ScaleTransform

type ScaleTransform struct {
	ScaleX float64
	ScaleY float64
	// TODO: Scaling by start and end point should
	// use the rotate_scale transform.
	StartPoint       path.Point
	EndPoint         path.Point
	Width            float64
	Height           float64
	SegmentOperators path.SegmentOperators
}

This changes the size and proportions of the given path

func (ScaleTransform) PathTransform

func (st ScaleTransform) PathTransform(p path.Path) (path.Path, error)

type SegmentReverse

type SegmentReverse struct {
}

func (SegmentReverse) SegmentTransform

func (s SegmentReverse) SegmentTransform(segment path.Segment) path.Segment

Reverses a single segment. Note that this flips the segment, but will need a Move to start if you expect it to render properly within a path

type ShiftTransform

type ShiftTransform struct {
	DeltaX           float64
	DeltaY           float64
	SegmentOperators path.SegmentOperators
}

This shifts the path by the requested amount in X and/or Y

func (ShiftTransform) PathTransform

func (st ShiftTransform) PathTransform(p path.Path) (path.Path, error)

type SimpleJoin

type SimpleJoin struct {
}

func (SimpleJoin) JoinPaths

func (sj SimpleJoin) JoinPaths(paths ...path.Path) path.Path

type SizeShouldBe

type SizeShouldBe int

type TrimWhitespaceTransform

type TrimWhitespaceTransform struct {
	SegmentOperators path.SegmentOperators
}

func (TrimWhitespaceTransform) PathTransform

func (tw TrimWhitespaceTransform) PathTransform(p path.Path) (path.Path, error)

PathTransform trims any whitespace by moving the path to as close to 0,0 as possible. Note that you should typically call simplify before triming whitespace to avoid things like M 0 0, M 10, 11

Jump to

Keyboard shortcuts

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