2 * Copyright (c) 2023 Codefoco (codefoco@codefoco.com)
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:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
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
24 using System.ComponentModel;
25 using System.Runtime.InteropServices;
27 namespace Tizen.NUI.Physics2D.Chipmunk
30 /// RGBA channels as floats used to represent the color for debug drawing.
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 [StructLayout(LayoutKind.Sequential)]
34 public struct DebugColor : IEquatable<DebugColor>
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
44 /// Red component in the RGBA color space.
46 [EditorBrowsable(EditorBrowsableState.Never)]
47 public float Red => red;
50 /// Green component in the RGBA color space.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public float Green => green;
56 /// Blue component in the RGBA color space.
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public float Blue => blue;
62 /// Alpha component in the RGBA color space.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public float Alpha => alpha;
68 /// Create a <see cref="DebugColor"/> with the given color channel values.
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public DebugColor(float red, float green, float blue)
72 : this(red, green, blue, 1.0f)
77 /// Create a <see cref="DebugColor"/> with the given color channel values.
79 [EditorBrowsable(EditorBrowsableState.Never)]
80 public DebugColor(float red, float green, float blue, float alpha)
89 /// Check if a <see cref="DebugColor"/> is equal to another object.
91 [EditorBrowsable(EditorBrowsableState.Never)]
92 public override bool Equals(object obj)
94 var other = obj as DebugColor?;
99 return Equals(other.Value);
103 /// Check if a <see cref="DebugColor"/> is reference-equal to the other.
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 public bool Equals(DebugColor color)
108 return this == color;
112 /// Get the hash code.
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public override int GetHashCode()
117 var hashCode = -1813971818;
119 hashCode = hashCode * -1521134295 + red.GetHashCode();
120 hashCode = hashCode * -1521134295 + green.GetHashCode();
121 hashCode = hashCode * -1521134295 + blue.GetHashCode();
122 hashCode = hashCode * -1521134295 + alpha.GetHashCode();
128 /// Return a string formatted as "(R, G, B, A)".
130 [EditorBrowsable(EditorBrowsableState.Never)]
131 public override string ToString()
133 return $"({red},{green},{blue},{alpha})";
137 /// Return true if two <see cref="DebugColor"/> are reference-equal.
139 [EditorBrowsable(EditorBrowsableState.Never)]
140 public static bool operator ==(DebugColor a, DebugColor b)
142 #pragma warning disable RECS0018 // Comparison of floating point numbers with equality operator
143 return a.red == b.red &&
144 a.green == b.green &&
147 #pragma warning restore RECS0018 // Comparison of floating point numbers with equality operator
152 /// Return true if two <see cref="DebugColor"/> are not reference-equal.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public static bool operator !=(DebugColor a, DebugColor b)