kurbo

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: BSD-3-Clause, MIT Imports: 2 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package kurbo is a port of a subset of the Rust crate kurbo 0.13.1, a 2D curves library, at the commit 838b69ef.

okage ports only the types and functions that svgtypes and usvg call, and what they need (D7): Point, Vec2, Line, QuadBez, CubicBez, SvgArc, Arc, the traits ParamCurve, ParamCurveDeriv and ParamCurveArclen, and the parts of common.rs that they use. velato and subsetter call a few more items, such as CubicBez::to_quads. SUBSET.md lists each item, with the file of svgtypes, usvg, velato or subsetter that uses it. flatten serves the merge paths of lottie (D94).

The arithmetic gives the same bits as the Rust code. A multiply that is followed by an add is written as float64(x*y) + z, so that the Go compiler cannot fuse the two operations (D16). The functions that Rust takes from the C library, such as sin and atan2, are the correctly rounded functions of internal/crmath (D26). The C library of the Rust oracle can differ from them in the last bit.

Index

Constants

View Source
const DefaultAccuracy = 1e-6

DefaultAccuracy is DEFAULT_ACCURACY in kurbo kurbo/src/param_curve.rs.

A default value for methods that take an 'accuracy' argument.

This value is intended to be suitable for general-purpose use, such as 2d graphics.

View Source
const MaxArcSubdivisions = 1 << 12

MaxArcSubdivisions is the largest number of cubic curves that AppendIter makes for one arc (D30). Upstream has no limit. The number of curves is at most the ceiling of (1.1163 * r / tolerance)^(1/6), where r is the larger radius. It reaches 4,096 only when r / tolerance is about 4.23e21 or more: at the tolerance 0.1 of svgtypes, a radius of about 4.23e20. A smaller arc gives the same curves as upstream. A larger arc still covers its whole sweep, with fewer curves and an error larger than the tolerance. The limit is not higher because each curve calls the correctly rounded sine and cosine of internal/crmath, which take microseconds (D26).

Variables

View Source
var GaussLegendreCoeffs16Half = [][2]float64{
	{0.1894506104550685, 0.0950125098376374},
	{0.1826034150449236, 0.2816035507792589},
	{0.1691565193950025, 0.4580167776572274},
	{0.1495959888165767, 0.6178762444026438},
	{0.1246289712555339, 0.7554044083550030},
	{0.0951585116824928, 0.8656312023878318},
	{0.0622535239386479, 0.9445750230732326},
	{0.0271524594117541, 0.9894009349916499},
}

GaussLegendreCoeffs16Half is GAUSS_LEGENDRE_COEFFS_16_HALF in kurbo kurbo/src/common.rs.

Just the positive x_i values.

View Source
var GaussLegendreCoeffs24Half = [][2]float64{
	{0.1279381953467522, 0.0640568928626056},
	{0.1258374563468283, 0.1911188674736163},
	{0.1216704729278034, 0.3150426796961634},
	{0.1155056680537256, 0.4337935076260451},
	{0.1074442701159656, 0.5454214713888396},
	{0.0976186521041139, 0.6480936519369755},
	{0.0861901615319533, 0.7401241915785544},
	{0.0733464814110803, 0.8200019859739029},
	{0.0592985849154368, 0.8864155270044011},
	{0.0442774388174198, 0.9382745520027328},
	{0.0285313886289337, 0.9747285559713095},
	{0.0123412297999872, 0.9951872199970213},
}

GaussLegendreCoeffs24Half is GAUSS_LEGENDRE_COEFFS_24_HALF in kurbo kurbo/src/common.rs.

View Source
var GaussLegendreCoeffs8 = [][2]float64{
	{0.3626837833783620, -0.1834346424956498},
	{0.3626837833783620, 0.1834346424956498},
	{0.3137066458778873, -0.5255324099163290},
	{0.3137066458778873, 0.5255324099163290},
	{0.2223810344533745, -0.7966664774136267},
	{0.2223810344533745, 0.7966664774136267},
	{0.1012285362903763, -0.9602898564975363},
	{0.1012285362903763, 0.9602898564975363},
}

GaussLegendreCoeffs8 is GAUSS_LEGENDRE_COEFFS_8 in kurbo kurbo/src/common.rs.

View Source
var GaussLegendreCoeffs8Half = [][2]float64{
	{0.3626837833783620, 0.1834346424956498},
	{0.3137066458778873, 0.5255324099163290},
	{0.2223810344533745, 0.7966664774136267},
	{0.1012285362903763, 0.9602898564975363},
}

GaussLegendreCoeffs8Half is GAUSS_LEGENDRE_COEFFS_8_HALF in kurbo kurbo/src/common.rs.

View Source
var IdentityAffine = AffineScale(1.0)

IdentityAffine is Affine::IDENTITY in kurbo kurbo/src/affine.rs.

Functions

func Abs

func Abs(x float64) float64

Abs is FloatFuncs::abs in kurbo kurbo/src/common.rs.

func Atan2

func Atan2(y, x float64) float64

Atan2 is FloatFuncs::atan2 in kurbo kurbo/src/common.rs. It is atan2(y, x), with y the receiver of the Rust method, correctly rounded.

func Ceil

func Ceil(x float64) float64

Ceil is FloatFuncs::ceil in kurbo kurbo/src/common.rs.

