• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 22018275163

14 Feb 2026 01:30PM UTC coverage: 77.463% (-0.02%) from 77.486%
22018275163

push

github

web-flow
Merge pull request #977 from DomCR/issue-971_insert-explode-fix

Issue 971 insert explode fix

8144 of 11374 branches covered (71.6%)

Branch coverage included in aggregate %.

15 of 36 new or added lines in 6 files covered. (41.67%)

10 existing lines in 2 files now uncovered.

29454 of 37163 relevant lines covered (79.26%)

151428.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

51.05
/src/ACadSharp/Entities/PolyLine.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Extensions;
3
using CSMath;
4
using CSUtilities.Extensions;
5
using System.Collections.Generic;
6
using System.Linq;
7

8
namespace ACadSharp.Entities
9
{
10
        /// <summary>
11
        /// Represents a <see cref="Polyline{T}"/> entity.
12
        /// </summary>
13
        [DxfName(DxfFileToken.EntityPolyline)]
14
        [DxfSubClass(null, true)]
15
        public abstract class Polyline<T> : Entity, IPolyline
16
                where T : Entity, IVertex
17
        {
18
                /// <inheritdoc/>
19
                [DxfCodeValue(30)]
20
                public double Elevation { get; set; } = 0.0;
32,025✔
21

22
                /// <summary>
23
                /// End width.
24
                /// </summary>
25
                [DxfCodeValue(41)]
26
                public double EndWidth { get; set; } = 0.0;
21,499✔
27

28
                /// <summary>
29
                /// Polyline flags.
30
                /// </summary>
31
                [DxfCodeValue(70)]
32
                public virtual PolylineFlags Flags { get => this._flags; set => this._flags = value; }
10,107✔
33

34
                /// <inheritdoc/>
35
                public bool IsClosed
36
                {
37
                        get
38
                        {
33✔
39
                                return this.Flags.HasFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM) || this.Flags.HasFlag(PolylineFlags.ClosedPolygonMeshInN);
33✔
40
                        }
33✔
41
                        set
42
                        {
234✔
43
                                if (value)
234✔
44
                                {
37✔
45
                                        this._flags.AddFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
37✔
46
                                        this._flags.AddFlag(PolylineFlags.ClosedPolygonMeshInN);
37✔
47
                                }
37✔
48
                                else
49
                                {
197✔
50
                                        this._flags.RemoveFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
197✔
51
                                        this._flags.RemoveFlag(PolylineFlags.ClosedPolygonMeshInN);
197✔
52
                                }
197✔
53
                        }
234✔
54
                }
55

56
                /// <inheritdoc/>
57
                [DxfCodeValue(210, 220, 230)]
58
                public XYZ Normal { get; set; } = XYZ.AxisZ;
21,581✔
59

60
                /// <inheritdoc/>
61
                public override string ObjectName => DxfFileToken.EntityPolyline;
8,254✔
62

63
                /// <summary>
64
                /// Curves and smooth surface type.
65
                /// </summary>
66
                [DxfCodeValue(75)]
67
                public SmoothSurfaceType SmoothSurface { get; set; }
163✔
68

69
                /// <summary>
70
                /// Start width.
71
                /// </summary>
72
                [DxfCodeValue(40)]
73
                public double StartWidth { get; set; } = 0.0;
21,499✔
74

75
                /// <inheritdoc/>
76
                [DxfCodeValue(39)]
77
                public double Thickness { get; set; } = 0.0;
21,433✔
78

79
                /// <summary>
80
                /// Vertices that form this polyline.
81
                /// </summary>
82
                /// <remarks>
83
                /// Each <see cref="Vertex"/> has it's own unique handle.
84
                /// </remarks>
85
                public SeqendCollection<T> Vertices { get; private set; }
616,390✔
86

87
                /// <inheritdoc/>
88
                IEnumerable<IVertex> IPolyline.Vertices { get { return this.Vertices; } }
630✔
89

90
                private PolylineFlags _flags;
91

92
                /// <summary>
93
                /// Default constructor.
94
                /// </summary>
95
                public Polyline() : base()
21,394✔
96
                {
21,394✔
97
                        this.Vertices = new SeqendCollection<T>(this);
21,394✔
98
                        this.Vertices.OnAdd += this.onAddVertices;
21,394✔
99
                }
21,394✔
100

101
                public Polyline(IEnumerable<T> vertices, bool isClosed) : this()
184✔
102
                {
184✔
103
                        if (vertices == null)
184!
104
                                throw new System.ArgumentException("The vertices enumerable cannot be null or empty", nameof(vertices));
×
105

106
                        this.Vertices.AddRange(vertices);
184✔
107
                        this.IsClosed = isClosed;
184✔
108
                }
184✔
109

110
                /// <inheritdoc/>
111
                public override void ApplyTransform(Transform transform)
112
                {
×
113
                        var newNormal = this.transformNormal(transform, this.Normal);
×
114

115
                        this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
116

117
                        foreach (var vertex in this.Vertices)
×
118
                        {
×
119
                                XYZ v = transOW * vertex.Location.Convert<XYZ>();
×
120
                                v = transform.ApplyTransform(v);
×
121
                                v = transWO * v;
×
122
                                vertex.Location = v;
×
123
                        }
×
124

125
                        this.Normal = newNormal;
×
126
                }
×
127

128
                /// <inheritdoc/>
129
                public override CadObject Clone()
130
                {
300✔
131
                        Polyline<T> clone = (Polyline<T>)base.Clone();
300✔
132

133
                        clone.Vertices = new SeqendCollection<T>(clone);
300✔
134
                        foreach (T v in this.Vertices)
2,158✔
135
                        {
629✔
136
                                clone.Vertices.Add((T)v.Clone());
629✔
137
                        }
629✔
138

139
                        return clone;
300✔
140
                }
300✔
141

142
                /// <inheritdoc/>
143
                public override BoundingBox GetBoundingBox()
144
                {
4✔
145
                        if (this.Vertices.Any(v => v.Bulge != 0))
24!
146
                        {
×
147
                                return BoundingBox.FromPoints(this.GetPoints<XYZ>(byte.MaxValue));
×
148
                        }
149

150
                        return BoundingBox.FromPoints(this.Vertices.Select(v => v.Location.Convert<XYZ>()));
24✔
151
                }
4✔
152

153
                internal static IEnumerable<Entity> Explode(IPolyline polyline)
154
                {
×
155
                        //Generic explode method for Polyline2D and LwPolyline
156
                        List<Entity> entities = new List<Entity>();
×
157

158
                        for (int i = 0; i < polyline.Vertices.Count(); i++)
×
159
                        {
×
160
                                IVertex curr = polyline.Vertices.ElementAt(i);
×
161
                                IVertex next = polyline.Vertices.ElementAtOrDefault(i + 1);
×
162

163
                                if (next == null && polyline.IsClosed)
×
164
                                {
×
165
                                        next = polyline.Vertices.First();
×
166
                                }
×
167
                                else if (next == null)
×
168
                                {
×
169
                                        break;
×
170
                                }
171

172
                                Entity e = null;
×
173
                                if (curr.Bulge == 0)
×
174
                                {
×
175
                                        //Is a line
176
                                        e = new Line
×
177
                                        {
×
178
                                                StartPoint = curr.Location.Convert<XYZ>(),
×
179
                                                EndPoint = next.Location.Convert<XYZ>(),
×
180
                                                Normal = polyline.Normal,
×
181
                                                Thickness = polyline.Thickness,
×
182
                                        };
×
183
                                }
×
184
                                else
185
                                {
×
186
                                        XY p1 = curr.Location.Convert<XY>();
×
187
                                        XY p2 = next.Location.Convert<XY>();
×
188

189
                                        //Is an arc
190
                                        Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge);
×
191
                                        arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);
×
192
                                        arc.Normal = polyline.Normal;
×
193
                                        arc.Thickness = polyline.Thickness;
×
194

195
                                        e = arc;
×
196
                                }
×
197

NEW
198
                                e.MatchProperties(polyline);
×
199

200
                                entities.Add(e);
×
201
                        }
×
202

203
                        return entities;
×
204
                }
×
205

206
                internal override void AssignDocument(CadDocument doc)
207
                {
21,189✔
208
                        base.AssignDocument(doc);
21,189✔
209
                        doc.RegisterCollection(this.Vertices);
21,189✔
210
                }
21,189✔
211

212
                internal override void UnassignDocument()
213
                {
66✔
214
                        this.Document.UnregisterCollection(this.Vertices);
66✔
215
                        base.UnassignDocument();
66✔
216
                }
66✔
217

218
                private void onAddVertices(object sender, CollectionChangedEventArgs e)
219
                {
547,687✔
220
                        if (!(e.Item is Entity entity))
547,687!
221
                        {
×
222
                                return;
×
223
                        }
224

225
                        entity.MatchProperties(this);
547,687✔
226
                }
547,687✔
227
        }
228
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc