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

DomCR / ACadSharp / 17802077781

17 Sep 2025 03:07PM UTC coverage: 78.428% (+0.004%) from 78.424%
17802077781

Pull #795

github

web-flow
Merge 1553544b3 into 8a4aed335
Pull Request #795: Polyface mesh clone fix

6676 of 9251 branches covered (72.17%)

Branch coverage included in aggregate %.

2 of 4 new or added lines in 2 files covered. (50.0%)

15 existing lines in 4 files now uncovered.

25866 of 32242 relevant lines covered (80.22%)

108735.65 hits per line

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

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

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

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

26
                /// <summary>
27
                /// Polyline flags.
28
                /// </summary>
29
                [DxfCodeValue(70)]
30
                public PolylineFlags Flags { get => _flags; set => _flags = value; }
822✔
31

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

54
                /// <inheritdoc/>
55
                [DxfCodeValue(210, 220, 230)]
56
                public XYZ Normal { get; set; } = XYZ.AxisZ;
22,580✔
57

58
                /// <inheritdoc/>
59
                public override string ObjectName => DxfFileToken.EntityPolyline;
2,736✔
60

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

67
                /// <summary>
68
                /// Start width.
69
                /// </summary>
70
                [DxfCodeValue(40)]
71
                public double StartWidth { get; set; } = 0.0;
22,496✔
72

73
                /// <inheritdoc/>
74
                [DxfCodeValue(39)]
75
                public double Thickness { get; set; } = 0.0;
22,496✔
76

77
                //71        Polygon mesh M vertex count(optional; default = 0)
78
                //72        Polygon mesh N vertex count(optional; default = 0)
79
                //73        Smooth surface M density(optional; default = 0)
80
                //74        Smooth surface N density(optional; default = 0)
81
                /// <summary>
82
                /// Vertices that form this polyline.
83
                /// </summary>
84
                /// <remarks>
85
                /// Each <see cref="Vertex"/> has it's own unique handle.
86
                /// </remarks>
87
                public SeqendCollection<Vertex> Vertices { get; private set; }
560,254✔
88

89
                /// <inheritdoc/>
NEW
90
                IEnumerable<IVertex> IPolyline.Vertices { get { return this.Vertices; } }
×
91

92
                private PolylineFlags _flags;
93

94
                public Polyline() : base()
22,461✔
95
                {
22,461✔
96
                        this.Vertices = new SeqendCollection<Vertex>(this);
22,461✔
97
                        this.Vertices.OnAdd += this.verticesOnAdd;
22,461✔
98
                }
22,461✔
99

100
                public Polyline(IEnumerable<Vertex> vertices, bool isColsed) : this()
19✔
101
                {
19✔
102
                        this.Vertices.AddRange(vertices);
19✔
103
                        this.IsClosed = isColsed;
19✔
104
                }
19✔
105

106
                /// <inheritdoc/>
107
                public override void ApplyTransform(Transform transform)
108
                {
×
UNCOV
109
                        var newNormal = this.transformNormal(transform, this.Normal);
×
110

UNCOV
111
                        this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
112

113
                        foreach (var vertex in this.Vertices)
×
114
                        {
×
115
                                XYZ v = transOW * vertex.Location;
×
116
                                v = transform.ApplyTransform(v);
×
117
                                v = transWO * v;
×
118
                                vertex.Location = v;
×
UNCOV
119
                        }
×
120

121
                        this.Normal = newNormal;
×
UNCOV
122
                }
×
123

124
                /// <inheritdoc/>
125
                public override CadObject Clone()
126
                {
10✔
127
                        Polyline clone = (Polyline)base.Clone();
10✔
128

129
                        clone.Vertices = new SeqendCollection<Vertex>(clone);
10✔
130
                        foreach (Vertex v in this.Vertices)
36✔
131
                        {
3✔
132
                                clone.Vertices.Add((Vertex)v.Clone());
3✔
133
                        }
3✔
134

135
                        return clone;
10✔
136
                }
10✔
137

138
                /// <inheritdoc/>
139
                public abstract IEnumerable<Entity> Explode();
140

141
                /// <inheritdoc/>