func Copysign

func Copysign(x, sign float64) float64

Copysign is FloatFuncs::copysign in kurbo kurbo/src/common.rs.

func Cos

func Cos(x float64) float64

Cos is FloatFuncs::cos in kurbo kurbo/src/common.rs, correctly rounded.

func Floor

func Floor(x float64) float64

Floor is FloatFuncs::floor in kurbo kurbo/src/common.rs.

func GaussArclen

func GaussArclen[D ParamCurve[D]](c ParamCurveDeriv[D], coeffs [][2]float64) float64

GaussArclen is the default method ParamCurveDeriv::gauss_arclen in kurbo kurbo/src/param_curve.rs.

Estimate arclength using Gaussian quadrature.

The coefficients are assumed to cover the range (-1..1), which is traditional.

func Ln

func Ln(x float64) float64

Ln is FloatFuncs::ln in kurbo kurbo/src/common.rs, correctly rounded.

func Log2

func Log2(x float64) float64

Log2 is FloatFuncs::log2 in kurbo kurbo/src/common.rs, correctly rounded.

func Powf

func Powf(x, n float64) float64

Powf is FloatFuncs::powf in kurbo kurbo/src/common.rs, correctly rounded.

func Powi

func Powi(x float64, n int32) float64

Powi is FloatFuncs::powi in kurbo kurbo/src/common.rs, which is f64::powi.

Rust computes powi with repeated multiplication, not with pow. For a constant n, LLVM expands it into the multiplications of the binary method, and for any other n it calls __powidf2 of compiler-rt, which does the same multiplications in the same order. This is __powidf2: x*x for 2, and x*(x*x) for 3.

func Round

func Round(x float64) float64

Round is FloatFuncs::round in kurbo kurbo/src/common.rs. It rounds half away from zero, as math.Round does.

func Signum

func Signum(x float64) float64

Signum is FloatFuncs::signum in kurbo kurbo/src/common.rs, which is f64::signum. It is 1 for a positive x and for +0, -1 for a negative x and for -0, and NaN for NaN.

func Sin

func Sin(x float64) float64

Sin is FloatFuncs::sin in kurbo kurbo/src/common.rs, correctly rounded.

func SinCos

func SinCos(x float64) (float64, float64)

SinCos is FloatFuncs::sin_cos in kurbo kurbo/src/common.rs. The Rust standard library computes it as (sin(x), cos(x)). crmath.SinCos64 gives the same two results, and computes them together.

func SolveCubic

func SolveCubic(c0, c1, c2, c3 float64) []float64

SolveCubic is solve_cubic in kurbo kurbo/src/common.rs.

Find real roots of cubic equation: the values of x for which c0 + c1 x + c2 x² + c3 x³ = 0.

Port: Rust computes cbrt with the C library. Go takes math.Cbrt, which can differ in the last bit.

func SolveItp

func SolveItp(f func(float64) float64, a, b, epsilon float64, n0 uint, k1, ya, yb float64) float64

SolveItp is solve_itp in kurbo kurbo/src/common.rs.

Solve an arbitrary function for a zero-crossing.

This uses the ITP method, as described in the paper An Enhancement of the Bisection Method Average Performance Preserving Minmax Optimality.

The values of `ya` and `yb` are given as arguments rather than computed from `f`, as the values may already be known, or they may be less expensive to compute as special cases.

It is assumed that `ya < 0.0` and `yb > 0.0`, otherwise unexpected results may occur.

The value of `epsilon` must be larger than 2^-63 times `b - a`, otherwise integer overflow may occur. The `a` and `b` parameters represent the lower and upper bounds of the bracket searched for a solution.

The ITP method has tuning parameters. This implementation hardwires k2 to 2, both because it avoids an expensive floating point exponentiation, and because this value has been tested to work well with curve fitting problems.

The `n0` parameter controls the relative impact of the bisection and secant components. When it is 0, the number of iterations is guaranteed to be no more than the number required by bisection (thus, this method is strictly superior to bisection). However, when the function is smooth, a value of 1 gives the secant method more of a chance to engage, so the average number of iterations is likely lower, though there can be one more iteration than bisection in the worst case.

The `k1` parameter is harder to characterize, and interested users are referred to the paper, as well as encouraged to do empirical testing. To match the paper, a value of `0.2 / (b - a)` is suggested, and this is confirmed to give good results.

When the function is monotonic, the returned result is guaranteed to be within `epsilon` of the zero crossing. For more detailed analysis, again see the paper.

func SolveQuadratic

func SolveQuadratic(c0, c1, c2 float64) []float64

SolveQuadratic is solve_quadratic in kurbo kurbo/src/common.rs.

Find real roots of quadratic equation: the values of x for which c0 + c1 x + c2 x² = 0.

func Sqrt

func Sqrt(x float64) float64

Sqrt is FloatFuncs::sqrt in kurbo kurbo/src/common.rs.

func Tan

func Tan(x float64) float64

Tan is FloatFuncs::tan in kurbo kurbo/src/common.rs, correctly rounded.

func Trunc

func Trunc(x float64) float64

Trunc is FloatFuncs::trunc in kurbo kurbo/src/common.rs.

Types

type Affine

type Affine [6]float64

Affine is Affine in kurbo kurbo/src/affine.rs.

A 2D affine transform. The six coefficients are the matrix

