Title: util.representation + Bonsai: fix two nested mapped-item transform bugs (#3019) by petruconduraru · Pull Request #8335 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: util.representation + Bonsai: fix two nested mapped-item transform bugs (#3019) by petruconduraru · Pull Request #8335 · IfcOpenShell/IfcOpenShell
X Title: util.representation + Bonsai: fix two nested mapped-item transform bugs (#3019) by petruconduraru · Pull Request #8335 · IfcOpenShell/IfcOpenShell
Description: Fixes #3019. Two distinct bugs in the same few lines of nested mapped-item transform handling. They are shipped together because they overlap textually, and splitting them would guarantee a conflict. Bug 1: composition order IfcImporter.is_native (src/bonsai/bonsai/bim/import_ifc.py) walks a chain of single-item mapped representations accumulating matrix = rep_matrix @ matrix. For a nested chain that yields M_inner @ M_outer, but the correct nesting is M_outer @ M_inner: the inner mapping places geometry into the middle representation, the outer places that into the product. A single non-nested mapped item reduces to M_outer either way, which is why this only ever showed up "on certain files" (aothms, 2023). ifcopenshell/util/representation.py's resolve_items had the same order bug and is fixed the same way. Verified against the geometry engine as ground truth: a swept disk solid inside an inner mapped item (translate +10 x) inside an outer mapped item (rotate 90 degrees Z, translate +100 y), deliberately non-commuting. The fixed order composes to (0, 110, 0), matching the geometry engine's world bounding box. The old order gives (10, 100, 0), which lands nowhere near it. Bug 2: an identity transform discarded the whole parent chain resolve_items only composed the accumulated matrix when the mapped item's own transform was non-identity: if not np.allclose(rep_matrix, np.eye(4)): rep_matrix = matrix.copy() @ rep_matrix When a nested IfcMappedItem's own transform is the identity, that guard skipped the composition and passed a bare identity matrix down as the new accumulator, silently discarding every parent transform above it. Measured: outer mapped item translating (10, 20, 30) with an identity inner item returned (0, 0, 0). Three levels deep with an identity middle returned (1, 2, 3) instead of (11, 22, 33). The expected matrices were derived by composing the hand-built transforms directly, not by reading the patched code's output. The guard was never needed, since matrix @ eye(4) is matrix, so the fix is to compose unconditionally. Correction to an earlier version of this description A previous version of this text stated that the resolve_items change had "no runtime change today" because all callers read only the item. That is wrong, and the effect is real. Loader.create_native_swept_disk_solid (src/bonsai/bonsai/tool/loader.py:1264) calls resolve_items, then at line 1299 does matrix = item_data["matrix"] and uses it to transform every vertex of the resulting curve. So both bugs above misplace native swept disk solid geometry rather than being latent. Bug 2 needs two or more levels of mapped-item nesting with a trivial inner level, which is plausible in Revit and Tekla style type instantiation chains. Tests Adds src/ifcopenshell-python/test/util/test_representation.py with a TestResolveItems class covering four nesting combinations plus a three-level chain. There was no existing test for resolve_items, so nothing enshrined the old behaviour. Both failing cases fail before and pass after; the "outer identity, inner non-identity" case passes either way, since there is no parent transform to lose. Merge-order note for whoever takes this: two other open PRs, #9013 and #8317, also intend to create test/util/test_representation.py. Whichever lands first wins the file, and the others will need their test classes merged in by hand. Correction: the new test file is src/ifcopenshell-python/test/util/test_representation_mapped_items.py, not test/util/test_representation.py, so the merge-order note about #9013 and #8317 also creating test_representation.py does not apply to this pull request. The loader lines are now tool/loader.py 1268 and 1303 on v0.9.0. Generated with the assistance of an AI coding tool.
Open Graph Description: Fixes #3019. Two distinct bugs in the same few lines of nested mapped-item transform handling. They are shipped together because they overlap textually, and splitting them would guarantee a conflic...
X Description: Fixes #3019. Two distinct bugs in the same few lines of nested mapped-item transform handling. They are shipped together because they overlap textually, and splitting them would guarantee a conflic...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/pull/8335
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c1405797-2ce8-9764-9c21-607f7b3cc604 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C9A0:9F770:4E1D18:6AD1FB:6B04C3D0 |
| html-safe-nonce | 18325af9c0e8d1e986913342a7be11e7a206fbf55e0d46e4cb77657b3f3e72dd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOUEwOjlGNzcwOjRFMUQxODo2QUQxRkI6NkIwNEMzRDAiLCJ2aXNpdG9yX2lkIjoiNjc0MTU1MTc1MTAyOTM3NTk1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a9fd665740066aeb0da0cc3366387449ebaa4eba314119b26c00cbe01a2f9af9 |
| hovercard-subject-tag | pull_request:4005420719 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/IfcOpenShell/IfcOpenShell/pull/8335/files |
| twitter:image | https://avatars.githubusercontent.com/u/139251053?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/139251053?s=400&v=4 |
| og:image:alt | Fixes #3019. Two distinct bugs in the same few lines of nested mapped-item transform handling. They are shipped together because they overlap textually, and splitting them would guarantee a conflic... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85dd75377eb77313206b8fc108bcee6a3a029286d94bf32bf9b4426e4d92e0c4 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0d64fa748a2bab9a5b587a967ac4da1cfa8da6dd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width