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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 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
                public override string ObjectName => DxfFileToken.EntityPolyline;
×
18

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

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

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

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

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

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

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

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

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

101
                /// <inheritdoc/>
102
                public override BoundingBox GetBoundingBox()
103
                {
×
104
                        //TODO: can a polyline have only 1 vertex?
105
                        if (this.Vertices.Count < 2)
×
106
                        {
×
107
                                return BoundingBox.Null;
×
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
                }
×
126

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

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

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

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

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

169
                                        e = arc;
×
170
                                }
×
171

172
                                polyline.MatchProperties(e);
×
173

174
                                entities.Add(e);
×
175
                        }
×
176

177
                        return entities;
×
178
                }
×
179

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

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

191
                        return clone;
×
192
                }
×
193

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

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