PathSeg

class kurbopy.PathSeg
arclen(accuracy)

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.

area()

Compute the signed area under the curve.

For a closed path, the signed area of the path is the sum of signed areas of the segments. This is a variant of the “shoelace formula.” See: <https://github.com/Pomax/bezierinfo/issues/44> and <http://ich.deanmcnamee.com/graphics/2016/03/30/CurveArea.html>

This can be computed exactly for Béziers thanks to Green’s theorem, and also for simple curves such as circular arcs. For more exotic curves, it’s probably best to subdivide to cubics. We leave that to the caller, which is why we don’t give an accuracy param here.

as_cubic()
as_line()
as_path_el()

Get the [PathEl] that is equivalent to discarding the segment start point.

as_quad()
bounding_box()

The smallest rectangle that encloses the curve in the range (0..1).

contains(pt)

Returns true if the [Point] is inside this shape.

This is only meaningful for closed shapes.

curvature(t)
deriv()
end()

The end point.

eval(t)

Evaluate the curve at parameter t.

Generally t is in the range [0..1].

extrema()

Compute the extrema of the curve.

Only extrema within the interior of the curve count.

The extrema should be reported in increasing parameter order.

extrema_ranges()

Return parameter ranges, each of which is monotonic within the range.

intersect_line(line)

Compute intersections against a line.

Returns a vector of the intersections. For each intersection, the t value of the segment and line are given.

Note: This test is designed to be inclusive of points near the endpoints of the segment. This is so that testing a line against multiple contiguous segments of a path will be guaranteed to catch at least one of them. In such cases, use higher level logic to coalesce the hits (the t value may be slightly outside the range of 0..1).

inv_arclen(arclen, accuracy)

Solve for the parameter that has the given arc length from the start.

This implementation uses the IPT method, as provided by [common::solve_itp]. This is as robust as bisection but typically converges faster. In addition, the method takes care to compute arc lengths of increasingly smaller segments of the curve, as that is likely faster than repeatedly computing the arc length of the segment starting at t=0.

is_finite()

Is this value finite?

is_nan()

Is this value NaN?

min_dist(other, accuracy)

Minimum distance between two [PathSeg]s.

Returns a tuple of the distance, the path time t1 of the closest point on the first PathSeg, and the path time t2 of the closest point on the second PathSeg.

nearest(point, accuracy)

Find the position on the curve that is nearest to the given point.

This returns a [Nearest] struct that contains information about the position.

perimeter(accuracy)

Total length of perimeter.

reverse()

Returns a new PathSeg describing the same path as self, but with the points reversed.

signed_area()

Compute the signed area under the curve.

For a closed path, the signed area of the path is the sum of signed areas of the segments. This is a variant of the “shoelace formula.” See: <https://github.com/Pomax/bezierinfo/issues/44> and <http://ich.deanmcnamee.com/graphics/2016/03/30/CurveArea.html>

This can be computed exactly for Béziers thanks to Green’s theorem, and also for simple curves such as circular arcs. For more exotic curves, it’s probably best to subdivide to cubics. We leave that to the caller, which is why we don’t give an accuracy param here.

start()

The start point.

subdivide()

Subdivide into (roughly) halves.

subsegment()

Get a subsegment of the curve for the given parameter range.

to_cubic()

Convert this segment to a cubic bezier.

to_path(tolerance)

Convert to a Bézier path.

winding(pt)

The winding number of a point.

This method only produces meaningful results with closed shapes.

The sign of the winding number is consistent with that of area, meaning it is +1 when the point is inside a positive area shape and -1 when it is inside a negative area shape. Of course, greater magnitude values are also possible when the shape is more complex.

LineIntersection

class kurbopy.LineIntersection
is_finite()

Is this value finite?

is_nan()

Is this value NaN?

line_t
segment_t