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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

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

0.0
/src/ACadSharp/Transparency.cs
1
using System;
2

3
namespace ACadSharp
4
{
5
        /// <summary>
6
        /// Represents the transparency for the graphical objects.
7
        /// </summary>
8
        public struct Transparency
9
        {
10
                /// <summary>
11
                /// Gets the ByLayer transparency.
12
                /// </summary>
13
                public static Transparency ByLayer { get { return new Transparency(-1); } }
×
14

15
                /// <summary>
16
                /// Gets the ByBlock transparency.
17
                /// </summary>
18
                public static Transparency ByBlock { get { return new Transparency(100); } }
×
19

20
                /// <summary>
21
                /// Gets the Opaque transparency.
22
                /// </summary>
23
                public static Transparency Opaque { get { return new Transparency(0); } }
×
24

25
                /// <summary>
26
                /// Defines if the transparency is defined by layer.
27
                /// </summary>
28
                public bool IsByLayer
29
                {
30
                        get { return _value == -1; }
×
31
                }
32

33
                /// <summary>
34
                /// Defines if the transparency is defined by block.
35
                /// </summary>
36
                public bool IsByBlock
37
                {
38
                        get { return _value == 100; }
×
39
                }
40

41
                /// <summary>
42
                /// Gets or sets the transparency value.
43
                /// </summary>
44
                /// <remarks>
45
                /// Transparency values must be in range from 0 (opaque) to 90 (transparent), the reserved values -1 and 100 represents ByLayer and ByBlock.
46
                /// </remarks>
47
                public short Value
48
                {
49
                        get { return _value; }
×
50
                        set
51
                        {
×
52
                                if (value == -1)
×
53
                                {
×
54
                                        _value = value;
×
55
                                        return;
×
56
                                }
57

58
                                if (value == 100)
×
59
                                {
×
60
                                        _value = value;
×
61
                                        return;
×
62
                                }
63

64
                                if (value < 0 || value > 90)
×
65
                                        throw new ArgumentOutOfRangeException(nameof(value), value, "Transparency must be in range from 0 to 90.");
×
66

67
                                _value = value;
×
68
                        }
×
69
                }
70

71
                private short _value;
72

73
                /// <summary>
74
                /// Initializes a new instance of the Transparency struct.
75
                /// </summary>
76
                /// <param name="value">Alpha value range from 0 to 90.</param>
77
                /// <remarks>
78
                /// Transparency values must be in range from 0 (opaque) to 90 (transparent), the reserved values -1 and 100 represents ByLayer and ByBlock.
79
                /// </remarks>
80
                public Transparency(short value)
81
                {
×
82
                        _value = -1;
×
83
                        this.Value = value;
×
84
                }
×
85

86
                /// <summary>
87
                /// Gets the alpha value of a transperency.
88
                /// </summary>
89
                /// <param name="transparency"></param>
90
                /// <returns></returns>
91
                public static int ToAlphaValue(Transparency transparency)
92
                {
×
93
                        byte alpha = (byte)(255 * (100 - transparency.Value) / 100.0);
×
94
                        byte[] bytes = transparency.IsByBlock ? new byte[] { 0, 0, 0, 1 } : new byte[] { alpha, 0, 0, 2 };
×
95
                        return BitConverter.ToInt32(bytes, 0);
×
96
                }
×
97

98
                /// <summary>
99
                /// Gets the transparency from a transparency value
100
                /// </summary>
101
                /// <param name="value">A transparency value</param>
102
                /// <returns>A <see cref="Transparency"></see></returns>
103
                public static Transparency FromAlphaValue(int value)
104
                {
×
105
                        byte[] bytes = BitConverter.GetBytes(value);
×
106
                        short alpha = (short)(100 - (bytes[0] / 255.0) * 100);
×
107

108
                        if (alpha == -1)
×
109
                        {
×
110
                                return ByLayer;
×
111
                        }
112

113
                        if (alpha == 100)
×
114
                        {
×
115
                                return ByBlock;
×
116
                        }
117

118
                        if (alpha < 0)
×
119
                        {
×
120
                                return new Transparency(0);
×
121
                        }
122

123
                        if (alpha > 90)
×
124
                        {
×
125
                                return new Transparency(90);
×
126
                        }
127

128
                        return new Transparency(alpha);
×
129
                }
×
130
        }
131
}
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