142
                public override BoundingBox GetBoundingBox()
143
                {
3✔
144
                        //TODO: can a polyline have only 1 vertex?
145
                        if (this.Vertices.Count < 2)
3!
146
                        {
3✔
147
                                return BoundingBox.Null;
3✔
148
                        }
149

150
                        XYZ first = this.Vertices[0].Location;
×
UNCOV
151
                        XYZ second = this.Vertices[1].Location;
×
152

153
                        XYZ min = new XYZ(System.Math.Min(first.X, second.X), System.Math.Min(first.Y, second.Y), System.Math.Min(first.Z, second.Z));
×
UNCOV
154
                        XYZ max = new XYZ(System.Math.Max(first.X, second.X), System.Math.Max(first.Y, second.Y), System.Math.Max(first.Z, second.Z));
×
155

156
                        for (int i = 2; i < this.Vertices.Count; i++)
×
157
                        {
×
UNCOV
158
                                XYZ curr = this.Vertices[i].Location;
×
159

160
                                min = new XYZ(System.Math.Min(min.X, curr.X), System.Math.Min(min.Y, curr.Y), System.Math.Min(min.Z, curr.Z));
×
161
                                max = new XYZ(System.Math.Max(max.X, curr.X), System.Math.Max(max.Y, curr.Y), System.Math.Max(max.Z, curr.Z));
×
UNCOV
162
                        }
×
163

UNCOV
164
                        return new BoundingBox(min, max);
×
165
                }
3✔
166

167
                internal static IEnumerable<Entity> Explode(IPolyline polyline)
168
                {
3✔
169
                        //Generic explode method for Polyline2D and LwPolyline
170
                        List<Entity> entities = new List<Entity>();
3✔
171

172
                        for (int i = 0; i < polyline.Vertices.Count(); i++)
26✔
173
                        {
12✔
174
                                IVertex curr = polyline.Vertices.ElementAt(i);
12✔
175
                                IVertex next = polyline.Vertices.ElementAtOrDefault(i + 1);
12✔
176

177
                                if (next == null && polyline.IsClosed)
12✔
178
                                {
1✔
179
                                        next = polyline.Vertices.First();
1✔
180
                                }
1✔
181
                                else if (next == null)
11✔
182
                                {
2✔
183
                                        break;
2✔
184
                                }
185

186
                                Entity e = null;
10✔
187
                                if (curr.Bulge == 0)
10✔
188
                                {
9✔
189
                                        //Is a line
190
                                        e = new Line
9✔
191
                                        {
9✔
192
                                                StartPoint = curr.Location.Convert<XYZ>(),
9✔
193
                                                EndPoint = next.Location.Convert<XYZ>(),
9✔
194
                                                Normal = polyline.Normal,
9✔
195
                                                Thickness = polyline.Thickness,
9✔
196
                                        };
9✔
197
                                }
9✔
198
                                else
199
                                {
1✔
200
                                        XY p1 = curr.Location.Convert<XY>();
1✔
201
                                        XY p2 = next.Location.Convert<XY>();
1✔
202

203
                                        //Is an arc
204
                                        Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge);
1✔
205
                                        arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);
1✔
206
                                        arc.Normal = polyline.Normal;
1✔
207
                                        arc.Thickness = polyline.Thickness;
1✔
208

209
                                        e = arc;
1✔
210
                                }
1✔
211

212
                                polyline.MatchProperties(e);
10✔
213

214
                                entities.Add(e);
10✔
215
                        }
10✔
216

217
                        return entities;
3✔
218
                }
3✔
219

220
                internal override void AssignDocument(CadDocument doc)
221
                {
10,806✔
222
                        base.AssignDocument(doc);
10,806✔
223
                        doc.RegisterCollection(this.Vertices);
10,806✔
224
                }
10,806✔
225

226
                internal override void UnassignDocument()
227
                {
52✔
228
                        this.Document.UnregisterCollection(this.Vertices);
52✔
229
                        base.UnassignDocument();
52✔
230
                }
52✔
231

232
                protected abstract void verticesOnAdd(object sender, CollectionChangedEventArgs e);
233
        }
234
}
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