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

DomCR / ACadSharp / 12559245072

31 Dec 2024 11:54AM UTC coverage: 75.021% (+0.02%) from 75.001%
12559245072

Pull #518

github

web-flow
Merge e65a8119e into f0cbe7044
Pull Request #518: Imrpove CI

5141 of 7558 branches covered (68.02%)

Branch coverage included in aggregate %.

20493 of 26611 relevant lines covered (77.01%)

36386.35 hits per line

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

77.98
/src/ACadSharp/Entities/CadImageBase.cs
1
using ACadSharp.Attributes;
2
using CSMath;
3
using System.Collections.Generic;
4
using System;
5
using ACadSharp.Objects;
6
using System.Linq;
7

8
namespace ACadSharp.Entities
9
{
10
        /// <summary>
11
        /// Common base class for <see cref="RasterImage" /> and <see cref="Wipeout" />.
12
        /// </summary>
13
        [DxfSubClass(null, true)]
14
        public abstract class CadImageBase : Entity
15
        {
16
                /// <summary>
17
                /// Class version
18
                /// </summary>
19
                [DxfCodeValue(90)]
20
                public int ClassVersion { get; set; }
190✔
21

22
                /// <summary>
23
                /// Insertion point(in WCS)
24
                /// </summary>
25
                [DxfCodeValue(10, 20, 30)]
26
                public XYZ InsertPoint { get; set; }
190✔
27

28
                /// <summary>
29
                /// U-vector of a single pixel(points along the visual bottom of the image, starting at the insertion point) (in WCS)
30
                /// </summary>
31
                [DxfCodeValue(11, 21, 31)]
32
                public XYZ UVector { get; set; } = XYZ.AxisX;
354✔
33

34
                /// <summary>
35
                /// V-vector of a single pixel(points along the visual left side of the image, starting at the insertion point) (in WCS)
36
                /// </summary>
37
                [DxfCodeValue(12, 22, 32)]
38
                public XYZ VVector { get; set; } = XYZ.AxisY;
354✔
39

40
                /// <summary>
41
                /// Image size in pixels
42
                /// </summary>
43
                /// <remarks>
44
                /// 2D point(U and V values)
45
                /// </remarks>
46
                [DxfCodeValue(13, 23)]
47
                public XY Size { get; set; }
190✔
48

49
                /// <summary>
50
                /// Image display properties
51
                /// </summary>
52
                [DxfCodeValue(70)]
53
                public ImageDisplayFlags Flags { get; set; }
264✔
54

55
                /// <summary>
56
                /// Clipping state
57
                /// </summary>
58
                [DxfCodeValue(280)]
59
                public bool ClippingState { get; set; }
190✔
60

61
                /// <summary>
62
                /// Brightness
63
                /// </summary>
64
                /// <remarks>
65
                /// 0-100; default = 50
66
                /// </remarks>
67
                [DxfCodeValue(281)]
68
                public byte Brightness
69
                {
70
                        get { return this._brightness; }
84✔
71
                        set
72
                        {
162✔
73
                                if (value < 0 || value > 100)
162!
74
                                {
×
75
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
×
76
                                }
77

78
                                this._brightness = value;
162✔
79
                        }
162✔
80
                }
81

82
                /// <summary>
83
                /// Contrast
84
                /// </summary>
85
                /// <remarks>
86
                /// 0-100; default = 50
87
                /// </remarks>
88
                [DxfCodeValue(282)]
89
                public byte Contrast
90
                {
91
                        get { return this._contrast; }
84✔
92
                        set
93
                        {
162✔
94
                                if (value < 0 || value > 100)
162!
95
                                {
4✔
96
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
4✔
97
                                }
98

99
                                this._contrast = value;
158✔
100
                        }
158✔
101
                }
102

103
                /// <summary>
104
                /// Fade
105
                /// </summary>
106
                /// <remarks>
107
                /// 0-100; default = 0
108
                /// </remarks>
109
                [DxfCodeValue(283)]
110
                public byte Fade
111
                {
112
                        get { return this._fade; }
84✔
113
                        set
114
                        {
162✔
115
                                if (value < 0 || value > 100)
162!
116
                                {
5✔
117
                                        throw new ArgumentException($"Invalid Brightness value: {value}, must be in range 0-100");
5✔
118
                                }
119

120
                                this._fade = value;
157✔
121
                        }
157✔
122
                }
123

124
                /// <summary>
125
                /// Clipping state
126
                /// </summary>
127
                [DxfCodeValue(290)]
128
                public ClipMode ClipMode { get; set; }
66✔
129

130
                /// <summary>
131
                /// Clipping boundary type
132
                /// </summary>
133
                [DxfCodeValue(71)]
134
                public ClipType ClipType { get; set; } = ClipType.Rectangular;
528✔
135

136
                /// <summary>
137
                /// Clip boundary vertices
138
                /// </summary>
139
                /// <remarks>
140
                /// For rectangular clip boundary type, two opposite corners must be specified.Default is (-0.5,-0.5), (size.x-0.5, size.y-0.5). 2) For polygonal clip boundary type, three or more vertices must be specified.Polygonal vertices must be listed sequentially
141
                /// </remarks>
142
                [DxfCodeValue(DxfReferenceType.Count, 91)]
143
                [DxfCollectionCodeValue(14, 24)]
144
                public List<XY> ClipBoundaryVertices { get; set; } = new List<XY>();
698✔
145

146
                /// <summary>
147
                /// Image definition.
148
                /// </summary>
149
                [DxfCodeValue(DxfReferenceType.Handle, 340)]
150
                public ImageDefinition Definition
151
                {
152
                        get { return this._definition; }
732✔
153
                        set
154
                        {
114✔
155
                                if (value == null)
114✔
156
                                {
16✔
157
                                        return;
16✔
158
                                }
159

160
                                if (this.Document != null)
98✔
161
                                {
77✔
162
                                        this._definition = this.updateCollection(value, this.Document.ImageDefinitions);
77✔
163
                                }
77✔
164
                                else
165
                                {
21✔
166
                                        this._definition = value;
21✔
167
                                }
21✔
168
                        }
114✔
169
                }
170

171
                /// <summary>
172
                /// Reference to image definition reactor
173
                /// </summary>
174
                //It seems that is not necessecary, keep it hidden for now
175
                [DxfCodeValue(DxfReferenceType.Handle, 360)]
176
                internal ImageDefinitionReactor DefinitionReactor
177
                {
178
                        get { return this._definitionReactor; }
×
179
                        set
180
                        {
77✔
181
                                this._definitionReactor = value;
77✔
182
                        }
77✔
183
                }
184

185
                private byte _brightness = 50;
164✔
186
                private byte _contrast = 50;
164✔
187
                private byte _fade = 0;
164✔
188

189
                private ImageDefinition _definition;
190
                private ImageDefinitionReactor _definitionReactor;
191

192
                /// <inheritdoc/>
193
                public override BoundingBox GetBoundingBox()
194
                {
2✔
195
                        if (!this.ClipBoundaryVertices.Any())
2!
196
                        {
2✔
197
                                return BoundingBox.Null;
2✔
198
                        }
199

200
                        double minX = this.ClipBoundaryVertices.Select(v => v.X).Min();
×
201
                        double minY = this.ClipBoundaryVertices.Select(v => v.Y).Min();
×
202
                        XYZ min = new XYZ(minX, minY, 0) + this.InsertPoint;
×
203

204
                        double maxX = this.ClipBoundaryVertices.Select(v => v.X).Max();
×
205
                        double maxY = this.ClipBoundaryVertices.Select(v => v.Y).Max();
×
206
                        XYZ max = new XYZ(maxX, maxY, 0) + this.InsertPoint;
×
207

208
                        BoundingBox box = new BoundingBox(min, max);
×
209

210
                        return box;
×
211
                }
2✔
212

213
                /// <inheritdoc/>
214
                public override CadObject Clone()
215
                {
4✔
216
                        CadImageBase clone = (CadImageBase)base.Clone();
4✔
217

218
                        clone.Definition = (ImageDefinition)this.Definition?.Clone();
4✔
219

220
                        return clone;
4✔
221
                }
4✔
222

223
                internal override void AssignDocument(CadDocument doc)
224
                {
184✔
225
                        base.AssignDocument(doc);
184✔
226

227
                        this._definition = this.updateCollection(this.Definition, doc.ImageDefinitions);
184✔
228

229
                        this.Document.ImageDefinitions.OnRemove += this.imageDefinitionsOnRemove;
184✔
230
                }
184✔
231

232
                internal override void UnassignDocument()
233
                {
28✔
234
                        this.Document.ImageDefinitions.OnRemove -= this.imageDefinitionsOnRemove;
28✔
235

236
                        base.UnassignDocument();
28✔
237

238
                        this.Definition = (ImageDefinition)this.Definition?.Clone();
28✔
239
                }
28✔
240

241
                private void imageDefinitionsOnRemove(object sender, CollectionChangedEventArgs e)
242
                {
×
243
                        if (e.Item.Equals(this.Definition))
×
244
                        {
×
245
                                this.Definition = null;
×
246
                        }
×
247
                }
×
248
        }
249
}
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