diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b5e657..b84503b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ### Added - Reintroduced Unity support - X10D: Added `Color.Inverted()` +- X10D: Added `Color.WithA()` +- X10D: Added `Color.WithB()` +- X10D: Added `Color.WithG()` +- X10D: Added `Color.WithR()` - X10D: Added `ICollection.ClearAndDisposeAll()` - X10D: Added `ICollection.ClearAndDisposeAllAsync()` - X10D: Added `IEnumerable.For()` (#50) @@ -14,7 +18,15 @@ - X10D: Added `Rune.IsEmoji` - X10D: Added `string.IsEmoji` - X10D.Unity: Added `Color.Inverted()` +- X10D.Unity: Added `Color.WithA()` +- X10D.Unity: Added `Color.WithB()` +- X10D.Unity: Added `Color.WithG()` +- X10D.Unity: Added `Color.WithR()` - X10D.Unity: Added `Color32.Inverted()` +- X10D.Unity: Added `Color32.WithA()` +- X10D.Unity: Added `Color32.WithB()` +- X10D.Unity: Added `Color32.WithG()` +- X10D.Unity: Added `Color32.WithR()` - X10D.Unity: Added `Component.GetComponentsInChildrenOnly()` - X10D.Unity: Added `GameObject.GetComponentsInChildrenOnly()` - X10D.Unity: Added `GameObject.LookAt(GameObject[, Vector3])` diff --git a/X10D.Tests/src/Drawing/ColorTests.cs b/X10D.Tests/src/Drawing/ColorTests.cs index 0178a69..09c642c 100644 --- a/X10D.Tests/src/Drawing/ColorTests.cs +++ b/X10D.Tests/src/Drawing/ColorTests.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Drawing; using Microsoft.VisualStudio.TestTools.UnitTesting; using X10D.Drawing; @@ -37,4 +37,33 @@ public class ColorTests Assert.AreEqual(expected, actual); } + + [TestMethod] + public void WithA0_ShouldReturnSameColor_GivenWhite() + { + Color transparent = Color.FromArgb(0, 255, 255, 255); + Assert.AreEqual(transparent, White.WithA(0)); + Assert.AreEqual(transparent, transparent.WithA(0)); + } + + [TestMethod] + public void WithB0_ShouldReturnYellow_GivenWhite() + { + Assert.AreEqual(Yellow, White.WithB(0)); + Assert.AreEqual(Yellow, Yellow.WithB(0)); + } + + [TestMethod] + public void WithG0_ShouldReturnMagenta_GivenWhite() + { + Assert.AreEqual(Magenta, White.WithG(0)); + Assert.AreEqual(Magenta, Magenta.WithG(0)); + } + + [TestMethod] + public void WithR0_ShouldReturnCyan_GivenWhite() + { + Assert.AreEqual(Cyan, White.WithR(0)); + Assert.AreEqual(Cyan, Cyan.WithR(0)); + } } diff --git a/X10D.Unity.Tests/Assets/Tests/Drawing/Color32Tests.cs b/X10D.Unity.Tests/Assets/Tests/Drawing/Color32Tests.cs index 1816e39..ec25662 100644 --- a/X10D.Unity.Tests/Assets/Tests/Drawing/Color32Tests.cs +++ b/X10D.Unity.Tests/Assets/Tests/Drawing/Color32Tests.cs @@ -42,5 +42,42 @@ namespace X10D.Unity.Tests.Drawing yield break; } + + [UnityTest] + public IEnumerator WithA0_ShouldReturnSameColor_GivenWhite() + { + var transparent = new Color32(255, 255, 255, 0); + Assert.AreEqual(transparent, White.WithA(0)); + Assert.AreEqual(transparent, transparent.WithA(0)); + + yield break; + } + + [UnityTest] + public IEnumerator WithB0_ShouldReturnYellow_GivenWhite() + { + Assert.AreEqual(Yellow, White.WithB(0)); + Assert.AreEqual(Yellow, Yellow.WithB(0)); + + yield break; + } + + [UnityTest] + public IEnumerator WithG0_ShouldReturnMagenta_GivenWhite() + { + Assert.AreEqual(Magenta, White.WithG(0)); + Assert.AreEqual(Magenta, Magenta.WithG(0)); + + yield break; + } + + [UnityTest] + public IEnumerator WithR0_ShouldReturnCyan_GivenWhite() + { + Assert.AreEqual(Cyan, White.WithR(0)); + Assert.AreEqual(Cyan, Cyan.WithR(0)); + + yield break; + } } } diff --git a/X10D.Unity.Tests/Assets/Tests/Drawing/ColorTests.cs b/X10D.Unity.Tests/Assets/Tests/Drawing/ColorTests.cs index f28b463..c27ad2c 100644 --- a/X10D.Unity.Tests/Assets/Tests/Drawing/ColorTests.cs +++ b/X10D.Unity.Tests/Assets/Tests/Drawing/ColorTests.cs @@ -42,5 +42,42 @@ namespace X10D.Unity.Tests.Drawing yield break; } + + [UnityTest] + public IEnumerator WithA0_ShouldReturnSameColor_GivenWhite() + { + var transparent = new Color(1, 1, 1, 0); + Assert.AreEqual(transparent, White.WithA(0)); + Assert.AreEqual(transparent, transparent.WithA(0)); + + yield break; + } + + [UnityTest] + public IEnumerator WithB0_ShouldReturnYellow_GivenWhite() + { + Assert.AreEqual(Yellow, White.WithB(0)); + Assert.AreEqual(Yellow, Yellow.WithB(0)); + + yield break; + } + + [UnityTest] + public IEnumerator WithG0_ShouldReturnMagenta_GivenWhite() + { + Assert.AreEqual(Magenta, White.WithG(0)); + Assert.AreEqual(Magenta, Magenta.WithG(0)); + + yield break; + } + + [UnityTest] + public IEnumerator WithR0_ShouldReturnCyan_GivenWhite() + { + Assert.AreEqual(Cyan, White.WithR(0)); + Assert.AreEqual(Cyan, Cyan.WithR(0)); + + yield break; + } } } diff --git a/X10D.Unity/src/Drawing/Color32Extensions.cs b/X10D.Unity/src/Drawing/Color32Extensions.cs index 80a1c49..363f14d 100644 --- a/X10D.Unity/src/Drawing/Color32Extensions.cs +++ b/X10D.Unity/src/Drawing/Color32Extensions.cs @@ -20,4 +20,76 @@ public static class Color32Extensions { return new Color32((byte)(255 - color.r), (byte)(255 - color.g), (byte)(255 - color.b), color.a); } + + /// + /// Returns a vector whose red, green, and blue components are the same as the specified color, and whose alpha component + /// is a new value. + /// + /// The color to copy. + /// The new alpha component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color32 WithA(this Color32 color, byte a) + { + return color with {a = a}; + } + + /// + /// Returns a vector whose red, green, and alpha components are the same as the specified color, and whose blue component + /// is a new value. + /// + /// The color to copy. + /// The new blue component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color32 WithB(this Color32 color, byte b) + { + return color with {b = b}; + } + + /// + /// Returns a vector whose red, blue, and alpha components are the same as the specified color, and whose green component + /// is a new value. + /// + /// The color to copy. + /// The new green component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color32 WithG(this Color32 color, byte g) + { + return color with {g = g}; + } + + /// + /// Returns a vector whose green, blue, and alpha components are the same as the specified color, and whose red component + /// is a new value. + /// + /// The color to copy. + /// The new red component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color32 WithR(this Color32 color, byte r) + { + return color with {r = r}; + } } diff --git a/X10D.Unity/src/Drawing/ColorExtensions.cs b/X10D.Unity/src/Drawing/ColorExtensions.cs index a74e84b..95a6561 100644 --- a/X10D.Unity/src/Drawing/ColorExtensions.cs +++ b/X10D.Unity/src/Drawing/ColorExtensions.cs @@ -20,4 +20,76 @@ public static class ColorExtensions { return new Color(1f - color.r, 1f - color.g, 1f - color.b, color.a); } + + /// + /// Returns a vector whose red, green, and blue components are the same as the specified color, and whose alpha component + /// is a new value. + /// + /// The color to copy. + /// The new alpha component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color WithA(this Color color, float a) + { + return color with {a = a}; + } + + /// + /// Returns a vector whose red, green, and alpha components are the same as the specified color, and whose blue component + /// is a new value. + /// + /// The color to copy. + /// The new blue component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color WithB(this Color color, float b) + { + return color with {b = b}; + } + + /// + /// Returns a vector whose red, blue, and alpha components are the same as the specified color, and whose green component + /// is a new value. + /// + /// The color to copy. + /// The new green component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color WithG(this Color color, float g) + { + return color with {g = g}; + } + + /// + /// Returns a vector whose green, blue, and alpha components are the same as the specified color, and whose red component + /// is a new value. + /// + /// The color to copy. + /// The new red component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Color WithR(this Color color, float r) + { + return color with {r = r}; + } } diff --git a/X10D/src/Drawing/ColorExtensions.cs b/X10D/src/Drawing/ColorExtensions.cs index b335fb2..e21cf9e 100644 --- a/X10D/src/Drawing/ColorExtensions.cs +++ b/X10D/src/Drawing/ColorExtensions.cs @@ -24,4 +24,92 @@ public static class ColorExtensions { return Color.FromArgb(color.A, 255 - color.R, 255 - color.G, 255 - color.B); } + + /// + /// Returns a vector whose red, green, and blue components are the same as the specified color, and whose alpha component + /// is a new value. + /// + /// The color to copy. + /// The new alpha component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static Color WithA(this Color color, int a) + { + return Color.FromArgb(a, color.R, color.G, color.B); + } + + /// + /// Returns a vector whose red, green, and alpha components are the same as the specified color, and whose blue component + /// is a new value. + /// + /// The color to copy. + /// The new blue component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static Color WithB(this Color color, int b) + { + return Color.FromArgb(color.A, color.R, color.G, b); + } + + /// + /// Returns a vector whose red, blue, and alpha components are the same as the specified color, and whose green component + /// is a new value. + /// + /// The color to copy. + /// The new green component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static Color WithG(this Color color, int g) + { + return Color.FromArgb(color.A, color.R, g, color.B); + } + + /// + /// Returns a vector whose green, blue, and alpha components are the same as the specified color, and whose red component + /// is a new value. + /// + /// The color to copy. + /// The new red component value. + /// + /// A new instance of whose , , and + /// components are the same as that of , and whose + /// component is . + /// + [Pure] +#if NETSTANDARD2_1 + [MethodImpl(MethodImplOptions.AggressiveInlining)] +#else + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] +#endif + public static Color WithR(this Color color, int r) + { + return Color.FromArgb(color.A, r, color.G, color.B); + } }