vector

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 767

Documentation

Overview

Package vector provides functions for vector graphics rendering.

This package is under experiments and the API might be changed with breaking backward compatibility.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawFilledCircle deprecated added in v2.5.0

func DrawFilledCircle(dst *ebiten.Image, cx, cy, r float32, clr color.Color, antialias bool)

DrawFilledCircle fills a circle with the specified center position (cx, cy), the radius (r) and color.

Deprecated: as of v2.9. Use FillCircle instead.

func DrawFilledRect deprecated added in v2.5.0

func DrawFilledRect(dst *ebiten.Image, x, y, width, height float32, clr color.Color, antialias bool)

DrawFilledRect fills a rectangle with the specified width and color.

Deprecated: as of v2.9. Use FillRect instead.

func FillCircle added in v2.9.0

func FillCircle(dst *ebiten.Image, cx, cy, r float32, clr color.Color, antialias bool)

FillCircle fills a circle with the specified center position (cx, cy), the radius (r) and color.

func FillPath added in v2.9.0

func FillPath(dst *ebiten.Image, path *Path, fillOptions *FillOptions, drawPathOptions *DrawPathOptions)

FillPath fills the specified path with the specified options.

func FillRect added in v2.9.0

func FillRect(dst *ebiten.Image, x, y, width, height float32, clr color.Color, antialias bool)

FillRect fills a rectangle with the specified width and color.

func StrokeCircle added in v2.5.0

func StrokeCircle(dst *ebiten.Image, cx, cy, r float32, strokeWidth float32, clr color.Color, antialias bool)

StrokeCircle strokes a circle with the specified center position (cx, cy), the radius (r), width and color.

func StrokeLine added in v2.5.0

func StrokeLine(dst *ebiten.Image, x0, y0, x1, y1 float32, strokeWidth float32, clr color.Color, antialias bool)

StrokeLine strokes a line (x0, y0)-(x1, y1) with the specified width and color.

func StrokePath added in v2.9.0

func StrokePath(dst *ebiten.Image, path *Path, strokeOptions *StrokeOptions, drawPathOptions *DrawPathOptions)

StrokePath strokes the specified path with the specified options.

func StrokeRect added in v2.5.0

func StrokeRect(dst *ebiten.Image, x, y, width, height float32, strokeWidth float32, clr color.Color, antialias bool)

StrokeRect strokes a rectangle with the specified width and color.

Types

type AddPathOptions added in v2.9.0

type AddPathOptions struct {
	// GeoM is a geometry matrix to apply to the path.
	//
	// The default (zero) value is an identity matrix.
	GeoM ebiten.GeoM
}

AddPathOptions is options for Path.AddPath.

type AddStrokeOptions added in v2.9.0

type AddStrokeOptions struct {
	// StrokeOptions is options for the stroke.
	StrokeOptions

	// GeoM is a geometry matrix to apply to the path.
	//
	// The default (zero) value is an identity matrix.
	GeoM ebiten.GeoM
}

AddStrokeOptions is options for Path.AddStroke.

type Direction added in v2.2.0

type Direction int

Direction represents clockwise or counterclockwise.

const (
	Clockwise Direction = iota
	CounterClockwise
)

type DrawPathOptions added in v2.9.0

type DrawPathOptions struct {
	// AntiAlias is whether the path is drawn with anti-aliasing.
	// The default (zero) value is false.
	AntiAlias bool

	// ColorScale is the color scale to apply to the path.
	// The default (zero) value is identity, which is (1, 1, 1, 1) (white).
	ColorScale ebiten.ColorScale

	// Blend is the blend mode to apply to the path.
	// The default (zero) value is ebiten.BlendSourceOver.
	Blend ebiten.Blend
}

DrawPathOptions is options to draw a path.

type FillOptions

type FillOptions struct {
	// FillRule is the rule whether an overlapped region is rendered or not.
	// The default (zero) value is FillRuleNonZero.
	FillRule FillRule
}

FillOptions is options to fill a path.

type FillRule added in v2.9.0

type FillRule int

FillRule is the rule whether an overlapped region is rendered or not.

The number of overlaps is counted with a limited precision, so a region with too many overlapping triangles can be rendered incorrectly.

const (
	// FillRuleNonZero means that triangles are rendered based on the non-zero rule.
	// If and only if the number of overlaps is not 0, the region is rendered.
	FillRuleNonZero FillRule = iota

	// FillRuleEvenOdd means that triangles are rendered based on the even-odd rule.
	// If and only if the number of overlaps is odd, the region is rendered.
	FillRuleEvenOdd
)

type LineCap added in v2.5.0

type LineCap int

LineCap represents the way in which how the ends of the stroke are rendered.

const (
	LineCapButt LineCap = iota
	LineCapRound
	LineCapSquare
)

type LineJoin added in v2.5.0

type LineJoin int

LineJoin represents the way in which how two segments are joined.

const (
	LineJoinMiter LineJoin = iota
	LineJoinBevel
	LineJoinRound
)

type Path

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

Path represents a collection of vector graphics operations.

All the coordinates in a path must be finite. A path with a non-finite coordinate produces an undefined result.

func (*Path) AddPath added in v2.9.0

func (p *Path) AddPath(src *Path, options *AddPathOptions)

AddPath adds the given path src to this path p as a sub-path.

func (*Path) AddStroke added in v2.9.0

func (p *Path) AddStroke(src *Path, options *AddStrokeOptions)

AddStroke adds a stroke path to the path p.

The added stroke path must be rendered with FillRuleNonZero.

func (*Path) AppendVerticesAndIndicesForFilling deprecated added in v2.2.0

func (p *Path) AppendVerticesAndIndicesForFilling(vertices []ebiten.Vertex, indices []uint16) ([]ebiten.Vertex, []uint16)

