Skip to content

Plate 2d nesting - #720

Open
nbbosco wants to merge 17 commits into
mainfrom
plate_2d_nesting
Open

Plate 2d nesting#720
nbbosco wants to merge 17 commits into
mainfrom
plate_2d_nesting

Conversation

@nbbosco

@nbbosco nbbosco commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

PlateNester is a 2D packing class that takes the plates and tries to place them on sheet stock with as little waste as possible, while keeping placements valid for fabrication.

Continuing @papachap base work I implemented the following workflow:

  1. Filters and groups plates:
    It decides which stock each plate is compatible with (mainly by thickness), and optionally nests per model group (NOTE: Currently is based on the blank bounding box of the plate shape, maybe this could be improved using the edges of the shape?)..

  2. Orders plates for placement:
    It places larger/more critical plates first (deterministic order), or uses a reproducible shuffled order when a seed is given (NOTE: Seeds are useful to give the user nesting options and keep track of them).

  3. Tries both orientations:
    For each plate, it tests normal and 90° rotated layouts (NOTE: More angle rotation can take more process time but maybe could also be added as an optional input).

  4. Chooses a placement strategy:

  • Fast mode: skyline-based heuristic, optimized for speed.
  • Non-fast mode: bottom-left style ranking for slightly different packing behavior.
  1. Validates geometry before committing:
    Even if a candidate looks good by bounding logic, it still checks polygon fit to avoid overlaps/out-of-bounds placements.

  2. Updates stock state:
    When a plate is placed, it updates:

  • remaining geometry boundary
  • skyline profile
  • used area and placement metadata for reporting/export
  1. Reports what happened:
    It returns a NestingResult with:
  • stocks used
  • utilization metrics
  • unplaced plate GUIDs
  • reasons for unplaced items
  • effective spacing and seed info

Basically:
Sort plates → pick a stock → find best valid spot (with rotation options) → place → update sheet profile → repeat → report leftovers.

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas_timber.datastructures.Beam.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation, including updating class_diagrams.rst (if appropriate).

output
image

@nbbosco nbbosco linked an issue Mar 19, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Mar 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.23490% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.60%. Comparing base (e43ad8f) to head (973f082).

Files with missing lines Patch % Lines
src/compas_timber/planning/nesting.py 85.20% 66 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #720      +/-   ##
==========================================
+ Coverage   80.38%   80.60%   +0.22%     
==========================================
  Files          79       79              
  Lines       11250    11691     +441     
==========================================
+ Hits         9043     9424     +381     
- Misses       2207     2267      +60     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nbbosco
nbbosco marked this pull request as ready for review March 20, 2026 11:14
@nbbosco
nbbosco marked this pull request as draft March 20, 2026 12:29
@nbbosco
nbbosco marked this pull request as ready for review March 24, 2026 16:01
@nbbosco
nbbosco requested a review from papachap March 24, 2026 16:01
@nbbosco nbbosco self-assigned this Mar 24, 2026
Copilot AI review requested due to automatic review settings June 30, 2026 14:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces 2D sheet nesting for Plate elements via a new PlateNester, expanding the existing nesting framework (previously beam-focused) to support plate stock packing and richer nesting result reporting.

Changes:

  • Added PlateNester with skyline-based (fast) and bottom-left-style (non-fast) placement strategies, including deterministic vs seeded ordering and 0/90° orientation trials.
  • Extended PlateStock and NestingResult to support plate nesting state, unplaced-element reporting, and per-stock utilization/report payloads.
  • Added a comprehensive plate nesting test suite and exported PlateNester from compas_timber.planning.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/compas_timber/planning/nesting.py Adds PlateNester, extends PlateStock for 2D nesting, and augments NestingResult with reporting/utilization metadata.
tests/compas_timber/test_nesting.py Adds tests validating plate nesting placement bounds, overlap avoidance, spacing, determinism, seeded ordering, and reporting.
src/compas_timber/planning/__init__.py Exposes PlateNester at the planning package level.
CHANGELOG.md Adds changelog notes for the new plate nesting feature and reporting changes.

Comment thread src/compas_timber/planning/nesting.py
Comment thread src/compas_timber/planning/nesting.py
Comment thread src/compas_timber/planning/nesting.py Outdated
Comment thread tests/compas_timber/test_nesting.py Outdated
Comment thread CHANGELOG.md Outdated

@obucklin obucklin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Nico, this looks pretty good. I want to defer to @papachap, since he wrote the beam nester, to give final approveal. @papachap, can you please take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement 2d plate nesting

4 participants