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

DomCR / ACadSharp / 14236632495

03 Apr 2025 06:41AM UTC coverage: 76.148% (-0.2%) from 76.343%
14236632495

Pull #525

github

web-flow
Merge 7f8069492 into 04434c5d6
Pull Request #525: Issue-524 Explode Hatch

5584 of 8036 branches covered (69.49%)

Branch coverage included in aggregate %.

6 of 99 new or added lines in 17 files covered. (6.06%)

6 existing lines in 5 files now uncovered.

22073 of 28284 relevant lines covered (78.04%)

74241.2 hits per line

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

76.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
                public override string ObjectName => DxfFileToken.EntityPolyline;
52✔
18

19
                /// <inheritdoc/>
20
                [DxfCodeValue(30)]
21
                public double Elevation { get; set; } = 0.0;
11,587✔
22

23
                /// <inheritdoc/>
24
                [DxfCodeValue(39)]
25
                public double Thickness { get; set; } = 0.0;
11,115✔
26

27
                /// <inheritdoc/>
28
                [DxfCodeValue(210, 220, 230)]
29
                public XYZ Normal { get; set; } = XYZ.AxisZ;
11,179✔
30

31
                /// <summary>
32
                /// Polyline flags.
33
                /// </summary>
34
                [DxfCodeValue(70)]
35
                public PolylineFlags Flags { get; set; }
846✔
36

37
                /// <summary>
38
                /// Start width.
39
                /// </summary>
40
                [DxfCodeValue(40)]
41
                public double StartWidth { get; set; } = 0.0;
11,115✔
42

43
                /// <summary>
44
                /// End width.
45
                /// </summary>
46
                [DxfCodeValue(41)]
47
                public double EndWidth { get; set; } = 0.0;
11,115✔
48

49
                //71        Polygon mesh M vertex count(optional; default = 0)
50
                //72        Polygon mesh N vertex count(optional; default = 0)
51
                //73        Smooth surface M density(optional; default = 0)
52
                //74        Smooth surface N density(optional; default = 0)
53

54
                /// <summary>
55
                /// Curves and smooth surface type.
56
                /// </summary>
57
                [DxfCodeValue(75)]
58
                public SmoothSurfaceType SmoothSurface { get; set; }
64✔
59

60
                /// <summary>
61
                /// Vertices that form this polyline.
62
                /// </summary>
63
                /// <remarks>
64
                /// Each <see cref="Vertex"/> has it's own unique handle.
65
                /// </remarks>
66
                public SeqendCollection<Vertex> Vertices { get; private set; }
27,212✔
67

68
                /// <inheritdoc/>
69
                public bool IsClosed
70
                {
71
                        get
72
                        {
×
73
                                return this.Flags.HasFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM) || this.Flags.HasFlag(PolylineFlags.ClosedPolygonMeshInN);
×
74
                        }
×
75
                        set
76
                        {
27✔
77
                                if (value)
27!
78
                                {
×
79
                                        this.Flags = this.Flags.AddFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
×
80
                                        this.Flags = this.Flags.AddFlag(PolylineFlags.ClosedPolygonMeshInN);
×
81
                                }
×
82
                                else
83
                                {
27✔
84
                                        this.Flags = this.Flags.RemoveFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
27✔
85
                                        this.Flags = this.Flags.RemoveFlag(PolylineFlags.ClosedPolygonMeshInN);
27✔
86
                                }
27✔
87
                        }
27✔
88
                }
89

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

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

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

105
                /// <inheritdoc/>
106
                public abstract IEnumerable<Entity> Explode();
107

108
                /// <inheritdoc/>
109
                public override BoundingBox GetBoundingBox()
110
                {
3✔
111
                        //TODO: can a polyline have only 1 vertex?
112
                        if (this.Vertices.Count < 2)
3!
113
                        {
3✔
114
                                return BoundingBox.Null;
3✔
115
                        }
116

117
                        XYZ first = this.Vertices[0].Location;
×
118
                        XYZ second = this.Vertices[1].Location;
×
119

120
                        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));
