Skip to main content

planarcurve

planarcurve provides numerical building blocks for planar curves and trajectories: polylines, Bezier curves, B-splines, normalized heading-rate trajectories, affine transforms, SVG paths, and fitting. Its core geometry API requires NumPy and does not depend on application-specific models.

Install

python -m pip install planarcurve

Install optional features as needed:

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]'     # SciPy and FontTools

For development, install planarcurve[dev].

Quick start

Resample a polyline by 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)

Polyline scoring

planarcurve.polyline.symmetric_polyline_distance(a, b, samples=64) resamples both polylines uniformly by arc length, computes nearest-segment distances in both directions, and returns their mean. The result uses the input coordinate units and does not depend on either polyline's vertex count.

mean_squared_turn_angle(points, samples=None) returns the mean squared angle between adjacent nonzero segments in radians squared. Supplying samples first resamples the polyline by arc length. SkeletonPaths uses this metric with 64 samples as a deterministic route tie-breaker.

import numpy as np
from planarcurve.polyline import mean_squared_turn_angle, symmetric_polyline_distance

points = np.array([[0.0, 0.0], [1.0, 1.0], [3.0, 0.0]])
other = points + np.array([0.0, 0.5])
print(symmetric_polyline_distance(points, other))
print(mean_squared_turn_angle(points, samples=64))

Create and sample 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))

u is normalized progress in [0, 1]. Heading-rate values are degrees per unit progress. Geometric curvature is signed inverse length and is exposed separately by planarcurve.trajectory.curvature; for a trajectory of length L, it equals radians(heading_rate) / L.

B-spline operations require SciPy:

import numpy as np
from planarcurve.spline import BSplineCurve

curve = BSplineCurve(
    knots=(0, 0, 0, 0, 0.5, 1, 1, 1, 1),
    control_points=((0, 0), (1, 2), (2, 3), (3, 2), (4, 0)),
)
sample = curve.sample_by_arclength(64)
path_segments = curve.to_cubic_segments(tolerance=1e-7)

SVG path parsing and conversion require FontTools. Fitting APIs live in planarcurve.fitting; see examples/fit_polyline_to_spline.py and examples/fit_shared_trajectory.py for complete workflows.

Concepts and numerical behavior

  • A trajectory's heading-rate profile is a function of normalized progress. Supported linear and cubic-Hermite profiles use an exact piecewise antiderivative for heading and total turn.
  • Trajectory positions integrate the heading-derived tangent numerically. Increasing the evaluation or integration resolution improves the position approximation.
  • Arc-length resampling approximates cumulative distance from sampled geometry. It is useful for uniform output spacing, but its accuracy depends on the sampling resolution.
  • trajectory_to_cubic_path adaptively subdivides a trajectory and checks the requested positional error at quarter, midpoint, and three-quarter samples of each piece. The tolerance is a sampled approximation criterion, not a formal continuous error bound.
  • Affine2D applies its linear transform and then translation. Similarity2D represents uniform scale, rotation, and translation.

Optional dependencies

The package core imports with NumPy only. planarcurve.spline uses SciPy, as do the fitting modules. planarcurve.svg uses FontTools. Installing the core package does not import these optional modules.

API stability

The package is pre-release and follows a 0.x compatibility policy. Public names and numerical behavior may change between minor releases. See the API docstrings and focused tests for current contracts.

Examples

Install all optional features and run the examples from a working directory of your choice:

python -m pip install 'planarcurve[all]'
python examples/curvature_gallery.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

The gallery and fitting examples write SVG files to the current directory. See examples/README.md for details.

Provenance

The generic numerical 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.0

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.0
File Size Uploaded Provenance Actions
planarcurve-0.1.0.tar.gz 83.6 kB Without provenance Details for planarcurve-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 122.1 kB

Release files / planarcurve-0.1.0.tar.gz

Download URL planarcurve-0.1.0.tar.gz
Size 83.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e5cf2950afccb02450ff64ff9adf372374a707f486d35c45ba7919fce633a128
BLAKE2b-256 checksum
How to use checksums
1fbdb2d92f2b6f286f283585f99143a7ba820b5fce92f8146638fec45fafb952
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.0-py3-none-any.whl

Download URL planarcurve-0.1.0-py3-none-any.whl
Size 38.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
caa72d19b45052ffa52518d5be2ff85c0afddd0ddee52f50d144bfa6a7359b27
BLAKE2b-256 checksum
How to use checksums
cb7b1bb8299d10042098fb8fb2085bff3aa8e480290b632eeb842aef041f2058
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.0

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