37 lines
987 B
C#
37 lines
987 B
C#
using System.Numerics;
|
|
using Silk.NET.Maths;
|
|
|
|
namespace Nebulix
|
|
{
|
|
public static class ArrayExtensions
|
|
{
|
|
/// <summary>
|
|
/// Copies the given arrays to the start of this array. The order of <paramref name="arrays"/> is preserved
|
|
/// </summary>
|
|
/// <param name="arrays">The arrays copied into this array</param>
|
|
public static void CopyFrom(this Array array, params Array[] arrays)
|
|
{
|
|
int lastIndex = 0;
|
|
for (int i = 0; i < arrays.Length; i++)
|
|
{
|
|
arrays[i].CopyTo(array, lastIndex);
|
|
lastIndex += arrays[i].Length;
|
|
}
|
|
}
|
|
|
|
public static T[] ExtractComponents<T>(this Vector3D<T>[] array) where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
|
|
{
|
|
T[] result = new T[array.Length * 3]; // * 3 cause a Vector3D has 3 components
|
|
int resultIdx = 0;
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
result[resultIdx] = array[i].X;
|
|
result[resultIdx + 1] = array[i].Y;
|
|
result[resultIdx + 2] = array[i].Z;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|