×
121
                        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));
×
122

123
                        for (int i = 2; i < this.Vertices.Count; i++)
×
124
                        {
×
125
                                XYZ curr = this.Vertices[i].Location;
×
126

127
                                min = new XYZ(System.Math.Min(min.X, curr.X), System.Math.Min(min.Y, curr.Y), System.Math.Min(min.Z, curr.Z));
×
128
                                max = new XYZ(System.Math.Max(max.X, curr.X), System.Math.Max(max.Y, curr.Y), System.Math.Max(max.Z, curr.Z));
×
129
                        }
×
130

131
                        return new BoundingBox(min, max);
×
132
                }
3✔
133

134
                protected abstract void verticesOnAdd(object sender, CollectionChangedEventArgs e);
135

136
                internal static IEnumerable<Entity> Explode(IPolyline polyline)
137
                {
3✔
138
                        //Generic explode method for Polyline2D and LwPolyline
139
                        List<Entity> entities = new List<Entity>();
3✔
140

141
                        for (int i = 0; i < polyline.Vertices.Count(); i++)
26✔
142
                        {
12✔
143
                                IVertex curr = polyline.Vertices.ElementAt(i);
12✔
144
                                IVertex next = polyline.Vertices.ElementAtOrDefault(i + 1);
12✔
145

146
                                if (next == null && polyline.IsClosed)
12✔
147
                                {
1✔
148
                                        next = polyline.Vertices.First();
1✔
149
                                }
1✔
150
                                else if (next == null)
11✔
151
                                {
2✔
152
                                        break;
2✔
153
                                }
154

155
                                Entity e = null;
10✔
156
                                if (curr.Bulge == 0)
10✔
157
                                {
9✔
158
                                        //Is a line
159
                                        e = new Line
9✔
160
                                        {
9✔
161
                                                StartPoint = curr.Location.Convert<XYZ>(),
9✔
162
                                                EndPoint = next.Location.Convert<XYZ>(),
9✔
163
                                                Normal = polyline.Normal,
9✔
164
                                                Thickness = polyline.Thickness,
9✔
165
                                        };
9✔
166
                                }
9✔
167
                                else
168
                                {
1✔
169
                                        XY p1 = curr.Location.Convert<XY>();
1✔
170
                                        XY p2 = next.Location.Convert<XY>();
1✔
171

172
                                        //Is an arc
173
                                        Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge);
1✔
174
                                        arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);
1✔
175
                                        arc.Normal = polyline.Normal;
1✔
176
                                        arc.Thickness = polyline.Thickness;
1✔
177

178
                                        e = arc;
1✔
179
                                }
1✔
180

181
                                polyline.MatchProperties(e);
10✔
182

183
                                entities.Add(e);
10✔
184
                        }
10✔
185

186
                        return entities;
3✔
187
                }
3✔
188

189
                /// <inheritdoc/>
190
                public override CadObject Clone()
191
                {
10✔
192
                        Polyline clone = (Polyline)base.Clone();
10✔
193

194
                        clone.Vertices = new SeqendCollection<Vertex>(clone);
10✔
195
                        foreach (Vertex v in this.Vertices)
36✔
196
                        {
3✔
197
                                clone.Vertices.Add((Vertex)v.Clone());
3✔
198
                        }
3✔
199

200
                        return clone;
10✔
201
                }
10✔
202

203
                internal override void AssignDocument(CadDocument doc)
204
                {
698✔
205
                        base.AssignDocument(doc);
698✔
206
                        doc.RegisterCollection(this.Vertices);
698✔
207
                }
698✔
208

209
                internal override void UnassignDocument()
210
                {
28✔
211
                        this.Document.UnregisterCollection(this.Vertices);
28✔
212
                        base.UnassignDocument();
28✔
213
                }
28✔
214
        }
215
}
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