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

DomCR / ACadSharp / 10530740636

23 Aug 2024 06:42PM UTC coverage: 76.025% (+0.04%) from 75.984%
10530740636

push

github

web-flow
Merge pull request #429 from DomCR/cadcollections-refactor

Cadcollections refactor

4831 of 7017 branches covered (68.85%)

Branch coverage included in aggregate %.

19256 of 24666 relevant lines covered (78.07%)

33127.24 hits per line

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

78.99
/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;
59✔
18

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

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

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

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

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

43
                /// <summary>
44
                /// End width.
45
                /// </summary>
46
                [DxfCodeValue(41)]
47
                public double EndWidth { get; set; } = 0.0;
5,107✔
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; }
8,007✔
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
                        {
24✔
77
                                if (value)
24!
78
                                {
×
79
                                        this.Flags = this.Flags.AddFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
×
80
                                        this.Flags = this.Flags.AddFlag(PolylineFlags.ClosedPolygonMeshInN);
×
81
                                }
×
82
                                else
83
                                {
24✔
84
                                        this.Flags = this.Flags.RemoveFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
24✔
85
                                        this.Flags = this.Flags.RemoveFlag(PolylineFlags.ClosedPolygonMeshInN);
24✔
86
                                }
24✔
87
                        }
24✔
88
                }
89

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

93
                public Polyline() : base()
5,083✔
94
                {
5,083✔
95
                        this.Vertices = new SeqendCollection<Vertex>(this);
5,083✔
96
                }
5,083✔
97

98
                /// <inheritdoc/>
99
                public abstract IEnumerable<Entity> Explode();
100

101
                /// <inheritdoc/>
102
                public override BoundingBox GetBoundingBox()
103
                {
3✔
104
                        //TODO: can a polyline have only 1 vertex?
105
                        if (this.Vertices.Count < 2)
3!
106
                        {
3✔
107
                                return BoundingBox.Null;
3✔
108
                        }
109

110
                        XYZ first = this.Vertices[0].Location;
×
111
                        XYZ second = this.Vertices[1].Location;
×
112

113
                        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));
×
114
                        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));
×
115

116
                        for (int i = 2; i < this.Vertices.Count; i++)
×
117
                        {
×
118
                                XYZ curr = this.Vertices[i].Location;
×
119

120
                                min = new XYZ(System.Math.Min(min.X, curr.X), System.Math.Min(min.Y, curr.Y), System.Math.Min(min.Z, curr.Z));
×
121
                                max = new XYZ(System.Math.Max(max.X, curr.X), System.Math.Max(max.Y, curr.Y), System.Math.Max(max.Z, curr.Z));
×
122
                        }
×
123

124
                        return new BoundingBox(min, max);
×
125
                }
3✔
126

127
                internal static IEnumerable<Entity> Explode(IPolyline polyline)
128
                {
3✔
129
                        //Generic explode method for Polyline2D and LwPolyline
130
                        List<Entity> entities = new List<Entity>();
3✔
131

132
                        for (int i = 0; i < polyline.Vertices.Count(); i++)
26✔
133
                        {
12✔
134
                                IVertex curr = polyline.Vertices.ElementAt(i);
12✔
135
                                IVertex next = polyline.Vertices.ElementAtOrDefault(i + 1);
12✔
136

137
                                if (next == null && polyline.IsClosed)
12✔
138
                                {
1✔
139
                                        next = polyline.Vertices.First();
1✔
140
                                }
1✔
141
                                else if (next == null)
11✔
142
                                {
2✔
143
                                        break;
2✔
144
                                }
145

146
                                Entity e = null;
10✔
147
                                if (curr.Bulge == 0)
10✔
148
                                {
9✔
149
                                        //Is a line
150
                                        e = new Line
9✔
151
                                        {
9✔
152
                                                StartPoint = curr.Location.Convert<XYZ>(),
9✔
153
                                                EndPoint = next.Location.Convert<XYZ>(),
9✔
154
                                                Normal = polyline.Normal,
9✔
155
                                                Thickness = polyline.Thickness,
9✔
156
                                        };
9✔
157
                                }
9✔
158
                                else
159
                                {
1✔
160
                                        XY p1 = curr.Location.Convert<XY>();
1✔
161
                                        XY p2 = next.Location.Convert<XY>();
1✔
162

163
                                        //Is an arc
164
                                        Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge);
1✔
165
                                        arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);
1✔
166
                                        arc.Normal = polyline.Normal;
1✔
167
                                        arc.Thickness = polyline.Thickness;
1✔
168

169
                                        e = arc;
1✔
170
                                }
1✔
171

172
                                polyline.MatchProperties(e);
10✔
173

174
                                entities.Add(e);
10✔
175
                        }
10✔
176

177
                        return entities;
3✔
178
                }
3✔
179

180
                /// <inheritdoc/>
181
                public override CadObject Clone()
182
                {
7✔
183
                        Polyline clone = (Polyline)base.Clone();
7✔
184

185
                        clone.Vertices = new SeqendCollection<Vertex>(clone);
7✔
186
                        foreach (Vertex v in this.Vertices)
27✔
187
                        {
3✔
188
                                clone.Vertices.Add((Vertex)v.Clone());
3✔
189
                        }
3✔
190

191
                        return clone;
7✔
192
                }
7✔
193

194
                internal override void AssignDocument(CadDocument doc)
195
                {
380✔
196
                        base.AssignDocument(doc);
380✔
197
                        doc.RegisterCollection(this.Vertices);
380✔
198
                }
380✔
199

200
                internal override void UnassignDocument()
201
                {
28✔
202
                        this.Document.UnregisterCollection(this.Vertices);
28✔
203
                        base.UnassignDocument();
28✔
204
                }
28✔
205
        }
206
}
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