Add math
This commit is contained in:
parent
a2dc2bed3c
commit
1065aeec0b
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>lib</RootNamespace>
|
||||
<AssemblyName>SharpLib</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
@ -29,7 +29,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
@ -61,6 +61,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="att\CanBeNullAttribute.cs" />
|
||||
<Compile Include="att\NotNullAttribute.cs" />
|
||||
<Compile Include="Conn.cs" />
|
||||
<Compile Include="Clock.cs" />
|
||||
<Compile Include="Config.cs" />
|
||||
@ -81,6 +83,7 @@
|
||||
<Compile Include="math\ColorExtensions.cs" />
|
||||
<Compile Include="math\ColorHSV.cs" />
|
||||
<Compile Include="math\ContainmentType.cs" />
|
||||
<Compile Include="math\DataMemberIgnoreAttribute.cs" />
|
||||
<Compile Include="math\DataStyleAttribute.cs" />
|
||||
<Compile Include="math\Double2.cs" />
|
||||
<Compile Include="math\Double3.cs" />
|
||||
@ -96,12 +99,10 @@
|
||||
<Compile Include="math\Int4.cs" />
|
||||
<Compile Include="math\MathUtil.cs" />
|
||||
<Compile Include="math\Matrix.cs" />
|
||||
<Compile Include="math\Module.cs" />
|
||||
<Compile Include="math\NamespaceDoc.cs" />
|
||||
<Compile Include="math\Plane.cs" />
|
||||
<Compile Include="math\PlaneIntersectionType.cs" />
|
||||
<Compile Include="math\Point.cs" />
|
||||
<Compile Include="math\Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="math\Quaternion.cs" />
|
||||
<Compile Include="math\RandomSeed.cs" />
|
||||
<Compile Include="math\Ray.cs" />
|
||||
@ -124,6 +125,8 @@
|
||||
<Compile Include="SerializableDictionary.cs" />
|
||||
<Compile Include="Timer.cs" />
|
||||
<Compile Include="Token.cs" />
|
||||
<Compile Include="Utilities.cs" />
|
||||
<Compile Include="Utilities.Interop.cs" />
|
||||
<Compile Include="VersionFormatter.cs" />
|
||||
<Compile Include="XmlFormatter.cs" />
|
||||
<Compile Include="XmlFormatter2.cs" />
|
||||
|
||||
8
Timer.cs
8
Timer.cs
@ -237,22 +237,24 @@ namespace lib
|
||||
|
||||
// Start the timer
|
||||
|
||||
public void Start()
|
||||
public Timer Start()
|
||||
{
|
||||
m_watch.Start();
|
||||
startTime = m_watch.ElapsedMicroseconds;
|
||||
stopTime = m_watch.ElapsedMicroseconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Stop the timer
|
||||
|
||||
public void Stop()
|
||||
public Timer Stop()
|
||||
{
|
||||
m_watch.Stop();
|
||||
stopTime = m_watch.ElapsedMicroseconds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public double Seconds
|
||||
public double Seconds
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
165
Utilities.Interop.cs
Normal file
165
Utilities.Interop.cs
Normal file
@ -0,0 +1,165 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
//
|
||||
// Copyright (c) 2010-2012 SharpDX - Alexandre Mutel
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
#pragma warning disable SA1300 // Element must begin with upper-case letter
|
||||
#pragma warning disable SA1649 // File name must match first type name
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace lib
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility class.
|
||||
/// </summary>
|
||||
internal sealed class Interop
|
||||
{
|
||||
public static T Pin<T>(ref T source) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static T IncrementPinned<T>(T source) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static T AddPinned<T>(T source, int offset) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static void Pin<T>(T data) where T : class
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Fixed<T>(ref T data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* FixedOut<T>(out T data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Fixed<T>(T[] data)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Cast<T>(ref T data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* CastOut<T>(out T data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static TCAST[] CastArray<TCAST, T>(T[] arrayData)
|
||||
where T : struct
|
||||
where TCAST : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void memcpy(void* pDest, void* pSrc, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void memset(void* pDest, byte value, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Read<T>(void* pSrc, ref T data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe T ReadInline<T>(void* pSrc) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void WriteInline<T>(void* pDest, ref T data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void CopyInline<T>(ref T data, void* pSrc) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void CopyInline<T>(void* pDest, ref T srcData)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void CopyInlineOut<T>(out T data, void* pSrc)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* ReadOut<T>(void* pSrc, out T data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Read<T>(void* pSrc, T[] data, int offset, int count) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Read2D<T>(void* pSrc, T[,] data, int offset, int count) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int SizeOf<T>()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Write<T>(void* pDest, ref T data) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Write<T>(void* pDest, T[] data, int offset, int count) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static unsafe void* Write2D<T>(void* pDest, T[,] data, int offset, int count) where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
823
Utilities.cs
Normal file
823
Utilities.cs
Normal file
@ -0,0 +1,823 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
//
|
||||
// Copyright (c) 2010-2012 SharpDX - Alexandre Mutel
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
#pragma warning disable SA1405 // Debug.Assert must provide message text
|
||||
using att;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace lib
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility class.
|
||||
/// </summary>
|
||||
public static class Util
|
||||
{
|
||||
|
||||
/*
|
||||
#if XENKO_PLATFORM_UWP
|
||||
public static unsafe void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
|
||||
{
|
||||
Interop.memcpy((void*)dest, (void*)src, sizeInBytesToCopy);
|
||||
}
|
||||
#else
|
||||
#if XENKO_PLATFORM_WINDOWS_DESKTOP
|
||||
private const string MemcpyDll = "msvcrt.dll";
|
||||
#elif XENKO_PLATFORM_ANDROID
|
||||
private const string MemcpyDll = "libc.so";
|
||||
#elif XENKO_PLATFORM_UNIX
|
||||
// We do not specifiy the .so extension as libc.so on Linux
|
||||
// is actually not a .so files but a script. Using just libc
|
||||
// will automatically find the corresponding .so.
|
||||
private const string MemcpyDll = "libc";
|
||||
#elif XENKO_PLATFORM_IOS
|
||||
private const string MemcpyDll = ObjCRuntime.Constants.SystemLibrary;
|
||||
#else
|
||||
# error Unsupported platform
|
||||
#endif
|
||||
[DllImport(MemcpyDll, EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
|
||||
#if !XENKO_RUNTIME_CORECLR
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
#endif
|
||||
private static extern IntPtr CopyMemory(IntPtr dest, IntPtr src, ulong sizeInBytesToCopy);
|
||||
|
||||
/// <summary>
|
||||
/// Copy memory.
|
||||
/// </summary>
|
||||
/// <param name="dest">The destination memory location</param>
|
||||
/// <param name="src">The source memory location.</param>
|
||||
/// <param name="sizeInBytesToCopy">The count.</param>
|
||||
public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
|
||||
{
|
||||
CopyMemory(dest, src, (ulong)sizeInBytesToCopy);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Compares two block of memory.
|
||||
/// </summary>
|
||||
/// <param name="from">The pointer to compare from.</param>
|
||||
/// <param name="against">The pointer to compare against.</param>
|
||||
/// <param name="sizeToCompare">The size in bytes to compare.</param>
|
||||
/// <returns>True if the buffers are equivalent, false otherwise.</returns>
|
||||
public static unsafe bool CompareMemory(IntPtr from, IntPtr against, int sizeToCompare)
|
||||
{
|
||||
var pSrc = (byte*)from;
|
||||
var pDst = (byte*)against;
|
||||
|
||||
// Compare 8 bytes.
|
||||
var numberOf = sizeToCompare >> 3;
|
||||
while (numberOf > 0)
|
||||
{
|
||||
if (*(long*)pSrc != *(long*)pDst)
|
||||
return false;
|
||||
pSrc += 8;
|
||||
pDst += 8;
|
||||
numberOf--;
|
||||
}
|
||||
|
||||
// Compare remaining bytes.
|
||||
numberOf = sizeToCompare & 7;
|
||||
while (numberOf > 0)
|
||||
{
|
||||
if (*pSrc != *pDst)
|
||||
return false;
|
||||
pSrc++;
|
||||
pDst++;
|
||||
numberOf--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the memory.
|
||||
/// </summary>
|
||||
/// <param name="dest">The dest.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="sizeInBytesToClear">The size in bytes to clear.</param>
|
||||
public static void ClearMemory(IntPtr dest, byte value, int sizeInBytesToClear)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Interop.memset((void*)dest, value, sizeInBytesToClear);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the sizeof a struct from a CLR. Equivalent to sizeof operator but works on generics too.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">a struct to evaluate</typeparam>
|
||||
/// <returns>sizeof this struct</returns>
|
||||
public static int SizeOf<T>() where T : struct
|
||||
{
|
||||
return Interop.SizeOf<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the sizeof an array of struct. Equivalent to sizeof operator but works on generics too.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">a struct</typeparam>
|
||||
/// <param name="array">The array of struct to evaluate.</param>
|
||||
/// <returns>sizeof in bytes of this array of struct</returns>
|
||||
public static int SizeOf<T>(T[] array) where T : struct
|
||||
{
|
||||
return array == null ? 0 : array.Length * Interop.SizeOf<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pins the specified source and call an action with the pinned pointer.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to pin</typeparam>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <param name="pinAction">The pin action to perform on the pinned pointer.</param>
|
||||
public static void Pin<T>(ref T source, Action<IntPtr> pinAction) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
pinAction((IntPtr)Interop.Fixed(ref source));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pins the specified source and call an action with the pinned pointer.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to pin</typeparam>
|
||||
/// <param name="source">The source array.</param>
|
||||
/// <param name="pinAction">The pin action to perform on the pinned pointer.</param>
|
||||
public static void Pin<T>(T[] source, [NotNull] Action<IntPtr> pinAction) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
pinAction(source == null ? IntPtr.Zero : (IntPtr)Interop.Fixed(source));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Covnerts a structured array to an equivalent byte array.
|
||||
/// </summary>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <returns>The byte array.</returns>
|
||||
public static byte[] ToByteArray<T>(T[] source) where T : struct
|
||||
{
|
||||
if (source == null) return null;
|
||||
|
||||
var buffer = new byte[SizeOf<T>() * source.Length];
|
||||
|
||||
if (source.Length == 0)
|
||||
return buffer;
|
||||
|
||||
unsafe
|
||||
{
|
||||
fixed (void* pBuffer = buffer)
|
||||
Interop.Write(pBuffer, source, 0, source.Length);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified T data from a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to read</typeparam>
|
||||
/// <param name="source">Memory location to read from.</param>
|
||||
/// <returns>The data read from the memory location</returns>
|
||||
public static T Read<T>(IntPtr source) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return Interop.ReadInline<T>((void*)source);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified T data from a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to read</typeparam>
|
||||
/// <param name="source">Memory location to read from.</param>
|
||||
/// <param name="data">The data write to.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Read<T>(IntPtr source, ref T data) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Interop.CopyInline(ref data, (void*)source);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified T data from a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to read</typeparam>
|
||||
/// <param name="source">Memory location to read from.</param>
|
||||
/// <param name="data">The data write to.</param>
|
||||
public static void ReadOut<T>(IntPtr source, out T data) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Interop.CopyInlineOut(out data, (void*)source);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified T data from a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to read</typeparam>
|
||||
/// <param name="source">Memory location to read from.</param>
|
||||
/// <param name="data">The data write to.</param>
|
||||
/// <returns>source pointer + sizeof(T)</returns>
|
||||
public static IntPtr ReadAndPosition<T>(IntPtr source, ref T data) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return (IntPtr)Interop.Read((void*)source, ref data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified array T[] data from a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to read</typeparam>
|
||||
/// <param name="source">Memory location to read from.</param>
|
||||
/// <param name="data">The data write to.</param>
|
||||
/// <param name="offset">The offset in the array to write to.</param>
|
||||
/// <param name="count">The number of T element to read from the memory location</param>
|
||||
/// <returns>source pointer + sizeof(T) * count</returns>
|
||||
public static IntPtr Read<T>(IntPtr source, T[] data, int offset, int count) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return (IntPtr)Interop.Read((void*)source, data, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified T data to a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to write</typeparam>
|
||||
/// <param name="destination">Memory location to write to.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Write<T>(IntPtr destination, ref T data) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Interop.CopyInline((void*)destination, ref data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified T data to a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to write</typeparam>
|
||||
/// <param name="destination">Memory location to write to.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
/// <returns>destination pointer + sizeof(T)</returns>
|
||||
public static IntPtr WriteAndPosition<T>(IntPtr destination, ref T data) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return (IntPtr)Interop.Write((void*)destination, ref data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified array T[] data to a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to write</typeparam>
|
||||
/// <param name="destination">Memory location to write to.</param>
|
||||
/// <param name="data">The array of T data to write.</param>
|
||||
/// <param name="offset">The offset in the array to read from.</param>
|
||||
/// <param name="count">The number of T element to write to the memory location</param>
|
||||
public static void Write<T>(byte[] destination, T[] data, int offset, int count) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (void* pDest = destination)
|
||||
{
|
||||
Write((IntPtr)pDest, data, offset, count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified array T[] data to a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to write</typeparam>
|
||||
/// <param name="destination">Memory location to write to.</param>
|
||||
/// <param name="data">The array of T data to write.</param>
|
||||
/// <param name="offset">The offset in the array to read from.</param>
|
||||
/// <param name="count">The number of T element to write to the memory location</param>
|
||||
/// <returns>destination pointer + sizeof(T) * count</returns>
|
||||
public static IntPtr Write<T>(IntPtr destination, T[] data, int offset, int count) where T : struct
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
return (IntPtr)Interop.Write((void*)destination, data, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate an aligned memory buffer.
|
||||
/// </summary>
|
||||
/// <param name="sizeInBytes">Size of the buffer to allocate.</param>
|
||||
/// <param name="align">Alignment, a positive value which is a power of 2. 16 bytes by default.</param>
|
||||
/// <returns>A pointer to a buffer aligned.</returns>
|
||||
/// <remarks>
|
||||
/// To free this buffer, call <see cref="FreeMemory"/>
|
||||
/// </remarks>
|
||||
public static unsafe IntPtr AllocateMemory(int sizeInBytes, int align = 16)
|
||||
{
|
||||
var mask = align - 1;
|
||||
if ((align & mask) != 0)
|
||||
{
|
||||
throw new ArgumentException("Alignment is not power of 2", nameof(align));
|
||||
}
|
||||
var memPtr = Marshal.AllocHGlobal(sizeInBytes + mask + sizeof(void*));
|
||||
var ptr = (byte*)((ulong)(memPtr.ToInt32() + sizeof(void*) + mask) & ~(ulong)mask);
|
||||
((IntPtr*)ptr)[-1] = memPtr;
|
||||
return new IntPtr(ptr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate an aligned memory buffer and clear it with a specified value (0 by defaault).
|
||||
/// </summary>
|
||||
/// <param name="sizeInBytes">Size of the buffer to allocate.</param>
|
||||
/// <param name="clearValue">Default value used to clear the buffer.</param>
|
||||
/// <param name="align">Alignment, 16 bytes by default.</param>
|
||||
/// <returns>A pointer to a buffer aligned.</returns>
|
||||
/// <remarks>
|
||||
/// To free this buffer, call <see cref="FreeMemory"/>
|
||||
/// </remarks>
|
||||
public static IntPtr AllocateClearedMemory(int sizeInBytes, byte clearValue = 0, int align = 16)
|
||||
{
|
||||
var ptr = AllocateMemory(sizeInBytes, align);
|
||||
ClearMemory(ptr, clearValue, sizeInBytes);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified memory pointer is aligned in memory.
|
||||
/// </summary>
|
||||
/// <param name="memoryPtr">The memory pointer.</param>
|
||||
/// <param name="align">The align.</param>
|
||||
/// <returns><c>true</c> if the specified memory pointer is aligned in memory; otherwise, <c>false</c>.</returns>
|
||||
public static bool IsMemoryAligned(IntPtr memoryPtr, int align = 16)
|
||||
{
|
||||
return (memoryPtr.ToInt64() & (align - 1)) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allocate an aligned memory buffer.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The buffer must have been allocated with <see cref="AllocateMemory"/>
|
||||
/// </remarks>
|
||||
public static unsafe void FreeMemory(IntPtr alignedBuffer)
|
||||
{
|
||||
Marshal.FreeHGlobal(((IntPtr*)alignedBuffer)[-1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If non-null, disposes the specified object and set it to null, otherwise do nothing.
|
||||
/// </summary>
|
||||
/// <param name="disposable">The disposable.</param>
|
||||
public static void Dispose<T>(ref T disposable) where T : class, IDisposable
|
||||
{
|
||||
if (disposable != null)
|
||||
{
|
||||
disposable.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// String helper join method to display an array of object as a single string.
|
||||
/// </summary>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <param name="array">The array.</param>
|
||||
/// <returns>a string with array elements serparated by the seperator</returns>
|
||||
[NotNull]
|
||||
public static string Join<T>(string separator, T[] array)
|
||||
{
|
||||
var text = new StringBuilder();
|
||||
if (array != null)
|
||||
{
|
||||
for (var i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (i > 0) text.Append(separator);
|
||||
text.Append(array[i]);
|
||||
}
|
||||
}
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// String helper join method to display an enumrable of object as a single string.
|
||||
/// </summary>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <param name="elements">The enumerable.</param>
|
||||
/// <returns>a string with array elements serparated by the seperator</returns>
|
||||
[NotNull]
|
||||
public static string Join(string separator, [NotNull] IEnumerable elements)
|
||||
{
|
||||
var elementList = new List<string>();
|
||||
foreach (var element in elements)
|
||||
elementList.Add(element.ToString());
|
||||
|
||||
var text = new StringBuilder();
|
||||
for (var i = 0; i < elementList.Count; i++)
|
||||
{
|
||||
var element = elementList[i];
|
||||
if (i > 0) text.Append(separator);
|
||||
text.Append(element);
|
||||
}
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// String helper join method to display an enumrable of object as a single string.
|
||||
/// </summary>
|
||||
/// <param name="separator">The separator.</param>
|
||||
/// <param name="elements">The enumerable.</param>
|
||||
/// <returns>a string with array elements serparated by the seperator</returns>
|
||||
[NotNull]
|
||||
public static string Join(string separator, [NotNull] IEnumerator elements)
|
||||
{
|
||||
var elementList = new List<string>();
|
||||
while (elements.MoveNext())
|
||||
elementList.Add(elements.Current.ToString());
|
||||
|
||||
var text = new StringBuilder();
|
||||
for (var i = 0; i < elementList.Count; i++)
|
||||
{
|
||||
var element = elementList[i];
|
||||
if (i > 0) text.Append(separator);
|
||||
text.Append(element);
|
||||
}
|
||||
return text.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read stream to a byte[] buffer
|
||||
/// </summary>
|
||||
/// <param name = "stream">input stream</param>
|
||||
/// <returns>a byte[] buffer</returns>
|
||||
[NotNull]
|
||||
public static byte[] ReadStream([NotNull] Stream stream)
|
||||
{
|
||||
var readLength = 0;
|
||||
return ReadStream(stream, ref readLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read stream to a byte[] buffer
|
||||
/// </summary>
|
||||
/// <param name = "stream">input stream</param>
|
||||
/// <param name = "readLength">length to read</param>
|
||||
/// <returns>a byte[] buffer</returns>
|
||||
[NotNull]
|
||||
public static byte[] ReadStream([NotNull] Stream stream, ref int readLength)
|
||||
{
|
||||
System.Diagnostics.Debug.Assert(stream != null);
|
||||
System.Diagnostics.Debug.Assert(stream.CanRead);
|
||||
var num = readLength;
|
||||
System.Diagnostics.Debug.Assert(num <= (stream.Length - stream.Position));
|
||||
if (num == 0)
|
||||
readLength = (int)(stream.Length - stream.Position);
|
||||
num = readLength;
|
||||
|
||||
System.Diagnostics.Debug.Assert(num >= 0);
|
||||
if (num == 0)
|
||||
return new byte[0];
|
||||
|
||||
var buffer = new byte[num];
|
||||
var bytesRead = 0;
|
||||
if (num > 0)
|
||||
{
|
||||
do
|
||||
{
|
||||
bytesRead += stream.Read(buffer, bytesRead, readLength - bytesRead);
|
||||
} while (bytesRead < readLength);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes a hashcode for a dictionary.
|
||||
/// </summary>
|
||||
/// <returns>Hashcode for the list.</returns>
|
||||
public static int GetHashCode(IDictionary dict)
|
||||
{
|
||||
if (dict == null)
|
||||
return 0;
|
||||
|
||||
var hashCode = 0;
|
||||
foreach (DictionaryEntry keyValue in dict)
|
||||
{
|
||||
hashCode = (hashCode * 397) ^ keyValue.Key.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ (keyValue.Value?.GetHashCode() ?? 0);
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes a hashcode for an enumeration
|
||||
/// </summary>
|
||||
/// <param name="it">An enumerator.</param>
|
||||
/// <returns>Hashcode for the list.</returns>
|
||||
public static int GetHashCode(IEnumerable it)
|
||||
{
|
||||
if (it == null)
|
||||
return 0;
|
||||
|
||||
var hashCode = 0;
|
||||
foreach (var current in it)
|
||||
{
|
||||
hashCode = (hashCode * 397) ^ (current?.GetHashCode() ?? 0);
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes a hashcode for an enumeration
|
||||
/// </summary>
|
||||
/// <param name="it">An enumerator.</param>
|
||||
/// <returns>Hashcode for the list.</returns>
|
||||
public static int GetHashCode(IEnumerator it)
|
||||
{
|
||||
if (it == null)
|
||||
return 0;
|
||||
|
||||
var hashCode = 0;
|
||||
while (it.MoveNext())
|
||||
{
|
||||
var current = it.Current;
|
||||
hashCode = (hashCode * 397) ^ (current?.GetHashCode() ?? 0);
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two collection, element by elements.
|
||||
/// </summary>
|
||||
/// <param name="left">A "from" enumerator.</param>
|
||||
/// <param name="right">A "to" enumerator.</param>
|
||||
/// <returns>True if lists are identical. False otherwise.</returns>
|
||||
public static bool Compare(IEnumerable left, IEnumerable right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
return true;
|
||||
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
return false;
|
||||
|
||||
return Compare(left.GetEnumerator(), right.GetEnumerator());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two collection, element by elements.
|
||||
/// </summary>
|
||||
/// <param name="leftIt">A "from" enumerator.</param>
|
||||
/// <param name="rightIt">A "to" enumerator.</param>
|
||||
/// <returns>True if lists are identical. False otherwise.</returns>
|
||||
public static bool Compare(IEnumerator leftIt, IEnumerator rightIt)
|
||||
{
|
||||
if (ReferenceEquals(leftIt, rightIt))
|
||||
return true;
|
||||
if (ReferenceEquals(leftIt, null) || ReferenceEquals(rightIt, null))
|
||||
return false;
|
||||
|
||||
bool hasLeftNext;
|
||||
bool hasRightNext;
|
||||
while (true)
|
||||
{
|
||||
hasLeftNext = leftIt.MoveNext();
|
||||
hasRightNext = rightIt.MoveNext();
|
||||
if (!hasLeftNext || !hasRightNext)
|
||||
break;
|
||||
|
||||
if (!Equals(leftIt.Current, rightIt.Current))
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there is any left element
|
||||
if (hasLeftNext != hasRightNext)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two collection, element by elements.
|
||||
/// </summary>
|
||||
/// <param name="first">The collection to compare from.</param>
|
||||
/// <param name="second">The colllection to compare to.</param>
|
||||
/// <returns>True if lists are identical (but no necessarely of the same time). False otherwise.</returns>
|
||||
public static bool Compare<TKey, TValue>(IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second)
|
||||
{
|
||||
if (ReferenceEquals(first, second)) return true;
|
||||
if (ReferenceEquals(first, null) || ReferenceEquals(second, null)) return false;
|
||||
if (first.Count != second.Count) return false;
|
||||
|
||||
var comparer = EqualityComparer<TValue>.Default;
|
||||
|
||||
foreach (var keyValue in first)
|
||||
{
|
||||
TValue secondValue;
|
||||
if (!second.TryGetValue(keyValue.Key, out secondValue)) return false;
|
||||
if (!comparer.Equals(keyValue.Value, secondValue)) return false;
|
||||
}
|
||||
|
||||
// Check that all keys in second are in first
|
||||
return second.Keys.All(first.ContainsKey);
|
||||
}
|
||||
|
||||
public static bool Compare<T>(T[] left, T[] right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
return true;
|
||||
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
return false;
|
||||
|
||||
if (left.Length != right.Length)
|
||||
return false;
|
||||
|
||||
var comparer = EqualityComparer<T>.Default;
|
||||
for (var i = 0; i < left.Length; ++i)
|
||||
{
|
||||
if (!comparer.Equals(left[i], right[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares two collection, element by elements.
|
||||
/// </summary>
|
||||
/// <param name="left">The collection to compare from.</param>
|
||||
/// <param name="right">The colllection to compare to.</param>
|
||||
/// <returns>True if lists are identical (but no necessarely of the same time). False otherwise.</returns>
|
||||
public static bool Compare<T>(ICollection<T> left, ICollection<T> right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
return true;
|
||||
if (ReferenceEquals(left, null) || ReferenceEquals(right, null))
|
||||
return false;
|
||||
|
||||
if (left.Count != right.Count)
|
||||
return false;
|
||||
|
||||
var count = 0;
|
||||
var leftIt = left.GetEnumerator();
|
||||
var rightIt = right.GetEnumerator();
|
||||
var comparer = EqualityComparer<T>.Default;
|
||||
while (leftIt.MoveNext() && rightIt.MoveNext())
|
||||
{
|
||||
if (!comparer.Equals(leftIt.Current, rightIt.Current))
|
||||
return false;
|
||||
count++;
|
||||
}
|
||||
|
||||
// Just double check to make sure that the iterator actually returns
|
||||
// the exact number of elements
|
||||
if (count != left.Count)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Swaps the value between two references.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to swap.</typeparam>
|
||||
/// <param name="left">The left value.</param>
|
||||
/// <param name="right">The right value.</param>
|
||||
public static void Swap<T>(ref T left, ref T right)
|
||||
{
|
||||
var temp = left;
|
||||
left = right;
|
||||
right = temp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspends current thread for a <see cref="sleepTime"/>.
|
||||
/// </summary>
|
||||
/// <param name="sleepTime">The duration of sleep.</param>
|
||||
public static void Sleep(TimeSpan sleepTime)
|
||||
{
|
||||
var ms = (long)sleepTime.TotalMilliseconds;
|
||||
if (ms < 0 || ms > int.MaxValue)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(sleepTime), "Sleep time must be a duration less than '2^31 - 1' milliseconds.");
|
||||
}
|
||||
// MH PORTED NativeInvoke.Sleep((int)ms);
|
||||
Thread.Sleep( (int)ms );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspends current thread for a <see cref="sleepTimeInMillis"/>.
|
||||
/// </summary>
|
||||
/// <param name="sleepTimeInMillis">The duration of sleep in milliseconds.</param>
|
||||
public static void Sleep(int sleepTimeInMillis)
|
||||
{
|
||||
// MH PORTED NativeInvoke.Sleep(sleepTimeInMillis);
|
||||
Thread.Sleep( sleepTimeInMillis );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified T data to a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to write</typeparam>
|
||||
/// <param name="destination">Memory location to write to.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
internal static void UnsafeWrite<T>(IntPtr destination, ref T data)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Interop.CopyInline((void*)destination, ref data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified T data from a memory location.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of a data to read</typeparam>
|
||||
/// <param name="source">Memory location to read from.</param>
|
||||
/// <param name="data">The data write to.</param>
|
||||
internal static void UnsafeReadOut<T>(IntPtr source, out T data)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Interop.CopyInlineOut(out data, (void*)source);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return the sizeof a struct from a CLR. Equivalent to sizeof operator but works on generics too.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">a struct to evaluate</typeparam>
|
||||
/// <returns>sizeof this struct</returns>
|
||||
internal static int UnsafeSizeOf<T>()
|
||||
{
|
||||
return Interop.SizeOf<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Linq assisted full tree iteration and collection in a single line.
|
||||
/// Warning, could be slow.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to iterate.</typeparam>
|
||||
/// <param name="root">The root item</param>
|
||||
/// <param name="childrenF">The function to retrieve a child</param>
|
||||
public static IEnumerable<T> IterateTree<T>(T root, Func<T, IEnumerable<T>> childrenF)
|
||||
{
|
||||
var q = new List<T> { root };
|
||||
while (q.Any())
|
||||
{
|
||||
var c = q[0];
|
||||
q.RemoveAt(0);
|
||||
q.AddRange(childrenF(c) ?? Enumerable.Empty<T>());
|
||||
yield return c;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="Stopwatch" /> raw time to a <see cref="TimeSpan" />.
|
||||
/// </summary>
|
||||
/// <param name="delta">The delta.</param>
|
||||
/// <returns>The <see cref="TimeSpan" />.</returns>
|
||||
public static TimeSpan ConvertRawToTimestamp(long delta)
|
||||
{
|
||||
return new TimeSpan(delta == 0 ? 0 : (delta * TimeSpan.TicksPerSecond) / Stopwatch.Frequency);
|
||||
}
|
||||
}
|
||||
}
|
||||
51
att/CanBeNullAttribute.cs
Normal file
51
att/CanBeNullAttribute.cs
Normal file
@ -0,0 +1,51 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
|
||||
/* MIT License
|
||||
|
||||
Copyright (c) 2016 JetBrains http://www.jetbrains.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE. */
|
||||
|
||||
using System;
|
||||
|
||||
namespace att
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the value of the marked element could be <c>null</c> sometimes, so the check for <c>null</c>
|
||||
/// is necessary before its usage.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// [CanBeNull] object Test() => null;
|
||||
///
|
||||
/// void UseTest() {
|
||||
/// var p = Test();
|
||||
/// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
|
||||
AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event |
|
||||
AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)]
|
||||
public sealed class CanBeNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
25
att/NotNullAttribute.cs
Normal file
25
att/NotNullAttribute.cs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace att
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the value of the marked element could never be <c>null</c>.
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// <code>
|
||||
/// [NotNull] object Foo() {
|
||||
/// return null; // Warning: Possible 'null' assignment
|
||||
/// }
|
||||
/// </code>
|
||||
/// </example>
|
||||
[AttributeUsage(
|
||||
AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property |
|
||||
AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event |
|
||||
AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter)]
|
||||
public sealed class NotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -195,7 +195,7 @@ namespace math
|
||||
if (points == null) throw new ArgumentNullException("points");
|
||||
fixed (void* pointsPtr = points)
|
||||
{
|
||||
FromPoints((IntPtr)pointsPtr, 0, points.Length, Utilities.SizeOf<Vector3>(), out result);
|
||||
FromPoints((IntPtr)pointsPtr, 0, points.Length, lib.Util.SizeOf<Vector3>(), out result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
using att;
|
||||
using System.Globalization;
|
||||
using Xenko.Core.Annotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
|
||||
36
math/DataMemberIgnoreAttribute.cs
Normal file
36
math/DataMemberIgnoreAttribute.cs
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
// Original code from SlimMath project. http://code.google.com/p/slimmath/
|
||||
// Greetings to SlimDX Group. Original code published with the following license:
|
||||
// -----------------------------------------------------------------------------
|
||||
/*
|
||||
* Copyright (c) 2007-2011 SlimDX Group
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
using System;
|
||||
|
||||
namespace math
|
||||
{
|
||||
internal class DataMemberIgnoreAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -21,7 +21,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Double2"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Double2>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Double2>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Double2"/> with all of its components set to zero.
|
||||
|
||||
@ -21,7 +21,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Double3"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Double3>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Double3>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Double3"/> with all of its components set to zero.
|
||||
|
||||
@ -21,7 +21,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Double4"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Double4>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Double4>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Double4"/> with all of its components set to zero.
|
||||
|
||||
@ -25,7 +25,6 @@ using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xenko.Core.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xenko.Core.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xenko.Core.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xenko.Core.Serialization;
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
|
||||
@ -44,7 +44,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Int2"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Int2>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Int2>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Int2"/> with all of its components set to zero.
|
||||
|
||||
@ -44,7 +44,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="Int3"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Int3>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Int3>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="Int3"/> with all of its components set to zero.
|
||||
|
||||
@ -38,7 +38,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref = "Int4" /> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Int4>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Int4>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref = "Int4" /> with all of its components set to zero.
|
||||
|
||||
@ -47,7 +47,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Matrix"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Matrix>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Matrix>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Matrix"/> with all of its components set to zero.
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
using System.Reflection;
|
||||
using Xenko.Core.Reflection;
|
||||
|
||||
namespace math
|
||||
{
|
||||
/// <summary>
|
||||
/// Module initializer.
|
||||
/// </summary>
|
||||
internal class Module
|
||||
{
|
||||
/// <summary>
|
||||
/// Module initializer.
|
||||
/// </summary>
|
||||
[ModuleInitializer]
|
||||
public static void Initialize()
|
||||
{
|
||||
AssemblyRegistry.Register(typeof(Module).GetTypeInfo().Assembly, AssemblyCommonCategories.Assets);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xenko.Core.Serialization;
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
||||
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#pragma warning disable 436 // Xenko.PublicKeys is defined in multiple assemblies
|
||||
|
||||
[assembly: InternalsVisibleTo("math.Serializers" + Xenko.PublicKeys.Default)]
|
||||
@ -44,7 +44,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Quaternion"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Quaternion>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Quaternion>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Quaternion"/> with all of its components set to zero.
|
||||
|
||||
@ -97,7 +97,7 @@ namespace math
|
||||
// ReSharper restore UnusedParameter.Local
|
||||
{
|
||||
if (l > maxOrder - 1)
|
||||
throw new IndexOutOfRangeException("'l' parameter should be between '0' and '{0}' (order-1).".ToFormat(maxOrder-1));
|
||||
throw new IndexOutOfRangeException($"'l' parameter should be between '0' and '{maxOrder-1}' (order-1).");
|
||||
|
||||
if (Math.Abs(m) > l)
|
||||
throw new IndexOutOfRangeException("'m' parameter should be between '-l' and '+l'.");
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.InteropServices;
|
||||
using Xenko.Core.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace math
|
||||
@ -38,7 +37,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref = "UInt4" /> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<UInt4>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<UInt4>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref = "UInt4" /> with all of its components set to zero.
|
||||
|
||||
@ -46,7 +46,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Vec2"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Vec2>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Vec2>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Vec2"/> with all of its components set to zero.
|
||||
|
||||
@ -46,7 +46,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Vector3"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Vector3>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Vector3>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Vector3"/> with all of its components set to zero.
|
||||
|
||||
@ -45,7 +45,7 @@ namespace math
|
||||
/// <summary>
|
||||
/// The size of the <see cref="math.Vector4"/> type, in bytes.
|
||||
/// </summary>
|
||||
public static readonly int SizeInBytes = Utilities.SizeOf<Vector4>();
|
||||
public static readonly int SizeInBytes = lib.Util.SizeOf<Vector4>();
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="math.Vector4"/> with all of its components set to zero.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user