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

DomCR / ACadSharp / 16494678346

24 Jul 2025 10:40AM UTC coverage: 75.178% (+0.1%) from 75.057%
16494678346

push

github

web-flow
Merge pull request #718 from DomCR/svg-tests

SVG tests

6032 of 8820 branches covered (68.39%)

Branch coverage included in aggregate %.

148 of 167 new or added lines in 6 files covered. (88.62%)

8 existing lines in 3 files now uncovered.

23967 of 31084 relevant lines covered (77.1%)

78848.76 hits per line

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

59.31
/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; }
29,031✔
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,058,263✔
41

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

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

58
                                this._layer = updateTable(value, this.Document?.Layers);
286,909✔
59
                        }
286,909✔
60
                }
61

62
                /// <inheritdoc/>
63
                [DxfCodeValue(DxfReferenceType.Name, 6)]
64
                public LineType LineType
65
                {
66
                        get { return this._lineType; }
2,522,925✔
67
                        set
68
                        {
88,712✔
69
                                if (value == null)
88,712!
70
                                {
×
71
                                        throw new ArgumentNullException(nameof(value));
×
72
                                }
73

74
                                this._lineType = updateTable(value, this.Document?.LineTypes);
88,712✔
75
                        }
88,712✔
76
                }
77

78
                /// <inheritdoc/>
79
                [DxfCodeValue(48)]
80
                public double LinetypeScale { get; set; } = 1.0;
956,120✔
81

82
                /// <inheritdoc/>
83
                [DxfCodeValue(370)]
84
                public LineweightType LineWeight { get; set; } = LineweightType.ByLayer;
965,982✔
85

86
                /// <inheritdoc/>
87
                [DxfCodeValue(DxfReferenceType.Handle, 347)]
88
                public Material Material { get; set; }
22,748✔
89

90
                /// <inheritdoc/>
91
                public override string SubclassMarker => DxfSubclassMarker.Entity;
494,595✔
92

93
                /// <inheritdoc/>
94
                [DxfCodeValue(440)]
95
                public Transparency Transparency { get; set; } = Transparency.ByLayer;
976,169✔
96

97
                private BookColor _bookColor = null;
870,149✔
98

99
                private Layer _layer = Layer.Default;
870,149✔
100

101
                private LineType _lineType = LineType.ByLayer;
870,149✔
102

103
                /// <inheritdoc/>
104
                public Entity() : base() { }
2,610,447✔
105

106
                /// <summary>
107
                /// Apply a translation to this entity.
108
                /// </summary>
109
                /// <param name="translation"></param>
110
                public void ApplyTranslation(XYZ translation)
111
                {
1✔
112
                        Transform transform = Transform.CreateTranslation(translation);
1✔
113
                        this.ApplyTransform(transform);
1✔
114
                }
1✔
115

116
                /// <summary>
117
                /// Apply a rotation to this entity.
118
                /// </summary>
119
                /// <param name="axis"></param>
120
                /// <param name="rotation">The angle to rotate around the given axis, in radians.</param>
121
                public void ApplyRotation(XYZ axis, double rotation)
122
                {
×
123
                        Transform transform = Transform.CreateRotation(axis, rotation);
×
124
                        this.ApplyTransform(transform);
×
125
                }
×
126

127
                /// <summary>
128
                /// Apply a scale to this entity.
129
                /// </summary>
130
                /// <param name="scale"></param>
131
                public void ApplyScaling(XYZ scale)
132
                {
×
133
                        Transform transform = Transform.CreateScaling(scale);
×
134
                        this.ApplyTransform(transform);
×
135
                }
×
136

137
                public void ApplyScaling(XYZ scale, XYZ origin)
138
                {
×
139
                        Transform transform = Transform.CreateScaling(scale, origin);
×
140
                        this.ApplyTransform(transform);
×
141
                }
×
142

143
                /// <inheritdoc/>
144
                public abstract void ApplyTransform(Transform transform);
145

146
                /// <inheritdoc/>
147
                public override CadObject Clone()
148
                {
11,374✔
149
                        Entity clone = (Entity)base.Clone();
11,374✔
150

151
                        clone.Layer = (Layer)this.Layer.Clone();
11,374✔
152
                        clone.LineType = (LineType)this.LineType.Clone();
11,374✔
153
                        clone.Material = (Material)this.Material?.Clone();
11,374!
154

155
                        return clone;
11,374✔
156
                }
