graphics2d

package module
v0.0.0-...-716269e Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 3

README

Yet Another 2D Graphics Package For Go

Go Reference godocs.io Go Report Card Build Status

Gophers rendered with graphics2d

Dancing gophers rendered with graphics2d primitives.

The top level Path and Shape types are complete, and the majority of PathProcessors implemented, including:

  • StrokeProc - fixed width strokes with a variety of cap and join types.
  • SnipProc - chops up a path according to a pattern
  • DashProc - wrapper around SnipProc for creating a dashed path
  • CompoundProc - allows concatenation of PathProcessors

dashedstroke := NewCompoundProc(NewDashProc(pattern, offs), NewStrokeProc(1))

Wiki entries here

Code Structure

Visualization of the codebase

Documentation

Overview

Package graphics2d contains types and functions for 2D graphics rendering.

If all you want to do is render a point, line, arc or path of a particular color into an image, then use the draw functions which hide all of the mechanics described below from you:

DrawPoint
DrawLine
DrawArc
DrawPath

However, to take full advantage of the package, here's a few more things you'll need to know.

The lowest type is a Path. Paths start from a location and add steps using a number of control points. The number of control points determines the polynomial order of the step: 0 - line; 1 - quadratic; 2 - cubic; 3 - quartic; ... A path can be closed which forces a line from the start location to the last. Once a path is closed, no more steps can be added. Unlike other implementations, a path here represents a single stroke (pen down). There is no move (pen up) step.

The Shape type is a container for paths and represents something that can be filled and rendered. When paths are rendered, they must be fillable (i.e. closed), so they are forced closed by the renderer.

This can lead to unexpected results...

If a shape is rendered with a pen (see DrawShape) and the pen has a stroke associated with it, then open paths are not an issue since strokes return closed paths.

A pen is a combination of a color (or image), a stroke and a transformation from shape space to image space. If you're defining operations in the same space as the image, then the transformation is simply the identity transformation. If, however, say your operations are in a space [0, 1]^2, then you'd specify a transformation that maps [0, 1] => [0, width-1] etc. (i.e. scale by image width and height). Note that this transformation is applied *after* the stroke, so for a 1 pixel wide stroke the stroke width would be 1 / width. You don't have to use pens, you can use the RenderShape, PathProcessor, image filler and transformation functions directly. Pens just provide a convenient abstraction that hides path processing.

Note that if the image is written to every graphics operation (as it is with the Draw*() functions), this can kill performance as the image defined by the shape's bounds is written every time. It's better to collect all the operations associated with a color in a shape and then render that shape once.

The PathProcessor interface is where the magic happens. Given a path, a function implementing this interface returns a collection of paths derived from it. This allows for stroking, dashing and a variety of other possibilities:

CapsProc - adds shapes at the start and end of a path
CompoundProc - allows multiple path processors to be run in sequence
CurvesToLinesProc - replaces curved steps with lines between the points
DashProc - wraps SnipProc to produce a dashed path
FlattenProc - wraps Path.Flatten
JitterProc - randomly move segment endpoints by some percentage of the segment's length
LineProc - wraps Path.Line
MunchProc - converts a path into length sized line paths
OpenProc - wraps Path.Open
PointsProc - adds shapes at the start of each step and the end of the last step
ReverseProc - wraps Path.Reverse
RoundedProc - rounds the corners of adjacent line segments in a path
SimplifyProc - wraps Path.Simplify
ShapesProc - distributes shapes along a path separated by some distance
SnipProc - cuts up a path into smaller pieces according to a pattern
SplitProc - splits each step into its own path
StrokeProc - creates a fixed width outline of a path with options for the cap and
join styles
TraceProc - creates a new path by tracing the normals of the path at a fixed distance
TransformProc - wraps Path.Transform

Shapes are rendered with the render functions. Paths are forced closed when rendered (see shapes above). Convenience methods are provided for rendering with a single color or an image (see also pens, above). The full render function allows a clip mask to be supplied, and the draw.Op to be specified.

The Aff3 type provides the ability to specify affine transforms on Paths and Shapes.

Utility functions are provided to generate common forms of paths:

Point
Line
PolyLine
Curve
PolyCurve
Arc
ArcFromPoint
PolyArcFromPoint
Circle
Ellipse
EllipticalArc
EllipticalArcFromPoint
Lune
RegularPolygon
ReentrantPolygon
IrregularPolygon

A shape function is provided to capture glyphs:

GlyphToShape

Index

Constants

View Source
const (
	TwoPi  = 2 * math.Pi
	HalfPi = math.Pi / 2
)

Mathematical constants.

View Source
const DefaultRenderFlatten = 0.6

DefaultRenderFlatten is the standard curve flattening value.

View Source
const Sqrt3 = 1.7320508075688772935274463415058723669428052538103806280558069794519330169088

Sqrt3 is the square root of 3

Variables

View Source
var (
	BlackPen     = NewPen(g2dc.Black, 1)
	DarkGrayPen  = NewPen(g2dc.DarkGray, 1)
	GrayPen      = NewPen(g2dc.Gray, 1)
	LightGrayPen = NewPen(g2dc.LightGray, 1)
	WhitePen     = NewPen(g2dc.White, 1)
	RedPen       = NewPen(g2dc.Red, 1)
	GreenPen     = NewPen(g2dc.Green, 1)
	BluePen      = NewPen(g2dc.Blue, 1)
	YellowPen    = NewPen(g2dc.Yellow, 1)
	MagentaPen   = NewPen(g2dc.Magenta, 1)
	CyanPen      = NewPen(g2dc.Cyan, 1)
	OrangePen    = NewPen(g2dc.Orange, 1)
	BrownPen     = NewPen(g2dc.Brown, 1)
)

Predefined pens.

View Source
var RenderFlatten = DefaultRenderFlatten

RenderFlatten is the curve flattening value used when rendering.

View Source
var SafeFraction float64 = -1

SafeFraction if greater than 0 causes Simplify to perform a check of the mid-point against the part centroid. If the two are within SafeFraction of the distance from p[0] to the centroid then no further subdivision of the curve is performed.

Functions

func CPSafe

func CPSafe(part [][]float64) bool

CPSafe returns true if all the control points are on the same side of the line formed by start and the last part points and the point at t = 0.5 is close to the centroid of the part.

func CapButt

