feat(python): expose path operations in extract_paths() dict#261
Open
willywg wants to merge 1 commit intoyfedoseev:mainfrom
Open
feat(python): expose path operations in extract_paths() dict#261willywg wants to merge 1 commit intoyfedoseev:mainfrom
willywg wants to merge 1 commit intoyfedoseev:mainfrom
Conversation
Add 'operations' field to the path dict returned by extract_paths(),
extract_lines(), and extract_rects() Python bindings.
Each operation is a dict with 'op' key and coordinates:
- move_to: {op, x, y}
- line_to: {op, x, y}
- curve_to: {op, cx1, cy1, cx2, cy2, x, y}
- rectangle: {op, x, y, width, height}
- close_path: {op}
This enables vector extraction use cases (snap-to-geometry, CAD overlays)
that need actual path coordinates, not just bounding boxes.
Relates to yfedoseev#147
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.
Description
Add an
operationsfield to the path dict returned byextract_paths(),extract_lines(), andextract_rects()Python bindings.Currently the Python API only exposes
operations_count(the number of path operations) but not the actual operations with their coordinates. This makes it impossible to access the precise vector geometry from Python — users only get the bounding box.Each operation is a dict with an
opkey and the relevant coordinates:move_to:{op, x, y}line_to:{op, x, y}curve_to:{op, cx1, cy1, cx2, cy2, x, y}rectangle:{op, x, y, width, height}close_path:{op}Use case: We're building a construction document processing platform that extracts vector geometry from architectural PDFs for snap-to-geometry and CAD overlay features. pdf_oxide is the fastest library we've tested, and this change makes it fully usable for our vector extraction pipeline.
Type of Change
Related Issues
Relates to #147 — This PR exposes the raw path operations to Python, which is a prerequisite for the
PathContent::to_points(tolerance)API discussed in that issue.Changes Made
path_to_py_dict()insrc/python.rsto include anoperationslist alongside the existingoperations_countPathOperationvariant is converted to a Python dict with theoptype and coordinatestest_extract_paths_operationstest intests/test_python.pyTesting
cargo test— 128 passed, 0 failed)cargo clippy -- -D warningspasses with no warningscargo fmt --checkpassesPython Bindings (if applicable)
ruff format— N/A (only added test, follows existing style)ruff check— N/ADocumentation
Checklist
Additional Notes
operations_countfield is preserved, and the newoperationsfield is simply added to the same dictPathOperationenum already had all the data; only the Python serialization inpath_to_py_dict()needed updating (~40 lines)f32as they come from the Rust struct, matching the existingbboxandstroke_widthprecision