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

DomCR / ACadSharp / 14680051233

26 Apr 2025 09:45AM UTC coverage: 75.224% (+0.02%) from 75.202%
14680051233

push

github

web-flow
Merge pull request #634 from DomCR/issue-631_PolygonalVertexes-fix

Issue 631 polygonal vertexes fix

5661 of 8257 branches covered (68.56%)

Branch coverage included in aggregate %.

77 of 104 new or added lines in 5 files covered. (74.04%)

17 existing lines in 4 files now uncovered.

22548 of 29243 relevant lines covered (77.11%)

83187.1 hits per line

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

57.43
/src/ACadSharp/Entities/Entity.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Entities;
3
using ACadSharp.Objects;
4
using ACadSharp.Tables;
5
using CSMath;
6
using CSUtilities.Extensions;
7
using System;
8
using System.Collections.Generic;
9

10
namespace ACadSharp.Entities
11
{
12
        /// <summary>
13
        /// The standard class for a basic CAD entity or a graphical object.
14
        /// </summary>
15
        [DxfSubClass(DxfSubclassMarker.Entity)]
16
        public abstract class Entity : CadObject, IEntity
17
        {
18
                /// <summary>
19
                /// Book color for this entity.
20
                /// </summary>
21
                [DxfCodeValue(DxfReferenceType.Name, 430)]
22
                public BookColor BookColor
23
                {
24
                        get { return this._bookColor; }
26,580✔
25
                        set
26
                        {
275✔
27
                                if (this.Document != null)
275!
28
                                {
275✔
29
                                        this._bookColor = this.updateCollection(value, this.Document.Colors);
275✔
30
                                }
275✔
31
                                else
32
                                {
×
33
                                        this._bookColor = value;
×
34
                                }
×
35
                        }
275✔
36
                }
37

38
                /// <inheritdoc/>
39
                [DxfCodeValue(62, 420)]
40
                public Color Color { get; set; } = Color.ByLayer;
1,053,181✔
41

42
                /// <inheritdoc/>
43
                [DxfCodeValue(60)]
44
                public bool IsInvisible { get; set; } = false;
952,053✔
45

46
                /// <inheritdoc/>
47
                [DxfCodeValue(DxfReferenceType.Name, 8)]
48
                public Layer Layer
49
                {
50
                        get { return this._layer; }
2,075,175✔
51
                        set
52
                        {
275,984✔
53
                                if (value == null)
275,984!
54
                                {
×
55
                                        throw new ArgumentNullException(nameof(value));
×
56
                                }
57

58
                                if (this.Document != null)
275,984✔
59
                                {
143,641✔
60
                                        this._layer = this.updateTable(value, this.Document.Layers);
143,641✔
61
                                }
143,641✔
62
                                else
63
                                {
132,343✔
64
                                        this._layer = value;
132,343✔
65
                                }
132,343✔
66
                        }
275,984✔
67
                }
68

69
                /// <inheritdoc/>
70
                [DxfCodeValue(DxfReferenceType.Name, 6)]
71
                public LineType LineType
72
                {
73
                        get { return this._lineType; }
2,088,906✔
74
                        set
75
                        {
78,038✔
76
                                if (value == null)
78,038!
77
                                {
×
78
                                        throw new ArgumentNullException(nameof(value));
×
79
                                }
80

81
                                this._lineType = this.updateTable(value, this.Document?.LineTypes);
78,038✔
82
                        }
78,038✔
83
                }
84

85
                /// <inheritdoc/>
86
                [DxfCodeValue(48)]
87
                public double LinetypeScale { get; set; } = 1.0;
952,385✔
88

89
                /// <inheritdoc/>
90
                [DxfCodeValue(370)]
91
                public LineweightType LineWeight { get; set; } = LineweightType.ByLayer;
962,178✔
92

93
                /// <inheritdoc/>
94
                [DxfCodeValue(DxfReferenceType.Handle, 347)]
95
                public Material Material { get; set; }
4,248✔
96

97
                /// <inheritdoc/>
98
                public override string SubclassMarker => DxfSubclassMarker.Entity;
494,595✔
99

100
                /// <inheritdoc/>
101
                [DxfCodeValue(440)]
102
                public Transparency Transparency { get; set; } = Transparency.ByLayer;
971,965✔
103

104
                private BookColor _bookColor = null;
867,402✔
105

106
                private Layer _layer = Layer.Default;
867,402✔
107

108
                private LineType _lineType = LineType.ByLayer;
867,402✔
109

110
                /// <inheritdoc/>
111
                public Entity() : base() { }
2,602,206✔
112

113
                /// <summary>
114
                /// Apply a translation to this entity.
115
                /// </summary>
116
                /// <param name="translation"></param>
117
                public void ApplyTranslation(XYZ translation)
118
                {
1✔
119
                        Transform transform = Transform.CreateTranslation(translation);
1✔
120
                        this.ApplyTransform(transform);
1✔
121
                }
1✔
122

123
                /// <summary>
124
                /// Apply a rotation to this entity.
125
                /// </summary>
126
                /// <param name="axis"></param>
127
                /// <param name="rotation"></param>
128
                public void ApplyRotation(XYZ axis, double rotation)
129
                {
×
130
                        Transform transform = Transform.CreateRotation(axis, rotation);
×
131
                        this.ApplyTransform(transform);
×
132
                }
×
133

134
                /// <summary>
135
                /// Apply a scale to this entity.
136
                /// </summary>
137
                /// <param name="scale"></param>
138
                public void ApplyScaling(XYZ scale)
139
                {
×
140
                        Transform transform = Transform.CreateScaling(scale);
×
141
                        this.ApplyTransform(transform);
×
142
                }
×
143

144
                public void ApplyScaling(XYZ scale, XYZ origin)
145
                {
×
146
                        Transform transform = Transform.CreateScaling(scale, origin);
×
147
                        this.ApplyTransform(transform);
×
148
                }
×
149

150
                /// <inheritdoc/>
151
                public abstract void ApplyTransform(Transform transform);
152

153
                /// <inheritdoc/>
154
                public override CadObject Clone()
155
                {
2,124✔
156
                        Entity clone = (Entity)base.Clone();
2,124✔
157

158
                        clone.Layer = (Layer)this.Layer.Clone();
2,124✔
159
                        clone.LineType = (LineType)this.LineType.Clone();
2,124✔
160
                        clone.Material = (Material)this.Material?.Clone();
2,124!
161

162
                        return clone;
2,124✔
163
                }
2,124✔
164

165
                /// <inheritdoc/>
166
                public Color GetActiveColor()
167
                {
22✔
168
                        Color color;
169
                        if (this.Color.IsByLayer)
22✔
170
                        {
18✔
171
                                color = this.Layer.Color;
18✔
172
                        }
18✔
173
                        else
174
                        {
4✔
175
                                color = this.Color;
4✔
176
                        }
4✔
177

178
                        return color;
22✔
179
                }
22✔
180

181
                /// <inheritdoc/>
182
                public abstract BoundingBox GetBoundingBox();
183

184
                /// <inheritdoc/>
185
                public void MatchProperties(IEntity entity)
186
                {
13✔
187
                        if (entity is null)
13!
188
                        {
×
189
                                throw new ArgumentNullException(nameof(entity));
×
190
                        }
191

192
                        if (entity.Handle == 0)
13!
193
                        {
13✔
194
                                entity.Layer = (Layer)this.Layer.Clone();
13✔
195
                                entity.LineType = (LineType)this.LineType.Clone();
13✔
196
                        }
13✔
197
                        else
198
                        {
×
199
                                entity.Layer = this.Layer;
×
200
                                entity.LineType = this.LineType;
×
201
                        }
×
202

203
                        entity.Color = this.Color;
13✔
204
                        entity.LineWeight = this.LineWeight;
13✔
205
                        entity.LinetypeScale = this.LinetypeScale;
13✔
206
                        entity.IsInvisible = this.IsInvisible;
13✔
207
                        entity.Transparency = this.Transparency;
13✔
208
                }
13✔
209

210
                internal override void AssignDocument(CadDocument doc)
211
                {
671,214✔
212
                        base.AssignDocument(doc);
671,214✔
213

214
                        this._layer = this.updateTable(this.Layer, doc.Layers);
671,214✔
215
                        this._lineType = this.updateTable(this.LineType, doc.LineTypes);
671,214✔
216

217
                        doc.Layers.OnRemove += this.tableOnRemove;
671,214✔
218
                        doc.LineTypes.OnRemove += this.tableOnRemove;
671,214✔
219
                }
671,214✔
220

221
                internal override void UnassignDocument()
222
                {
4,209✔
223
                        this.Document.Layers.OnRemove -= this.tableOnRemove;
4,209✔
224
                        this.Document.LineTypes.OnRemove -= this.tableOnRemove;
4,209✔
225

226
                        base.UnassignDocument();
4,209✔
227

228
                        this.Layer = (Layer)this.Layer.Clone();
4,209✔
229
                        this.LineType = (LineType)this.LineType.Clone();
4,209✔
230
                }
4,209✔
231

232
                protected XYZ transformNormal(Transform transform, XYZ normal)
233
                {
12✔
234
                        return transform.Rotate(normal).Normalize();
12✔
235
                }
12✔
236

237
                protected virtual void tableOnRemove(object sender, CollectionChangedEventArgs e)
238
                {
46✔
239
                        if (e.Item.Equals(this.Layer))
46✔
240
                        {
1✔
241
                                this.Layer = this.Document.Layers[Layer.DefaultName];
1✔
242
                        }
1✔
243

244
                        if (e.Item.Equals(this.LineType))
46✔
245
                        {
1✔
246
                                this.LineType = this.Document.LineTypes[LineType.ByLayerName];
1✔
247
                        }
1✔
248
                }
46✔
249

250
                protected Matrix3 getWorldMatrix(Transform transform, XYZ normal, XYZ newNormal, out Matrix3 transOW, out Matrix3 transWO)
251
                {
9✔
252
                        transOW = Matrix3.ArbitraryAxis(normal);
9✔
253
                        transWO = Matrix3.ArbitraryAxis(newNormal).Transpose();
9✔
254
                        return new Matrix3(transform.Matrix);
9✔
255
                }
9✔
256

257
                protected XYZ applyWorldMatrix(XYZ xyz, Transform transform, Matrix3 transOW, Matrix3 transWO)
258
                {
×
259
                        XYZ v = transOW * xyz;
×
260
                        v = transform.ApplyTransform(v);
×
261
                        v = transWO * v;
×
262
                        return v;
×
263
                }
×
264

265
                protected XYZ applyWorldMatrix(XYZ xyz, XYZ normal, XYZ newNormal)
NEW
266
                {
×
NEW
267
                        var transOW = Matrix3.ArbitraryAxis(normal).Transpose();
×
NEW
268
                        var transWO = Matrix3.ArbitraryAxis(newNormal);
×
NEW
269
                        XYZ v = transOW * xyz;
×
NEW
270
                        v = transWO * v;
×
NEW
271
                        return v;
×
NEW
272
                }
×
273

274
                protected List<XY> applyRotation(IEnumerable<XY> points, double rotation)
275
                {
×
276
                        if (points == null)
×
277
                        {
×
278
                                throw new ArgumentNullException(nameof(points));
×
279
                        }
280

281
                        if (MathHelper.IsZero(rotation))
×
282
                        {
×
283
                                return new List<XY>(points);
×
284
                        }
285

286
                        double sin = Math.Sin(rotation);
×
287
                        double cos = Math.Cos(rotation);
×
288

289
                        List<XY> transPoints;
290

291
                        transPoints = new List<XY>();
×
292
                        foreach (XY p in points)
×
293
                        {
×
294
                                transPoints.Add(new XY(p.X * cos - p.Y * sin, p.X * sin + p.Y * cos));
×
295
                        }
×
296
                        return transPoints;
×
297
                }
×
298

299
                protected List<XYZ> applyRotation(IEnumerable<XYZ> points, XYZ zAxis)
300
                {
×
301
                        if (points == null)
×
302
                        {
×
303
                                throw new ArgumentNullException(nameof(points));
×
304
                        }
305

306
                        Matrix3 trans = Matrix3.ArbitraryAxis(zAxis);
×
307
                        List<XYZ> transPoints;
308
                        transPoints = new List<XYZ>();
×
309
                        foreach (XYZ p in points)
×
310
                        {
×
311
                                transPoints.Add(trans * p);
×
312
                        }
×
313
                        return transPoints;
×
314
                }
×
315

316
                protected XYZ applyRotation(XYZ points, XYZ zAxis)
NEW
317
                {
×
NEW
318
                        Matrix4 trans = Matrix4.GetArbitraryAxis(zAxis).Transpose();
×
NEW
319
                        return trans * points;
×
NEW
320
                }
×
321
        }
322
}
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