[ a c e ]
[ b d f ]
[ 0 0 1 ]

in the order a, b, c, d, e, f.

func AffineRotate

func AffineRotate(th float64) Affine

AffineRotate is Affine::rotate in kurbo kurbo/src/affine.rs. th is in radians.

func AffineScale

func AffineScale(s float64) Affine

AffineScale is Affine::scale in kurbo kurbo/src/affine.rs.

func AffineScaleNonUniform

func AffineScaleNonUniform(sx, sy float64) Affine

AffineScaleNonUniform is Affine::scale_non_uniform in kurbo kurbo/src/affine.rs.

func AffineSkew

func AffineSkew(skewX, skewY float64) Affine

AffineSkew is Affine::skew in kurbo kurbo/src/affine.rs.

func AffineTranslate

func AffineTranslate(p Vec2) Affine

AffineTranslate is Affine::translate in kurbo kurbo/src/affine.rs.

func NewAffine

func NewAffine(c [6]float64) Affine

NewAffine is Affine::new in kurbo kurbo/src/affine.rs.

func (Affine) Determinant

func (a Affine) Determinant() float64

Determinant is Affine::determinant in kurbo kurbo/src/affine.rs.

func (Affine) Inverse

func (a Affine) Inverse() Affine

Inverse is Affine::inverse in kurbo kurbo/src/affine.rs. A singular transform gives non-finite coefficients.

func (Affine) IsFinite

func (a Affine) IsFinite() bool

IsFinite is Affine::is_finite in kurbo kurbo/src/affine.rs.

func (Affine) Mul

func (a Affine) Mul(other Affine) Affine

Mul is impl Mul for Affine in kurbo kurbo/src/affine.rs: the transform that applies other first and then a.

func (Affine) MulPathEl

func (a Affine) MulPathEl(el PathEl) PathEl

MulPathEl is impl Mul<PathEl> for Affine in kurbo kurbo/src/bezpath.rs.

func (Affine) MulPoint

func (a Affine) MulPoint(p Point) Point

MulPoint is impl Mul<Point> for Affine in kurbo kurbo/src/affine.rs.

func (Affine) TransformRectBbox

func (a Affine) TransformRectBbox(rect Rect) Rect

TransformRectBbox is Affine::transform_rect_bbox in kurbo kurbo/src/affine.rs.

func (Affine) Translation

func (a Affine) Translation() Vec2

Translation is Affine::translation in kurbo kurbo/src/affine.rs.

type Arc

type Arc struct {
	// The arc's centre point.
	Center Point
	// The arc's radii, where the vector's x-component is the radius in the
	// positive x direction after applying `x_rotation`.
	Radii Vec2
	// The start angle in radians.
	StartAngle float64
	// The angle between the start and end of the arc, in radians.
	SweepAngle float64
	// How much the arc is rotated, in radians.
	XRotation float64
}

Arc is Arc in kurbo kurbo/src/arc.rs.

A single elliptical arc segment.

func FromSvgArc

func FromSvgArc(arc *SvgArc) (Arc, bool)

FromSvgArc is Arc::from_svg_arc in kurbo kurbo/src/svg.rs.

Creates an `Arc` from a `SvgArc`.

Returns false if `arc` is actually a straight line.

func NewArc

func NewArc(center Point, radii Vec2, startAngle, sweepAngle, xRotation float64) Arc

NewArc is Arc::new in kurbo kurbo/src/arc.rs.

Create a new `Arc`.

func (Arc) AppendIter

func (a Arc) AppendIter(tolerance float64) *ArcAppendIter

AppendIter is Arc::append_iter in kurbo kurbo/src/arc.rs.

Create an iterator generating Bezier path elements.

The generated elements can be appended to an existing bezier path.

func (Arc) End

func (a Arc) End() Point

End is the default method ParamCurve::end for Arc, in kurbo kurbo/src/param_curve.rs.

func (Arc) Eval

func (a Arc) Eval(t float64) Point

Eval is ParamCurve::eval for Arc in kurbo kurbo/src/arc.rs.

func (Arc) PathElements

func (a Arc) PathElements(tolerance float64) []PathEl

PathElements is impl Shape for Arc in kurbo kurbo/src/arc.rs: a MoveTo to the start, and the curves of AppendIter.

func (Arc) Reversed

func (a Arc) Reversed() Arc

Reversed is Arc::reversed in kurbo kurbo/src/arc.rs.

Returns a copy of this `Arc` in the opposite direction.

The new `Arc` will sweep towards the original `Arc`s start angle.

func (Arc) Start

func (a Arc) Start() Point

Start is the default method ParamCurve::start for Arc, in kurbo kurbo/src/param_curve.rs.

func (Arc) Subdivide

func (a Arc) Subdivide() (Arc, Arc)

Subdivide is the default method ParamCurve::subdivide for Arc, in kurbo kurbo/src/param_curve.rs.

func (Arc) Subsegment

func (a Arc) Subsegment(start, end float64) Arc

Subsegment is ParamCurve::subsegment for Arc in kurbo kurbo/src/arc.rs.

func (Arc) ToCubicBeziers

func (a Arc) ToCubicBeziers(tolerance float64, p func(p1, p2, p3 Point))

ToCubicBeziers is Arc::to_cubic_beziers in kurbo kurbo/src/arc.rs.