AppendVerticesAndIndicesForFilling appends vertices and indices to fill this path and returns them.

AppendVerticesAndIndicesForFilling works in a similar way to the built-in append function. If the arguments are nils, AppendVerticesAndIndicesForFilling returns new slices.

The returned vertices' SrcX and SrcY are 0, and ColorR, ColorG, ColorB, and ColorA are 1.

The returned values are intended to be passed to DrawTriangles or DrawTrianglesShader with FillRuleNonZero or FillRuleEvenOdd in order to render a complex polygon like a concave polygon, a polygon with holes, or a self-intersecting polygon.

The returned vertices and indices should be rendered with a solid (non-transparent) color with the default Blend (source-over). Otherwise, there is no guarantee about the rendering result.

AppendVerticesAndIndicesForFilling must not be called for one path from multiple goroutines simultaneously.

AppendVerticesAndIndicesForFilling panics if appending this path would make the vertex count exceed 1 << 16.

Deprecated: as of v2.9. Use FillPath instead.

func (*Path) AppendVerticesAndIndicesForStroke deprecated added in v2.5.0

func (p *Path) AppendVerticesAndIndicesForStroke(vertices []ebiten.Vertex, indices []uint16, op *StrokeOptions) ([]ebiten.Vertex, []uint16)

AppendVerticesAndIndicesForStroke appends vertices and indices to render a stroke of this path and returns them. AppendVerticesAndIndicesForStroke works in a similar way to the built-in append function. If the arguments are nils, AppendVerticesAndIndicesForStroke returns new slices.

The returned vertices' SrcX and SrcY are 0, and ColorR, ColorG, ColorB, and ColorA are 1.

The returned values are intended to be passed to DrawTriangles or DrawTrianglesShader with a solid (non-transparent) color with FillRuleFillAll or FillRuleNonZero, not FillRuleEvenOdd.

AppendVerticesAndIndicesForStroke panics if appending this stroke would make the vertex count exceed 1 << 16.

Deprecated: as of v2.9. Use StrokePath or Path.AddStroke instead.

func (*Path) Arc added in v2.2.0

func (p *Path) Arc(x, y, radius, startAngle, endAngle float32, dir Direction)

Arc adds an arc to the path. (x, y) is the center of the arc. radius must be non-negative. A negative radius produces an undefined result.

func (*Path) ArcTo added in v2.2.0

func (p *Path) ArcTo(x1, y1, x2, y2, radius float32)

ArcTo adds an arc curve to the path. The arc is tangent to the line from the current position to (x1, y1) and to the line from (x1, y1) to (x2, y2). (x1, y1) is the corner point where the two tangent lines meet, and (x2, y2) gives the direction of the second tangent line. The arc ends at the tangent point on the second tangent line, which is at the distance of radius / tan(θ/2) from (x1, y1), where θ is the angle at (x1, y1) between the two rays. radius must be non-negative. A negative radius produces an undefined result.

func (*Path) Bounds added in v2.9.0

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

Bounds returns the minimum bounding rectangle of the path. The rectangle can have a zero width or height when the path is degenerate in an axis, like a horizontal line. Bounds returns the zero rectangle when the path has no drawing operations.

func (*Path) Close added in v2.5.0

func (p *Path) Close()

Close adds a new line from the last position of the current sub-path to the first position of the current sub-path, and marks the current sub-path closed. Following operations for this path will start with a new sub-path.

func (*Path) CubicTo

func (p *Path) CubicTo(x1, y1, x2, y2, x3, y3 float32)

CubicTo adds a cubic Bézier curve to the path. (x1, y1) and (x2, y2) are the control points, and (x3, y3) is the destination.

func (*Path) LineTo

func (p *Path) LineTo(x, y float32)

LineTo adds a line segment to the path, which starts from the last position of the current sub-path and ends to the given position (x, y). If p doesn't have any sub-paths, LineTo sets (x, y) as the start position of a new sub-path. If the last sub-path is closed, LineTo creates a new sub-path whose start position is the same as the closed sub-path's.

func (*Path) MoveTo

func (p *Path) MoveTo(x, y float32)

MoveTo starts a new sub-path with the given position (x, y), without adding any line segments. If the last sub-path is still empty, MoveTo updates its start position instead of adding a new one.

func (*Path) QuadTo

func (p *Path) QuadTo(x1, y1, x2, y2 float32)

QuadTo adds a quadratic Bézier curve to the path. (x1, y1) is the control point, and (x2, y2) is the destination.

func (*Path) Reset added in v2.9.0

func (p *Path) Reset()

Reset resets the path. Reset doesn't release the allocated memory so that the memory can be reused.

type StrokeOptions added in v2.5.0

type StrokeOptions struct {
	// Width is the stroke width in pixels.
	//
	// The default (zero) value is 0.
	Width float32

	// LineCap is the way in which how the ends of the stroke are rendered.
	// Line caps are not rendered when the sub-path is marked as closed.
	//
	// The default (zero) value is [LineCapButt].
	LineCap LineCap

	// LineJoin is the way in which how two segments are joined.
	//
	// The default (zero) value is [LineJoinMiter].
	LineJoin LineJoin

	// MiterLimit is the miter limit for [LineJoinMiter].
	// A join whose miter ratio exceeds MiterLimit is rendered as a bevel join instead.
	// The ratio is always 1 or greater, so a MiterLimit less than 1 renders every join as a bevel join.
	// For details, see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-miterlimit.
	//
	// The default (zero) value is 0, which renders every join as a bevel join.
	MiterLimit float32
}

StrokeOptions is options to render a stroke.

Jump to

Keyboard shortcuts

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