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

DomCR / ACadSharp / 19388119560

15 Nov 2025 09:57AM UTC coverage: 78.209% (+0.04%) from 78.169%
19388119560

push

github

web-flow
Merge pull request #874 from DomCR/issue-872_polyline-getboundingbox-curves-fix

issue 872

7403 of 10253 branches covered (72.2%)

Branch coverage included in aggregate %.

22 of 24 new or added lines in 4 files covered. (91.67%)

2 existing lines in 2 files now uncovered.

27637 of 34550 relevant lines covered (79.99%)

98617.41 hits per line

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

50.0
/src/ACadSharp/Entities/PolyLine.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Extensions;
3
using CSMath;
4
using CSUtilities.Extensions;
5
using System.Collections.Generic;
6
using System.Linq;
7

8
namespace ACadSharp.Entities
9
{
10
        /// <summary>
11
        /// Represents a <see cref="Polyline{T}"/> entity.
12
        /// </summary>
13
        [DxfName(DxfFileToken.EntityPolyline)]
14
        [DxfSubClass(null, true)]
15
        public abstract class Polyline<T> : Entity, IPolyline
16
                where T : Entity, IVertex
17
        {
18
                /// <inheritdoc/>
19
                [DxfCodeValue(30)]
20
                public double Elevation { get; set; } = 0.0;
35,746✔
21

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

28
                /// <summary>
29
                /// Polyline flags.
30
                /// </summary>
31
                [DxfCodeValue(70)]
32
                public PolylineFlags Flags { get => this._flags; set => this._flags = value; }
11,748✔
33

34
                /// <inheritdoc/>
35
                public bool IsClosed
36
                {
37
                        get
38
                        {
30✔
39
                                return this.Flags.HasFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM) || this.Flags.HasFlag(PolylineFlags.ClosedPolygonMeshInN);
30✔
40
                        }
30✔
41
                        set
42
                        {
148✔
43
                                if (value)
148✔
44
                                {
30✔
45
                                        this._flags.AddFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
30✔
46
                                        this._flags.AddFlag(PolylineFlags.ClosedPolygonMeshInN);
30✔
47
                                }
30✔
48
                                else
49
                                {
118✔
50
                                        this._flags.RemoveFlag(PolylineFlags.ClosedPolylineOrClosedPolygonMeshInM);
118✔
51
                                        this._flags.RemoveFlag(PolylineFlags.ClosedPolygonMeshInN);
118✔
52
                                }
118✔
53
                        }
148✔
54
                }
55

56
                /// <inheritdoc/>
57
                [DxfCodeValue(210, 220, 230)]
58
                public XYZ Normal { get; set; } = XYZ.AxisZ;
23,398✔
59

60
                /// <inheritdoc/>
61
                public override string ObjectName => DxfFileToken.EntityPolyline;
4,838✔
62

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

69
                /// <summary>
70
                /// Start width.
71
                /// </summary>
72
                [DxfCodeValue(40)]
73
                public double StartWidth { get; set; } = 0.0;
23,362✔
74

75
                /// <inheritdoc/>
76
                [DxfCodeValue(39)]
77
                public double Thickness { get; set; } = 0.0;
23,284✔
78

79
                /// <summary>
80
                /// Vertices that form this polyline.
81
                /// </summary>
82
                /// <remarks>
83
                /// Each <see cref="Vertex"/> has it's own unique handle.
84
                /// </remarks>
85
                public SeqendCollection<T> Vertices { get; private set; }
608,270✔
86

87
                /// <inheritdoc/>
88
                IEnumerable<IVertex> IPolyline.Vertices { get { return this.Vertices; } }
630✔
89

90
                private PolylineFlags _flags;
91

92
                /// <summary>
93
                /// Default constructor.
94
                /// </summary>
95
                public Polyline() : base()
23,253✔
96
                {
23,253✔
97
                        this.Vertices = new SeqendCollection<T>(this);
23,253✔
98
                }
23,253✔
99

100
                public Polyline(IEnumerable<T> vertices, bool isClosed) : this()
102✔
101
                {
102✔
102
                        if (vertices == null)
102!
103
                                throw new System.ArgumentException("The vertices enumerable cannot be null or empty", nameof(vertices));
×
104

105
                        this.Vertices.AddRange(vertices);
102✔
106
                        this.IsClosed = isClosed;
102✔
107
                }
102✔
108

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

114
                        this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
115

116
                        foreach (var vertex in this.Vertices)
×
117
                        {
×
118
                                XYZ v = transOW * vertex.Location.Convert<XYZ>();
×
119
                                v = transform.ApplyTransform(v);
×
120
                                v = transWO * v;
×
121
                                vertex.Location = v;
×
122
                        }
×
123

124
                        this.Normal = newNormal;
×
125
                }
