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

DomCR / ACadSharp / 13724254762

07 Mar 2025 03:49PM UTC coverage: 75.29% (-0.8%) from 76.11%
13724254762

Pull #457

github

web-flow
Merge b30f393b9 into a1ba04cda
Pull Request #457: Geometric transform

5484 of 8007 branches covered (68.49%)

Branch coverage included in aggregate %.

220 of 615 new or added lines in 40 files covered. (35.77%)

292 existing lines in 16 files now uncovered.

21823 of 28262 relevant lines covered (77.22%)

74130.22 hits per line

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

70.68
/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,581✔
19

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

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

54
                /// <inheritdoc/>
55
                [DxfCodeValue(210, 220, 230)]
56
                public XYZ Normal { get; set; } = XYZ.AxisZ;
11,173✔
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,109✔
72

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

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

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

97
                /// <inheritdoc/>
98
                public override void ApplyTransform(Transform transform)
NEW
99
                {
×
NEW
100
                        var newNormal = this.transformNormal(transform, this.Normal);
×
101

NEW
102
                        this.getWorldMatrix(transform, this.Normal, newNormal, out Matrix3 transOW, out Matrix3 transWO);
×
103

NEW
104
                        foreach (var vertex in this.Vertices)
×
NEW
105
                        {
×
NEW
106
                                XYZ v = transOW * vertex.Location;
×
NEW
107
                                v = transform.ApplyTransform(v);
×
NEW
108
                                v = transWO * v;
×
NEW
109
                                vertex.Location = v;
×
NEW
110
                        }
×
111

NEW
112
                        this.Normal = newNormal;
×
NEW
113
                }
×
114

115
                /// <inheritdoc/>
116
                public override CadObject Clone()
117
                {
7✔
118
                        Polyline clone = (Polyline)base.Clone();
7✔
119

120
                        clone.Vertices = new SeqendCollection<Vertex>(clone);
7✔
121
                        foreach (Vertex v in this.Vertices)
27✔
122
                        {
3✔
123
                                clone.Vertices.Add((Vertex)v.Clone());
3✔
124
                        }
3✔
125

126
                        return clone;
7✔
127
                }
7✔
128

129
                /// <inheritdoc/>
130
                public abstract IEnumerable<Entity> Explode();
131

132
                /// <inheritdoc/>
133
                public override BoundingBox GetBoundingBox()
134
                {
3✔
135
                        //TODO: can a polyline have only 1 vertex?
136
                        if (this.Vertices.Count < 2)
3!
137
                        {
3✔
138
                                return BoundingBox.Null;
3✔
139
                        }
140

141
                        XYZ first = this.Vertices[0].Location;
×
142
                        XYZ second = this.Vertices[1].Location;
×
143

144
                        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));
×
145
                        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));
×
146

147
                        for (int i = 2; i < this.Vertices.Count; i++)
×
148
                        {
×
149
                                XYZ curr = this.Vertices[i].Location;
×
150

151
                                min = new XYZ(System.Math.Min(min.X, curr.X), System.Math.Min(min.Y, curr.Y), System.Math.Min(min.Z, curr.Z));
×
152
                                max = new XYZ(System.Math.Max(max.X, curr.X), System.Math.Max(max.Y, curr.Y), System.Math.Max(max.Z, curr.Z));
×
153
                        }
×
154

155
                        return new BoundingBox(min, max);
×
156
                }
3✔
157

158
                internal static IEnumerable<Entity> Explode(IPolyline polyline)
159
                {
3✔
160
                        //Generic explode method for Polyline2D and LwPolyline
161
                        List<Entity> entities = new List<Entity>();
3✔
162

163
                        for (int i = 0; i < polyline.Vertices.Count(); i++)
26✔
164
                        {
12✔
165
                                IVertex curr = polyline.Vertices.ElementAt(i);
12✔
166
                                IVertex next = polyline.Vertices.ElementAtOrDefault(i + 1);
12✔
167

168
                                if (next == null && polyline.IsClosed)
12✔
169
                                {
1✔
170
                                        next = polyline.Vertices.First();
1✔
171
                                }
1✔
172
                                else if (next == null)
11✔
173
                                {
2✔
174
                                        break;
2✔
175
                                }
176

177
                                Entity e = null;
10✔
178
                                if (curr.Bulge == 0)
10✔
179
                                {
9✔
180
                                        //Is a line
181
                                        e = new Line
9✔
182
                                        {
9✔
183
                                                StartPoint = curr.Location.Convert<XYZ>(),
9✔
184
                                                EndPoint = next.Location.Convert<XYZ>(),
9✔
185
                                                Normal = polyline.Normal,
9✔
186
                                                Thickness = polyline.Thickness,
9✔
187
                                        };
9✔
188
                                }
9✔
189
                                else
190
                                {
1✔
191
                                        XY p1 = curr.Location.Convert<XY>();
1✔
192
                                        XY p2 = next.Location.Convert<XY>();
1✔
193

194
                                        //Is an arc
195
                                        Arc arc = Arc.CreateFromBulge(p1, p2, curr.Bulge);
1✔
196
                                        arc.Center = new XYZ(arc.Center.X, arc.Center.Y, polyline.Elevation);
1✔
197
                                        arc.Normal = polyline.Normal;
1✔
198
                                        arc.Thickness = polyline.Thickness;
1✔
199

200
                                        e = arc;
1✔
201
                                }
1✔
202

203
                                polyline.MatchProperties(e);
10✔
204

205
                                entities.Add(e);
10✔
206
                        }
10✔
207

208
                        return entities;
3✔
209
                }
3✔
210

211
                internal override void AssignDocument(CadDocument doc)
212
                {
698✔
213
                        base.AssignDocument(doc);
698✔
214
                        doc.RegisterCollection(this.Vertices);
698✔
215
                }
698✔
216

217
                internal override void UnassignDocument()
218
                {
28✔
219
                        this.Document.UnregisterCollection(this.Vertices);
28✔
220
                        base.UnassignDocument();
28✔
221
                }
28✔
222
        }
223
}
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