90ad56fd6158cf46010b946f5a6536492d317934
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Physics2D / src / public / chipmunk / DebugColor.cs
1 /*
2  * Copyright (c) 2023 Codefoco (codefoco@codefoco.com)
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  * 
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  * 
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 using System;
24 using System.ComponentModel;
25 using System.Runtime.InteropServices;
26
27 namespace Tizen.NUI.Physics2D.Chipmunk
28 {
29     /// <summary>
30     /// RGBA channels as floats used to represent the color for debug drawing.
31     /// </summary>
32     [EditorBrowsable(EditorBrowsableState.Never)]
33     [StructLayout(LayoutKind.Sequential)]
34     public struct DebugColor : IEquatable<DebugColor>
35     {
36 #pragma warning disable IDE0032
37         private readonly float red;
38         private readonly float green;
39         private readonly float blue;
40         private readonly float alpha;
41 #pragma warning restore IDE0032
42
43         /// <summary>
44         /// Red component in the RGBA color space.
45         /// </summary>
46         [EditorBrowsable(EditorBrowsableState.Never)]
47         public float Red => red;
48
49         /// <summary>
50         /// Green component in the RGBA color space.
51         /// </summary>
52         [EditorBrowsable(EditorBrowsableState.Never)]
53         public float Green => green;
54
55         /// <summary>
56         /// Blue component in the RGBA color space.
57         /// </summary>
58         [EditorBrowsable(EditorBrowsableState.Never)]
59         public float Blue => blue;
60
61         /// <summary>
62         /// Alpha component in the RGBA color space.
63         /// </summary>
64         [EditorBrowsable(EditorBrowsableState.Never)]
65         public float Alpha => alpha;
66
67         /// <summary>
68         /// Create a <see cref="DebugColor"/> with the given color channel values.
69         /// </summary>
70         [EditorBrowsable(EditorBrowsableState.Never)]
71         public DebugColor(float red, float green, float blue)
72             : this(red, green, blue, 1.0f)
73         {
74         }
75
76         /// <summary>
77         /// Create a <see cref="DebugColor"/> with the given color channel values.
78         /// </summary>
79         [EditorBrowsable(EditorBrowsableState.Never)]
80         public DebugColor(float red, float green, float blue, float alpha)
81         {
82             this.red = red;
83             this.green = green;
84             this.blue = blue;
85             this.alpha = alpha;
86         }
87
88         /// <summary>
89         /// Check if a <see cref="DebugColor"/> is equal to another object.
90         /// </summary>
91         [EditorBrowsable(EditorBrowsableState.Never)]
92         public override bool Equals(object obj)
93         {
94             var other = obj as DebugColor?;
95
96             if (other == null)
97                 return false;
98
99             return Equals(other.Value);
100         }
101
102         /// <summary>
103         /// Check if a <see cref="DebugColor"/> is reference-equal to the other.
104         /// </summary>
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public bool Equals(DebugColor color)
107         {
108             return this == color;
109         }
110
111         /// <summary>
112         /// Get the hash code.
113         /// </summary>
114         [EditorBrowsable(EditorBrowsableState.Never)]
115         public override int GetHashCode()
116         {
117             unchecked
118             {
119                 var hashCode = -1813971818;
120
121                 hashCode = hashCode * -1521134295 + red.GetHashCode();
122                 hashCode = hashCode * -1521134295 + green.GetHashCode();
123                 hashCode = hashCode * -1521134295 + blue.GetHashCode();
124                 hashCode = hashCode * -1521134295 + alpha.GetHashCode();
125
126                 return hashCode;
127             }
128         }
129
130         /// <summary>
131         /// Return a string formatted as "(R, G, B, A)".
132         /// </summary>
133         [EditorBrowsable(EditorBrowsableState.Never)]
134         public override string ToString()
135         {
136             return $"({red},{green},{blue},{alpha})";
137         }
138
139         /// <summary>
140         /// Return true if two <see cref="DebugColor"/> are reference-equal.
141         /// </summary>
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public static bool operator ==(DebugColor a, DebugColor b)
144         {
145 #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
146             return a.red == b.red &&
147                 a.green == b.green &&
148                 a.blue == b.blue &&
149                 a.alpha == b.alpha;
150 #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
151         }
152
153
154         /// <summary>
155         /// Return true if two <see cref="DebugColor"/> are not reference-equal.
156         /// </summary>
157         [EditorBrowsable(EditorBrowsableState.Never)]
158         public static bool operator !=(DebugColor a, DebugColor b)
159         {
160             return !(a == b);
161         }
162     }
163 }