1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:48:46 +00:00

Add Vector.With* methods (resolves #56)

This commit is contained in:
Oliver Booth 2022-05-09 10:33:21 +01:00
parent d904daf431
commit 4d19e2f64c
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
16 changed files with 807 additions and 0 deletions

View File

@ -17,6 +17,15 @@
- X10D: Added `char.IsEmoji`
- X10D: Added `Rune.IsEmoji`
- X10D: Added `string.IsEmoji`
- X10D: Added `Vector2.WithX()`
- X10D: Added `Vector2.WithY()`
- X10D: Added `Vector3.WithX()`
- X10D: Added `Vector3.WithY()`
- X10D: Added `Vector3.WithZ()`
- X10D: Added `Vector4.WithX()`
- X10D: Added `Vector4.WithY()`
- X10D: Added `Vector4.WithZ()`
- X10D: Added `Vector4.WithW()`
- X10D.Unity: Added `Color.Inverted()`
- X10D.Unity: Added `Color.WithA()`
- X10D.Unity: Added `Color.WithB()`
@ -45,6 +54,15 @@
- X10D.Unity: Added `Random.NextUnitVector3()`
- X10D.Unity: Added `Transform.LookAt(GameObject[, Vector3])`
- X10D.Unity: Added `Transform.SetParent(GameObject[, bool])`
- X10D.Unity: Added `Vector2.WithX()`
- X10D.Unity: Added `Vector2.WithY()`
- X10D.Unity: Added `Vector3.WithX()`
- X10D.Unity: Added `Vector3.WithY()`
- X10D.Unity: Added `Vector3.WithZ()`
- X10D.Unity: Added `Vector4.WithX()`
- X10D.Unity: Added `Vector4.WithY()`
- X10D.Unity: Added `Vector4.WithZ()`
- X10D.Unity: Added `Vector4.WithW()`
## [3.0.0]

View File

@ -0,0 +1,37 @@
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Numerics;
namespace X10D.Tests.Numerics;
[TestClass]
public class Vector2Tests
{
[TestMethod]
public void WithX_ShouldReturnVectorWithNewX_GivenVector()
{
Assert.AreEqual(Vector2.UnitY, Vector2.One.WithX(0));
Assert.AreEqual(Vector2.Zero, Vector2.Zero.WithX(0));
Assert.AreEqual(Vector2.Zero, Vector2.UnitX.WithX(0));
Assert.AreEqual(Vector2.UnitY, Vector2.UnitY.WithX(0));
Assert.AreEqual(Vector2.One, Vector2.One.WithX(1));
Assert.AreEqual(Vector2.UnitX, Vector2.Zero.WithX(1));
Assert.AreEqual(Vector2.UnitX, Vector2.UnitX.WithX(1));
Assert.AreEqual(Vector2.One, Vector2.UnitY.WithX(1));
}
[TestMethod]
public void WithY_ShouldReturnVectorWithNewY_GivenVector()
{
Assert.AreEqual(Vector2.UnitX, Vector2.One.WithY(0));
Assert.AreEqual(Vector2.Zero, Vector2.Zero.WithY(0));
Assert.AreEqual(Vector2.UnitX, Vector2.UnitX.WithY(0));
Assert.AreEqual(Vector2.Zero, Vector2.UnitY.WithY(0));
Assert.AreEqual(Vector2.One, Vector2.One.WithY(1));
Assert.AreEqual(Vector2.UnitY, Vector2.Zero.WithY(1));
Assert.AreEqual(Vector2.One, Vector2.UnitX.WithY(1));
Assert.AreEqual(Vector2.UnitY, Vector2.UnitY.WithY(1));
}
}

View File

@ -0,0 +1,57 @@
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Numerics;
namespace X10D.Tests.Numerics;
[TestClass]
public class Vector3Tests
{
[TestMethod]
public void WithX_ShouldReturnVectorWithNewX_GivenVector()
{
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.One.WithX(0));
Assert.AreEqual(Vector3.Zero, Vector3.Zero.WithX(0));
Assert.AreEqual(Vector3.Zero, Vector3.UnitX.WithX(0));
Assert.AreEqual(Vector3.UnitY, Vector3.UnitY.WithX(0));
Assert.AreEqual(Vector3.UnitZ, Vector3.UnitZ.WithX(0));
Assert.AreEqual(Vector3.One, Vector3.One.WithX(1));
Assert.AreEqual(Vector3.UnitX, Vector3.Zero.WithX(1));
Assert.AreEqual(Vector3.UnitX, Vector3.UnitX.WithX(1));
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.UnitY.WithX(1));
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.UnitZ.WithX(1));
}
[TestMethod]
public void WithY_ShouldReturnVectorWithNewY_GivenVector()
{
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.One.WithY(0));
Assert.AreEqual(Vector3.Zero, Vector3.Zero.WithY(0));
Assert.AreEqual(Vector3.UnitX, Vector3.UnitX.WithY(0));
Assert.AreEqual(Vector3.Zero, Vector3.UnitY.WithY(0));
Assert.AreEqual(Vector3.UnitZ, Vector3.UnitZ.WithY(0));
Assert.AreEqual(Vector3.One, Vector3.One.WithY(1));
Assert.AreEqual(Vector3.UnitY, Vector3.Zero.WithY(1));
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.UnitX.WithY(1));
Assert.AreEqual(Vector3.UnitY, Vector3.UnitY.WithY(1));
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.UnitZ.WithY(1));
}
[TestMethod]
public void WithZ_ShouldReturnVectorWithNewZ_GivenVector()
{
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.One.WithZ(0));
Assert.AreEqual(Vector3.Zero, Vector3.Zero.WithZ(0));
Assert.AreEqual(Vector3.UnitX, Vector3.UnitX.WithZ(0));
Assert.AreEqual(Vector3.UnitY, Vector3.UnitY.WithZ(0));
Assert.AreEqual(Vector3.Zero, Vector3.UnitZ.WithZ(0));
Assert.AreEqual(Vector3.One, Vector3.One.WithZ(1));
Assert.AreEqual(Vector3.UnitZ, Vector3.Zero.WithZ(1));
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.UnitX.WithZ(1));
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.UnitY.WithZ(1));
Assert.AreEqual(Vector3.UnitZ, Vector3.UnitZ.WithZ(1));
}
}

