moonbit-vector-trace-plan

A bitmap vector tracing and path planning library in MoonBit.

vector
trace
contour
potrace
path-planning
moon add zgfzgf899/moonbit-vector-trace-plan@0.2.0
Download zip
Author
Version
0.2.0
License
MIT
Last updated
2 hours ago
Downloads
2
README

#moonbit-vector-trace-plan

moonbit-vector-trace-plan is a pure MoonBit toolkit for converting packed-color raster images into editable vector paths and machine-oriented drawing plans. It is designed for deterministic geometry processing: the same image and options produce the same layers, paths, metrics, serialized output, and plan fingerprint across supported targets.

#Core capabilities

  • Raster image and binary-mask primitives with checked dimensions, morphology, connected components, skeletonization, distance fields, tiling, run-length encoding, filters, and metrics.
  • Moore-neighborhood contour tracing with color selection, palette analysis, topology diagnostics, hole handling, and configurable component filtering.
  • Vector IR for points, rectangles, bounds, line/quadratic/cubic paths, color layers, and manifests.
  • Geometry algorithms including clipping, convex hulls, triangulation, polygon predicates, offsets, arrangements, mesh operations, and spatial hit testing.
  • Simplification with RDP, radial filtering, Visvalingam-Whyatt, Chaikin smoothing, adaptive modes, corner preservation, Bézier fitting, and deterministic noise cleanup.
  • Path planning with order-preserving and nearest-neighbor strategies, reversal, two-opt improvement, machine commands, G-code/CSV export, scheduling, safety normalization, and timing estimates.

#Quick start

Install the current stable MoonBit CLI from the official installer, then verify the toolchain:

moon version --all moon check --target all --deny-warn moon test --target all --deny-warn

The library is organized as local MoonBit packages, so it can be consumed from a MoonBit workspace by importing the package paths listed in moon.pkg files.

#CLI

Run the small deterministic demonstration:

moon run cmd/main

Run the reproducible benchmark fixture:

moon run --target native --release cmd/bench

The benchmark prints image dimensions, color count, traced layers/paths/points, drawing and travel lengths, machine-time estimate, manifest fingerprint, and SVG byte count. It does not use synthetic timing values in its output.

#Architecture

lib/core data model, geometry primitives, transforms, validation, export helpers lib/raster masks, components, morphology, skeletons, filters, tiles, graph metrics lib/geometry polygon algorithms, clipping, hulls, triangulation, offsets, meshes lib/simplify RDP and advanced simplification, Bézier fitting, noise cleanup lib/trace tracing, color/palette analysis, topology, polygonization, reports, exports lib/plan route planning, machine commands, scheduling, optimization, timing cmd/main runnable end-to-end example cmd/bench fixed-fixture benchmark and diagnostics

The dependency direction is intentionally one-way: core is foundational; raster and geometry build on it; simplify uses core/geometry; trace composes those packages; plan consumes core paths. Generated interfaces are produced by MoonBit and are not hand-edited.

#Benchmarks

The checked-in fixture is a deterministic 128 × 128 raster containing three foreground colors. On Windows 11, PowerShell, Moon 0.1.20260807 / Moonc 0.10.7+bc794d341, the command below was measured five times after the native release target was warm:

moon run --target native --release cmd/bench wall time: min 275.43 ms, median 292.83 ms, mean 290.36 ms, max 299.81 ms trace: 3 layers, 33 paths, 72 points, 105 segments plan: 318 commands, drawing length 655.6812408671319, travel length 556.9027543437462 export: SVG 3825 bytes, fingerprint 2265334813485276573

Wall time includes the CLI process and Moon runner overhead; it is a reproducibility baseline, not a platform-independent microbenchmark. Re-run the command on the target machine before comparing changes.

#Tests and source scale

The repository contains 86 executable MoonBit tests, including empty inputs, invalid dimensions, degenerate geometry, touching borders, disconnected components, diagonal connectivity, single pixels, partial tiles, malformed runs, topology round trips, route safety, and serialization boundaries.

The local source-scale check currently reports 12,556 non-empty .mbt lines across 71 files: 11,291 production lines and 1,265 test lines. The count excludes _build artifacts and is generated from the working tree rather than being a hand-entered claim.

moon check --target all --deny-warn moon test --target all --deny-warn

#CI

GitHub Actions checks Ubuntu, macOS, and Windows. Each job installs the current stable MoonBit CLI, runs moon version --all, updates dependencies, verifies formatting and generated interfaces, checks all targets with warnings denied, runs all-target tests, and enforces the repository source-scale check. See .github/workflows/test.yml.

#License

MIT. See LICENSE.