planarcurve
planarcurve provides numerical building blocks for planar polylines, Bezier curves, cubic B-splines, normalized heading-rate trajectories, transforms, fitting, and SVG paths. Core geometry uses NumPy and remains independent of application-specific models.
Documentation: Guides, concepts, and API reference.
Install
python -m pip install planarcurve
Optional features:
python -m pip install 'planarcurve[spline]' # B-spline evaluation
python -m pip install 'planarcurve[fit]' # spline and trajectory fitting
python -m pip install 'planarcurve[svg]' # SVG path adapters
python -m pip install 'planarcurve[all]' # all optional dependencies
For development, install planarcurve[dev].
API map
planarcurve.polyline lengths, resampling, projection, intersections, scoring
planarcurve.bezier evaluation, derivatives, curvature, flattening
planarcurve.trajectory normalized heading-rate trajectories
planarcurve.trajectory_chain directed segments, pose propagation, chain sampling
planarcurve.transforms affine and similarity transforms
planarcurve.spline cubic B-splines and cubic-path conversion (SciPy)
planarcurve.fitting spline and trajectory fitting (SciPy)
planarcurve.svg SVG parsing, sampling, and transformation (FontTools)
Quick start
Resample a polyline by its piecewise-linear arc length:
import numpy as np
from planarcurve.polyline import polyline_length, resample_polyline_by_arclength
points = np.array([[0.0, 0.0], [1.0, 1.0], [3.0, 0.0]])
uniform = resample_polyline_by_arclength(points, count=20)
print(polyline_length(points), uniform.shape)
Create a normalized heading-rate trajectory:
from planarcurve.trajectory import (
HeadingRateChange,
HeadingRateProfile,
Trajectory2D,
trajectory_total_turn,
)
trajectory = Trajectory2D(
length=12.0,
start_heading_deg=15.0,
heading_rate=HeadingRateProfile(
start_rate_deg_per_u=0.0,
changes=(HeadingRateChange(0.5, 180.0),),
end_rate_deg_per_u=0.0,
interpolation="linear",
),
)
sample = trajectory.evaluate(count=129)
print(sample.xy[-1], trajectory_total_turn(trajectory))
Here u is normalized progress in [0, 1]. Heading rates are degrees per unit progress. Geometric curvature is signed inverse length and equals radians(heading_rate) / trajectory.length.
Directed trajectory chains
TrajectoryChain composes generic Trajectory2D segments in either direction. Reversal uses the heading-rate profile, and chain samples preserve segment boundaries, tangent changes, and cumulative arc length. trajectory_chain_to_cubic_path() provides a connected cubic representation. These primitives contain no application-specific movement semantics.
Fitting
Fitting
Fitting requires SciPy. Spline fitting estimates shared control points with weighted sparse least squares and IRLS. Trajectory fitting uses a normalized length-1, zero-heading profile plus a similarity transform for each occurrence. See the fitting guide for residual units, endpoint policies, options, and metrics.
Supported spline geometry
BSplineCurve intentionally supports clamped cubic geometry with simple interior knots, not arbitrary SciPy spline configurations. The cubic-hermite heading-rate mode computes shape-preserving slopes from rate knots; callers do not supply derivative values. See spline concepts for the full contract.
Numerical contracts
| Operation | Contract |
|---|---|
| Heading and theoretical trajectory arc length | Piecewise heading integration is analytic; arc length is exactly length * u. |
| Trajectory positions and trajectory-to-cubic conversion | Adaptive numerical integration and sampled error checks, not a continuous global bound. |
| Polyline length and Bezier evaluation/derivatives | Exact for the supplied geometry, up to floating-point arithmetic. |
| Bezier flattening/length and B-spline arc-length sampling | Adaptive or dense-sample approximations. |
| SVG curve lengths and endpoint tangents | Sampled approximations controlled by samples_per_curve. |
Public points are finite 2D coordinates. Polyline projection compares every query with every segment, using O(M*N) time and temporary memory. SVG sample_path() accepts one subpath; use sample_subpaths() to preserve multiple subpaths without artificial connectors. Frozen result dataclasses do not make embedded NumPy arrays immutable.
Optional dependencies and examples
The core package imports with NumPy only. planarcurve.spline and the fitting modules use SciPy. planarcurve.svg uses FontTools. These optional modules are not imported by the core package.
Install optional features and run examples from the repository root:
python -m pip install 'planarcurve[all]'
python examples/trajectory_gallery.py
python examples/bezier_basics.py
python examples/spline_to_bezier.py
python examples/svg_pipeline.py
python examples/fit_polyline_to_spline.py
python examples/fit_shared_trajectory.py
See the examples guide for all six scripts, their optional dependencies, and generated output.
API stability and provenance
The package is pre-release and follows a 0.x compatibility policy. Public names and numerical behavior may change between minor releases. The generic geometry and fitting functionality was extracted and adapted from InkGrammar. planarcurve uses neutral geometry types and does not include handwriting, glyph, dataset, Pydantic, or application orchestration concepts. The project is licensed under Apache-2.0.
Metadata
Release files for planarcurve 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| planarcurve-0.1.3.tar.gz | 246.6 kB | Without provenance | Details for planarcurve-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| planarcurve-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for planarcurve-0.1.3-py3-none-any.whl |
Total release size: 307.0 kB
Release files / planarcurve-0.1.3.tar.gz
| Download URL | planarcurve-0.1.3.tar.gz |
|---|---|
| Size | 246.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a934a66e527655e5d5d5305a8d006f706f854d4291dfe5ce72494762a45ec836
|
|
BLAKE2b-256 checksum How to use checksums |
7343eb110388fd951f7e4d27de1855886b9495a279793f66672a487ecd9568cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / planarcurve-0.1.3-py3-none-any.whl
| Download URL | planarcurve-0.1.3-py3-none-any.whl |
|---|---|
| Size | 60.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bc9603b17193f0c6bc3561f141897fcfdb91f6492c6767a356d6e4b03a209bc
|
|
BLAKE2b-256 checksum How to use checksums |
ef7e8ef6df1757759a0a0de225ce53c125217d576d0dfd7a5a46ea363223a575
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for planarcurve 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.