View File

@ -0,0 +1,81 @@
using System.Numerics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Numerics;
namespace X10D.Tests.Numerics;
[TestClass]
public class Vector4Tests
{
[TestMethod]
public void WithW_ShouldReturnVectorWithNewW_GivenVector()
{
Assert.AreEqual(new Vector4(1, 1, 1, 0), Vector4.One.WithW(0));
Assert.AreEqual(Vector4.Zero, Vector4.Zero.WithW(0));
Assert.AreEqual(Vector4.Zero, Vector4.UnitW.WithW(0));
Assert.AreEqual(Vector4.UnitX, Vector4.UnitX.WithW(0));
Assert.AreEqual(Vector4.UnitY, Vector4.UnitY.WithW(0));
Assert.AreEqual(Vector4.UnitZ, Vector4.UnitZ.WithW(0));
Assert.AreEqual(Vector4.One, Vector4.One.WithW(1));
Assert.AreEqual(Vector4.UnitW, Vector4.Zero.WithW(1));
Assert.AreEqual(Vector4.UnitW, Vector4.UnitW.WithW(1));
Assert.AreEqual(new Vector4(1, 0, 0, 1), Vector4.UnitX.WithW(1));
Assert.AreEqual(new Vector4(0, 1, 0, 1), Vector4.UnitY.WithW(1));
Assert.AreEqual(new Vector4(0, 0, 1, 1), Vector4.UnitZ.WithW(1));
}
[TestMethod]
public void WithX_ShouldReturnVectorWithNewX_GivenVector()
{
Assert.AreEqual(new Vector4(0, 1, 1, 1), Vector4.One.WithX(0));
Assert.AreEqual(Vector4.Zero, Vector4.Zero.WithX(0));
Assert.AreEqual(Vector4.UnitW, Vector4.UnitW.WithX(0));
Assert.AreEqual(Vector4.Zero, Vector4.UnitX.WithX(0));
Assert.AreEqual(Vector4.UnitY, Vector4.UnitY.WithX(0));
Assert.AreEqual(Vector4.UnitZ, Vector4.UnitZ.WithX(0));
Assert.AreEqual(Vector4.One, Vector4.One.WithX(1));
Assert.AreEqual(Vector4.UnitX, Vector4.Zero.WithX(1));
Assert.AreEqual(new Vector4(1, 0, 0, 1), Vector4.UnitW.WithX(1));
Assert.AreEqual(Vector4.UnitX, Vector4.UnitX.WithX(1));
Assert.AreEqual(new Vector4(1, 1, 0, 0), Vector4.UnitY.WithX(1));
Assert.AreEqual(new Vector4(1, 0, 1, 0), Vector4.UnitZ.WithX(1));
}
[TestMethod]
public void WithY_ShouldReturnVectorWithNewY_GivenVector()
{
Assert.AreEqual(new Vector4(1, 0, 1, 1), Vector4.One.WithY(0));
Assert.AreEqual(Vector4.Zero, Vector4.Zero.WithY(0));
Assert.AreEqual(Vector4.UnitW, Vector4.UnitW.WithY(0));
Assert.AreEqual(Vector4.UnitX, Vector4.UnitX.WithY(0));
Assert.AreEqual(Vector4.Zero, Vector4.UnitY.WithY(0));
Assert.AreEqual(Vector4.UnitZ, Vector4.UnitZ.WithY(0));
Assert.AreEqual(Vector4.One, Vector4.One.WithY(1));
Assert.AreEqual(Vector4.UnitY, Vector4.Zero.WithY(1));
Assert.AreEqual(new Vector4(0, 1, 0, 1), Vector4.UnitW.WithY(1));
Assert.AreEqual(new Vector4(1, 1, 0, 0), Vector4.UnitX.WithY(1));
Assert.AreEqual(Vector4.UnitY, Vector4.UnitY.WithY(1));
Assert.AreEqual(new Vector4(0, 1, 1, 0), Vector4.UnitZ.WithY(1));
}
[TestMethod]
public void WithZ_ShouldReturnVectorWithNewZ_GivenVector()
{
Assert.AreEqual(new Vector4(1, 1, 0, 1), Vector4.One.WithZ(0));
Assert.AreEqual(Vector4.Zero, Vector4.Zero.WithZ(0));
Assert.AreEqual(Vector4.UnitW, Vector4.UnitW.WithZ(0));
Assert.AreEqual(Vector4.UnitX, Vector4.UnitX.WithZ(0));
Assert.AreEqual(Vector4.UnitY, Vector4.UnitY.WithZ(0));
Assert.AreEqual(Vector4.Zero, Vector4.UnitZ.WithZ(0));
Assert.AreEqual(Vector4.One, Vector4.One.WithZ(1));
Assert.AreEqual(Vector4.UnitZ, Vector4.Zero.WithZ(1));
Assert.AreEqual(new Vector4(0, 0, 1, 1), Vector4.UnitW.WithZ(1));
Assert.AreEqual(new Vector4(1, 0, 1, 0), Vector4.UnitX.WithZ(1));
Assert.AreEqual(new Vector4(0, 1, 1, 0), Vector4.UnitY.WithZ(1));
Assert.AreEqual(Vector4.UnitZ, Vector4.UnitZ.WithZ(1));
}
}

