Skip to main content

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 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
python examples/fit_shared_trajectory_family.py
python examples/select_trajectory_complexity.py

See the examples guide for what each script demonstrates, its optional dependencies, and its 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.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for planarcurve 0.1.4
File Size Uploaded Provenance Actions
planarcurve-0.1.4.tar.gz 254.8 kB Without provenance Details for planarcurve-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for planarcurve 0.1.4
File Interpreter ABI Platform Actions
planarcurve-0.1.4-py3-none-any.whl Python 3 none any Details for planarcurve-0.1.4-py3-none-any.whl

Total release size: 318.1 kB

Release files / planarcurve-0.1.4.tar.gz

Download URL planarcurve-0.1.4.tar.gz
Size 254.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7b374ea1b6f222444d88640e4000809d0dd812ff131c1b57099805078e0ed4af
BLAKE2b-256 checksum
How to use checksums
89921cba1fb4143fdae6d5c52d1ed99c8bb56c5377f0781fa94e815489ed1e15
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.4-py3-none-any.whl

Download URL planarcurve-0.1.4-py3-none-any.whl
Size 63.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98a6f4b729bae44aa85c7ebfd6b58585cc91f51d9217d421aa6f6a4fe4812b43
BLAKE2b-256 checksum
How to use checksums
c6d1cd5012f1db02745a14f5ef774e0babfce12bd32a5a92870f982c8ec8bc2e
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.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page