Repository navigation
Add curve_points and curve_length utils: bezier control-point measurement - #1425
Open
payswapdotorg wants to merge 1 commit into
Open
payswapdotorg wants to merge 1 commit into
payswapdotorg wants to merge 1 commit into
Conversation
…ment The path attribute has exposed bezier control points since v0.11.0, but no measurement capability used them: endpoint-only distances under-read curved paths substantially (a quarter-arc by chord is ~10% short). - curve_points(curve): all control points of a curve object's path, in path order — the full drawn geometry, recoverable in one call. - curve_length(curve, n=32): the arc length in points — lines and closes contribute their euclidean lengths; each cubic segment is flattened at n sample points (t = k/n, direct Bernstein form) and contributes the chord sum. For a kappa-approximated quarter-arc of r=100 at the default n=32 the value is 157.08587595730572 (~4e-5 relative above the analytic arc — the kappa bezier deviates outward; the chord flattening inside it reads correspondingly low; the effects nearly cancel). Four new tests (173 -> 177): control-point order, exact line+close euclidean, the quarter-arc convergence with the pinned N=32 literal, and default-n + multi-subpath summation.
payswapdotorg
pushed a commit
to payswapdotorg/engineering-os
that referenced
this pull request
Nov 1, 2026
…plumber#1425 opened against develop from the payswapdotorg fork (ADR-0011 Stage 5's last open half, PAT-blocked since the thirty-second pass, user-confirmed): the branch re-cut off the pinned base 2fcbe6a via git am (develop's head verified EXACTLY the pin — no rebase), and the ENTIRE battery re-earned first-hand on the submission host before the push — baseline 173 passed, fail-on-prior 4 AttributeError failures, post-change 177 passed, black/isort(profile=black)/flake8/mypy all clean, and the bit-identity cross-check recomputed standalone: 157.08587595730572; the PR open + mergeable, 1 commit / 3 files / +162/−2; PR-TEXT.md + VERIFICATION.md updated with the SUBMITTED status and this host's numbers; the thirty-sixth pass recorded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SummaryThe
pathattribute has exposed bezier control points since v0.11.0, but nomeasurement capability uses them: the only length information on a curve
object is its bounding box, and endpoint-to-endpoint distances under-read
curved paths substantially — a kappa-approximated quarter-arc measured by its
chord is ~10% short (282.84 vs 314.20 at r=200, measured downstream in
[engineering takeoff tooling built on pdfplumber]).
This PR adds two utilities to
pdfplumber.utils:curve_points(curve)— all control points of a curve object's path, inpath order: the full drawn geometry (including the
ccommands' off-curvecontrol points), recoverable in one call.
curve_length(curve, n=32)— the arc length in points. Lines (l) andcloses (
h) contribute their euclidean lengths; each cubic bezier segment(
c) is flattened atnsample points (t = k/n,k = 1..n, directBernstein form) and contributes the chord sum — the standard flattening
approximation.
n < 1raisesValueError.The arithmetic, pinned
For a kappa-approximated quarter-arc of radius 100 (control constant
kappa = 0.5522847498307936), at the defaultn = 32:100 × π/2 = 157.07963267948966curve_length(...)returns157.08587595730572—3.97e-5relativeabove the analytic arc. The kappa bezier itself deviates outward from the
true circle (its length exceeds the arc's), while the chord flattening
inside the bezier reads correspondingly low; at
n = 32the two effectsnearly cancel. The test pins the exact literal.
Tests (173 → 177)
curve_pointsreturns the control points in path order (m / c / l / h).curve_lengthof a line-and-close path is the exact euclidean total.n = 32literal +< 1e-4relative vs the analytic arc.
n = 32equals an explicitn = 32; segment lengths sumacross subpaths (the same arc drawn twice = twice the single-arc length,
pinned at
1e-12— sequential float addition may differ from the exactdoubling in the last ulp).
Verification (the full record in VERIFICATION.md)
run against the pre-change tree fail with
AttributeError).black --check: clean ·isort --check-only --profile black: clean ·flake8: clean ·mypy pdfplumber/:Success: no issues found in 20 source files.n = 32literal is bit-identical to the value the downstreamengineering-takeoff harness computes with the same Bernstein-form
arithmetic at the same
n— the two implementations were writtenindependently and agree to the last bit.