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

DomCR / ACadSharp / 14305968221

07 Apr 2025 09:41AM UTC coverage: 75.187% (-1.0%) from 76.181%
14305968221

push

github

DomCR
badge fix

5615 of 8186 branches covered (68.59%)

Branch coverage included in aggregate %.

22386 of 29056 relevant lines covered (77.04%)

72281.98 hits per line

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

71.94
/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;
11,588✔
19

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

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

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

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

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

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

73
                /// <inheritdoc/>
74
                [DxfCodeValue(39)]
75
                public double Thickness { get; set; } = 0.0;
11,116✔
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; }
27,215✔
88

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

92
                public Polyline() : base()
11,089✔
93
                {
11,089✔
94
                        this.Vertices = new SeqendCollection<Vertex>(this);
11,089✔
95
                        this.Vertices.OnAdd += this.verticesOnAdd;
11,089✔
96
                }
11,089✔
97

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

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

109
                        this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
110

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

119
                        this.Normal = newNormal;
×
120
                }
×
121

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

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

133
                        return clone;
10✔
134
                }
10✔
135

136
                /// <inheritdoc/>
137
                public abstract IEnumerable<Entity> Explode();
138

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

148
                        XYZ first = this.Vertices[0].Location;
×
149
                        XYZ second = this.Vertices[1].Location;
×
150

151
                        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));
×
152
                        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));
×
153

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

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

162
                        return new BoundingBox(min, max);
×
163
                }
3✔
164

165
                protected abstract void verticesOnAdd(object sender, CollectionChangedEventArgs e);
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
                {
698✔
222
                        base.AssignDocument(doc);
698✔
223
                        doc.RegisterCollection(this.Vertices);
698✔
224
                }
698✔
225

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