paths

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package paths provides tools for manipulating 2d paths consisting of line segments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	Min, Max Vec2
}

Bounds describes an axis-aligned bounding box.

type Path

type Path struct {
	V []Vec2
}

A Path is a contiguous series of line segments, from the first point in the V slice to the last.

type Paths

type Paths struct {
	Bounds Bounds
	P      []Path
}

Paths is a set of paths, along with a view bounds.

func FromSVG

func FromSVG(r io.Reader) (p *Paths, rerr error)

FromSVG parses an SVG file, extracting paths. This provides only limited SVG parsing support, and will fail or produce incorrect results if the SVG file uses features that it doesn't understand.

func (*Paths) Clip

func (ps *Paths) Clip(b Bounds)

Clip removes all line segments outside the given bounds. If a path crosses the bounds, it's broken into multiple paths.

func (*Paths) SVG

func (ps *Paths) SVG(w io.Writer) error

SVG writes an SVG file that contains black strokes along the paths.

func (*Paths) Simplify

func (ps *Paths) Simplify(tol float64)

Simplify removes points from paths, with the guarantee that all removed points are within the given tolerance (distance) from the new path.

func (*Paths) Sort

func (ps *Paths) Sort(cfg *SortConfig)

Sort reorders paths to reduce the amount of movement between the end of one path and the start of the next. This is intended to improve rendering time using a physical xy plotter. The reordering can be configured in a limited way.

func (*Paths) Transform

func (ps *Paths) Transform(nb Bounds)

Transform resizes all paths so that the rectangle forming the current bounds is the size of the new bounds. The bounds are also updated to the new bounds.

type SortConfig

type SortConfig struct {
	Split   bool // ok to split continuous paths
	Reverse bool // ok to draw paths in the reverse direction
}

SortConfig provides options for path sorting.

type Vec2

type Vec2 [2]float64

Vec2 is a 2-dimensional vector.

Jump to

Keyboard shortcuts

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