From 3a5b017a72856992b28bf9d407a52177cdce40f9 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 13 Jul 2022 14:35:56 +0100 Subject: [PATCH] Add Color.Deconstruct --- CHANGELOG.md | 3 ++ X10D.Unity/src/Drawing/Color32Extensions.cs | 54 +++++++++++++++++++++ X10D.Unity/src/Drawing/ColorExtensions.cs | 54 +++++++++++++++++++++ X10D/src/Drawing/ColorExtensions.cs | 54 +++++++++++++++++++++ 4 files changed, 165 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2617b08..63bb7db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Added - X10D: Added `MathUtility.InverseLerp(float, float, float)` and `MathUtility.InverseLerp(double, double, double)` - X10D: Added `Circle`, `CircleF`, `Cuboid`, `Ellipse`, `EllipseF`, `Line3D`, `Line`, `LineF`, `Polygon`, `PolygonF`, `Polyhedron`, and `Sphere`, to complement System.Drawing structs such as `Point` and `Rectangle` +- X10D: Added `Color.Deconstruct()` - with optional alpha parameter - X10D: Added `Color.GetClosestConsoleColor()` - X10D: Added `DateTime.GetIso8601WeekOfYear()` and `DateTimeOffset.GetIso8601WeekOfYear()` - X10D: Added `DirectoryInfo.Clear([bool])` @@ -34,8 +35,10 @@ - X10D.Unity: Added `DebugEx`, which mimics `UnityEngine.Debug` while offering more useful primitive drawing methods - X10D.Unity: Added `System.Drawing.Color.ToUnityColor()` - X10D.Unity: Added `System.Drawing.Color.ToUnityColor32()` +- X10D.Unity: Added `Color.Deconstruct()` - with optional alpha parameter - X10D.Unity: Added `Color.GetClosestConsoleColor()` - X10D.Unity: Added `Color.ToSystemDrawingColor()` +- X10D.Unity: Added `Color32.Deconstruct()` - with optional alpha parameter - X10D.Unity: Added `Color32.GetClosestConsoleColor()` - X10D.Unity: Added `Color32.ToSystemDrawingColor()` - X10D.Unity: Added `Point.ToUnityVector2()` diff --git a/X10D.Unity/src/Drawing/Color32Extensions.cs b/X10D.Unity/src/Drawing/Color32Extensions.cs index 6c0cfa0..a505c94 100644 --- a/X10D.Unity/src/Drawing/Color32Extensions.cs +++ b/X10D.Unity/src/Drawing/Color32Extensions.cs @@ -10,6 +10,60 @@ namespace X10D.Unity.Drawing; /// public static class Color32Extensions { + /// + /// Deconstructs the current color into its RGB components. + /// + /// The source color. + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static void Deconstruct(this Color32 color, out byte a, out byte r, out byte g, out byte b) + { + a = color.a; + (r, g, b) = color; + } + + /// + /// Deconstructs the current color into its RGB components. + /// + /// The source color. + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static void Deconstruct(this Color32 color, out byte r, out byte g, out byte b) + { + r = color.r; + g = color.g; + b = color.b; + } + /// /// Returns a which most closely resembles the current color. /// diff --git a/X10D.Unity/src/Drawing/ColorExtensions.cs b/X10D.Unity/src/Drawing/ColorExtensions.cs index f3b5861..06fcb6a 100644 --- a/X10D.Unity/src/Drawing/ColorExtensions.cs +++ b/X10D.Unity/src/Drawing/ColorExtensions.cs @@ -10,6 +10,60 @@ namespace X10D.Unity.Drawing; /// public static class ColorExtensions { + /// + /// Deconstructs the current color into its ARGB components. + /// + /// The source color. + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static void Deconstruct(this Color color, out float a, out float r, out float g, out float b) + { + a = color.a; + (r, g, b) = color; + } + + /// + /// Deconstructs the current color into its RGB components. + /// + /// The source color. + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static void Deconstruct(this Color color, out float r, out float g, out float b) + { + r = color.r; + g = color.g; + b = color.b; + } + /// /// Returns a which most closely resembles the current color. /// diff --git a/X10D/src/Drawing/ColorExtensions.cs b/X10D/src/Drawing/ColorExtensions.cs index 5d71965..4542264 100644 --- a/X10D/src/Drawing/ColorExtensions.cs +++ b/X10D/src/Drawing/ColorExtensions.cs @@ -9,6 +9,60 @@ namespace X10D.Drawing; /// public static class ColorExtensions { + /// + /// Deconstructs the current color into its ARGB components. + /// + /// The source color. + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static void Deconstruct(this Color color, out byte a, out byte r, out byte g, out byte b) + { + a = color.A; + (r, g, b) = color; + } + + /// + /// Deconstructs the current color into its RGB components. + /// + /// The source color. + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + /// + /// When this method returns, contains the component of . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static void Deconstruct(this Color color, out byte r, out byte g, out byte b) + { + r = color.R; + g = color.G; + b = color.B; + } + /// /// Returns a which most closely resembles the current color. ///