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

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.2

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.2
File Size Uploaded Provenance Actions
planarcurve-0.1.2.tar.gz 208.6 kB Without provenance Details for planarcurve-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 257.7 kB

Release files / planarcurve-0.1.2.tar.gz

Download URL planarcurve-0.1.2.tar.gz
Size 208.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6fcdfd642cc66cd22e585d378489df91e8b57e1634baa168ce1a704cb79dc3dc
BLAKE2b-256 checksum
How to use checksums
e8d05f3b01b847cab66e7eb81b8a4e009d41e0fce77bae92718f7945922c499f
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.2-py3-none-any.whl

Download URL planarcurve-0.1.2-py3-none-any.whl
Size 49.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2eff2373651e42b8e25a168b5fda842238ac7263a6c7d3c7c7e2e5aae40c9b4
BLAKE2b-256 checksum
How to use checksums
055f7f4d1af5e98cd71fde95150bf81d41523491d77c692694e0b75c004880d7
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.2

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