Converts an `Arc` into a series of cubic bezier segments.

The closure `p` will be invoked with the control points for each segment.

type ArcAppendIter

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

ArcAppendIter is ArcAppendIter in kurbo kurbo/src/arc.rs. Upstream hides it from the documentation.

func (*ArcAppendIter) Next

func (it *ArcAppendIter) Next() (Point, Point, Point, bool)

Next is Iterator::next for ArcAppendIter in kurbo kurbo/src/arc.rs.

Upstream returns the path element PathEl::CurveTo(p1, p2, p3), the only element that it makes. okage does not port PathEl, so Next returns the three points, and false at the end.

type ConstPoint

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

ConstPoint is ConstPoint in kurbo kurbo/src/line.rs.

A trivial "curve" that is just a constant.

func (ConstPoint) Arclen

func (c ConstPoint) Arclen(_ float64) float64

Arclen is ParamCurveArclen::arclen for ConstPoint in kurbo kurbo/src/line.rs.

func (ConstPoint) Deriv

func (c ConstPoint) Deriv() ConstPoint

Deriv is ParamCurveDeriv::deriv for ConstPoint in kurbo kurbo/src/line.rs.

func (ConstPoint) End

func (c ConstPoint) End() Point

End is the default method ParamCurve::end for ConstPoint, in kurbo kurbo/src/param_curve.rs.

func (ConstPoint) Eval

func (c ConstPoint) Eval(_ float64) Point

Eval is ParamCurve::eval for ConstPoint in kurbo kurbo/src/line.rs.

func (ConstPoint) InvArclen

func (c ConstPoint) InvArclen(_, _ float64) float64

InvArclen is ParamCurveArclen::inv_arclen for ConstPoint in kurbo kurbo/src/line.rs.

func (ConstPoint) Start

func (c ConstPoint) Start() Point

Start is the default method ParamCurve::start for ConstPoint, in kurbo kurbo/src/param_curve.rs.

func (ConstPoint) Subdivide

func (c ConstPoint) Subdivide() (ConstPoint, ConstPoint)

Subdivide is the default method ParamCurve::subdivide for ConstPoint, in kurbo kurbo/src/param_curve.rs.

func (ConstPoint) Subsegment

func (c ConstPoint) Subsegment(_, _ float64) ConstPoint

Subsegment is ParamCurve::subsegment for ConstPoint in kurbo kurbo/src/line.rs.

type CubicBez

type CubicBez struct {
	P0 Point
	P1 Point
	P2 Point
	P3 Point
}

CubicBez is CubicBez in kurbo kurbo/src/cubicbez.rs.

A single cubic Bézier segment.

func NewCubicBez

func NewCubicBez(p0, p1, p2, p3 Point) CubicBez

NewCubicBez is CubicBez::new in kurbo kurbo/src/cubicbez.rs.

Create a new cubic Bézier segment.

func (CubicBez) Arclen

func (c CubicBez) Arclen(accuracy float64) float64

Arclen is ParamCurveArclen::arclen for CubicBez in kurbo kurbo/src/cubicbez.rs.

Arclength of a cubic Bézier segment.

This is an adaptive subdivision approach using Legendre-Gauss quadrature in the base case, and an error estimate to decide when to subdivide.

func (CubicBez) Deriv

func (c CubicBez) Deriv() QuadBez

Deriv is ParamCurveDeriv::deriv for CubicBez in kurbo kurbo/src/cubicbez.rs.

func (CubicBez) End

func (c CubicBez) End() Point

End is ParamCurve::end for CubicBez in kurbo kurbo/src/cubicbez.rs.

func (CubicBez) Eval

func (c CubicBez) Eval(t float64) Point

Eval is ParamCurve::eval for CubicBez in kurbo kurbo/src/cubicbez.rs.

func (CubicBez) InvArclen

func (c CubicBez) InvArclen(arclen, accuracy float64) float64

InvArclen is the default method ParamCurveArclen::inv_arclen for CubicBez, in kurbo kurbo/src/param_curve.rs.

func (CubicBez) IsFinite

func (c CubicBez) IsFinite() bool

IsFinite is CubicBez::is_finite in kurbo kurbo/src/cubicbez.rs.

func (CubicBez) Start

func (c CubicBez) Start() Point

Start is ParamCurve::start for CubicBez in kurbo kurbo/src/cubicbez.rs.

func (CubicBez) Subdivide

func (c CubicBez) Subdivide() (CubicBez, CubicBez)

Subdivide is ParamCurve::subdivide for CubicBez in kurbo kurbo/src/cubicbez.rs.

Subdivide into halves, using de Casteljau.

func (CubicBez) Subsegment

func (c CubicBez) Subsegment(start, end float64) CubicBez

Subsegment is ParamCurve::subsegment for CubicBez in kurbo kurbo/src/cubicbez.rs.

func (CubicBez) ToQuads added in v0.14.0

func (c CubicBez) ToQuads(accuracy float64) *ToQuads

ToQuads is CubicBez::to_quads in kurbo kurbo/src/cubicbez.rs.

Convert to quadratic Béziers.

The iterator returns the start and end parameter in the cubic of each quadratic segment, along with the quadratic.

Note that the resulting quadratic Béziers are not in general G1 continuous. They are optimized for minimizing distance error.

This iterator will always produce at least one QuadBez.

type Ellipse

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

