From 70478ec9461f4b8ecf4809ade92d297b631452f9 Mon Sep 17 00:00:00 2001 From: komal0000 Date: Sun, 25 Oct 2026 11:39:13 +0545 Subject: [PATCH] Explode a bulge over a zero-length segment as a line --- src/ACadSharp.Tests/Entities/LwPolylineTest.cs | 17 +++++++++++++++++ src/ACadSharp/Extensions/PolylineExtensions.cs | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ACadSharp.Tests/Entities/LwPolylineTest.cs b/src/ACadSharp.Tests/Entities/LwPolylineTest.cs index e6a525036..74011b754 100644 --- a/src/ACadSharp.Tests/Entities/LwPolylineTest.cs +++ b/src/ACadSharp.Tests/Entities/LwPolylineTest.cs @@ -115,6 +115,23 @@ public void ExplodeClosedInLines() } } + [Fact] + public void ExplodeBulgeOverZeroLengthSegment() + { + LwPolyline lwPolyline = new LwPolyline(); + lwPolyline.Vertices.Add(new LwPolyline.Vertex(new XY(0, 0)) { Bulge = 1.0 }); + lwPolyline.Vertices.Add(new LwPolyline.Vertex(new XY(0, 0))); + lwPolyline.Vertices.Add(new LwPolyline.Vertex(new XY(10, 0))); + + List entities = lwPolyline.Explode().ToList(); + + Assert.Equal(2, entities.Count); + Line l = Assert.IsType(entities[0]); + Assert.Equal(XYZ.Zero, l.StartPoint); + Assert.Equal(XYZ.Zero, l.EndPoint); + Assert.IsType(entities[1]); + } + public override void GetBoundingBoxTest() { } diff --git a/src/ACadSharp/Extensions/PolylineExtensions.cs b/src/ACadSharp/Extensions/PolylineExtensions.cs index 426fee5bf..c1b738d50 100644 --- a/src/ACadSharp/Extensions/PolylineExtensions.cs +++ b/src/ACadSharp/Extensions/PolylineExtensions.cs @@ -32,8 +32,12 @@ public static IEnumerable Explode(this IPolyline polyline) break; } + XY p1 = curr.Location.Convert(); + XY p2 = next.Location.Convert(); + Entity e = null; - if (curr.Bulge == 0) + //A bulge over a zero-length segment has no arc to create + if (curr.Bulge == 0 || p1.Equals(p2)) { //Is a line e = new Line @@ -46,9 +50,6 @@ public static IEnumerable Explode(this IPolyline polyline) } else { - XY p1 = curr.Location.Convert(); - XY p2 = next.Location.Convert(); - //Is an arc Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge); arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);