Skip to content

Handwriting-like stroke order, row tuning, and pen-up metrics for G-code export#1

Open
RealBuddy wants to merge 4 commits into
mainfrom
experiment/gcode-pipeline
Open

Handwriting-like stroke order, row tuning, and pen-up metrics for G-code export#1
RealBuddy wants to merge 4 commits into
mainfrom
experiment/gcode-pipeline

Conversation

@RealBuddy

@RealBuddy RealBuddy commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

This branch delivers a single, opinionated stroke-ordering pipeline for Samsung Notes → GRBL G-code, tools to measure and tune it, and a sensible default row scale from optimization on a sample note.

Stroke ordering

  • One algorithm replaces the previous split between “global greedy” and “ruled-rows chain”: ruled rows (top-to-bottom), then horizontal bands inside each row (word-sized X gaps), greedy chain per band with backward-X penalty, debris (small marks) attached to the nearest band and drawn after that band.
  • Carriage hint on a new row: first stroke of the next row prefers a pen-down near extra lines × intra-line slack below the previous row’s bottom.
  • Legacy modes removed: --ruled-rows-order and order_strokes_writing_mode are gone; public entry is order_strokes().

Tuning & quality

  • RULED_LINE_ROW_HEIGHT_SCALE default set to 1.1 after --optimize-row-scale on the sample (min total pen-up XY travel for that file).
  • StrokeOrderTuning dataclass (x-gap factor, chain Y/back-X weights, intra-line slack, carriage multiplier) with defaults matching old hard-coded behavior; threaded through ordering and collect_strokes_mm_for_page / G-code build (optional stroke_order_tuning on the API).

CLI & metrics

  • samsung-notes metrics: per-page tables (--sweep-row-scale), sequential --optimize-row-scale [MIN:MAX:STEP] (default 0.8:2.5:0.1) for total pen-up mm across pages, plus 1D sweeps for order knobs: --optimize-x-gap-factor, --optimize-chain-y-weight, --optimize-chain-back-x-weight, --optimize-intra-line-y-factor, --optimize-carriage-y-lines (each optional MIN:MAX:STEP or built-in default when the flag is bare).
  • pen_up_travel_xy_mm() — sum of Euclidean XY jumps between consecutive stroke starts (matches emitted G0 travel between polylines).
  • --row-height-scale on gcode, inbox, and plot_strokes (--show-rows) so SVG row bands match the same grid as G-code when desired.

Docs

  • README updated for metrics, tuning flags, and the single ordering story.

Suggested review focus

  • Plot a sample .sdocx and compare visual row bands (plot_strokes --show-rows) vs pen-up from metrics when changing --row-height-scale.
  • Confirm GRBL output still matches your machine profile (preamble/Z feeds unchanged in spirit; only stroke order and optional scale/tuning inputs are new).

- Add extract_to_dict() and argparse-based extract CLI with -o/--output
- Replace plot_strokes subprocess with direct extract_to_dict import
- Add sdocx_gcode: px-to-mm scaling, Z pen lift profile, multi-page/M0
- Add samsung-notes entry point: extract, gcode, inbox batch
- Bundle default profile samsung_notes_profiles/grbl_plotter_z.toml
- Document pip install -e . and commands in README
- Ignore outbox, inbox, build, and egg-info
- Replace global (ymin, xmin) sort with ymin-sweep row bands and xmin within row
- Add --flip-y/--no-flip-y with default mirror for page-to-machine Y
- Update README and CLI help for writing-order and flip defaults
- Replace global greedy and ruled-rows chain with one order_strokes() path
  (ruled rows, horizontal bands, local greedy chain, debris per band, carriage Y)
- Remove --ruled-rows-order and ruled_rows_order from CLI/API
- G-code page comment: "reordered" when stroke reordering is on
- Update README and plot_strokes --show-rows help text
- Add pen_up_travel_xy_mm and samsung-notes metrics (sweep, optimize-row-scale)
- StrokeOrderTuning dataclass; thread row_height_scale and tuning through G-code path
- Sequential optimize sweeps for x-gap, chain weights, intra-line slack, carriage Y
- plot_strokes: optional --row-height-scale for row overlay
- Default RULED_LINE_ROW_HEIGHT_SCALE=1.1 after sample optimize
- README: metrics and tuning examples
@RealBuddy RealBuddy changed the title Experiment/gcode pipeline Handwriting-like stroke order, row tuning, and pen-up metrics for G-code export Apr 27, 2026
@RealBuddy
RealBuddy requested a review from bxff April 27, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant