Skip to content

Fix compas-brep API use in Lap and Pocket - #843

Open
ericgozzi wants to merge 3 commits into
mainfrom
fix-compas-brep-face-api
Open

Fix compas-brep API use in Lap and Pocket#843
ericgozzi wants to merge 3 commits into
mainfrom
fix-compas-brep-face-api

Conversation

@ericgozzi

@ericgozzi ericgozzi commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Pocket, Lap, and BTLxPart's Brep-handling code still called the old compas.geometry.brep API (face.nurbssurface, face.frame_at) which no longer exists on compas_brep's BrepFace. face.surface now returns a Plane directly for planar faces, so no NurbsSurface/frame_at detour is needed; only genuinely curved faces need surface.frame_at.

Along the way, face.surface didn't account for face.is_reversed, so opposite faces of a box reported identical normals instead of opposite ones - fixed by flipping the normal for reversed faces.

Also fixes _get_optimal_ref_side_index in Pocket and Lap, where edge.curve already returns a Line directly (no .points attribute to unpack).

Pocket.apply additionally now raises a clear FeatureApplicationError when start_depth is negative (the pocket volume lies entirely outside the element's material on the ref_side's outward side) instead of letting a corrupted/erased geometry reach the boolean subtraction.

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).

Pocket, Lap, and BTLxPart's Brep-handling code still called the old
compas.geometry.brep API (face.nurbssurface, face.frame_at) which no
longer exists on compas_brep's BrepFace. face.surface now returns a
Plane directly for planar faces, so no NurbsSurface/frame_at detour is
needed; only genuinely curved faces need surface.frame_at.

Along the way, face.surface didn't account for face.is_reversed, so
opposite faces of a box reported identical normals instead of opposite
ones - fixed by flipping the normal for reversed faces.

Also fixes _get_optimal_ref_side_index in Pocket and Lap, where
edge.curve already returns a Line directly (no .points attribute to
unpack).

Pocket.apply additionally now raises a clear FeatureApplicationError
when start_depth is negative (the pocket volume lies entirely outside
the element's material on the ref_side's outward side) instead of
letting a corrupted/erased geometry reach the boolean subtraction.
@ericgozzi
ericgozzi requested review from chenkasirer and obucklin and a lite review from Copilot and removed request for Copilot August 10, 2026 09:00
Line is no longer needed in pocket.py now that _get_optimal_ref_side_index
uses edge.curve directly instead of wrapping it in Line(*curve.points).
@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.57%. Comparing base (b9e0e20) to head (84ffb77).

Files with missing lines Patch % Lines
src/compas_timber/fabrication/pocket.py 0.00% 9 Missing ⚠️
src/compas_timber/fabrication/lap.py 0.00% 7 Missing ⚠️
src/compas_timber/fabrication/btlx.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #843      +/-   ##
==========================================
- Coverage   82.67%   82.57%   -0.11%     
==========================================
  Files          83       83              
  Lines       12009    12018       +9     
==========================================
- Hits         9929     9924       -5     
- Misses       2080     2094      +14     

☔ 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.

@ericgozzi
ericgozzi requested review from papachap and a lite review from Copilot August 10, 2026 09:02

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 updates COMPAS Timber’s fabrication features to match the current compas_brep Brep API, removing calls to deprecated/removed methods and fixing orientation handling for reversed Brep faces so downstream plane/frame computations behave correctly.

Changes:

  • Replace deprecated Brep face surface access (nurbssurface, frame_at) with face.surface and handle planar vs curved faces appropriately.
  • Correct face orientation handling by flipping normals/frames when face.is_reversed so opposing faces report opposing normals.
  • Fix Pocket/Lap ref-side edge handling (edge.curve already returns a Line) and add an early FeatureApplicationError for negative Pocket.start_depth.

Reviewed changes

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

File Description
src/compas_timber/fabrication/pocket.py Update Brep face plane extraction + edge handling; add explicit error for negative start_depth to prevent invalid boolean subtraction.
src/compas_timber/fabrication/lap.py Update Brep face plane extraction + edge handling to use the current Brep API and correct reversed-face orientation.
src/compas_timber/fabrication/btlx.py Make BTLx shape export robust for planar faces by avoiding frame_at on Plane and correcting reversed-face orientation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +349 to +353
for face in volume.faces:
plane = face.surface
if face.is_reversed:
plane.normal = -plane.normal
planes.append(plane)
Comment on lines +417 to +421
for face in volume.faces:
plane = face.surface
if face.is_reversed:
plane.normal = -plane.normal
planes.append(plane)
Comment on lines +563 to +567
if self.start_depth < -TOL.absolute:
raise FeatureApplicationError(
None,
geometry.transformed(element.modeltransformation),
"Pocket's start_depth ({:.4f}) is negative: the pocket volume lies entirely outside "
Comment on lines +654 to +658
surface = face.surface
# planar faces (the common case) return a Plane, which has no frame_at (parameter-independent
# anyway); only genuinely curved faces (NurbsSurface, etc.) need parametric evaluation.
frame = Frame.from_plane(surface) if isinstance(surface, Plane) else surface.frame_at(0.5, 0.5)
if face.is_reversed:
scaled_geometry = self.element.geometry.scaled(self._scale_factor)
for face in scaled_geometry.faces:
pts = []
frame = face.surface.frame_at(0.5, 0.5)

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! I think these should be fixed upstream. could you check if gramaziokohler/compas_brep#8
solves these issues?

it should be as easy as calling face.from_at() which should now get you the properly oriented frame.

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.

3 participants