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
- Variables
- func Abs(x float64) float64
- func Atan2(y, x float64) float64
- func Ceil(x float64) float64
- func Copysign(x, sign float64) float64
- func Cos(x float64) float64
- func Floor(x float64) float64
- func GaussArclen[D ParamCurve[D]](c ParamCurveDeriv[D], coeffs [][2]float64) float64
- func Ln(x float64) float64
- func Log2(x float64) float64
- func Powf(x, n float64) float64
- func Powi(x float64, n int32) float64
- func Round(x float64) float64
- func Signum(x float64) float64
- func Sin(x float64) float64
- func SinCos(x float64) (float64, float64)
- func SolveCubic(c0, c1, c2, c3 float64) []float64
- func SolveItp(f func(float64) float64, a, b, epsilon float64, n0 uint, k1, ya, yb float64) float64
- func SolveQuadratic(c0, c1, c2 float64) []float64
- func Sqrt(x float64) float64
- func Tan(x float64) float64
- func Trunc(x float64) float64
- type Affine
- func (a Affine) Determinant() float64
- func (a Affine) Inverse() Affine
- func (a Affine) IsFinite() bool
- func (a Affine) Mul(other Affine) Affine
- func (a Affine) MulPathEl(el PathEl) PathEl
- func (a Affine) MulPoint(p Point) Point
- func (a Affine) TransformRectBbox(rect Rect) Rect
- func (a Affine) Translation() Vec2
- type Arc
- func (a Arc) AppendIter(tolerance float64) *ArcAppendIter
- func (a Arc) End() Point
- func (a Arc) Eval(t float64) Point
- func (a Arc) PathElements(tolerance float64) []PathEl
- func (a Arc) Reversed() Arc
- func (a Arc) Start() Point
- func (a Arc) Subdivide() (Arc, Arc)
- func (a Arc) Subsegment(start, end float64) Arc
- func (a Arc) ToCubicBeziers(tolerance float64, p func(p1, p2, p3 Point))
- type ArcAppendIter
- type ConstPoint
- func (c ConstPoint) Arclen(_ float64) float64
- func (c ConstPoint) Deriv() ConstPoint
- func (c ConstPoint) End() Point
- func (c ConstPoint) Eval(_ float64) Point
- func (c ConstPoint) InvArclen(_, _ float64) float64
- func (c ConstPoint) Start() Point
- func (c ConstPoint) Subdivide() (ConstPoint, ConstPoint)
- func (c ConstPoint) Subsegment(_, _ float64) ConstPoint
- type CubicBez
- func (c CubicBez) Arclen(accuracy float64) float64
- func (c CubicBez) Deriv() QuadBez
- func (c CubicBez) End() Point
- func (c CubicBez) Eval(t float64) Point
- func (c CubicBez) InvArclen(arclen, accuracy float64) float64
- func (c CubicBez) IsFinite() bool
- func (c CubicBez) Start() Point
- func (c CubicBez) Subdivide() (CubicBez, CubicBez)
- func (c CubicBez) Subsegment(start, end float64) CubicBez
- func (c CubicBez) ToQuads(accuracy float64) *ToQuads
- type Ellipse
- type Line
- func (l Line) Arclen(_ float64) float64
- func (l Line) Deriv() ConstPoint
- func (l Line) End() Point
- func (l Line) Eval(t float64) Point
- func (l Line) InvArclen(arclen, _ float64) float64
- func (l Line) Start() Point
- func (l Line) Subdivide() (Line, Line)
- func (l Line) Subsegment(start, end float64) Line
- type ParamCurve
- type ParamCurveArclen
- type ParamCurveDeriv
- type PathEl
- type PathElKind
- type PathSeg
- func (s PathSeg) Arclen(accuracy float64) float64
- func (s PathSeg) AsPathEl() PathEl
- func (s PathSeg) End() Point
- func (s PathSeg) Eval(t float64) Point
- func (s PathSeg) InvArclen(arclen, accuracy float64) float64
- func (s PathSeg) Reverse() PathSeg
- func (s PathSeg) Start() Point
- func (s PathSeg) Subsegment(start, end float64) PathSeg
- type PathSegKind
- type Point
- func (p Point) Add(other Vec2) Point
- func (p Point) Distance(other Point) float64
- func (p Point) IsFinite() bool
- func (p Point) Lerp(other Point, t float64) Point
- func (p Point) Midpoint(other Point) Point
- func (p Point) Sub(other Point) Vec2
- func (p Point) SubVec(other Vec2) Point
- func (p Point) ToVec2() Vec2
- type QuadBez
- func (q QuadBez) Arclen(_ float64) float64
- func (q QuadBez) BoundingBox() Rect
- func (q QuadBez) Deriv() Line
- func (q QuadBez) End() Point
- func (q QuadBez) Eval(t float64) Point
- func (q QuadBez) Extrema() []float64
- func (q QuadBez) InvArclen(arclen, accuracy float64) float64
- func (q QuadBez) IsFinite() bool
- func (q QuadBez) Raise() CubicBez
- func (q QuadBez) Start() Point
- func (q QuadBez) Subdivide() (QuadBez, QuadBez)
- func (q QuadBez) Subsegment(start, end float64) QuadBez
- type Rect
- type RoundedRect
- type Size
- type SvgArc
- type ToQuads
- type Vec2
- func (v Vec2) Add(other Vec2) Vec2
- func (v Vec2) Atan2() float64
- func (v Vec2) Cross(other Vec2) float64
- func (v Vec2) Dot(other Vec2) float64
- func (v Vec2) Hypot() float64
- func (v Vec2) Hypot2() float64
- func (v Vec2) IsFinite() bool
- func (v Vec2) Lerp(other Vec2, t float64) Vec2
- func (v Vec2) Mul(other float64) Vec2
- func (v Vec2) Sub(other Vec2) Vec2
- func (v Vec2) ToPoint() Point
Constants ¶
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.
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 ¶
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.
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.
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.
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.
var IdentityAffine = AffineScale(1.0)
IdentityAffine is Affine::IDENTITY in kurbo kurbo/src/affine.rs.
Functions ¶
func Atan2 ¶
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 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 Powi ¶
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 ¶
Round is FloatFuncs::round in kurbo kurbo/src/common.rs. It rounds half away from zero, as math.Round does.
func Signum ¶
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 SinCos ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
AffineRotate is Affine::rotate in kurbo kurbo/src/affine.rs. th is in radians.
func AffineScale ¶
AffineScale is Affine::scale in kurbo kurbo/src/affine.rs.
func AffineScaleNonUniform ¶
AffineScaleNonUniform is Affine::scale_non_uniform in kurbo kurbo/src/affine.rs.
func AffineSkew ¶
AffineSkew is Affine::skew in kurbo kurbo/src/affine.rs.
func AffineTranslate ¶
AffineTranslate is Affine::translate in kurbo kurbo/src/affine.rs.
func (Affine) Determinant ¶
Determinant is Affine::determinant in kurbo kurbo/src/affine.rs.
func (Affine) Inverse ¶
Inverse is Affine::inverse in kurbo kurbo/src/affine.rs. A singular transform gives non-finite coefficients.
func (Affine) Mul ¶
Mul is impl Mul for Affine in kurbo kurbo/src/affine.rs: the transform that applies other first and then a.
func (Affine) TransformRectBbox ¶
TransformRectBbox is Affine::transform_rect_bbox in kurbo kurbo/src/affine.rs.
func (Affine) Translation ¶
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 ¶
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 (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 ¶
End is the default method ParamCurve::end for Arc, in kurbo kurbo/src/param_curve.rs.
func (Arc) PathElements ¶
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 ¶
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 ¶
Start is the default method ParamCurve::start for Arc, in kurbo kurbo/src/param_curve.rs.
func (Arc) Subdivide ¶
Subdivide is the default method ParamCurve::subdivide for Arc, in kurbo kurbo/src/param_curve.rs.
func (Arc) Subsegment ¶
Subsegment is ParamCurve::subsegment for Arc in kurbo kurbo/src/arc.rs.
func (Arc) ToCubicBeziers ¶
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 ¶
CubicBez is CubicBez in kurbo kurbo/src/cubicbez.rs.
A single cubic Bézier segment.
func NewCubicBez ¶
NewCubicBez is CubicBez::new in kurbo kurbo/src/cubicbez.rs.
Create a new cubic Bézier segment.
func (CubicBez) Arclen ¶
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 ¶
Deriv is ParamCurveDeriv::deriv for CubicBez in kurbo kurbo/src/cubicbez.rs.
func (CubicBez) InvArclen ¶
InvArclen is the default method ParamCurveArclen::inv_arclen for CubicBez, in kurbo kurbo/src/param_curve.rs.
func (CubicBez) Subdivide ¶
Subdivide is ParamCurve::subdivide for CubicBez in kurbo kurbo/src/cubicbez.rs.
Subdivide into halves, using de Casteljau.
func (CubicBez) Subsegment ¶
Subsegment is ParamCurve::subsegment for CubicBez in kurbo kurbo/src/cubicbez.rs.
func (CubicBez) ToQuads ¶ added in v0.14.0
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 ¶
NewEllipse is Ellipse::new in kurbo kurbo/src/ellipse.rs.
func (Ellipse) PathElements ¶
PathElements is impl Shape for Ellipse in kurbo kurbo/src/ellipse.rs. The outline has no ClosePath, as in kurbo.
type Line ¶
Line is Line in kurbo kurbo/src/line.rs.
A single line.
func (Line) Deriv ¶
func (l Line) Deriv() ConstPoint
Deriv is ParamCurveDeriv::deriv for Line in kurbo kurbo/src/line.rs.
func (Line) InvArclen ¶
InvArclen is ParamCurveArclen::inv_arclen for Line in kurbo kurbo/src/line.rs.
func (Line) Subdivide ¶
Subdivide is the default method ParamCurve::subdivide for Line, in kurbo kurbo/src/param_curve.rs.
func (Line) Subsegment ¶
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 Flatten ¶ added in v0.21.0
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).
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 ¶
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) InvArclen ¶
InvArclen is impl ParamCurveArclen for PathSeg in kurbo kurbo/src/bezpath.rs.
func (PathSeg) Subsegment ¶
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 ¶
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 ¶
NewPoint is Point::new in kurbo kurbo/src/point.rs.
Create a new `Point` with the provided `x` and `y` coordinates.
func (Point) Add ¶
Add is the operator `Point + Vec2`, the impl Add<Vec2> for Point in kurbo kurbo/src/point.rs.
func (Point) Distance ¶
Distance is Point::distance in kurbo kurbo/src/point.rs.
Euclidean distance.
See Vec2.Hypot for the same operation on Vec2.
func (Point) Lerp ¶
Lerp is Point::lerp in kurbo kurbo/src/point.rs.
Linearly interpolate between two points.
func (Point) Midpoint ¶
Midpoint is Point::midpoint in kurbo kurbo/src/point.rs.
Determine the midpoint of two points.
func (Point) Sub ¶
Sub is the operator `Point - Point`, the impl Sub<Point> for Point in kurbo kurbo/src/point.rs.
type QuadBez ¶
QuadBez is QuadBez in kurbo kurbo/src/quadbez.rs.
A single quadratic Bézier segment.
func NewQuadBez ¶
NewQuadBez is QuadBez::new in kurbo kurbo/src/quadbez.rs.
Create a new quadratic Bézier segment.
func (QuadBez) Arclen ¶
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 ¶
BoundingBox is ParamCurveExtrema::bounding_box in kurbo kurbo/src/param_curve.rs, for QuadBez.
func (QuadBez) Extrema ¶
Extrema is impl ParamCurveExtrema for QuadBez in kurbo kurbo/src/quadbez.rs.
func (QuadBez) InvArclen ¶
InvArclen is the default method ParamCurveArclen::inv_arclen for QuadBez, in kurbo kurbo/src/param_curve.rs.
func (QuadBez) Raise ¶
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) Subdivide ¶
Subdivide is ParamCurve::subdivide for QuadBez in kurbo kurbo/src/quadbez.rs.
Subdivide into halves, using de Casteljau.
func (QuadBez) Subsegment ¶
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 RectFromPoints ¶
RectFromPoints is Rect::from_points in kurbo kurbo/src/rect.rs.
func (Rect) PathElements ¶
PathElements is impl Shape for Rect in kurbo kurbo/src/rect.rs: the outline of the rectangle, clockwise in a y-down coordinate system.
type RoundedRect ¶
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 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 ¶
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
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.
type Vec2 ¶
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 (Vec2) Add ¶
Add is the operator `Vec2 + Vec2`, the impl Add for Vec2 in kurbo kurbo/src/vec2.rs.
func (Vec2) Atan2 ¶
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) Hypot ¶
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 ¶
Hypot2 is Vec2::hypot2 in kurbo kurbo/src/vec2.rs.
Magnitude squared of vector.
func (Vec2) Lerp ¶
Lerp is Vec2::lerp in kurbo kurbo/src/vec2.rs.
Linearly interpolate between two vectors.
func (Vec2) Mul ¶
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.