Fix a bulge over a zero-length segment discarding the whole polyline - #1229
Open
redbluevn wants to merge 1 commit into
Open
Fix a bulge over a zero-length segment discarding the whole polyline#1229redbluevn wants to merge 1 commit into
redbluevn wants to merge 1 commit into
Conversation
When any vertex carries a bulge, a polyline's bounding box is computed by tessellating each segment through Arc.CreateFromBulge. A repeated vertex that still carries a bulge describes an arc over a chord of no length: the radius its own maths recovers is exactly zero, and Circle's Radius setter throws ArgumentOutOfRangeException over it. One such vertex therefore threw away the measurement of the entire polyline - and, because polylines live inside blocks, of every insert of that block. Duplicated vertices are common in real exports. Such a segment covers no ground, so it now contributes its endpoints and nothing else. Measured over eighteen architectural drawings: two zero-length bulged segments, one of which was throwing. After this, no entity in the corpus fails to report a box - the only remaining non-measurable entities are Regions, which return BoundingBox.Null by design because modeler geometry is not tessellated. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
redbluevn
force-pushed
the
moredwg/pr77-degenerate-bulge
branch
from
September 5, 2026 07:41
010c53c to
6767f53
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
When any vertex carries a bulge, a polyline's bounding box is computed by tessellating each segment through
Arc.CreateFromBulge.A repeated vertex that still carries a bulge describes an arc over a chord of no length.
Arc.GetCentercomputesc = start.DistanceFrom(end) / 2.0— zero — soradius = c / sin(theta/2)is exactly zero, andCircle'sRadiussetter throws:One such vertex therefore threw away the measurement of the entire polyline — and, because polylines live inside blocks, of every insert of that block.
Duplicated vertices are common in real exports.
The fix
Such a segment covers no ground, so it contributes its endpoints and nothing else.
Evidence
Across eighteen architectural drawings: two zero-length bulged segments, one of them throwing. After this, no entity in the corpus fails to report a box. The only remaining non-measurable entities are
Regions, which returnBoundingBox.Nullby design because modeler geometry is not tessellated — that is not a defect and is left alone.Adjacent, not fixed here
Three more paths can throw out of
GetBoundingBoxfor the same reason — a raw value the readers store faithfully and an entity setter refuses:Hatch.BoundaryPath.Arc.GetBoundingBoxbuilds anArcentity, so an edge with radius ≤ 0 throws. (The entity reader already clamps this —DwgObjectReadermapsradius <= 0toMathHelper.Epsilon— but the boundary-edge reader does not.)Hatch.BoundaryPath.Ellipse.GetBoundingBoxbuilds anEllipse, so an edge ratio of 0 or above 1 throws.BlockRecord.GetBoundingBoxevaluates every child's box twice, once for the infinite check and once for the merge — quadratic through nested blocks.None of the three occurs in my corpus (measured: 0, 0, and the double evaluation is a cost not a fault), so I have left them out rather than ship unexercised code. Raising them in case they are worth a separate look.
Tests
ABulgeOverAZeroLengthSegmentDoesNotThrowfails against the current code withArgumentOutOfRangeException.dotnet test: 2314 passed / 17 failed, againstmasterat 592d70a on this machine at 2313 / 17.Related
#1223, #1224, #1225, #1226, #1227 and DomCR/CSUtilities#23.