Nest Endpoint

Use the Nest service to pack polygonal parts into available bins. The service mirrors the CLI contract and streams progress via NDJSON.

Endpoint

POST /api/v1/nest

  • Authentication: Bearer token
  • Headers: Content-Type: application/json
  • Response: NDJSON stream of progress, solution, and lifecycle messages.

Search Strategy

  • Smart seeding: Sort polygons by descending area so the largest pieces claim space first.
  • Guided search: Genetic algorithm mutates placement order and allowed rotations, evaluating collisions and fitness along the way.
  • Solution space: With N polygons and M rotations each, the theoretical maximum permutations equal N! × M^N. Heuristics prune the search to keep runtimes practical.

Top-Level Configuration

KeyTypeDefaultNotes
polygonsarray<polyline>requiredParts to nest. Empty arrays return 422.
binsarray<bin>requiredAvailable stock sheets. Must include at least one entry.
serverIdstring"slow"Selects a preferred solver queue (slow or fast). The "slow" server is free to use, but is capped at 30 seconds per request. The "fast" server is a paid service; see the pricing page for details.
instancesinteger1Launch this many parallel solvers. Each solver runs on an 2 vCPU cloud server. Parallel jobs share the same payload but explore different random seeds. The best solution across all instances is returned. More than 1 instance is a paid feature.
minDistancenumber1.0Clearance between parts. Applied as minDistance / 2 offset per polygon.
curveTolerancenumber1.0Polyline simplification tolerance. Tune alongside minDistance.
matchingTypestring"solid"Accepted values: solid, pattern, vertical, horizontal.
gravityDirectionstring"top"One of top, right, bottom, left. Drives placement bias and fitness axis.
xStepsinteger (≥1)1Splits cellWidth into finer horizontal snapping increments.
yStepsinteger (≥1)1Splits cellHeight into finer vertical snapping increments.
allowedRotationsarray<number>[0.0]Degrees available to each part. Empty arrays fall back to 0.
optimizationobject{ type: "length" }Switch between length and area; optional paper size params for area mode.
populationSizeinteger10Minimum value of 1. Controls genetic algorithm breadth.
mutationRatenumber0.1Chance of mutating each genome entry per generation.
reportIntervalnumber (ms)1000Zero disables periodic updates. Negative values clamp to zero.
maximumExecutionTimenumber (s)300.0Clamped to the range (0, 3600]. Hard stop per request.

Polyline definition

KeyTypeDefaultDescription
idstring""Identifier forwarded to placement results.
origin[x, y] | nullnullOptional placement anchor for pattern matching. Defaults to polyline bounding-box top-left.
pointsarray<[x, y]>[]Vertices describing closed loops. Winding direction is normalised automatically.

Coordinates are unit-agnostic. Use a consistent measurement system across polygons, bins, holes, and distances.

Bin Definition

KeyTypeDefaultDescription
boundarypolylinerequiredOuter contour of the sheet.
holesarray<polyline>[]Keep-out zones within the bin.
cellWidthnumber0.0Native grid spacing along X. Combined with xSteps for snapping.
cellHeightnumber0.0Native grid spacing along Y. Combined with ySteps.

In vertical and horizontal matching modes, placements snap to the derived grid. Other modes evaluate multiple snapped origins per candidate.

Optimisation

KeyTypeDefaultDescription
typestring"length"length minimises span along the active gravity axis; area minimises occupied area.
params.paperWidthnumber | undefinedIn area mode, estimate sheet utilisation by combining paper width and height.
params.paperHeightnumber | undefinedPartner value for paperWidth to compute sheet counts.

Execution Behaviour

  • Requests without polygons or bins return validation errors before solving.
  • All rotations are sourced from allowedRotations; include every angle you need.
  • minDistance and curveTolerance both affect preprocessing. Increase clearance when you raise the tolerance.
  • maximumExecutionTime caps runtime per request. Values above one hour clamp to 3600 seconds.
  • reportInterval governs progress cadence. Zero disables periodic updates but the solver still runs at least one generation.

Streaming Messages

Responses are newline-delimited JSON (NDJSON). Each line carries a type key. Clients should parse per-line and tolerate additional fields as the service evolves.

TypeWhen SentAdditional Fields
progressQueue notice or periodic solver update.status, generation, tested, elapsedSeconds, optional queuedPosition.
solutionFirst viable placement (generation: 0) and any improvements thereafter.Includes fitness, usage envelope, placements array, and unplaced ids.
infoEmitted when the solver hits the time limit.message, elapsedSeconds.
doneAlways final message after optional info.None.
errorValidation or runtime failure.message describing the failure.

Example Stream

{"type":"progress","status":"queued","generation":0,"tested":0,"elapsedSeconds":0.0,"queued_position":2}
{"type":"solution","fitness":0.42,"usage":{"width":200.0,"length":300.0,"area":60000.0},"placements":[{"id":"A","position":[10.0,20.0],"rotation":0.0}],"unplaced":[],"generation":0,"elapsedSeconds":0.18}
{"type":"progress","generation":1,"tested":128,"elapsedSeconds":0.92}
{"type":"solution","fitness":0.37,"usage":{"width":195.0,"length":295.0,"area":57525.0},"placements":[...],"unplaced":[],"generation":2,"tested":512,"elapsedSeconds":1.34}
{"type":"done"}
SeamScape™
Copyright © 2026 Illumetric Technologies AB.
Seamscape logo