Ellipse is Ellipse in kurbo kurbo/src/ellipse.rs: a unit circle under an affine transform.

func NewEllipse

func NewEllipse(center Point, radii Vec2, xRotation float64) Ellipse

NewEllipse is Ellipse::new in kurbo kurbo/src/ellipse.rs.

func (Ellipse) Center

func (e Ellipse) Center() Point

Center is Ellipse::center in kurbo kurbo/src/ellipse.rs.

func (Ellipse) PathElements

func (e Ellipse) PathElements(tolerance float64) []PathEl

PathElements is impl Shape for Ellipse in kurbo kurbo/src/ellipse.rs. The outline has no ClosePath, as in kurbo.

type Line

type Line struct {
	// The line's start point.
	P0 Point
	// The line's end point.
	P1 Point
}

Line is Line in kurbo kurbo/src/line.rs.

A single line.

func NewLine

func NewLine(p0, p1 Point) Line

NewLine is Line::new in kurbo kurbo/src/line.rs.

Create a new line.

func (Line) Arclen

func (l Line) Arclen(_ float64) float64

Arclen is ParamCurveArclen::arclen for Line in kurbo kurbo/src/line.rs.

func (Line) Deriv

func (l Line) Deriv() ConstPoint

Deriv is ParamCurveDeriv::deriv for Line in kurbo kurbo/src/line.rs.

func (Line) End

func (l Line) End() Point

End is ParamCurve::end for Line in kurbo kurbo/src/line.rs.

func (Line) Eval

func (l Line) Eval(t float64) Point

Eval is ParamCurve::eval for Line in kurbo kurbo/src/line.rs.

func (Line) InvArclen

func (l Line) InvArclen(arclen, _ float64) float64

InvArclen is ParamCurveArclen::inv_arclen for Line in kurbo kurbo/src/line.rs.

func (Line) Start

func (l Line) Start() Point

Start is ParamCurve::start for Line in kurbo kurbo/src/line.rs.

func (Line) Subdivide

func (l Line) Subdivide() (Line, Line)

Subdivide is the default method ParamCurve::subdivide for Line, in kurbo kurbo/src/param_curve.rs.

func (Line) Subsegment

func (l Line) Subsegment(start, end float64) Line

Subsegment is ParamCurve::subsegment for Line in kurbo kurbo/src/line.rs.

type ParamCurve

type ParamCurve[T any] interface {
	// Evaluate the curve at parameter `t`.
	//
	// Generally `t` is in the range [0..1].
	Eval(t float64) Point

	// Get a subsegment of the curve for the given parameter range, from
	// start to end. Rust takes a Range<f64>.
	Subsegment(start, end float64) T

	// Subdivide into (roughly) halves.
	Subdivide() (T, T)

	// The start point.
	Start() Point

	// The end point.
	End() Point
}

ParamCurve is the trait ParamCurve in kurbo kurbo/src/param_curve.rs. T is the type that implements it.

A curve parameterized by a scalar.

If the result is interpreted as a point, this represents a curve. But the result can be interpreted as a vector as well.

type ParamCurveArclen

type ParamCurveArclen[T any] interface {
	ParamCurve[T]

	// The arc length of the curve.
	//
	// The result is accurate to the given accuracy (subject to
	// roundoff errors for ridiculously low values). Compute time
	// may vary with accuracy, if the curve needs to be subdivided.
	Arclen(accuracy float64) float64

	// Solve for the parameter that has the given arc length from the start.
	InvArclen(arclen, accuracy float64) float64
}

ParamCurveArclen is the trait ParamCurveArclen in kurbo kurbo/src/param_curve.rs. T is the type that implements it.

A parameterized curve that can have its arc length measured.

type ParamCurveDeriv

type ParamCurveDeriv[D ParamCurve[D]] interface {
	// The derivative of the curve.
	//
	// Note that the type of the return value is somewhat inaccurate, as
	// the derivative of a curve (mapping of param to point) is a mapping
	// of param to vector. We choose to accept this rather than have a
	// more complex type scheme.
	Deriv() D
}

ParamCurveDeriv is the trait ParamCurveDeriv in kurbo kurbo/src/param_curve.rs. D is the associated type DerivResult.

A differentiable parameterized curve.

type PathEl

type PathEl struct {
	Kind PathElKind
	P    [3]Point
}

PathEl is PathEl in kurbo kurbo/src/bezpath.rs. A MoveTo and a LineTo use P[0], a QuadTo uses P[0] and P[1], and a CurveTo uses all three points.

func ClosePath

func ClosePath() PathEl

ClosePath is PathEl::ClosePath in kurbo kurbo/src/bezpath.rs.

func CurveTo

func CurveTo(p1, p2, p3 Point) PathEl

CurveTo is PathEl::CurveTo in kurbo kurbo/src/bezpath.rs.

func Flatten added in v0.21.0

func Flatten(path []PathEl, tolerance float64, dst []PathEl) []PathEl

Flatten is flatten in kurbo kurbo/src/bezpath.rs. It appends to dst the elements of path with each curve flattened to lines, and returns dst.

The tolerance value controls the maximum distance between the curved input segments and their polyline approximations. (In technical terms, this is the Hausdorff distance). The algorithm attempts to bound this distance by tolerance but this is not absolutely guaranteed. The number of segments tends to scale as the inverse square root of tolerance.