11,374✔
157

158
                /// <inheritdoc/>
159
                public Color GetActiveColor()
160
                {
119✔
161
                        Color color;
162
                        if (this.Color.IsByLayer)
119✔
163
                        {
100✔
164
                                color = this.Layer.Color;
100✔
165
                        }
100✔
166
                        else if (this.Color.IsByBlock && this.Owner is BlockRecord record)
19!
NEW
167
                        {
×
NEW
168
                                color = record.BlockEntity.Color;
×
NEW
169
                        }
×
170
                        else
171
                        {
19✔
172
                                color = this.Color;
19✔
173
                        }
19✔
174

175
                        return color;
119✔
176
                }
119✔
177

178
                /// <inheritdoc/>
179
                public abstract BoundingBox GetBoundingBox();
180

181
                /// <inheritdoc/>
182
                public void MatchProperties(IEntity entity)
183
                {
14✔
184
                        if (entity is null)
14!
185
                        {
×
186
                                throw new ArgumentNullException(nameof(entity));
×
187
                        }
188

189
                        if (entity.Handle == 0)
14!
190
                        {
14✔
191
                                entity.Layer = (Layer)this.Layer.Clone();
14✔
192
                                entity.LineType = (LineType)this.LineType.Clone();
14✔
193
                        }
14✔
194
                        else
195
                        {
×
196
                                entity.Layer = this.Layer;
×
197
                                entity.LineType = this.LineType;
×
198
                        }
×
199

200
                        entity.Color = this.Color;
14✔
201
                        entity.LineWeight = this.LineWeight;
14✔
202
                        entity.LinetypeScale = this.LinetypeScale;
14✔
203
                        entity.IsInvisible = this.IsInvisible;
14✔
204
                        entity.Transparency = this.Transparency;
14✔
205
                }
14✔
206

207
                internal override void AssignDocument(CadDocument doc)
208
                {
804,495✔
209
                        base.AssignDocument(doc);
804,495✔
210

211
                        this._layer = updateTable(this.Layer, doc.Layers);
804,495✔
212
                        this._lineType = updateTable(this.LineType, doc.LineTypes);
804,495✔
213

214
                        doc.Layers.OnRemove += this.tableOnRemove;
804,495✔
215
                        doc.LineTypes.OnRemove += this.tableOnRemove;
804,495✔
216
                }
804,495✔
217

218
                internal override void UnassignDocument()
219
                {
5,505✔
220
                        this.Document.Layers.OnRemove -= this.tableOnRemove;
5,505✔
221
                        this.Document.LineTypes.OnRemove -= this.tableOnRemove;
5,505✔
222

223
                        base.UnassignDocument();
5,505✔
224

225
                        this.Layer = (Layer)this.Layer.Clone();
5,505✔
226
                        this.LineType = (LineType)this.LineType.Clone();
5,505✔
227
                }
5,505✔
228

229
                protected XYZ transformNormal(Transform transform, XYZ normal)
230
                {
13✔
231
                        return transform.Rotate(normal).Normalize();
13✔
232
                }
13✔
233

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

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

247
                protected Matrix3 getWorldMatrix(Transform transform, XYZ normal, XYZ newNormal, out Matrix3 transOW, out Matrix3 transWO)
248
                {
10✔
249
                        transOW = Matrix3.ArbitraryAxis(normal);
10✔
250
                        transWO = Matrix3.ArbitraryAxis(newNormal).Transpose();
10✔
251
                        return new Matrix3(transform.Matrix);
10✔
252
                }
10✔
253

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

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

271
                protected List<XY> applyRotation(IEnumerable<XY> points, double rotation)
272
                {
1✔
273
                        if (points == null)
1!
274
                        {
×
275
                                throw new ArgumentNullException(nameof(points));
×
276
                        }
277

278
                        if (MathHelper.IsZero(rotation))
1!
279
                        {
1✔
280
                                return new List<XY>(points);
1✔
281
                        }
282

283
                        double sin = Math.Sin(rotation);
×
284
                        double cos = Math.Cos(rotation);
×
285

286
                        List<XY> transPoints;
287

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

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

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

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