bulge_gcode 0.1.1

A lightweight G-Code generator for Polylines with Bulge support (CNC/DXF style), WASM compatible.
Documentation
  • Coverage
  • 0%
    0 out of 37 items documented0 out of 17 items with examples
  • Size
  • Source code size: 16.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.63 MB This is the summed size of all files generated by rustdoc for all configured targets
  • ร˜ build duration
  • this release: 29s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sagittaracc/bulge-gcode
    0 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sagittaracc

Bulge G-Code Builder ๐Ÿ› ๏ธ

Wasm Support License: MIT

A high-performance library for converting geometry defined as Polylines (with Bulge parameters) into CNC-compatible G-Code. Written in Rust and available for WebAssembly.


โ“ Why Bulge?

In CAD systems like AutoCAD (DXF), arcs are often stored not as centers and radii, but as a Bulge value on a polyline vertex.

  • Calculating the center, radius, and start/end angles manually is tedious and error-prone.
  • This library handles all the math for you. It converts Bulge-defined segments directly into standard G02/G03 (CW/CCW) circular interpolation commands, saving you hours of geometry implementation.

๐Ÿš€ Installation

For Rust Projects

Add this to your Cargo.toml:

[dependencies]
bulge_gcode = { git = "https://github.com/sagittaracc/bulge-gcode" }

For Web / Node.js (WASM)

Download the latest archive from the Releases page.

import init, { generate_gcode } from './pkg/web/bulge_gcode.js';

๐Ÿ’ป Usage

Rust Example

use bulge_gcode::{Vertex, Polyline, GCodeBuilder, CoordinateMode};

fn main() {
    let mut pline = Polyline::new();

    // Circle centered at (0,0) with radius 5.0
    // Parameters: x, y, bulge
    
    // First vertex: upper point of the circle
    // Bulge -1.0 creates a clockwise semicircle
    pline.add_vertex(Vertex::new(0.0, 5.0, -1.0)); 

    // Second vertex: lower point of the circle
    // Bulge -1.0 completes the clockwise circle
    pline.add_vertex(Vertex::new(0.0, -5.0, -1.0)); 

    // Ensure the polyline closes back to the first vertex
    pline.closed = true;

    let builder = GCodeBuilder::new(pline)
        .with_mode(CoordinateMode::Absolute);

    match builder.build() {
        Some(code) => println!("{}", code),
        None => println!(""),
    }
}

WASM / JavaScript Example

// Data format: [x, y, bulge, x, y, bulge, ...]
const data = new Float64Array([0, 5, -1, 0, -5, -1]);
const places = 3;   // Decimal places
const scale = 1.0;  // Multiplier (e.g., 1000 for microns)

const gcode = generate_gcode(data, true, true, places, scale);
console.log(gcode);

๐Ÿ›  Features

  • Arc Support: Full support for circular interpolation via Bulge.
  • Precision Control: Configurable decimal places and scaling (microns/mm/inches).
  • Dialects: Support for both G0/G1 and G00/G01 command styles.
  • Cross-Platform: Works in native Rust, Browser, and Node.js.

๐Ÿงช Development

Run tests: cargo test
Build all WASM targets: ./build.sh


Licensed under MIT/Apache.