Port: kurbo calls a callback with each element. Flatten appends them to a slice, so that it takes no closure (D25, D94).

func LineTo

func LineTo(p Point) PathEl

LineTo is PathEl::LineTo in kurbo kurbo/src/bezpath.rs.

func MoveTo

func MoveTo(p Point) PathEl

MoveTo is PathEl::MoveTo in kurbo kurbo/src/bezpath.rs.

func QuadTo

func QuadTo(p1, p2 Point) PathEl

QuadTo is PathEl::QuadTo in kurbo kurbo/src/bezpath.rs.

type PathElKind

type PathElKind uint8

PathElKind is the variant of PathEl in kurbo kurbo/src/bezpath.rs (D27).

const (
	PathElMoveTo PathElKind = iota
	PathElLineTo
	PathElQuadTo
	PathElCurveTo
	PathElClosePath
)

The variants of PathEl.

type PathSeg

type PathSeg struct {
	Kind  PathSegKind
	Line  Line
	Quad  QuadBez
	Cubic CubicBez
}

PathSeg is PathSeg in kurbo kurbo/src/bezpath.rs. The field of its kind holds the segment.

func Segments

func Segments(elements []PathEl) []PathSeg

Segments is segments in kurbo kurbo/src/bezpath.rs: the segments of a sequence of path elements.

Port: kurbo gives an iterator that panics on a first element ClosePath. Segments returns a slice, and a ClosePath before any point gives no segment.

func (PathSeg) Arclen

func (s PathSeg) Arclen(accuracy float64) float64

Arclen is impl ParamCurveArclen for PathSeg in kurbo kurbo/src/bezpath.rs.

func (PathSeg) AsPathEl

func (s PathSeg) AsPathEl() PathEl

AsPathEl is PathSeg::as_path_el in kurbo kurbo/src/bezpath.rs.

func (PathSeg) End

func (s PathSeg) End() Point

End is impl ParamCurve for PathSeg in kurbo kurbo/src/bezpath.rs.

func (PathSeg) Eval

func (s PathSeg) Eval(t float64) Point

Eval is impl ParamCurve for PathSeg in kurbo kurbo/src/bezpath.rs.

func (PathSeg) InvArclen

func (s PathSeg) InvArclen(arclen, accuracy float64) float64

InvArclen is impl ParamCurveArclen for PathSeg in kurbo kurbo/src/bezpath.rs.

func (PathSeg) Reverse

func (s PathSeg) Reverse() PathSeg

Reverse is PathSeg::reverse in kurbo kurbo/src/bezpath.rs.

func (PathSeg) Start

func (s PathSeg) Start() Point

Start is impl ParamCurve for PathSeg in kurbo kurbo/src/bezpath.rs.

func (PathSeg) Subsegment

func (s PathSeg) Subsegment(start, end float64) PathSeg

Subsegment is impl ParamCurve for PathSeg in kurbo kurbo/src/bezpath.rs.

type PathSegKind

type PathSegKind uint8

PathSegKind is the variant of PathSeg in kurbo kurbo/src/bezpath.rs (D27).

const (
	PathSegLine PathSegKind = iota
	PathSegQuad
	PathSegCubic
)

The variants of PathSeg.

type Point

type Point struct {
	// The x coordinate.
	X float64
	// The y coordinate.
	Y float64
}

Point is Point in kurbo kurbo/src/point.rs.

A 2D point.

This type represents a point in 2D space. It has the same layout as Vec2, but its meaning is different: `Vec2` represents a change in location (for example velocity).

In general, `kurbo` overloads math operators where it makes sense, for example implementing `Affine * Point` as the point under the affine transformation. However `Point + Point` and `f64 * Point` are not implemented, because the operations do not make geometric sense. If you need to apply these operations, then 1) check what you're doing makes geometric sense, then 2) use Point.ToVec2 to convert the point to a `Vec2`.

func NewPoint

func NewPoint(x, y float64) Point

NewPoint is Point::new in kurbo kurbo/src/point.rs.

Create a new `Point` with the provided `x` and `y` coordinates.

func (Point) Add

func (p Point) Add(other Vec2) Point

Add is the operator `Point + Vec2`, the impl Add<Vec2> for Point in kurbo kurbo/src/point.rs.

func (Point) Distance

func (p Point) Distance(other Point) float64

Distance is Point::distance in kurbo kurbo/src/point.rs.

Euclidean distance.

See Vec2.Hypot for the same operation on Vec2.

func (Point) IsFinite

func (p Point) IsFinite() bool

IsFinite is Point::is_finite in kurbo kurbo/src/point.rs.

func (Point) Lerp

func (p Point) Lerp(other Point, t float64) Point

Lerp is Point::lerp in kurbo kurbo/src/point.rs.

Linearly interpolate between two points.

func (Point) Midpoint

func (p Point) Midpoint(other Point) Point

Midpoint is Point::midpoint in kurbo kurbo/src/point.rs.

Determine the midpoint of two points.

func (Point) Sub

func (p Point) Sub(other Point) Vec2

Sub is the operator `Point - Point`, the impl Sub<Point> for Point in kurbo kurbo/src/point.rs.

func (Point) SubVec

func (p Point) SubVec(other Vec2) Point

SubVec is the operator `Point - Vec2`, the impl Sub<Vec2> for Point in kurbo kurbo/src/point.rs.