View File

@ -0,0 +1,43 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using X10D.Unity.Numerics;
namespace X10D.Unity.Tests.Numerics
{
public class Vector2Tests
{
[UnityTest]
public IEnumerator WithX_ShouldReturnVectorWithNewX_GivenVector()
{
Assert.AreEqual(Vector2.up, Vector2.one.WithX(0));
Assert.AreEqual(Vector2.zero, Vector2.zero.WithX(0));
Assert.AreEqual(Vector2.zero, Vector2.right.WithX(0));
Assert.AreEqual(Vector2.up, Vector2.up.WithX(0));
Assert.AreEqual(Vector2.one, Vector2.one.WithX(1));
Assert.AreEqual(Vector2.right, Vector2.zero.WithX(1));
Assert.AreEqual(Vector2.right, Vector2.right.WithX(1));
Assert.AreEqual(Vector2.one, Vector2.up.WithX(1));
yield break;
}
[UnityTest]
public IEnumerator WithY_ShouldReturnVectorWithNewY_GivenVector()
{
Assert.AreEqual(Vector2.right, Vector2.one.WithY(0));
Assert.AreEqual(Vector2.zero, Vector2.zero.WithY(0));
Assert.AreEqual(Vector2.right, Vector2.right.WithY(0));
Assert.AreEqual(Vector2.zero, Vector2.up.WithY(0));
Assert.AreEqual(Vector2.one, Vector2.one.WithY(1));
Assert.AreEqual(Vector2.up, Vector2.zero.WithY(1));
Assert.AreEqual(Vector2.one, Vector2.right.WithY(1));
Assert.AreEqual(Vector2.up, Vector2.up.WithY(1));
yield break;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 83385270996049569380ae9769ff1381
timeCreated: 1652088132

View File

@ -0,0 +1,65 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using X10D.Unity.Numerics;
namespace X10D.Unity.Tests.Numerics
{
public class Vector3Tests
{
[UnityTest]
public IEnumerator WithX_ShouldReturnVectorWithNewX_GivenVector()
{
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.one.WithX(0));
Assert.AreEqual(Vector3.zero, Vector3.zero.WithX(0));
Assert.AreEqual(Vector3.zero, Vector3.right.WithX(0));
Assert.AreEqual(Vector3.up, Vector3.up.WithX(0));
Assert.AreEqual(Vector3.forward, Vector3.forward.WithX(0));
Assert.AreEqual(Vector3.one, Vector3.one.WithX(1));
Assert.AreEqual(Vector3.right, Vector3.zero.WithX(1));
Assert.AreEqual(Vector3.right, Vector3.right.WithX(1));
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.up.WithX(1));
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.forward.WithX(1));
yield break;
}
[UnityTest]
public IEnumerator WithY_ShouldReturnVectorWithNewY_GivenVector()
{
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.one.WithY(0));
Assert.AreEqual(Vector3.zero, Vector3.zero.WithY(0));
Assert.AreEqual(Vector3.right, Vector3.right.WithY(0));
Assert.AreEqual(Vector3.zero, Vector3.up.WithY(0));
Assert.AreEqual(Vector3.forward, Vector3.forward.WithY(0));
Assert.AreEqual(Vector3.one, Vector3.one.WithY(1));
Assert.AreEqual(Vector3.up, Vector3.zero.WithY(1));
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.right.WithY(1));
Assert.AreEqual(Vector3.up, Vector3.up.WithY(1));
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.forward.WithY(1));
yield break;
}
[UnityTest]
public IEnumerator WithZ_ShouldReturnVectorWithNewZ_GivenVector()
{
Assert.AreEqual(new Vector3(1, 1, 0), Vector3.one.WithZ(0));
Assert.AreEqual(Vector3.zero, Vector3.zero.WithZ(0));
Assert.AreEqual(Vector3.right, Vector3.right.WithZ(0));
Assert.AreEqual(Vector3.up, Vector3.up.WithZ(0));
Assert.AreEqual(Vector3.zero, Vector3.forward.WithZ(0));
Assert.AreEqual(Vector3.one, Vector3.one.WithZ(1));
Assert.AreEqual(Vector3.forward, Vector3.zero.WithZ(1));
Assert.AreEqual(new Vector3(1, 0, 1), Vector3.right.WithZ(1));
Assert.AreEqual(new Vector3(0, 1, 1), Vector3.up.WithZ(1));
Assert.AreEqual(Vector3.forward, Vector3.forward.WithZ(1));
yield break;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a00d613201bd497d91c9e98bca8dd6b1
timeCreated: 1652088132

View File

@ -0,0 +1,91 @@
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using X10D.Unity.Numerics;
namespace X10D.Unity.Tests.Numerics
{
public class Vector4Tests
{
[UnityTest]
public IEnumerator WithW_ShouldReturnVectorWithNewW_GivenVector()
{
Assert.AreEqual(new Vector4(1, 1, 1, 0), Vector4.one.WithW(0));
Assert.AreEqual(Vector4.zero, Vector4.zero.WithW(0));
Assert.AreEqual(Vector4.zero, new Vector4(0, 0, 0, 1).WithW(0));
Assert.AreEqual(new Vector4(1, 0, 0, 0), new Vector4(1, 0, 0, 0).WithW(0));
Assert.AreEqual(new Vector4(0, 1, 0, 0), new Vector4(0, 1, 0, 0).WithW(0));
Assert.AreEqual(new Vector4(0, 0, 1, 0), new Vector4(0, 0, 1, 0).WithW(0));
Assert.AreEqual(Vector4.one, Vector4.one.WithW(1));
Assert.AreEqual(new Vector4(0, 0, 0, 1), Vector4.zero.WithW(1));
Assert.AreEqual(new Vector4(0, 0, 0, 1), new Vector4(0, 0, 0, 1).WithW(1));
Assert.AreEqual(new Vector4(1, 0, 0, 1), new Vector4(1, 0, 0, 0).WithW(1));
Assert.AreEqual(new Vector4(0, 1, 0, 1), new Vector4(0, 1, 0, 0).WithW(1));
Assert.AreEqual(new Vector4(0, 0, 1, 1), new Vector4(0, 0, 1, 0).WithW(1));
yield break;
}
[UnityTest]
public IEnumerator WithX_ShouldReturnVectorWithNewX_GivenVector()
{
Assert.AreEqual(new Vector4(0, 1, 1, 1), Vector4.one.WithX(0));
Assert.AreEqual(Vector4.zero, Vector4.zero.WithX(0));
Assert.AreEqual(new Vector4(0, 0, 0, 1), new Vector4(0, 0, 0, 1).WithX(0));
Assert.AreEqual(Vector4.zero, new Vector4(1, 0, 0, 0).WithX(0));
Assert.AreEqual(new Vector4(0, 1, 0, 0), new Vector4(0, 1, 0, 0).WithX(0));
Assert.AreEqual(new Vector4(0, 0, 1, 0), new Vector4(0, 0, 1, 0).WithX(0));
Assert.AreEqual(Vector4.one, Vector4.one.WithX(1));
Assert.AreEqual(new Vector4(1, 0, 0, 0), Vector4.zero.WithX(1));
Assert.AreEqual(new Vector4(1, 0, 0, 1), new Vector4(0, 0, 0, 1).WithX(1));
Assert.AreEqual(new Vector4(1, 0, 0, 0), new Vector4(1, 0, 0, 0).WithX(1));
Assert.AreEqual(new Vector4(1, 1, 0, 0), new Vector4(0, 1, 0, 0).WithX(1));
Assert.AreEqual(new Vector4(1, 0, 1, 0), new Vector4(0, 0, 1, 0).WithX(1));
yield break;
}
[UnityTest]
public IEnumerator WithY_ShouldReturnVectorWithNewY_GivenVector()
{
Assert.AreEqual(new Vector4(1, 0, 1, 1), Vector4.one.WithY(0));
Assert.AreEqual(Vector4.zero, Vector4.zero.WithY(0));
Assert.AreEqual(new Vector4(0, 0, 0, 1), new Vector4(0, 0, 0, 1).WithY(0));
Assert.AreEqual(new Vector4(1, 0, 0, 0), new Vector4(1, 0, 0, 0).WithY(0));
Assert.AreEqual(Vector4.zero, new Vector4(0, 1, 0, 0).WithY(0));
Assert.AreEqual(new Vector4(0, 0, 1, 0), new Vector4(0, 0, 1, 0).WithY(0));
Assert.AreEqual(Vector4.one, Vector4.one.WithY(1));
Assert.AreEqual(new Vector4(0, 1, 0, 0), Vector4.zero.WithY(1));
Assert.AreEqual(new Vector4(0, 1, 0, 1), new Vector4(0, 0, 0, 1).WithY(1));
Assert.AreEqual(new Vector4(1, 1, 0, 0), new Vector4(1, 0, 0, 0).WithY(1));
Assert.AreEqual(new Vector4(0, 1, 0, 0), new Vector4(0, 1, 0, 0).WithY(1));
Assert.AreEqual(new Vector4(0, 1, 1, 0), new Vector4(0, 0, 1, 0).WithY(1));
yield break;
}
[UnityTest]
public IEnumerator WithZ_ShouldReturnVectorWithNewZ_GivenVector()
{
Assert.AreEqual(new Vector4(1, 1, 0, 1), Vector4.one.WithZ(0));
Assert.AreEqual(Vector4.zero, Vector4.zero.WithZ(0));
Assert.AreEqual(new Vector4(0, 0, 0, 1), new Vector4(0, 0, 0, 1).WithZ(0));
Assert.AreEqual(new Vector4(1, 0, 0, 0), new Vector4(1, 0, 0, 0).WithZ(0));
Assert.AreEqual(new Vector4(0, 1, 0, 0), new Vector4(0, 1, 0, 0).WithZ(0));
Assert.AreEqual(Vector4.zero, new Vector4(0, 0, 1, 0).WithZ(0));
Assert.AreEqual(Vector4.one, Vector4.one.WithZ(1));
Assert.AreEqual(new Vector4(0, 0, 1, 0), Vector4.zero.WithZ(1));
Assert.AreEqual(new Vector4(0, 0, 1, 1), new Vector4(0, 0, 0, 1).WithZ(1));
Assert.AreEqual(new Vector4(1, 0, 1, 0), new Vector4(1, 0, 0, 0).WithZ(1));
Assert.AreEqual(new Vector4(0, 1, 1, 0), new Vector4(0, 1, 0, 0).WithZ(1));
Assert.AreEqual(new Vector4(0, 0, 1, 0), new Vector4(0, 0, 1, 0).WithZ(1));
yield break;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0d487c2046a64354b199f4de01d57391
timeCreated: 1652088132

View File

@ -0,0 +1,43 @@
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace X10D.Unity.Numerics;
/// <summary>
/// Numeric-extensions for <see cref="Vector2" />.
/// </summary>
public static class Vector2Extensions
{
/// <summary>
/// Returns a vector whose Y component is the same as the specified vector, and whose X component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="x">The new X component value.</param>
/// <returns>
/// A new instance of <see cref="Vector2" /> whose <see cref="Vector2.y" /> components is the same as that of
/// <paramref name="vector" />, and whose <see cref="Vector2.x" /> component is <paramref name="x" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 WithX(this Vector2 vector, float x)
{
return vector with {x = x};
}
/// <summary>
/// Returns a vector whose X component is the same as the specified vector, and whose Y component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="y">The new Y component value.</param>
/// <returns>
/// A new instance of <see cref="Vector2" /> whose <see cref="Vector2.x" /> components is the same as that of
/// <paramref name="vector" />, and whose <see cref="Vector2.y" /> component is <paramref name="y" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 WithY(this Vector2 vector, float y)
{
return vector with {y = y};
}
}

View File

@ -0,0 +1,59 @@
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace X10D.Unity.Numerics;
/// <summary>
/// Numeric-extensions for <see cref="Vector3" />.
/// </summary>
public static class Vector3Extensions
{
/// <summary>
/// Returns a vector whose Y and Z components are the same as the specified vector, and whose X component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="x">The new X component value.</param>
/// <returns>
/// A new instance of <see cref="Vector3" /> whose <see cref="Vector3.y" /> and <see cref="Vector3.z" /> components are
/// the same as that of <paramref name="vector" />, and whose <see cref="Vector3.x" /> component is <paramref name="x" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 WithX(this Vector3 vector, float x)
{
return vector with {x = x};
}
/// <summary>
/// Returns a vector whose X and Z components are the same as the specified vector, and whose Y component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="y">The new Y component value.</param>
/// <returns>
/// A new instance of <see cref="Vector3" /> whose <see cref="Vector3.x" /> and <see cref="Vector3.z" /> components are
/// the same as that of <paramref name="vector" />, and whose <see cref="Vector3.y" /> component is <paramref name="y" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 WithY(this Vector3 vector, float y)
{
return vector with {y = y};
}
/// <summary>
/// Returns a vector whose X and Y components are the same as the specified vector, and whose Z component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="z">The new Z component value.</param>
/// <returns>
/// A new instance of <see cref="Vector3" /> whose <see cref="Vector3.x" /> and <see cref="Vector3.y" /> components are
/// the same as that of <paramref name="vector" />, and whose <see cref="Vector3.z" /> component is <paramref name="z" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 WithZ(this Vector3 vector, float z)
{
return vector with {z = z};
}
}

View File

@ -0,0 +1,83 @@
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace X10D.Unity.Numerics;
/// <summary>
/// Numeric-extensions for <see cref="Vector4" />.
/// </summary>
public static class Vector4Extensions
{
/// <summary>
/// Returns a vector whose Y, Z, and W components are the same as the specified vector, and whose X component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="x">The new X component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.y" />, <see cref="Vector4.z" />, and
/// <see cref="Vector4.w" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.x" /> component is <paramref name="x" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 WithX(this Vector4 vector, float x)
{
return vector with {x = x};
}
/// <summary>
/// Returns a vector whose X, Z, and W components are the same as the specified vector, and whose Y component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="y">The new Y component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.x" />, <see cref="Vector4.z" />, and
/// <see cref="Vector4.w" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.y" /> component is <paramref name="y" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 WithY(this Vector4 vector, float y)
{
return vector with {y = y};
}
/// <summary>
/// Returns a vector whose X, Y, and W components are the same as the specified vector, and whose Z component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="z">The new Z component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.x" />, <see cref="Vector4.y" />, and
/// <see cref="Vector4.w" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.z" /> component is <paramref name="z" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 WithZ(this Vector4 vector, float z)
{
return vector with {z = z};
}
/// <summary>
/// Returns a vector whose X, Y, and Z components are the same as the specified vector, and whose W component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="w">The new W component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.x" />, <see cref="Vector4.y" />, and
/// <see cref="Vector4.z" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.w" /> component is <paramref name="w" />.
/// </returns>
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector4 WithW(this Vector4 vector, float w)
{
return vector with {w = w};
}
}

View File

@ -0,0 +1,51 @@
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace X10D.Numerics;
/// <summary>
/// Numeric-extensions for <see cref="Vector2" />.
/// </summary>
public static class Vector2Extensions
{
/// <summary>
/// Returns a vector whose Y component is the same as the specified vector, and whose X component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="x">The new X component value.</param>
/// <returns>
/// A new instance of <see cref="Vector2" /> whose <see cref="Vector2.Y" /> components is the same as that of
/// <paramref name="vector" />, and whose <see cref="Vector2.X" /> component is <paramref name="x" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector2 WithX(this Vector2 vector, float x)
{
return vector with {X = x};
}
/// <summary>
/// Returns a vector whose X component is the same as the specified vector, and whose Y component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="y">The new Y component value.</param>
/// <returns>
/// A new instance of <see cref="Vector2" /> whose <see cref="Vector2.X" /> components is the same as that of
/// <paramref name="vector" />, and whose <see cref="Vector2.Y" /> component is <paramref name="y" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector2 WithY(this Vector2 vector, float y)
{
return vector with {Y = y};
}
}

View File

@ -0,0 +1,71 @@
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace X10D.Numerics;
/// <summary>
/// Numeric-extensions for <see cref="Vector3" />.
/// </summary>
public static class Vector3Extensions
{
/// <summary>
/// Returns a vector whose Y and Z components are the same as the specified vector, and whose X component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="x">The new X component value.</param>
/// <returns>
/// A new instance of <see cref="Vector3" /> whose <see cref="Vector3.Y" /> and <see cref="Vector3.Z" /> components are
/// the same as that of <paramref name="vector" />, and whose <see cref="Vector3.Y" /> component is <paramref name="x" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector3 WithX(this Vector3 vector, float x)
{
return vector with {X = x};
}
/// <summary>
/// Returns a vector whose X and Z components are the same as the specified vector, and whose Y component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="y">The new Y component value.</param>
/// <returns>
/// A new instance of <see cref="Vector3" /> whose <see cref="Vector3.X" /> and <see cref="Vector3.Z" /> components are
/// the same as that of <paramref name="vector" />, and whose <see cref="Vector3.Y" /> component is <paramref name="y" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector3 WithY(this Vector3 vector, float y)
{
return vector with {Y = y};
}
/// <summary>
/// Returns a vector whose X and Y components are the same as the specified vector, and whose Z component is a new value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="z">The new Z component value.</param>
/// <returns>
/// A new instance of <see cref="Vector3" /> whose <see cref="Vector3.X" /> and <see cref="Vector3.Y" /> components are
/// the same as that of <paramref name="vector" />, and whose <see cref="Vector3.Z" /> component is <paramref name="z" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector3 WithZ(this Vector3 vector, float z)
{
return vector with {Z = z};
}
}

View File

@ -0,0 +1,99 @@
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace X10D.Numerics;
/// <summary>
/// Numeric-extensions for <see cref="Vector4" />.
/// </summary>
public static class Vector4Extensions
{
/// <summary>
/// Returns a vector whose Y, Z, and W components are the same as the specified vector, and whose X component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="x">The new X component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.Y" />, <see cref="Vector4.Z" />, and
/// <see cref="Vector4.W" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.X" /> component is <paramref name="x" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector4 WithX(this Vector4 vector, float x)
{
return vector with {X = x};
}
/// <summary>
/// Returns a vector whose X, Z, and W components are the same as the specified vector, and whose Y component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="y">The new Y component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.X" />, <see cref="Vector4.Z" />, and
/// <see cref="Vector4.W" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.Y" /> component is <paramref name="y" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector4 WithY(this Vector4 vector, float y)
{
return vector with {Y = y};
}
/// <summary>
/// Returns a vector whose X, Y, and W components are the same as the specified vector, and whose Z component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="z">The new Z component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.X" />, <see cref="Vector4.Y" />, and
/// <see cref="Vector4.W" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.Z" /> component is <paramref name="z" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector4 WithZ(this Vector4 vector, float z)
{
return vector with {Z = z};
}
/// <summary>
/// Returns a vector whose X, Y, and Z components are the same as the specified vector, and whose W component is a new
/// value.
/// </summary>
/// <param name="vector">The vector to copy.</param>
/// <param name="w">The new W component value.</param>
/// <returns>
/// A new instance of <see cref="Vector4" /> whose <see cref="Vector4.X" />, <see cref="Vector4.Y" />, and
/// <see cref="Vector4.Z" /> components are the same as that of <paramref name="vector" />, and whose
/// <see cref="Vector4.W" /> component is <paramref name="w" />.
/// </returns>
[Pure]
#if NETSTANDARD2_1
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#else
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
#endif
public static Vector4 WithW(this Vector4 vector, float w)
{
return vector with {W = w};
}
}