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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/src/ACadSharp/Entities/Entity.cs
1
using ACadSharp.Attributes;
2
using ACadSharp.Objects;
3
using ACadSharp.Tables;
4
using CSMath;
5
using System;
6
using System.Collections.Generic;
7

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

36
                /// <inheritdoc/>
37
                [DxfCodeValue(62, 420)]
UNCOV
38
                public Color Color { get; set; } = Color.ByLayer;
×
39

40
                /// <inheritdoc/>
41
                [DxfCodeValue(60)]
UNCOV
42
                public bool IsInvisible { get; set; } = false;
×
43

44
                /// <inheritdoc/>
45
                [DxfCodeValue(DxfReferenceType.Name, 8)]
46
                public Layer Layer
47
                {
UNCOV
48
                        get { return this._layer; }
×
49
                        set
UNCOV
50
                        {
×
UNCOV
51
                                if (value == null)
×
52
                                {
×
53
                                        throw new ArgumentNullException(nameof(value));
×
54
                                }
55

UNCOV
56
                                this._layer = updateCollection(value, this.Document?.Layers);
×
UNCOV
57
                        }
×
58
                }
59

60
                /// <inheritdoc/>
61
                [DxfCodeValue(DxfReferenceType.Name, 6)]
62
                public LineType LineType
63
                {
UNCOV
64
                        get { return this._lineType; }
×
65
                        set
UNCOV
66
                        {
×
UNCOV
67
                                if (value == null)
×
68
                                {
×
69
                                        throw new ArgumentNullException(nameof(value));
×
70
                                }
71

UNCOV
72
                                this._lineType = CadObject.updateCollection(value, this.Document?.LineTypes);
×
UNCOV
73
                        }
×
74
                }
75

76
                /// <inheritdoc/>
77
                [DxfCodeValue(48)]
UNCOV
78
                public double LineTypeScale { get; set; } = 1.0;
×
79

80
                /// <inheritdoc/>
81
                [DxfCodeValue(370)]
UNCOV
82
                public LineWeightType LineWeight { get; set; } = LineWeightType.ByLayer;
×
83

84
                /// <inheritdoc/>
85
                [DxfCodeValue(DxfReferenceType.Handle, 347)]
UNCOV
86
                public Material Material { get; set; }
×
87

88
                /// <inheritdoc/>
UNCOV
89
                public override string SubclassMarker => DxfSubclassMarker.Entity;
×
90

91
                /// <inheritdoc/>
92
                [DxfCodeValue(440)]
UNCOV
93
                public Transparency Transparency { get; set; } = Transparency.ByLayer;
×
94

UNCOV
95
                private BookColor _bookColor = null;
×
96

UNCOV
97
                private Layer _layer = Layer.Default;
×
98

UNCOV
99
                private LineType _lineType = LineType.ByLayer;
×
100

101
                /// <inheritdoc/>
UNCOV
102
                public Entity() : base() { }
×
103

104
                /// <summary>
105
                /// Apply a rotation to this entity.
106
                /// </summary>
107
                /// <param name="axis"></param>
108
                /// <param name="rotation">The angle to rotate around the given axis, in radians.</param>
109
                public void ApplyRotation(XYZ axis, double rotation)
UNCOV
110
                {
×
UNCOV
111
                        Transform transform = Transform.CreateRotation(axis, rotation);
×
UNCOV
112
                        this.ApplyTransform(transform);
×
UNCOV
113
                }
×
114

115
                /// <summary>
116
                /// Apply a scaling transformation to this entity.
117
                /// </summary>
118
                /// <param name="scale"></param>
119
                public void ApplyScaling(XYZ scale)
120
                {
×
121
                        Transform transform = Transform.CreateScaling(scale);
×
122
                        this.ApplyTransform(transform);
×
123
                }
×
124

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

136
                /// <inheritdoc/>
137
                public abstract void ApplyTransform(Transform transform);
138

139
                /// <summary>
140
                /// Apply a translation to this entity.
141
                /// </summary>
142
                /// <param name="translation"></param>
143
                public void ApplyTranslation(XYZ translation)
UNCOV
144
                {
×
UNCOV
145
                        Transform transform = Transform.CreateTranslation(translation);
×
UNCOV
146
                        this.ApplyTransform(transform);
×
UNCOV
147
                }