func (Point) ToVec2

func (p Point) ToVec2() Vec2

ToVec2 is Point::to_vec2 in kurbo kurbo/src/point.rs.

Convert this point into a `Vec2`.

type QuadBez

type QuadBez struct {
	P0 Point
	P1 Point
	P2 Point
}

QuadBez is QuadBez in kurbo kurbo/src/quadbez.rs.

A single quadratic Bézier segment.

func NewQuadBez

func NewQuadBez(p0, p1, p2 Point) QuadBez

NewQuadBez is QuadBez::new in kurbo kurbo/src/quadbez.rs.

Create a new quadratic Bézier segment.

func (QuadBez) Arclen

func (q QuadBez) Arclen(_ float64) float64

Arclen is ParamCurveArclen::arclen for QuadBez in kurbo kurbo/src/quadbez.rs.

Arclength of a quadratic Bézier segment.

This computation is based on an analytical formula. Since that formula suffers from numerical instability when the curve is very close to a straight line, we detect that case and fall back to Legendre-Gauss quadrature.

Accuracy should be better than 1e-13 over the entire range.

Adapted from <http://www.malczak.linuxpl.com/blog/quadratic-bezier-curve-length/> with permission.

func (QuadBez) BoundingBox

func (q QuadBez) BoundingBox() Rect

BoundingBox is ParamCurveExtrema::bounding_box in kurbo kurbo/src/param_curve.rs, for QuadBez.

func (QuadBez) Deriv

func (q QuadBez) Deriv() Line

Deriv is ParamCurveDeriv::deriv for QuadBez in kurbo kurbo/src/quadbez.rs.

func (QuadBez) End

func (q QuadBez) End() Point

End is ParamCurve::end for QuadBez in kurbo kurbo/src/quadbez.rs.

func (QuadBez) Eval

func (q QuadBez) Eval(t float64) Point

Eval is ParamCurve::eval for QuadBez in kurbo kurbo/src/quadbez.rs.

func (QuadBez) Extrema

func (q QuadBez) Extrema() []float64

Extrema is impl ParamCurveExtrema for QuadBez in kurbo kurbo/src/quadbez.rs.

func (QuadBez) InvArclen

func (q QuadBez) InvArclen(arclen, accuracy float64) float64

InvArclen is the default method ParamCurveArclen::inv_arclen for QuadBez, in kurbo kurbo/src/param_curve.rs.

func (QuadBez) IsFinite

func (q QuadBez) IsFinite() bool

IsFinite is QuadBez::is_finite in kurbo kurbo/src/quadbez.rs.

func (QuadBez) Raise

func (q QuadBez) Raise() CubicBez

Raise is QuadBez::raise in kurbo kurbo/src/quadbez.rs.

Raise the order by 1.

Returns a cubic Bézier segment that exactly represents this quadratic.

func (QuadBez) Start

func (q QuadBez) Start() Point

Start is ParamCurve::start for QuadBez in kurbo kurbo/src/quadbez.rs.

func (QuadBez) Subdivide

func (q QuadBez) Subdivide() (QuadBez, QuadBez)

Subdivide is ParamCurve::subdivide for QuadBez in kurbo kurbo/src/quadbez.rs.

Subdivide into halves, using de Casteljau.

func (QuadBez) Subsegment

func (q QuadBez) Subsegment(start, end float64) QuadBez

Subsegment is ParamCurve::subsegment for QuadBez in kurbo kurbo/src/quadbez.rs.

type Rect

type Rect struct {
	X0, Y0, X1, Y1 float64
}

Rect is Rect in kurbo kurbo/src/rect.rs.

A rectangle, with the minimum x and y in X0 and Y0 and the maximum in X1 and Y1.

func NewRect

func NewRect(x0, y0, x1, y1 float64) Rect

NewRect is Rect::new in kurbo kurbo/src/rect.rs.

func RectFromPoints

func RectFromPoints(p0, p1 Point) Rect

RectFromPoints is Rect::from_points in kurbo kurbo/src/rect.rs.

func (Rect) Abs

func (r Rect) Abs() Rect

Abs is Rect::abs in kurbo kurbo/src/rect.rs.

func (Rect) Height

func (r Rect) Height() float64

Height is Rect::height in kurbo kurbo/src/rect.rs.

func (Rect) PathElements

func (r Rect) PathElements(_ float64) []PathEl

PathElements is impl Shape for Rect in kurbo kurbo/src/rect.rs: the outline of the rectangle, clockwise in a y-down coordinate system.

func (Rect) Union

func (r Rect) Union(other Rect) Rect

Union is Rect::union in kurbo kurbo/src/rect.rs.

func (Rect) UnionPt

func (r Rect) UnionPt(pt Point) Rect

UnionPt is Rect::union_pt in kurbo kurbo/src/rect.rs.

func (Rect) Width

func (r Rect) Width() float64

Width is Rect::width in kurbo kurbo/src/rect.rs.

type RoundedRect

type RoundedRect struct {
	Rect   Rect
	Radius float64
}

RoundedRect is RoundedRect in kurbo kurbo/src/rounded_rect.rs, with one radius for the four corners, as RoundedRectRadii::from_single_radius gives.

func NewRoundedRect

func NewRoundedRect(x0, y0, x1, y1, radius float64) RoundedRect

