From 364b6fb21d1838d462cb00d899d0fe0ced27558d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 20 Nov 2020 12:02:03 +0100 Subject: [PATCH] Added FloatExtensions type --- .../System.Numerics/FloatExtensions.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/ComputeSharp/Extensions/System.Numerics/FloatExtensions.cs diff --git a/src/ComputeSharp/Extensions/System.Numerics/FloatExtensions.cs b/src/ComputeSharp/Extensions/System.Numerics/FloatExtensions.cs new file mode 100644 index 00000000..7707f4aa --- /dev/null +++ b/src/ComputeSharp/Extensions/System.Numerics/FloatExtensions.cs @@ -0,0 +1,84 @@ +using System.Diagnostics.Contracts; +using ComputeSharp; +using static System.Runtime.InteropServices.MemoryMarshal; + +namespace System.Numerics +{ + /// + /// A that contains extension methods for the , and types. + /// + public static class FloatExtensions + { + /// + /// Converts a array into a with items of type . + /// + /// The input array. + /// A with items of type , mapping the original array. + [Pure] + public static Span AsVector2Span(this Float2[] array) => Cast(array); + + /// + /// Converts a into a with items of type + /// + /// The input . + /// A with items of type , mapping the original . + [Pure] + public static ReadOnlySpan AsVector2Span(this ReadOnlySpan span) => Cast(span); + + /// + /// Converts a into a with items of type . + /// + /// The input . + /// A with items of type , mapping the original . + [Pure] + public static Span AsVector2Span(this Span span) => Cast(span); + + /// + /// Converts a array into a with items of type . + /// + /// The input array. + /// A with items of type , mapping the original array. + [Pure] + public static Span AsVector3Span(this Float3[] array) => Cast(array); + + /// + /// Converts a into a with items of type . + /// + /// The input . + /// A with items of type , mapping the original . + [Pure] + public static ReadOnlySpan AsVector3Span(this ReadOnlySpan span) => Cast(span); + + /// + /// Converts a into a with items of type . + /// + /// The input . + /// A with items of type , mapping the original . + [Pure] + public static Span AsVector3Span(this Span span) => Cast(span); + + /// + /// Converts a array into a with items of type . + /// + /// The input array. + /// A with items of type , mapping the original array. + [Pure] + public static Span AsVector4Span(this Float4[] array) => Cast(array); + + /// + /// Converts a into a with items of type . + /// + /// The input . + /// A with items of type , mapping the original . + [Pure] + public static ReadOnlySpan AsVector4Span(this ReadOnlySpan span) => Cast(span); + + /// + /// Converts a into a with items of type . + /// + /// The input . + /// A with items of type , mapping the original . + [Pure] + public static Span AsVector4Span(this Span span) => Cast(span); + } +}