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

DomCR / ACadSharp / 18093480635

29 Sep 2025 10:12AM UTC coverage: 77.923% (-0.4%) from 78.349%
18093480635

push

github

web-flow
Merge pull request #776 from DomCR/svg-linetypes

Svg linetypes

6787 of 9447 branches covered (71.84%)

Branch coverage included in aggregate %.

112 of 319 new or added lines in 10 files covered. (35.11%)

11 existing lines in 3 files now uncovered.

26081 of 32733 relevant lines covered (79.68%)

109509.64 hits per line

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

77.62
/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,075✔
19

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

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

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

54
                /// <inheritdoc/>
55
                [DxfCodeValue(210, 220, 230)]
56
                public XYZ Normal { get; set; } = XYZ.AxisZ;
22,619✔
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,535✔
72

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

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

85
                /// <inheritdoc/>
86
                IEnumerable<IVertex> IPolyline.Vertices { get { return this.Vertices; } }
×
87

88
                private PolylineFlags _flags;
89

90
                /// <summary>
91
                /// Default constructor.
92
                /// </summary>
93
                public Polyline() : base()
22,500✔
94
                {
22,500✔
95
                        this.Vertices = new SeqendCollection<Vertex>(this);
22,500✔
96
                        this.Vertices.OnAdd += this.verticesOnAdd;
22,500✔
97
                }
22,500✔
98

99
                public Polyline(IEnumerable<Vertex> vertices, bool isColsed) : this()
19✔
100
                {
19✔
101
                        if (vertices == null)
19!
NEW
102
                                throw new System.ArgumentException("The vertices enumerable cannot be null or empty", nameof(vertices));
×
103

104
                        this.Vertices.AddRange(vertices);
19✔
105
                        this.IsClosed = isColsed;
19✔
106
                }
19✔
107

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

113
                        this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
114

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

123
                        this.Normal = newNormal;
×
124
                }
×
125

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

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

137
                        return clone;
10✔
138
                }
10✔
139

140
                /// <inheritdoc/>
141
                public abstract IEnumerable<Entity> Explode();
142

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

152
                        XYZ first = this.Vertices[0].Location;
×
153
                        XYZ second = this.Vertices[1].Location;
×
154

155
                        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));
×
156
                        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));
×
157

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

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

166
                        return new BoundingBox(min, max);
×
167
                }
3✔
168

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

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

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

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

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

211
                                        e = arc;
1✔
212
                                }
1✔
213

214
                                polyline.MatchProperties(e);
10✔
215

216
                                entities.Add(e);
10✔
217
                        }
10✔
218

219
                        return entities;
3✔
220
                }
3✔
221

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

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

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