NewRoundedRect is RoundedRect::new in kurbo kurbo/src/rounded_rect.rs.

func (RoundedRect) PathElements

func (r RoundedRect) PathElements(tolerance float64) []PathEl

PathElements is impl Shape for RoundedRect in kurbo kurbo/src/rounded_rect.rs. It goes clockwise in a y-down coordinate system, from the top of the left side.

type Size

type Size struct {
	Width, Height float64
}

Size is Size in kurbo kurbo/src/size.rs.

func NewSize

func NewSize(width, height float64) Size

NewSize is Size::new in kurbo kurbo/src/size.rs.

type SvgArc

type SvgArc struct {
	// The arc's start point.
	From Point
	// The arc's end point.
	To Point
	// The arc's radii, where the vector's x-component is the radius in the
	// positive x direction after applying `x_rotation`.
	Radii Vec2
	// How much the arc is rotated, in radians.
	XRotation float64
	// Does this arc sweep through more than π radians?
	LargeArc bool
	// Determines if the arc should begin moving at positive angles.
	Sweep bool
}

SvgArc is SvgArc in kurbo kurbo/src/svg.rs.

A single SVG arc segment.

func (*SvgArc) IsStraightLine

func (a *SvgArc) IsStraightLine() bool

IsStraightLine is SvgArc::is_straight_line in kurbo kurbo/src/svg.rs.

Checks that arc is actually a straight line.

In this case, it can be replaced with a `LineTo`.

type ToQuads added in v0.14.0

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

ToQuads is ToQuads in kurbo kurbo/src/cubicbez.rs, the iterator of CubicBez.ToQuads, which produces quadratic Bézier segments. Upstream keeps it private and returns it as an iterator.

func (*ToQuads) Len added in v0.14.0

func (it *ToQuads) Len() int

Len is Iterator::size_hint for ToQuads in kurbo kurbo/src/cubicbez.rs. It returns the number of segments that Next has not returned yet.

func (*ToQuads) Next added in v0.14.0

func (it *ToQuads) Next() (float64, float64, QuadBez, bool)

Next is Iterator::next for ToQuads in kurbo kurbo/src/cubicbez.rs. It returns the start and the end parameter in the cubic of the next quadratic segment, and the quadratic. It returns false at the end.

type Vec2

type Vec2 struct {
	// The x-coordinate.
	X float64
	// The y-coordinate.
	Y float64
}

Vec2 is Vec2 in kurbo kurbo/src/vec2.rs.

A 2D vector.

This is intended primarily for a vector in the mathematical sense, but it can be interpreted as a translation, and converted to and from a Point (vector relative to the origin) and `Size`.

func NewVec2

func NewVec2(x, y float64) Vec2

NewVec2 is Vec2::new in kurbo kurbo/src/vec2.rs.

Create a new vector.

func (Vec2) Add

func (v Vec2) Add(other Vec2) Vec2

Add is the operator `Vec2 + Vec2`, the impl Add for Vec2 in kurbo kurbo/src/vec2.rs.

func (Vec2) Atan2

func (v Vec2) Atan2() float64

Atan2 is Vec2::atan2 in kurbo kurbo/src/vec2.rs.

Find the angle in radians between this vector and the vector `Vec2 { x: 1.0, y: 0.0 }` in the positive `y` direction.

If the vector is interpreted as a complex number, this is the argument. The angle is expressed in radians.

func (Vec2) Cross

func (v Vec2) Cross(other Vec2) float64

Cross is Vec2::cross in kurbo kurbo/src/vec2.rs.

func (Vec2) Dot

func (v Vec2) Dot(other Vec2) float64

Dot is Vec2::dot in kurbo kurbo/src/vec2.rs.

Dot product of two vectors.

func (Vec2) Hypot

func (v Vec2) Hypot() float64

Hypot is Vec2::hypot in kurbo kurbo/src/vec2.rs.

Magnitude of vector.

See Point.Distance for the same operation on Point.

func (Vec2) Hypot2

func (v Vec2) Hypot2() float64

Hypot2 is Vec2::hypot2 in kurbo kurbo/src/vec2.rs.

Magnitude squared of vector.

func (Vec2) IsFinite

func (v Vec2) IsFinite() bool

IsFinite is Vec2::is_finite in kurbo kurbo/src/vec2.rs.

func (Vec2) Lerp

func (v Vec2) Lerp(other Vec2, t float64) Vec2

Lerp is Vec2::lerp in kurbo kurbo/src/vec2.rs.

Linearly interpolate between two vectors.

func (Vec2) Mul

func (v Vec2) Mul(other float64) Vec2

Mul is the operator `Vec2 * f64`, the impl Mul<f64> for Vec2 in kurbo kurbo/src/vec2.rs. The operator `f64 * Vec2`, the impl Mul<Vec2> for f64, is `other * self` in Rust, so it is Mul too.

func (Vec2) Sub

func (v Vec2) Sub(other Vec2) Vec2

Sub is the operator `Vec2 - Vec2`, the impl Sub for Vec2 in kurbo kurbo/src/vec2.rs.

func (Vec2) ToPoint

func (v Vec2) ToPoint() Point

ToPoint is Vec2::to_point in kurbo kurbo/src/vec2.rs.

Convert this vector into a Point.

Jump to

Keyboard shortcuts

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