×
148

149
                /// <inheritdoc/>
150
                public override CadObject Clone()
UNCOV
151
                {
×
UNCOV
152
                        Entity clone = (Entity)base.Clone();
×
153

UNCOV
154
                        clone.Layer = (Layer)this.Layer.Clone();
×
UNCOV
155
                        clone.LineType = (LineType)this.LineType.Clone();
×
UNCOV
156
                        clone.Material = (Material)this.Material?.Clone();
×
157

UNCOV
158
                        return clone;
×
UNCOV
159
                }
×
160

161
                /// <inheritdoc/>
162
                public Color GetActiveColor()
UNCOV
163
                {
×
164
                        Color color;
UNCOV
165
                        if (this.Color.IsByLayer)
×
UNCOV
166
                        {
×
UNCOV
167
                                color = this.Layer.Color;
×
UNCOV
168
                        }
×
UNCOV
169
                        else if (this.Color.IsByBlock && this.Owner is BlockRecord record)
×
UNCOV
170
                        {
×
UNCOV
171
                                color = record.BlockEntity.Color;
×
UNCOV
172
                        }
×
173
                        else
UNCOV
174
                        {
×
UNCOV
175
                                color = this.Color;
×
UNCOV
176
                        }
×
177

UNCOV
178
                        return color;
×
UNCOV
179
                }
×
180

181
                /// <inheritdoc/>
182
                public LineType GetActiveLineType()
UNCOV
183
                {
×
UNCOV
184
                        if (this.LineType.Name.Equals(LineType.ByLayerName, StringComparison.InvariantCultureIgnoreCase))
×
UNCOV
185
                        {
×
UNCOV
186
                                return this.Layer.LineType;
×
187
                        }
UNCOV
188
                        else if (this.LineType.Name.Equals(LineType.ByBlockName, StringComparison.InvariantCultureIgnoreCase)
×
UNCOV
189
                                && this.Owner is BlockRecord record)
×
UNCOV
190
                        {
×
UNCOV
191
                                return record.BlockEntity.LineType;
×
192
                        }
193

UNCOV
194
                        return this.LineType;
×
UNCOV
195
                }
×
196

197
                /// <inheritdoc/>
198
                public LineWeightType GetActiveLineWeightType()
UNCOV
199
                {
×
UNCOV
200
                        switch (this.LineWeight)
×
201
                        {
202
                                case LineWeightType.ByLayer:
UNCOV
203
                                        return this.Layer.LineWeight;
×
204
                                case LineWeightType.ByBlock:
UNCOV
205
                                        if (this.Owner is BlockRecord record)
×
UNCOV
206
                                        {
×
UNCOV
207
                                                return record.BlockEntity.LineWeight;
×
208
                                        }
209
                                        else
210
                                        {
×
211
                                                return this.LineWeight;
×
212
                                        }
213
                                default:
UNCOV
214
                                        return this.LineWeight;
×
215
                        }
UNCOV
216
                }
×
217

218
                /// <inheritdoc/>
219
                public abstract BoundingBox GetBoundingBox();
220

221
                /// <inheritdoc/>
222
                public void MatchProperties(IEntity entity)
UNCOV
223
                {
×
UNCOV
224
                        if (entity is null)
×
225
                        {
×
226
                                throw new ArgumentNullException(nameof(entity));
×
227
                        }
228

UNCOV
229
                        if (entity.Handle == 0)
×
UNCOV
230
                        {
×
UNCOV
231
                                entity.Layer = (Layer)this.Layer.Clone();
×
UNCOV
232
                                entity.LineType = (LineType)this.LineType.Clone();
×
UNCOV
233
                        }
×
234
                        else
235
                        {
×
236
                                entity.Layer = this.Layer;
×
237
                                entity.LineType = this.LineType;
×
238
                        }
×
239

UNCOV
240
                        entity.Color = this.Color;
×
UNCOV
241
                        entity.LineWeight = this.LineWeight;
×
UNCOV
242
                        entity.LineTypeScale = this.LineTypeScale;
×
UNCOV
243
                        entity.IsInvisible = this.IsInvisible;
×
UNCOV
244
                        entity.Transparency = this.Transparency;
×
UNCOV
245
                }
×
246

