Title: Bonsai: ortho_view_frame treats ortho_scale as the width, so the frame of a portrait drawing is wrong · Issue #10110 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Bonsai: ortho_view_frame treats ortho_scale as the width, so the frame of a portrait drawing is wrong · Issue #10110 · IfcOpenShell/IfcOpenShell
X Title: Bonsai: ortho_view_frame treats ortho_scale as the width, so the frame of a portrait drawing is wrong · Issue #10110 · IfcOpenShell/IfcOpenShell
Description: Bug Description BIMCameraProperties.get_scale_and_aspect_ratio (src/bonsai/bonsai/bim/module/drawing/prop.py, line 722) sets ortho_scale = max(width, height), and update_camera_resolution (lines 701–712) sizes the raster accordingly. So ...
Open Graph Description: Bug Description BIMCameraProperties.get_scale_and_aspect_ratio (src/bonsai/bonsai/bim/module/drawing/prop.py, line 722) sets ortho_scale = max(width, height), and update_camera_resolution (lines 70...
X Description: Bug Description BIMCameraProperties.get_scale_and_aspect_ratio (src/bonsai/bonsai/bim/module/drawing/prop.py, line 722) sets ortho_scale = max(width, height), and update_camera_resolution (lines 70...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/10110
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bonsai: ortho_view_frame treats ortho_scale as the width, so the frame of a portrait drawing is wrong","articleBody":"### Bug Description\n\n`BIMCameraProperties.get_scale_and_aspect_ratio` (`src/bonsai/bonsai/bim/module/drawing/prop.py`, line 722) sets `ortho_scale = max(width, height)`, and `update_camera_resolution` (lines 701–712) sizes the raster accordingly. So for a drawing that is taller than it is wide, `ortho_scale` is the **height**.\n\n`helper.ortho_view_frame` (`src/bonsai/bonsai/bim/module/drawing/helper.py`, lines 497–518) always uses it as the **width**:\n\n```python\naspect = props.raster_y / props.raster_x\nsize = camera.ortho_scale\nhwidth = size * 0.5\nhheight = size * 0.5 * aspect\n```\n\nFor a portrait drawing both half-sizes come out too large by the aspect ratio. A 3 × 20 m section gets a frame of x ±10 m (instead of ±1.5 m) and y ±66.7 m (instead of ±10 m).\n\n### Effect\n\n`ortho_view_frame` is used to place the automatic references (`src/bonsai/bonsai/tool/drawing.py`, lines 1720, 1835, 2013, 2017):\n\n- storey level marks (`generate_storey_points`) are drawn across x ±10 m, far outside the drawing, and storeys well above or below the view still get a mark because the y test uses ±66.7 m;\n- grid and section reference lines are clipped to the wrong box.\n\nLandscape and square drawings are not affected. We noticed it on a tall section: the storey level marks ended up outside the sheet. The attached screenshot shows a 3 × 12 m section in Bonsai 0.9.1: the storey marks run across ±6 m.\n\n### Reproduction\n\nThe script below runs Bonsai's unmodified `get_scale_and_aspect_ratio`, `update_camera_resolution` and `ortho_view_frame` with stand-ins for `bpy` and `tool`, without Blender:\n\n```python\n# Runs Bonsai's unmodified camera sizing and ortho_view_frame, without Blender.\n# Usage: python check_ortho_view_frame.py path/to/src/bonsai/bonsai\nimport ast, sys, textwrap, types\nroot = sys.argv[1]\ndef grab(path, names):\n src = open(f\"{root}/{path}\", encoding=\"utf-8\").read()\n return {n.name: textwrap.dedent(ast.get_source_segment(src, n))\n for n in ast.walk(ast.parse(src)) if isinstance(n, ast.FunctionDef) and n.name in names}\nhelper = grab(\"bim/module/drawing/helper.py\", {\"ortho_view_frame\"})\nprop = grab(\"bim/module/drawing/prop.py\", {\"update_camera_resolution\", \"get_scale_and_aspect_ratio\"})\n\nclass Props:\n dpi = 75\n def __init__(self, w, h): self.width, self.height = w, h\nclass Camera:\n clip_start, clip_end = 0.0, 10.0\n def __init__(self, props): self.props = props; props.id_data = self\ntool = types.SimpleNamespace(Drawing=types.SimpleNamespace(\n get_camera_props=lambda cam: cam.props, get_diagram_scale=lambda cam: {\"Scale\": \"1/50\"},\n get_scale_ratio=lambda s: 1 / 50))\nns = {\"tool\": tool, \"bpy\": types.SimpleNamespace(types=types.SimpleNamespace(Camera=Camera)),\n \"parse_diagram_scale\": lambda camera: 1 / 50}\nfor code in (*prop.values(), *helper.values()):\n exec(code, ns)\nProps.update_camera_resolution = ns[\"update_camera_resolution\"]\nProps.get_scale_and_aspect_ratio = ns[\"get_scale_and_aspect_ratio\"]\n\nfor w, h in ((20.0, 3.0), (3.0, 20.0)):\n p = Props(w, h); cam = Camera(p); p.update_camera_resolution()\n xmin, xmax, ymin, ymax = ns[\"ortho_view_frame\"](cam, margin=0.0)[:4]\n ok = abs((xmax - xmin) - w) \u003c 0.01 * w and abs((ymax - ymin) - h) \u003c 0.01 * h # raster is rounded to pixels\n print(f\"{'OK ' if ok else 'WRONG'} drawing {w:g} x {h:g} m, ortho_scale {cam.ortho_scale:g}: \"\n f\"frame x {xmin:+.2f}..{xmax:+.2f}, y {ymin:+.2f}..{ymax:+.2f}\")\n```\n\nOutput on `v0.9.0` at 28bae19 (2026-10-30):\n\n```\nOK drawing 20 x 3 m, ortho_scale 20: frame x -10.00..+10.00, y -1.50..+1.50\nWRONG drawing 3 x 20 m, ortho_scale 20: frame x -10.00..+10.00, y -66.72..+66.72\n```\n\n### Expected\n\nThe frame matches the drawing's width and height, whichever is larger.\n\n### Possible fix\n\n```diff\n aspect = props.raster_y / props.raster_x\n size = camera.ortho_scale\n- hwidth = size * 0.5\n- hheight = size * 0.5 * aspect\n+ # ortho_scale is the larger of width and height (see BIMCameraProperties.get_scale_and_aspect_ratio)\n+ if aspect \u003c= 1:\n+ hwidth = size * 0.5\n+ hheight = size * 0.5 * aspect\n+ else:\n+ hheight = size * 0.5\n+ hwidth = size * 0.5 / aspect\n```\n\nWith this the script prints `OK` for both drawings. It sits next to the lines #8972 changes (the margin), so whichever lands second may need a small rebase. Happy to turn this into a PR if that helps.\n\n*The reproduction script and the fix were prepared with the help of an AI assistant and checked by me.*\n\n\u003cimg width=\"800\" height=\"793\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/306fc430-3249-489c-9f69-c57dc668a5d6\" />\n\nBonsai 0.9.1-alpha261027 (IfcOpenShell 0.9.1a261027), Blender 5.2.0 LTS, Windows\nCode checked on v0.9.0 at 28bae19 (2026-10-30)\n\n### Attachments\n\n_No response_\n\n### Debug and Error Output\n\n```true\n\n```","author":{"url":"https://github.com/SautaRoc","@type":"Person","name":"SautaRoc"},"datePublished":"2026-10-31T09:33:24Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/10110"}
| 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 | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:36b4a0a0-42b3-6ebc-d14a-9539efd8bdec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8196:24C069:15E917:1E35C8:6B0465A2 |
| html-safe-nonce | 5c3504db4e3510721b9d618e0dc5501073a0b465b75f626630c28b173656e2c4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTk2OjI0QzA2OToxNUU5MTc6MUUzNUM4OjZCMDQ2NUEyIiwidmlzaXRvcl9pZCI6IjU4MDI2NTQ3ODg5NzQwNDQ1NzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 79364e4a73663c8b27197a128621a5fb190880f3203996497ec96e97c7d9bba1 |
| hovercard-subject-tag | issue:6133367306 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/10110/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0d33512ef296401dccc9a45eb97d865d1346face9fb5bd09acaccf04b4616ff2/IfcOpenShell/IfcOpenShell/issues/10110 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0d33512ef296401dccc9a45eb97d865d1346face9fb5bd09acaccf04b4616ff2/IfcOpenShell/IfcOpenShell/issues/10110 |
| og:image:alt | Bug Description BIMCameraProperties.get_scale_and_aspect_ratio (src/bonsai/bonsai/bim/module/drawing/prop.py, line 722) sets ortho_scale = max(width, height), and update_camera_resolution (lines 70... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SautaRoc |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width