moonnest

    Deterministic polygon nesting and no-fit nesting for MoonBit, built on MoonClip exact geometry.

    nesting
    geometry
    computational-geometry
    optimization
    moonclip
    Download zip
    Author
    Version
    0.3.2
    License
    Apache-2.0
    Last updated
    4 hours ago
    Downloads
    2

    #MoonNest

    MoonNest is a deterministic polygon nesting library and command-line tool for MoonBit. It quantizes decimal JSON geometry to an integer grid, generates rotation and translation candidates, and verifies placements with exact polygon predicates.

    #Run

    moon run cmd/moonnest -- nest examples/demo.json -o layout.json --svg layout.svg --stats moon run cmd/moonnest -- nfp examples/demo.json --all-regions --workers 4 -o nfp.json moon run cmd/moonnest -- validate examples/demo.json moon run cmd/moonnest -- inspect examples/demo.json --pretty moon run cmd/moonnest -- benchmark examples --workers 4 -o benchmark.json moon run cmd/moonnest -- verify examples/demo.json -o verification.json moon run cmd/moonnest -- cut examples/demo.json -o cutting.json --svg cutting.svg moon run cmd/moonnest -- schedule examples/production.json --format json moon run cmd/moonnest -- version

    Both nest and nfp accept --precision 0..6; the default is three fractional digits. Use - for standard input or output. nest supports JSON, SVG, CSV and text output, --config, --explain, --debug-svg and --pretty.

    #Input format

    { "sheet": { "contour": [ { "x": 0, "y": 0 }, { "x": 100, "y": 0 }, { "x": 100, "y": 60 }, { "x": 0, "y": 60 } ], "holes": [] }, "parts": [ { "id": "bracket", "quantity": 4, "contours": [ [ { "x": 0, "y": 0 }, { "x": 20, "y": 0 }, { "x": 20, "y": 10 }, { "x": 0, "y": 10 } ] ], "holes": [ [ { "x": 4, "y": 2 }, { "x": 8, "y": 2 }, { "x": 8, "y": 8 }, { "x": 4, "y": 8 } ] ] } ], "gap": 0.75, "margin": 1, "rotations": { "step_degrees": 15 } }

    Contours are closed rings of at least three points. sheet.holes and parts[].holes default to empty. Multiple filled islands can be supplied in contours. Coordinates, gap, and margin are quantized before geometry operations. The supported coordinate range is ±1,000,000,000 grid units per axis.

    rotations.step_degrees must be zero or divide 90. Zero enables rotations every five degrees; 90 enables right angles. Identical rotated geometries are deduplicated.

    #Inventory, fixed instances and quality regions

    A sheets array can replace the single sheet field:

    { "sheets": [ { "id": "small", "quantity": 1, "cost": 1, "contour": [{ "x": 0, "y": 0 }, { "x": 10, "y": 0 }, { "x": 10, "y": 10 }, { "x": 0, "y": 10 }], "holes": [] } ], "parts": [] }

    Fixed instances and preoccupied material are expressed in sheet coordinates:

    { "fixed": [ { "part": 0, "sheet": 0, "rotation_degrees": 0, "x": 0, "y": 0 } ], "preoccupied": [ { "sheet": 0, "contours": [[{ "x": 20, "y": 0 }, { "x": 30, "y": 0 }, { "x": 30, "y": 10 }, { "x": 20, "y": 10 }]] } ] }

    Quality regions use kind values forbidden, restricted, high_value, and defect. Restricted regions list eligible part indices in parts; weighted regions influence deterministic candidate scoring.

    #Part rules and suites

    Each part may define:

    { "rules": { "rotations": [0, 90], "mirror": true, "priority": 10, "sheets": [0], "min_quantity": 1, "group": "kit", "label": "bracket", "metadata": { "material": "steel" } } }

    Suites place inner parts into holes of an outer part:

    { "suites": [{ "id": "assembly", "outer": 0, "inner": [1] }] }

    #Manufacturing constraints

    machine validates stock against a machine envelope. Part rules accept grain_degrees, grain_tolerance_degrees, rotation_setup_cost, and edge_clearance. cutting configures the weighted rapid-travel/pierce objective, safe height, lead-in, and lead-out. production defines machines and dated jobs for deterministic due-date/setup-cost scheduling.

    { "machine": { "id": "laser-1", "max_width": 500, "max_height": 400 }, "cutting": { "rapid_weight": 1, "cut_weight": 0.1, "pierce_weight": 1, "pierce_cost": 1, "safe_height": 5, "lead_in": 2, "lead_out": 2 }, "production": { "machines": [{ "id": "laser-1", "available_minute": 0 }], "jobs": [ { "id": "job-1", "part": 0, "quantity": 10, "due_minute": 480, "priority": 10, "setup_group": "steel", "duration_minutes": 120, "setup_minutes": 15 } ], "due_weight": 1, "setup_weight": 1 } }

    gap and margin remain uniform defaults. margin also accepts { "top": 0, "right": 0, "bottom": 0, "left": 0 }. Additional controls are:

    • parts[].gap: symmetric part-level clearance override.
    • pair_gaps: symmetric overrides between two part indices.
    • hole_clearance: safety clearance around sheet holes.
    • join: miter, bevel, square, or round.
    • strategies: independent order, gravity, and scoring combinations.
    • budget: max_nodes, max_backtracks, beam_width, workers, max_milliseconds, and max_candidates.

    { "strategies": [ { "order": "area", "gravity": "left_bottom", "scoring": "distance" }, { "order": "longest_side", "gravity": "right_bottom", "scoring": "composite" } ], "budget": { "max_nodes": 1000, "max_backtracks": 4, "beam_width": 2, "workers": 4, "max_candidates": 500000 } }

    • Parts are normalized into counterclockwise outer contours and clockwise holes. Sheet holes are excluded from the usable region.
    • margin insets the sheet outline. gap expands placed material before sheet containment and pairwise collision checks.
    • Candidate sources include sheet corners, vertex contacts, NFP edges, hole interiors, and fixed points.
    • Orthogonal geometry uses exact grid decomposition for no-fit regions, collision predicates, and unused-material reporting.
    • Non-orthogonal no-fit queries use convex decomposition, Minkowski sums, and a normalized union boundary with clockwise holes. NoFitRegion::contains applies nonzero winding to the pre-display-quantization floating-point boundary and treats contour contact as allowed. JSON, CLI, and web outputs expose both integer contours and floating-point exact_contours. The library field uses grid units; JSON divides it by the nesting scale to emit input units.
    • Search supports priority ordering, multiple deterministic strategies, bounded backtracking, true beam search, left/bottom or alternate-corner compaction, local reinsertion, rotation replay, instance swaps, and suite nesting.
    • Local improvement supports non-orthogonal material and never moves fixed instances.
    • Fixed instances participate in collision and quality checks but are never moved by search or compaction.
    • nest_with_transforms_async can run independent strategies concurrently under budget.workers; the synchronous API remains serial for compatibility.
    • budget.max_milliseconds is a global deadline shared by all strategies and bounds search and post-processing. Layout JSON reports deterministic cache_hits; CLI --stats reports elapsed time, and --timeout-ms overrides the input budget.
    • CLI benchmark --workers N runs independent inputs in separate native processes, merges results by input index, and reports peak_memory_bytes.
    • CLI nfp --all-regions --workers N partitions ordered part/rotation tasks into native subprocesses and merges raw JSON chunks in serial task order.
    • max_candidates bounds total candidate evaluations across search, local improvement, and compression without relying on wall-clock timing.

    #Output format

    Layout::to_json emits:

    • width, height, precision, area2, and quality_cost.
    • contours and legacy contour-level placements.
    • Stable instances with part sequence, sheet, transform, anchors, contour and hole indices, and fixed/searched origin.
    • Per-sheet sheets with inventory identity, utilization, hole area, clearance area, unused area, and unused contours.
    • Structured unplaced_details, material report, compaction statistics, strategy summaries, winning strategy, search budget, nodes, and backtracks.
    • Resolved suites hierarchy.
    • cache_hits and the complete search budget, including max_milliseconds. CLI --stats and benchmark reports include elapsed time.

    Layout::to_svg produces a standalone SVG. NestingResult::to_debug_svg adds source anchors, local anchors, and translation vectors.

    #Library API

    ///|
    let problem = @moonnest.Problem::from_json(input_json, precision={
    digits: Some(3),
    })

    ///|
    let result = @moonnest.nest_with_transforms(problem)

    ///|
    let parallel_result = @moonnest.nest_with_transforms_async(problem)

    ///|
    let layout_json = result.layout.to_json()

    ///|
    let svg = result.layout.to_svg()

    ///|
    let debug_svg = result.to_debug_svg()

    ///|
    let regions = @moonnest.no_fit_regions(problem)

    ///|
    let orientations = @moonnest.no_fit_orientations(problem, 0)

    ///|
    let region = @moonnest.no_fit_region_for(problem, 0, 1, 0, 0)

    ///|
    let diagnostics = @moonnest.diagnose_geometry(problem)

    PlacementTransform::to_sheet, to_output, and to_source share one anchor model. Right-angle transforms round-trip exactly; arbitrary-angle transforms use the same deterministic grid rounding as placement.

    #Web package

    The web package is a thin JSON wrapper around the native engine:

    moon build web --target wasm moon build web/demo --target js

    It exports nest_json, nfp_regions_json, and inspect_json. After building the JS demo, open web/demo/index.html in a browser to edit JSON, run nesting, inspect complete NFP regions, and render the resulting layout.

    #Examples

    examples/ contains rectangle packing, concave parts, hole suites, multi-sheet inventory, fixed/preoccupied layouts, spacing controls, and multi-strategy search.

    #Tests and build

    moon fmt moon check --target all --deny-warn moon test --target all moon test --target all --release moon build --target native moon build web --target wasm moon build web/demo --target js moon build cmd/moonnest --target native --release python scripts/generate_benchmarks.py

    Tests cover public APIs, geometry diagnostics, exact NFP membership, anchors, spacing, inventory, fixed instances, quality regions, strategies, budgets, compaction, local improvement, suites, JSON/SVG serialization, determinism, and CLI parsing, manufacturing constraints, cutting paths, scheduling, layout verification, time budgets, and telemetry.

    bench/ contains graded 10/50/100/300-instance cases plus multi-sheet and multi-rotation workloads. Benchmarks use deterministic node and candidate budgets, so parallel execution changes elapsed time but not placement or work counters. benchmark --repeat N reports mean, p50, p95, minimum, maximum, and peak memory. --check enforces --max-ms, --max-memory-mb, --min-utilization-pct, and --max-unplaced gates.

    moon run cmd/moonnest -- benchmark bench --workers 4 --repeat 3 --check \ --max-ms 120000 --max-memory-mb 4096 --max-unplaced 10000 python scripts/verify_performance.py python scripts/benchmark_nfp.py

    Current Windows release baseline with the generated budgets:

    CasePlacedUnplacedElapsed
    10 rectangles1000.29s
    50 mixed5002.96s
    100 hole parts71293.77s
    300 stress792215.66s
    Multi-sheet6003.36s
    Multi-rotation30034.68s

    The six-case serial benchmark completed in 51.32s; four benchmark processes completed it in 35.98s (1.43x) with identical deterministic records. The 24,960-region NFP benchmark completed in 1.37s serially and 1.02s with four workers (1.35x), with byte-identical JSON. These cases establish a reproducible baseline, not a production placement-quality guarantee.

    #Limitations

    MoonNest is a deterministic heuristic packer, not a global optimizer or a proof of optimal utilization. Non-orthogonal NFP contours are quantized to the configured integer grid; exact_contours are pre-display-quantization floating-point boundaries, not mathematically exact rational rings. Library strategy concurrency follows MoonBit runtime scheduling, while CLI benchmark and NFP subprocess parallelism are the validated CPU-scaling paths. Wall-clock deadlines are cooperative; max_candidates is the deterministic work limit.

    NestError

    pub(all) suberror NestError {
    PlacementFailed(String)
    JsonError(String)
    } derive(Eq,
    Debug
    )

    CandidateScoring

    pub(all) enum CandidateScoring {
    Distance
    BoundsArea
    Utilization
    FutureSpace
    Composite
    } derive(Eq,
    Debug
    )

    Candidate scoring formula.

    CandidateSource

    pub(all) enum CandidateSource {
    SheetCorner
    VertexContact
    NfpEdge
    HoleInterior
    FixedPoint
    } derive(Eq,
    Debug
    )

    Origin of a generated placement candidate.

    CompressionReport

    pub(all) struct CompressionReport {
    before_width : Double
    before_height : Double
    after_width : Double
    after_height : Double
    iterations : Int
    } derive(Eq,
    Debug
    )

    Deterministic compaction statistics.

    CompressionReport::default

    Contact

    pub(all) enum Contact {
    Clear
    Touch
    Overlap
    } derive(Eq,
    Debug
    )

    CuttingConfig

    pub(all) struct CuttingConfig {
    rapid_weight : Double
    cut_weight : Double
    pierce_weight : Double
    pierce_cost : Double
    safe_height : Double
    lead_in : Double
    lead_out : Double
    } derive(Eq,
    Debug
    )

    Weighted cutting-path objective and machine clearance parameters.

    CuttingConfig::default

    fn CuttingConfig::default() -> CuttingConfig

    CuttingMove

    pub(all) struct CuttingMove {
    kind : CuttingMoveKind
    contour_index : Int
    instance_id : Int
    from_x : Double
    from_y : Double
    to_x : Double
    to_y : Double
    safe_height : Double
    } derive(Eq,
    Debug
    )

    CuttingMoveKind

    pub(all) enum CuttingMoveKind {
    Rapid
    Pierce
    LeadIn
    Cut
    LeadOut
    } derive(Eq,
    Debug
    )

    CuttingPlan

    pub(all) struct CuttingPlan {
    moves : Array[CuttingMove]
    rapid_distance : Double
    cut_distance : Double
    pierces : Int
    cost : Double
    } derive(Eq,
    Debug
    )

    CuttingPlan::to_json

    Serializes the cutting plan with coordinates in input units.

    CuttingPlan::to_svg

    fn CuttingPlan::to_svg(self : CuttingPlan, precision? : Precision) -> String raise NestError

    Renders the cutting plan as a standalone SVG in input units.

    FixedPlacement

    pub(all) struct FixedPlacement {
    part : Int
    sheet : Int
    rotation_degrees : Int
    mirrored : Bool
    translation_x : Int64
    translation_y : Int64
    } derive(Eq,
    Debug
    )

    A fixed instance translation in normalized part coordinates.

    GapJoin

    pub(all) enum GapJoin {
    Round
    Bevel
    Miter
    Square
    } derive(Eq,
    Debug
    )

    Corner strategy used when expanding material for clearance.

    GeometryDiagnostic

    pub(all) struct GeometryDiagnostic {
    subject : String
    ring : String
    contour_index : Int
    issue : GeometryIssue
    message : String
    } derive(Eq,
    Debug
    )

    A geometry diagnostic tied to a source object and ring index.

    GeometryIssue

    pub(all) enum GeometryIssue {
    CoordinateRange
    DuplicatePoint
    ZeroArea
    SelfIntersection
    HoleOutside
    HoleIntersection
    IslandOverlap
    QuantizedCollapse
    } derive(Eq,
    Debug
    )

    A structured geometry validation finding.

    Gravity

    pub(all) enum Gravity {
    LeftBottom
    RightBottom
    LeftTop
    RightTop
    } derive(Eq,
    Debug
    )

    Gravity direction used for candidate scoring and compaction.

    Instance

    pub(all) struct Instance {
    instance_id : Int
    part : Int
    part_instance_index : Int
    sheet : Int
    rotation_degrees : Int
    mirrored : Bool
    translation_x : Int64
    translation_y : Int64
    source_anchor_x : Int64
    source_anchor_y : Int64
    final_anchor_x : Int64
    final_anchor_y : Int64
    contour_indices : Array[Int]
    hole_indices : Array[Int]
    origin : PlacementOrigin
    } derive(Eq,
    Debug
    )

    A stable instance record independent of output contour numbering.

    Layout

    pub(all) struct Layout {
    width : Double
    height : Double
    area2 : Int64
    quality_cost : Int64
    contours : Array[Array[
    Point64
    ]]
    placements : Array[Placement]
    instances : Array[Instance]
    sheets : Array[SheetLayout]
    unplaced : Array[Int]
    unplaced_details : Array[UnplacedInstance]
    report : MaterialReport
    compression : CompressionReport
    winning_strategy : Int
    strategy_summaries : Array[StrategySummary]
    budget : SearchBudget
    nodes : Int
    backtracks : Int
    budget_exhausted : Bool
    suites : Array[SuiteLayout]
    iterations : Int
    trials : Int
    cache_hits : Int
    precision : Precision
    } derive(Eq,
    Debug
    )

    A complete layout. area2 is twice the occupied material area in the configured integer grid, including negative hole contours.

    Layout::to_json

    fn Layout::to_json(self : Layout, precision? : Precision) ->
    Json
    raise NestError

    Serializes a layout to the public JSON format.

    Layout::to_svg

    fn Layout::to_svg(self : Layout, precision? : Precision) -> String raise NestError

    Renders the layout as a standalone SVG.

    MachineSpec

    pub(all) struct MachineSpec {
    id : String
    max_width : Double
    max_height : Double
    } derive(Eq,
    Debug
    )

    Machine envelope used to validate stock dimensions before nesting.

    MaterialReport

    pub(all) struct MaterialReport {
    width : Double
    height : Double
    hole_area2 : Int64
    gap_area2 : Int64
    unused_area2 : Int64
    part_totals : Array[PartTotal]
    } derive(Eq,
    Debug
    )

    Material and utilization report for a complete layout.

    MaterialReport::default

    NestingResult

    pub(all) struct NestingResult {
    layout : Layout
    transforms : Array[PlacementTransform]
    } derive(Eq,
    Debug
    )

    A layout together with the coordinate transforms that produced it.

    NestingResult::to_debug_svg

    fn NestingResult::to_debug_svg(self : NestingResult, precision? : Precision) -> String raise NestError

    Renders the layout with source anchors, local anchors and translation vectors for every placed instance.

    NoFitPolygon

    pub(all) struct NoFitPolygon {
    moving : Int
    stationary : Int
    moving_degrees : Int
    stationary_degrees : Int
    moving_mirrored : Bool
    stationary_mirrored : Bool
    contour : Array[
    Point64
    ]
    precision : Precision
    } derive(Eq,
    Debug
    )

    A no-fit polygon for one ordered pair of part types and rotations.

    NoFitPolygon::to_json

    Serializes a representative no-fit polygon.

    NoFitRegion

    pub(all) struct NoFitRegion {
    moving : Int
    stationary : Int
    moving_degrees : Int
    stationary_degrees : Int
    moving_mirrored : Bool
    stationary_mirrored : Bool
    contours : Array[Array[
    Point64
    ]]
    exact_contours : Array[Array[(Double, Double)]]
    precision : Precision
    } derive(Eq,
    Debug
    )

    A complete no-fit region. Positive contours are forbidden outer regions and negative contours are holes where the moving part may fit without overlap. exact_contours preserves the pre-display-quantization floating-point boundary for membership tests and JSON output.

    NoFitRegion::contains

    fn NoFitRegion::contains(self : NoFitRegion, point :
    Point64
    ) -> Bool

    Tests forbidden-region membership using nonzero winding. Boundary-only contact is not considered forbidden unless another contour covers it.

    NoFitRegion::to_json

    Serializes a complete no-fit region.

    PairGap

    pub(all) struct PairGap {
    first : Int
    second : Int
    gap : Double
    } derive(Eq,
    Debug
    )

    A symmetric clearance override between two part types.

    Part

    pub(all) struct Part {
    id : String
    quantity : Int
    contours : Array[Array[
    Point64
    ]]
    holes : Array[Array[
    Point64
    ]]
    gap : Double?
    rules : PartRules
    } derive(Eq,
    Debug
    )

    A part definition. Contours are filled islands and holes are excluded.

    PartOrder

    pub(all) enum PartOrder {
    Area
    LongestSide
    Perimeter
    BoundsArea
    } derive(Eq,
    Debug
    )

    Part ordering used by a deterministic search strategy.

    PartRules

    pub(all) struct PartRules {
    rotations : Array[Int]?
    mirror : Bool
    priority : Int
    sheets : Array[Int]?
    min_quantity : Int
    group : String?
    label : String?
    metadata : Array[(String, String)]
    grain_degrees : Int?
    grain_tolerance_degrees : Int
    rotation_setup_cost : Double
    edge_clearance : Double
    } derive(Eq,
    Debug
    )

    Optional per-part rules. Defaults inherit the problem-wide policy.

    PartRules::default

    fn PartRules::default() -> PartRules

    PartTotal

    pub(all) struct PartTotal {
    part : Int
    count : Int
    area2 : Int64
    } derive(Eq,
    Debug
    )

    Aggregate material quantity for one part type.

    Placement

    pub(all) struct Placement {
    instance_id : Int
    sheet : Int
    part : Int
    contour_index : Int
    rotation_degrees : Int
    mirrored : Bool
    source_x : Double
    source_y : Double
    origin : PlacementOrigin
    } derive(Eq,
    Debug
    )

    Maps one placed instance to its output contours.

    PlacementOrigin

    pub(all) enum PlacementOrigin {
    Fixed
    Searched
    } derive(Eq,
    Debug
    )

    Whether an instance was supplied or generated by the search.

    PlacementTransform

    pub(all) struct PlacementTransform {
    instance_id : Int
    part : Int
    rotation_degrees : Int
    mirrored : Bool
    source_anchor_x : Int64
    source_anchor_y : Int64
    rotated_anchor_x : Int64
    rotated_anchor_y : Int64
    translation_x : Int64
    translation_y : Int64
    output_origin_x : Int64
    output_origin_y : Int64
    origin : PlacementOrigin
    } derive(Eq,
    Debug
    )

    Reversible coordinate transform for one placed instance. All anchors and translations use the configured integer grid.

    PlacementTransform::to_output

    Maps a point from input coordinates to normalized output coordinates.

    PlacementTransform::to_sheet

    Maps a point from input coordinates to sheet coordinates.

    PlacementTransform::to_source

    Maps a point from normalized output coordinates back to input coordinates. Arbitrary-angle rotations use the same grid rounding as placement.

    Precision

    pub(all) struct Precision {
    digits : Int?
    } derive(Eq,
    Debug
    )

    Optional decimal precision. None uses three fractional digits.

    PreoccupiedRegion

    pub(all) struct PreoccupiedRegion {
    sheet : Int
    contours : Array[Array[
    Point64
    ]]
    } derive(Eq,
    Debug
    )

    Material that is already unavailable on a sheet.

    Problem

    pub(all) struct Problem {
    sheet : Stock
    sheets : Array[SheetSpec]?
    parts : Array[Part]
    gap : Double
    margin : Double
    sheet_margin : SheetMargin?
    pair_gaps : Array[PairGap]
    hole_clearance : Double
    join : GapJoin
    fixed : Array[FixedPlacement]
    preoccupied : Array[PreoccupiedRegion]
    quality_regions : Array[QualityRegion]
    strategies : Array[SearchStrategy]?
    budget : SearchBudget
    suites : Array[SuiteSpec]
    precision : Precision?
    rotations : RotationPolicy
    machine : MachineSpec?
    cutting : CuttingConfig?
    production : ProductionConfig?
    } derive(Eq,
    Debug
    )

    A complete nesting problem.

    Problem::from_json

    fn Problem::from_json(value :
    Json
    , precision? : Precision) -> Problem raise NestError

    Converts JSON into a nesting problem, quantizing fractional coordinates.

    Problem::validate

    fn Problem::validate(parts : Array[Part], margin : Double, gap : Double, precision~ : Precision) -> Unit raise NestError

    Validates part geometry and quantities without a sheet.

    ProductionConfig

    pub(all) struct ProductionConfig {
    machines : Array[ProductionMachine]
    jobs : Array[ProductionJob]
    due_weight : Double
    setup_weight : Double
    } derive(Eq,
    Debug
    )

    Deterministic due-date and setup-cost scheduling configuration.

    ProductionConfig::default

    ProductionJob

    pub(all) struct ProductionJob {
    id : String
    part : Int
    quantity : Int
    due_minute : Int
    priority : Int
    setup_group : String
    duration_minutes : Int
    setup_minutes : Int
    } derive(Eq,
    Debug
    )

    One production order for a part type.

    ProductionMachine

    pub(all) struct ProductionMachine {
    id : String
    available_minute : Int
    } derive(Eq,
    Debug
    )

    A production machine available at a specific minute.

    QualityKind

    pub(all) enum QualityKind {
    Forbidden
    PartRestricted
    HighValue
    Defect
    } derive(Eq,
    Debug
    )

    Semantic role of a sheet quality region.

    QualityRegion

    pub(all) struct QualityRegion {
    sheet : Int
    kind : QualityKind
    contours : Array[Array[
    Point64
    ]]
    parts : Array[Int]
    weight : Double
    } derive(Eq,
    Debug
    )

    A sheet region that participates in feasibility or scoring.

    RotationPolicy

    pub(all) struct RotationPolicy {
    step_degrees : Int
    } derive(Eq,
    Debug
    )

    Rotation stride in degrees. Zero means every five degrees.

    SchedulePlan

    pub(all) struct SchedulePlan {
    entries : Array[ScheduledJob]
    total_setup_minutes : Int
    total_tardiness_minutes : Int
    cost : Double
    } derive(Eq,
    Debug
    )

    SchedulePlan::to_csv

    fn SchedulePlan::to_csv(self : SchedulePlan) -> String

    SchedulePlan::to_json

    ScheduledJob

    pub(all) struct ScheduledJob {
    job_id : String
    machine_id : String
    start_minute : Int
    end_minute : Int
    setup_minutes : Int
    tardiness_minutes : Int
    } derive(Eq,
    Debug
    )

    SearchBudget

    pub(all) struct SearchBudget {
    max_nodes : Int
    max_backtracks : Int
    beam_width : Int
    workers : Int
    max_milliseconds : Int64
    max_candidates : Int
    } derive(Eq,
    Debug
    )

    Explicit search limits. Zero disables the corresponding limit; beam width defaults to one.

    SearchBudget::default

    fn SearchBudget::default() -> SearchBudget

    SearchStrategy

    pub(all) struct SearchStrategy {
    order : PartOrder
    gravity : Gravity
    scoring : CandidateScoring
    } derive(Eq,
    Debug
    )

    One deterministic search strategy.

    SearchStrategy::default

    SheetLayout

    pub(all) struct SheetLayout {
    sheet : Int
    sheet_id : String
    instance_ids : Array[Int]
    contour_indices : Array[Int]
    width : Double
    height : Double
    material_area2 : Int64
    used_area2 : Int64
    hole_area2 : Int64
    gap_area2 : Int64
    unused_area2 : Int64
    utilization : Double
    unused : Array[Array[
    Point64
    ]]
    } derive(Eq,
    Debug
    )

    Per-sheet layout summary and unused material.

    SheetMargin

    pub(all) struct SheetMargin {
    top : Double
    right : Double
    bottom : Double
    left : Double
    } derive(Eq,
    Debug
    )

    Independent sheet edge margins in input units.

    SheetSpec

    pub(all) struct SheetSpec {
    id : String
    stock : Stock
    quantity : Int
    cost : Double
    } derive(Eq,
    Debug
    )

    A sheet stock specification and inventory quantity.

    Stats

    pub(all) struct Stats {
    iterations : Int
    placements : Int
    rejected : Int
    nfps : Int
    candidates : Int
    nodes : Int
    backtracks : Int
    budget_exhausted : Bool
    elapsed_ms : Double
    cache_hits : Int
    started_at :
    Timestamp

    } derive(
    Debug
    )

    Work counters for a nesting run.

    Stock

    Sheet outline and unavailable holes.

    StrategySummary

    pub(all) struct StrategySummary {
    sheet : Int
    strategy_index : Int
    placed : Int
    unplaced : Int
    area2 : Int64
    width : Double
    height : Double
    quality_cost : Int64
    } derive(Eq,
    Debug
    )

    Summary of one strategy run on one sheet.

    SuiteLayout

    pub(all) struct SuiteLayout {
    suite_id : String
    outer_instance : Int
    inner_instances : Array[Int]
    } derive(Eq,
    Debug
    )

    Resolved suite hierarchy in a layout.

    SuiteSpec

    pub(all) struct SuiteSpec {
    id : String
    outer : Int
    inner : Array[Int]
    } derive(Eq,
    Debug
    )

    A nested suite: inner parts may occupy holes in the outer part.

    UnplacedInstance

    pub(all) struct UnplacedInstance {
    part : Int
    part_instance_index : Int
    reason : UnplacedReason
    } derive(Eq,
    Debug
    )

    A structured unplaced instance entry.

    UnplacedReason

    pub(all) enum UnplacedReason {
    TooLarge
    NoAllowedRotation
    NoAllowedSheet
    FixedConflict
    BudgetExhausted
    InvalidGeometry
    Occupied
    } derive(Eq,
    Debug
    )

    Why a requested instance could not be placed.

    ValidationIssue

    pub(all) struct ValidationIssue {
    severity : ValidationSeverity
    code : String
    message : String
    instance_id : Int?
    } derive(Eq,
    Debug
    )

    ValidationReport

    pub(all) struct ValidationReport {
    issues : Array[ValidationIssue]
    checked_instances : Int
    checked_pairs : Int
    } derive(Eq,
    Debug
    )

    ValidationReport::has_errors

    fn ValidationReport::has_errors(self : ValidationReport) -> Bool

    ValidationReport::to_json

    ValidationSeverity

    pub(all) enum ValidationSeverity {
    Error
    Warning
    } derive(Eq,
    Debug
    )

    contact

    Classifies contour contact. Boundary-only contact is Touch.

    diagnose_geometry

    fn diagnose_geometry(problem : Problem) -> Array[GeometryDiagnostic] raise NestError

    Returns structured geometry diagnostics for a problem without nesting it.

    inspect_problem

    fn inspect_problem(problem : Problem) ->
    Json
    raise NestError

    Returns a normalized geometry summary for inspection tools.

    nest

    fn nest(problem : Problem, stats? : Array[Stats]) -> Layout raise NestError

    Nests parts deterministically and reports work counters through stats.

    nest_with_transforms

    fn nest_with_transforms(problem : Problem, stats? : Array[Stats]) -> NestingResult raise NestError

    Nests parts and returns the reversible coordinate transform for every placed instance. The layout is identical to nest for the same input.

    nest_with_transforms_async

    async fn nest_with_transforms_async(problem : Problem, stats? : Array[Stats]) -> NestingResult raise NestError

    Async variant that can execute independent strategies in parallel.

    no_fit_orientations

    fn no_fit_orientations(problem : Problem, part : Int) -> Array[(Int, Bool)] raise NestError

    Returns the unique orientations used by complete no-fit queries.

    no_fit_polygons

    fn no_fit_polygons(problem : Problem) -> Array[NoFitPolygon] raise NestError

    Computes one no-fit polygon for every ordered pair of distinct part types and each unique moving rotation. Stationary geometry uses its canonical orientation, so stationary_degrees is zero.

    no_fit_region_for

    fn no_fit_region_for(problem : Problem, moving : Int, stationary : Int, moving_degrees : Int, stationary_degrees : Int, moving_mirrored? : Bool, stationary_mirrored? : Bool) -> NoFitRegion? raise NestError

    Computes one no-fit region for an explicit ordered part pair and rotation.

    no_fit_regions

    fn no_fit_regions(problem : Problem) -> Array[NoFitRegion] raise NestError

    Computes complete no-fit regions for every ordered pair of distinct part types and every unique pair of moving and stationary rotations.

    plan_cutting

    fn plan_cutting(problem : Problem, result : NestingResult) -> CuttingPlan raise NestError

    Builds a deterministic weighted cutting path from existing layout contours.

    schedule_production

    fn schedule_production(config : ProductionConfig) -> SchedulePlan raise NestError

    Schedules jobs by due date, priority, and id using minimum incremental weighted setup and tardiness cost.

    validate_layout

    fn validate_layout(problem : Problem, result : NestingResult) -> ValidationReport raise NestError