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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/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)]
UNCOV
18
                public double Elevation { get; set; } = 0.0;
×
19

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

26
                /// <summary>
27
                /// Polyline flags.
28
                /// </summary>
29
                [DxfCodeValue(70)]
NEW
30
                public PolylineFlags Flags { get => _flags; set => _flags = value; }
×
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
UNCOV
40
                        {
×
UNCOV
41
                                if (value)
×
UNCOV
42
                                {
×
NEW
43
                                        this._flags.AddFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
×
NEW
44
                                        this._flags.AddFlag(PolylineFlags.ClosedPolygonMeshInN);
×
UNCOV
45
                                }
×
46
                                else
UNCOV
47
                                {
×
NEW
48
                                        this._flags.RemoveFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
×
NEW
49
                                        this._flags.RemoveFlag(PolylineFlags.ClosedPolygonMeshInN);
×
UNCOV
50
                                }
×
UNCOV
51
                        }
×
52
                }
53

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

58
                /// <inheritdoc/>
UNCOV
59
                public override string ObjectName => DxfFileToken.EntityPolyline;
×
60

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

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

73
                /// <inheritdoc/>
74
                [DxfCodeValue(39)]
UNCOV
75
                public double Thickness { get; set; } = 0.0;
×
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>
UNCOV
87
                public SeqendCollection<Vertex> Vertices { get; private set; }
×
88

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

92
                private PolylineFlags _flags;
93

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

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

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

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;
×
119
                        }
×
120

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

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

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

UNCOV
135
                        return clone;
×
UNCOV
136
                }
×
137

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

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

150
                        XYZ first = this.Vertices[0].Location;
×
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));
×
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
                        {
×
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));
×
162
                        }
×
163

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

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

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

UNCOV
177
                                if (next == null && polyline.IsClosed)
×
UNCOV
178
                                {
×
UNCOV
179
                                        next = polyline.Vertices.First();
×
UNCOV
180
                                }
×
UNCOV
181
                                else if (next == null)
×
UNCOV
182
                                {
×
UNCOV
183
                                        break;
×
184
                                }
185

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

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

UNCOV
209
                                        e = arc;
×
UNCOV
210
                                }
×
211

UNCOV
212
                                polyline.MatchProperties(e);
×
213

UNCOV
214
                                entities.Add(e);
×
UNCOV
215
                        }
×
216

UNCOV
217
                        return entities;
×
UNCOV
218
                }
×
219

220
                internal override void AssignDocument(CadDocument doc)
UNCOV
221
                {
×
UNCOV
222
                        base.AssignDocument(doc);
×
UNCOV
223
                        doc.RegisterCollection(this.Vertices);
×
UNCOV
224
                }
×
225

226
                internal override void UnassignDocument()
UNCOV
227
                {
×
UNCOV
228
                        this.Document.UnregisterCollection(this.Vertices);
×
UNCOV
229
                        base.UnassignDocument();
×
UNCOV
230
                }
×
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