Deterministic polygon nesting and no-fit nesting for MoonBit, built on MoonClip exact geometry.
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{
"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 }
}{
"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": [
{ "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 }]] }
]
}{
"rules": {
"rotations": [0, 90],
"mirror": true,
"priority": 10,
"sheets": [0],
"min_quantity": 1,
"group": "kit",
"label": "bracket",
"metadata": { "material": "steel" }
}
}{
"suites": [{ "id": "assembly", "outer": 0, "inner": [1] }]
}{
"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
}
}{
"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 }
}///|
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)moon build web --target wasm
moon build web/demo --target jsmoon 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.pymoon 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| Case | Placed | Unplaced | Elapsed |
|---|---|---|---|
| 10 rectangles | 10 | 0 | 0.29s |
| 50 mixed | 50 | 0 | 2.96s |
| 100 hole parts | 71 | 29 | 3.77s |
| 300 stress | 79 | 221 | 5.66s |
| Multi-sheet | 60 | 0 | 3.36s |
| Multi-rotation | 30 | 0 | 34.68s |
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)pub(all) struct CuttingPlan {
moves : Array[CuttingMove]
rapid_distance : Double
cut_distance : Double
pierces : Int
cost : Double
} derive(Eq, Debug)pub(all) struct GeometryDiagnostic {
subject : String
ring : String
contour_index : Int
issue : GeometryIssue
message : String
} derive(Eq, Debug)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)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)pub(all) struct NestingResult {
layout : Layout
transforms : Array[PlacementTransform]
} derive(Eq, Debug)fn NestingResult::to_debug_svg(self : NestingResult, precision? : Precision) -> String raise NestErrorpub(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)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)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)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)pub(all) struct ProductionConfig {
machines : Array[ProductionMachine]
jobs : Array[ProductionJob]
due_weight : Double
setup_weight : Double
} derive(Eq, Debug)pub(all) struct SchedulePlan {
entries : Array[ScheduledJob]
total_setup_minutes : Int
total_tardiness_minutes : Int
cost : Double
} derive(Eq, Debug)pub(all) struct SearchStrategy {
order : PartOrder
gravity : Gravity
scoring : CandidateScoring
} derive(Eq, Debug)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)pub(all) struct UnplacedInstance {
part : Int
part_instance_index : Int
reason : UnplacedReason
} derive(Eq, Debug)pub(all) struct ValidationIssue {
severity : ValidationSeverity
code : String
message : String
instance_id : Int?
} derive(Eq, Debug)pub(all) struct ValidationReport {
issues : Array[ValidationIssue]
checked_instances : Int
checked_pairs : Int
} derive(Eq, Debug)async fn nest_with_transforms_async(problem : Problem, stats? : Array[Stats]) -> NestingResult raise NestErrorfn no_fit_region_for(problem : Problem, moving : Int, stationary : Int, moving_degrees : Int, stationary_degrees : Int, moving_mirrored? : Bool, stationary_mirrored? : Bool) -> NoFitRegion? raise NestErrorInstall
Download zipDeterministic polygon nesting and no-fit nesting for MoonBit, built on MoonClip exact geometry.