Expand description
§U-Nesting 2D
2D nesting algorithms for the U-Nesting spatial optimization engine.
This crate provides polygon-based 2D nesting with NFP (No-Fit Polygon) computation and various placement algorithms.
§Features
- Polygon geometry with holes support
- Multiple placement strategies (BLF, NFP-guided, GA, BRKGA, SA)
- Convex hull and convexity detection
- Configurable rotation and mirroring constraints
- NFP-based collision-free placement
- Spatial indexing for fast queries
§Quick Start
use u_nesting_d2::{Geometry2D, Boundary2D, Nester2D, Config, Strategy, Solver};
// Create geometries
let rect = Geometry2D::rectangle("rect1", 100.0, 50.0)
.with_quantity(5)
.with_rotations_deg(vec![0.0, 90.0]);
// Create boundary
let boundary = Boundary2D::rectangle(500.0, 300.0);
// Configure and solve
let config = Config::new()
.with_strategy(Strategy::NfpGuided)
.with_spacing(2.0);
let nester = Nester2D::new(config);
let result = nester.solve(&[rect], &boundary).unwrap();
println!("Placed {} items, utilization: {:.1}%",
result.placements.len(),
result.utilization * 100.0);§Geometry Creation
use u_nesting_d2::Geometry2D;
// Rectangle
let rect = Geometry2D::rectangle("r1", 100.0, 50.0);
// Circle (approximated)
let circle = Geometry2D::circle("c1", 25.0, 32);
// L-shape
let l_shape = Geometry2D::l_shape("l1", 100.0, 80.0, 30.0, 30.0);
// Custom polygon
let custom = Geometry2D::new("custom")
.with_polygon(vec![(0.0, 0.0), (100.0, 0.0), (50.0, 80.0)])
.with_quantity(3);Re-exports§
pub use boundary::Boundary2D;pub use geometry::Geometry2D;pub use nester::Nester2D;pub use nfp::NfpConfig;pub use nfp::NfpMethod;pub use spatial_index::SpatialEntry2D;pub use spatial_index::SpatialIndex2D;
Modules§
- alns_
nesting - Adaptive Large Neighborhood Search (ALNS) based 2D nesting optimization.
- boundary
- 2D boundary types.
- brkga_
nesting - BRKGA-based 2D nesting optimization.
- ga_
nesting - Genetic Algorithm based 2D nesting optimization.
- gdrr_
nesting - Goal-Driven Ruin and Recreate (GDRR) based 2D nesting optimization.
- geometry
- 2D geometry types.
- nester
- 2D nesting solver.
- nfp
- No-Fit Polygon (NFP) computation.
- nfp_
sliding - Improved Sliding Algorithm for No-Fit Polygon generation.
- sa_
nesting - Simulated Annealing-based 2D nesting optimization.
- spatial_
index - Spatial indexing for 2D collision detection using R*-tree.
Structs§
- AABB2D
- Axis-aligned bounding box in 2D.
- Config
- Common configuration for solvers.
- Placement
- Represents the placement of a geometry within a boundary.
- Solve
Result - Result of a nesting or packing solve operation.
- Transform2D
- A 2D rigid transformation (rotation + translation).
Enums§
- Error
- Errors that can occur during nesting/packing operations.
- Rotation
Constraint - Allowed rotation angles for a geometry.
- Strategy
- Optimization strategy.
Traits§
- Boundary
- Trait for boundaries/containers that hold geometries.
- Boundary2D
Ext - Extended trait for 2D boundaries.
- Geometry
- Trait for geometric shapes that can be nested or packed.
- Geometry2D
Ext - Extended trait for 2D geometries.
- Solver
- Trait for nesting/packing solvers.
Functions§
- clamp_
placement_ to_ boundary - Computes valid placement bounds and clamps a position to keep geometry within boundary.
- clamp_
placement_ to_ boundary_ with_ margin - Computes valid placement bounds with margin and clamps a position to keep geometry within boundary.
- is_
placement_ within_ bounds - Checks if a placement is within the boundary.
- validate_
and_ filter_ placements - Validates all placements in a SolveResult and removes any that are outside the boundary.
Type Aliases§
- Result
- Result type alias for U-Nesting operations.