func CapButt(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapButt draws a line from e1 to s1.

func CapHead

func CapHead(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapHead draws an extended arrow head from e1 to extended p and then to s1.

func CapInvRound

func CapInvRound(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapInvRound extends e1 and s1 and draws a semicircle that passes through p.

func CapRound

func CapRound(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapRound draws a semicircle from e1 to s1 centered on p.

func CapSquare

func CapSquare(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapSquare draws an extended square (stroke width/2) from e1 and s1.

func CapTail

func CapTail(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapTail draws an extended arrow tail (stroke width/2) from extended e1 to p and then to extended s1.

func DrawArc

func DrawArc(dst draw.Image, start, center []float64, radians float64, pen *Pen)

DrawArc renders an arc with the pen into the destination image. radians +ve CCW, -ve CW

func DrawClippedShape

func DrawClippedShape(dst draw.Image, shape, clip *Shape, pen *Pen)

DrawClippedShape renders a shape with the pen against a clip shape into the destination image.

func DrawLine

func DrawLine(dst draw.Image, start, end []float64, pen *Pen)

DrawLine renders a line with the pen into the destination image.

func DrawPath

func DrawPath(dst draw.Image, path *Path, pen *Pen)

DrawPath renders a path with the pen into the destination image.

func DrawPoint

func DrawPoint(dst draw.Image, at []float64, pen *Pen)

DrawPoint renders a point with the pen into the destination image.

func DrawShape

func DrawShape(dst draw.Image, shape *Shape, pen *Pen)

DrawShape renders a shape with the pen into the destination image.

func FillClippedShape

func FillClippedShape(dst draw.Image, shape, clip *Shape, pen *Pen)

FillClippedShape renders a shape with the pen filler against a clipe shape and transform into the destination image.

func FillPath

func FillPath(dst draw.Image, path *Path, pen *Pen)

FillPath renders a path with the pen filler image and transform into the destination image.

func FillShape

func FillShape(dst draw.Image, shape *Shape, pen *Pen)

FillShape renders a shape with the pen filler and transform into the destination image.

func FlattenPart

func FlattenPart(d float64, part [][]float64) [][][]float64

FlattenPart works by subdividing the curve until its control points are within d^2 (d squared) of the line through the end points.

func I266ToF64

func I266ToF64(fi fixed.Int26_6) float64

I266ToF64 converts a fixed.Int26_6 to float64

func InvalidPoint

func InvalidPoint(p []float64) bool

InvalidPoint checks that both values are valid (i.e. not NaN)

func JoinBevel

func JoinBevel(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

JoinBevel creates a bevel join from e1 to s2.

func JoinRound

func JoinRound(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

JoinRound creates a round join from e1 to s2, centered on p.

func Lerp

func Lerp(t float64, p1, p2 []float64) []float64

Lerp performs a linear interpolation between two points.

func MakeArcParts

func MakeArcParts(cx, cy, r, offs, ang float64) [][][]float64

MakeArcParts creates at least one cubic bezier that describes a curve from offs to offs+ang centered on {cx, cy} with radius r.

func PartLength

func PartLength(d float64, part [][]float64) float64

PartLength returns the approximate length of a part by flattening it to the supplied degree of flatness.

func PartsIntersection

func PartsIntersection(part1, part2 [][]float64, d float64) []float64

PartsIntersection returns the location of where the two parts intersect or nil. Assumes the parts are the result of simplification. Uses a brute force approach for curves with d as the flattening value.

func PointCircle

func PointCircle(pt []float64, w float64) [][][]float64

PointCircle renders points as circles/

func PointDiamond

func PointDiamond(pt []float64, w float64) [][][]float64

PointDiamond renders points as diamonds aligned in x/y.

func PointSquare

func PointSquare(pt []float64, w float64) [][][]float64

PointSquare renders points as squares aligned in x/y.

func RenderClippedShape

func RenderClippedShape(dst draw.Image, shape, clip *Shape, filler image.Image)

RenderClippedShape renders the supplied shape with the fill image into the destination image as masked by the clip shape.

func RenderColoredShape

func RenderColoredShape(dst draw.Image, shape *Shape, fill color.Color)

RenderColoredShape renders the supplied shape with the fill color into the destination image.

func RenderShape

func RenderShape(dst draw.Image, shape *Shape, filler image.Image)

RenderShape renders the supplied shape with the fill image into the destination image.

func RenderShapeAlpha

func RenderShapeAlpha(shape *Shape) *image.Alpha

RenderShapeAlpha creates and returns the shape's alpha mask. The mask size and location are determined by the shape's bounds.

func RenderShapeExt

func RenderShapeExt(dst draw.Image, drect image.Rectangle, shape *Shape, filler image.Image, fp image.Point, clip *image.Alpha, cp image.Point, op draw.Op)

RenderShapeExt renders the supplied shape with the fill and clip images into the destination image region using op.

func ReverseParts

func ReverseParts(parts [][][]float64) [][][]float64

ReverseParts reverses the order (and points) of the supplied part slice.

func ReversePoints

func ReversePoints(cp [][]float64) [][]float64

[pts]x/y

func SimplifyExtremities

func SimplifyExtremities(part [][]float64) [][][]float64

SimplifyExtremities chops curve into pieces based on maxima, minima and inflections in x and y.

func SimplifyPart

func SimplifyPart(part [][]float64) [][][]float64

SimplifyPart recursively cuts the curve in half until CPSafe is satisfied.

func StringToShape

func StringToShape(tfont *sfnt.Font, str string) (*Shape, []*Shape, error)

StringToShape returns the string rendered as both a single shape, and as individual shapes, correctly offset. Glyphs with no paths are not returned (e.g. space etc.).

Types

type Aff3

type Aff3 [6]float64

Aff3 is a 3x3 affine transformation matrix in row major order, where the bottom row is implicitly [0 0 1].

m[3*r+c] is the element in the r'th row and c'th column.

func BoxTransform

func BoxTransform(x1, y1, x2, y2, h, x1p, y1p, x2p, y2p, hp float64) *Aff3

BoxTransform produces a transform that maps the line {p1, p2} to {p1', p2'} and scales the perpendicular by hp / h. Assumes neither of the lines nor h are degenerate.

func CreateTransform

func CreateTransform(x, y, scale, rotation float64) *Aff3

CreateTransform returns a transform that performs the requested translation, scaling and rotation based on {0, 0}.

func FlipY

func FlipY(height float64) *Aff3

FlipY is a convenience function to create a transform that has +ve Y point up rather than down.

func LineTransform

func LineTransform(x1, y1, x2, y2, x1p, y1p, x2p, y2p float64) *Aff3

LineTransform produces a transform that maps the line {p1, p2} to {p1', p2'}. Assumes neither of the lines are degenerate.

func NewAff3

func NewAff3() *Aff3

NewAff3 creates the identity transform.

func Reflect

func Reflect(x1, y1, x2, y2 float64) *Aff3

Reflect creates a reflection transform.

func Rotate

func Rotate(th float64) *Aff3

Rotate creates a rotation transform.

func RotateAbout

func RotateAbout(th, ax, ay float64) *Aff3

RotateAbout creates a rotation transform about a point.

func Scale

func Scale(sx, sy float64) *Aff3

Scale creates a scale transform.

func ScaleAbout

func ScaleAbout(sx, sy, ax, ay float64) *Aff3

ScaleAbout creates a scale transform about a point.

func ScaleAndInset

func ScaleAndInset(width, height, iwidth, iheight float64, fix bool, bb [][]float64) *Aff3

ScaleAndInset produces a transform that will scale and translate a set of points bounded by bb so they fit inside the inset box described by width, height, iwidth, iheight located at {0, 0}. If fix is true then the aspect ratio is maintained.

func Shear

func Shear(shx, shy float64) *Aff3

Shear creates a shear transform.

func ShearAbout

func ShearAbout(shx, shy, ax, ay float64) *Aff3

ShearAbout creates a shear transform about a point.

func Translate

func Translate(x, y float64) *Aff3

Translate creates a translation transform.

func (*Aff3) Apply

func (a *Aff3) Apply(pts ...[]float64) [][]float64

Apply implements the Transform interface.

func (*Aff3) Concatenate

func (a *Aff3) Concatenate(aff Aff3) *Aff3

Concatenate concatenates a transform to the transform.

func (*Aff3) Copy

func (a *Aff3) Copy() *Aff3

Copy returns a copy of the transform.

func (*Aff3) Determinant

func (a *Aff3) Determinant() float64

Determinant calculates the transform's matrix determinant.

func (*Aff3) Identity

func (a *Aff3) Identity() bool

Identity returns true if the transform is the identity.

func (*Aff3) InverseOf

func (a *Aff3) InverseOf() (*Aff3, error)

InverseOf returns the inverse of the transform.

func (*Aff3) Invert

func (a *Aff3) Invert() error

Invert inverts the transform.

func (*Aff3) PreConcatenate

func (a *Aff3) PreConcatenate(aff Aff3) *Aff3

PreConcatenate preconcatenates a transform to the transform.

func (*Aff3) QuadrantRotate

func (a *Aff3) QuadrantRotate(n int) *Aff3

QuadrantRotate adds a rotation (n * 90 degrees) to the transform. The rotation is about {0, 0}. It avoids rounding issues with the trig functions.

func (*Aff3) QuadrantRotateAbout

func (a *Aff3) QuadrantRotateAbout(n int, ax, ay float64) *Aff3

QuadrantRotateAbout adds a rotation (n * 90 degrees) about a point to the transform. It avoids rounding issues with the trig functions.

func (*Aff3) Reflect

func (a *Aff3) Reflect(x1, y1, x2, y2 float64) *Aff3

Reflect performs a reflection along the axis defined by the two non-coincident points.

func (*Aff3) Rotate

func (a *Aff3) Rotate(th float64) *Aff3

Rotate adds a rotation to the transform. The rotation is about {0, 0}.

func (*Aff3) RotateAbout

func (a *Aff3) RotateAbout(th, ax, ay float64) *Aff3

RotateAbout adds a rotation about a point to the transform.

func (*Aff3) Scale

func (a *Aff3) Scale(sx, sy float64) *Aff3

Scale adds a scaling to the transform centered on {0, 0}.

func (*Aff3) ScaleAbout

func (a *Aff3) ScaleAbout(sx, sy, ax, ay float64) *Aff3

ScaleAbout adds a scale about a point to the transform.

func (*Aff3) Shear

func (a *Aff3) Shear(shx, shy float64) *Aff3

Shear adds a shear to the transform centered on {0, 0}.

func (*Aff3) ShearAbout

func (a *Aff3) ShearAbout(shx, shy, ax, ay float64) *Aff3

ShearAbout adds a shear about a point to the transform.

func (*Aff3) String

func (a *Aff3) String() string

String converts the transform into a string.

func (*Aff3) Translate

func (a *Aff3) Translate(x, y float64) *Aff3

Translate adds a translation to the transform.

type ArcStyle

type ArcStyle int

ArcStyle defines the type of arc - open, chord (closed) and pie (closed).

const (
	ArcOpen ArcStyle = iota
	ArcChord
	ArcPie
)

Constants for arc styles.

type BoxerProc

type BoxerProc struct {
	Width float64 // Width of box
	Offs  float64 // Offset from path of box
	Flat  float64 // Flatten value
}

BoxerProc is a path processor that converts a path into a set of boxes along the path with the specified width. If the offset is 0 then the box is centered on the path.

func NewBoxerProc

func NewBoxerProc(width, offs float64) *BoxerProc

NewBoxerProc returns a new BoxerProc path processor.

func (*BoxerProc) Process

func (bp *BoxerProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type CapsProc

type CapsProc struct {
	Start  *Shape
	End    *Shape
	Mid    *Shape
	Rotate bool
}

CapsProc contains a trio of shapes, one which will be placed using the start at the path, one at each step and the last, at the end. If either shape is nil, then it is skipped. The rotation flag indicates if the shapes should be rotated relative to the path's tangent at that point.

func (*CapsProc) Process

func (cp *CapsProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type CompoundProc

type CompoundProc struct {
	Procs       []PathProcessor
	Concatenate bool // If set, concatenate processed paths into a single path after every processor
}

CompoundProc applies a collection of PathProcessors to a path.

func NewCompoundProc

func NewCompoundProc(procs ...PathProcessor) *CompoundProc

NewCompoundProc creates a new CompoundProcessor with the supplied path processors.

func (*CompoundProc) Process

func (cp *CompoundProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type CurveProc

type CurveProc struct {
	Scale float64
	Style CurveStyle
}

CurveProc replaces the steps on a path with cubics. The locations of the control points are controlled by the Style setting and whether or not the path is closed.

func (*CurveProc) Process

func (cp *CurveProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type CurveStyle

type CurveStyle int

CurveStyle determines how the curve behaves relative to the path points. With Bezier, the path will intersect the mid-point of each path step. With Catmul, the path will intersect point.

const (
	Bezier CurveStyle = iota
	Quad
	CatmullRom
)

Constants for curve styles.

type CurvesToLinesProc

type CurvesToLinesProc struct {
	SkipCP bool
}

CurvesToLinesProc takes a path and converts all of the points to lines.

func (*CurvesToLinesProc) Process

func (clp *CurvesToLinesProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type DashProc

type DashProc struct {
	Snip *FSnipProc
}

DashProc contains the dash pattern and offset. The dash pattern represents lengths of pen down, pen up, ... and is in the same coordinate system as the path. The offset provides the ability to start from anywhere in the pattern.

func NewDashProc

func NewDashProc(pattern []float64, offs float64) *DashProc

NewDashProc creates a new dash path processor with the supplied pattern and offset. If the pattern is odd in length then it is replicated to create an even length pattern.

func (*DashProc) Process

func (d *DashProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type FSnipProc

type FSnipProc struct {
	N       int
	Pattern []float64
	Flatten float64
	State   int
	// contains filtered or unexported fields
}

FSnipProc contains the snip pattern and offset. The snip pattern represents lengths of state0, state1, ... stateN-1, and is in the same coordinate system as the path. The offset provides the ability to start from anywhere in the pattern.

func NewFSnipProc

func NewFSnipProc(n int, pattern []float64, offs float64) *FSnipProc

NewFSnipProc creates a new snip path processor with the supplied pattern and offset. If the pattern is not N in length then it is replicated to create a mod N length pattern.

func (*FSnipProc) Offset

func (sp *FSnipProc) Offset(offs float64)

Offset determines where in the pattern the path processor will start.

func (*FSnipProc) Process

func (sp *FSnipProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type FlattenProc

type FlattenProc struct {
	Flatten float64
}

FlattenProc is a wrapper around Path.Flatten() and contains the minimum required distance to the control points.

func (*FlattenProc) Process

func (fp *FlattenProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type HandDrawnProc

type HandDrawnProc struct {
	Comp *CompoundProc
}

HandDrawnProc contains the compound path processor used to create a hand drawn look.

func NewHandDrawnProc

func NewHandDrawnProc(l float64) *HandDrawnProc

NewHandDrawnProc takes the segment length to apply the MPD path processor to and returns a new HandDrawnProc path processor.

func (*HandDrawnProc) Process

func (h *HandDrawnProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type JitterProc

type JitterProc struct {
	Perc float64 // Percentage
}

JitterProc contains the percentage degree to which segment endpoints will be moved to their left or right (relative to their tangents) based on their length. Can be used with MunchProc to get a hand drawn look.

func (*JitterProc) Process

func (j *JitterProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type LineProc

type LineProc struct{}

LineProc replaces a path with a single line.

func (*LineProc) Process

func (lp *LineProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type LinesProc

type LinesProc struct {
	IncludeCP bool
}

LinesProc replaces a path step with a line.

func (*LinesProc) Process

func (lp *LinesProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type MPDProc

type MPDProc struct {
	Perc  float64 // Percentage of step length used as initial displacement
	Itrs  int     // Number of iterations to perform
	Scale float64 // Multiplier (Hurst) used on displacement per iteration
	Rel   bool    // if set, normal is the relative one and not the original
}

MPDProc contains the variables that control the degree to which a step is chopped up into smaller line segments. Unlike JitterProc, the step end points don't vary. Can be used with MunchProc to get a hand drawn look.

func NewMPDProc

func NewMPDProc(l float64) *MPDProc

NewMPDProc creates an MPDProc with sensible parameters for iterations and Hurst.

func (*MPDProc) MPD

func (m *MPDProc) MPD(a, b []float64) [][]float64

MPD takes two points and adds points between them using the mid-point displacement algorithm driven by the parameters stored in the MPDProc structure.

func (*MPDProc) Process

func (m *MPDProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type MiterJoin

type MiterJoin struct {
	MiterLimit   float64
	MiterAltFunc func([][]float64, []float64, [][]float64) [][][]float64
}

MiterJoin describes the limit and alternative function to use when the limit is exceeded for a miter join.

func NewMiterJoin

func NewMiterJoin() *MiterJoin

NewMiterJoin creates a default MiterJoin with the limit set to 10 degrees and the alternative function to JoinBevel.

func (*MiterJoin) JoinMiter

func (mj *MiterJoin) JoinMiter(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

JoinMiter creates a miter join from e1 to s2 unless the moter limit is exceeded in which case the alternative function is used to perform the join.

type MunchProc

type MunchProc struct {
	Comp *CompoundProc
}

MunchProc contains the munching compound path processor.

func NewMunchProc

func NewMunchProc(l float64) *MunchProc

NewMunchProc creates a munching path processor. It calculates points along a path spaced l apart and creates new paths that join the points with lines.

func (*MunchProc) Process

func (mp *MunchProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type OpenProc

type OpenProc struct{}

OpenProc replaces a path with its open version.

func (*OpenProc) Process

func (op *OpenProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type OvalCap

type OvalCap struct {
	Rxy  float64 // Ratio of Rx to Ry
	Offs float64 // Offset from center line [-1,1] -1 = LHS, 0 = centerline, 1 = RHS
}

OvalCap contains the ratio of rx to ry for the oval and a center line offset

func (*OvalCap) CapInvOval

func (oc *OvalCap) CapInvOval(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapInvOval creates an inverted half oval with rx = w/2 and ry = rxy * rx Offs is ignored

func (*OvalCap) CapOval

func (oc *OvalCap) CapOval(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapOval creates a half oval with ry = w/2 and rx = Rxy * ry

type Path

type Path struct {
	// contains filtered or unexported fields
}

Path contains the housekeeping necessary for path building.

func Arc

func Arc(c []float64, r, offs, ang float64, s ArcStyle) *Path

Arc returns a path with an arc centered on c with radius r from offs in the direction and length of ang.

func ArcFromPoint

func ArcFromPoint(pt, c []float64, ang float64, s ArcStyle) *Path

ArcFromPoint returns a path describing an arc starting from pt based on c and ang.

func ArcFromPoints

func ArcFromPoints(a, b, c []float64, s ArcStyle) *Path

ArcFromPoints returns a path describing an arc passing through a, b and c such that the arc starts at a, passes through b and ends at c.

func Circle

func Circle(c []float64, r float64) *Path

Circle returns a closed path describing a circle centered on c with radius r.

func ConcatenatePaths

func ConcatenatePaths(paths ...*Path) (*Path, error)

ConcatenatePaths concatenates all the paths into a new path. If any path is closed then an error is returned. If the paths aren't coincident, then they are joined with a line.

func Curve

func Curve(pts ...[]float64) *Path

Curve returns a path describing the polynomial curve.

func Egg

func Egg(c []float64, w, h, d, xang float64) *Path

Egg uses IrregularEllipse to generate an egg shape with the specified width and height. The waist is specified as a percentage distance along the height axis (from the base). The egg is rotated by xang.

func Ellipse

func Ellipse(c []float64, rx, ry, xang float64) *Path

Ellipse returns a closed path describing an ellipse with rx and ry rotated by xang from the x axis.

func EllipseFromPoints

func EllipseFromPoints(p1, p2, c []float64) *Path

EllipseFromPoints returns a path describing the smallest ellipse containing points p1 and p2. If p1, p2 and c are colinear and not equidistant then nil is returned.

func EllipticalArc

func EllipticalArc(c []float64, rx, ry, offs, ang, xang float64, s ArcStyle) *Path

EllipticalArc returns a path describing an arc starting at offs and ending at offs+ang on the ellipse defined by rx and ry rotated by xang from the x axis.

func EllipticalArcFromPoint

func EllipticalArcFromPoint(pt, c []float64, rxy, ang, xang float64, s ArcStyle) *Path

EllipticalArcFromPoint returns a path describing an ellipse arc from a point. The ratio of rx to ry is specified by rxy.

func EllipticalArcFromPoints

func EllipticalArcFromPoints(p1, p2, c []float64, s ArcStyle) *Path

EllipticalArcFromPoints returns a path describing the smallest ellipse arc from a point p1 to p2 (ccw). If p1, p2 and c are colinear and not equidistant then nil is returned.

func EllipticalArcFromPoints2

func EllipticalArcFromPoints2(p1, p2 []float64, rx, ry, xang float64, arc, swp bool, s ArcStyle) *Path

EllipticalArcFromPoints2 provides a specification similar to that found in the SVG11 standard where the center is calculated from the given rx and ry values and flag specifications. See https://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes

func Equilateral

func Equilateral(c []float64, s float64) *Path

Equilateral returns a closed path describing an equliateral triangle with side s, centered on c.

func ExtendLine

func ExtendLine(pt1, pt2 []float64, bounds [][]float64) *Path

ExtendLine returns the line that passes through the bounds (or nil) defined by the line equation of pt1 and pt2.

func IrregularEllipse

func IrregularEllipse(c []float64, rx1, rx2, ry1, ry2, disp, xang float64) *Path

IrregularEllipse uses different rx and ry values for each quadrant of an ellipse. disp (-1,1) determines how far along either rx1 (+ve) or rx2 (-ve), ry2 extends from (ry1 extends from c).

func IrregularPolygon

func IrregularPolygon(cp []float64, r float64, n int, nr bool) *Path

IrregularPolygon returns an n sided polgon guaranteed to be located within a circle of radius r centered on cp. If nr is set to true then polygon is forced to be non-reentrant.

func Line

func Line(pt1, pt2 []float64) *Path

Line returns a path describing the line.

func Lune

func Lune(c []float64, r0, r1, r2, th float64) *Path

Lune returns a closed path made up of two arcs with end points at c plus/minus r0 in y, all rotated by th. The arcs are calculated from the circumcircles of the two triangles defined by the end points, and c displaced by r1 or r2 in x.

func Nellipse

func Nellipse(l float64, foci ...[]float64) *Path

Nellipse takes a slice of ordered foci, assumed to be on the hull of a convex polygon, and a length, and uses them to construct a Gardener's ellipse (an approximation that ignores foci within the hull). The closed path will be made up of twice as many arcs as there are foci. If the length isn't sufficient to wrap the foci, then nil is returned.

func NewPath

func NewPath(start []float64) *Path

NewPath creates a new path starting at start.

func PartsToPath

func PartsToPath(parts ...[][]float64) *Path

PartsToPath constructs a new path by concatenating the parts.

func Point

func Point(pt []float64) *Path

Point returns a path containing the point.

func PolyArcFromPoint

func PolyArcFromPoint(pt []float64, cs [][]float64, angs []float64) *Path

PolyArcFromPoint returns a path concatenating the arcs.

func PolyCurve

func PolyCurve(pts ...[][]float64) *Path

PolyCurve returns a path describing the polynomial curves.

func PolyLine

func PolyLine(pts ...[]float64) *Path

PolyLine returns a path with lines joining successive points.

func Polygon

func Polygon(pts ...[]float64) *Path

Polygon returns a closed path with lines joining successive points.

func Rectangle

func Rectangle(c []float64, w, h float64) *Path

Rectangle returns a closed path describing a rectangle with sides w and h, centered on c.

func ReentrantPolygon

func ReentrantPolygon(c []float64, r float64, n int, t, ang float64) *Path

ReentrantPolygon returns a closed path describing an n pointed star.

func RegularPolygon

func RegularPolygon(pt1, pt2 []float64, n int) *Path

RegularPolygon returns a closed path describing an n-sided polygon given the initial edge.

func RightEgg

func RightEgg(c []float64, h, d, xang float64) *Path

RightEgg uses IrregularEllipse to generate an egg shape with the specified height and a semicircular base. The waist is specified as a percentage distance along the height axis (from the base). The egg is rotated by xang.

func Square

func Square(c []float64, s float64) *Path

Square returns a closed path describing a square with side s, centered on c.

func StringToPath

func StringToPath(str string) *Path

StringToPath converts a string created using path.String() back into a path. Returns nil if the string isn't parsable into a path.

func (*Path) AddStep

func (p *Path) AddStep(points ...[]float64) error

AddStep takes an array of points and treats n-1 of them as control points and the last as a point on the curve.

func (*Path) AddSteps

func (p *Path) AddSteps(steps ...[][]float64) error

AddSteps adds multiple steps to the path.

func (*Path) BoundingBox

func (p *Path) BoundingBox() [][]float64

BoundingBox calculates a bounding box that the Path is guaranteed to fit within. It's unlikely to be the minimal bounding box for the path since the control points are also included. If a tight bounding box is required then use CalcExtremities().

func (*Path) Bounds

func (p *Path) Bounds() image.Rectangle

Bounds calculates a rectangle that the Path is guaranteed to fit within. It's unlikely to be the minimal bounding rectangle for the path since the control points are also included. If a tight bounding rectangle is required then use CalcExtremities().

func (*Path) Close

func (p *Path) Close()

Close marks the path as closed.

func (*Path) Closed

func (p *Path) Closed() bool

Closed returns true if the path is closed.

func (*Path) Concatenate

func (p *Path) Concatenate(paths ...*Path) error

Concatenate adds the paths to this path. If any path is closed then an error is returned. If the paths aren't coincident, then they are joined with a line.

func (*Path) Copy

func (p *Path) Copy() *Path

Copy performs a deepish copy - points themselves aren't duplicated.

func (*Path) Flatten

func (p *Path) Flatten(d float64) *Path

Flatten works by recursively subdividing the path until the control points are within d of the line through the end points.

func (*Path) Length

func (p *Path) Length(flat float64) float64

Length returns the approximate length of a path by flattening it to the desired degree and summing the line steps.

func (*Path) Line

func (p *Path) Line() *Path

Line reduces a path to a line between its endpoints. For a closed path or one where the start and endpoints are coincident, a single point is returned.

func (*Path) Lines

func (p *Path) Lines(inccp bool) *Path

Lines reduces a path to a line for every step. If inccp is set then the control points are included.

func (*Path) MarshalJSON

func (p *Path) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding.json.Marshaler interface

func (*Path) Open

func (p *Path) Open() *Path

Open performs a deepish copy like Copy() but leaves the path open.

func (*Path) Parent

func (p *Path) Parent() *Path

Parent returns the path's parent

func (*Path) Parts

func (p *Path) Parts() [][][]float64

Parts returns the steps of a path, each prepended with its start.

func (*Path) PointInPath

func (p *Path) PointInPath(pt []float64) bool

PointInPath returns if a point is contained within a closed path according to the setting of util.WindingRule. If the path is not closed then false is returned, regardless.

func (*Path) Poly

func (p *Path) Poly() [][]float64

Poly converts a path into a flat sided polygon. Returns an empty slice if the path isn't closed.

func (*Path) Process

func (p *Path) Process(proc PathProcessor) []*Path

Process applies a processor to a path.

func (*Path) ProjectPoint

func (p *Path) ProjectPoint(pt []float64) ([]float64, float64, float64)

ProjectPoint returns the point, it's t on the path closest to pt and the distance^2. Note t can be very non-linear.

func (*Path) Reverse

func (p *Path) Reverse() *Path

Reverse returns a new path describing the current path in reverse order (i.e start and end switched).

func (*Path) Simplify

func (p *Path) Simplify() *Path

Simplify breaks up a path into steps where for any step, its control points are all on the same side and its midpoint is well behaved. If a step doesn't meet the criteria, it is recursively subdivided in half until it does.

func (*Path) Steps

func (p *Path) Steps() [][][]float64

Steps returns a shallow copy of all the steps in the path.

func (*Path) String

func (p *Path) String() string

String converts a path into a string. P %f,%f [S %d [%f,%f ]] [C]

func (*Path) Tangents

func (p *Path) Tangents() [][][]float64

Tangents returns the normalized start and end tangents of every part in the path. [part]start/end[normalized x/y]

func (*Path) Transform

func (p *Path) Transform(xfm Transform) *Path

Transform applies an affine transform to the points in a path to create a new one.

func (*Path) UnmarshalJSON

func (p *Path) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the encoding.json.Unmarshaler interface

type PathProcessor

type PathProcessor interface {
	Process(p *Path) []*Path
}

PathProcessor defines the interface required for function passed to the Process function in Path.

type PathSnipProc

type PathSnipProc struct {
	Flatten float64
	Path    *Path
}

PathSnipProc contains the snip path.

func NewPathSnipProc

func NewPathSnipProc(path *Path) *PathSnipProc

NewPathSnipProc creates a new path snip path processor with the supplied path.

func (*PathSnipProc) Process

func (psp *PathSnipProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type Pen

type Pen struct {
	Filler image.Image
	Stroke PathProcessor
	Xfm    *Aff3
}

Pen describes the color/image, stroke and shape to image transform to use when rendering shapes. If Stroke is nil then the shape's paths are used as is and forced closed (i.e. this is a fill). If Xfm is nil then the identity xfm is assumed.

func NewColoredPens

func NewColoredPens(colors []color.Color, width float64) []*Pen

NewColoredPens constructs a slice of n pens with the given colors and width.

func NewFilledPen

func NewFilledPen(grad image.Image, width float64) *Pen

NewFilledPen returns a pen that will render a shape with the given pen width and a random hued color into an image.

func NewNamedPen

func NewNamedPen(name string, width float64) *Pen

NewNamedPen returns a pen that will render a shape with the given width and named color into an image. If the name is not matched then a black pen will be returned.

func NewPen

func NewPen(color color.Color, width float64) *Pen

NewPen returns a pen that will render a shape with the given pen width and color into an image.

func NewPens

func NewPens(color color.Color, n int, width, winc float64) []*Pen

NewPens constructs a slice of n pens with the given color starting at width and increasing by winc.

func NewProcessorPen

func NewProcessorPen(color color.Color, width float64, proc PathProcessor) *Pen

NewProcessorPen returns a pen that will render a shape with the given pen width and color into an image after applying the supplied path processor.

func NewRandomHuePen

func NewRandomHuePen(width float64) *Pen

NewRandomHuePen returns a pen that will render a shape with the given pen width and a random hued color into an image.

func NewRandomPen

func NewRandomPen(width float64) *Pen

NewRandomPen returns a pen that will render a shape with the given pen width and a random color into an image.

func (*Pen) ChangeWidth

func (p *Pen) ChangeWidth(width float64) *Pen

ChangeWidth returns a new pen the width while preserving the other aspects of the pen's stroke. Note this only works for pens with a StrokeProc path processor.

func (*Pen) ScaleWidth

func (p *Pen) ScaleWidth(scale float64) *Pen

ScaleWidth returns a new pen the scaled width while preserving the other aspects of the pen's stroke. Note this only works for pens with a StrokeProc path processor.

func (*Pen) Width

func (p *Pen) Width() float64

Width returns the width of this pen. Note this only works for pens with a StrokeProc path processor.

type PointRot

type PointRot int

PointRot specifies the type of shape rotation

const (
	// RotFixed no rotation
	RotFixed PointRot = iota
	// RotRelative rotation relative to the tangent of the path step
	RotRelative
	// RotRandom rotation is randomized
	RotRandom
)

type PointsProc

type PointsProc struct {
	Points []*Shape
	Rotate PointRot
}

PointsProc contains a slice of shapes, one of which will be placed at the start of each step in the path and at the path end, if not closed. If any shape is nil, then it is skipped. The rotation flag indicates if the shapes should be rotated relative to the path's tangent at that point.

func NewPointsProc

func NewPointsProc(shapes []*Shape, rot PointRot) *PointsProc

NewPointsProc creates a new points path processor with the supplied shapes and rotation flag.

func (*PointsProc) Process

func (pp *PointsProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type RSCap

type RSCap struct {
	Perc float64
}

RSCap contains the percentage [0,1] of the corner taken up by an arc. Perc = 1 is equivalent to CapRound Perc = 0, to CapSquare.

func (*RSCap) CapRoundedSquare

func (rc *RSCap) CapRoundedSquare(p1 [][]float64, p []float64, p2 [][]float64) [][][]float64

CapRoundedSquare creates a square cap with rounded corners

type Renderable

type Renderable struct {
	Shapes  []*Shape
	Clips   []*Shape
	Fillers []image.Image
}

Renderable represents a set of shapes and the images to fill them. In other words, enough information to be able to render something. This structure is used to build complex multicolored objects in a composable way.

func NewRenderable

func NewRenderable(shape *Shape, filler image.Image, xfm *Aff3) *Renderable

NewRenderable creates a new instance with the given shape and filler image.

func (*Renderable) AddClippedColoredShape

func (r *Renderable) AddClippedColoredShape(shape, clip *Shape, col color.Color, xfm *Aff3) *Renderable

AddClippedColoredShape adds the given shape, clip and color to the Renderable after being transformed.

func (*Renderable) AddClippedPennedShape

func (r *Renderable) AddClippedPennedShape(shape, clip *Shape, pen *Pen, xfm *Aff3) *Renderable

AddClippedPennedShape adds the given shape, clip and pen to the Renderable after being transformed.

func (*Renderable) AddClippedShape

func (r *Renderable) AddClippedShape(shape, clip *Shape, filler image.Image, xfm *Aff3) *Renderable

AddClippedShape adds the given shape, clip and filler to the Renderable after being transformed.

func (*Renderable) AddColoredShape

func (r *Renderable) AddColoredShape(shape *Shape, col color.Color, xfm *Aff3) *Renderable

AddColoredShape adds the given shape and color to the Renderable after being transformed.

func (*Renderable) AddPennedShape

func (r *Renderable) AddPennedShape(shape *Shape, pen *Pen, xfm *Aff3) *Renderable

AddPennedShape adds the given shape and pen to the Renderable after being transformed.

func (*Renderable) AddRenderable

func (r *Renderable) AddRenderable(rend *Renderable, xfm *Aff3) *Renderable

AddRenderable allows another renderable to be concatenated (post transform) to the current one.

func (*Renderable) AddShape

func (r *Renderable) AddShape(shape *Shape, filler image.Image, xfm *Aff3) *Renderable

AddShape adds the given shape and filler to the Renderable after being transformed.

func (*Renderable) Bounds

func (r *Renderable) Bounds() image.Rectangle

Bounds returns the extent of the renderable.

func (*Renderable) Image

func (r *Renderable) Image() *image.RGBA

Image renders the shapes in the renderable with their respective fillers.

func (*Renderable) Render

func (r *Renderable) Render(img draw.Image, xfm *Aff3)

Render renders the shapes in the renderable with their respective fillers after being transformed.

type ReverseProc

type ReverseProc struct{}

ReverseProc replaces a path with its reverse.

func (*ReverseProc) Process

func (rp *ReverseProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type RoundedEdgeProc

type RoundedEdgeProc struct {
	Dist float64
	Abs  bool
	Elip bool
}

RoundedEdgeProc is a path processor that replaces the parts of a path with an arc defined by the end points of the path and a third point normal to the part midpoint at either an absolute or relative (to the part length) distance from the midpoint. If Elip is set, then an elliptical arc of ry = d, rx = edge length / 2 is used instead.

func (*RoundedEdgeProc) Process

func (rp *RoundedEdgeProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type RoundedProc

type RoundedProc struct {
	Radius float64
}

RoundedProc replaces adjacent line segments in a path with line-arc-line where the radius of the arc is the minimum of Radius or the maximum allowable for the length of the shorter line segment. This ensures that the rounded corner doesn't end beyond the mid point of either line.

func (*RoundedProc) Process

func (rp *RoundedProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type Shape

type Shape struct {
	// contains filtered or unexported fields
}

Shape is a fillable collection of paths. For a path to be fillable, it must be closed, so paths added to the shape are forced closed on rendering.

func GlyphIndexToShape

func GlyphIndexToShape(font *sfnt.Font, x sfnt.GlyphIndex) (*Shape, error)

GlyphIndexToShape returns a shape containing the paths for glyph index x as found in the font. The path is in font units. Use font.UnitsPerEm() to calculate scale factors.

func GlyphToShape

func GlyphToShape(font *sfnt.Font, r rune) (*Shape, error)

GlyphToShape returns a shape containing the paths for rune r as found in the font. The path is in font units. Use font.UnitsPerEm() to calculate scale factors.

func NewShape

func NewShape(paths ...*Path) *Shape

NewShape constructs a shape from the supplied paths.

func (*Shape) AddPaths

func (s *Shape) AddPaths(paths ...*Path)

AddPaths adds paths to the shape.

func (*Shape) AddShapes

func (s *Shape) AddShapes(shapes ...*Shape)

AddShapes adds the paths from the supplied shapes to this shape.

func (*Shape) BoundingBox

func (s *Shape) BoundingBox() [][]float64

BoundingBox calculates a bounding box that the Shape is guaranteed to fit within.

func (*Shape) Bounds

func (s *Shape) Bounds() image.Rectangle

Bounds calculates the union of the bounds of the paths the shape contains.

func (*Shape) Contains

func (s *Shape) Contains(pts ...[]float64) bool

Contains returns true if the points are contained within the shape, false otherwise.

func (*Shape) Copy

func (s *Shape) Copy() *Shape

Copy creates a new instance of this shape with a shallow copy of its paths.

func (*Shape) MarshalJSON

func (s *Shape) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding.json.Marshaler interface

func (*Shape) Mask

func (s *Shape) Mask() *image.Alpha

Mask returns an Alpha image defined by the shape's bounds, containing the result of rendering the shape.

func (*Shape) Paths

func (s *Shape) Paths() []*Path

Paths returns a shallow copy of the paths contained by this shape.

func (*Shape) PointInShape

func (s *Shape) PointInShape(pt []float64) bool

PointInShape returns true if the point is contained within any path within the shape.

func (*Shape) Process

func (s *Shape) Process(proc ShapeProcessor) []*Shape

Process applies a shape processor to the shape and returns a collection of new shapes.

func (*Shape) ProcessPaths

func (s *Shape) ProcessPaths(proc PathProcessor) *Shape

ProcessPaths applies a path processor to the shape and returns a new shape containing the processed paths.

func (*Shape) String

func (s *Shape) String() string

String converts a shape into a string.

func (*Shape) Transform

func (s *Shape) Transform(xfm Transform) *Shape

Transform applies an affine transform to all the paths in the shape and returns a new shape.

func (*Shape) UnmarshalJSON

func (s *Shape) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the encoding.json.Unmarshaler interface

type ShapeProc

type ShapeProc struct{}

ShapeProc creates a new shape for every path in the shape.

func (*ShapeProc) Process

func (sp *ShapeProc) Process(s *Shape) []*Shape

Process implements the ShapeProcessor interface.

type ShapeProcessor

type ShapeProcessor interface {
	Process(s *Shape) []*Shape
}

ShapeProcessor defines the interface required for function passed to the Process function in Shape.

type ShapesProc

type ShapesProc struct {
	Comp   *CompoundProc
	Shapes *PointsProc
}

ShapesProc contains a slice of shapes, which will be placed sequentially along the path, starting at the beginning and spaced there after by the spacing value, and at the path end, if not closed. If any shape is nil, then it is skipped. The rotation flag indicates if the shapes should be rotated relative to the path's tangent at that point.

func NewShapesProc

func NewShapesProc(shapes []*Shape, spacing float64, rot PointRot) *ShapesProc

NewShapesProc creates a new shapes path processor with the supplied shapes, spacing and rotation flag.

func (*ShapesProc) Process

func (sp *ShapesProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type SimpleStrokeProc

type SimpleStrokeProc struct {
	Width float64
}

SimpleStrokeProc implements the simplest stroke path processor - flatten everything to RenderFlatten tolerance and turn each flattened line step into a rectangle Width wide. No joins or caps, just lots of little rectangles.

func (*SimpleStrokeProc) Process

func (cp *SimpleStrokeProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type SimplifyProc

type SimplifyProc struct{}

SimplifyProc is a wrpper around Path.Simplify().

func (*SimplifyProc) Process

func (sp *SimplifyProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type SnipProc

type SnipProc struct {
	N       int
	Pattern []float64
	Flatten float64
	State   int
	// contains filtered or unexported fields
}

SnipProc contains the snip pattern and offset. The snip pattern represents lengths of state0, state1, ... stateN-1, and is in the same coordinate system as the path. The offset provides the ability to start from anywhere in the pattern.

func NewSnipProc

func NewSnipProc(n int, pattern []float64, offs float64) *SnipProc

NewSnipProc creates a new snip path processor with the supplied pattern and offset. If the pattern is not N in length then it is replicated to create a mod N length pattern.

func (*SnipProc) Offset

func (sp *SnipProc) Offset(offs float64)

Offset determines where in the pattern the path processor will start.

func (*SnipProc) Process

func (sp *SnipProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type SplitProc

type SplitProc struct{}

SplitProc breaks up a path into a collection of paths, one for each step in the original path.

func (*SplitProc) Process

func (sp *SplitProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type SquareWaveProc

type SquareWaveProc struct {
	HalfLambda float64 // Half wave length
	Scale      float64 // Ratio of amplitude to lambda
	KeepZero   bool    // Keeps internal zero-point crossings if set
	Flip       bool    // Flips the wave phase by 180 (pi) if set
}

SquareWaveProc applies a square wave along a path with a defined wave length and amplitude. The wave starts and ends on zero-crossing points and the last half wave is truncated to the path length remaining. The internal zero-crossing points can be optionally preserved.

func NewSquareWaveProc

func NewSquareWaveProc(lambda, amplitude float64) *SquareWaveProc

NewSquareWaveProc creates a new SquareWaveProc with the supplied wave length and amplitude.

func (*SquareWaveProc) Process

func (sp *SquareWaveProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type StepsProc

type StepsProc struct{}

StepsProc converts each path step into its own path.

func (*StepsProc) Process

func (sp *StepsProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type StrokeProc

type StrokeProc struct {
	RTraceProc    *TraceProc
	LTraceProc    *TraceProc
	PostTraceProc PathProcessor
	// (pt, r) []part
	PointFunc func([]float64, float64) [][][]float64
	// (part1, pt, part2) []part
	CapStartFunc func([][]float64, []float64, [][]float64) [][][]float64
	CapEndFunc   func([][]float64, []float64, [][]float64) [][][]float64
}

StrokeProc defines the width, join and cap types of the stroke.

func NewStrokeProc

func NewStrokeProc(w float64) *StrokeProc

NewStrokeProc creates a stroke path processor with width w, the bevel join and butt cap types.

func NewStrokeProcExt

func NewStrokeProcExt(rw, lw float64,
	jf func([][]float64, []float64, [][]float64) [][][]float64,
	d float64,
	cf func([][]float64, []float64, [][]float64) [][][]float64) *StrokeProc

NewStrokeProcExt creates a stroke path processor where the widths are specified separately for each side of the stroke. This allows the stroke to be offset to the left or right of the path being processed.

func (*StrokeProc) Process

func (sp *StrokeProc) Process(p *Path) []*Path

Process implements the PathProcessor interface and will return either one or two paths depending on whether the path is open or closed.

type TraceProc

type TraceProc struct {
	Width    float64
	Flatten  float64
	JoinFunc func([][]float64, []float64, [][]float64) [][][]float64
}

TraceProc defines the width and join types of the trace. The gap between two adjacent steps must be greater than MinGap for the join function to be called.

func NewTraceProc

func NewTraceProc(w float64) *TraceProc

NewTraceProc creates a trace path processor with width w, the bevel join and butt cap types.

func (*TraceProc) Process

func (tp *TraceProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

func (*TraceProc) ProcessParts

func (tp *TraceProc) ProcessParts(p *Path) [][][]float64

ProcessParts returns the processed path as a slice of parts, rather a path so other path processors don't have to round trip path -> parts -> path -> parts (e.g. StrokeProc).

type Transform

type Transform interface {
	Apply(points ...[]float64) [][]float64
}

Transform interface provides the Apply function to transform a set of points.

type TransformProc

type TransformProc struct {
	Transform *Aff3
}

TransformProc is a wrapper around Path.Transform() and contains the Aff3 transform to be applied.

func (*TransformProc) Process

func (tp *TransformProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

type TriangleWaveProc

type TriangleWaveProc struct {
	HalfLambda float64 // Half wave length
	Scale      float64 // Ratio of amplitude to lambda
	KeepZero   bool    // Keeps internal zero-point crossings if set
	Flip       bool    // Flips the wave phase by 180 (pi) if set
}

TriangleWaveProc applies a triangle wave along a path with a defined wave length and amplitude. The wave starts and ends on zero-crossing points and the last half wave is truncated to the path length remaining. The internal zero-crossing points can be optionally preserved.

func NewTriangleWaveProc

func NewTriangleWaveProc(lambda, amplitude float64) *TriangleWaveProc

NewTriangleWaveProc creates a new TriangleWaveProc with the supplied wave length and amplitutde.

func (*TriangleWaveProc) Process

func (tp *TriangleWaveProc) Process(p *Path) []*Path

Process implements the PathProcessor interface.

Directories

Path Synopsis
Package color contains types and functions for color management.
Package color contains types and functions for color management.
Package image contains functions that mostly operate on image.Gray.
Package image contains functions that mostly operate on image.Gray.
texture
Package texture contains functions that populate images with texture.
Package texture contains functions that populate images with texture.
Package util contains functions for linear and non-linear interpolations and their inversions.
Package util contains functions for linear and non-linear interpolations and their inversions.

Jump to

Keyboard shortcuts

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