×
126

127
                /// <inheritdoc/>
128
                public override CadObject Clone()
129
                {
586✔
130
                        Polyline<T> clone = (Polyline<T>)base.Clone();
586✔
131

132
                        clone.Vertices = new SeqendCollection<T>(clone);
586✔
133
                        foreach (T v in this.Vertices)
4,200✔
134
                        {
1,221✔
135
                                clone.Vertices.Add((T)v.Clone());
1,221✔
136
                        }
1,221✔
137

138
                        return clone;
586✔
139
                }
586✔
140

141
                /// <inheritdoc/>
142
                public override BoundingBox GetBoundingBox()
143
                {
3✔
144
                        if (this.Vertices.Any(v => v.Bulge != 0))
3!
UNCOV
145
                        {
×
NEW
146
                                return BoundingBox.FromPoints(this.GetPoints<XYZ>(byte.MaxValue));
×
147
                        }
148

149
                        return BoundingBox.FromPoints(this.Vertices.Select(v => v.Location.Convert<XYZ>()));
3✔
150
                }
3✔
151

152
                internal static IEnumerable<Entity> Explode(IPolyline polyline)
153
                {
×
154
                        //Generic explode method for Polyline2D and LwPolyline
155
                        List<Entity> entities = new List<Entity>();
×
156

157
                        for (int i = 0; i < polyline.Vertices.Count(); i++)
×
158
                        {
×
159
                                IVertex curr = polyline.Vertices.ElementAt(i);
×
160
                                IVertex next = polyline.Vertices.ElementAtOrDefault(i + 1);
×
161

162
                                if (next == null && polyline.IsClosed)
×
163
                                {
×
164
                                        next = polyline.Vertices.First();
×
165
                                }
×
166
                                else if (next == null)
×
167
                                {
×
168
                                        break;
×
169
                                }
170

171
                                Entity e = null;
×
172
                                if (curr.Bulge == 0)
×
173
                                {
×
174
                                        //Is a line
175
                                        e = new Line
×
176
                                        {
×
177
                                                StartPoint = curr.Location.Convert<XYZ>(),
×
178
                                                EndPoint = next.Location.Convert<XYZ>(),
×
179
                                                Normal = polyline.Normal,
×
180
                                                Thickness = polyline.Thickness,
×
181
                                        };
×
182
                                }
×
183
                                else
184
                                {
×
185
                                        XY p1 = curr.Location.Convert<XY>();
×
186
                                        XY p2 = next.Location.Convert<XY>();
×
187

188
                                        //Is an arc
189
                                        Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge);
×
190
                                        arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);
×
191
                                        arc.Normal = polyline.Normal;
×
192
                                        arc.Thickness = polyline.Thickness;
×
193

194
                                        e = arc;
×
195
                                }
×
196

197
                                polyline.MatchProperties(e);
×
198

199
                                entities.Add(e);
×
200
                        }
×
201

202
                        return entities;
×
203
                }
×
204

205
                internal override void AssignDocument(CadDocument doc)
206
                {
23,324✔
207
                        base.AssignDocument(doc);
23,324✔
208
                        doc.RegisterCollection(this.Vertices);
23,324✔
209
                }
23,324✔
210

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

© 2025 Coveralls, Inc