how it worksnesting algorithmbin packingeducation

How Does Automatic Nesting Software Work?

A clear explanation of how nesting software works: the algorithms, the geometry, the file formats, and why it produces better layouts than manual nesting. Covers NFP, metaheuristics, and more.

Lapas Team

When you use nesting software, you upload a DXF file, click a button, and get an optimized cutting layout. But what’s actually happening between those two steps? How does software figure out the best way to pack dozens of irregular shapes onto a sheet?

This article explains how nesting software works — from the geometry, to the algorithms, to the output — in plain language.

The problem: 2D irregular bin packing

At its core, nesting software solves a mathematical problem called 2D irregular bin packing: given a set of shapes (parts) and a set of containers (sheets), find the arrangement of shapes that:

  1. Fits all shapes within the containers without any two shapes overlapping
  2. Minimizes the number of containers (sheets) used

This is an NP-hard problem — there’s no known algorithm that can guarantee finding the perfect solution in a reasonable time for large instances. Instead, nesting software uses heuristics and metaheuristics — intelligent search strategies that find very good (but not necessarily optimal) solutions quickly.

Step 1: Parsing the geometry

Before any nesting can happen, the software needs to understand the geometry of each part. DXF files contain entities like:

  • LWPOLYLINE — the most common; a sequence of line segments and arc segments
  • LINE — a simple straight segment
  • ARC — a circular arc
  • CIRCLE — a full circle (holes, circular parts)
  • SPLINE — a smooth curve
  • INSERT (BLOCK) — a reference to a reusable group of entities

The nesting engine converts all of these into polygon representations — usually discretizing curves into many short line segments for computational efficiency. The quality of this tessellation affects both nesting accuracy and computation speed.

Step 2: Computing the No-Fit Polygon (NFP)

The key data structure in irregular nesting is the No-Fit Polygon (NFP).

For any two shapes A and B, the NFP describes all positions where placing A’s reference point would cause A to overlap with B. This is computed by effectively “sliding” A around the perimeter of B and tracing the path of A’s reference point.

The complement of the NFP — all positions not inside the NFP — represents valid placements of A relative to B (no overlap).

By combining NFPs for all already-placed parts on the sheet, the solver can quickly determine all valid positions for the next part to be placed.

Inner Fit Polygon (IFP)

A related structure is the Inner Fit Polygon (IFP) — the set of positions where A fits entirely inside the sheet boundary. The valid placement region for a new part is the intersection of the IFP with the complement of all existing NFPs.

Step 3: The optimization strategy

With collision-checking handled by NFPs, the nesting engine can now search for good arrangements. There are two main approaches:

Greedy heuristic (fast, moderate quality)

  1. Sort parts by some criterion (usually area, descending)
  2. For each part, find the “lowest-leftmost” valid position and place it there
  3. Repeat until all parts are placed or the sheet is full

This runs in seconds but often produces suboptimal results — it makes locally optimal decisions without considering how earlier placements affect later ones.

Metaheuristic search (slower, higher quality)

More advanced engines use metaheuristics — algorithms that explore a much larger space of possible arrangements:

  • Genetic algorithm — maintains a population of candidate arrangements, breeds them together, and occasionally introduces random mutations. Used by SVGNest and Deepnest.
  • Simulated annealing — starts from a random arrangement, makes random changes, and accepts “worse” changes with a probability that decreases over time (mimicking the cooling of metal). Effective at escaping local optima.
  • Custom metaheuristics — proprietary combinations of the above, often with problem-specific optimizations. Lapas’s Sparrow engine uses this approach.

The metaheuristic runs many iterations — each evaluating a candidate arrangement’s utilization — and keeps improving until a time limit is reached.

Step 4: Rotation handling

Parts can often be rotated to fit more tightly. The nesting engine handles this by:

  • Computing NFPs for each allowed rotation of each part
  • Including rotation as a parameter in the optimization search

Allowing free rotation (any angle) gives the best utilization but increases computation time significantly. Most practical implementations discretize rotation to a set of angles (e.g., 0°, 15°, 30°… 345°) for performance.

Lapas offers:

  • Free rotation — any angle, highest utilization
  • Fixed angles — only 0°, 90°, 180°, 270°
  • No rotation — fixed orientation (for grain direction, branded parts, etc.)

Step 5: Multi-sheet handling

When all parts don’t fit on a single sheet, the engine continues placing remaining parts onto additional sheets, using the same optimization approach for each sheet.

Some advanced engines jointly optimize placement across multiple sheets simultaneously; others process sheets sequentially. Joint optimization can achieve slightly better global utilization but is computationally much more demanding.

Step 6: Output generation

Once the placement is determined, the software generates the output files:

  • DXF — draws each part at its placed position with correct rotation, in a DXF coordinate system matching the sheet size
  • G-code — generates toolpaths including lead-in/lead-out moves, cut order, and machine-specific parameters
  • PLT/HPGL — a pen plotter format used by some older controllers
  • PDF — a visual report showing the sheet layout with part labels, utilization statistics, and sheet count

Why manual nesting is so much worse

When a human manually arranges parts, they face fundamental cognitive limits:

  • They can only consider a small number of arrangements
  • They can’t efficiently compute NFPs
  • They tend to use rectangular mental bounding boxes rather than exact outlines
  • They stop when the layout looks “good enough”

An automated optimizer evaluates thousands or millions of candidate arrangements and considers exact geometry at every step. This is why automated nesting reliably achieves 20–30% better utilization than experienced manual operators.

The difference between nesting engines

Not all nesting engines are equal. The quality difference between a greedy heuristic and a well-tuned metaheuristic can be 5–15% utilization on complex jobs — which translates directly to sheets saved and material cost.

Lapas provides two engines so you can choose the right trade-off for each job:

  • Heuristic engine — results in seconds, good for quick estimates or simple jobs
  • Metaheuristic (Sparrow) engine — runs longer, finds better arrangements for complex multi-part jobs

Try Lapas free

No credit card. No install. Start nesting in 60 seconds.

Start free