247
                internal override void AssignDocument(CadDocument doc)
UNCOV
248
                {
×
UNCOV
249
                        base.AssignDocument(doc);
×
250

UNCOV
251
                        this._layer = CadObject.updateCollection(this.Layer, doc.Layers);
×
UNCOV
252
                        this._lineType = CadObject.updateCollection(this.LineType, doc.LineTypes);
×
253

UNCOV
254
                        doc.Layers.OnRemove += this.tableOnRemove;
×
UNCOV
255
                        doc.LineTypes.OnRemove += this.tableOnRemove;
×
UNCOV
256
                }
×
257

258
                internal override void UnassignDocument()
UNCOV
259
                {
×
UNCOV
260
                        this.Document.Layers.OnRemove -= this.tableOnRemove;
×
UNCOV
261
                        this.Document.LineTypes.OnRemove -= this.tableOnRemove;
×
262

UNCOV
263
                        base.UnassignDocument();
×
264

UNCOV
265
                        this.Layer = (Layer)this.Layer.Clone();
×
UNCOV
266
                        this.LineType = (LineType)this.LineType.Clone();
×
UNCOV
267
                }
×
268

269
                protected List<XY> applyRotation(IEnumerable<XY> points, double rotation)
UNCOV
270
                {
×
UNCOV
271
                        if (points == null)
×
272
                        {
×
273
                                throw new ArgumentNullException(nameof(points));
×
274
                        }
275

UNCOV
276
                        if (MathHelper.IsZero(rotation))
×
UNCOV
277
                        {
×
UNCOV
278
                                return new List<XY>(points);
×
279
                        }
280

281
                        double sin = Math.Sin(rotation);
×
282
                        double cos = Math.Cos(rotation);
×
283

284
                        List<XY> transPoints;
285

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

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

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

311
                protected XYZ applyRotation(XYZ points, XYZ zAxis)
312
                {
×
313
                        Matrix4 trans = Matrix4.GetArbitraryAxis(zAxis).Transpose();
×
314
                        return trans * points;
×
315
                }
×
316

317
                protected XYZ applyWorldMatrix(XYZ xyz, Transform transform, Matrix3 transOW, Matrix3 transWO)
318
                {
×
319
                        XYZ v = transOW * xyz;
×
320
                        v = transform.ApplyTransform(v);
×
321
                        v = transWO * v;
×
322
                        return v;
×
323
                }
×
324

325
                protected XYZ applyWorldMatrix(XYZ xyz, XYZ normal, XYZ newNormal)
326
                {
×
327
                        var transOW = Matrix3.ArbitraryAxis(normal).Transpose();
×
328
                        var transWO = Matrix3.ArbitraryAxis(newNormal);
×
329
                        XYZ v = transOW * xyz;
×
330
                        v = transWO * v;
×
331
                        return v;
×
332
                }
×
333

334
                protected Matrix3 getWorldMatrix(Transform transform, XYZ normal, XYZ newNormal, out Matrix3 transOW, out Matrix3 transWO)
UNCOV
335
                {
×
UNCOV
336
                        transOW = Matrix3.ArbitraryAxis(normal);
×
UNCOV
337
                        transWO = Matrix3.ArbitraryAxis(newNormal).Transpose();
×
UNCOV
338
                        return new Matrix3(transform.Matrix);
×
UNCOV
339
                }
×
340

341
                protected virtual void tableOnRemove(object sender, CollectionChangedEventArgs e)
UNCOV
342
                {
×
UNCOV
343
                        if (e.Item.Equals(this.Layer))
×
UNCOV
344
                        {
×
UNCOV
345
                                this.Layer = this.Document.Layers[Layer.DefaultName];
×
UNCOV
346
                        }
×
347

UNCOV
348
                        if (e.Item.Equals(this.LineType))
×
UNCOV
349
                        {
×
UNCOV
350
                                this.LineType = this.Document.LineTypes[LineType.ByLayerName];
×
UNCOV
351
                        }
×
UNCOV
352
                }
×
353

354
                protected XYZ transformNormal(Transform transform, XYZ normal)
UNCOV
355
                {
×
UNCOV
356
                        return transform.ApplyRotation(normal).Normalize();
×
UNCOV
357
                }
×
358
        }
359
}
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