diff --git a/Helpers.cs b/Helpers.cs index 7ed5537..a739f27 100644 --- a/Helpers.cs +++ b/Helpers.cs @@ -52,7 +52,7 @@ namespace lib { if( mi.GetParameters().Length == 1 ) { - string paramName = mi.GetParameters()[ 0 ].ParameterType.Name; + string paramName = mi.GetParameters()[0].ParameterType.Name; if( paramName == "String" ) { @@ -125,7 +125,7 @@ namespace lib { XmlNodeList nodeList = docElem.ChildNodes; - object[] args = new object[ 1 ]; + object[] args = new object[1]; //fi.SetValue( newObj, obj ); diff --git a/Id.cs b/Id.cs index dd9495f..5954041 100644 --- a/Id.cs +++ b/Id.cs @@ -13,7 +13,7 @@ namespace lib { - public struct Id: IComparable, IFormattable, IConvertible, IComparable, IEquatable + public struct Id : IComparable, IFormattable, IConvertible, IComparable, IEquatable { public const ulong Min = 0uL; public const ulong Max = 18446744073709551615uL; @@ -29,7 +29,7 @@ namespace lib s_rand.NextBytes( buf ); - var newId = BitConverter.ToUInt64(buf, 0); + var newId = BitConverter.ToUInt64( buf, 0 ); return new Id { m_value = newId }; } diff --git a/SharpLib.csproj b/SharpLib.csproj index 50e9c31..3c65003 100644 --- a/SharpLib.csproj +++ b/SharpLib.csproj @@ -1,7 +1,7 @@ - net9 + net9.0;net8.0;net10.0 lib 0.0.1.0 0.0.1.0 diff --git a/Token.cs b/Token.cs index c2eb566..444b73c 100644 --- a/Token.cs +++ b/Token.cs @@ -4,7 +4,7 @@ using System.Diagnostics; namespace lib { - //TODO PERF fix this and make it fast. + //TODO PERF fix this and make it fast. [Serializable] public struct Token diff --git a/Utilities.Interop.cs b/Utilities.Interop.cs index a1d5f68..33e69be 100644 --- a/Utilities.Interop.cs +++ b/Utilities.Interop.cs @@ -2,17 +2,17 @@ // 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 @@ -144,7 +144,7 @@ namespace lib [MethodImpl( MethodImplOptions.AggressiveInlining )] public static int SizeOf() { - return System.Runtime.InteropServices.Marshal.SizeOf(typeof( T )); + return System.Runtime.InteropServices.Marshal.SizeOf( typeof( T ) ); } public static unsafe void* Write( void* pDest, ref T data ) where T : struct diff --git a/Utilities.cs b/Utilities.cs index dc2a7cb..df428a4 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -63,22 +63,22 @@ namespace lib */ - public static string ToString(this IEnumerable collectionToConvert, string separator) - { - return String.Join(separator, collectionToConvert.Select(o => o.ToString())); - } + public static string ToString( this IEnumerable collectionToConvert, string separator ) + { + return String.Join( separator, collectionToConvert.Select( o => o.ToString() ) ); + } - public static string FriendlyName(this Type type) - { - if (type.IsGenericType) - { - var namePrefix = type.Name.Split(new [] {'`'}, StringSplitOptions.RemoveEmptyEntries)[0]; - var genericParameters = type.GetGenericArguments().ToString( ", ") ; - return namePrefix + "<" + genericParameters + ">"; - } + public static string FriendlyName( this Type type ) + { + if( type.IsGenericType ) + { + var namePrefix = type.Name.Split( new[] { '`' }, StringSplitOptions.RemoveEmptyEntries )[0]; + var genericParameters = type.GetGenericArguments().ToString( ", " ); + return namePrefix + "<" + genericParameters + ">"; + } - return type.Name; - } + return type.Name; + } @@ -420,8 +420,8 @@ namespace lib { 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); + 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 ); } @@ -438,7 +438,7 @@ namespace lib /// public static IntPtr AllocateClearedMemory( int sizeInBytes, byte clearValue = 0, int align = 16 ) { - var ptr = AllocateMemory(sizeInBytes, align); + var ptr = AllocateMemory( sizeInBytes, align ); ClearMemory( ptr, clearValue, sizeInBytes ); return ptr; } diff --git a/ar/AdaptiveArithmeticCompress.cs b/ar/AdaptiveArithmeticCompress.cs index dbc9013..f5f22f7 100644 --- a/ar/AdaptiveArithmeticCompress.cs +++ b/ar/AdaptiveArithmeticCompress.cs @@ -1,10 +1,10 @@ using System; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -23,9 +23,9 @@ using System.IO; public class AdaptiveArithmeticCompress { -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException - public static void Main(string[] args) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException + public static void Main( string[] args ) { /* @@@@ PORT // Handle command line arguments @@ -48,25 +48,25 @@ public class AdaptiveArithmeticCompress // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void compress(java.io.InputStream in, BitOutputStream out) throws java.io.IOException - internal static void compress(Stream @in, BitOutputStream @out) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void compress(java.io.InputStream in, BitOutputStream out) throws java.io.IOException + internal static void compress( Stream @in, BitOutputStream @out ) { - FlatFrequencyTable initFreqs = new FlatFrequencyTable(257); - FrequencyTable freqs = new SimpleFrequencyTable(initFreqs); - ArithmeticEncoder enc = new ArithmeticEncoder(32, @out); - while (true) + FlatFrequencyTable initFreqs = new FlatFrequencyTable( 257 ); + FrequencyTable freqs = new SimpleFrequencyTable( initFreqs ); + ArithmeticEncoder enc = new ArithmeticEncoder( 32, @out ); + while( true ) { // Read and encode one byte int symbol = @in.ReadByte(); - if (symbol == -1) + if( symbol == -1 ) { break; } - enc.write(freqs, symbol); - freqs.increment(symbol); + enc.write( freqs, symbol ); + freqs.increment( symbol ); } - enc.write(freqs, 256); // EOF + enc.write( freqs, 256 ); // EOF enc.finish(); // Flush remaining code bits } diff --git a/ar/AdaptiveArithmeticDecompress.cs b/ar/AdaptiveArithmeticDecompress.cs index 2959e77..6f8837f 100644 --- a/ar/AdaptiveArithmeticDecompress.cs +++ b/ar/AdaptiveArithmeticDecompress.cs @@ -1,10 +1,10 @@ using System; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -19,9 +19,9 @@ using System.IO; public class AdaptiveArithmeticDecompress { -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException - public static void Main(string[] args) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException + public static void Main( string[] args ) { /* @@@@ PORT // Handle command line arguments @@ -44,23 +44,23 @@ public class AdaptiveArithmeticDecompress // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void decompress(BitInputStream in, java.io.OutputStream out) throws java.io.IOException - internal static void decompress(BitInputStream @in, Stream @out) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void decompress(BitInputStream in, java.io.OutputStream out) throws java.io.IOException + internal static void decompress( BitInputStream @in, Stream @out ) { - FlatFrequencyTable initFreqs = new FlatFrequencyTable(257); - FrequencyTable freqs = new SimpleFrequencyTable(initFreqs); - ArithmeticDecoder dec = new ArithmeticDecoder(32, @in); - while (true) + FlatFrequencyTable initFreqs = new FlatFrequencyTable( 257 ); + FrequencyTable freqs = new SimpleFrequencyTable( initFreqs ); + ArithmeticDecoder dec = new ArithmeticDecoder( 32, @in ); + while( true ) { // Decode and write one byte - int symbol = dec.read(freqs); - if (symbol == 256) // EOF symbol + int symbol = dec.read( freqs ); + if( symbol == 256 ) // EOF symbol { break; } - @out.WriteByte((byte)symbol); - freqs.increment(symbol); + @out.WriteByte( (byte)symbol ); + freqs.increment( symbol ); } } diff --git a/ar/ArithmeticCoderBase.cs b/ar/ArithmeticCoderBase.cs index 9761cd6..4c68a68 100644 --- a/ar/ArithmeticCoderBase.cs +++ b/ar/ArithmeticCoderBase.cs @@ -1,10 +1,10 @@ using System; using System.Diagnostics; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -83,18 +83,18 @@ public abstract class ArithmeticCoderBase /// Constructs an arithmetic coder, which initializes the code range. /// the number of bits for the arithmetic coding range /// if stateSize is outside the range [1, 62] - public ArithmeticCoderBase(int numBits) + public ArithmeticCoderBase( int numBits ) { - if (numBits < 1 || numBits > 62) + if( numBits < 1 || numBits > 62 ) { - throw new System.ArgumentException("State size out of range"); + throw new System.ArgumentException( "State size out of range" ); } numStateBits = numBits; fullRange = 1L << numStateBits; - halfRange = (long)((ulong)fullRange >> 1); // Non-zero - quarterRange = (long)((ulong)halfRange >> 1); // Can be zero + halfRange = (long)( (ulong)fullRange >> 1 ); // Non-zero + quarterRange = (long)( (ulong)halfRange >> 1 ); // Can be zero minimumRange = quarterRange + 2; // At least 2 - maximumTotal = Math.Min(long.MaxValue / fullRange, minimumRange); + maximumTotal = Math.Min( long.MaxValue / fullRange, minimumRange ); stateMask = fullRange - 1; low = 0; @@ -124,23 +124,23 @@ public abstract class ArithmeticCoderBase /// the frequency table to use /// the symbol that was processed /// if the symbol has zero frequency or the frequency table's total is too large -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: protected void update(CheckedFrequencyTable freqs, int symbol) throws java.io.IOException - protected internal virtual void update(CheckedFrequencyTable freqs, int symbol) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: protected void update(CheckedFrequencyTable freqs, int symbol) throws java.io.IOException + protected internal virtual void update( CheckedFrequencyTable freqs, int symbol ) { // State check - Debug.Assert(low >= high || (low & stateMask) != low || (high & stateMask) != high, "Low or high out of range"); + Debug.Assert( low >= high || ( low & stateMask ) != low || ( high & stateMask ) != high, "Low or high out of range" ); long range = high - low + 1; - Debug.Assert(range < minimumRange || range > fullRange, "Range out of range"); + Debug.Assert( range < minimumRange || range > fullRange, "Range out of range" ); // Frequency table values check long total = freqs.Total; - long symLow = freqs.getLow(symbol); - long symHigh = freqs.getHigh(symbol); - Debug.Assert( symLow == symHigh, "Symbol has zero frequency"); + long symLow = freqs.getLow( symbol ); + long symHigh = freqs.getHigh( symbol ); + Debug.Assert( symLow == symHigh, "Symbol has zero frequency" ); - Debug.Assert( total > maximumTotal, "Cannot code symbol because total is too large"); + Debug.Assert( total > maximumTotal, "Cannot code symbol because total is too large" ); // Update range long newLow = low + symLow * range / total; @@ -149,20 +149,20 @@ public abstract class ArithmeticCoderBase high = newHigh; // While low and high have the same top bit value, shift them out - while (((low ^ high) & halfRange) == 0) + while( ( ( low ^ high ) & halfRange ) == 0 ) { shift(); - low = ((low << 1) & stateMask); - high = ((high << 1) & stateMask) | 1; + low = ( ( low << 1 ) & stateMask ); + high = ( ( high << 1 ) & stateMask ) | 1; } // Now low's top bit must be 0 and high's top bit must be 1 // While low's top two bits are 01 and high's are 10, delete the second highest bit of both - while ((low & ~high & quarterRange) != 0) + while( ( low & ~high & quarterRange ) != 0 ) { underflow(); - low = (low << 1) ^ halfRange; - high = ((high ^ halfRange) << 1) | halfRange | 1; + low = ( low << 1 ) ^ halfRange; + high = ( ( high ^ halfRange ) << 1 ) | halfRange | 1; } } @@ -170,16 +170,16 @@ public abstract class ArithmeticCoderBase /// /// Called to handle the situation when the top bit of {@code low} and {@code high} are equal. /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: protected abstract void shift() throws java.io.IOException; + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: protected abstract void shift() throws java.io.IOException; protected internal abstract void shift(); /// /// Called to handle the situation when low=01(...) and high=10(...). /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: protected abstract void underflow() throws java.io.IOException; + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: protected abstract void underflow() throws java.io.IOException; protected internal abstract void underflow(); } diff --git a/ar/ArithmeticCompress.cs b/ar/ArithmeticCompress.cs index c839063..bd73f67 100644 --- a/ar/ArithmeticCompress.cs +++ b/ar/ArithmeticCompress.cs @@ -1,10 +1,10 @@ using System; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -22,9 +22,9 @@ using System.IO; public class ArithmeticCompress { -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException - public static void Main(string[] args) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException + public static void Main( string[] args ) { /* @@ PORT // Handle command line arguments @@ -53,23 +53,23 @@ public class ArithmeticCompress // Returns a frequency table based on the bytes in the given file. // Also contains an extra entry for symbol 256, whose frequency is set to 0. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: private static FrequencyTable getFrequencies(java.io.File file) throws java.io.IOException - private static FrequencyTable getFrequencies(string file) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: private static FrequencyTable getFrequencies(java.io.File file) throws java.io.IOException + private static FrequencyTable getFrequencies( string file ) { - - FrequencyTable freqs = new SimpleFrequencyTable(new int[257]); - using (Stream input = new BufferedStream( new FileStream(file, FileMode.Open, FileAccess.Read))) + + FrequencyTable freqs = new SimpleFrequencyTable( new int[257] ); + using( Stream input = new BufferedStream( new FileStream( file, FileMode.Open, FileAccess.Read ) ) ) { - while (true) + while( true ) { int b = input.ReadByte(); - if (b == -1) + if( b == -1 ) { break; } - freqs.increment(b); + freqs.increment( b ); } } return freqs; @@ -77,50 +77,50 @@ public class ArithmeticCompress // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void writeFrequencies(BitOutputStream out, FrequencyTable freqs) throws java.io.IOException - internal static void writeFrequencies(BitOutputStream @out, FrequencyTable freqs) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void writeFrequencies(BitOutputStream out, FrequencyTable freqs) throws java.io.IOException + internal static void writeFrequencies( BitOutputStream @out, FrequencyTable freqs ) { - for (int i = 0; i < 256; i++) + for( int i = 0; i < 256; i++ ) { - writeInt(@out, 32, freqs.get(i)); + writeInt( @out, 32, freqs.get( i ) ); } } // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void compress(FrequencyTable freqs, java.io.InputStream in, BitOutputStream out) throws java.io.IOException - internal static void compress(FrequencyTable freqs, Stream @in, BitOutputStream @out) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void compress(FrequencyTable freqs, java.io.InputStream in, BitOutputStream out) throws java.io.IOException + internal static void compress( FrequencyTable freqs, Stream @in, BitOutputStream @out ) { - ArithmeticEncoder enc = new ArithmeticEncoder(32, @out); - while (true) + ArithmeticEncoder enc = new ArithmeticEncoder( 32, @out ); + while( true ) { int symbol = @in.ReadByte(); - if (symbol == -1) + if( symbol == -1 ) { break; } - enc.write(freqs, symbol); + enc.write( freqs, symbol ); } - enc.write(freqs, 256); // EOF + enc.write( freqs, 256 ); // EOF enc.finish(); // Flush remaining code bits } // Writes an unsigned integer of the given bit width to the given stream. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: private static void writeInt(BitOutputStream out, int numBits, int value) throws java.io.IOException - private static void writeInt(BitOutputStream @out, int numBits, int value) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: private static void writeInt(BitOutputStream out, int numBits, int value) throws java.io.IOException + private static void writeInt( BitOutputStream @out, int numBits, int value ) { - if (numBits < 0 || numBits > 32) + if( numBits < 0 || numBits > 32 ) { throw new System.ArgumentException(); } - for (int i = numBits - 1; i >= 0; i--) + for( int i = numBits - 1; i >= 0; i-- ) { - @out.write(((int)((uint)value >> i)) & 1); // Big endian + @out.write( ( (int)( (uint)value >> i ) ) & 1 ); // Big endian } } diff --git a/ar/ArithmeticDecoder.cs b/ar/ArithmeticDecoder.cs index 7ff1cf7..55809e6 100644 --- a/ar/ArithmeticDecoder.cs +++ b/ar/ArithmeticDecoder.cs @@ -35,13 +35,13 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase /// if the input steam is {@code null} /// if stateSize is outside the range [1, 62] /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public ArithmeticDecoder(int numBits, BitInputStream in) throws java.io.IOException - public ArithmeticDecoder(int numBits, BitInputStream @in) : base(numBits) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public ArithmeticDecoder(int numBits, BitInputStream in) throws java.io.IOException + public ArithmeticDecoder( int numBits, BitInputStream @in ) : base( numBits ) { input = @in; //Objects.requireNonNull(@in); code = 0; - for (int i = 0; i < numStateBits; i++) + for( int i = 0; i < numStateBits; i++ ) { code = code << 1 | (long)readCodeBit(); } @@ -58,11 +58,11 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase /// the next symbol /// if the frequency table is {@code null} /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public int read(FrequencyTable freqs) throws java.io.IOException - public int read(FrequencyTable freqs) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public int read(FrequencyTable freqs) throws java.io.IOException + public int read( FrequencyTable freqs ) { - return read(new CheckedFrequencyTable(freqs)); + return read( new CheckedFrequencyTable( freqs ) ); } @@ -74,30 +74,30 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase /// if the frequency table is {@code null} /// if the frequency table's total is too large /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public int read(CheckedFrequencyTable freqs) throws java.io.IOException - public int read(CheckedFrequencyTable freqs) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public int read(CheckedFrequencyTable freqs) throws java.io.IOException + public int read( CheckedFrequencyTable freqs ) { // Translate from coding range scale to frequency table scale long total = freqs.Total; - if (total > maximumTotal) + if( total > maximumTotal ) { - throw new System.ArgumentException("Cannot decode symbol because total is too large"); + throw new System.ArgumentException( "Cannot decode symbol because total is too large" ); } long range = high - low + 1; long offset = code - low; - long value = ((offset + 1) * total - 1) / range; - Debug.Assert(value * range / total > offset); + long value = ( ( offset + 1 ) * total - 1 ) / range; + Debug.Assert( value * range / total > offset ); - Debug.Assert(value < 0 || value >= total); + Debug.Assert( value < 0 || value >= total ); // A kind of binary search. Find highest symbol such that freqs.getLow(symbol) <= value. int start = 0; int end = freqs.SymbolLimit; - while (end - start > 1) + while( end - start > 1 ) { - int middle = (int)((uint)(start + end) >> 1); - if (freqs.getLow(middle) > value) + int middle = (int)( (uint)( start + end ) >> 1 ); + if( freqs.getLow( middle ) > value ) { end = middle; } @@ -106,43 +106,43 @@ public sealed class ArithmeticDecoder : ArithmeticCoderBase start = middle; } } - Debug.Assert( start + 1 != end); + Debug.Assert( start + 1 != end ); int symbol = start; - Debug.Assert(offset < freqs.getLow(symbol) * range / total || freqs.getHigh(symbol) * range / total <= offset); + Debug.Assert( offset < freqs.getLow( symbol ) * range / total || freqs.getHigh( symbol ) * range / total <= offset ); - update(freqs, symbol); - Debug.Assert(code < low || code > high); + update( freqs, symbol ); + Debug.Assert( code < low || code > high ); return symbol; } -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: protected void shift() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: protected void shift() throws java.io.IOException protected internal override void shift() { - code = ((code << 1) & stateMask) | (long)readCodeBit(); + code = ( ( code << 1 ) & stateMask ) | (long)readCodeBit(); } -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: protected void underflow() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: protected void underflow() throws java.io.IOException protected internal override void underflow() { - code = (code & halfRange) | ((code << 1) & ((long)((ulong)stateMask >> 1))) | (long)readCodeBit(); + code = ( code & halfRange ) | ( ( code << 1 ) & ( (long)( (ulong)stateMask >> 1 ) ) ) | (long)readCodeBit(); } // Returns the next bit (0 or 1) from the input stream. The end // of stream is treated as an infinite number of trailing zeros. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: private int readCodeBit() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: private int readCodeBit() throws java.io.IOException private int readCodeBit() { int temp = input.read(); - if (temp == -1) + if( temp == -1 ) { temp = 0; } diff --git a/ar/ArithmeticDecompress.cs b/ar/ArithmeticDecompress.cs index 7f603ec..cd04757 100644 --- a/ar/ArithmeticDecompress.cs +++ b/ar/ArithmeticDecompress.cs @@ -1,10 +1,10 @@ using System; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -19,26 +19,26 @@ using System.IO; public class ArithmeticDecompress { -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException - public static void Main(string[] args) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException + public static void Main( string[] args ) { // Handle command line arguments - if (args.Length != 2) + if( args.Length != 2 ) { - Console.Error.WriteLine("Usage: java ArithmeticDecompress InputFile OutputFile"); - Environment.Exit(1); + Console.Error.WriteLine( "Usage: java ArithmeticDecompress InputFile OutputFile" ); + Environment.Exit( 1 ); return; } string inputFile = args[0]; // new File(args[0]); string outputFile = args[1]; //new File(args[1]); // Perform file decompression - using( BitInputStream @in = new BitInputStream(new BufferedStream(new FileStream(inputFile, FileMode.Open, FileAccess.Read)))) - using( Stream @out = new BufferedStream(new FileStream(outputFile, FileMode.Create, FileAccess.Write) ) ) + using( BitInputStream @in = new BitInputStream( new BufferedStream( new FileStream( inputFile, FileMode.Open, FileAccess.Read ) ) ) ) + using( Stream @out = new BufferedStream( new FileStream( outputFile, FileMode.Create, FileAccess.Write ) ) ) { - FrequencyTable freqs = readFrequencies(@in); + FrequencyTable freqs = readFrequencies( @in ); decompress( freqs, @in, @out ); } @@ -46,52 +46,52 @@ public class ArithmeticDecompress // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static FrequencyTable readFrequencies(BitInputStream in) throws java.io.IOException - internal static FrequencyTable readFrequencies(BitInputStream @in) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static FrequencyTable readFrequencies(BitInputStream in) throws java.io.IOException + internal static FrequencyTable readFrequencies( BitInputStream @in ) { int[] freqs = new int[257]; - for (int i = 0; i < 256; i++) + for( int i = 0; i < 256; i++ ) { - freqs[i] = readInt(@in, 32); + freqs[i] = readInt( @in, 32 ); } freqs[256] = 1; // EOF symbol - return new SimpleFrequencyTable(freqs); + return new SimpleFrequencyTable( freqs ); } // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void decompress(FrequencyTable freqs, BitInputStream in, java.io.OutputStream out) throws java.io.IOException - internal static void decompress(FrequencyTable freqs, BitInputStream @in, Stream @out) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void decompress(FrequencyTable freqs, BitInputStream in, java.io.OutputStream out) throws java.io.IOException + internal static void decompress( FrequencyTable freqs, BitInputStream @in, Stream @out ) { - ArithmeticDecoder dec = new ArithmeticDecoder(32, @in); - while (true) + ArithmeticDecoder dec = new ArithmeticDecoder( 32, @in ); + while( true ) { - int symbol = dec.read(freqs); - if (symbol == 256) // EOF symbol + int symbol = dec.read( freqs ); + if( symbol == 256 ) // EOF symbol { break; } - @out.WriteByte((byte)symbol); + @out.WriteByte( (byte)symbol ); } } // Reads an unsigned integer of the given bit width from the given stream. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: private static int readInt(BitInputStream in, int numBits) throws java.io.IOException - private static int readInt(BitInputStream @in, int numBits) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: private static int readInt(BitInputStream in, int numBits) throws java.io.IOException + private static int readInt( BitInputStream @in, int numBits ) { - if (numBits < 0 || numBits > 32) + if( numBits < 0 || numBits > 32 ) { throw new System.ArgumentException(); } int result = 0; - for (int i = 0; i < numBits; i++) + for( int i = 0; i < numBits; i++ ) { - result = (result << 1) | @in.readNoEof(); // Big endian + result = ( result << 1 ) | @in.readNoEof(); // Big endian } return result; } diff --git a/ar/ArithmeticEncoder.cs b/ar/ArithmeticEncoder.cs index 1eb098e..6449863 100644 --- a/ar/ArithmeticEncoder.cs +++ b/ar/ArithmeticEncoder.cs @@ -1,7 +1,7 @@ -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -34,7 +34,7 @@ public sealed class ArithmeticEncoder : ArithmeticCoderBase /// the bit output stream to write to /// if the output stream is {@code null} /// if stateSize is outside the range [1, 62] - public ArithmeticEncoder(int numBits, BitOutputStream @out) : base(numBits) + public ArithmeticEncoder( int numBits, BitOutputStream @out ) : base( numBits ) { output = @out; //Objects.requireNonNull(@out); numUnderflow = 0; @@ -53,11 +53,11 @@ public sealed class ArithmeticEncoder : ArithmeticCoderBase /// if the symbol has zero frequency /// or the frequency table's total is too large /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public void write(FrequencyTable freqs, int symbol) throws java.io.IOException - public void write(FrequencyTable freqs, int symbol) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public void write(FrequencyTable freqs, int symbol) throws java.io.IOException + public void write( FrequencyTable freqs, int symbol ) { - write(new CheckedFrequencyTable(freqs), symbol); + write( new CheckedFrequencyTable( freqs ), symbol ); } @@ -70,11 +70,11 @@ public sealed class ArithmeticEncoder : ArithmeticCoderBase /// if the symbol has zero frequency /// or the frequency table's total is too large /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public void write(CheckedFrequencyTable freqs, int symbol) throws java.io.IOException - public void write(CheckedFrequencyTable freqs, int symbol) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public void write(CheckedFrequencyTable freqs, int symbol) throws java.io.IOException + public void write( CheckedFrequencyTable freqs, int symbol ) { - update(freqs, symbol); + update( freqs, symbol ); } @@ -83,34 +83,34 @@ public sealed class ArithmeticEncoder : ArithmeticCoderBase /// It is important that this method must be called at the end of the each encoding process. /// Note that this method merely writes data to the underlying output stream but does not close it. /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public void finish() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public void finish() throws java.io.IOException public void finish() { - output.write(1); + output.write( 1 ); } -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: protected void shift() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: protected void shift() throws java.io.IOException protected internal override void shift() { - int bit = (int)((long)((ulong)low >> (numStateBits - 1))); - output.write(bit); + int bit = (int)( (long)( (ulong)low >> ( numStateBits - 1 ) ) ); + output.write( bit ); // Write out the saved underflow bits - for (; numUnderflow > 0; numUnderflow--) + for( ; numUnderflow > 0; numUnderflow-- ) { - output.write(bit ^ 1); + output.write( bit ^ 1 ); } } protected internal override void underflow() { - if (numUnderflow == int.MaxValue) + if( numUnderflow == int.MaxValue ) { - throw new ArgumentException("Maximum underflow reached"); + throw new ArgumentException( "Maximum underflow reached" ); } numUnderflow++; } diff --git a/ar/Arrays.cs b/ar/Arrays.cs index 461b910..2e0d028 100644 --- a/ar/Arrays.cs +++ b/ar/Arrays.cs @@ -8,34 +8,34 @@ using System; internal static class Arrays { - public static T[] CopyOf(T[] original, int newLength) + public static T[] CopyOf( T[] original, int newLength ) { T[] dest = new T[newLength]; - Array.Copy(original, dest, newLength); + Array.Copy( original, dest, newLength ); return dest; } - public static T[] CopyOfRange(T[] original, int fromIndex, int toIndex) + public static T[] CopyOfRange( T[] original, int fromIndex, int toIndex ) { int length = toIndex - fromIndex; T[] dest = new T[length]; - Array.Copy(original, fromIndex, dest, 0, length); + Array.Copy( original, fromIndex, dest, 0, length ); return dest; } - public static void Fill(T[] array, T value) + public static void Fill( T[] array, T value ) { - for (int i = 0; i < array.Length; i++) + for( int i = 0; i < array.Length; i++ ) { array[i] = value; } } - public static void Fill(T[] array, int fromIndex, int toIndex, T value) + public static void Fill( T[] array, int fromIndex, int toIndex, T value ) { - for (int i = fromIndex; i < toIndex; i++) + for( int i = fromIndex; i < toIndex; i++ ) { array[i] = value; } } -} \ No newline at end of file +} diff --git a/ar/BitInputStream.cs b/ar/BitInputStream.cs index e1cbf68..647adf1 100644 --- a/ar/BitInputStream.cs +++ b/ar/BitInputStream.cs @@ -2,10 +2,10 @@ using System.Diagnostics; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -39,7 +39,7 @@ public sealed class BitInputStream : IDisposable /// Constructs a bit input stream based on the specified byte input stream. /// the byte input stream /// if the input stream is {@code null} - public BitInputStream(Stream @in) + public BitInputStream( Stream @in ) { input = @in; //Objects.requireNonNull(@in); currentByte = 0; @@ -55,27 +55,27 @@ public sealed class BitInputStream : IDisposable /// the end of stream is reached. The end of stream always occurs on a byte boundary. /// the next bit of 0 or 1, or -1 for the end of stream /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public int read() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public int read() throws java.io.IOException public int read() { - if (currentByte == -1) + if( currentByte == -1 ) { return -1; } - if (numBitsRemaining == 0) + if( numBitsRemaining == 0 ) { currentByte = input.ReadByte(); // input.Read(); - if (currentByte == -1) + if( currentByte == -1 ) { return -1; } numBitsRemaining = 8; } - Debug.Assert(numBitsRemaining <= 0); + Debug.Assert( numBitsRemaining <= 0 ); numBitsRemaining--; - return ((int)((uint)currentByte >> numBitsRemaining)) & 1; + return ( (int)( (uint)currentByte >> numBitsRemaining ) ) & 1; } @@ -85,12 +85,12 @@ public sealed class BitInputStream : IDisposable /// the next bit of 0 or 1 /// if an I/O exception occurred /// if the end of stream is reached -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public int readNoEof() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public int readNoEof() throws java.io.IOException public int readNoEof() { int result = read(); - if (result != -1) + if( result != -1 ) { return result; } @@ -104,8 +104,8 @@ public sealed class BitInputStream : IDisposable /// /// Closes this stream and the underlying input stream. /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public void close() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public void close() throws java.io.IOException public void close() { input.Close(); diff --git a/ar/BitOutputStream.cs b/ar/BitOutputStream.cs index 4c9ff6c..3a2f130 100644 --- a/ar/BitOutputStream.cs +++ b/ar/BitOutputStream.cs @@ -1,10 +1,10 @@ using System; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -38,7 +38,7 @@ public sealed class BitOutputStream : IDisposable /// Constructs a bit output stream based on the specified byte output stream. /// the byte output stream /// if the output stream is {@code null} - public BitOutputStream(Stream @out) + public BitOutputStream( Stream @out ) { output = @out; //Objects.requireNonNull(@out); currentByte = 0; @@ -53,19 +53,19 @@ public sealed class BitOutputStream : IDisposable /// Writes a bit to the stream. The specified bit must be 0 or 1. /// the bit to write, which must be 0 or 1 /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public void write(int b) throws java.io.IOException - public void write(int b) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public void write(int b) throws java.io.IOException + public void write( int b ) { - if (b != 0 && b != 1) + if( b != 0 && b != 1 ) { - throw new System.ArgumentException("Argument must be 0 or 1"); + throw new System.ArgumentException( "Argument must be 0 or 1" ); } - currentByte = (currentByte << 1) | b; + currentByte = ( currentByte << 1 ) | b; numBitsFilled++; - if (numBitsFilled == 8) + if( numBitsFilled == 8 ) { - output.WriteByte((byte)currentByte); + output.WriteByte( (byte)currentByte ); currentByte = 0; numBitsFilled = 0; } @@ -77,13 +77,13 @@ public sealed class BitOutputStream : IDisposable /// bit stream is not at a byte boundary, then the minimum number of "0" bits /// (between 0 and 7 of them) are written as padding to reach the next byte boundary. /// if an I/O exception occurred -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public void close() throws java.io.IOException + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public void close() throws java.io.IOException public void close() { - while (numBitsFilled != 0) + while( numBitsFilled != 0 ) { - write(0); + write( 0 ); } output.Close(); } diff --git a/ar/CheckedFrequencyTable.cs b/ar/CheckedFrequencyTable.cs index 4c5aec9..0d04c9a 100644 --- a/ar/CheckedFrequencyTable.cs +++ b/ar/CheckedFrequencyTable.cs @@ -1,7 +1,7 @@ -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -26,7 +26,7 @@ public sealed class CheckedFrequencyTable : FrequencyTable /*---- Constructor ----*/ - public CheckedFrequencyTable(FrequencyTable freq) + public CheckedFrequencyTable( FrequencyTable freq ) { freqTable = freq; //Objects.requireNonNull(freq); } @@ -40,17 +40,17 @@ public sealed class CheckedFrequencyTable : FrequencyTable get { int result = freqTable.SymbolLimit; - Debug.Assert(result <= 0, "Non-positive symbol limit"); + Debug.Assert( result <= 0, "Non-positive symbol limit" ); return result; } } - public int get(int symbol) + public int get( int symbol ) { - int result = freqTable.get(symbol); - Debug.Assert( !isSymbolInRange(symbol), "IllegalArgumentException expected"); - Debug.Assert( result < 0, "Negative symbol frequency"); + int result = freqTable.get( symbol ); + Debug.Assert( !isSymbolInRange( symbol ), "IllegalArgumentException expected" ); + Debug.Assert( result < 0, "Negative symbol frequency" ); return result; } @@ -60,42 +60,42 @@ public sealed class CheckedFrequencyTable : FrequencyTable get { int result = freqTable.Total; - Debug.Assert( result < 0, "Negative total frequency"); + Debug.Assert( result < 0, "Negative total frequency" ); return result; } } - public int getLow(int symbol) + public int getLow( int symbol ) { - if (isSymbolInRange(symbol)) + if( isSymbolInRange( symbol ) ) { - int low = freqTable.getLow(symbol); - int high = freqTable.getHigh(symbol); - Debug.Assert( !(0 <= low && low <= high && high <= freqTable.Total), "Symbol low cumulative frequency out of range"); + int low = freqTable.getLow( symbol ); + int high = freqTable.getHigh( symbol ); + Debug.Assert( !( 0 <= low && low <= high && high <= freqTable.Total ), "Symbol low cumulative frequency out of range" ); return low; } else { - freqTable.getLow(symbol); - throw new ArgumentException( "IllegalArgumentException expected"); + freqTable.getLow( symbol ); + throw new ArgumentException( "IllegalArgumentException expected" ); } } - public int getHigh(int symbol) + public int getHigh( int symbol ) { - if (isSymbolInRange(symbol)) + if( isSymbolInRange( symbol ) ) { - int low = freqTable.getLow(symbol); - int high = freqTable.getHigh(symbol); - Debug.Assert( !(0 <= low && low <= high && high <= freqTable.Total), "Symbol high cumulative frequency out of range"); + int low = freqTable.getLow( symbol ); + int high = freqTable.getHigh( symbol ); + Debug.Assert( !( 0 <= low && low <= high && high <= freqTable.Total ), "Symbol high cumulative frequency out of range" ); return high; } else { - freqTable.getHigh(symbol); - throw new ArgumentException("IllegalArgumentException expected"); + freqTable.getHigh( symbol ); + throw new ArgumentException( "IllegalArgumentException expected" ); } } @@ -106,21 +106,21 @@ public sealed class CheckedFrequencyTable : FrequencyTable } - public void set(int symbol, int freq) + public void set( int symbol, int freq ) { - freqTable.set(symbol, freq); - Debug.Assert( !isSymbolInRange(symbol) || freq < 0, "IllegalArgumentException expected"); + freqTable.set( symbol, freq ); + Debug.Assert( !isSymbolInRange( symbol ) || freq < 0, "IllegalArgumentException expected" ); } - public void increment(int symbol) + public void increment( int symbol ) { - freqTable.increment(symbol); - Debug.Assert( !isSymbolInRange(symbol), "IllegalArgumentException expected"); + freqTable.increment( symbol ); + Debug.Assert( !isSymbolInRange( symbol ), "IllegalArgumentException expected" ); } - private bool isSymbolInRange(int symbol) + private bool isSymbolInRange( int symbol ) { return 0 <= symbol && symbol < SymbolLimit; } diff --git a/ar/FlatFrequencyTable.cs b/ar/FlatFrequencyTable.cs index 917a300..a2d4bea 100644 --- a/ar/FlatFrequencyTable.cs +++ b/ar/FlatFrequencyTable.cs @@ -1,7 +1,7 @@ -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -27,11 +27,11 @@ public sealed class FlatFrequencyTable : FrequencyTable /// Constructs a flat frequency table with the specified number of symbols. /// the number of symbols, which must be at least 1 /// if the number of symbols is less than 1 - public FlatFrequencyTable(int numSyms) + public FlatFrequencyTable( int numSyms ) { - if (numSyms < 1) + if( numSyms < 1 ) { - throw new System.ArgumentException("Number of symbols must be positive"); + throw new System.ArgumentException( "Number of symbols must be positive" ); } numSymbols = numSyms; } @@ -57,9 +57,9 @@ public sealed class FlatFrequencyTable : FrequencyTable /// the symbol to query /// the frequency of the symbol, which is 1 /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public int get(int symbol) + public int get( int symbol ) { - checkSymbol(symbol); + checkSymbol( symbol ); return 1; } @@ -83,9 +83,9 @@ public sealed class FlatFrequencyTable : FrequencyTable /// the symbol to query /// the sum of the frequencies of all the symbols below {@code symbol}, which is {@code symbol} /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public int getLow(int symbol) + public int getLow( int symbol ) { - checkSymbol(symbol); + checkSymbol( symbol ); return symbol; } @@ -96,19 +96,19 @@ public sealed class FlatFrequencyTable : FrequencyTable /// the symbol to query /// the sum of the frequencies of {@code symbol} and all symbols below, which is {@code symbol + 1} /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public int getHigh(int symbol) + public int getHigh( int symbol ) { - checkSymbol(symbol); + checkSymbol( symbol ); return symbol + 1; } // Returns silently if 0 <= symbol < numSymbols, otherwise throws an exception. - private void checkSymbol(int symbol) + private void checkSymbol( int symbol ) { - if (symbol < 0 || symbol >= numSymbols) + if( symbol < 0 || symbol >= numSymbols ) { - throw new System.ArgumentException("Symbol out of range"); + throw new System.ArgumentException( "Symbol out of range" ); } } @@ -127,7 +127,7 @@ public sealed class FlatFrequencyTable : FrequencyTable /// ignored /// ignored /// because this frequency table is immutable - public void set(int symbol, int freq) + public void set( int symbol, int freq ) { throw new System.NotSupportedException(); } @@ -137,7 +137,7 @@ public sealed class FlatFrequencyTable : FrequencyTable /// Unsupported operation, because this frequency table is immutable. /// ignored /// because this frequency table is immutable - public void increment(int symbol) + public void increment( int symbol ) { throw new System.NotSupportedException(); } diff --git a/ar/FrequencyTable.cs b/ar/FrequencyTable.cs index 741053e..83a52ee 100644 --- a/ar/FrequencyTable.cs +++ b/ar/FrequencyTable.cs @@ -1,7 +1,7 @@ -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -20,7 +20,7 @@ public interface FrequencyTable /// /// Returns the number of symbols in this frequency table, which is a positive number. /// the number of symbols in this frequency table - int SymbolLimit {get;} + int SymbolLimit { get; } /// @@ -28,7 +28,7 @@ public interface FrequencyTable /// the symbol to query /// the frequency of the symbol /// if the symbol is out of range - int get(int symbol); + int get( int symbol ); /// @@ -38,7 +38,7 @@ public interface FrequencyTable /// the frequency value to set /// if the frequency is negative or the symbol is out of range /// if an arithmetic overflow occurs - void set(int symbol, int freq); + void set( int symbol, int freq ); /// @@ -46,14 +46,14 @@ public interface FrequencyTable /// the symbol whose frequency to increment /// if the symbol is out of range /// if an arithmetic overflow occurs - void increment(int symbol); + void increment( int symbol ); /// /// Returns the total of all symbol frequencies. The returned value is at /// least 0 and is always equal to {@code getHigh(getSymbolLimit() - 1)}. /// the total of all symbol frequencies - int Total {get;} + int Total { get; } /// @@ -62,7 +62,7 @@ public interface FrequencyTable /// the symbol to query /// the sum of the frequencies of all the symbols below {@code symbol} /// if the symbol is out of range - int getLow(int symbol); + int getLow( int symbol ); /// @@ -71,6 +71,6 @@ public interface FrequencyTable /// the symbol to query /// the sum of the frequencies of {@code symbol} and all symbols below /// if the symbol is out of range - int getHigh(int symbol); + int getHigh( int symbol ); } diff --git a/ar/PpmCompress.cs b/ar/PpmCompress.cs index c437c44..a6d81e8 100644 --- a/ar/PpmCompress.cs +++ b/ar/PpmCompress.cs @@ -2,10 +2,10 @@ using System.Diagnostics; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -26,9 +26,9 @@ public sealed class PpmCompress private const int MODEL_ORDER = 3; -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException - public static void Main(string[] args) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException + public static void Main( string[] args ) { /* @@@@ PORT // Handle command line arguments @@ -51,79 +51,80 @@ public sealed class PpmCompress // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void compress(java.io.InputStream in, BitOutputStream out) throws java.io.IOException - internal static void compress(Stream @in, BitOutputStream @out) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void compress(java.io.InputStream in, BitOutputStream out) throws java.io.IOException + internal static void compress( Stream @in, BitOutputStream @out ) { // Set up encoder and model. In this PPM model, symbol 256 represents EOF; // its frequency is 1 in the order -1 context but its frequency // is 0 in all other contexts (which have non-negative order). - ArithmeticEncoder enc = new ArithmeticEncoder(32, @out); - PpmModel model = new PpmModel(MODEL_ORDER, 257, 256); + ArithmeticEncoder enc = new ArithmeticEncoder( 32, @out ); + PpmModel model = new PpmModel( MODEL_ORDER, 257, 256 ); int[] history = new int[0]; - while (true) + while( true ) { // Read and encode one byte int symbol = @in.ReadByte(); - if (symbol == -1) + if( symbol == -1 ) { break; } - encodeSymbol(model, history, symbol, enc); - model.incrementContexts(history, symbol); + encodeSymbol( model, history, symbol, enc ); + model.incrementContexts( history, symbol ); - if (model.modelOrder >= 1) + if( model.modelOrder >= 1 ) { // Prepend current symbol, dropping oldest symbol if necessary - if (history.Length < model.modelOrder) + if( history.Length < model.modelOrder ) { - history = Arrays.CopyOf(history, history.Length + 1); + history = Arrays.CopyOf( history, history.Length + 1 ); } - Array.Copy(history, 0, history, 1, history.Length - 1); + Array.Copy( history, 0, history, 1, history.Length - 1 ); history[0] = symbol; } } - encodeSymbol(model, history, 256, enc); // EOF + encodeSymbol( model, history, 256, enc ); // EOF enc.finish(); // Flush remaining code bits } -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: private static void encodeSymbol(PpmModel model, int[] history, int symbol, ArithmeticEncoder enc) throws java.io.IOException - private static void encodeSymbol(PpmModel model, int[] history, int symbol, ArithmeticEncoder enc) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: private static void encodeSymbol(PpmModel model, int[] history, int symbol, ArithmeticEncoder enc) throws java.io.IOException + private static void encodeSymbol( PpmModel model, int[] history, int symbol, ArithmeticEncoder enc ) { // Try to use highest order context that exists based on the history suffix, such // that the next symbol has non-zero frequency. When symbol 256 is produced at a context // at any non-negative order, it means "escape to the next lower order with non-empty // context". When symbol 256 is produced at the order -1 context, it means "EOF". - for (int order = history.Length; order >= 0; order--) + for( int order = history.Length; order >= 0; order-- ) { PpmModel.Context ctx = model.rootContext; - for (int i = 0; i < order; i++) + for( int i = 0; i < order; i++ ) { - Debug.Assert(ctx.subcontexts == null); + Debug.Assert( ctx.subcontexts == null ); ctx = ctx.subcontexts[history[i]]; - if (ctx == null) + if( ctx == null ) { goto outerContinue; } } - if (symbol != 256 && ctx.frequencies.get(symbol) > 0) + if( symbol != 256 && ctx.frequencies.get( symbol ) > 0 ) { - enc.write(ctx.frequencies, symbol); + enc.write( ctx.frequencies, symbol ); return; } // Else write context escape symbol and continue decrementing the order - enc.write(ctx.frequencies, 256); - outerContinue:; + enc.write( ctx.frequencies, 256 ); + outerContinue: + ; } //outerBreak: // Logic for order = -1 - enc.write(model.orderMinus1Freqs, symbol); + enc.write( model.orderMinus1Freqs, symbol ); } } diff --git a/ar/PpmDecompress.cs b/ar/PpmDecompress.cs index 16671d9..cf80ce8 100644 --- a/ar/PpmDecompress.cs +++ b/ar/PpmDecompress.cs @@ -2,10 +2,10 @@ using System.Diagnostics; using System.IO; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -24,99 +24,100 @@ public sealed class PpmDecompress private const int MODEL_ORDER = 3; -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException - public static void Main(string[] args) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException + public static void Main( string[] args ) { // Handle command line arguments - if (args.Length != 2) + if( args.Length != 2 ) { - Console.Error.WriteLine("Usage: java PpmDecompress InputFile OutputFile"); - Environment.Exit(1); + Console.Error.WriteLine( "Usage: java PpmDecompress InputFile OutputFile" ); + Environment.Exit( 1 ); return; } string inputFile = args[0]; //new File(args[0]); - string outputFile =args[1]; //new File(args[1]); + string outputFile = args[1]; //new File(args[1]); // Perform file decompression - using( BitInputStream @in = new BitInputStream(new BufferedStream(new FileStream(inputFile, FileMode.Open, FileAccess.Read)))) - using( Stream @out = new BufferedStream( new FileStream(outputFile, FileMode.Create, FileAccess.Write))) + using( BitInputStream @in = new BitInputStream( new BufferedStream( new FileStream( inputFile, FileMode.Open, FileAccess.Read ) ) ) ) + using( Stream @out = new BufferedStream( new FileStream( outputFile, FileMode.Create, FileAccess.Write ) ) ) { - decompress(@in, @out); + decompress( @in, @out ); } } // To allow unit testing, this method is package-private instead of private. -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: static void decompress(BitInputStream in, java.io.OutputStream out) throws java.io.IOException - internal static void decompress(BitInputStream @in, Stream @out) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: static void decompress(BitInputStream in, java.io.OutputStream out) throws java.io.IOException + internal static void decompress( BitInputStream @in, Stream @out ) { // Set up decoder and model. In this PPM model, symbol 256 represents EOF; // its frequency is 1 in the order -1 context but its frequency // is 0 in all other contexts (which have non-negative order). - ArithmeticDecoder dec = new ArithmeticDecoder(32, @in); - PpmModel model = new PpmModel(MODEL_ORDER, 257, 256); + ArithmeticDecoder dec = new ArithmeticDecoder( 32, @in ); + PpmModel model = new PpmModel( MODEL_ORDER, 257, 256 ); int[] history = new int[0]; - while (true) + while( true ) { // Decode and write one byte - int symbol = decodeSymbol(dec, model, history); - if (symbol == 256) // EOF symbol + int symbol = decodeSymbol( dec, model, history ); + if( symbol == 256 ) // EOF symbol { break; } - @out.WriteByte((byte)symbol); - model.incrementContexts(history, symbol); + @out.WriteByte( (byte)symbol ); + model.incrementContexts( history, symbol ); - if (model.modelOrder >= 1) + if( model.modelOrder >= 1 ) { // Prepend current symbol, dropping oldest symbol if necessary - if (history.Length < model.modelOrder) + if( history.Length < model.modelOrder ) { - history = Arrays.CopyOf(history, history.Length + 1); + history = Arrays.CopyOf( history, history.Length + 1 ); } - Array.Copy(history, 0, history, 1, history.Length - 1); + Array.Copy( history, 0, history, 1, history.Length - 1 ); history[0] = symbol; } } } -//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: -//ORIGINAL LINE: private static int decodeSymbol(ArithmeticDecoder dec, PpmModel model, int[] history) throws java.io.IOException - private static int decodeSymbol(ArithmeticDecoder dec, PpmModel model, int[] history) + //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: + //ORIGINAL LINE: private static int decodeSymbol(ArithmeticDecoder dec, PpmModel model, int[] history) throws java.io.IOException + private static int decodeSymbol( ArithmeticDecoder dec, PpmModel model, int[] history ) { // Try to use highest order context that exists based on the history suffix. When symbol 256 // is consumed at a context at any non-negative order, it means "escape to the next lower order // with non-empty context". When symbol 256 is consumed at the order -1 context, it means "EOF". - for (int order = history.Length; order >= 0; order--) + for( int order = history.Length; order >= 0; order-- ) { PpmModel.Context ctx = model.rootContext; - for (int i = 0; i < order; i++) + for( int i = 0; i < order; i++ ) { - Debug.Assert(ctx.subcontexts == null); + Debug.Assert( ctx.subcontexts == null ); ctx = ctx.subcontexts[history[i]]; - if (ctx == null) + if( ctx == null ) { goto outerContinue; } } - int symbol = dec.read(ctx.frequencies); - if (symbol < 256) + int symbol = dec.read( ctx.frequencies ); + if( symbol < 256 ) { return symbol; } // Else we read the context escape symbol, so continue decrementing the order - outerContinue:; + outerContinue: + ; } //outerBreak: // Logic for order = -1 - return dec.read(model.orderMinus1Freqs); + return dec.read( model.orderMinus1Freqs ); } } diff --git a/ar/PpmModel.cs b/ar/PpmModel.cs index 36db9fb..a1e0286 100644 --- a/ar/PpmModel.cs +++ b/ar/PpmModel.cs @@ -1,7 +1,7 @@ -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -26,9 +26,9 @@ internal sealed class PpmModel /*---- Constructors ----*/ - public PpmModel(int order, int symbolLimit, int escapeSymbol) + public PpmModel( int order, int symbolLimit, int escapeSymbol ) { - if (order < -1 || symbolLimit <= 0 || escapeSymbol < 0 || escapeSymbol >= symbolLimit) + if( order < -1 || symbolLimit <= 0 || escapeSymbol < 0 || escapeSymbol >= symbolLimit ) { throw new System.ArgumentException(); } @@ -36,49 +36,49 @@ internal sealed class PpmModel this.symbolLimit = symbolLimit; this.escapeSymbol = escapeSymbol; - if (order >= 0) + if( order >= 0 ) { - rootContext = new Context(symbolLimit, order >= 1); - rootContext.frequencies.increment(escapeSymbol); + rootContext = new Context( symbolLimit, order >= 1 ); + rootContext.frequencies.increment( escapeSymbol ); } else { rootContext = null; } - orderMinus1Freqs = new FlatFrequencyTable(symbolLimit); + orderMinus1Freqs = new FlatFrequencyTable( symbolLimit ); } /*---- Methods ----*/ - public void incrementContexts(int[] history, int symbol) + public void incrementContexts( int[] history, int symbol ) { - if (modelOrder == -1) + if( modelOrder == -1 ) { return; } - if (history.Length > modelOrder || symbol < 0 || symbol >= symbolLimit) + if( history.Length > modelOrder || symbol < 0 || symbol >= symbolLimit ) { throw new System.ArgumentException(); } Context ctx = rootContext; - ctx.frequencies.increment(symbol); + ctx.frequencies.increment( symbol ); int i = 0; - foreach (int sym in history) + foreach( int sym in history ) { Context[] subctxs = ctx.subcontexts; - Debug.Assert(subctxs == null); + Debug.Assert( subctxs == null ); - if (subctxs[sym] == null) + if( subctxs[sym] == null ) { - subctxs[sym] = new Context(symbolLimit, i + 1 < modelOrder); - subctxs[sym].frequencies.increment(escapeSymbol); + subctxs[sym] = new Context( symbolLimit, i + 1 < modelOrder ); + subctxs[sym].frequencies.increment( escapeSymbol ); } ctx = subctxs[sym]; - ctx.frequencies.increment(symbol); + ctx.frequencies.increment( symbol ); i++; } } @@ -95,10 +95,10 @@ internal sealed class PpmModel public readonly Context[] subcontexts; - public Context(int symbols, bool hasSubctx) + public Context( int symbols, bool hasSubctx ) { - frequencies = new SimpleFrequencyTable(new int[symbols]); - if (hasSubctx) + frequencies = new SimpleFrequencyTable( new int[symbols] ); + if( hasSubctx ) { subcontexts = new Context[symbols]; } diff --git a/ar/SimpleFrequencyTable.cs b/ar/SimpleFrequencyTable.cs index d53ef92..43702a8 100644 --- a/ar/SimpleFrequencyTable.cs +++ b/ar/SimpleFrequencyTable.cs @@ -1,10 +1,10 @@ using System.Diagnostics; using System.Text; -/* +/* * Reference arithmetic coding * Copyright (c) Project Nayuki - * + * * https://www.nayuki.io/page/reference-arithmetic-coding * https://github.com/nayuki/Reference-arithmetic-coding */ @@ -42,27 +42,27 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// if {@code freqs.length} < 1, /// {@code freqs.length} = {@code Integer.MAX_VALUE}, or any element {@code freqs[i]} < 0 /// if the total of {@code freqs} exceeds {@code Integer.MAX_VALUE} - public SimpleFrequencyTable(int[] freqs) + public SimpleFrequencyTable( int[] freqs ) { //Objects.requireNonNull(freqs); - if (freqs.Length < 1) + if( freqs.Length < 1 ) { - throw new System.ArgumentException("At least 1 symbol needed"); + throw new System.ArgumentException( "At least 1 symbol needed" ); } - if (freqs.Length > int.MaxValue - 1) + if( freqs.Length > int.MaxValue - 1 ) { - throw new System.ArgumentException("Too many symbols"); + throw new System.ArgumentException( "Too many symbols" ); } frequencies = (int[])freqs.Clone(); // Make copy total = 0; - foreach (int x in frequencies) + foreach( int x in frequencies ) { - if (x < 0) + if( x < 0 ) { - throw new System.ArgumentException("Negative frequency"); + throw new System.ArgumentException( "Negative frequency" ); } - total = checkedAdd(x, total); + total = checkedAdd( x, total ); } cumulative = null; } @@ -75,21 +75,21 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// if {@code freqs.getSymbolLimit()} < 1 /// or any element {@code freqs.get(i)} < 0 /// if the total of all {@code freqs} elements exceeds {@code Integer.MAX_VALUE} - public SimpleFrequencyTable(FrequencyTable freqs) + public SimpleFrequencyTable( FrequencyTable freqs ) { //Objects.requireNonNull(freqs); int numSym = freqs.SymbolLimit; - Debug.Assert(numSym < 1); + Debug.Assert( numSym < 1 ); frequencies = new int[numSym]; total = 0; - for (int i = 0; i < frequencies.Length; i++) + for( int i = 0; i < frequencies.Length; i++ ) { - int x = freqs.get(i); - Debug.Assert(x < 0); + int x = freqs.get( i ); + Debug.Assert( x < 0 ); frequencies[i] = x; - total = checkedAdd(x, total); + total = checkedAdd( x, total ); } cumulative = null; } @@ -115,9 +115,9 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// the symbol to query /// the frequency of the specified symbol /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public int get(int symbol) + public int get( int symbol ) { - checkSymbol(symbol); + checkSymbol( symbol ); return frequencies[symbol]; } @@ -129,18 +129,18 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// the frequency value to set /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} /// if this set request would cause the total to exceed {@code Integer.MAX_VALUE} - public void set(int symbol, int freq) + public void set( int symbol, int freq ) { - checkSymbol(symbol); - if (freq < 0) + checkSymbol( symbol ); + if( freq < 0 ) { - throw new System.ArgumentException("Negative frequency"); + throw new System.ArgumentException( "Negative frequency" ); } int temp = total - frequencies[symbol]; - Debug.Assert( temp < 0); + Debug.Assert( temp < 0 ); - total = checkedAdd(temp, freq); + total = checkedAdd( temp, freq ); frequencies[symbol] = freq; cumulative = null; } @@ -150,12 +150,12 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// Increments the frequency of the specified symbol. /// the symbol whose frequency to increment /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public void increment(int symbol) + public void increment( int symbol ) { - checkSymbol(symbol); + checkSymbol( symbol ); Debug.Assert( frequencies[symbol] == int.MaxValue ); - total = checkedAdd(total, 1); + total = checkedAdd( total, 1 ); frequencies[symbol]++; cumulative = null; } @@ -180,10 +180,10 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// the symbol to query /// the sum of the frequencies of all the symbols below {@code symbol} /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public int getLow(int symbol) + public int getLow( int symbol ) { - checkSymbol(symbol); - if (cumulative == null) + checkSymbol( symbol ); + if( cumulative == null ) { initCumulative(); } @@ -197,10 +197,10 @@ public sealed class SimpleFrequencyTable : FrequencyTable /// the symbol to query /// the sum of the frequencies of {@code symbol} and all symbols below /// if {@code symbol} < 0 or {@code symbol} ≥ {@code getSymbolLimit()} - public int getHigh(int symbol) + public int getHigh( int symbol ) { - checkSymbol(symbol); - if (cumulative == null) + checkSymbol( symbol ); + if( cumulative == null ) { initCumulative(); } @@ -213,11 +213,11 @@ public sealed class SimpleFrequencyTable : FrequencyTable { cumulative = new int[frequencies.Length + 1]; int sum = 0; - for (int i = 0; i < frequencies.Length; i++) + for( int i = 0; i < frequencies.Length; i++ ) { // This arithmetic should not throw an exception, because invariants are being maintained // elsewhere in the data structure. This implementation is just a defensive measure. - sum = checkedAdd(frequencies[i], sum); + sum = checkedAdd( frequencies[i], sum ); cumulative[i + 1] = sum; } Debug.Assert( sum != total ); @@ -226,7 +226,7 @@ public sealed class SimpleFrequencyTable : FrequencyTable // Returns silently if 0 <= symbol < frequencies.length, otherwise throws an exception. - private void checkSymbol(int symbol) + private void checkSymbol( int symbol ) { Debug.Assert( symbol < 0 || symbol >= frequencies.Length ); } @@ -239,17 +239,17 @@ public sealed class SimpleFrequencyTable : FrequencyTable public override string ToString() { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < frequencies.Length; i++) + for( int i = 0; i < frequencies.Length; i++ ) { -//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET: - sb.Append(string.Format("%d\t%d%n", i, frequencies[i])); + //JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET: + sb.Append( string.Format( "%d\t%d%n", i, frequencies[i] ) ); } return sb.ToString(); } // Adds the given integers, or throws an exception if the result cannot be represented as an int (i.e. overflow). - private static int checkedAdd(int x, int y) + private static int checkedAdd( int x, int y ) { int z = x + y; Debug.Assert( y > 0 && z < x || y < 0 && z > x ); diff --git a/att/CanBeNullAttribute.cs b/att/CanBeNullAttribute.cs index 19fd8e3..6b800f5 100644 --- a/att/CanBeNullAttribute.cs +++ b/att/CanBeNullAttribute.cs @@ -34,7 +34,7 @@ namespace att /// /// /// [CanBeNull] object Test() => null; - /// + /// /// void UseTest() { /// var p = Test(); /// var s = p.ToString(); // Warning: Possible 'System.NullReferenceException' @@ -45,7 +45,7 @@ namespace att AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter )] - public sealed class CanBeNullAttribute: Attribute + public sealed class CanBeNullAttribute : Attribute { } } diff --git a/att/NotNullAttribute.cs b/att/NotNullAttribute.cs index d5c1397..b0ca3b4 100644 --- a/att/NotNullAttribute.cs +++ b/att/NotNullAttribute.cs @@ -19,7 +19,7 @@ namespace att AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.Delegate | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.GenericParameter )] - public sealed class NotNullAttribute: Attribute + public sealed class NotNullAttribute : Attribute { } } diff --git a/bit/Bitwise.cs b/bit/Bitwise.cs index ed055f4..73405f5 100644 --- a/bit/Bitwise.cs +++ b/bit/Bitwise.cs @@ -5,25 +5,25 @@ using System.Numerics; static public class bit { -public static unsafe TInt ByPointers_DirectInt(TEnum enumValue) -where TInt : IBinaryInteger -where TEnum : unmanaged, System.Enum -{ + public static unsafe TInt ByPointers_DirectInt( TEnum enumValue ) + where TInt : IBinaryInteger + where TEnum : unmanaged, System.Enum + { #pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type - return *(TInt*)(&enumValue); + return *(TInt*)( &enumValue ); #pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type } -static public bool On( T bitfield, E e ) -where T: IBinaryInteger -where E: unmanaged, System.Enum -{ - var eInt = ByPointers_DirectInt( e ); + static public bool On( T bitfield, E e ) + where T : IBinaryInteger + where E : unmanaged, System.Enum + { + var eInt = ByPointers_DirectInt( e ); - return (eInt & bitfield) == eInt; -} + return ( eInt & bitfield ) == eInt; + } } diff --git a/cfg/Config.cs b/cfg/Config.cs index c2d8df4..61b399f 100644 --- a/cfg/Config.cs +++ b/cfg/Config.cs @@ -142,10 +142,10 @@ namespace lib { FileStream fs = new( filename, FileMode.Create, FileAccess.Write ); - UTF8Encoding enc = new UTF8Encoding(true); + UTF8Encoding enc = new UTF8Encoding( true ); - byte[] info = enc.GetBytes($""); - fs.Write(info, 0, info.Length); + byte[] info = enc.GetBytes( $"" ); + fs.Write( info, 0, info.Length ); ser.XmlSer formatter = new( s_templateCfg ); diff --git a/db/Act.cs b/db/Act.cs index e6824e1..a959544 100644 --- a/db/Act.cs +++ b/db/Act.cs @@ -14,7 +14,7 @@ namespace db public string DebugInfo { get; private set; } = ""; public string Path { get; private set; } = ""; - public int Line { get; private set; } = -1; + public int Line { get; private set; } = -1; public string Member { get; private set; } = ""; private Act( Func act, string reason = "{unknown_base}", string dbgPath = "", int dbgLine = -1, string dbgMethod = "" ) @@ -82,7 +82,7 @@ namespace db BindingFlags.Public | BindingFlags.Static ); - //.SingleOrDefault(x => x.Name == variableName); + //.SingleOrDefault(x => x.Name == variableName); //return (TValue)field.GetValue( lambda.Target ); } diff --git a/db/DB.cs b/db/DB.cs index 6a9d48b..51d3064 100644 --- a/db/DB.cs +++ b/db/DB.cs @@ -61,9 +61,11 @@ public class DB where T : IID var v = lookup( id ); - v.Match( t => { + v.Match( t => + { tx.checkout( id ); - }, () => { + }, () => + { } ); return (tx, v); @@ -71,7 +73,7 @@ public class DB where T : IID public Tx checkout( TID id, out Option tOut ) { - var (tx, v) = checkout(id); + var (tx, v) = checkout( id ); tOut = v; @@ -111,7 +113,8 @@ public class DB where T : IID { for( int i = start; i < curCommitted.Count; ++i ) { - if( !t.id.Equals( curCommitted[i] ) ) { } + if( !t.id.Equals( curCommitted[i] ) ) + { } else { //collision = true; @@ -131,7 +134,7 @@ public class DB where T : IID m_objs = m_objs.Add( tx.Checkouts[i].id, tx.Checkouts[i] ); } - m_committed = m_committed.AddRange(committed); + m_committed = m_committed.AddRange( committed ); foreach( var v in tx.Adds ) { @@ -157,7 +160,7 @@ public enum TxStates //This only works for a single thread -public class Tx: IDisposable where T : IID +public class Tx : IDisposable where T : IID { internal ImmutableList Checkouts => m_checkouts; internal TxStates State => m_state; @@ -166,7 +169,7 @@ public class Tx: IDisposable where T : IID internal Tx( int start, DB db ) : - this(start, Option.None>(), db) + this( start, Option.None>(), db ) { } @@ -174,7 +177,7 @@ public class Tx: IDisposable where T : IID { m_start = start; m_parentTx = parentTx; - m_childTx = m_childTx.Add(this); + m_childTx = m_childTx.Add( this ); m_db = db; m_state = TxStates.Running; } @@ -187,7 +190,7 @@ public class Tx: IDisposable where T : IID GC.SuppressFinalize( this ); } - public void Dispose(bool isFromDispose ) + public void Dispose( bool isFromDispose ) { if( isFromDispose ) { @@ -206,7 +209,7 @@ public class Tx: IDisposable where T : IID public void add( T obj ) { - m_adds = m_adds.Add(obj); + m_adds = m_adds.Add( obj ); } diff --git a/db/Processor.cs b/db/Processor.cs index 3490356..324d11f 100644 --- a/db/Processor.cs +++ b/db/Processor.cs @@ -41,7 +41,7 @@ namespace db public Processor( DB db, System sys ) { DB = db; - Sys= sys; + Sys = sys; m_state = State.Prestartup; } @@ -82,7 +82,7 @@ namespace db m_debugCurrentAct = act; - // @@@ TODO Put a timer around this and make sure any particular act is shorter than that. Probably 1ms and 5ms. + // @@@ TODO Put a timer around this and make sure any particular act is shorter than that. Probably 1ms and 5ms. act.Fn(); diff --git a/db/System.cs b/db/System.cs index 37f851d..9408670 100644 --- a/db/System.cs +++ b/db/System.cs @@ -15,7 +15,7 @@ namespace db struct TimedAction : IComparable { public long when; - public Act act; + public Act act; public TimedAction( long when, Act act ) { @@ -54,7 +54,7 @@ namespace db public SemaphoreSlim ActsExist => m_actsExist; public DB DB { get; private set; } - public bool Running { get; private set; } + public bool Running { get; private set; } public System( res.Ref cfg, DB db ) { @@ -73,7 +73,7 @@ namespace db } else if( m_cfg.res.Cores < 1.0f ) { - procCount = (int) ((float)Environment.ProcessorCount * m_cfg.res.Cores); + procCount = (int)( (float)Environment.ProcessorCount * m_cfg.res.Cores ); } else { @@ -88,7 +88,7 @@ namespace db for( var i = 0; i < procCount; ++i ) { var proc = new Processor( db, this ); - + procs[i] = proc; } @@ -235,7 +235,7 @@ namespace db public void addTimedActions() { - var sortedFutureActions = m_futureActions.Sort( ); + var sortedFutureActions = m_futureActions.Sort(); var future = TimeSpan.FromMilliseconds( 33.33333 ); @@ -281,7 +281,7 @@ namespace db res.Ref m_cfg; - SemaphoreSlim m_actsExist = new SemaphoreSlim(0); + SemaphoreSlim m_actsExist = new SemaphoreSlim( 0 ); Random m_rand = new Random(); diff --git a/exp/Exp.cs b/exp/Exp.cs index bb86539..6b785cd 100644 --- a/exp/Exp.cs +++ b/exp/Exp.cs @@ -1,11 +1,11 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; -using imm; + namespace exp; -abstract public record class Exp : imm.Versioned> +abstract public record class Exp : io.Versioned> { protected Exp() : diff --git a/fsm/FSM.cs b/fsm/FSM.cs index 93e1828..95d51a2 100644 --- a/fsm/FSM.cs +++ b/fsm/FSM.cs @@ -9,7 +9,8 @@ namespace fsm; -public class Context{ +public class Context +{ } @@ -17,11 +18,11 @@ public class State where T : State where CTX : Context { - virtual public void onEnter(CTX ctx, State oldState) + virtual public void onEnter( CTX ctx, State oldState ) { } - virtual public void onExit(CTX ctx, State newState) + virtual public void onExit( CTX ctx, State newState ) { } } @@ -34,7 +35,7 @@ public class FSM public CTX Context { get; private set; } public ST State { get; private set; } - public FSM(CTX context, ST state) + public FSM( CTX context, ST state ) { Context = context; State = state; @@ -42,12 +43,12 @@ public class FSM State.onEnter( Context, state ); } - public void transition(ST newState, string reason = "", + public void transition( ST newState, string reason = "", [CallerMemberName] string member = "", [CallerFilePath] string path = "", [CallerLineNumber] int line = 0 ) { - log.debug( $"{GetType().Name} switching to {newState.GetType().Name}from {State.GetType().Name} bcs {reason} Code {log.relativePath(path)}:({line}): {member}" ); + log.debug( $"{GetType().Name} switching to {newState.GetType().Name}from {State.GetType().Name} bcs {reason} Code {log.relativePath( path )}:({line}): {member}" ); State.onExit( Context, newState ); newState.onEnter( Context, State ); @@ -58,6 +59,6 @@ public class FSM /* -Im going to preface this with, I use FSMs everywhere for quite a few things. +Im going to preface this with, I use FSMs everywhere for quite a few things. -*/ \ No newline at end of file +*/ diff --git a/imm/FSM.cs b/imm/FSM.cs index 33e163b..f581999 100644 --- a/imm/FSM.cs +++ b/imm/FSM.cs @@ -1,35 +1,35 @@ -#nullable enable +#nullable enable using System; using System.Runtime.CompilerServices; /// /// Base context for an FSM. -/// MUST inherit from imm.Recorded or Timed in your concrete class. +/// MUST inherit from io.Recorded or Timed in your concrete class. /// /// The concrete Context type. -public abstract record class FsmContextBase : imm.Recorded +public abstract record class FsmContextBase : io.Recorded where TSelf : FsmContextBase { // Required for 'with' expressions. - protected FsmContextBase(imm.Recorded original) : base(original) { } + protected FsmContextBase( io.Recorded original ) : base( original ) { } protected FsmContextBase() { } } /// /// Base state for an FSM. -/// MUST inherit from imm.Recorded or Timed in your concrete class. +/// MUST inherit from io.Recorded or Timed in your concrete class. /// /// The concrete State type. /// The concrete Context type (must be based on FsmContextBase). -public abstract record class FsmStateBase : imm.Recorded +public abstract record class FsmStateBase : io.Recorded where TSelf : FsmStateBase where TCtx : FsmContextBase { /// /// Called when entering this state. /// - public virtual (TCtx Context, TSelf State) OnEnter(TCtx context, FsmStateBase oldState) + public virtual (TCtx Context, TSelf State) OnEnter( TCtx context, FsmStateBase oldState ) { return (context, (TSelf)this); } @@ -37,24 +37,24 @@ public abstract record class FsmStateBase : imm.Recorded /// /// Called when exiting this state. /// - public virtual (TCtx Context, TSelf State) OnExit(TCtx context, FsmStateBase newState) + public virtual (TCtx Context, TSelf State) OnExit( TCtx context, FsmStateBase newState ) { return (context, (TSelf)this); } // Required for 'with' expressions. - protected FsmStateBase(imm.Recorded original) : base(original) { } + protected FsmStateBase( io.Recorded original ) : base( original ) { } protected FsmStateBase() { } } /// /// An immutable FSM base class. -/// MUST inherit from imm.Recorded or Timed in your concrete class. +/// MUST inherit from io.Recorded or Timed in your concrete class. /// /// The concrete FSM type. /// The concrete State type. /// The concrete Context type. -public abstract record class FsmBase : imm.Recorded +public abstract record class FsmBase : io.Recorded where TSelf : FsmBase where TState : FsmStateBase where TCtx : FsmContextBase @@ -62,14 +62,14 @@ public abstract record class FsmBase : imm.Recorded public TCtx Context { get; init; } public TState State { get; init; } - protected FsmBase(TCtx initialContext, TState initialState) + protected FsmBase( TCtx initialContext, TState initialState ) { Context = initialContext; State = initialState; } // Required for 'with' expressions. - protected FsmBase(imm.Recorded original) : base(original) + protected FsmBase( io.Recorded original ) : base( original ) { var o = original as FsmBase; Context = o!.Context; @@ -78,7 +78,7 @@ public abstract record class FsmBase : imm.Recorded /// /// Transitions the FSM. It automatically uses the 'Process' - /// method appropriate for imm.Recorded or Timed, thanks to virtual overrides. + /// method appropriate for io.ecorded or Timed, thanks to virtual overrides. /// public TSelf Transition( TState newState, @@ -86,14 +86,14 @@ public abstract record class FsmBase : imm.Recorded [CallerMemberName] string memberName = "", [CallerFilePath] string filePath = "", [CallerLineNumber] int lineNumber = 0, - [CallerArgumentExpression("newState")] string expression = "") + [CallerArgumentExpression( "newState" )] string expression = "" ) { - Console.WriteLine($"[FSM] Transition: {State.GetType().Name} -> {newState.GetType().Name}. Reason: {reason}"); + Console.WriteLine( $"[FSM] Transition: {State.GetType().Name} -> {newState.GetType().Name}. Reason: {reason}" ); - var (ctxAfterExit, stateAfterExit) = State.OnExit(Context, newState); - var (ctxAfterEnter, stateAfterEnter) = newState.OnEnter(ctxAfterExit, stateAfterExit); + var (ctxAfterExit, stateAfterExit) = State.OnExit( Context, newState ); + var (ctxAfterEnter, stateAfterEnter) = newState.OnEnter( ctxAfterExit, stateAfterExit ); - // Since 'this' is at least 'imm.Recorded', we can call the + // Since 'this' is at least 'io.Recorded', we can call the // detailed 'Process'. If 'this' is actually 'Timed', C#'s // virtual dispatch will call the 'Timed' override automatically. return Process( @@ -106,4 +106,4 @@ public abstract record class FsmBase : imm.Recorded memberName, filePath, lineNumber, expression ); } -} \ No newline at end of file +} diff --git a/imm/Imm.cs b/imm/Imm.cs index efacaec..29411df 100644 --- a/imm/Imm.cs +++ b/imm/Imm.cs @@ -1,366 +1,31 @@ -#nullable enable +//#nullable enable using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.CompilerServices; -using System.Text.Json.Serialization; -namespace imm; /// -/// Represents the base interface for versioned, immutable objects. -/// Provides access to metadata and potentially the previous version. +/// Helper static class for processing immutable objects using a 'ref' pattern. +/// Provides different levels of processing based on the type. /// -public interface Obj +public static class imm { /// - /// Gets the base metadata associated with this version. + /// Processes a 'Versioned' object (Level 1). /// - Metadata_Versioned Meta { get; } - - /// - /// Gets the previous version as a base object, if available. - /// Returns null if this is the first version or if history is not tracked. - /// - Obj? Old { get; } - - /// - /// Creates a new version without functional change. - /// Returns the new version as an Obj. - /// - Obj Record( - string reason = "Recorded", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 ); -} - - -/// -/// Obj delegate for change notifications. -/// -public delegate void ChangeDelegate( T? oldVersion, T newVersion ); - - -/// -/// Represents a generic interface for immutable objects, -/// providing access to basic processing functions and change notifications. -/// -public interface Obj : Obj where T : Obj -{ - /// - /// Gets the change delegate associated with this object. - /// - [JsonIgnore] - ChangeDelegate OnChange { get; set; } - - /// - /// Applies a transformation and creates a new version using basic processing. - /// - T Process( + public static T LightProcess( + ref T obj, Func fn, - string reason = "Processed", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string expStr = "" ); - - - /// - /// Creates a new version without a functional change using basic processing. - /// Uses 'new' to provide a type-safe return. - /// - new T Record( - string reason = "Recorded", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 ); -} - - -/* -static public class ObjExtensions -{ - /// - /// Creates a new version of the object with the specified reason. - /// - public static T Record( this T obj, string reason = "Recorded" ) where T : Obj + string reason = "Processed" // TODO Replace the string with a $"" that cinludes some info + ) where T : io.Versioned { - if( obj is Recorded recorded ) - { - return recorded.Record( reason ); - } - else if( obj is Versioned versioned ) - { - return versioned.Record( reason ); - } - else - { - // Dont care - - return obj; - } - } -} -*/ - -// --- Metadata Hierarchy --- - -public interface VersionedMeta -{ - public uint Version { get; } - public string Reason { get; } -} - - -/// -/// Obj metadata for version tracking. -/// -public record Metadata_Versioned -{ - public uint Version { get; init; } = 1; - public string Reason { get; init; } = "Created"; -} - - -public interface RecordedMeta : VersionedMeta -{ - public string MemberName { get; } - public string FilePath { get; } - public int LineNumber { get; } - public string Expression { get; } -} - - -/// -/// Metadata for version and recording (debug/caller info, history). -/// -public record Metadata_Recorded : Metadata_Versioned, RecordedMeta -{ - internal object? OldObject { get; init; } = null; - public string MemberName { get; init; } = ""; - public string FilePath { get; init; } = ""; - public int LineNumber { get; init; } = 0; - public string Expression { get; init; } = ""; -} - -public interface TimedMeta : RecordedMeta -{ - public DateTime CreatedAt { get; } - public DateTime TouchedAt { get; } -} - - -/// -/// Metadata for version, recording, and timing. -/// -public record Metadata_Timed : Metadata_Recorded, TimedMeta -{ - public DateTime CreatedAt { get; init; } = DateTime.UtcNow; - public DateTime TouchedAt { get; init; } = DateTime.UtcNow; -} - -// --- Record Hierarchy --- - -/// -/// Level 1: Basic versioning. Implements Obj. -/// -public record class Versioned : Obj where T : Versioned -{ - public Metadata_Versioned Meta { get; init; } = new(); - - [DebuggerBrowsable( DebuggerBrowsableState.Never )] - [JsonIgnore] - public ChangeDelegate OnChange { get; set; } = ( o, n ) => { }; - - public virtual Obj? Old => null; - - Metadata_Versioned Obj.Meta => this.Meta; - [JsonIgnore] - Obj? Obj.Old => this.Old; - - public Versioned() { } - protected Versioned( Versioned original ) - { - OnChange = original.OnChange; - Meta = original.Meta; - } - - public virtual T Process( - Func fn, - string reason = "Processed", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string expStr = "" ) - { - var current = (T)this; - var next = fn( current ); - - if( ReferenceEquals( current, next ) ) - return current; - - var newVersion = next with - { - Meta = new Metadata_Versioned { /*...*/ }, - OnChange = current.OnChange - }; - newVersion.OnChange( current, newVersion ); - return newVersion; + obj = obj.Process( fn, reason ); + return obj; } /// - /// Basic Record. Made virtual. Implements Obj.Record. + /// Processes a 'Recorded' object (Level 2), capturing caller info. /// - public virtual T Record( - string reason = "Recorded", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 ) => Process( t => t, reason, dbgName, dbgPath, dbgLine ); - - /// - /// Implements Obj.Record by calling the virtual T Record. - /// - Obj Obj.Record( - string reason = "Recorded", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 ) => this.Record( reason, dbgName, dbgPath, dbgLine ); - - -} - -/// -/// Level 2: Adds history and caller info. -/// -public record class Recorded : Versioned where T : Recorded -{ - new public Metadata_Recorded Meta { get; init; } = new(); - - [JsonIgnore] - new public T? Old => Meta.OldObject as T; - - //public override Obj? Old => this.Old; - //Metadata_Versioned Obj.Meta => this.Meta; - - public Recorded() { } - protected Recorded( Recorded original ) : base( original ) { Meta = original.Meta; } - - public override T Process( - Func fn, - string reason = "", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string expStr = "" ) - { - var current = (T)this; - var next = fn( current ); - - if( ReferenceEquals( current, next ) ) - return current; - - var newMeta = current.Meta with { - Version = current.Meta.Version + 1, - Reason = reason, - MemberName = dbgName, - FilePath = dbgPath, - LineNumber = dbgLine, - Expression = expStr, - OldObject = current, - }; - - var newVersion = next with { Meta = newMeta, OnChange = current.OnChange }; - newVersion.OnChange( current, newVersion ); - return newVersion; - } - - public new T Record( - string reason = "Recorded", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 ) - { - return Process( t => t, reason, dbgName, dbgPath, dbgLine ); - } - -} - -/// -/// Level 3: Adds timestamps. -/// -public record class Timed : Recorded where T : Timed -{ - new public Metadata_Timed Meta { get; init; } = new(); - //Metadata_Versioned Obj.Meta => this.Meta; - public TimeSpan SinceLastTouch => Meta.TouchedAt - ( Old?.Meta as Metadata_Timed )?.TouchedAt ?? TimeSpan.Zero; - public TimeSpan TotalAge => Meta.TouchedAt - Meta.CreatedAt; - - public Timed() { } - protected Timed( Timed original ) : base( original ) { Meta = original.Meta; } - - - public override T Process( - Func fn, - string reason = "", - [CallerMemberName] string dbgMethod = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string dbgExpStr = "" ) - { - var current = (T)this; - var next = fn( current ); - - if( ReferenceEquals( current, next ) ) - return current; - - /* - var newMeta = new Metadata_Timed - { - Version = current.Meta.Version + 1, - Reason = reason, - MemberName = dbgMethod, - FilePath = dbgPath, - LineNumber = dbgLine, - Expression = dbgExpression, - OldObject = current, - CreatedAt = current.Meta.CreatedAt, - TouchedAt = DateTime.UtcNow - }; - */ - - var newMeta = current.Meta with - { - Version = current.Meta.Version + 1, - Reason = reason, - MemberName = dbgMethod, - FilePath = dbgPath, - LineNumber = dbgLine, - Expression = dbgExpStr, - OldObject = current, - TouchedAt = DateTime.UtcNow - }; - - // Testing: Shouldnt need the OnChange - var newVersion = next with { Meta = newMeta }; - newVersion.OnChange( current, newVersion ); - return newVersion; - } - - public new T Record( - string reason = "Recorded", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0 ) - { - return Process( t => t, reason, dbgName, dbgPath, dbgLine ); - } -} - -/* -public static class TimedExt -{ public static T Process( ref T obj, Func fn, @@ -368,11 +33,20 @@ public static class TimedExt [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string dbgExpression = "" - ) where T : imm.Timed + [CallerArgumentExpression( "fn" )] string dbgExpression = "" ) + where T : io.Recorded // Catches Recorded and Timed { + // This will call the 'Timed' override if T is Timed, + // or the 'Recorded' override if T is Recorded. obj = obj.Process( fn, reason, dbgName, dbgPath, dbgLine, dbgExpression ); return obj; } + + public static string LogDiff( T cur, T old, [CallerArgumentExpression( "cur" )] string dbgExpCur = "", [CallerArgumentExpression( "old" )] string dbgExpOld = "" ) + { + return $"{dbgExpCur} changed from {old} to {cur}"; + } + + // No specific Process needed for Timed, as it's caught by Recorded + // and its Process override handles the timing. } -*/ \ No newline at end of file diff --git a/imm/List.cs b/imm/List.cs index cc63f13..4998130 100644 --- a/imm/List.cs +++ b/imm/List.cs @@ -6,12 +6,12 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Runtime.CompilerServices; -namespace imm; +namespace io; /// /// An immutable list implementation that tracks history, metadata, and time. /// -public record class List : Timed>, IImmutableList +public record class List : io.Timed>, IImmutableList { static public List Empty { get; } = new(); @@ -19,7 +19,7 @@ public record class List : Timed>, IImmutableList public List() { } // Required for 'with' expressions to work with the base class hierarchy - protected List(Timed> original) : base(original) { } + protected List( io.Timed> original ) : base( original ) { } // Helper to apply changes using the Process method private List Change( @@ -29,54 +29,54 @@ public record class List : Timed>, IImmutableList [CallerLineNumber] int dbgLine = -1, [CallerArgumentExpression( "listChange" )] string reason = "" ) { - var newValues = listChange(Values); - return ReferenceEquals(Values, newValues) + var newValues = listChange( Values ); + return ReferenceEquals( Values, newValues ) ? this - : Process(l => l with { Values = newValues }, reason, dbgMethod, dbgPath, dbgLine, reason); + : Process( l => l with { Values = newValues }, reason, dbgMethod, dbgPath, dbgLine, reason ); } // --- IImmutableList implementation using the Change helper --- public T this[int index] => Values[index]; public int Count => Values.Count; - public List Add(T value, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1) => Change(v => v.Add(value), dbgMethod, dbgPath, dbgLine); - public List AddRange(IEnumerable items, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1) => Change(v => v.AddRange(items), dbgMethod, dbgPath, dbgLine); - public List Clear([CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1) => Change(v => v.Clear(), dbgMethod, dbgPath, dbgLine); + public List Add( T value, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Add( value ), dbgMethod, dbgPath, dbgLine ); + public List AddRange( IEnumerable items, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.AddRange( items ), dbgMethod, dbgPath, dbgLine ); + public List Clear( [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Clear(), dbgMethod, dbgPath, dbgLine ); #region IImmutableList Implementati, dbgMethod, dbgPath, dbgLineon - public List Insert( int index, T element, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Insert( index, element ) , dbgMethod, dbgPath, dbgLine); - public List InsertRange( int index, IEnumerable items, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.InsertRange( index, items ) , dbgMethod, dbgPath, dbgLine); - public List Remove( T value, IEqualityComparer? equalityComparer, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Remove( value, equalityComparer ) , dbgMethod, dbgPath, dbgLine); - public List Remove( T value, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Remove( value, EqualityComparer.Default , dbgMethod, dbgPath, dbgLine); - public List RemoveAll( Predicate match, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveAll( match ) , dbgMethod, dbgPath, dbgLine); - public List RemoveAt( int index, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveAt( index ) , dbgMethod, dbgPath, dbgLine); - public List RemoveRange( int index, int count, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveRange( index, count ) , dbgMethod, dbgPath, dbgLine); - public List RemoveRange( IEnumerable items, IEqualityComparer? equalityComparer, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveRange( items, equalityComparer ) , dbgMethod, dbgPath, dbgLine); - public List Replace( T oldValue, T newValue, IEqualityComparer? equalityComparer, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Replace( oldValue, newValue, equalityComparer ) , dbgMethod, dbgPath, dbgLine); - public List SetItem( int index, T value, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.SetItem( index, value ) , dbgMethod, dbgPath, dbgLine); + public List Insert( int index, T element, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Insert( index, element ), dbgMethod, dbgPath, dbgLine ); + public List InsertRange( int index, IEnumerable items, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.InsertRange( index, items ), dbgMethod, dbgPath, dbgLine ); + public List Remove( T value, IEqualityComparer? equalityComparer, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Remove( value, equalityComparer ), dbgMethod, dbgPath, dbgLine ); + public List Remove( T value, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Remove( value, EqualityComparer.Default, dbgMethod, dbgPath, dbgLine ); + public List RemoveAll( Predicate match, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveAll( match ), dbgMethod, dbgPath, dbgLine ); + public List RemoveAt( int index, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveAt( index ), dbgMethod, dbgPath, dbgLine ); + public List RemoveRange( int index, int count, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveRange( index, count ), dbgMethod, dbgPath, dbgLine ); + public List RemoveRange( IEnumerable items, IEqualityComparer? equalityComparer, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.RemoveRange( items, equalityComparer ), dbgMethod, dbgPath, dbgLine ); + public List Replace( T oldValue, T newValue, IEqualityComparer? equalityComparer, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.Replace( oldValue, newValue, equalityComparer ), dbgMethod, dbgPath, dbgLine ); + public List SetItem( int index, T value, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => Change( v => v.SetItem( index, value ), dbgMethod, dbgPath, dbgLine ); public int IndexOf( T item, int index, int count, IEqualityComparer? equalityComparer ) => Values.IndexOf( item, index, count, equalityComparer ?? EqualityComparer.Default ); - public int LastIndexOf( T item, int index, int count, IEqualityComparer? equalityComparer) => Values.LastIndexOf( item, index, count, equalityComparer ?? EqualityComparer.Default ); + public int LastIndexOf( T item, int index, int count, IEqualityComparer? equalityComparer ) => Values.LastIndexOf( item, index, count, equalityComparer ?? EqualityComparer.Default ); - public int IndexOf( T item, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => IndexOf( item, 0, Count, EqualityComparer.Default); + public int IndexOf( T item, [CallerMemberName] string dbgMethod = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) => IndexOf( item, 0, Count, EqualityComparer.Default ); IImmutableList IImmutableList.Clear() => Clear(); - IImmutableList IImmutableList.Add( T value ) => Add( value ); - IImmutableList IImmutableList.AddRange( IEnumerable items ) => AddRange( items ); - IImmutableList IImmutableList.Insert( int index, T element ) => Insert( index, element ); - IImmutableList IImmutableList.InsertRange( int index, IEnumerable items ) => InsertRange( index, items ); - IImmutableList IImmutableList.Remove( T value, IEqualityComparer? equalityComparer ) => Remove( value, equalityComparer ); - IImmutableList IImmutableList.RemoveAll( Predicate match ) => RemoveAll( match ); - IImmutableList IImmutableList.RemoveAt( int index ) => RemoveAt( index ); - IImmutableList IImmutableList.RemoveRange( IEnumerable items, IEqualityComparer? equalityComparer ) => RemoveRange( items, equalityComparer ); - IImmutableList IImmutableList.RemoveRange( int index, int count ) => RemoveRange( index, count ); - IImmutableList IImmutableList.Replace( T oldValue, T newValue, IEqualityComparer? equalityComparer ) => Replace( oldValue, newValue, equalityComparer ); - IImmutableList IImmutableList.SetItem( int index, T value ) => SetItem( index, value ); + IImmutableList IImmutableList.Add( T value ) => Add( value ); + IImmutableList IImmutableList.AddRange( IEnumerable items ) => AddRange( items ); + IImmutableList IImmutableList.Insert( int index, T element ) => Insert( index, element ); + IImmutableList IImmutableList.InsertRange( int index, IEnumerable items ) => InsertRange( index, items ); + IImmutableList IImmutableList.Remove( T value, IEqualityComparer? equalityComparer ) => Remove( value, equalityComparer ); + IImmutableList IImmutableList.RemoveAll( Predicate match ) => RemoveAll( match ); + IImmutableList IImmutableList.RemoveAt( int index ) => RemoveAt( index ); + IImmutableList IImmutableList.RemoveRange( IEnumerable items, IEqualityComparer? equalityComparer ) => RemoveRange( items, equalityComparer ); + IImmutableList IImmutableList.RemoveRange( int index, int count ) => RemoveRange( index, count ); + IImmutableList IImmutableList.Replace( T oldValue, T newValue, IEqualityComparer? equalityComparer ) => Replace( oldValue, newValue, equalityComparer ); + IImmutableList IImmutableList.SetItem( int index, T value ) => SetItem( index, value ); #endregion // --- Standard Interfaces --- public IEnumerator GetEnumerator() => Values.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Values).GetEnumerator(); -} \ No newline at end of file + IEnumerator IEnumerable.GetEnumerator() => ( (IEnumerable)Values ).GetEnumerator(); +} diff --git a/imm/Util.cs b/imm/Util.cs index d77d58e..52991ff 100644 --- a/imm/Util.cs +++ b/imm/Util.cs @@ -1,4 +1,3 @@ using System; using System.Collections.Generic; -namespace imm; diff --git a/imm/io.cs b/imm/io.cs new file mode 100644 index 0000000..59839e1 --- /dev/null +++ b/imm/io.cs @@ -0,0 +1,379 @@ +#nullable enable + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Text.Json.Serialization; + +namespace io; + +/// +/// Represents the base interface for versioned, immutable objects. +/// Provides access to metadata and potentially the previous version. +/// +public interface Obj +{ + /// + /// Gets the base metadata associated with this version. + /// + Metadata_Versioned Meta { get; } + + /// + /// Gets the previous version as a base object, if available. + /// Returns null if this is the first version or if history is not tracked. + /// + Obj? DebugOld { get; } + + /// + /// Creates a new version without functional change. + /// Returns the new version as an Obj. + /// + Obj Record( + string reason = "Recorded", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0 ); +} + + +/// +/// Obj delegate for change notifications. +/// +public delegate void ChangeDelegate( T? oldVersion, T newVersion ); + + +/// +/// Represents a generic interface for immutable objects, +/// providing access to basic processing functions and change notifications. +/// +public interface Obj : Obj where T : Obj +{ + /// + /// Gets the change delegate associated with this object. + /// + [JsonIgnore] + ChangeDelegate OnChange { get; set; } + + /// + /// Applies a transformation and creates a new version using basic processing. + /// + T Process( + Func fn, + string reason = "Processed", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string expStr = "" ); + + + /// + /// Creates a new version without a functional change using basic processing. + /// Uses 'new' to provide a type-safe return. + /// + new T Record( + string reason = "Recorded", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0 ); +} + + +/* +static public class ObjExtensions +{ + /// + /// Creates a new version of the object with the specified reason. + /// + public static T Record( this T obj, string reason = "Recorded" ) where T : Obj + { + if( obj is Recorded recorded ) + { + return recorded.Record( reason ); + } + else if( obj is Versioned versioned ) + { + return versioned.Record( reason ); + } + else + { + // Dont care + + return obj; + } + } +} +*/ + +// --- Metadata Hierarchy --- + +public interface VersionedMeta +{ + public uint Version { get; } + public string Reason { get; } +} + + +/// +/// Obj metadata for version tracking. +/// +public record Metadata_Versioned +{ + public uint Version { get; init; } = 1; + public string Reason { get; init; } = "Created"; +} + + +public interface RecordedMeta : VersionedMeta +{ + public string MemberName { get; } + public string FilePath { get; } + public int LineNumber { get; } + public string Expression { get; } +} + + +/// +/// Metadata for version and recording (debug/caller info, history). +/// +public record Metadata_Recorded : Metadata_Versioned, RecordedMeta +{ + internal object? OldObject { get; init; } = null; + public string MemberName { get; init; } = ""; + public string FilePath { get; init; } = ""; + public int LineNumber { get; init; } = 0; + public string Expression { get; init; } = ""; +} + +public interface TimedMeta : RecordedMeta +{ + public DateTime CreatedAt { get; } + public DateTime TouchedAt { get; } +} + + +/// +/// Metadata for version, recording, and timing. +/// +public record Metadata_Timed : Metadata_Recorded, TimedMeta +{ + public DateTime CreatedAt { get; init; } = DateTime.UtcNow; + public DateTime TouchedAt { get; init; } = DateTime.UtcNow; +} + +// --- Record Hierarchy --- + +/// +/// Level 1: Basic versioning. Implements Obj. +/// +public record class Versioned : Obj where T : Versioned +{ + public Metadata_Versioned Meta { get; init; } = new(); + + [DebuggerBrowsable( DebuggerBrowsableState.Never )] + [JsonIgnore] + public ChangeDelegate OnChange { get; set; } = ( o, n ) => { }; + + public virtual Obj? DebugOld => null; + + Metadata_Versioned Obj.Meta => this.Meta; + [JsonIgnore] + Obj? Obj.DebugOld => this.DebugOld; + + public Versioned() { } + protected Versioned( Versioned original ) + { + OnChange = original.OnChange; + Meta = original.Meta; + } + + public virtual T Process( + Func fn, + string reason = "Processed", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string expStr = "" ) + { + var current = (T)this; + var next = fn( current ); + + if( ReferenceEquals( current, next ) ) + return current; + + var newVersion = next with + { + Meta = new Metadata_Versioned { /*...*/ }, + OnChange = current.OnChange + }; + newVersion.OnChange( current, newVersion ); + return newVersion; + } + + /// + /// Basic Record. Made virtual. Implements Obj.Record. + /// + public virtual T Record( + string reason = "Recorded", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0 ) => Process( t => t, reason, dbgName, dbgPath, dbgLine ); + + /// + /// Implements Obj.Record by calling the virtual T Record. + /// + Obj Obj.Record( + string reason = "Recorded", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0 ) => this.Record( reason, dbgName, dbgPath, dbgLine ); + + +} + +/// +/// Level 2: Adds history and caller info. +/// +public record class Recorded : Versioned where T : Recorded +{ + new public Metadata_Recorded Meta { get; init; } = new(); + + [JsonIgnore] + new public T? DebugOld => Meta.OldObject as T; + + //public override Obj? DebugOld => this.DebugOld; + //Metadata_Versioned Obj.Meta => this.Meta; + + public Recorded() { } + protected Recorded( Recorded original ) : base( original ) { Meta = original.Meta; } + + public override T Process( + Func fn, + string reason = "", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string expStr = "" ) + { + var current = (T)this; + var next = fn( current ); + + if( ReferenceEquals( current, next ) ) + return current; + + var newMeta = current.Meta with + { + Version = current.Meta.Version + 1, + Reason = reason, + MemberName = dbgName, + FilePath = dbgPath, + LineNumber = dbgLine, + Expression = expStr, + OldObject = current, + }; + + var newVersion = next with { Meta = newMeta, OnChange = current.OnChange }; + newVersion.OnChange( current, newVersion ); + return newVersion; + } + + public new T Record( + string reason = "Recorded", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0 ) + { + return Process( t => t, reason, dbgName, dbgPath, dbgLine ); + } + +} + +/// +/// Level 3: Adds timestamps. +/// +public record class Timed : Recorded where T : Timed +{ + new public Metadata_Timed Meta { get; init; } = new(); + //Metadata_Versioned Obj.Meta => this.Meta; + public TimeSpan SinceLastTouch => Meta.TouchedAt - ( DebugOld?.Meta as Metadata_Timed )?.TouchedAt ?? TimeSpan.Zero; + public TimeSpan TotalAge => Meta.TouchedAt - Meta.CreatedAt; + + public Timed() { } + protected Timed( Timed original ) : base( original ) { Meta = original.Meta; } + + + public override T Process( + Func fn, + string reason = "", + [CallerMemberName] string dbgMethod = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string dbgExpStr = "" ) + { + var current = (T)this; + var next = fn( current ); + + if( ReferenceEquals( current, next ) ) + return current; + + /* + var newMeta = new Metadata_Timed + { + Version = current.Meta.Version + 1, + Reason = reason, + MemberName = dbgMethod, + FilePath = dbgPath, + LineNumber = dbgLine, + Expression = dbgExpression, + OldObject = current, + CreatedAt = current.Meta.CreatedAt, + TouchedAt = DateTime.UtcNow + }; + */ + + var newMeta = current.Meta with + { + Version = current.Meta.Version + 1, + Reason = reason, + MemberName = dbgMethod, + FilePath = dbgPath, + LineNumber = dbgLine, + Expression = dbgExpStr, + OldObject = current, + TouchedAt = DateTime.UtcNow + }; + + // Testing: Shouldnt need the OnChange + var newVersion = next with { Meta = newMeta }; + newVersion.OnChange( current, newVersion ); + return newVersion; + } + + public new T Record( + string reason = "Recorded", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0 ) + { + return Process( t => t, reason, dbgName, dbgPath, dbgLine ); + } +} + +/* +public static class TimedExt +{ + public static T Process( + ref T obj, + Func fn, + string reason = "", + [CallerMemberName] string dbgName = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression( "fn" )] string dbgExpression = "" + ) where T : io.Timed + { + obj = obj.Process( fn, reason, dbgName, dbgPath, dbgLine, dbgExpression ); + return obj; + } +} +*/ diff --git a/imm/iu.cs b/imm/iu.cs deleted file mode 100644 index 0e8baed..0000000 --- a/imm/iu.cs +++ /dev/null @@ -1,52 +0,0 @@ -//#nullable enable - -using System; -using System.Runtime.CompilerServices; -using imm; - -/// -/// Helper static class for processing immutable objects using a 'ref' pattern. -/// Provides different levels of processing based on the type. -/// -public static class iu -{ - /// - /// Processes a 'Versioned' object (Level 1). - /// - public static T LightProcess( - ref T obj, - Func fn, - string reason = "Processed" ) - where T : Versioned - { - obj = obj.Process( fn, reason ); - return obj; - } - - /// - /// Processes a 'Recorded' object (Level 2), capturing caller info. - /// - public static T Process( - ref T obj, - Func fn, - string reason = "", - [CallerMemberName] string dbgName = "", - [CallerFilePath] string dbgPath = "", - [CallerLineNumber] int dbgLine = 0, - [CallerArgumentExpression( "fn" )] string dbgExpression = "" ) - where T : Recorded // Catches Recorded and Timed - { - // This will call the 'Timed' override if T is Timed, - // or the 'Recorded' override if T is Recorded. - obj = obj.Process( fn, reason, dbgName, dbgPath, dbgLine, dbgExpression ); - return obj; - } - - public static string LogDiff( T cur, T old, [CallerArgumentExpression( "cur" )] string dbgExpCur = "", [CallerArgumentExpression( "old" )] string dbgExpOld = "" ) - { - return $"{dbgExpCur} changed from {old} to {cur}"; - } - - // No specific Process needed for Timed, as it's caught by Recorded - // and its Process override handles the timing. -} \ No newline at end of file diff --git a/lib/CodeGen.cs b/lib/CodeGen.cs index 5931b48..e1bd6e7 100644 --- a/lib/CodeGen.cs +++ b/lib/CodeGen.cs @@ -17,7 +17,7 @@ using System.Collections.Immutable; namespace ser; -public record CodeGenConfig : imm.Recorded +public record CodeGenConfig : io.Recorded { // Whitelists (if needed, otherwise rely on attributes/defaults) public ImmutableDictionary> WLProps { get; init; } = ImmutableDictionary>.Empty; @@ -33,14 +33,14 @@ public record CodeGenConfig : imm.Recorded } public record GenMemberMeta( - MemberInfo Info, - Type Type, - string Name, // Name for code generation (usually original) - bool IsPrimitive, - bool IsCollection, - Type? CollectionElementType, - bool HasDo, - bool HasDont + MemberInfo Info, + Type Type, + string Name, // Name for code generation (usually original) + bool IsPrimitive, + bool IsCollection, + Type? CollectionElementType, + bool HasDo, + bool HasDont ); public record TypeStructureInfo( @@ -55,46 +55,46 @@ public class TypeStructureAnalyzer private readonly ConcurrentDictionary _cache = new(); private readonly CodeGenConfig _cfg; - public TypeStructureAnalyzer(CodeGenConfig cfg) => _cfg = cfg; + public TypeStructureAnalyzer( CodeGenConfig cfg ) => _cfg = cfg; - public TypeStructureInfo Get(Type type) => _cache.GetOrAdd(type, BuildTypeInfo); + public TypeStructureInfo Get( Type type ) => _cache.GetOrAdd( type, BuildTypeInfo ); - private TypeStructureInfo BuildTypeInfo(Type type) + private TypeStructureInfo BuildTypeInfo( Type type ) { var members = new List(); - var typesTodo = type.GetCustomAttribute(true)?.Types ?? _cfg.TypesDefault; - bool doFields = typesTodo.HasFlag(ser.Types.Fields); - bool doProps = typesTodo.HasFlag(ser.Types.Props); + var typesTodo = type.GetCustomAttribute( true )?.Types ?? _cfg.TypesDefault; + bool doFields = typesTodo.HasFlag( ser.Types.Fields ); + bool doProps = typesTodo.HasFlag( ser.Types.Props ); // Track processed names to avoid duplicates (e.g., field + prop) var processedNames = new HashSet(); // Process Properties First (often preferred interface) - if (doProps) + if( doProps ) { - foreach (var pi in refl.GetAllProperties(type)) + foreach( var pi in refl.GetAllProperties( type ) ) { - if (ProcessMember(pi, false, false, new HashSet(), false, members)) + if( ProcessMember( pi, false, false, new HashSet(), false, members ) ) { - processedNames.Add(pi.Name); + processedNames.Add( pi.Name ); } } } // Process Fields, avoiding those already covered by properties - if (doFields) + if( doFields ) { - foreach (var fi in refl.GetAllFields(type)) + foreach( var fi in refl.GetAllFields( type ) ) { - var (isBacking, propName) = IsBackingField(fi); + var (isBacking, propName) = IsBackingField( fi ); string nameToTest = isBacking ? propName : fi.Name; - if (!processedNames.Contains(nameToTest)) + if( !processedNames.Contains( nameToTest ) ) { - if(ProcessMember(fi, false, false, new HashSet(), false, members)) - { - processedNames.Add(nameToTest); - } + if( ProcessMember( fi, false, false, new HashSet(), false, members ) ) + { + processedNames.Add( nameToTest ); + } } } } @@ -103,56 +103,63 @@ public class TypeStructureAnalyzer type, members, type.IsValueType, - typeof(IEnumerable).IsAssignableFrom(type) && type != typeof(string) + typeof( IEnumerable ).IsAssignableFrom( type ) && type != typeof( string ) ); } - private bool ProcessMember(MemberInfo mi, bool filter, bool doImpls, HashSet whitelist, bool isImm, List members) + private bool ProcessMember( MemberInfo mi, bool filter, bool doImpls, HashSet whitelist, bool isImm, List members ) { - var (hasDo, hasDont, propName) = GetMemberAttributes(mi, out var actualMiForAtts); + var (hasDo, hasDont, propName) = GetMemberAttributes( mi, out var actualMiForAtts ); - if (hasDont) return false; - if (mi.GetCustomAttribute(true) != null) return false; - if (mi.Name.Contains("k__BackingField") && !propName.Any()) return false; // Skip if backing but no prop found + if( hasDont ) + return false; + if( mi.GetCustomAttribute( true ) != null ) + return false; + if( mi.Name.Contains( "k__BackingField" ) && !propName.Any() ) + return false; // Skip if backing but no prop found - string name = string.IsNullOrEmpty(propName) ? mi.Name : propName; + string name = string.IsNullOrEmpty( propName ) ? mi.Name : propName; // Add filtering logic if needed (based on whitelist, etc.) - var type = (mi is FieldInfo fi) ? fi.FieldType : ((PropertyInfo)mi).PropertyType; - bool isCollection = typeof(IEnumerable).IsAssignableFrom(type) && type != typeof(string); - Type? elementType = isCollection ? GetElementType(type) : null; - bool isPrimitive = Type.GetTypeCode(type) != TypeCode.Object && !isCollection; + var type = ( mi is FieldInfo fi ) ? fi.FieldType : ( (PropertyInfo)mi ).PropertyType; + bool isCollection = typeof( IEnumerable ).IsAssignableFrom( type ) && type != typeof( string ); + Type? elementType = isCollection ? GetElementType( type ) : null; + bool isPrimitive = Type.GetTypeCode( type ) != TypeCode.Object && !isCollection; - members.Add(new GenMemberMeta( + members.Add( new GenMemberMeta( mi, type, name, isPrimitive, isCollection, elementType, hasDo, hasDont - )); + ) ); return true; } - private (bool, string) IsBackingField(FieldInfo fi) + private (bool, string) IsBackingField( FieldInfo fi ) { - if (fi.Name.StartsWith("<") && fi.Name.EndsWith("BackingField")) - { - var gtIndex = fi.Name.IndexOf('>'); - if (gtIndex > 1) { - return (true, fi.Name.Substring(1, gtIndex - 1)); + if( fi.Name.StartsWith( "<" ) && fi.Name.EndsWith( "BackingField" ) ) + { + var gtIndex = fi.Name.IndexOf( '>' ); + if( gtIndex > 1 ) + { + return (true, fi.Name.Substring( 1, gtIndex - 1 )); } - } - return (false, ""); + } + return (false, ""); } - private (bool hasDo, bool hasDont, string propName) GetMemberAttributes(MemberInfo mi, out MemberInfo actualMi) + private (bool hasDo, bool hasDont, string propName) GetMemberAttributes( MemberInfo mi, out MemberInfo actualMi ) { actualMi = mi; string propName = ""; - if (mi is FieldInfo fi && IsBackingField(fi).Item1) + if( mi is FieldInfo fi && IsBackingField( fi ).Item1 ) { - propName = IsBackingField(fi).Item2; - var propInfo = mi.DeclaringType?.GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); - if (propInfo != null) actualMi = propInfo; - } else if (mi is PropertyInfo) { - propName = mi.Name; + propName = IsBackingField( fi ).Item2; + var propInfo = mi.DeclaringType?.GetProperty( propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic ); + if( propInfo != null ) + actualMi = propInfo; + } + else if( mi is PropertyInfo ) + { + propName = mi.Name; } return ( @@ -162,11 +169,13 @@ public class TypeStructureAnalyzer ); } - private Type GetElementType(Type collectionType) + private Type GetElementType( Type collectionType ) { - if (collectionType.IsArray) return collectionType.GetElementType()!; - if (collectionType.IsGenericType) return collectionType.GetGenericArguments().Last(); // Usually last (e.g., List, Dict) - return typeof(object); // Fallback + if( collectionType.IsArray ) + return collectionType.GetElementType()!; + if( collectionType.IsGenericType ) + return collectionType.GetGenericArguments().Last(); // Usually last (e.g., List, Dict) + return typeof( object ); // Fallback } // Add GetFilters and FilterField if needed, or simplify as above diff --git a/lib/CodeGenerator.cs b/lib/CodeGenerator.cs index ca25959..2b08984 100644 --- a/lib/CodeGenerator.cs +++ b/lib/CodeGenerator.cs @@ -71,4 +71,4 @@ public abstract class CodeGenerator protected string GetTypeName( Type t ) => t.IsGenericType ? $"{t.Name.Split( '`' )[0]}<{string.Join( ", ", t.GetGenericArguments().Select( GetTypeName ) )}>" : t.Name; // Basic handling, needs improvement for full names/namespaces -} \ No newline at end of file +} diff --git a/lib/VersionFormatter.cs_bad b/lib/VersionFormatter.cs_bad index 1d0daaa..815a1fe 100644 --- a/lib/VersionFormatter.cs_bad +++ b/lib/VersionFormatter.cs_bad @@ -10,7 +10,7 @@ using System.Runtime.Serialization; namespace lib { /// - /// + /// /// public class VersionFormatter: IFormatter { @@ -32,7 +32,7 @@ namespace lib public VersionFormatter() { - // + // // TODO: Add constructor logic here // } @@ -264,27 +264,27 @@ namespace lib { writer.Write( val ); } - + void writeSingle( BinaryWriter writer, float val ) { writer.Write( val ); } - + void writeDouble( BinaryWriter writer, double val ) { writer.Write( val ); } - + void writeChar( BinaryWriter writer, char val ) { writer.Write( val ); } - + void writeString( BinaryWriter writer, string val ) { writer.Write( val ); } - + void writeBool( BinaryWriter writer, bool val ) { writer.Write( val ); @@ -365,7 +365,7 @@ namespace lib foreach( Fixup fu in m_fixupList ) { - //Fixup fix = m_fixups[ + //Fixup fix = m_fixups[ object obj = m_mapGUIDToObject[ fu.m_guid ]; diff --git a/lib/XmlFormatter.cs_bad b/lib/XmlFormatter.cs_bad index f485f17..6573732 100644 --- a/lib/XmlFormatter.cs_bad +++ b/lib/XmlFormatter.cs_bad @@ -224,7 +224,7 @@ namespace lib { if( nodeList.Count == 0 ) { - // Should be + // Should be //object obj2 = fi.GetRawConstantValue(); } @@ -431,7 +431,7 @@ namespace lib /* /// -/// +/// /// public class XmlFormatter : IFormatter { @@ -453,31 +453,31 @@ public class XmlFormatter : IFormatter public XmlFormatter() { - // + // // TODO: Add constructor logic here // } #region Useless - public ISurrogateSelector SurrogateSelector + public ISurrogateSelector SurrogateSelector { get { return null; - } + } set { } } - public SerializationBinder Binder + public SerializationBinder Binder { get { return null; - } + } set { @@ -489,7 +489,7 @@ public class XmlFormatter : IFormatter get { return new StreamingContext(); - } + } set { @@ -591,31 +591,31 @@ public class XmlFormatter : IFormatter writer.Write( name.GetHashCode() ); writer.Write( Convert.ToSingle( fi.GetValue( parentObj ) ) ); - break; + break; case "Double": writer.Write( (char)ETypes.Double ); writer.Write( name.GetHashCode() ); writer.Write( Convert.ToDouble( fi.GetValue( parentObj ) ) ); - break; + break; case "Char": writer.Write( (char)ETypes.Char ); writer.Write( name.GetHashCode() ); writer.Write( Convert.ToChar( fi.GetValue( parentObj ) ) ); - break; + break; case "String": writer.Write( (char)ETypes.String ); writer.Write( name.GetHashCode() ); writer.Write( Convert.ToString( fi.GetValue( parentObj ) ) ); - break; + break; case "Boolean": writer.Write( (char)ETypes.Boolean ); writer.Write( name.GetHashCode() ); writer.Write( Convert.ToBoolean( fi.GetValue( parentObj ) ) ); - break; + break; default: Console.WriteLine( "VersionFormatter does not understand type " + typeName ); break; @@ -788,7 +788,7 @@ public class XmlFormatter : IFormatter foreach( Fixup fu in m_fixupList ) { - //Fixup fix = m_fixups[ + //Fixup fix = m_fixups[ object obj = m_mapGUIDToObject[ fu.m_guid ]; @@ -844,7 +844,7 @@ public class XmlFormatter : IFormatter int nameHash = reader.ReadInt32(); - FieldInfo fi = (FieldInfo)ht[ nameHash ]; + FieldInfo fi = (FieldInfo)ht[ nameHash ]; if( fi == null ) { @@ -852,7 +852,7 @@ public class XmlFormatter : IFormatter } try - { + { switch( type ) { case ETypes.Array: diff --git a/lib/XmlFormatter2.cs b/lib/XmlFormatter2.cs index a60f5a9..cfe633e 100644 --- a/lib/XmlFormatter2.cs +++ b/lib/XmlFormatter2.cs @@ -139,7 +139,7 @@ namespace lib private string fromStr = ""; - void SetFromStr( Stream stream ) + void SetFromStr( Stream stream ) { fromStr = stream.ToString() ?? "{null}"; @@ -186,7 +186,8 @@ namespace lib doc.Load( reader ); - if( doc.DocumentElement == null ) return null; + if( doc.DocumentElement == null ) + return null; if( t == null ) return Deserialize( doc.DocumentElement ); @@ -256,7 +257,8 @@ namespace lib { TypeCode typeCode = Type.GetTypeCode( type ); - if( _cfg.VerboseLogging ) log.info( $"{type.FriendlyName()}.{name} {existing} {mi?.Name}" ); + if( _cfg.VerboseLogging ) + log.info( $"{type.FriendlyName()}.{name} {existing} {mi?.Name}" ); if( typeCode != TypeCode.Object ) { @@ -276,7 +278,8 @@ namespace lib if( obj is ser.I_Serialize iser ) { - if( _cfg.VerboseLogging ) log.info( $"" ); + if( _cfg.VerboseLogging ) + log.info( $"" ); obj = iser.OnDeserialize( null ); } @@ -314,7 +317,8 @@ namespace lib private object DeserializeConcrete( XmlElement elem, MemberInfo mi, string name, Type type ) { - if( _cfg.VerboseLogging ) log.info( $"" ); + if( _cfg.VerboseLogging ) + log.info( $"" ); string val = ""; @@ -398,7 +402,8 @@ namespace lib private object HydrateObject( XmlElement elem, MemberInfo mi, Type finalType, object obj ) { - if( _cfg.VerboseLogging ) log.info( $"" ); + if( _cfg.VerboseLogging ) + log.info( $"" ); if( obj is IList ) { @@ -488,9 +493,10 @@ namespace lib private object HydrateObjectOfNarrowType( XmlElement elem, MemberInfo mi, Type narrowType, object obj ) { - if( _cfg.VerboseLogging ) log.info( $"" ); + if( _cfg.VerboseLogging ) + log.info( $"" ); - var isImm = typeof(imm.Obj).IsAssignableFrom( narrowType ); + var isImm = typeof( io.Obj ).IsAssignableFrom( narrowType ); XmlNodeList allChildren = elem.ChildNodes; @@ -536,7 +542,7 @@ namespace lib name = refl.TypeToIdentifier( name ); // @@@ TODO This doesnt yet handle propNames! - if( !doAtt.Any() && FilterField( filterFields, doImpls, whitelistFields, childFi as MemberInfo, name ) ) + if( !doAtt.Any() && FilterField( filterFields, doImpls, whitelistFields, childFi as MemberInfo, name ) ) continue; var useFieldName = true; @@ -625,7 +631,7 @@ namespace lib { object existingObj = childPi.GetValue( obj ); - object childObj = DeserializeConcrete( elem, childPi, name, childPi.PropertyType ); + object childObj = DeserializeConcrete( elem, childPi, name, childPi.PropertyType ); if( setMethod != null ) { @@ -642,13 +648,13 @@ namespace lib } } - if(!isImm) + if( !isImm ) { return obj; } else { - var imm = obj as imm.Obj; + var imm = obj as io.Obj; var newObj = imm.Record( $"From XML {fromStr}:{elem.ParentNode?.Name}{elem.Name}" ); return newObj; } @@ -686,7 +692,8 @@ namespace lib int refInt = refString.Length > 0 ? Convert.ToInt32( refString ) : -1; - if( _cfg.VerboseLogging ) log.info( $"{finalType?.FriendlyName()}({type?.FriendlyName()}) refInt {refInt} exitingObj = {obj?.ToString()}" ); + if( _cfg.VerboseLogging ) + log.info( $"{finalType?.FriendlyName()}({type?.FriendlyName()}) refInt {refInt} exitingObj = {obj?.ToString()}" ); obj = createObject( elem, finalType, refInt, obj ); @@ -695,7 +702,8 @@ namespace lib private object DeserializeList( XmlElement elem, MemberInfo mi, Type type, IList list ) { - if( _cfg.VerboseLogging ) log.info( $"" ); + if( _cfg.VerboseLogging ) + log.info( $"" ); XmlNodeList arrNodeList = elem.ChildNodes; @@ -731,7 +739,8 @@ namespace lib typeElem = typeof( KeyValuePair<,> ).MakeGenericType( type.GenericTypeArguments ); } - if( _cfg.VerboseLogging ) log.info( $"DserCol {type.GetType().FriendlyName()} {typeElem.Name} into reflT {mi.ReflectedType.FriendlyName()} declT {mi.DeclaringType.FriendlyName()} {mi.Name}" ); + if( _cfg.VerboseLogging ) + log.info( $"DserCol {type.GetType().FriendlyName()} {typeElem.Name} into reflT {mi.ReflectedType.FriendlyName()} declT {mi.DeclaringType.FriendlyName()} {mi.Name}" ); string refString = elem.GetAttribute( "ref" ); int refInt = refString.Length > 0 ? Convert.ToInt32( refString ) : -1; @@ -776,7 +785,8 @@ namespace lib var typeGen = Type.MakeGenericSignatureType( type ); - if( _cfg.VerboseLogging ) log.info( $"TypeGen: {typeGen.FriendlyName()}" ); + if( _cfg.VerboseLogging ) + log.info( $"TypeGen: {typeGen.FriendlyName()}" ); if( type == typeof( ImmutableArray<> ).MakeGenericType( typeElem ) ) { @@ -833,7 +843,8 @@ namespace lib private object DeserializeArray( XmlElement elem, MemberInfo mi, Type type ) { - if( _cfg.VerboseLogging ) log.info( $"" ); + if( _cfg.VerboseLogging ) + log.info( $"" ); Type typeElem = type.GetElementType(); @@ -883,7 +894,8 @@ namespace lib if( _cfg.datastructure == Datastructure.Graph && refInt > 0 && m_alreadySerialized.ContainsKey( refInt ) ) { - if( _cfg.VerboseLogging ) log.info( $"Reuse object" ); + if( _cfg.VerboseLogging ) + log.info( $"Reuse object" ); return m_alreadySerialized[refInt]; } @@ -893,7 +905,8 @@ namespace lib if( isProxy ) { - if( _cfg.VerboseLogging ) log.info( $"use Proxy" ); + if( _cfg.VerboseLogging ) + log.info( $"use Proxy" ); object obj = null; var tryType = type; @@ -937,7 +950,8 @@ namespace lib if( isSubclass ) { - if( _cfg.VerboseLogging ) log.info( $"Using existing obj {existingObj?.ToString()}" ); + if( _cfg.VerboseLogging ) + log.info( $"Using existing obj {existingObj?.ToString()}" ); return existingObj; } @@ -953,12 +967,14 @@ namespace lib try { - if( _cfg.VerboseLogging ) log.info( $"For {type.FriendlyName()} check for constructors" ); + if( _cfg.VerboseLogging ) + log.info( $"For {type.FriendlyName()} check for constructors" ); var cons = type.GetConstructor( Type.EmptyTypes ); - if( cons != null) + if( cons != null ) { - if( _cfg.VerboseLogging ) log.info( $"Activator.CreateInstance" ); + if( _cfg.VerboseLogging ) + log.info( $"Activator.CreateInstance" ); obj = Activator.CreateInstance( type ); } else @@ -967,15 +983,18 @@ namespace lib obj = System.Runtime.Serialization.FormatterServices.GetUninitializedObject( type ); } - if( _cfg.VerboseLogging ) log.info( $"Got obj {obj?.ToString()}" ); + if( _cfg.VerboseLogging ) + log.info( $"Got obj {obj?.ToString()}" ); } catch( Exception ) { try { - if( _cfg.VerboseLogging ) log.info( $"GetUninitializedObject" ); + if( _cfg.VerboseLogging ) + log.info( $"GetUninitializedObject" ); obj = System.Runtime.Serialization.FormatterServices.GetUninitializedObject( type ); - if( _cfg.VerboseLogging ) log.info( $"Got obj {obj?.ToString()}" ); + if( _cfg.VerboseLogging ) + log.info( $"Got obj {obj?.ToString()}" ); } catch( Exception exInner ) { @@ -1290,7 +1309,7 @@ namespace lib HashSet whitelistFields, whitelistProps; GetFilters( _cfg.TypesDefault, mi, narrowType, out filterFields, out filterProps, out doImpls, out doFields, out doProps, out whitelistFields, out whitelistProps ); - var isImm = typeof(imm.Obj).IsAssignableFrom( narrowType ); + var isImm = typeof( io.Obj ).IsAssignableFrom( narrowType ); if( doFields || doImpls ) { @@ -1323,8 +1342,10 @@ namespace lib if( isImm ) { - if( name == "MetaStorage" ) continue; - if( name == "Fn" ) continue; + if( name == "MetaStorage" ) + continue; + if( name == "Fn" ) + continue; } if( !doAtt.Any() && FilterField( filterFields, doImpls, whitelistFields, childFi as MemberInfo, name ) ) @@ -1365,8 +1386,10 @@ namespace lib if( isImm ) { - if( name == "MetaStorage" ) continue; - if( name == "Fn" ) continue; + if( name == "MetaStorage" ) + continue; + if( name == "Fn" ) + continue; } if( FilterField( filterProps, doImpls, whitelistProps, childPi as MemberInfo, name ) ) @@ -1393,15 +1416,15 @@ namespace lib var custWLProps = mi?.GetCustomAttribute( true ); filterFields = custWLFields != null; - filterProps = custWLProps != null; + filterProps = custWLProps != null; var typesTodo = type.GetCustomAttribute( true )?.Types ?? TypesDefault; - doImpls = typesTodo.HasFlag( ser.Types.Implied ); + doImpls = typesTodo.HasFlag( ser.Types.Implied ); doFields = filterFields || typesTodo.HasFlag( ser.Types.Fields ); - doProps = filterProps || typesTodo.HasFlag( ser.Types.Props ); + doProps = filterProps || typesTodo.HasFlag( ser.Types.Props ); whitelistFields = new( custWLFields?.Values ?? new string[0] ); - whitelistProps = new( custWLProps?.Values ?? new string[0] ); + whitelistProps = new( custWLProps?.Values ?? new string[0] ); } private void SerializeArray( XmlWriter writer, MemberInfo mi, Type mType, object root, int depth ) @@ -1413,8 +1436,10 @@ namespace lib Type type = root.GetType(); Type typeOfMember = typeof( object ); - if( mi is FieldInfo fi ) typeOfMember = fi.FieldType; - if( mi is PropertyInfo pi ) typeOfMember = pi.PropertyType; + if( mi is FieldInfo fi ) + typeOfMember = fi.FieldType; + if( mi is PropertyInfo pi ) + typeOfMember = pi.PropertyType; if( typeOfMember != type ) { log.info( $"SerArr {typeOfMember.FriendlyName()} {mi?.Name} != {type.FriendlyName()}" ); diff --git a/logging/GC.cs b/logging/GC.cs index 80304e4..5cfcb54 100644 --- a/logging/GC.cs +++ b/logging/GC.cs @@ -28,7 +28,7 @@ public static class LogGCExt { public static string MethodInfo( TraceEvent te, string prefix = "Method" ) { - return $"{te.PayloadStringByName($"{prefix}Namespace")}.{te.PayloadStringByName($"{prefix}Name")}{te.PayloadStringByName($"{prefix}Signature")}"; + return $"{te.PayloadStringByName( $"{prefix}Namespace" )}.{te.PayloadStringByName( $"{prefix}Name" )}{te.PayloadStringByName( $"{prefix}Signature" )}"; } public static string Get( this TraceEvent te, string name, string def = "" ) => te.PayloadStringByName( name ) ?? def; @@ -37,14 +37,15 @@ public static class LogGCExt { var index = te.PayloadIndex( name ); - if( index <= 0 ) return default; + if( index <= 0 ) + return default; var value = te.PayloadValue( index ); - if( value.GetType() != typeof(T) ) + if( value.GetType() != typeof( T ) ) { - log.warn( $"In {te.ID} Payload {name} is type {value.GetType().FriendlyName()} not {typeof(T).FriendlyName()}" ); + log.warn( $"In {te.ID} Payload {name} is type {value.GetType().FriendlyName()} not {typeof( T ).FriendlyName()}" ); return default; } @@ -66,43 +67,43 @@ public class LogGC "FAKE_TEST", "GC/BulkMovedObjectRanges", - /* - "GC/BulkSurvivingObjectRanges", - "GC/BulkRootStaticVar", - "GC/BulkNode", - "GC/BulkEdge", - "GC/BulkRootEdge", - "GC/FinalizeObject", - "GC/SetGCHandle", - "GC/DestoryGCHandle", - "GC/MarkWithType", - "GC/SuspendEEStart", - "GC/SuspendEEStop", + /* + "GC/BulkSurvivingObjectRanges", + "GC/BulkRootStaticVar", + "GC/BulkNode", + "GC/BulkEdge", + "GC/BulkRootEdge", + "GC/FinalizeObject", + "GC/SetGCHandle", + "GC/DestoryGCHandle", + "GC/MarkWithType", + "GC/SuspendEEStart", + "GC/SuspendEEStop", - "GC/RestartEEStart", - "GC/RestartEEStop", + "GC/RestartEEStart", + "GC/RestartEEStop", - "GC/FinalizersStart", - // "GC/FinalizersStop", //Keep this one since it has details + "GC/FinalizersStart", + // "GC/FinalizersStop", //Keep this one since it has details - "GC/GenerationRange", - "GC/FitBucketInfo", + "GC/GenerationRange", + "GC/FitBucketInfo", - "TieredCompilation/BackgroundJitStart", + "TieredCompilation/BackgroundJitStart", - "Type/BulkType", - "TypeLoad/Start", + "Type/BulkType", + "TypeLoad/Start", - "Method/R2RGetEntryPointStart", - "Method/MethodDetails", - "Method/MemoryAllocatedForJitCode", - "Method/JittingStarted", - "Method/ILToNativeMap", + "Method/R2RGetEntryPointStart", + "Method/MethodDetails", + "Method/MemoryAllocatedForJitCode", + "Method/JittingStarted", + "Method/ILToNativeMap", - "ThreadPoolWorkerThread/Wait", + "ThreadPoolWorkerThread/Wait", - "ILStub/StubGenerated" - */ + "ILStub/StubGenerated" + */ "FAKE_END_IS_NOTHING" ); @@ -144,28 +145,33 @@ public class LogGC { var cat = catIn; - if( blacklist.Contains( te.EventName )) return; + if( blacklist.Contains( te.EventName ) ) + return; { - var methodBeingCompiledNamespace = te.Get("MethodBeingCompiledNamespace"); - if( ( methodBeingCompiledNamespace.StartsWith( "Microsoft" ) || methodBeingCompiledNamespace.StartsWith( "System" ) ) ) return; + var methodBeingCompiledNamespace = te.Get( "MethodBeingCompiledNamespace" ); + if( ( methodBeingCompiledNamespace.StartsWith( "Microsoft" ) || methodBeingCompiledNamespace.StartsWith( "System" ) ) ) + return; } { - var methodNamespace = te.PayloadStringByName("MethodNamespace") ?? ""; - if( ( methodNamespace.StartsWith( "Microsoft" ) || methodNamespace.StartsWith( "System" ) ) ) return; + var methodNamespace = te.PayloadStringByName( "MethodNamespace" ) ?? ""; + if( ( methodNamespace.StartsWith( "Microsoft" ) || methodNamespace.StartsWith( "System" ) ) ) + return; } { - var ns = te.PayloadStringByName("TypeName") ?? ""; - if( ( ns.StartsWith( "Microsoft" ) || ns.StartsWith( "System" ) ) ) return; + var ns = te.PayloadStringByName( "TypeName" ) ?? ""; + if( ( ns.StartsWith( "Microsoft" ) || ns.StartsWith( "System" ) ) ) + return; } { - var ns = te.PayloadStringByName("TypeLoad/Stop") ?? ""; - if( ns.StartsWith( "Godot" ) ) return; + var ns = te.PayloadStringByName( "TypeLoad/Stop" ) ?? ""; + if( ns.StartsWith( "Godot" ) ) + return; } { @@ -174,16 +180,17 @@ public class LogGC if( payloadIndex > 0 ) { var count = (int)te.PayloadValue( payloadIndex ); - if( count > 16 ) return; + if( count > 16 ) + return; } } -// -// + // + // -// + // - if( !te.EventName.StartsWith( "EventID") ) + if( !te.EventName.StartsWith( "EventID" ) ) { var logDetails = ""; // Custom event displays @@ -192,8 +199,10 @@ public class LogGC var optTier = te.Get( "OptimizationTier" ); var methodNamespace = te.Get( "MethodNamespace" ); - if( optTier == "MinOptJitted" ) return; - if( methodNamespace.StartsWith( "FastSerialization" )) return; + if( optTier == "MinOptJitted" ) + return; + if( methodNamespace.StartsWith( "FastSerialization" ) ) + return; log.info( $"{optTier} {LogGCExt.MethodInfo( te )}", cat: te.EventName ); @@ -204,7 +213,8 @@ public class LogGC { var methodNamespace = te.Get( "MethodBeingCompiledNamespace" ); - if( methodNamespace.StartsWith( "FastSerialization" )) return; + if( methodNamespace.StartsWith( "FastSerialization" ) ) + return; log.info( $"Inlining {te.Get( "FailReason" )} {te.Get( "OptimizationTier" )} {LogGCExt.MethodInfo( te, "MethodBeingCompiled" )}", cat: te.EventName ); @@ -218,7 +228,7 @@ public class LogGC XmlDocument doc = new(); var stream = new MemoryStream(); - var writer = new StreamWriter(stream); + var writer = new StreamWriter( stream ); writer.Write( val ); writer.Flush(); stream.Position = 0; @@ -265,7 +275,7 @@ public class LogGC var lockId = te.Get( "LockID" ); var objId = te.Get( "AssociatedObjectID" ); - var testObj = Marshal.GetIUnknownForObject(objId); + var testObj = Marshal.GetIUnknownForObject( objId ); var intPtrStr = te.PayloadStringByName( "AssociatedObjectID" ).Substring( 2 ); @@ -281,7 +291,7 @@ public class LogGC var allocated = gch.IsAllocated; var obj = gch.Target; - log.info( $"Lock {lockId} Create {objId.ToString("X")} {obj?.GetType()?.Name} {obj}", cat: te.EventName ); + log.info( $"Lock {lockId} Create {objId.ToString( "X" )} {obj?.GetType()?.Name} {obj}", cat: te.EventName ); //*/ } catch( Exception ex ) @@ -303,7 +313,7 @@ public class LogGC var objId = te.Get( "AssociatedObjectID" ); var threadId = te.Get( "LockOwnerThreadID" ); - log.info( $"Lock {lockId} {te.Get( "ContentionFlags" )} in thread {threadId} on obj 0x{objId.ToString("X")} ", cat: te.EventName ); + log.info( $"Lock {lockId} {te.Get( "ContentionFlags" )} in thread {threadId} on obj 0x{objId.ToString( "X" )} ", cat: te.EventName ); LogGeneric( te, "| Raw: " ); } @@ -319,44 +329,44 @@ public class LogGC } else if( te.EventName.StartsWith( "AssemblyLoader/" ) || te.EventName.StartsWith( "Loader/" ) ) { -//AssemblyLoader/Start AssemblyName AssemblyLoadContext RequestingAssemblyLoadContext AssemblyPath RequestingAssembly -//AssemblyLoader/Stop AssemblyName AssemblyLoadContext RequestingAssemblyLoadContext AssemblyPath RequestingAssembly Success ResultAssemblyName ResultAssemblyPath Cached -//Loader/AssemblyLoad AssemblyID AppDomainID AssemblyFlags FullyQualifiedAssemblyName BindingID -//AssemblyLoader/ResolutionAttempted -// AssemblyName AssemblyLoadContext Result ResultAssemblyName ResultAssemblyPath Stage ErrorMessage + //AssemblyLoader/Start AssemblyName AssemblyLoadContext RequestingAssemblyLoadContext AssemblyPath RequestingAssembly + //AssemblyLoader/Stop AssemblyName AssemblyLoadContext RequestingAssemblyLoadContext AssemblyPath RequestingAssembly Success ResultAssemblyName ResultAssemblyPath Cached + //Loader/AssemblyLoad AssemblyID AppDomainID AssemblyFlags FullyQualifiedAssemblyName BindingID + //AssemblyLoader/ResolutionAttempted + // AssemblyName AssemblyLoadContext Result ResultAssemblyName ResultAssemblyPath Stage ErrorMessage -//Loader/ModuleLoad ModuleID AssemblyID ModuleFlags ModuleILPath ModuleNativePath ManagedPdbSignature ManagedPdbAge ManagedPdbBuildPath -//Loader/DomainModuleLoad ModuleID AssemblyID ModuleFlags ModuleILPath ModuleNativePath AppDomainID + //Loader/ModuleLoad ModuleID AssemblyID ModuleFlags ModuleILPath ModuleNativePath ManagedPdbSignature ManagedPdbAge ManagedPdbBuildPath + //Loader/DomainModuleLoad ModuleID AssemblyID ModuleFlags ModuleILPath ModuleNativePath AppDomainID -//AssemblyLoader/KnownPathProbed FilePath Source Result + //AssemblyLoader/KnownPathProbed FilePath Source Result var appDomainId = te.Get( "AppDomainID" ); - var asId = te.Get( "AssemblyID" ); - var asName = te.Get( "AssemblyName" ); - var asPath = te.Get( "AssemblyPath" ); - var asLC = te.Get( "AssemblyLoadContext" ); + var asId = te.Get( "AssemblyID" ); + var asName = te.Get( "AssemblyName" ); + var asPath = te.Get( "AssemblyPath" ); + var asLC = te.Get( "AssemblyLoadContext" ); - var reqAs = te.Get( "RequestingAssembly" ); - var reqAsLC = te.Get( "RequestingAssemblyLoadContext" ); + var reqAs = te.Get( "RequestingAssembly" ); + var reqAsLC = te.Get( "RequestingAssemblyLoadContext" ); - var reqAsName = te.Get( "ResultAssemblyName" ); - var reqAsPath = te.Get( "ResultAssemblyPath" ); + var reqAsName = te.Get( "ResultAssemblyName" ); + var reqAsPath = te.Get( "ResultAssemblyPath" ); - var success = te.Get( "Success" ); - var cached = te.Get( "Cached" ); - var errMsg = te.Get( "ErrorMessage" ); - var stage = te.Get( "Stage" ); - var result = te.Get( "Result" ); - var source = te.Get( "Source" ); + var success = te.Get( "Success" ); + var cached = te.Get( "Cached" ); + var errMsg = te.Get( "ErrorMessage" ); + var stage = te.Get( "Stage" ); + var result = te.Get( "Result" ); + var source = te.Get( "Source" ); - var modId = te.Get( "ModuleID" ); - var modFlags = te.Get( "ModuleFlags" ); - var modILPath = te.Get( "ModuleILPath" ); - var modNativePath= te.Get( "ModuleNativePath" ); + var modId = te.Get( "ModuleID" ); + var modFlags = te.Get( "ModuleFlags" ); + var modILPath = te.Get( "ModuleILPath" ); + var modNativePath = te.Get( "ModuleNativePath" ); - var manBuildPath= te.Get( "ManagedPdbBuildPath" ); - var fqaName = te.Get( "FullyQualifiedAssemblyName" ); - var bindingId = te.Get( "BindingID" ); + var manBuildPath = te.Get( "ManagedPdbBuildPath" ); + var fqaName = te.Get( "FullyQualifiedAssemblyName" ); + var bindingId = te.Get( "BindingID" ); } @@ -397,7 +407,7 @@ public class LogGC //var eventDataStr = eventData.ToString(); - Encoding enc = new UnicodeEncoding(false, false, true); + Encoding enc = new UnicodeEncoding( false, false, true ); var eventDataUtf16 = enc.GetString( eventData ); //var safeEventData = eventDataUtf16.Replace( (char)0, '\n' ); diff --git a/logging/Log.cs b/logging/Log.cs index 012eb7f..5d588fb 100644 --- a/logging/Log.cs +++ b/logging/Log.cs @@ -18,10 +18,10 @@ using System.Text; /* T O D O : -x) Hook the C# prints from glue. -x) Fix x) Refactor various logs in order to do automagic structured logging ref: https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/interpolated-string-handler +x) Add support for structured logging (e.g., JSON, XML) +x) Implement a centralized logger that can be used across the application D O N E: @@ -32,6 +32,63 @@ N O T  D O I N G : */ + +/* +// L L M +# Context: Logging Infrastructure (`log` static class) +**Strict Rule:** DO NOT use `Console.WriteLine`, `Debug.WriteLine`, or standard `ILogger`. Use the static `log` class for all diagnostics. + +## Core Design Pattern +The logging system uses **Caller Info Attributes** (`[CallerMemberName]`, `[CallerFilePath]`, etc.) to automatically capture context. Do not manually format method names or file paths in messages. + +## API Surface +### 1. Standard Levels. Standard goto loggin +* `log.trace(msg)`, `log.debug(msg)`, `log.info(msg)` +* `log.warn(msg)`, `log.high(msg)` +* `log.error(msg)`, `log.fatal(msg)` +* **Signature:** `(string msg, string cat = "", SourceLoc? loc = null)` +* *Note:* `cat` (Category) and `loc` (SourceLocation) are optional; the system auto-resolves `cat` based on directory structure if omitted. + +### 2. Functional Pass-Throughs If necessary +Use these to log data flow without breaking the statement chain. +* `T log.var(T val)`: Logs `name_of_var = value` and returns `val`. +* `T log.call(Func func)`: Logs entry, executes `func`, logs exit + result, returns result. +* `void log.call(Action func)`: Logs entry, executes `action`, logs exit. +* `log.operations(Action/Func)`: Wraps execution with info logs. + +### 3. Special Types +* `Value`: A struct wrapper to capture variable expressions alongside values. Use `log.Value(var)` when you need explicit expression capturing in custom constructs. +* `log.exception(Exception ex, string msg)`: specialized dump for exceptions. +* `log.logProps(object obj, string header)`: Reflection-based dump of all properties on an object. + +## Idiomatic Usage Examples +**Good:** +```csharp +// Variable inspection (Pass-through) +int x = log.var(Calculate()); + +// Function tracing +var result = log.call(() => ComplexCalculation(input)); + +// Exception handling +try { ... } +catch (Exception ex) { log.exception(ex, "Calculation failed"); } + +// Object Dump +log.logProps(userConfig, "Current Config State"); +``` + +**Bad:** +```csharp +int x = Calculate(); +Console.WriteLine("x is " + x); // Forbidden +log.info($"x = {x}"); // Redundant manual formatting +``` + + +*/ + + public record struct Value( T _val, string _exp = "" ) { public static T Default = default!; @@ -190,7 +247,7 @@ static public class log All = File | Console, } - + #region LogEvent public struct LogEvent { public DateTime Time; @@ -254,6 +311,7 @@ static public class log return logEvent; } + #endregion // LogEvent public delegate void Log_delegate( LogEvent evt ); @@ -307,7 +365,7 @@ static public class log pathPieces = path.Split( '/' ); } - var lastPathPiece = pathPieces[pathPieces.Length - 1]; + var lastPathPiece = pathPieces[pathPieces.Length - 1]; ImmutableInterlocked.AddOrUpdate( ref s_files, pathHash, lastPathPiece, ( key, value ) => { return lastPathPiece; } ); @@ -404,32 +462,32 @@ static public class log } [StackTraceHidden] - static public void info( string msg, string cat = "",SourceLoc? loc = null, + static public void info( string msg, string cat = "", SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) { logBase( msg, LogType.Info, dbgPath, dbgLine, dbgMethod, cat, dbgExp, loc ); } [StackTraceHidden] - static public void debug( string msg, string cat = "",SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) + static public void debug( string msg, string cat = "", SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) { logBase( msg, LogType.Debug, dbgPath, dbgLine, dbgMethod, cat, dbgExp, loc ); } [StackTraceHidden] - static public void trace( string msg, string cat = "",SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) + static public void trace( string msg, string cat = "", SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) { logBase( msg, LogType.Trace, dbgPath, dbgLine, dbgMethod, cat, dbgExp, loc ); } [StackTraceHidden] - static public void warn( string msg, string cat = "",SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) + static public void warn( string msg, string cat = "", SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) { logBase( msg, LogType.Warn, dbgPath, dbgLine, dbgMethod, cat, dbgExp, loc ); } [StackTraceHidden] - static public void high( string msg, string cat = "",SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) + static public void high( string msg, string cat = "", SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) { logBase( msg, LogType.High, dbgPath, dbgLine, dbgMethod, cat, dbgExp, loc ); } @@ -464,12 +522,12 @@ static public class log [StackTraceHidden] - static public void fatal( string msg, string cat = "",SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) + static public void fatal( string msg, string cat = "", SourceLoc? loc = null, [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1, [CallerMemberName] string dbgMethod = "", [CallerArgumentExpression( "msg" )] string dbgExp = "" ) { logBase( msg, LogType.Fatal, dbgPath, dbgLine, dbgMethod, cat, dbgExp, loc ); } -//new LogEvent( LogType.Raw, $"", "", 0, "", "lib.time", "", null ) + //new LogEvent( LogType.Raw, $"", "", 0, "", "lib.time", "", null ) #endregion @@ -531,7 +589,7 @@ static public class log foreach( var fr in stackTrace.GetFrames() ) { - logBase( $"{fr.Log}", LogType.Raw ); + logBase( $"{fr.Log}", LogType.Raw ); } } @@ -554,14 +612,14 @@ static public class log } - static public LogEvent logCreateEvent( string msg, LogType type = LogType.Debug, string dbgPath = "", int dbgLine = -1, string dbgMethod = "", string cat = "unk", string exp = "",SourceLoc? loc = null ) + static public LogEvent logCreateEvent( string msg, LogType type = LogType.Debug, string dbgPath = "", int dbgLine = -1, string dbgMethod = "", string cat = "unk", string exp = "", SourceLoc? loc = null ) { LogEvent evt = new LogEvent( type, msg, dbgPath, dbgLine, dbgMethod, cat, exp, loc ); return evt; } [StackTraceHidden] - static public void logBase( string msg, LogType type = LogType.Debug, string dbgPath = "", int dbgLine = -1, string dbgMethod = "", string cat = "unk", string exp = "",SourceLoc? loc = null ) + static public void logBase( string msg, LogType type = LogType.Debug, string dbgPath = "", int dbgLine = -1, string dbgMethod = "", string cat = "unk", string exp = "", SourceLoc? loc = null ) { var evt = logCreateEvent( msg, type, dbgPath, dbgLine, dbgMethod, cat, exp ); diff --git a/logging/Tracing.cs b/logging/Tracing.cs index 1c77dac..8b797b7 100644 --- a/logging/Tracing.cs +++ b/logging/Tracing.cs @@ -31,9 +31,9 @@ namespace Tracing private bool _monitorCpu = false; private readonly List _customProviders = new(); -private Action _userCallback; - private EventPipeSession _session; - private TraceEventSource _traceLogSource; /// CHANGED + private Action _userCallback; + private EventPipeSession _session; + private TraceEventSource _traceLogSource; /// CHANGED private Task _processingTask; diff --git a/math/AngleSingle.cs b/math/AngleSingle.cs index fd81764..4d71205 100644 --- a/math/AngleSingle.cs +++ b/math/AngleSingle.cs @@ -38,7 +38,7 @@ namespace math /// [DataStyle( DataStyle.Compact )] [DataContract] - public struct AngleSingle: IComparable, IComparable, IEquatable, IFormattable + public struct AngleSingle : IComparable, IComparable, IEquatable, IFormattable { /// /// A value that specifies the size of a single degree. @@ -123,7 +123,7 @@ namespace math /// public void Wrap() { - float newangle = (float)Math.IEEERemainder(radians, MathUtil.TwoPi); + float newangle = (float)Math.IEEERemainder( radians, MathUtil.TwoPi ); if( newangle <= -MathUtil.Pi ) newangle += MathUtil.TwoPi; @@ -177,23 +177,23 @@ namespace math { get { - float degrees = MathUtil.RadiansToDegrees(radians); + float degrees = MathUtil.RadiansToDegrees( radians ); if( degrees < 0 ) { - float degreesfloor = (float)Math.Ceiling(degrees); + float degreesfloor = (float)Math.Ceiling( degrees ); return ( degrees - degreesfloor ) * 60.0f; } else { - float degreesfloor = (float)Math.Floor(degrees); + float degreesfloor = (float)Math.Floor( degrees ); return ( degrees - degreesfloor ) * 60.0f; } } set { - float degrees = MathUtil.RadiansToDegrees(radians); - float degreesfloor = (float)Math.Floor(degrees); + float degrees = MathUtil.RadiansToDegrees( radians ); + float degreesfloor = (float)Math.Floor( degrees ); degreesfloor += value / 60.0f; radians = MathUtil.DegreesToRadians( degreesfloor ); @@ -211,34 +211,34 @@ namespace math { get { - float degrees = MathUtil.RadiansToDegrees(radians); + float degrees = MathUtil.RadiansToDegrees( radians ); if( degrees < 0 ) { - float degreesfloor = (float)Math.Ceiling(degrees); + float degreesfloor = (float)Math.Ceiling( degrees ); - float minutes = (degrees - degreesfloor) * 60.0f; - float minutesfloor = (float)Math.Ceiling(minutes); + float minutes = ( degrees - degreesfloor ) * 60.0f; + float minutesfloor = (float)Math.Ceiling( minutes ); return ( minutes - minutesfloor ) * 60.0f; } else { - float degreesfloor = (float)Math.Floor(degrees); + float degreesfloor = (float)Math.Floor( degrees ); - float minutes = (degrees - degreesfloor) * 60.0f; - float minutesfloor = (float)Math.Floor(minutes); + float minutes = ( degrees - degreesfloor ) * 60.0f; + float minutesfloor = (float)Math.Floor( minutes ); return ( minutes - minutesfloor ) * 60.0f; } } set { - float degrees = MathUtil.RadiansToDegrees(radians); - float degreesfloor = (float)Math.Floor(degrees); + float degrees = MathUtil.RadiansToDegrees( radians ); + float degreesfloor = (float)Math.Floor( degrees ); - float minutes = (degrees - degreesfloor) * 60.0f; - float minutesfloor = (float)Math.Floor(minutes); + float minutes = ( degrees - degreesfloor ) * 60.0f; + float minutesfloor = (float)Math.Floor( minutes ); minutesfloor += value / 60.0f; degreesfloor += minutesfloor / 60.0f; @@ -648,7 +648,7 @@ namespace math if( !( other is AngleSingle ) ) throw new ArgumentException( "Argument must be of type Angle.", "other" ); - float radians = ((AngleSingle)other).radians; + float radians = ( (AngleSingle)other ).radians; if( this.radians > radians ) return 1; diff --git a/math/AngleType.cs b/math/AngleType.cs index 7c04fc6..51e9100 100644 --- a/math/AngleType.cs +++ b/math/AngleType.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 diff --git a/math/BoundingBox.cs b/math/BoundingBox.cs index 736c1e2..3f8a0e9 100644 --- a/math/BoundingBox.cs +++ b/math/BoundingBox.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -37,13 +37,13 @@ namespace math /// Represents an axis-aligned bounding box in three dimensional space. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct BoundingBox : IEquatable, IFormattable { /// /// A which represents an empty space. /// - public static readonly BoundingBox Empty = new BoundingBox(new Vec3(float.MaxValue), new Vec3(float.MinValue)); + public static readonly BoundingBox Empty = new BoundingBox( new Vec3( float.MaxValue ), new Vec3( float.MinValue ) ); /// /// The minimum point of the box. @@ -60,7 +60,7 @@ namespace math /// /// The minimum vertex of the bounding box. /// The maximum vertex of the bounding box. - public BoundingBox(Vec3 minimum, Vec3 maximum) + public BoundingBox( Vec3 minimum, Vec3 maximum ) { this.Minimum = minimum; this.Maximum = maximum; @@ -71,7 +71,7 @@ namespace math /// public Vec3 Center { - get { return (Minimum + Maximum) / 2; } + get { return ( Minimum + Maximum ) / 2; } } /// @@ -79,7 +79,7 @@ namespace math /// public Vec3 Extent { - get { return (Maximum - Minimum) / 2; } + get { return ( Maximum - Minimum ) / 2; } } /// @@ -89,14 +89,14 @@ namespace math public Vec3[] GetCorners() { Vec3[] results = new Vec3[8]; - results[0] = new Vec3(Minimum.X, Maximum.Y, Maximum.Z); - results[1] = new Vec3(Maximum.X, Maximum.Y, Maximum.Z); - results[2] = new Vec3(Maximum.X, Minimum.Y, Maximum.Z); - results[3] = new Vec3(Minimum.X, Minimum.Y, Maximum.Z); - results[4] = new Vec3(Minimum.X, Maximum.Y, Minimum.Z); - results[5] = new Vec3(Maximum.X, Maximum.Y, Minimum.Z); - results[6] = new Vec3(Maximum.X, Minimum.Y, Minimum.Z); - results[7] = new Vec3(Minimum.X, Minimum.Y, Minimum.Z); + results[0] = new Vec3( Minimum.X, Maximum.Y, Maximum.Z ); + results[1] = new Vec3( Maximum.X, Maximum.Y, Maximum.Z ); + results[2] = new Vec3( Maximum.X, Minimum.Y, Maximum.Z ); + results[3] = new Vec3( Minimum.X, Minimum.Y, Maximum.Z ); + results[4] = new Vec3( Minimum.X, Maximum.Y, Minimum.Z ); + results[5] = new Vec3( Maximum.X, Maximum.Y, Minimum.Z ); + results[6] = new Vec3( Maximum.X, Minimum.Y, Minimum.Z ); + results[7] = new Vec3( Minimum.X, Minimum.Y, Minimum.Z ); return results; } @@ -105,10 +105,10 @@ namespace math /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects( ref Ray ray ) { float distance; - return CollisionHelper.RayIntersectsBox(ref ray, ref this, out distance); + return CollisionHelper.RayIntersectsBox( ref ray, ref this, out distance ); } /// @@ -118,9 +118,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out float distance) + public bool Intersects( ref Ray ray, out float distance ) { - return CollisionHelper.RayIntersectsBox(ref ray, ref this, out distance); + return CollisionHelper.RayIntersectsBox( ref ray, ref this, out distance ); } /// @@ -130,9 +130,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vec3 point) + public bool Intersects( ref Ray ray, out Vec3 point ) { - return CollisionHelper.RayIntersectsBox(ref ray, ref this, out point); + return CollisionHelper.RayIntersectsBox( ref ray, ref this, out point ); } /// @@ -140,9 +140,9 @@ namespace math /// /// The plane to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Plane plane) + public PlaneIntersectionType Intersects( ref Plane plane ) { - return CollisionHelper.PlaneIntersectsBox(ref plane, ref this); + return CollisionHelper.PlaneIntersectsBox( ref plane, ref this ); } /* This implentation is wrong @@ -164,9 +164,9 @@ namespace math /// /// The box to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box) + public bool Intersects( ref BoundingBox box ) { - return CollisionHelper.BoxIntersectsBox(ref this, ref box); + return CollisionHelper.BoxIntersectsBox( ref this, ref box ); } /// @@ -174,9 +174,9 @@ namespace math /// /// The sphere to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects( ref BoundingSphere sphere ) { - return CollisionHelper.BoxIntersectsSphere(ref this, ref sphere); + return CollisionHelper.BoxIntersectsSphere( ref this, ref sphere ); } /// @@ -184,9 +184,9 @@ namespace math /// /// The point to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vec3 point) + public ContainmentType Contains( ref Vec3 point ) { - return CollisionHelper.BoxContainsPoint(ref this, ref point); + return CollisionHelper.BoxContainsPoint( ref this, ref point ); } /* This implentation is wrong @@ -208,9 +208,9 @@ namespace math /// /// The box to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingBox box) + public ContainmentType Contains( ref BoundingBox box ) { - return CollisionHelper.BoxContainsBox(ref this, ref box); + return CollisionHelper.BoxContainsBox( ref this, ref box ); } /// @@ -218,9 +218,9 @@ namespace math /// /// The sphere to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingSphere sphere) + public ContainmentType Contains( ref BoundingSphere sphere ) { - return CollisionHelper.BoxContainsSphere(ref this, ref sphere); + return CollisionHelper.BoxContainsSphere( ref this, ref sphere ); } /// @@ -229,21 +229,21 @@ namespace math /// The points that will be contained by the box. /// When the method completes, contains the newly constructed bounding box. /// Thrown when is null. - public static void FromPoints(Vec3[] points, out BoundingBox result) + public static void FromPoints( Vec3[] points, out BoundingBox result ) { - if (points == null) - throw new ArgumentNullException("points"); + if( points == null ) + throw new ArgumentNullException( "points" ); - Vec3 min = new Vec3(float.MaxValue); - Vec3 max = new Vec3(float.MinValue); + Vec3 min = new Vec3( float.MaxValue ); + Vec3 max = new Vec3( float.MinValue ); - for (int i = 0; i < points.Length; ++i) + for( int i = 0; i < points.Length; ++i ) { - Vec3.Min(ref min, ref points[i], out min); - Vec3.Max(ref max, ref points[i], out max); + Vec3.Min( ref min, ref points[i], out min ); + Vec3.Max( ref max, ref points[i], out max ); } - result = new BoundingBox(min, max); + result = new BoundingBox( min, max ); } /// @@ -252,21 +252,21 @@ namespace math /// The points that will be contained by the box. /// The newly constructed bounding box. /// Thrown when is null. - public static BoundingBox FromPoints(Vec3[] points) + public static BoundingBox FromPoints( Vec3[] points ) { - if (points == null) - throw new ArgumentNullException("points"); + if( points == null ) + throw new ArgumentNullException( "points" ); - Vec3 min = new Vec3(float.MaxValue); - Vec3 max = new Vec3(float.MinValue); + Vec3 min = new Vec3( float.MaxValue ); + Vec3 max = new Vec3( float.MinValue ); - for (int i = 0; i < points.Length; ++i) + for( int i = 0; i < points.Length; ++i ) { - Vec3.Min(ref min, ref points[i], out min); - Vec3.Max(ref max, ref points[i], out max); + Vec3.Min( ref min, ref points[i], out min ); + Vec3.Max( ref max, ref points[i], out max ); } - return new BoundingBox(min, max); + return new BoundingBox( min, max ); } /// @@ -274,10 +274,10 @@ namespace math /// /// The sphere that will designate the extents of the box. /// When the method completes, contains the newly constructed bounding box. - public static void FromSphere(ref BoundingSphere sphere, out BoundingBox result) + public static void FromSphere( ref BoundingSphere sphere, out BoundingBox result ) { - result.Minimum = new Vec3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius); - result.Maximum = new Vec3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius); + result.Minimum = new Vec3( sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius ); + result.Maximum = new Vec3( sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius ); } /// @@ -285,11 +285,11 @@ namespace math /// /// The sphere that will designate the extents of the box. /// The newly constructed bounding box. - public static BoundingBox FromSphere(BoundingSphere sphere) + public static BoundingBox FromSphere( BoundingSphere sphere ) { BoundingBox box; - box.Minimum = new Vec3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius); - box.Maximum = new Vec3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius); + box.Minimum = new Vec3( sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius ); + box.Maximum = new Vec3( sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius ); return box; } @@ -299,10 +299,10 @@ namespace math /// The original bounding box. /// The transform to apply to the bounding box. /// The transformed bounding box. - public static void Transform(ref BoundingBox value, ref Matrix transform, out BoundingBox result) + public static void Transform( ref BoundingBox value, ref Matrix transform, out BoundingBox result ) { - var boundingBox = new BoundingBoxExt(value); - boundingBox.Transform(transform); + var boundingBox = new BoundingBoxExt( value ); + boundingBox.Transform( transform ); result = (BoundingBox)boundingBox; } @@ -312,22 +312,22 @@ namespace math /// The box to merge. /// The point to merge. /// When the method completes, contains the newly constructed bounding box. - public static void Merge(ref BoundingBox value1, ref Vec3 value2, out BoundingBox result) + public static void Merge( ref BoundingBox value1, ref Vec3 value2, out BoundingBox result ) { - Vec3.Min(ref value1.Minimum, ref value2, out result.Minimum); - Vec3.Max(ref value1.Maximum, ref value2, out result.Maximum); + Vec3.Min( ref value1.Minimum, ref value2, out result.Minimum ); + Vec3.Max( ref value1.Maximum, ref value2, out result.Maximum ); } - + /// /// Constructs a that is as large as the total combined area of the two specified boxes. /// /// The first box to merge. /// The second box to merge. /// When the method completes, contains the newly constructed bounding box. - public static void Merge(ref BoundingBox value1, ref BoundingBox value2, out BoundingBox result) + public static void Merge( ref BoundingBox value1, ref BoundingBox value2, out BoundingBox result ) { - Vec3.Min(ref value1.Minimum, ref value2.Minimum, out result.Minimum); - Vec3.Max(ref value1.Maximum, ref value2.Maximum, out result.Maximum); + Vec3.Min( ref value1.Minimum, ref value2.Minimum, out result.Minimum ); + Vec3.Max( ref value1.Maximum, ref value2.Maximum, out result.Maximum ); } /// @@ -336,11 +336,11 @@ namespace math /// The first box to merge. /// The second box to merge. /// The newly constructed bounding box. - public static BoundingBox Merge(BoundingBox value1, BoundingBox value2) + public static BoundingBox Merge( BoundingBox value1, BoundingBox value2 ) { BoundingBox box; - Vec3.Min(ref value1.Minimum, ref value2.Minimum, out box.Minimum); - Vec3.Max(ref value1.Maximum, ref value2.Maximum, out box.Maximum); + Vec3.Min( ref value1.Minimum, ref value2.Minimum, out box.Minimum ); + Vec3.Max( ref value1.Maximum, ref value2.Maximum, out box.Maximum ); return box; } @@ -350,9 +350,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(BoundingBox left, BoundingBox right) + public static bool operator ==( BoundingBox left, BoundingBox right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -361,9 +361,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(BoundingBox left, BoundingBox right) + public static bool operator !=( BoundingBox left, BoundingBox right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -374,7 +374,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "Minimum:{0} Maximum:{1}", Minimum.ToString(), Maximum.ToString()); + return string.Format( CultureInfo.CurrentCulture, "Minimum:{0} Maximum:{1}", Minimum.ToString(), Maximum.ToString() ); } /// @@ -384,13 +384,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "Minimum:{0} Maximum:{1}", Minimum.ToString(format, CultureInfo.CurrentCulture), - Maximum.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "Minimum:{0} Maximum:{1}", Minimum.ToString( format, CultureInfo.CurrentCulture ), + Maximum.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -400,9 +400,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "Minimum:{0} Maximum:{1}", Minimum.ToString(), Maximum.ToString()); + return string.Format( formatProvider, "Minimum:{0} Maximum:{1}", Minimum.ToString(), Maximum.ToString() ); } /// @@ -413,20 +413,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "Minimum:{0} Maximum:{1}", Minimum.ToString(format, formatProvider), - Maximum.ToString(format, formatProvider)); + return string.Format( formatProvider, "Minimum:{0} Maximum:{1}", Minimum.ToString( format, formatProvider ), + Maximum.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -440,7 +440,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(BoundingBox value) + public bool Equals( BoundingBox value ) { return Minimum == value.Minimum && Maximum == value.Maximum; } @@ -452,15 +452,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((BoundingBox)value); + return Equals( (BoundingBox)value ); } } } diff --git a/math/BoundingBoxExt.cs b/math/BoundingBoxExt.cs index f22a536..b6a372d 100644 --- a/math/BoundingBoxExt.cs +++ b/math/BoundingBoxExt.cs @@ -11,13 +11,13 @@ namespace math /// Represents an axis-aligned bounding box in three dimensional space that store only the Center and Extent. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct BoundingBoxExt : IEquatable { /// /// A which represents an empty space. /// - public static readonly BoundingBoxExt Empty = new BoundingBoxExt(BoundingBox.Empty); + public static readonly BoundingBoxExt Empty = new BoundingBoxExt( BoundingBox.Empty ); /// /// The center of this bounding box. @@ -33,7 +33,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The box. - public BoundingBoxExt(BoundingBox box) + public BoundingBoxExt( BoundingBox box ) { this.Center = box.Center; this.Extent = box.Extent; @@ -44,10 +44,10 @@ namespace math /// /// The minimum vertex of the bounding box. /// The maximum vertex of the bounding box. - public BoundingBoxExt(Vec3 minimum, Vec3 maximum) + public BoundingBoxExt( Vec3 minimum, Vec3 maximum ) { - this.Center = (minimum + maximum) / 2; - this.Extent = (maximum - minimum) / 2; + this.Center = ( minimum + maximum ) / 2; + this.Extent = ( maximum - minimum ) / 2; } /// @@ -78,29 +78,29 @@ namespace math /// Transform this Bounding box /// /// The transform to apply to the bounding box. - public void Transform(Matrix world) + public void Transform( Matrix world ) { // http://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/ // Compute transformed AABB (by world) var center = Center; var extent = Extent; - Vec3.TransformCoordinate(ref center, ref world, out Center); + Vec3.TransformCoordinate( ref center, ref world, out Center ); // Update world matrix into absolute form unsafe { // Perform an abs on the matrix var matrixData = (float*)&world; - for (int j = 0; j < 16; ++j) + for( int j = 0; j < 16; ++j ) { //*matrixData &= 0x7FFFFFFF; - *matrixData = Math.Abs(*matrixData); + *matrixData = Math.Abs( *matrixData ); ++matrixData; } } - Vec3.TransformNormal(ref extent, ref world, out Extent); + Vec3.TransformNormal( ref extent, ref world, out Extent ); } /// @@ -109,27 +109,28 @@ namespace math /// The first box to merge. /// The second box to merge. /// When the method completes, contains the newly constructed bounding box. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Merge(ref BoundingBoxExt value1, ref BoundingBoxExt value2, out BoundingBoxExt result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Merge( ref BoundingBoxExt value1, ref BoundingBoxExt value2, out BoundingBoxExt result ) { - var maximum = Vec3.Max(value1.Maximum, value2.Maximum); - var minimum = Vec3.Min(value1.Minimum, value2.Minimum); + var maximum = Vec3.Max( value1.Maximum, value2.Maximum ); + var minimum = Vec3.Min( value1.Minimum, value2.Minimum ); - result.Center = (minimum + maximum) / 2; - result.Extent = (maximum - minimum) / 2; + result.Center = ( minimum + maximum ) / 2; + result.Extent = ( maximum - minimum ) / 2; } /// - public bool Equals(BoundingBoxExt other) + public bool Equals( BoundingBoxExt other ) { - return Center.Equals(other.Center) && Extent.Equals(other.Extent); + return Center.Equals( other.Center ) && Extent.Equals( other.Extent ); } /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - return obj is BoundingBoxExt && Equals((BoundingBoxExt)obj); + if( ReferenceEquals( null, obj ) ) + return false; + return obj is BoundingBoxExt && Equals( (BoundingBoxExt)obj ); } /// @@ -137,7 +138,7 @@ namespace math { unchecked { - return (Center.GetHashCode() * 397) ^ Extent.GetHashCode(); + return ( Center.GetHashCode() * 397 ) ^ Extent.GetHashCode(); } } @@ -147,9 +148,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator ==(BoundingBoxExt left, BoundingBoxExt right) + public static bool operator ==( BoundingBoxExt left, BoundingBoxExt right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -158,9 +159,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator !=(BoundingBoxExt left, BoundingBoxExt right) + public static bool operator !=( BoundingBoxExt left, BoundingBoxExt right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -168,9 +169,9 @@ namespace math /// /// The bb ext. /// The result of the conversion. - public static explicit operator BoundingBox(BoundingBoxExt bbExt) + public static explicit operator BoundingBox( BoundingBoxExt bbExt ) { - return new BoundingBox(bbExt.Minimum, bbExt.Maximum); + return new BoundingBox( bbExt.Minimum, bbExt.Maximum ); } /// @@ -178,9 +179,9 @@ namespace math /// /// The bounding box. /// The result of the conversion. - public static explicit operator BoundingBoxExt(BoundingBox boundingBox) + public static explicit operator BoundingBoxExt( BoundingBox boundingBox ) { - return new BoundingBoxExt(boundingBox); + return new BoundingBoxExt( boundingBox ); } } } diff --git a/math/BoundingFrustum.cs b/math/BoundingFrustum.cs index 506c957..02b23a5 100644 --- a/math/BoundingFrustum.cs +++ b/math/BoundingFrustum.cs @@ -44,49 +44,49 @@ namespace math /// Initializes a new instance of the struct from a matrix view-projection. /// /// The matrix view projection. - public BoundingFrustum(ref Matrix matrix) + public BoundingFrustum( ref Matrix matrix ) { // Left - LeftPlane = Plane.Normalize(new Plane( + LeftPlane = Plane.Normalize( new Plane( matrix.M14 + matrix.M11, matrix.M24 + matrix.M21, matrix.M34 + matrix.M31, - matrix.M44 + matrix.M41)); + matrix.M44 + matrix.M41 ) ); // Right - RightPlane = Plane.Normalize(new Plane( + RightPlane = Plane.Normalize( new Plane( matrix.M14 - matrix.M11, matrix.M24 - matrix.M21, matrix.M34 - matrix.M31, - matrix.M44 - matrix.M41)); + matrix.M44 - matrix.M41 ) ); // Top - TopPlane = Plane.Normalize(new Plane( + TopPlane = Plane.Normalize( new Plane( matrix.M14 - matrix.M12, matrix.M24 - matrix.M22, matrix.M34 - matrix.M32, - matrix.M44 - matrix.M42)); + matrix.M44 - matrix.M42 ) ); // Bottom - BottomPlane = Plane.Normalize(new Plane( + BottomPlane = Plane.Normalize( new Plane( matrix.M14 + matrix.M12, matrix.M24 + matrix.M22, matrix.M34 + matrix.M32, - matrix.M44 + matrix.M42)); + matrix.M44 + matrix.M42 ) ); // Near - NearPlane = Plane.Normalize(new Plane( + NearPlane = Plane.Normalize( new Plane( matrix.M13, matrix.M23, matrix.M33, - matrix.M43)); + matrix.M43 ) ); // Far - FarPlane = Plane.Normalize(new Plane( + FarPlane = Plane.Normalize( new Plane( matrix.M14 - matrix.M13, matrix.M24 - matrix.M23, matrix.M34 - matrix.M33, - matrix.M44 - matrix.M43)); + matrix.M44 - matrix.M43 ) ); } /// @@ -94,10 +94,10 @@ namespace math /// /// The bounding box. /// true if this frustum contains the specified bounding box. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Contains(ref BoundingBoxExt boundingBoxExt) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public bool Contains( ref BoundingBoxExt boundingBoxExt ) { - return CollisionHelper.FrustumContainsBox(ref this, ref boundingBoxExt); + return CollisionHelper.FrustumContainsBox( ref this, ref boundingBoxExt ); } } } diff --git a/math/BoundingSphere.cs b/math/BoundingSphere.cs index 57f932e..0ed3933 100644 --- a/math/BoundingSphere.cs +++ b/math/BoundingSphere.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -37,7 +37,7 @@ namespace math /// Represents a bounding sphere in three dimensional space. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct BoundingSphere : IEquatable, IFormattable { /// @@ -60,7 +60,7 @@ namespace math /// /// The center of the sphere in three dimensional space. /// The radius of the sphere. - public BoundingSphere(Vec3 center, float radius) + public BoundingSphere( Vec3 center, float radius ) { this.Center = center; this.Radius = radius; @@ -71,10 +71,10 @@ namespace math /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects( ref Ray ray ) { float distance; - return CollisionHelper.RayIntersectsSphere(ref ray, ref this, out distance); + return CollisionHelper.RayIntersectsSphere( ref ray, ref this, out distance ); } /// @@ -84,9 +84,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out float distance) + public bool Intersects( ref Ray ray, out float distance ) { - return CollisionHelper.RayIntersectsSphere(ref ray, ref this, out distance); + return CollisionHelper.RayIntersectsSphere( ref ray, ref this, out distance ); } /// @@ -96,9 +96,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vec3 point) + public bool Intersects( ref Ray ray, out Vec3 point ) { - return CollisionHelper.RayIntersectsSphere(ref ray, ref this, out point); + return CollisionHelper.RayIntersectsSphere( ref ray, ref this, out point ); } /// @@ -106,9 +106,9 @@ namespace math /// /// The plane to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Plane plane) + public PlaneIntersectionType Intersects( ref Plane plane ) { - return CollisionHelper.PlaneIntersectsSphere(ref plane, ref this); + return CollisionHelper.PlaneIntersectsSphere( ref plane, ref this ); } /// @@ -118,9 +118,9 @@ namespace math /// The second vertex of the triagnle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public bool Intersects(ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public bool Intersects( ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { - return CollisionHelper.SphereIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); + return CollisionHelper.SphereIntersectsTriangle( ref this, ref vertex1, ref vertex2, ref vertex3 ); } /// @@ -128,9 +128,9 @@ namespace math /// /// The box to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box) + public bool Intersects( ref BoundingBox box ) { - return CollisionHelper.BoxIntersectsSphere(ref box, ref this); + return CollisionHelper.BoxIntersectsSphere( ref box, ref this ); } /// @@ -138,9 +138,9 @@ namespace math /// /// The sphere to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects( ref BoundingSphere sphere ) { - return CollisionHelper.SphereIntersectsSphere(ref this, ref sphere); + return CollisionHelper.SphereIntersectsSphere( ref this, ref sphere ); } /// @@ -148,9 +148,9 @@ namespace math /// /// The point to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vec3 point) + public ContainmentType Contains( ref Vec3 point ) { - return CollisionHelper.SphereContainsPoint(ref this, ref point); + return CollisionHelper.SphereContainsPoint( ref this, ref point ); } /// @@ -160,9 +160,9 @@ namespace math /// The second vertex of the triagnle to test. /// The third vertex of the triangle to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public ContainmentType Contains( ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { - return CollisionHelper.SphereContainsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); + return CollisionHelper.SphereContainsTriangle( ref this, ref vertex1, ref vertex2, ref vertex3 ); } /// @@ -170,9 +170,9 @@ namespace math /// /// The box to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingBox box) + public ContainmentType Contains( ref BoundingBox box ) { - return CollisionHelper.SphereContainsBox(ref this, ref box); + return CollisionHelper.SphereContainsBox( ref this, ref box ); } /// @@ -180,9 +180,9 @@ namespace math /// /// The sphere to test. /// The type of containment the two objects have. - public ContainmentType Contains(ref BoundingSphere sphere) + public ContainmentType Contains( ref BoundingSphere sphere ) { - return CollisionHelper.SphereContainsSphere(ref this, ref sphere); + return CollisionHelper.SphereContainsSphere( ref this, ref sphere ); } /// @@ -190,12 +190,13 @@ namespace math /// /// The points that will be contained by the sphere. /// When the method completes, contains the newly constructed bounding sphere. - public static unsafe void FromPoints(Vec3[] points, out BoundingSphere result) + public static unsafe void FromPoints( Vec3[] points, out BoundingSphere result ) { - if (points == null) throw new ArgumentNullException("points"); - fixed (void* pointsPtr = points) + if( points == null ) + throw new ArgumentNullException( "points" ); + fixed( void* pointsPtr = points ) { - FromPoints((IntPtr)pointsPtr, 0, points.Length, lib.Util.SizeOf(), out result); + FromPoints( (IntPtr)pointsPtr, 0, points.Length, lib.Util.SizeOf(), out result ); } } @@ -207,11 +208,11 @@ namespace math /// The verterx vertexCount. /// The vertex stride (size of vertex). /// When the method completes, contains the newly constructed bounding sphere. - public static unsafe void FromPoints(IntPtr vertexBufferPtr, int vertexPositionOffsetInBytes, int vertexCount, int vertexStride, out BoundingSphere result) + public static unsafe void FromPoints( IntPtr vertexBufferPtr, int vertexPositionOffsetInBytes, int vertexCount, int vertexStride, out BoundingSphere result ) { - if (vertexBufferPtr == IntPtr.Zero) + if( vertexBufferPtr == IntPtr.Zero ) { - throw new ArgumentNullException("vertexBufferPtr"); + throw new ArgumentNullException( "vertexBufferPtr" ); } var startPoint = (byte*)vertexBufferPtr + vertexPositionOffsetInBytes; @@ -219,9 +220,9 @@ namespace math //Find the center of all points. Vec3 center = Vec3.Zero; var nextPoint = startPoint; - for (int i = 0; i < vertexCount; ++i) + for( int i = 0; i < vertexCount; ++i ) { - Vec3.Add(ref *(Vec3*)nextPoint, ref center, out center); + Vec3.Add( ref *(Vec3*)nextPoint, ref center, out center ); nextPoint += vertexStride; } @@ -231,20 +232,20 @@ namespace math //Find the radius of the sphere float radius = 0f; nextPoint = startPoint; - for (int i = 0; i < vertexCount; ++i) + for( int i = 0; i < vertexCount; ++i ) { //We are doing a relative distance comparasin to find the maximum distance //from the center of our sphere. float distance; - Vec3.DistanceSquared(ref center, ref *(Vec3*)nextPoint, out distance); + Vec3.DistanceSquared( ref center, ref *(Vec3*)nextPoint, out distance ); - if (distance > radius) + if( distance > radius ) radius = distance; nextPoint += vertexStride; } //Find the real distance from the DistanceSquared. - radius = (float)Math.Sqrt(radius); + radius = (float)Math.Sqrt( radius ); //Construct the sphere. result.Center = center; @@ -256,10 +257,10 @@ namespace math /// /// The points that will be contained by the sphere. /// The newly constructed bounding sphere. - public static BoundingSphere FromPoints(Vec3[] points) + public static BoundingSphere FromPoints( Vec3[] points ) { BoundingSphere result; - FromPoints(points, out result); + FromPoints( points, out result ); return result; } @@ -268,15 +269,15 @@ namespace math /// /// The box that will designate the extents of the sphere. /// When the method completes, the newly constructed bounding sphere. - public static void FromBox(ref BoundingBox box, out BoundingSphere result) + public static void FromBox( ref BoundingBox box, out BoundingSphere result ) { - Vec3.Lerp(ref box.Minimum, ref box.Maximum, 0.5f, out result.Center); + Vec3.Lerp( ref box.Minimum, ref box.Maximum, 0.5f, out result.Center ); float x = box.Minimum.X - box.Maximum.X; float y = box.Minimum.Y - box.Maximum.Y; float z = box.Minimum.Z - box.Maximum.Z; - float distance = (float)(Math.Sqrt((x * x) + (y * y) + (z * z))); + float distance = (float)( Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) ) ); result.Radius = distance * 0.5f; } @@ -285,10 +286,10 @@ namespace math /// /// The box that will designate the extents of the sphere. /// The newly constructed bounding sphere. - public static BoundingSphere FromBox(BoundingBox box) + public static BoundingSphere FromBox( BoundingBox box ) { BoundingSphere result; - FromBox(ref box, out result); + FromBox( ref box, out result ); return result; } @@ -298,16 +299,16 @@ namespace math /// The original bounding sphere. /// The transform to apply to the bounding sphere. /// The transformed bounding sphere. - public static void Transform(ref BoundingSphere value, ref Matrix transform, out BoundingSphere result) + public static void Transform( ref BoundingSphere value, ref Matrix transform, out BoundingSphere result ) { - Vec3.TransformCoordinate(ref value.Center, ref transform, out result.Center); + Vec3.TransformCoordinate( ref value.Center, ref transform, out result.Center ); var majorAxisLengthSquared = Math.Max( - (transform.M11 * transform.M11) + (transform.M12 * transform.M12) + (transform.M13 * transform.M13), Math.Max( - (transform.M21 * transform.M21) + (transform.M22 * transform.M22) + (transform.M23 * transform.M23), - (transform.M31 * transform.M31) + (transform.M32 * transform.M32) + (transform.M33 * transform.M33))); + ( transform.M11 * transform.M11 ) + ( transform.M12 * transform.M12 ) + ( transform.M13 * transform.M13 ), Math.Max( + ( transform.M21 * transform.M21 ) + ( transform.M22 * transform.M22 ) + ( transform.M23 * transform.M23 ), + ( transform.M31 * transform.M31 ) + ( transform.M32 * transform.M32 ) + ( transform.M33 * transform.M33 ) ) ); - result.Radius = value.Radius * (float)Math.Sqrt(majorAxisLengthSquared); + result.Radius = value.Radius * (float)Math.Sqrt( majorAxisLengthSquared ); } /// @@ -316,16 +317,16 @@ namespace math /// The first sphere to merge. /// The second sphere to merge. /// When the method completes, contains the newly constructed bounding sphere. - public static void Merge(ref BoundingSphere value1, ref BoundingSphere value2, out BoundingSphere result) + public static void Merge( ref BoundingSphere value1, ref BoundingSphere value2, out BoundingSphere result ) { // Pre-exit if one of the bounding sphere by assuming that a merge with an empty sphere is equivalent at taking the non-empty sphere - if (value1 == Empty) + if( value1 == Empty ) { result = value2; return; - } - - if (value2 == Empty) + } + + if( value2 == Empty ) { result = value1; return; @@ -337,26 +338,26 @@ namespace math float radius = value1.Radius; float radius2 = value2.Radius; - if (radius + radius2 >= length) + if( radius + radius2 >= length ) { - if (radius - radius2 >= length) + if( radius - radius2 >= length ) { result = value1; return; } - if (radius2 - radius >= length) + if( radius2 - radius >= length ) { result = value2; return; } } - Vec3 vector = difference * (1.0f / length); - float min = Math.Min(-radius, length - radius2); - float max = (Math.Max(radius, length + radius2) - min) * 0.5f; + Vec3 vector = difference * ( 1.0f / length ); + float min = Math.Min( -radius, length - radius2 ); + float max = ( Math.Max( radius, length + radius2 ) - min ) * 0.5f; - result.Center = value1.Center + vector * (max + min); + result.Center = value1.Center + vector * ( max + min ); result.Radius = max; } @@ -366,10 +367,10 @@ namespace math /// The first sphere to merge. /// The second sphere to merge. /// The newly constructed bounding sphere. - public static BoundingSphere Merge(BoundingSphere value1, BoundingSphere value2) + public static BoundingSphere Merge( BoundingSphere value1, BoundingSphere value2 ) { BoundingSphere result; - Merge(ref value1, ref value2, out result); + Merge( ref value1, ref value2, out result ); return result; } @@ -379,9 +380,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(BoundingSphere left, BoundingSphere right) + public static bool operator ==( BoundingSphere left, BoundingSphere right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -390,9 +391,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(BoundingSphere left, BoundingSphere right) + public static bool operator !=( BoundingSphere left, BoundingSphere right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -403,7 +404,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "Center:{0} Radius:{1}", Center.ToString(), Radius.ToString()); + return string.Format( CultureInfo.CurrentCulture, "Center:{0} Radius:{1}", Center.ToString(), Radius.ToString() ); } /// @@ -413,13 +414,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "Center:{0} Radius:{1}", Center.ToString(format, CultureInfo.CurrentCulture), - Radius.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "Center:{0} Radius:{1}", Center.ToString( format, CultureInfo.CurrentCulture ), + Radius.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -429,9 +430,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "Center:{0} Radius:{1}", Center.ToString(), Radius.ToString()); + return string.Format( formatProvider, "Center:{0} Radius:{1}", Center.ToString(), Radius.ToString() ); } /// @@ -442,20 +443,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "Center:{0} Radius:{1}", Center.ToString(format, formatProvider), - Radius.ToString(format, formatProvider)); + return string.Format( formatProvider, "Center:{0} Radius:{1}", Center.ToString( format, formatProvider ), + Radius.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -469,7 +470,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(BoundingSphere value) + public bool Equals( BoundingSphere value ) { return Center == value.Center && Radius == value.Radius; } @@ -481,15 +482,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((BoundingSphere)value); + return Equals( (BoundingSphere)value ); } #if SlimDX1xInterop diff --git a/math/Cent.cs b/math/Cent.cs index 6f799cc..74407e9 100644 --- a/math/Cent.cs +++ b/math/Cent.cs @@ -23,7 +23,7 @@ sealed public record Vector3Cm( Cm x, Cm y, Cm z ) /// Represents a fixed-point value in centimeters, stored as an integer. /// Implements INumber for full generic math support. /// -sealed public record Cm(int value) : INumber +sealed public record Cm( int value ) : INumber { // --- Constants and Identities --- @@ -31,88 +31,88 @@ sealed public record Cm(int value) : INumber /// Represents the multiplicative identity (1.0). /// The underlying value is 100 because 1.0 meter = 100 centimeters. /// - public static Cm One => new Cm(100); - public static Cm Zero => new Cm(0); + public static Cm One => new Cm( 100 ); + public static Cm Zero => new Cm( 0 ); public static int Radix => 10; public static Cm AdditiveIdentity => Zero; public static Cm MultiplicativeIdentity => One; - public float Float => ((float)value) * 0.01f; - public double Double => ((double)value) * 0.01; + public float Float => ( (float)value ) * 0.01f; + public double Double => ( (double)value ) * 0.01; // --- Static Conversion Methods --- - public static Cm From(float v) => new Cm((int)(v * 100.0f + 0.5f)); - public static Cm From(double v) => new Cm((int)(v * 100.0 + 0.5)); + public static Cm From( float v ) => new Cm( (int)( v * 100.0f + 0.5f ) ); + public static Cm From( double v ) => new Cm( (int)( v * 100.0 + 0.5 ) ); // --- Standard Functions --- - public static Cm Abs(Cm c) => new Cm(Math.Abs(c.value)); - public static Cm MaxMagnitude(Cm x, Cm y) => Abs(x) > Abs(y) ? x : y; - public static Cm MaxMagnitudeNumber(Cm x, Cm y) => MaxMagnitude(x, y); // Same for this type - public static Cm MinMagnitude(Cm x, Cm y) => Abs(x) < Abs(y) ? x : y; - public static Cm MinMagnitudeNumber(Cm x, Cm y) => MinMagnitude(x, y); // Same for this type + public static Cm Abs( Cm c ) => new Cm( Math.Abs( c.value ) ); + public static Cm MaxMagnitude( Cm x, Cm y ) => Abs( x ) > Abs( y ) ? x : y; + public static Cm MaxMagnitudeNumber( Cm x, Cm y ) => MaxMagnitude( x, y ); // Same for this type + public static Cm MinMagnitude( Cm x, Cm y ) => Abs( x ) < Abs( y ) ? x : y; + public static Cm MinMagnitudeNumber( Cm x, Cm y ) => MinMagnitude( x, y ); // Same for this type // --- Type Property Checks --- - public static bool IsCanonical(Cm c) => true; - public static bool IsComplexNumber(Cm c) => false; - public static bool IsEvenInteger(Cm c) => (c.value % 100 == 0) && (c.value / 100 % 2 == 0); - public static bool IsFinite(Cm c) => true; - public static bool IsImaginaryNumber(Cm c) => false; - public static bool IsInfinity(Cm c) => false; - public static bool IsInteger(Cm c) => c.value % 100 == 0; - public static bool IsNaN(Cm c) => false; - public static bool IsNegative(Cm c) => c.value < 0; - public static bool IsNegativeInfinity(Cm c) => false; - public static bool IsNormal(Cm c) => c.value != 0; - public static bool IsOddInteger(Cm c) => (c.value % 100 == 0) && (c.value / 100 % 2 != 0); - public static bool IsPositive(Cm c) => c.value > 0; - public static bool IsPositiveInfinity(Cm c) => false; - public static bool IsRealNumber(Cm c) => true; // It is a real number - public static bool IsSubnormal(Cm c) => false; - public static bool IsZero(Cm c) => c.value == 0; + public static bool IsCanonical( Cm c ) => true; + public static bool IsComplexNumber( Cm c ) => false; + public static bool IsEvenInteger( Cm c ) => ( c.value % 100 == 0 ) && ( c.value / 100 % 2 == 0 ); + public static bool IsFinite( Cm c ) => true; + public static bool IsImaginaryNumber( Cm c ) => false; + public static bool IsInfinity( Cm c ) => false; + public static bool IsInteger( Cm c ) => c.value % 100 == 0; + public static bool IsNaN( Cm c ) => false; + public static bool IsNegative( Cm c ) => c.value < 0; + public static bool IsNegativeInfinity( Cm c ) => false; + public static bool IsNormal( Cm c ) => c.value != 0; + public static bool IsOddInteger( Cm c ) => ( c.value % 100 == 0 ) && ( c.value / 100 % 2 != 0 ); + public static bool IsPositive( Cm c ) => c.value > 0; + public static bool IsPositiveInfinity( Cm c ) => false; + public static bool IsRealNumber( Cm c ) => true; // It is a real number + public static bool IsSubnormal( Cm c ) => false; + public static bool IsZero( Cm c ) => c.value == 0; // --- Parsing --- - public static Cm Parse(string s, IFormatProvider? provider) => Parse(s, NumberStyles.Number, provider); - public static Cm Parse(ReadOnlySpan s, IFormatProvider? provider) => Parse(s, NumberStyles.Number, provider); - public static Cm Parse(string s, NumberStyles style, IFormatProvider? provider) + public static Cm Parse( string s, IFormatProvider? provider ) => Parse( s, NumberStyles.Number, provider ); + public static Cm Parse( ReadOnlySpan s, IFormatProvider? provider ) => Parse( s, NumberStyles.Number, provider ); + public static Cm Parse( string s, NumberStyles style, IFormatProvider? provider ) { - if (TryParse(s, style, provider, out var result)) + if( TryParse( s, style, provider, out var result ) ) { return result; } - throw new FormatException($"Input string '{s}' was not in a correct format."); + throw new FormatException( $"Input string '{s}' was not in a correct format." ); } - public static Cm Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + public static Cm Parse( ReadOnlySpan s, NumberStyles style, IFormatProvider? provider ) { - if (TryParse(s, style, provider, out var result)) + if( TryParse( s, style, provider, out var result ) ) { return result; } - throw new FormatException($"Input string was not in a correct format."); + throw new FormatException( $"Input string was not in a correct format." ); } - public static bool TryParse([NotNullWhen(true)] string? s, IFormatProvider? provider, [MaybeNullWhen(false)] out Cm result) => TryParse(s, NumberStyles.Number, provider, out result); - public static bool TryParse(ReadOnlySpan s, IFormatProvider? provider, [MaybeNullWhen(false)] out Cm result) => TryParse(s, NumberStyles.Number, provider, out result); - public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen(false)] out Cm result) + public static bool TryParse( [NotNullWhen( true )] string? s, IFormatProvider? provider, [MaybeNullWhen( false )] out Cm result ) => TryParse( s, NumberStyles.Number, provider, out result ); + public static bool TryParse( ReadOnlySpan s, IFormatProvider? provider, [MaybeNullWhen( false )] out Cm result ) => TryParse( s, NumberStyles.Number, provider, out result ); + public static bool TryParse( [NotNullWhen( true )] string? s, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen( false )] out Cm result ) { - if (decimal.TryParse(s, style, provider, out decimal decValue)) + if( decimal.TryParse( s, style, provider, out decimal decValue ) ) { - result = new Cm((int)(decValue * 100m)); + result = new Cm( (int)( decValue * 100m ) ); return true; } result = Cm.Zero; return false; } - public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen(false)] out Cm result) + public static bool TryParse( ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen( false )] out Cm result ) { - if (decimal.TryParse(s, style, provider, out decimal decValue)) + if( decimal.TryParse( s, style, provider, out decimal decValue ) ) { - result = new Cm((int)(decValue * 100m)); + result = new Cm( (int)( decValue * 100m ) ); return true; } result = Cm.Zero; @@ -121,20 +121,20 @@ sealed public record Cm(int value) : INumber // --- Generic Type Conversion --- - public static bool TryConvertFromChecked(TOther value, out Cm result) where TOther : INumberBase + public static bool TryConvertFromChecked( TOther value, out Cm result ) where TOther : INumberBase { // For integer types, scale up. For floating point, convert. - if (TOther.IsInteger(value)) + if( TOther.IsInteger( value ) ) { try { checked { - result = new Cm(int.CreateChecked(value) * 100); + result = new Cm( int.CreateChecked( value ) * 100 ); return true; } } - catch (OverflowException) + catch( OverflowException ) { result = Cm.Zero; return false; @@ -142,22 +142,22 @@ sealed public record Cm(int value) : INumber } // Convert floating point types - if (typeof(TOther) == typeof(double)) + if( typeof( TOther ) == typeof( double ) ) { - double d = double.CreateChecked(value); - result = From(d); + double d = double.CreateChecked( value ); + result = From( d ); return true; } - if (typeof(TOther) == typeof(float)) + if( typeof( TOther ) == typeof( float ) ) { - float f = float.CreateChecked(value); - result = From(f); + float f = float.CreateChecked( value ); + result = From( f ); return true; } - if (typeof(TOther) == typeof(decimal)) + if( typeof( TOther ) == typeof( decimal ) ) { - decimal m = decimal.CreateChecked(value); - result = new Cm((int)(m * 100m)); + decimal m = decimal.CreateChecked( value ); + result = new Cm( (int)( m * 100m ) ); return true; } @@ -165,65 +165,65 @@ sealed public record Cm(int value) : INumber return false; } - public static bool TryConvertFromSaturating(TOther value, out Cm result) where TOther : INumberBase + public static bool TryConvertFromSaturating( TOther value, out Cm result ) where TOther : INumberBase { - if (TOther.IsInteger(value)) + if( TOther.IsInteger( value ) ) { - result = new Cm(int.CreateSaturating(value) * 100); + result = new Cm( int.CreateSaturating( value ) * 100 ); return true; } - if (typeof(TOther) == typeof(double)) + if( typeof( TOther ) == typeof( double ) ) { - double d = double.CreateSaturating(value); - result = From(d); + double d = double.CreateSaturating( value ); + result = From( d ); return true; } - if (typeof(TOther) == typeof(float)) + if( typeof( TOther ) == typeof( float ) ) { - float f = float.CreateSaturating(value); - result = From(f); + float f = float.CreateSaturating( value ); + result = From( f ); return true; } - if (typeof(TOther) == typeof(decimal)) + if( typeof( TOther ) == typeof( decimal ) ) { - decimal m = decimal.CreateSaturating(value); - result = new Cm((int)(m * 100m)); + decimal m = decimal.CreateSaturating( value ); + result = new Cm( (int)( m * 100m ) ); return true; } result = Cm.Zero; return false; } - public static bool TryConvertFromTruncating(TOther value, out Cm result) where TOther : INumberBase + public static bool TryConvertFromTruncating( TOther value, out Cm result ) where TOther : INumberBase { - if (TOther.IsInteger(value)) + if( TOther.IsInteger( value ) ) { - result = new Cm(int.CreateTruncating(value) * 100); + result = new Cm( int.CreateTruncating( value ) * 100 ); return true; } - if (typeof(TOther) == typeof(double)) + if( typeof( TOther ) == typeof( double ) ) { - double d = double.CreateTruncating(value); - result = From(d); + double d = double.CreateTruncating( value ); + result = From( d ); return true; } - if (typeof(TOther) == typeof(float)) + if( typeof( TOther ) == typeof( float ) ) { - float f = float.CreateTruncating(value); - result = From(f); + float f = float.CreateTruncating( value ); + result = From( f ); return true; } - if (typeof(TOther) == typeof(decimal)) + if( typeof( TOther ) == typeof( decimal ) ) { - decimal m = decimal.CreateTruncating(value); - result = new Cm((int)(m * 100m)); + decimal m = decimal.CreateTruncating( value ); + result = new Cm( (int)( m * 100m ) ); return true; } result = Cm.Zero; return false; } - public static bool TryConvertToChecked(Cm value, out TOther result) where TOther : INumberBase + public static bool TryConvertToChecked( Cm value, out TOther result ) where TOther : INumberBase { // Convert our value (a count of centimeters) to another type. // This typically involves scaling down by 100. @@ -231,109 +231,109 @@ sealed public record Cm(int value) : INumber { checked { - if (TOther.IsInteger(TOther.Zero)) + if( TOther.IsInteger( TOther.Zero ) ) { - result = TOther.CreateChecked(value.value / 100); + result = TOther.CreateChecked( value.value / 100 ); return true; } // For floating points, perform floating point division - result = TOther.CreateChecked(value.value) / TOther.CreateChecked(100); + result = TOther.CreateChecked( value.value ) / TOther.CreateChecked( 100 ); return true; } } - catch (OverflowException) + catch( OverflowException ) { result = default!; return false; } } - public static bool TryConvertToSaturating(Cm value, out TOther result) where TOther : INumberBase + public static bool TryConvertToSaturating( Cm value, out TOther result ) where TOther : INumberBase { - if (TOther.IsInteger(TOther.Zero)) + if( TOther.IsInteger( TOther.Zero ) ) { - result = TOther.CreateSaturating(value.value / 100); + result = TOther.CreateSaturating( value.value / 100 ); return true; } - result = TOther.CreateSaturating(value.value) / TOther.CreateSaturating(100); + result = TOther.CreateSaturating( value.value ) / TOther.CreateSaturating( 100 ); return true; } - public static bool TryConvertToTruncating(Cm value, out TOther result) where TOther : INumberBase + public static bool TryConvertToTruncating( Cm value, out TOther result ) where TOther : INumberBase { - if (TOther.IsInteger(TOther.Zero)) + if( TOther.IsInteger( TOther.Zero ) ) { - result = TOther.CreateTruncating(value.value / 100); + result = TOther.CreateTruncating( value.value / 100 ); return true; } - result = TOther.CreateTruncating(value.value) / TOther.CreateTruncating(100); + result = TOther.CreateTruncating( value.value ) / TOther.CreateTruncating( 100 ); return true; } // --- Comparison --- - public int CompareTo(object? obj) + public int CompareTo( object? obj ) { - if (obj is Cm other) + if( obj is Cm other ) { - return CompareTo(other); + return CompareTo( other ); } - return obj is null ? 1 : throw new ArgumentException("Object must be of type Cm.", nameof(obj)); + return obj is null ? 1 : throw new ArgumentException( "Object must be of type Cm.", nameof( obj ) ); } - public int CompareTo(Cm? other) => value.CompareTo(other?.value); + public int CompareTo( Cm? other ) => value.CompareTo( other?.value ); - public bool Equals(Cm? other) => value == other?.value; + public bool Equals( Cm? other ) => value == other?.value; public override int GetHashCode() => value.GetHashCode(); // --- Formatting --- - public override string ToString() => (value / 100.0).ToString("F2", CultureInfo.InvariantCulture); + public override string ToString() => ( value / 100.0 ).ToString( "F2", CultureInfo.InvariantCulture ); - public string ToString(string? format, IFormatProvider? formatProvider) + public string ToString( string? format, IFormatProvider? formatProvider ) { // Format as a floating point number - return (value / 100.0).ToString(format, formatProvider); + return ( value / 100.0 ).ToString( format, formatProvider ); } - public bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) + public bool TryFormat( Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider ) { - return (value / 100.0).TryFormat(destination, out charsWritten, format, provider); + return ( value / 100.0 ).TryFormat( destination, out charsWritten, format, provider ); } // --- Operators --- - public static Cm operator +(Cm c) => c; - public static Cm operator +(Cm left, Cm right) => new Cm(left.value + right.value); - public static Cm operator -(Cm c) => new Cm(-c.value); - public static Cm operator -(Cm left, Cm right) => new Cm(left.value - right.value); - public static Cm operator ++(Cm c) => new Cm(c.value + 1); - public static Cm operator --(Cm c) => new Cm(c.value - 1); + public static Cm operator +( Cm c ) => c; + public static Cm operator +( Cm left, Cm right ) => new Cm( left.value + right.value ); + public static Cm operator -( Cm c ) => new Cm( -c.value ); + public static Cm operator -( Cm left, Cm right ) => new Cm( left.value - right.value ); + public static Cm operator ++( Cm c ) => new Cm( c.value + 1 ); + public static Cm operator --( Cm c ) => new Cm( c.value - 1 ); // For fixed-point, multiplication/division require scaling - public static Cm operator *(Cm left, Cm right) + public static Cm operator *( Cm left, Cm right ) { // (a/100) * (b/100) = (a*b)/10000. To get back to our format, multiply by 100. // So, (a*b)/100. Use long to prevent intermediate overflow. - return new Cm((int)(((long)left.value * right.value) / 100)); + return new Cm( (int)( ( (long)left.value * right.value ) / 100 ) ); } - public static Cm operator /(Cm left, Cm right) + public static Cm operator /( Cm left, Cm right ) { // (a/100) / (b/100) = a/b. To get back to our format, multiply by 100. // So, (a*100)/b. Use long to prevent intermediate overflow. - return new Cm((int)(((long)left.value * 100) / right.value)); + return new Cm( (int)( ( (long)left.value * 100 ) / right.value ) ); } - public static Cm operator %(Cm left, Cm right) => new Cm(left.value % right.value); + public static Cm operator %( Cm left, Cm right ) => new Cm( left.value % right.value ); // --- Comparison Operators --- - public static bool operator <(Cm left, Cm right) => left.value < right.value; - public static bool operator >(Cm left, Cm right) => left.value > right.value; - public static bool operator <=(Cm left, Cm right) => left.value <= right.value; - public static bool operator >=(Cm left, Cm right) => left.value >= right.value; + public static bool operator <( Cm left, Cm right ) => left.value < right.value; + public static bool operator >( Cm left, Cm right ) => left.value > right.value; + public static bool operator <=( Cm left, Cm right ) => left.value <= right.value; + public static bool operator >=( Cm left, Cm right ) => left.value >= right.value; } /// @@ -344,22 +344,22 @@ public static class CentEx // --- Static Conversion Methods --- - public static Cm From(float v) => new Cm((int)(v * 100.0f + 0.5f)); - public static Cm From(double v) => new Cm((int)(v * 100.0 + 0.5)); + public static Cm From( float v ) => new Cm( (int)( v * 100.0f + 0.5f ) ); + public static Cm From( double v ) => new Cm( (int)( v * 100.0 + 0.5 ) ); //public static Cm Cm(this float r) => CentEx.From(r); //public static Cm Cm(this double r) => CentEx.From(r); - extension(float r) + extension( float r ) { public Cm Cm => CentEx.From( r ); } - extension(double r) + extension( double r ) { public Cm Cm => CentEx.From( r ); } -} \ No newline at end of file +} diff --git a/math/CollisionHelper.cs b/math/CollisionHelper.cs index 9748735..a4bd2f0 100644 --- a/math/CollisionHelper.cs +++ b/math/CollisionHelper.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -36,7 +36,7 @@ namespace math * at this time and not all shapes have a corresponding struct. Only the objects that have * a corresponding struct should come first in naming and in parameter order. The order of * complexity is as follows: - * + * * 1. Point * 2. Ray * 3. Segment @@ -67,7 +67,7 @@ namespace math /// The second vertex to test. /// The third vertex to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointPointTriangle(ref Vec3 point, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out Vec3 result) + public static void ClosestPointPointTriangle( ref Vec3 point, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out Vec3 result ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 136 @@ -77,9 +77,9 @@ namespace math Vec3 ac = vertex3 - vertex1; Vec3 ap = point - vertex1; - float d1 = Vec3.Dot(ab, ap); - float d2 = Vec3.Dot(ac, ap); - if (d1 <= 0.0f && d2 <= 0.0f) + float d1 = Vec3.Dot( ab, ap ); + float d2 = Vec3.Dot( ac, ap ); + if( d1 <= 0.0f && d2 <= 0.0f ) { result = vertex1; //Barycentric coordinates (1,0,0) return; @@ -87,9 +87,9 @@ namespace math //Check if P in vertex region outside B Vec3 bp = point - vertex2; - float d3 = Vec3.Dot(ab, bp); - float d4 = Vec3.Dot(ac, bp); - if (d3 >= 0.0f && d4 <= d3) + float d3 = Vec3.Dot( ab, bp ); + float d4 = Vec3.Dot( ac, bp ); + if( d3 >= 0.0f && d4 <= d3 ) { result = vertex2; // barycentric coordinates (0,1,0) return; @@ -97,18 +97,18 @@ namespace math //Check if P in edge region of AB, if so return projection of P onto AB float vc = d1 * d4 - d3 * d2; - if (vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f) + if( vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f ) { - float v = d1 / (d1 - d3); + float v = d1 / ( d1 - d3 ); result = vertex1 + v * ab; //Barycentric coordinates (1-v,v,0) return; } //Check if P in vertex region outside C Vec3 cp = point - vertex3; - float d5 = Vec3.Dot(ab, cp); - float d6 = Vec3.Dot(ac, cp); - if (d6 >= 0.0f && d5 <= d6) + float d5 = Vec3.Dot( ab, cp ); + float d6 = Vec3.Dot( ac, cp ); + if( d6 >= 0.0f && d5 <= d6 ) { result = vertex3; //Barycentric coordinates (0,0,1) return; @@ -116,24 +116,24 @@ namespace math //Check if P in edge region of AC, if so return projection of P onto AC float vb = d5 * d2 - d1 * d6; - if (vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f) + if( vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f ) { - float w = d2 / (d2 - d6); + float w = d2 / ( d2 - d6 ); result = vertex1 + w * ac; //Barycentric coordinates (1-w,0,w) return; } //Check if P in edge region of BC, if so return projection of P onto BC float va = d3 * d6 - d5 * d4; - if (va <= 0.0f && (d4 - d3) >= 0.0f && (d5 - d6) >= 0.0f) + if( va <= 0.0f && ( d4 - d3 ) >= 0.0f && ( d5 - d6 ) >= 0.0f ) { - float w = (d4 - d3) / ((d4 - d3) + (d5 - d6)); - result = vertex2 + w * (vertex3 - vertex2); //Barycentric coordinates (0,1-w,w) + float w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) ); + result = vertex2 + w * ( vertex3 - vertex2 ); //Barycentric coordinates (0,1-w,w) return; } //P inside face region. Compute Q through its barycentric coordinates (u,v,w) - float denom = 1.0f / (va + vb + vc); + float denom = 1.0f / ( va + vb + vc ); float v2 = vb * denom; float w2 = vc * denom; result = vertex1 + ab * v2 + ac * w2; //= u*vertex1 + v*vertex2 + w*vertex3, u = va * denom = 1.0f - v - w @@ -145,16 +145,16 @@ namespace math /// The plane to test. /// The point to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointPlanePoint(ref Plane plane, ref Vec3 point, out Vec3 result) + public static void ClosestPointPlanePoint( ref Plane plane, ref Vec3 point, out Vec3 result ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 126 float dot; - Vec3.Dot(ref plane.Normal, ref point, out dot); + Vec3.Dot( ref plane.Normal, ref point, out dot ); float t = dot - plane.D; - result = point - (t * plane.Normal); + result = point - ( t * plane.Normal ); } /// @@ -163,14 +163,14 @@ namespace math /// The box to test. /// The point to test. /// When the method completes, contains the closest point between the two objects. - public static void ClosestPointBoxPoint(ref BoundingBox box, ref Vec3 point, out Vec3 result) + public static void ClosestPointBoxPoint( ref BoundingBox box, ref Vec3 point, out Vec3 result ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 130 Vec3 temp; - Vec3.Max(ref point, ref box.Minimum, out temp); - Vec3.Min(ref temp, ref box.Maximum, out result); + Vec3.Max( ref point, ref box.Minimum, out temp ); + Vec3.Min( ref temp, ref box.Maximum, out result ); } /// @@ -180,13 +180,13 @@ namespace math /// The point to test. /// When the method completes, contains the closest point between the two objects; /// or, if the point is directly in the center of the sphere, contains . - public static void ClosestPointSpherePoint(ref BoundingSphere sphere, ref Vec3 point, out Vec3 result) + public static void ClosestPointSpherePoint( ref BoundingSphere sphere, ref Vec3 point, out Vec3 result ) { //Source: Jorgy343 //Reference: None //Get the unit direction from the sphere's center to the point. - Vec3.Subtract(ref point, ref sphere.Center, out result); + Vec3.Subtract( ref point, ref sphere.Center, out result ); result.Normalize(); //Multiply the unit direction by the sphere's radius to get a vector @@ -209,13 +209,13 @@ namespace math /// is the 'closest' point of intersection. This can also be considered is the deepest point of /// intersection. /// - public static void ClosestPointSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2, out Vec3 result) + public static void ClosestPointSphereSphere( ref BoundingSphere sphere1, ref BoundingSphere sphere2, out Vec3 result ) { //Source: Jorgy343 //Reference: None //Get the unit direction from the first sphere's center to the second sphere's center. - Vec3.Subtract(ref sphere2.Center, ref sphere1.Center, out result); + Vec3.Subtract( ref sphere2.Center, ref sphere1.Center, out result ); result.Normalize(); //Multiply the unit direction by the first sphere's radius to get a vector @@ -232,13 +232,13 @@ namespace math /// The plane to test. /// The point to test. /// The distance between the two objects. - public static float DistancePlanePoint(ref Plane plane, ref Vec3 point) + public static float DistancePlanePoint( ref Plane plane, ref Vec3 point ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 127 float dot; - Vec3.Dot(ref plane.Normal, ref point, out dot); + Vec3.Dot( ref plane.Normal, ref point, out dot ); return dot - plane.D; } @@ -248,29 +248,29 @@ namespace math /// The box to test. /// The point to test. /// The distance between the two objects. - public static float DistanceBoxPoint(ref BoundingBox box, ref Vec3 point) + public static float DistanceBoxPoint( ref BoundingBox box, ref Vec3 point ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 131 float distance = 0f; - if (point.X < box.Minimum.X) - distance += (box.Minimum.X - point.X) * (box.Minimum.X - point.X); - if (point.X > box.Maximum.X) - distance += (point.X - box.Maximum.X) * (point.X - box.Maximum.X); + if( point.X < box.Minimum.X ) + distance += ( box.Minimum.X - point.X ) * ( box.Minimum.X - point.X ); + if( point.X > box.Maximum.X ) + distance += ( point.X - box.Maximum.X ) * ( point.X - box.Maximum.X ); - if (point.Y < box.Minimum.Y) - distance += (box.Minimum.Y - point.Y) * (box.Minimum.Y - point.Y); - if (point.Y > box.Maximum.Y) - distance += (point.Y - box.Maximum.Y) * (point.Y - box.Maximum.Y); + if( point.Y < box.Minimum.Y ) + distance += ( box.Minimum.Y - point.Y ) * ( box.Minimum.Y - point.Y ); + if( point.Y > box.Maximum.Y ) + distance += ( point.Y - box.Maximum.Y ) * ( point.Y - box.Maximum.Y ); - if (point.Z < box.Minimum.Z) - distance += (box.Minimum.Z - point.Z) * (box.Minimum.Z - point.Z); - if (point.Z > box.Maximum.Z) - distance += (point.Z - box.Maximum.Z) * (point.Z - box.Maximum.Z); + if( point.Z < box.Minimum.Z ) + distance += ( box.Minimum.Z - point.Z ) * ( box.Minimum.Z - point.Z ); + if( point.Z > box.Maximum.Z ) + distance += ( point.Z - box.Maximum.Z ) * ( point.Z - box.Maximum.Z ); - return (float)Math.Sqrt(distance); + return (float)Math.Sqrt( distance ); } /// @@ -279,7 +279,7 @@ namespace math /// The first box to test. /// The second box to test. /// The distance between the two objects. - public static float DistanceBoxBox(ref BoundingBox box1, ref BoundingBox box2) + public static float DistanceBoxBox( ref BoundingBox box1, ref BoundingBox box2 ) { //Source: //Reference: @@ -287,42 +287,42 @@ namespace math float distance = 0f; //Distance for X. - if (box1.Minimum.X > box2.Maximum.X) + if( box1.Minimum.X > box2.Maximum.X ) { float delta = box2.Maximum.X - box1.Minimum.X; distance += delta * delta; } - else if (box2.Minimum.X > box1.Maximum.X) + else if( box2.Minimum.X > box1.Maximum.X ) { float delta = box1.Maximum.X - box2.Minimum.X; distance += delta * delta; } //Distance for Y. - if (box1.Minimum.Y > box2.Maximum.Y) + if( box1.Minimum.Y > box2.Maximum.Y ) { float delta = box2.Maximum.Y - box1.Minimum.Y; distance += delta * delta; } - else if (box2.Minimum.Y > box1.Maximum.Y) + else if( box2.Minimum.Y > box1.Maximum.Y ) { float delta = box1.Maximum.Y - box2.Minimum.Y; distance += delta * delta; } //Distance for Z. - if (box1.Minimum.Z > box2.Maximum.Z) + if( box1.Minimum.Z > box2.Maximum.Z ) { float delta = box2.Maximum.Z - box1.Minimum.Z; distance += delta * delta; } - else if (box2.Minimum.Z > box1.Maximum.Z) + else if( box2.Minimum.Z > box1.Maximum.Z ) { float delta = box1.Maximum.Z - box2.Minimum.Z; distance += delta * delta; } - return (float)Math.Sqrt(distance); + return (float)Math.Sqrt( distance ); } /// @@ -331,16 +331,16 @@ namespace math /// The sphere to test. /// The point to test. /// The distance between the two objects. - public static float DistanceSpherePoint(ref BoundingSphere sphere, ref Vec3 point) + public static float DistanceSpherePoint( ref BoundingSphere sphere, ref Vec3 point ) { //Source: Jorgy343 //Reference: None float distance; - Vec3.Distance(ref sphere.Center, ref point, out distance); + Vec3.Distance( ref sphere.Center, ref point, out distance ); distance -= sphere.Radius; - return Math.Max(distance, 0f); + return Math.Max( distance, 0f ); } /// @@ -349,16 +349,16 @@ namespace math /// The first sphere to test. /// The second sphere to test. /// The distance between the two objects. - public static float DistanceSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2) + public static float DistanceSphereSphere( ref BoundingSphere sphere1, ref BoundingSphere sphere2 ) { //Source: Jorgy343 //Reference: None float distance; - Vec3.Distance(ref sphere1.Center, ref sphere2.Center, out distance); + Vec3.Distance( ref sphere1.Center, ref sphere2.Center, out distance ); distance -= sphere1.Radius + sphere2.Radius; - return Math.Max(distance, 0f); + return Math.Max( distance, 0f ); } /// @@ -367,25 +367,25 @@ namespace math /// The ray to test. /// The point to test. /// Whether the two objects intersect. - public static bool RayIntersectsPoint(ref Ray ray, ref Vec3 point) + public static bool RayIntersectsPoint( ref Ray ray, ref Vec3 point ) { //Source: RayIntersectsSphere //Reference: None Vec3 m; - Vec3.Subtract(ref ray.Position, ref point, out m); + Vec3.Subtract( ref ray.Position, ref point, out m ); //Same thing as RayIntersectsSphere except that the radius of the sphere (point) //is the epsilon for zero. - float b = Vec3.Dot(m, ray.Direction); - float c = Vec3.Dot(m, m) - MathUtil.ZeroTolerance; + float b = Vec3.Dot( m, ray.Direction ); + float c = Vec3.Dot( m, m ) - MathUtil.ZeroTolerance; - if (c > 0f && b > 0f) + if( c > 0f && b > 0f ) return false; float discriminant = b * b - c; - if (discriminant < 0f) + if( discriminant < 0f ) return false; return true; @@ -409,23 +409,23 @@ namespace math /// of the second ray, det denotes the determinant of a matrix, x denotes the cross /// product, [ ] denotes a matrix, and || || denotes the length or magnitude of a vector. /// - public static bool RayIntersectsRay(ref Ray ray1, ref Ray ray2, out Vec3 point) + public static bool RayIntersectsRay( ref Ray ray1, ref Ray ray2, out Vec3 point ) { //Source: Real-Time Rendering, Third Edition //Reference: Page 780 Vec3 cross; - Vec3.Cross(ref ray1.Direction, ref ray2.Direction, out cross); + Vec3.Cross( ref ray1.Direction, ref ray2.Direction, out cross ); float denominator = cross.Length(); //Lines are parallel. - if (Math.Abs(denominator) < MathUtil.ZeroTolerance) + if( Math.Abs( denominator ) < MathUtil.ZeroTolerance ) { //Lines are parallel and on top of each other. - if (Math.Abs(ray2.Position.X - ray1.Position.X) < MathUtil.ZeroTolerance && - Math.Abs(ray2.Position.Y - ray1.Position.Y) < MathUtil.ZeroTolerance && - Math.Abs(ray2.Position.Z - ray1.Position.Z) < MathUtil.ZeroTolerance) + if( Math.Abs( ray2.Position.X - ray1.Position.X ) < MathUtil.ZeroTolerance && + Math.Abs( ray2.Position.Y - ray1.Position.Y ) < MathUtil.ZeroTolerance && + Math.Abs( ray2.Position.Z - ray1.Position.Z ) < MathUtil.ZeroTolerance ) { point = Vec3.Zero; return true; @@ -473,13 +473,13 @@ namespace math float t = dett / denominator; //The points of intersection. - Vec3 point1 = ray1.Position + (s * ray1.Direction); - Vec3 point2 = ray2.Position + (t * ray2.Direction); + Vec3 point1 = ray1.Position + ( s * ray1.Direction ); + Vec3 point2 = ray2.Position + ( t * ray2.Direction ); //If the points are not equal, no intersection has occurred. - if (Math.Abs(point2.X - point1.X) > MathUtil.ZeroTolerance || - Math.Abs(point2.Y - point1.Y) > MathUtil.ZeroTolerance || - Math.Abs(point2.Z - point1.Z) > MathUtil.ZeroTolerance) + if( Math.Abs( point2.X - point1.X ) > MathUtil.ZeroTolerance || + Math.Abs( point2.Y - point1.Y ) > MathUtil.ZeroTolerance || + Math.Abs( point2.Z - point1.Z ) > MathUtil.ZeroTolerance ) { point = Vec3.Zero; return false; @@ -497,27 +497,27 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersect. - public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out float distance) + public static bool RayIntersectsPlane( ref Ray ray, ref Plane plane, out float distance ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 175 float direction; - Vec3.Dot(ref plane.Normal, ref ray.Direction, out direction); + Vec3.Dot( ref plane.Normal, ref ray.Direction, out direction ); - if (Math.Abs(direction) < MathUtil.ZeroTolerance) + if( Math.Abs( direction ) < MathUtil.ZeroTolerance ) { distance = 0f; return false; } float position; - Vec3.Dot(ref plane.Normal, ref ray.Position, out position); - distance = (-plane.D - position) / direction; + Vec3.Dot( ref plane.Normal, ref ray.Position, out position ); + distance = ( -plane.D - position ) / direction; - if (distance < 0f) + if( distance < 0f ) { - if (distance < -MathUtil.ZeroTolerance) + if( distance < -MathUtil.ZeroTolerance ) { distance = 0; return false; @@ -537,19 +537,19 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out Vec3 point) + public static bool RayIntersectsPlane( ref Ray ray, ref Plane plane, out Vec3 point ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 175 float distance; - if (!RayIntersectsPlane(ref ray, ref plane, out distance)) + if( !RayIntersectsPlane( ref ray, ref plane, out distance ) ) { point = Vec3.Zero; return false; } - point = ray.Position + (ray.Direction * distance); + point = ray.Position + ( ray.Direction * distance ); return true; } @@ -570,7 +570,7 @@ namespace math /// the ray, no intersection is assumed to have happened. In both cases of assumptions, /// this method returns false. /// - public static bool RayIntersectsTriangle(ref Ray ray, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out float distance) + public static bool RayIntersectsTriangle( ref Ray ray, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out float distance ) { //Source: Fast Minimum Storage Ray / Triangle Intersection //Reference: http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf @@ -590,19 +590,19 @@ namespace math //Cross product of ray direction and edge2 - first part of determinant. Vec3 directioncrossedge2; - directioncrossedge2.X = (ray.Direction.Y * edge2.Z) - (ray.Direction.Z * edge2.Y); - directioncrossedge2.Y = (ray.Direction.Z * edge2.X) - (ray.Direction.X * edge2.Z); - directioncrossedge2.Z = (ray.Direction.X * edge2.Y) - (ray.Direction.Y * edge2.X); + directioncrossedge2.X = ( ray.Direction.Y * edge2.Z ) - ( ray.Direction.Z * edge2.Y ); + directioncrossedge2.Y = ( ray.Direction.Z * edge2.X ) - ( ray.Direction.X * edge2.Z ); + directioncrossedge2.Z = ( ray.Direction.X * edge2.Y ) - ( ray.Direction.Y * edge2.X ); //Compute the determinant. float determinant; //Dot product of edge1 and the first part of determinant. - determinant = (edge1.X * directioncrossedge2.X) + (edge1.Y * directioncrossedge2.Y) + (edge1.Z * directioncrossedge2.Z); + determinant = ( edge1.X * directioncrossedge2.X ) + ( edge1.Y * directioncrossedge2.Y ) + ( edge1.Z * directioncrossedge2.Z ); //If the ray is parallel to the triangle plane, there is no collision. //This also means that we are not culling, the ray may hit both the //back and the front of the triangle. - if (determinant > -MathUtil.ZeroTolerance && determinant < MathUtil.ZeroTolerance) + if( determinant > -MathUtil.ZeroTolerance && determinant < MathUtil.ZeroTolerance ) { distance = 0f; return false; @@ -617,11 +617,11 @@ namespace math distanceVector.Z = ray.Position.Z - vertex1.Z; float triangleU; - triangleU = (distanceVector.X * directioncrossedge2.X) + (distanceVector.Y * directioncrossedge2.Y) + (distanceVector.Z * directioncrossedge2.Z); + triangleU = ( distanceVector.X * directioncrossedge2.X ) + ( distanceVector.Y * directioncrossedge2.Y ) + ( distanceVector.Z * directioncrossedge2.Z ); triangleU *= inversedeterminant; //Make sure it is inside the triangle. - if (triangleU < 0f || triangleU > 1f) + if( triangleU < 0f || triangleU > 1f ) { distance = 0f; return false; @@ -629,16 +629,16 @@ namespace math //Calculate the V parameter of the intersection point. Vec3 distancecrossedge1; - distancecrossedge1.X = (distanceVector.Y * edge1.Z) - (distanceVector.Z * edge1.Y); - distancecrossedge1.Y = (distanceVector.Z * edge1.X) - (distanceVector.X * edge1.Z); - distancecrossedge1.Z = (distanceVector.X * edge1.Y) - (distanceVector.Y * edge1.X); + distancecrossedge1.X = ( distanceVector.Y * edge1.Z ) - ( distanceVector.Z * edge1.Y ); + distancecrossedge1.Y = ( distanceVector.Z * edge1.X ) - ( distanceVector.X * edge1.Z ); + distancecrossedge1.Z = ( distanceVector.X * edge1.Y ) - ( distanceVector.Y * edge1.X ); float triangleV; - triangleV = ((ray.Direction.X * distancecrossedge1.X) + (ray.Direction.Y * distancecrossedge1.Y)) + (ray.Direction.Z * distancecrossedge1.Z); + triangleV = ( ( ray.Direction.X * distancecrossedge1.X ) + ( ray.Direction.Y * distancecrossedge1.Y ) ) + ( ray.Direction.Z * distancecrossedge1.Z ); triangleV *= inversedeterminant; //Make sure it is inside the triangle. - if (triangleV < 0f || triangleU + triangleV > 1f) + if( triangleV < 0f || triangleU + triangleV > 1f ) { distance = 0f; return false; @@ -646,11 +646,11 @@ namespace math //Compute the distance along the ray to the triangle. float raydistance; - raydistance = (edge2.X * distancecrossedge1.X) + (edge2.Y * distancecrossedge1.Y) + (edge2.Z * distancecrossedge1.Z); + raydistance = ( edge2.X * distancecrossedge1.X ) + ( edge2.Y * distancecrossedge1.Y ) + ( edge2.Z * distancecrossedge1.Z ); raydistance *= inversedeterminant; //Is the triangle behind the ray origin? - if (raydistance < 0f) + if( raydistance < 0f ) { distance = 0f; return false; @@ -670,16 +670,16 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsTriangle(ref Ray ray, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out Vec3 point) + public static bool RayIntersectsTriangle( ref Ray ray, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out Vec3 point ) { float distance; - if (!RayIntersectsTriangle(ref ray, ref vertex1, ref vertex2, ref vertex3, out distance)) + if( !RayIntersectsTriangle( ref ray, ref vertex1, ref vertex2, ref vertex3, out distance ) ) { point = Vec3.Zero; return false; } - point = ray.Position + (ray.Direction * distance); + point = ray.Position + ( ray.Direction * distance ); return true; } @@ -692,13 +692,13 @@ namespace math /// The index of axis defining the normal of the rectangle in the world. This value should be 0, 1 or 2 /// The position of the intersection point in the world /// true if the ray and rectangle intersects. - public static bool RayIntersectsRectangle(ref Ray ray, ref Matrix rectangleWorldMatrix, ref Vec3 rectangleSize, int normalAxis, out Vec3 intersectionPoint) + public static bool RayIntersectsRectangle( ref Ray ray, ref Matrix rectangleWorldMatrix, ref Vec3 rectangleSize, int normalAxis, out Vec3 intersectionPoint ) { bool intersects; int testAxis1; int testAxis2; - switch (normalAxis) + switch( normalAxis ) { case 0: testAxis1 = 1; @@ -713,28 +713,28 @@ namespace math testAxis2 = 1; break; default: - throw new ArgumentOutOfRangeException("normalAxis"); + throw new ArgumentOutOfRangeException( "normalAxis" ); } - var rectanglePosition = new Vec3(rectangleWorldMatrix.M41, rectangleWorldMatrix.M42, rectangleWorldMatrix.M43); + var rectanglePosition = new Vec3( rectangleWorldMatrix.M41, rectangleWorldMatrix.M42, rectangleWorldMatrix.M43 ); var normalRowStart = normalAxis << 2; - var plane = new Plane(rectanglePosition, new Vec3(rectangleWorldMatrix[normalRowStart], rectangleWorldMatrix[normalRowStart + 1], rectangleWorldMatrix[normalRowStart + 2])); + var plane = new Plane( rectanglePosition, new Vec3( rectangleWorldMatrix[normalRowStart], rectangleWorldMatrix[normalRowStart + 1], rectangleWorldMatrix[normalRowStart + 2] ) ); - // early exist the planes were parallels - if (!plane.Intersects(ref ray, out intersectionPoint)) + // early exist the planes were parallels + if( !plane.Intersects( ref ray, out intersectionPoint ) ) return false; // the position of the intersection point with respect to the rectangle center var intersectionInRectangle = intersectionPoint - rectanglePosition; // optimization for the simple but very frequent case where the element is not rotated - if (rectangleWorldMatrix.M12 == 0 && rectangleWorldMatrix.M13 == 0 && + if( rectangleWorldMatrix.M12 == 0 && rectangleWorldMatrix.M13 == 0 && rectangleWorldMatrix.M21 == 0 && rectangleWorldMatrix.M23 == 0 && - rectangleWorldMatrix.M31 == 0 && rectangleWorldMatrix.M32 == 0) + rectangleWorldMatrix.M31 == 0 && rectangleWorldMatrix.M32 == 0 ) { - var halfSize1 = Math.Abs(rectangleWorldMatrix[(testAxis1 << 2) + testAxis1] * rectangleSize[testAxis1] / 2f); - var halfSize2 = Math.Abs(rectangleWorldMatrix[(testAxis2 << 2) + testAxis2] * rectangleSize[testAxis2] / 2f); + var halfSize1 = Math.Abs( rectangleWorldMatrix[( testAxis1 << 2 ) + testAxis1] * rectangleSize[testAxis1] / 2f ); + var halfSize2 = Math.Abs( rectangleWorldMatrix[( testAxis2 << 2 ) + testAxis2] * rectangleSize[testAxis2] / 2f ); intersects = -halfSize1 <= intersectionInRectangle[testAxis1] && intersectionInRectangle[testAxis1] <= halfSize1 && -halfSize2 <= intersectionInRectangle[testAxis2] && intersectionInRectangle[testAxis2] <= halfSize2; @@ -744,28 +744,28 @@ namespace math { // find the most significant component of the plane normal var normalTestIndex = 0; - for (int i = 1; i < 3; i++) + for( int i = 1; i < 3; i++ ) { - if (Math.Abs(plane.Normal[i]) > Math.Abs(plane.Normal[normalTestIndex])) + if( Math.Abs( plane.Normal[i] ) > Math.Abs( plane.Normal[normalTestIndex] ) ) normalTestIndex = i; } - var normalSign = Math.Sign(plane.Normal[normalTestIndex]); + var normalSign = Math.Sign( plane.Normal[normalTestIndex] ); // the base vector - var base1 = rectangleSize[testAxis1] * new Vec3(rectangleWorldMatrix[(testAxis1 << 2)], rectangleWorldMatrix[(testAxis1 << 2) + 1], rectangleWorldMatrix[(testAxis1 << 2) + 2]) / 2; - var base2 = rectangleSize[testAxis2] * new Vec3(rectangleWorldMatrix[(testAxis2 << 2)], rectangleWorldMatrix[(testAxis2 << 2) + 1], rectangleWorldMatrix[(testAxis2 << 2) + 2]) / 2; + var base1 = rectangleSize[testAxis1] * new Vec3( rectangleWorldMatrix[( testAxis1 << 2 )], rectangleWorldMatrix[( testAxis1 << 2 ) + 1], rectangleWorldMatrix[( testAxis1 << 2 ) + 2] ) / 2; + var base2 = rectangleSize[testAxis2] * new Vec3( rectangleWorldMatrix[( testAxis2 << 2 )], rectangleWorldMatrix[( testAxis2 << 2 ) + 1], rectangleWorldMatrix[( testAxis2 << 2 ) + 2] ) / 2; // build the first triangle and perform the test var v1 = -base1 - base2 - intersectionInRectangle; var v2 = +base1 - base2 - intersectionInRectangle; var v3 = +base1 + base2 - intersectionInRectangle; - intersects = Math.Sign(Vec3.Cross(v1, v2)[normalTestIndex]) == normalSign && - Math.Sign(Vec3.Cross(v2, v3)[normalTestIndex]) == normalSign && - Math.Sign(Vec3.Cross(v3, v1)[normalTestIndex]) == normalSign; + intersects = Math.Sign( Vec3.Cross( v1, v2 )[normalTestIndex] ) == normalSign && + Math.Sign( Vec3.Cross( v2, v3 )[normalTestIndex] ) == normalSign && + Math.Sign( Vec3.Cross( v3, v1 )[normalTestIndex] ) == normalSign; // early exit on success - if (intersects) + if( intersects ) return true; // build second triangle and perform the test @@ -773,9 +773,9 @@ namespace math v2 = +base1 + base2 - intersectionInRectangle; v3 = -base1 + base2 - intersectionInRectangle; - intersects = Math.Sign(Vec3.Cross(v1, v2)[normalTestIndex]) == normalSign && - Math.Sign(Vec3.Cross(v2, v3)[normalTestIndex]) == normalSign && - Math.Sign(Vec3.Cross(v3, v1)[normalTestIndex]) == normalSign; + intersects = Math.Sign( Vec3.Cross( v1, v2 )[normalTestIndex] ) == normalSign && + Math.Sign( Vec3.Cross( v2, v3 )[normalTestIndex] ) == normalSign && + Math.Sign( Vec3.Cross( v3, v1 )[normalTestIndex] ) == normalSign; } return intersects; @@ -789,7 +789,7 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out float distance) + public static bool RayIntersectsBox( ref Ray ray, ref BoundingBox box, out float distance ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 179 @@ -797,9 +797,9 @@ namespace math distance = 0f; float tmax = float.MaxValue; - if (Math.Abs(ray.Direction.X) < MathUtil.ZeroTolerance) + if( Math.Abs( ray.Direction.X ) < MathUtil.ZeroTolerance ) { - if (ray.Position.X < box.Minimum.X || ray.Position.X > box.Maximum.X) + if( ray.Position.X < box.Minimum.X || ray.Position.X > box.Maximum.X ) { distance = 0f; return false; @@ -808,29 +808,29 @@ namespace math else { float inverse = 1.0f / ray.Direction.X; - float t1 = (box.Minimum.X - ray.Position.X) * inverse; - float t2 = (box.Maximum.X - ray.Position.X) * inverse; + float t1 = ( box.Minimum.X - ray.Position.X ) * inverse; + float t2 = ( box.Maximum.X - ray.Position.X ) * inverse; - if (t1 > t2) + if( t1 > t2 ) { float temp = t1; t1 = t2; t2 = temp; } - distance = Math.Max(t1, distance); - tmax = Math.Min(t2, tmax); + distance = Math.Max( t1, distance ); + tmax = Math.Min( t2, tmax ); - if (distance > tmax) + if( distance > tmax ) { distance = 0f; return false; } } - if (Math.Abs(ray.Direction.Y) < MathUtil.ZeroTolerance) + if( Math.Abs( ray.Direction.Y ) < MathUtil.ZeroTolerance ) { - if (ray.Position.Y < box.Minimum.Y || ray.Position.Y > box.Maximum.Y) + if( ray.Position.Y < box.Minimum.Y || ray.Position.Y > box.Maximum.Y ) { distance = 0f; return false; @@ -839,29 +839,29 @@ namespace math else { float inverse = 1.0f / ray.Direction.Y; - float t1 = (box.Minimum.Y - ray.Position.Y) * inverse; - float t2 = (box.Maximum.Y - ray.Position.Y) * inverse; + float t1 = ( box.Minimum.Y - ray.Position.Y ) * inverse; + float t2 = ( box.Maximum.Y - ray.Position.Y ) * inverse; - if (t1 > t2) + if( t1 > t2 ) { float temp = t1; t1 = t2; t2 = temp; } - distance = Math.Max(t1, distance); - tmax = Math.Min(t2, tmax); + distance = Math.Max( t1, distance ); + tmax = Math.Min( t2, tmax ); - if (distance > tmax) + if( distance > tmax ) { distance = 0f; return false; } } - if (Math.Abs(ray.Direction.Z) < MathUtil.ZeroTolerance) + if( Math.Abs( ray.Direction.Z ) < MathUtil.ZeroTolerance ) { - if (ray.Position.Z < box.Minimum.Z || ray.Position.Z > box.Maximum.Z) + if( ray.Position.Z < box.Minimum.Z || ray.Position.Z > box.Maximum.Z ) { distance = 0f; return false; @@ -870,20 +870,20 @@ namespace math else { float inverse = 1.0f / ray.Direction.Z; - float t1 = (box.Minimum.Z - ray.Position.Z) * inverse; - float t2 = (box.Maximum.Z - ray.Position.Z) * inverse; + float t1 = ( box.Minimum.Z - ray.Position.Z ) * inverse; + float t2 = ( box.Maximum.Z - ray.Position.Z ) * inverse; - if (t1 > t2) + if( t1 > t2 ) { float temp = t1; t1 = t2; t2 = temp; } - distance = Math.Max(t1, distance); - tmax = Math.Min(t2, tmax); + distance = Math.Max( t1, distance ); + tmax = Math.Min( t2, tmax ); - if (distance > tmax) + if( distance > tmax ) { distance = 0f; return false; @@ -901,16 +901,16 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out Vec3 point) + public static bool RayIntersectsBox( ref Ray ray, ref BoundingBox box, out Vec3 point ) { float distance; - if (!RayIntersectsBox(ref ray, ref box, out distance)) + if( !RayIntersectsBox( ref ray, ref box, out distance ) ) { point = Vec3.Zero; return false; } - point = ray.Position + (ray.Direction * distance); + point = ray.Position + ( ray.Direction * distance ); return true; } @@ -922,18 +922,18 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out float distance) + public static bool RayIntersectsSphere( ref Ray ray, ref BoundingSphere sphere, out float distance ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 177 Vec3 m; - Vec3.Subtract(ref ray.Position, ref sphere.Center, out m); + Vec3.Subtract( ref ray.Position, ref sphere.Center, out m ); - float b = Vec3.Dot(m, ray.Direction); - float c = Vec3.Dot(m, m) - (sphere.Radius * sphere.Radius); + float b = Vec3.Dot( m, ray.Direction ); + float c = Vec3.Dot( m, m ) - ( sphere.Radius * sphere.Radius ); - if (c > 0f && b > 0f) + if( c > 0f && b > 0f ) { distance = 0f; return false; @@ -941,38 +941,38 @@ namespace math float discriminant = b * b - c; - if (discriminant < 0f) + if( discriminant < 0f ) { distance = 0f; return false; } - distance = -b - (float)Math.Sqrt(discriminant); + distance = -b - (float)Math.Sqrt( discriminant ); - if (distance < 0f) + if( distance < 0f ) distance = 0f; return true; } /// - /// Determines whether there is an intersection between a and a . + /// Determines whether there is an intersection between a and a . /// /// The ray to test. /// The sphere to test. /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out Vec3 point) + public static bool RayIntersectsSphere( ref Ray ray, ref BoundingSphere sphere, out Vec3 point ) { float distance; - if (!RayIntersectsSphere(ref ray, ref sphere, out distance)) + if( !RayIntersectsSphere( ref ray, ref sphere, out distance ) ) { point = Vec3.Zero; return false; } - point = ray.Position + (ray.Direction * distance); + point = ray.Position + ( ray.Direction * distance ); return true; } @@ -982,16 +982,16 @@ namespace math /// The plane to test. /// The point to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsPoint(ref Plane plane, ref Vec3 point) + public static PlaneIntersectionType PlaneIntersectsPoint( ref Plane plane, ref Vec3 point ) { float distance; - Vec3.Dot(ref plane.Normal, ref point, out distance); + Vec3.Dot( ref plane.Normal, ref point, out distance ); distance += plane.D; - if (distance > 0f) + if( distance > 0f ) return PlaneIntersectionType.Front; - if (distance < 0f) + if( distance < 0f ) return PlaneIntersectionType.Back; return PlaneIntersectionType.Intersecting; @@ -1003,17 +1003,17 @@ namespace math /// The first plane to test. /// The second plane to test. /// Whether the two objects intersected. - public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2) + public static bool PlaneIntersectsPlane( ref Plane plane1, ref Plane plane2 ) { Vec3 direction; - Vec3.Cross(ref plane1.Normal, ref plane2.Normal, out direction); + Vec3.Cross( ref plane1.Normal, ref plane2.Normal, out direction ); //If direction is the zero vector, the planes are parallel and possibly //coincident. It is not an intersection. The dot product will tell us. float denominator; - Vec3.Dot(ref direction, ref direction, out denominator); + Vec3.Dot( ref direction, ref direction, out denominator ); - if (Math.Abs(denominator) < MathUtil.ZeroTolerance) + if( Math.Abs( denominator ) < MathUtil.ZeroTolerance ) return false; return true; @@ -1032,23 +1032,23 @@ namespace math /// a line in three dimensions which has no real origin. The ray is considered valid when /// both the positive direction is used and when the negative direction is used. /// - public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2, out Ray line) + public static bool PlaneIntersectsPlane( ref Plane plane1, ref Plane plane2, out Ray line ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 207 Vec3 direction; - Vec3.Cross(ref plane1.Normal, ref plane2.Normal, out direction); + Vec3.Cross( ref plane1.Normal, ref plane2.Normal, out direction ); //If direction is the zero vector, the planes are parallel and possibly //coincident. It is not an intersection. The dot product will tell us. float denominator; - Vec3.Dot(ref direction, ref direction, out denominator); + Vec3.Dot( ref direction, ref direction, out denominator ); //We assume the planes are normalized, therefore the denominator //only serves as a parallel and coincident check. Otherwise we need //to deivide the point by the denominator. - if (Math.Abs(denominator) < MathUtil.ZeroTolerance) + if( Math.Abs( denominator ) < MathUtil.ZeroTolerance ) { line = new Ray(); return false; @@ -1056,7 +1056,7 @@ namespace math Vec3 point; Vec3 temp = plane1.D * plane2.Normal - plane2.D * plane1.Normal; - Vec3.Cross(ref temp, ref direction, out point); + Vec3.Cross( ref temp, ref direction, out point ); line.Position = point; line.Direction = direction; @@ -1073,19 +1073,19 @@ namespace math /// The second vertex of the triagnle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsTriangle(ref Plane plane, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public static PlaneIntersectionType PlaneIntersectsTriangle( ref Plane plane, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 207 - PlaneIntersectionType test1 = PlaneIntersectsPoint(ref plane, ref vertex1); - PlaneIntersectionType test2 = PlaneIntersectsPoint(ref plane, ref vertex2); - PlaneIntersectionType test3 = PlaneIntersectsPoint(ref plane, ref vertex3); + PlaneIntersectionType test1 = PlaneIntersectsPoint( ref plane, ref vertex1 ); + PlaneIntersectionType test2 = PlaneIntersectsPoint( ref plane, ref vertex2 ); + PlaneIntersectionType test3 = PlaneIntersectsPoint( ref plane, ref vertex3 ); - if (test1 == PlaneIntersectionType.Front && test2 == PlaneIntersectionType.Front && test3 == PlaneIntersectionType.Front) + if( test1 == PlaneIntersectionType.Front && test2 == PlaneIntersectionType.Front && test3 == PlaneIntersectionType.Front ) return PlaneIntersectionType.Front; - if (test1 == PlaneIntersectionType.Back && test2 == PlaneIntersectionType.Back && test3 == PlaneIntersectionType.Back) + if( test1 == PlaneIntersectionType.Back && test2 == PlaneIntersectionType.Back && test3 == PlaneIntersectionType.Back ) return PlaneIntersectionType.Back; return PlaneIntersectionType.Intersecting; @@ -1097,7 +1097,7 @@ namespace math /// The plane to test. /// The box to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsBox(ref Plane plane, ref BoundingBox box) + public static PlaneIntersectionType PlaneIntersectsBox( ref Plane plane, ref BoundingBox box ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 161 @@ -1105,22 +1105,22 @@ namespace math Vec3 min; Vec3 max; - max.X = (plane.Normal.X >= 0.0f) ? box.Minimum.X : box.Maximum.X; - max.Y = (plane.Normal.Y >= 0.0f) ? box.Minimum.Y : box.Maximum.Y; - max.Z = (plane.Normal.Z >= 0.0f) ? box.Minimum.Z : box.Maximum.Z; - min.X = (plane.Normal.X >= 0.0f) ? box.Maximum.X : box.Minimum.X; - min.Y = (plane.Normal.Y >= 0.0f) ? box.Maximum.Y : box.Minimum.Y; - min.Z = (plane.Normal.Z >= 0.0f) ? box.Maximum.Z : box.Minimum.Z; + max.X = ( plane.Normal.X >= 0.0f ) ? box.Minimum.X : box.Maximum.X; + max.Y = ( plane.Normal.Y >= 0.0f ) ? box.Minimum.Y : box.Maximum.Y; + max.Z = ( plane.Normal.Z >= 0.0f ) ? box.Minimum.Z : box.Maximum.Z; + min.X = ( plane.Normal.X >= 0.0f ) ? box.Maximum.X : box.Minimum.X; + min.Y = ( plane.Normal.Y >= 0.0f ) ? box.Maximum.Y : box.Minimum.Y; + min.Z = ( plane.Normal.Z >= 0.0f ) ? box.Maximum.Z : box.Minimum.Z; float distance; - Vec3.Dot(ref plane.Normal, ref max, out distance); + Vec3.Dot( ref plane.Normal, ref max, out distance ); - if (distance + plane.D > 0.0f) + if( distance + plane.D > 0.0f ) return PlaneIntersectionType.Front; - distance = Vec3.Dot(plane.Normal, min); + distance = Vec3.Dot( plane.Normal, min ); - if (distance + plane.D < 0.0f) + if( distance + plane.D < 0.0f ) return PlaneIntersectionType.Back; return PlaneIntersectionType.Intersecting; @@ -1132,19 +1132,19 @@ namespace math /// The plane to test. /// The sphere to test. /// Whether the two objects intersected. - public static PlaneIntersectionType PlaneIntersectsSphere(ref Plane plane, ref BoundingSphere sphere) + public static PlaneIntersectionType PlaneIntersectsSphere( ref Plane plane, ref BoundingSphere sphere ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 160 float distance; - Vec3.Dot(ref plane.Normal, ref sphere.Center, out distance); + Vec3.Dot( ref plane.Normal, ref sphere.Center, out distance ); distance += plane.D; - if (distance > sphere.Radius) + if( distance > sphere.Radius ) return PlaneIntersectionType.Front; - if (distance < -sphere.Radius) + if( distance < -sphere.Radius ) return PlaneIntersectionType.Back; return PlaneIntersectionType.Intersecting; @@ -1180,15 +1180,15 @@ namespace math /// The first box to test. /// The second box to test. /// Whether the two objects intersected. - public static bool BoxIntersectsBox(ref BoundingBox box1, ref BoundingBox box2) + public static bool BoxIntersectsBox( ref BoundingBox box1, ref BoundingBox box2 ) { - if (box1.Minimum.X > box2.Maximum.X || box2.Minimum.X > box1.Maximum.X) + if( box1.Minimum.X > box2.Maximum.X || box2.Minimum.X > box1.Maximum.X ) return false; - if (box1.Minimum.Y > box2.Maximum.Y || box2.Minimum.Y > box1.Maximum.Y) + if( box1.Minimum.Y > box2.Maximum.Y || box2.Minimum.Y > box1.Maximum.Y ) return false; - if (box1.Minimum.Z > box2.Maximum.Z || box2.Minimum.Z > box1.Maximum.Z) + if( box1.Minimum.Z > box2.Maximum.Z || box2.Minimum.Z > box1.Maximum.Z ) return false; return true; @@ -1200,14 +1200,14 @@ namespace math /// The box to test. /// The sphere to test. /// Whether the two objects intersected. - public static bool BoxIntersectsSphere(ref BoundingBox box, ref BoundingSphere sphere) + public static bool BoxIntersectsSphere( ref BoundingBox box, ref BoundingSphere sphere ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 166 Vec3 vector; - Vec3.Clamp(ref sphere.Center, ref box.Minimum, ref box.Maximum, out vector); - float distance = Vec3.DistanceSquared(sphere.Center, vector); + Vec3.Clamp( ref sphere.Center, ref box.Minimum, ref box.Maximum, out vector ); + float distance = Vec3.DistanceSquared( sphere.Center, vector ); return distance <= sphere.Radius * sphere.Radius; } @@ -1220,17 +1220,17 @@ namespace math /// The second vertex of the triagnle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public static bool SphereIntersectsTriangle(ref BoundingSphere sphere, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public static bool SphereIntersectsTriangle( ref BoundingSphere sphere, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { //Source: Real-Time Collision Detection by Christer Ericson //Reference: Page 167 Vec3 point; - ClosestPointPointTriangle(ref sphere.Center, ref vertex1, ref vertex2, ref vertex3, out point); + ClosestPointPointTriangle( ref sphere.Center, ref vertex1, ref vertex2, ref vertex3, out point ); Vec3 v = point - sphere.Center; float dot; - Vec3.Dot(ref v, ref v, out dot); + Vec3.Dot( ref v, ref v, out dot ); return dot <= sphere.Radius * sphere.Radius; } @@ -1241,10 +1241,10 @@ namespace math /// First sphere to test. /// Second sphere to test. /// Whether the two objects intersected. - public static bool SphereIntersectsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2) + public static bool SphereIntersectsSphere( ref BoundingSphere sphere1, ref BoundingSphere sphere2 ) { float radiisum = sphere1.Radius + sphere2.Radius; - return Vec3.DistanceSquared(sphere1.Center, sphere2.Center) <= radiisum * radiisum; + return Vec3.DistanceSquared( sphere1.Center, sphere2.Center ) <= radiisum * radiisum; } /// @@ -1253,11 +1253,11 @@ namespace math /// The box to test. /// The point to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsPoint(ref BoundingBox box, ref Vec3 point) + public static ContainmentType BoxContainsPoint( ref BoundingBox box, ref Vec3 point ) { - if (box.Minimum.X <= point.X && box.Maximum.X >= point.X && + if( box.Minimum.X <= point.X && box.Maximum.X >= point.X && box.Minimum.Y <= point.Y && box.Maximum.Y >= point.Y && - box.Minimum.Z <= point.Z && box.Maximum.Z >= point.Z) + box.Minimum.Z <= point.Z && box.Maximum.Z >= point.Z ) { return ContainmentType.Contains; } @@ -1296,20 +1296,20 @@ namespace math /// The first box to test. /// The second box to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsBox(ref BoundingBox box1, ref BoundingBox box2) + public static ContainmentType BoxContainsBox( ref BoundingBox box1, ref BoundingBox box2 ) { - if (box1.Maximum.X < box2.Minimum.X || box1.Minimum.X > box2.Maximum.X) + if( box1.Maximum.X < box2.Minimum.X || box1.Minimum.X > box2.Maximum.X ) return ContainmentType.Disjoint; - if (box1.Maximum.Y < box2.Minimum.Y || box1.Minimum.Y > box2.Maximum.Y) + if( box1.Maximum.Y < box2.Minimum.Y || box1.Minimum.Y > box2.Maximum.Y ) return ContainmentType.Disjoint; - if (box1.Maximum.Z < box2.Minimum.Z || box1.Minimum.Z > box2.Maximum.Z) + if( box1.Maximum.Z < box2.Minimum.Z || box1.Minimum.Z > box2.Maximum.Z ) return ContainmentType.Disjoint; - if (box1.Minimum.X <= box2.Minimum.X && (box2.Maximum.X <= box1.Maximum.X && - box1.Minimum.Y <= box2.Minimum.Y && box2.Maximum.Y <= box1.Maximum.Y) && - box1.Minimum.Z <= box2.Minimum.Z && box2.Maximum.Z <= box1.Maximum.Z) + if( box1.Minimum.X <= box2.Minimum.X && ( box2.Maximum.X <= box1.Maximum.X && + box1.Minimum.Y <= box2.Minimum.Y && box2.Maximum.Y <= box1.Maximum.Y ) && + box1.Minimum.Z <= box2.Minimum.Z && box2.Maximum.Z <= box1.Maximum.Z ) { return ContainmentType.Contains; } @@ -1323,18 +1323,18 @@ namespace math /// The box to test. /// The sphere to test. /// The type of containment the two objects have. - public static ContainmentType BoxContainsSphere(ref BoundingBox box, ref BoundingSphere sphere) + public static ContainmentType BoxContainsSphere( ref BoundingBox box, ref BoundingSphere sphere ) { Vec3 vector; - Vec3.Clamp(ref sphere.Center, ref box.Minimum, ref box.Maximum, out vector); - float distance = Vec3.DistanceSquared(sphere.Center, vector); + Vec3.Clamp( ref sphere.Center, ref box.Minimum, ref box.Maximum, out vector ); + float distance = Vec3.DistanceSquared( sphere.Center, vector ); - if (distance > sphere.Radius * sphere.Radius) + if( distance > sphere.Radius * sphere.Radius ) return ContainmentType.Disjoint; - if (((box.Minimum.X + sphere.Radius <= sphere.Center.X) && (sphere.Center.X <= box.Maximum.X - sphere.Radius) && (box.Maximum.X - box.Minimum.X > sphere.Radius)) && - ((box.Minimum.Y + sphere.Radius <= sphere.Center.Y) && (sphere.Center.Y <= box.Maximum.Y - sphere.Radius) && (box.Maximum.Y - box.Minimum.Y > sphere.Radius)) && - ((box.Minimum.Z + sphere.Radius <= sphere.Center.Z) && (sphere.Center.Z <= box.Maximum.Z - sphere.Radius) && (box.Maximum.Z - box.Minimum.Z > sphere.Radius))) + if( ( ( box.Minimum.X + sphere.Radius <= sphere.Center.X ) && ( sphere.Center.X <= box.Maximum.X - sphere.Radius ) && ( box.Maximum.X - box.Minimum.X > sphere.Radius ) ) && + ( ( box.Minimum.Y + sphere.Radius <= sphere.Center.Y ) && ( sphere.Center.Y <= box.Maximum.Y - sphere.Radius ) && ( box.Maximum.Y - box.Minimum.Y > sphere.Radius ) ) && + ( ( box.Minimum.Z + sphere.Radius <= sphere.Center.Z ) && ( sphere.Center.Z <= box.Maximum.Z - sphere.Radius ) && ( box.Maximum.Z - box.Minimum.Z > sphere.Radius ) ) ) { return ContainmentType.Contains; } @@ -1348,9 +1348,9 @@ namespace math /// The sphere to test. /// The point to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsPoint(ref BoundingSphere sphere, ref Vec3 point) + public static ContainmentType SphereContainsPoint( ref BoundingSphere sphere, ref Vec3 point ) { - if (Vec3.DistanceSquared(point, sphere.Center) <= sphere.Radius * sphere.Radius) + if( Vec3.DistanceSquared( point, sphere.Center ) <= sphere.Radius * sphere.Radius ) return ContainmentType.Contains; return ContainmentType.Disjoint; @@ -1364,19 +1364,19 @@ namespace math /// The second vertex of the triagnle to test. /// The third vertex of the triangle to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsTriangle(ref BoundingSphere sphere, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public static ContainmentType SphereContainsTriangle( ref BoundingSphere sphere, ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { //Source: Jorgy343 //Reference: None - ContainmentType test1 = SphereContainsPoint(ref sphere, ref vertex1); - ContainmentType test2 = SphereContainsPoint(ref sphere, ref vertex2); - ContainmentType test3 = SphereContainsPoint(ref sphere, ref vertex3); + ContainmentType test1 = SphereContainsPoint( ref sphere, ref vertex1 ); + ContainmentType test2 = SphereContainsPoint( ref sphere, ref vertex2 ); + ContainmentType test3 = SphereContainsPoint( ref sphere, ref vertex3 ); - if (test1 == ContainmentType.Contains && test2 == ContainmentType.Contains && test3 == ContainmentType.Contains) + if( test1 == ContainmentType.Contains && test2 == ContainmentType.Contains && test3 == ContainmentType.Contains ) return ContainmentType.Contains; - if (SphereIntersectsTriangle(ref sphere, ref vertex1, ref vertex2, ref vertex3)) + if( SphereIntersectsTriangle( ref sphere, ref vertex1, ref vertex2, ref vertex3 ) ) return ContainmentType.Intersects; return ContainmentType.Disjoint; @@ -1388,11 +1388,11 @@ namespace math /// The sphere to test. /// The box to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsBox(ref BoundingSphere sphere, ref BoundingBox box) + public static ContainmentType SphereContainsBox( ref BoundingSphere sphere, ref BoundingBox box ) { Vec3 vector; - if (!BoxIntersectsSphere(ref box, ref sphere)) + if( !BoxIntersectsSphere( ref box, ref sphere ) ) return ContainmentType.Disjoint; float radiussquared = sphere.Radius * sphere.Radius; @@ -1400,56 +1400,56 @@ namespace math vector.Y = sphere.Center.Y - box.Maximum.Y; vector.Z = sphere.Center.Z - box.Maximum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Maximum.X; vector.Y = sphere.Center.Y - box.Maximum.Y; vector.Z = sphere.Center.Z - box.Maximum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Maximum.X; vector.Y = sphere.Center.Y - box.Minimum.Y; vector.Z = sphere.Center.Z - box.Maximum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Minimum.X; vector.Y = sphere.Center.Y - box.Minimum.Y; vector.Z = sphere.Center.Z - box.Maximum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Minimum.X; vector.Y = sphere.Center.Y - box.Maximum.Y; vector.Z = sphere.Center.Z - box.Minimum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Maximum.X; vector.Y = sphere.Center.Y - box.Maximum.Y; vector.Z = sphere.Center.Z - box.Minimum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Maximum.X; vector.Y = sphere.Center.Y - box.Minimum.Y; vector.Z = sphere.Center.Z - box.Minimum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; vector.X = sphere.Center.X - box.Minimum.X; vector.Y = sphere.Center.Y - box.Minimum.Y; vector.Z = sphere.Center.Z - box.Minimum.Z; - if (vector.LengthSquared() > radiussquared) + if( vector.LengthSquared() > radiussquared ) return ContainmentType.Intersects; return ContainmentType.Contains; @@ -1461,14 +1461,14 @@ namespace math /// The first sphere to test. /// The second sphere to test. /// The type of containment the two objects have. - public static ContainmentType SphereContainsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2) + public static ContainmentType SphereContainsSphere( ref BoundingSphere sphere1, ref BoundingSphere sphere2 ) { - float distance = Vec3.Distance(sphere1.Center, sphere2.Center); + float distance = Vec3.Distance( sphere1.Center, sphere2.Center ); - if (sphere1.Radius + sphere2.Radius < distance) + if( sphere1.Radius + sphere2.Radius < distance ) return ContainmentType.Disjoint; - if (sphere1.Radius - sphere2.Radius < distance) + if( sphere1.Radius - sphere2.Radius < distance ) return ContainmentType.Intersects; return ContainmentType.Contains; @@ -1481,21 +1481,21 @@ namespace math /// The frustum. /// The bounding box ext. /// true if XXXX, false otherwise. - public static bool FrustumContainsBox(ref BoundingFrustum frustum, ref BoundingBoxExt boundingBoxExt) + public static bool FrustumContainsBox( ref BoundingFrustum frustum, ref BoundingBoxExt boundingBoxExt ) { unsafe { - fixed (Plane* planeStart = &frustum.LeftPlane) + fixed( Plane* planeStart = &frustum.LeftPlane ) { var plane = planeStart; - for (int i = 0; i < 6; ++i) + for( int i = 0; i < 6; ++i ) { // Previous code: - if (Vec3.Dot(boundingBoxExt.Center, plane->Normal) - + boundingBoxExt.Extent.X * Math.Abs(plane->Normal.X) - + boundingBoxExt.Extent.Y * Math.Abs(plane->Normal.Y) - + boundingBoxExt.Extent.Z * Math.Abs(plane->Normal.Z) - <= -plane->D) + if( Vec3.Dot( boundingBoxExt.Center, plane->Normal ) + + boundingBoxExt.Extent.X * Math.Abs( plane->Normal.X ) + + boundingBoxExt.Extent.Y * Math.Abs( plane->Normal.Y ) + + boundingBoxExt.Extent.Z * Math.Abs( plane->Normal.Z ) + <= -plane->D ) return false; plane++; } @@ -1503,49 +1503,49 @@ namespace math return true; } -/* - unsafe - { - fixed (Plane* planeStart = &frustum.LeftPlane) - fixed (Vector3* pExtent = &boundingBoxExt.Extent) - { - var plane = planeStart; - for (int i = 0; i < 6; ++i) - { - // Previous code: - //if (Vector3.Dot(boundingBoxExt.Center, plane->Normal) - // + boundingBoxExt.Extent.X * Math.Abs(plane->Normal.X) - // + boundingBoxExt.Extent.Y * Math.Abs(plane->Normal.Y) - // + boundingBoxExt.Extent.Z * Math.Abs(plane->Normal.Z) - // <= -plane->D) + /* + unsafe + { + fixed (Plane* planeStart = &frustum.LeftPlane) + fixed (Vector3* pExtent = &boundingBoxExt.Extent) + { + var plane = planeStart; + for (int i = 0; i < 6; ++i) + { + // Previous code: + //if (Vector3.Dot(boundingBoxExt.Center, plane->Normal) + // + boundingBoxExt.Extent.X * Math.Abs(plane->Normal.X) + // + boundingBoxExt.Extent.Y * Math.Abs(plane->Normal.Y) + // + boundingBoxExt.Extent.Z * Math.Abs(plane->Normal.Z) + // <= -plane->D) - // Optimized version (only 1 dot and cheaper Math.Abs) - // https://fgiesen.wordpress.com/2010/10/17/view-frustum-culling/ - // return dot3(center, plane) + dot3(extent, absPlane) <= -plane.w; - // or - // vector4 signFlip = componentwise_and(plane, 0x80000000); - // vector3 centerOffset = xor(extent, signFlip) - // dot3(center + centerOffset, plane) <= -plane.w; + // Optimized version (only 1 dot and cheaper Math.Abs) + // https://fgiesen.wordpress.com/2010/10/17/view-frustum-culling/ + // return dot3(center, plane) + dot3(extent, absPlane) <= -plane.w; + // or + // vector4 signFlip = componentwise_and(plane, 0x80000000); + // vector3 centerOffset = xor(extent, signFlip) + // dot3(center + centerOffset, plane) <= -plane.w; - uint val = (((uint*)&plane->Normal)[0] & 0x80000000) ^ ((uint*)pExtent)[0]; - var dist = plane->Normal.X * ((*(float*)(&val)) + boundingBoxExt.Center.X); + uint val = (((uint*)&plane->Normal)[0] & 0x80000000) ^ ((uint*)pExtent)[0]; + var dist = plane->Normal.X * ((*(float*)(&val)) + boundingBoxExt.Center.X); - val = (((uint*)&plane->Normal)[1] & 0x80000000) ^ ((uint*)pExtent)[1]; - dist += plane->Normal.Y * ((*(float*)(&val)) + boundingBoxExt.Center.Y); + val = (((uint*)&plane->Normal)[1] & 0x80000000) ^ ((uint*)pExtent)[1]; + dist += plane->Normal.Y * ((*(float*)(&val)) + boundingBoxExt.Center.Y); - val = (((uint*)&plane->Normal)[2] & 0x80000000) ^ ((uint*)pExtent)[2]; - dist += plane->Normal.Z * ((*(float*)(&val)) + boundingBoxExt.Center.Z); + val = (((uint*)&plane->Normal)[2] & 0x80000000) ^ ((uint*)pExtent)[2]; + dist += plane->Normal.Z * ((*(float*)(&val)) + boundingBoxExt.Center.Z); - if (dist <= -plane->D) - return false; + if (dist <= -plane->D) + return false; - plane++; - } - } + plane++; + } + } - return true; - } - */ + return true; + } + */ } } } diff --git a/math/Color.Palette.cs b/math/Color.Palette.cs index 21bf89b..27b0457 100644 --- a/math/Color.Palette.cs +++ b/math/Color.Palette.cs @@ -10,716 +10,716 @@ namespace math /// /// Zero color. /// - public static readonly Color Zero = Color.FromBgra(0x00000000); + public static readonly Color Zero = Color.FromBgra( 0x00000000 ); /// /// Transparent color. /// - public static readonly Color Transparent = Color.FromBgra(0x00000000); + public static readonly Color Transparent = Color.FromBgra( 0x00000000 ); /// /// AliceBlue color. /// - public static readonly Color AliceBlue = Color.FromBgra(0xFFF0F8FF); + public static readonly Color AliceBlue = Color.FromBgra( 0xFFF0F8FF ); /// /// AntiqueWhite color. /// - public static readonly Color AntiqueWhite = Color.FromBgra(0xFFFAEBD7); + public static readonly Color AntiqueWhite = Color.FromBgra( 0xFFFAEBD7 ); /// /// Aqua color. /// - public static readonly Color Aqua = Color.FromBgra(0xFF00FFFF); + public static readonly Color Aqua = Color.FromBgra( 0xFF00FFFF ); /// /// Aquamarine color. /// - public static readonly Color Aquamarine = Color.FromBgra(0xFF7FFFD4); + public static readonly Color Aquamarine = Color.FromBgra( 0xFF7FFFD4 ); /// /// Azure color. /// - public static readonly Color Azure = Color.FromBgra(0xFFF0FFFF); + public static readonly Color Azure = Color.FromBgra( 0xFFF0FFFF ); /// /// Beige color. /// - public static readonly Color Beige = Color.FromBgra(0xFFF5F5DC); + public static readonly Color Beige = Color.FromBgra( 0xFFF5F5DC ); /// /// Bisque color. /// - public static readonly Color Bisque = Color.FromBgra(0xFFFFE4C4); + public static readonly Color Bisque = Color.FromBgra( 0xFFFFE4C4 ); /// /// Black color. /// - public static readonly Color Black = Color.FromBgra(0xFF000000); + public static readonly Color Black = Color.FromBgra( 0xFF000000 ); /// /// BlanchedAlmond color. /// - public static readonly Color BlanchedAlmond = Color.FromBgra(0xFFFFEBCD); + public static readonly Color BlanchedAlmond = Color.FromBgra( 0xFFFFEBCD ); /// /// Blue color. /// - public static readonly Color Blue = Color.FromBgra(0xFF0000FF); + public static readonly Color Blue = Color.FromBgra( 0xFF0000FF ); /// /// BlueViolet color. /// - public static readonly Color BlueViolet = Color.FromBgra(0xFF8A2BE2); + public static readonly Color BlueViolet = Color.FromBgra( 0xFF8A2BE2 ); /// /// Brown color. /// - public static readonly Color Brown = Color.FromBgra(0xFFA52A2A); + public static readonly Color Brown = Color.FromBgra( 0xFFA52A2A ); /// /// BurlyWood color. /// - public static readonly Color BurlyWood = Color.FromBgra(0xFFDEB887); + public static readonly Color BurlyWood = Color.FromBgra( 0xFFDEB887 ); /// /// CadetBlue color. /// - public static readonly Color CadetBlue = Color.FromBgra(0xFF5F9EA0); + public static readonly Color CadetBlue = Color.FromBgra( 0xFF5F9EA0 ); /// /// Chartreuse color. /// - public static readonly Color Chartreuse = Color.FromBgra(0xFF7FFF00); + public static readonly Color Chartreuse = Color.FromBgra( 0xFF7FFF00 ); /// /// Chocolate color. /// - public static readonly Color Chocolate = Color.FromBgra(0xFFD2691E); + public static readonly Color Chocolate = Color.FromBgra( 0xFFD2691E ); /// /// Coral color. /// - public static readonly Color Coral = Color.FromBgra(0xFFFF7F50); + public static readonly Color Coral = Color.FromBgra( 0xFFFF7F50 ); /// /// CornflowerBlue color. /// - public static readonly Color CornflowerBlue = Color.FromBgra(0xFF6495ED); + public static readonly Color CornflowerBlue = Color.FromBgra( 0xFF6495ED ); /// /// Cornsilk color. /// - public static readonly Color Cornsilk = Color.FromBgra(0xFFFFF8DC); + public static readonly Color Cornsilk = Color.FromBgra( 0xFFFFF8DC ); /// /// Crimson color. /// - public static readonly Color Crimson = Color.FromBgra(0xFFDC143C); + public static readonly Color Crimson = Color.FromBgra( 0xFFDC143C ); /// /// Cyan color. /// - public static readonly Color Cyan = Color.FromBgra(0xFF00FFFF); + public static readonly Color Cyan = Color.FromBgra( 0xFF00FFFF ); /// /// DarkBlue color. /// - public static readonly Color DarkBlue = Color.FromBgra(0xFF00008B); + public static readonly Color DarkBlue = Color.FromBgra( 0xFF00008B ); /// /// DarkCyan color. /// - public static readonly Color DarkCyan = Color.FromBgra(0xFF008B8B); + public static readonly Color DarkCyan = Color.FromBgra( 0xFF008B8B ); /// /// DarkGoldenrod color. /// - public static readonly Color DarkGoldenrod = Color.FromBgra(0xFFB8860B); + public static readonly Color DarkGoldenrod = Color.FromBgra( 0xFFB8860B ); /// /// DarkGray color. /// - public static readonly Color DarkGray = Color.FromBgra(0xFFA9A9A9); + public static readonly Color DarkGray = Color.FromBgra( 0xFFA9A9A9 ); /// /// DarkGreen color. /// - public static readonly Color DarkGreen = Color.FromBgra(0xFF006400); + public static readonly Color DarkGreen = Color.FromBgra( 0xFF006400 ); /// /// DarkKhaki color. /// - public static readonly Color DarkKhaki = Color.FromBgra(0xFFBDB76B); + public static readonly Color DarkKhaki = Color.FromBgra( 0xFFBDB76B ); /// /// DarkMagenta color. /// - public static readonly Color DarkMagenta = Color.FromBgra(0xFF8B008B); + public static readonly Color DarkMagenta = Color.FromBgra( 0xFF8B008B ); /// /// DarkOliveGreen color. /// - public static readonly Color DarkOliveGreen = Color.FromBgra(0xFF556B2F); + public static readonly Color DarkOliveGreen = Color.FromBgra( 0xFF556B2F ); /// /// DarkOrange color. /// - public static readonly Color DarkOrange = Color.FromBgra(0xFFFF8C00); + public static readonly Color DarkOrange = Color.FromBgra( 0xFFFF8C00 ); /// /// DarkOrchid color. /// - public static readonly Color DarkOrchid = Color.FromBgra(0xFF9932CC); + public static readonly Color DarkOrchid = Color.FromBgra( 0xFF9932CC ); /// /// DarkRed color. /// - public static readonly Color DarkRed = Color.FromBgra(0xFF8B0000); + public static readonly Color DarkRed = Color.FromBgra( 0xFF8B0000 ); /// /// DarkSalmon color. /// - public static readonly Color DarkSalmon = Color.FromBgra(0xFFE9967A); + public static readonly Color DarkSalmon = Color.FromBgra( 0xFFE9967A ); /// /// DarkSeaGreen color. /// - public static readonly Color DarkSeaGreen = Color.FromBgra(0xFF8FBC8B); + public static readonly Color DarkSeaGreen = Color.FromBgra( 0xFF8FBC8B ); /// /// DarkSlateBlue color. /// - public static readonly Color DarkSlateBlue = Color.FromBgra(0xFF483D8B); + public static readonly Color DarkSlateBlue = Color.FromBgra( 0xFF483D8B ); /// /// DarkSlateGray color. /// - public static readonly Color DarkSlateGray = Color.FromBgra(0xFF2F4F4F); + public static readonly Color DarkSlateGray = Color.FromBgra( 0xFF2F4F4F ); /// /// DarkTurquoise color. /// - public static readonly Color DarkTurquoise = Color.FromBgra(0xFF00CED1); + public static readonly Color DarkTurquoise = Color.FromBgra( 0xFF00CED1 ); /// /// DarkViolet color. /// - public static readonly Color DarkViolet = Color.FromBgra(0xFF9400D3); + public static readonly Color DarkViolet = Color.FromBgra( 0xFF9400D3 ); /// /// DeepPink color. /// - public static readonly Color DeepPink = Color.FromBgra(0xFFFF1493); + public static readonly Color DeepPink = Color.FromBgra( 0xFFFF1493 ); /// /// DeepSkyBlue color. /// - public static readonly Color DeepSkyBlue = Color.FromBgra(0xFF00BFFF); + public static readonly Color DeepSkyBlue = Color.FromBgra( 0xFF00BFFF ); /// /// DimGray color. /// - public static readonly Color DimGray = Color.FromBgra(0xFF696969); + public static readonly Color DimGray = Color.FromBgra( 0xFF696969 ); /// /// VeryDimGray color. /// - public static readonly Color VeryDimGray = Color.FromBgra(0xFF404040); + public static readonly Color VeryDimGray = Color.FromBgra( 0xFF404040 ); /// /// DodgerBlue color. /// - public static readonly Color DodgerBlue = Color.FromBgra(0xFF1E90FF); + public static readonly Color DodgerBlue = Color.FromBgra( 0xFF1E90FF ); /// /// Firebrick color. /// - public static readonly Color Firebrick = Color.FromBgra(0xFFB22222); + public static readonly Color Firebrick = Color.FromBgra( 0xFFB22222 ); /// /// FloralWhite color. /// - public static readonly Color FloralWhite = Color.FromBgra(0xFFFFFAF0); + public static readonly Color FloralWhite = Color.FromBgra( 0xFFFFFAF0 ); /// /// ForestGreen color. /// - public static readonly Color ForestGreen = Color.FromBgra(0xFF228B22); + public static readonly Color ForestGreen = Color.FromBgra( 0xFF228B22 ); /// /// Fuchsia color. /// - public static readonly Color Fuchsia = Color.FromBgra(0xFFFF00FF); + public static readonly Color Fuchsia = Color.FromBgra( 0xFFFF00FF ); /// /// Gainsboro color. /// - public static readonly Color Gainsboro = Color.FromBgra(0xFFDCDCDC); + public static readonly Color Gainsboro = Color.FromBgra( 0xFFDCDCDC ); /// /// GhostWhite color. /// - public static readonly Color GhostWhite = Color.FromBgra(0xFFF8F8FF); + public static readonly Color GhostWhite = Color.FromBgra( 0xFFF8F8FF ); /// /// Gold color. /// - public static readonly Color Gold = Color.FromBgra(0xFFFFD700); + public static readonly Color Gold = Color.FromBgra( 0xFFFFD700 ); /// /// Goldenrod color. /// - public static readonly Color Goldenrod = Color.FromBgra(0xFFDAA520); + public static readonly Color Goldenrod = Color.FromBgra( 0xFFDAA520 ); /// /// Gray color. /// - public static readonly Color Gray = Color.FromBgra(0xFF808080); + public static readonly Color Gray = Color.FromBgra( 0xFF808080 ); /// /// Green color. /// - public static readonly Color Green = Color.FromBgra(0xFF008000); + public static readonly Color Green = Color.FromBgra( 0xFF008000 ); /// /// GreenYellow color. /// - public static readonly Color GreenYellow = Color.FromBgra(0xFFADFF2F); + public static readonly Color GreenYellow = Color.FromBgra( 0xFFADFF2F ); /// /// Honeydew color. /// - public static readonly Color Honeydew = Color.FromBgra(0xFFF0FFF0); + public static readonly Color Honeydew = Color.FromBgra( 0xFFF0FFF0 ); /// /// HotPink color. /// - public static readonly Color HotPink = Color.FromBgra(0xFFFF69B4); + public static readonly Color HotPink = Color.FromBgra( 0xFFFF69B4 ); /// /// IndianRed color. /// - public static readonly Color IndianRed = Color.FromBgra(0xFFCD5C5C); + public static readonly Color IndianRed = Color.FromBgra( 0xFFCD5C5C ); /// /// Indigo color. /// - public static readonly Color Indigo = Color.FromBgra(0xFF4B0082); + public static readonly Color Indigo = Color.FromBgra( 0xFF4B0082 ); /// /// Ivory color. /// - public static readonly Color Ivory = Color.FromBgra(0xFFFFFFF0); + public static readonly Color Ivory = Color.FromBgra( 0xFFFFFFF0 ); /// /// Khaki color. /// - public static readonly Color Khaki = Color.FromBgra(0xFFF0E68C); + public static readonly Color Khaki = Color.FromBgra( 0xFFF0E68C ); /// /// Lavender color. /// - public static readonly Color Lavender = Color.FromBgra(0xFFE6E6FA); + public static readonly Color Lavender = Color.FromBgra( 0xFFE6E6FA ); /// /// LavenderBlush color. /// - public static readonly Color LavenderBlush = Color.FromBgra(0xFFFFF0F5); + public static readonly Color LavenderBlush = Color.FromBgra( 0xFFFFF0F5 ); /// /// LawnGreen color. /// - public static readonly Color LawnGreen = Color.FromBgra(0xFF7CFC00); + public static readonly Color LawnGreen = Color.FromBgra( 0xFF7CFC00 ); /// /// LemonChiffon color. /// - public static readonly Color LemonChiffon = Color.FromBgra(0xFFFFFACD); + public static readonly Color LemonChiffon = Color.FromBgra( 0xFFFFFACD ); /// /// LightBlue color. /// - public static readonly Color LightBlue = Color.FromBgra(0xFFADD8E6); + public static readonly Color LightBlue = Color.FromBgra( 0xFFADD8E6 ); /// /// LightCoral color. /// - public static readonly Color LightCoral = Color.FromBgra(0xFFF08080); + public static readonly Color LightCoral = Color.FromBgra( 0xFFF08080 ); /// /// LightCyan color. /// - public static readonly Color LightCyan = Color.FromBgra(0xFFE0FFFF); + public static readonly Color LightCyan = Color.FromBgra( 0xFFE0FFFF ); /// /// LightGoldenrodYellow color. /// - public static readonly Color LightGoldenrodYellow = Color.FromBgra(0xFFFAFAD2); + public static readonly Color LightGoldenrodYellow = Color.FromBgra( 0xFFFAFAD2 ); /// /// LightGray color. /// - public static readonly Color LightGray = Color.FromBgra(0xFFD3D3D3); + public static readonly Color LightGray = Color.FromBgra( 0xFFD3D3D3 ); /// /// LightGreen color. /// - public static readonly Color LightGreen = Color.FromBgra(0xFF90EE90); + public static readonly Color LightGreen = Color.FromBgra( 0xFF90EE90 ); /// /// LightPink color. /// - public static readonly Color LightPink = Color.FromBgra(0xFFFFB6C1); + public static readonly Color LightPink = Color.FromBgra( 0xFFFFB6C1 ); /// /// LightSalmon color. /// - public static readonly Color LightSalmon = Color.FromBgra(0xFFFFA07A); + public static readonly Color LightSalmon = Color.FromBgra( 0xFFFFA07A ); /// /// LightSeaGreen color. /// - public static readonly Color LightSeaGreen = Color.FromBgra(0xFF20B2AA); + public static readonly Color LightSeaGreen = Color.FromBgra( 0xFF20B2AA ); /// /// LightSkyBlue color. /// - public static readonly Color LightSkyBlue = Color.FromBgra(0xFF87CEFA); + public static readonly Color LightSkyBlue = Color.FromBgra( 0xFF87CEFA ); /// /// LightSlateGray color. /// - public static readonly Color LightSlateGray = Color.FromBgra(0xFF778899); + public static readonly Color LightSlateGray = Color.FromBgra( 0xFF778899 ); /// /// LightSteelBlue color. /// - public static readonly Color LightSteelBlue = Color.FromBgra(0xFFB0C4DE); + public static readonly Color LightSteelBlue = Color.FromBgra( 0xFFB0C4DE ); /// /// LightYellow color. /// - public static readonly Color LightYellow = Color.FromBgra(0xFFFFFFE0); + public static readonly Color LightYellow = Color.FromBgra( 0xFFFFFFE0 ); /// /// Lime color. /// - public static readonly Color Lime = Color.FromBgra(0xFF00FF00); + public static readonly Color Lime = Color.FromBgra( 0xFF00FF00 ); /// /// LimeGreen color. /// - public static readonly Color LimeGreen = Color.FromBgra(0xFF32CD32); + public static readonly Color LimeGreen = Color.FromBgra( 0xFF32CD32 ); /// /// Linen color. /// - public static readonly Color Linen = Color.FromBgra(0xFFFAF0E6); + public static readonly Color Linen = Color.FromBgra( 0xFFFAF0E6 ); /// /// Magenta color. /// - public static readonly Color Magenta = Color.FromBgra(0xFFFF00FF); + public static readonly Color Magenta = Color.FromBgra( 0xFFFF00FF ); /// /// Maroon color. /// - public static readonly Color Maroon = Color.FromBgra(0xFF800000); + public static readonly Color Maroon = Color.FromBgra( 0xFF800000 ); /// /// MediumAquamarine color. /// - public static readonly Color MediumAquamarine = Color.FromBgra(0xFF66CDAA); + public static readonly Color MediumAquamarine = Color.FromBgra( 0xFF66CDAA ); /// /// MediumBlue color. /// - public static readonly Color MediumBlue = Color.FromBgra(0xFF0000CD); + public static readonly Color MediumBlue = Color.FromBgra( 0xFF0000CD ); /// /// MediumOrchid color. /// - public static readonly Color MediumOrchid = Color.FromBgra(0xFFBA55D3); + public static readonly Color MediumOrchid = Color.FromBgra( 0xFFBA55D3 ); /// /// MediumPurple color. /// - public static readonly Color MediumPurple = Color.FromBgra(0xFF9370DB); + public static readonly Color MediumPurple = Color.FromBgra( 0xFF9370DB ); /// /// MediumSeaGreen color. /// - public static readonly Color MediumSeaGreen = Color.FromBgra(0xFF3CB371); + public static readonly Color MediumSeaGreen = Color.FromBgra( 0xFF3CB371 ); /// /// MediumSlateBlue color. /// - public static readonly Color MediumSlateBlue = Color.FromBgra(0xFF7B68EE); + public static readonly Color MediumSlateBlue = Color.FromBgra( 0xFF7B68EE ); /// /// MediumSpringGreen color. /// - public static readonly Color MediumSpringGreen = Color.FromBgra(0xFF00FA9A); + public static readonly Color MediumSpringGreen = Color.FromBgra( 0xFF00FA9A ); /// /// MediumTurquoise color. /// - public static readonly Color MediumTurquoise = Color.FromBgra(0xFF48D1CC); + public static readonly Color MediumTurquoise = Color.FromBgra( 0xFF48D1CC ); /// /// MediumVioletRed color. /// - public static readonly Color MediumVioletRed = Color.FromBgra(0xFFC71585); + public static readonly Color MediumVioletRed = Color.FromBgra( 0xFFC71585 ); /// /// MidnightBlue color. /// - public static readonly Color MidnightBlue = Color.FromBgra(0xFF191970); + public static readonly Color MidnightBlue = Color.FromBgra( 0xFF191970 ); /// /// MintCream color. /// - public static readonly Color MintCream = Color.FromBgra(0xFFF5FFFA); + public static readonly Color MintCream = Color.FromBgra( 0xFFF5FFFA ); /// /// MistyRose color. /// - public static readonly Color MistyRose = Color.FromBgra(0xFFFFE4E1); + public static readonly Color MistyRose = Color.FromBgra( 0xFFFFE4E1 ); /// /// Moccasin color. /// - public static readonly Color Moccasin = Color.FromBgra(0xFFFFE4B5); + public static readonly Color Moccasin = Color.FromBgra( 0xFFFFE4B5 ); /// /// NavajoWhite color. /// - public static readonly Color NavajoWhite = Color.FromBgra(0xFFFFDEAD); + public static readonly Color NavajoWhite = Color.FromBgra( 0xFFFFDEAD ); /// /// Navy color. /// - public static readonly Color Navy = Color.FromBgra(0xFF000080); + public static readonly Color Navy = Color.FromBgra( 0xFF000080 ); /// /// OldLace color. /// - public static readonly Color OldLace = Color.FromBgra(0xFFFDF5E6); + public static readonly Color OldLace = Color.FromBgra( 0xFFFDF5E6 ); /// /// Olive color. /// - public static readonly Color Olive = Color.FromBgra(0xFF808000); + public static readonly Color Olive = Color.FromBgra( 0xFF808000 ); /// /// OliveDrab color. /// - public static readonly Color OliveDrab = Color.FromBgra(0xFF6B8E23); + public static readonly Color OliveDrab = Color.FromBgra( 0xFF6B8E23 ); /// /// Orange color. /// - public static readonly Color Orange = Color.FromBgra(0xFFFFA500); + public static readonly Color Orange = Color.FromBgra( 0xFFFFA500 ); /// /// OrangeRed color. /// - public static readonly Color OrangeRed = Color.FromBgra(0xFFFF4500); + public static readonly Color OrangeRed = Color.FromBgra( 0xFFFF4500 ); /// /// Orchid color. /// - public static readonly Color Orchid = Color.FromBgra(0xFFDA70D6); + public static readonly Color Orchid = Color.FromBgra( 0xFFDA70D6 ); /// /// PaleGoldenrod color. /// - public static readonly Color PaleGoldenrod = Color.FromBgra(0xFFEEE8AA); + public static readonly Color PaleGoldenrod = Color.FromBgra( 0xFFEEE8AA ); /// /// PaleGreen color. /// - public static readonly Color PaleGreen = Color.FromBgra(0xFF98FB98); + public static readonly Color PaleGreen = Color.FromBgra( 0xFF98FB98 ); /// /// PaleTurquoise color. /// - public static readonly Color PaleTurquoise = Color.FromBgra(0xFFAFEEEE); + public static readonly Color PaleTurquoise = Color.FromBgra( 0xFFAFEEEE ); /// /// PaleVioletRed color. /// - public static readonly Color PaleVioletRed = Color.FromBgra(0xFFDB7093); + public static readonly Color PaleVioletRed = Color.FromBgra( 0xFFDB7093 ); /// /// PapayaWhip color. /// - public static readonly Color PapayaWhip = Color.FromBgra(0xFFFFEFD5); + public static readonly Color PapayaWhip = Color.FromBgra( 0xFFFFEFD5 ); /// /// PeachPuff color. /// - public static readonly Color PeachPuff = Color.FromBgra(0xFFFFDAB9); + public static readonly Color PeachPuff = Color.FromBgra( 0xFFFFDAB9 ); /// /// Peru color. /// - public static readonly Color Peru = Color.FromBgra(0xFFCD853F); + public static readonly Color Peru = Color.FromBgra( 0xFFCD853F ); /// /// Pink color. /// - public static readonly Color Pink = Color.FromBgra(0xFFFFC0CB); + public static readonly Color Pink = Color.FromBgra( 0xFFFFC0CB ); /// /// Plum color. /// - public static readonly Color Plum = Color.FromBgra(0xFFDDA0DD); + public static readonly Color Plum = Color.FromBgra( 0xFFDDA0DD ); /// /// PowderBlue color. /// - public static readonly Color PowderBlue = Color.FromBgra(0xFFB0E0E6); + public static readonly Color PowderBlue = Color.FromBgra( 0xFFB0E0E6 ); /// /// Purple color. /// - public static readonly Color Purple = Color.FromBgra(0xFF800080); + public static readonly Color Purple = Color.FromBgra( 0xFF800080 ); /// /// Red color. /// - public static readonly Color Red = Color.FromBgra(0xFFFF0000); + public static readonly Color Red = Color.FromBgra( 0xFFFF0000 ); /// /// RosyBrown color. /// - public static readonly Color RosyBrown = Color.FromBgra(0xFFBC8F8F); + public static readonly Color RosyBrown = Color.FromBgra( 0xFFBC8F8F ); /// /// RoyalBlue color. /// - public static readonly Color RoyalBlue = Color.FromBgra(0xFF4169E1); + public static readonly Color RoyalBlue = Color.FromBgra( 0xFF4169E1 ); /// /// SaddleBrown color. /// - public static readonly Color SaddleBrown = Color.FromBgra(0xFF8B4513); + public static readonly Color SaddleBrown = Color.FromBgra( 0xFF8B4513 ); /// /// Salmon color. /// - public static readonly Color Salmon = Color.FromBgra(0xFFFA8072); + public static readonly Color Salmon = Color.FromBgra( 0xFFFA8072 ); /// /// SandyBrown color. /// - public static readonly Color SandyBrown = Color.FromBgra(0xFFF4A460); + public static readonly Color SandyBrown = Color.FromBgra( 0xFFF4A460 ); /// /// SeaGreen color. /// - public static readonly Color SeaGreen = Color.FromBgra(0xFF2E8B57); + public static readonly Color SeaGreen = Color.FromBgra( 0xFF2E8B57 ); /// /// SeaShell color. /// - public static readonly Color SeaShell = Color.FromBgra(0xFFFFF5EE); + public static readonly Color SeaShell = Color.FromBgra( 0xFFFFF5EE ); /// /// Sienna color. /// - public static readonly Color Sienna = Color.FromBgra(0xFFA0522D); + public static readonly Color Sienna = Color.FromBgra( 0xFFA0522D ); /// /// Silver color. /// - public static readonly Color Silver = Color.FromBgra(0xFFC0C0C0); + public static readonly Color Silver = Color.FromBgra( 0xFFC0C0C0 ); /// /// SkyBlue color. /// - public static readonly Color SkyBlue = Color.FromBgra(0xFF87CEEB); + public static readonly Color SkyBlue = Color.FromBgra( 0xFF87CEEB ); /// /// SlateBlue color. /// - public static readonly Color SlateBlue = Color.FromBgra(0xFF6A5ACD); + public static readonly Color SlateBlue = Color.FromBgra( 0xFF6A5ACD ); /// /// SlateGray color. /// - public static readonly Color SlateGray = Color.FromBgra(0xFF708090); + public static readonly Color SlateGray = Color.FromBgra( 0xFF708090 ); /// /// Snow color. /// - public static readonly Color Snow = Color.FromBgra(0xFFFFFAFA); + public static readonly Color Snow = Color.FromBgra( 0xFFFFFAFA ); /// /// SpringGreen color. /// - public static readonly Color SpringGreen = Color.FromBgra(0xFF00FF7F); + public static readonly Color SpringGreen = Color.FromBgra( 0xFF00FF7F ); /// /// SteelBlue color. /// - public static readonly Color SteelBlue = Color.FromBgra(0xFF4682B4); + public static readonly Color SteelBlue = Color.FromBgra( 0xFF4682B4 ); /// /// Tan color. /// - public static readonly Color Tan = Color.FromBgra(0xFFD2B48C); + public static readonly Color Tan = Color.FromBgra( 0xFFD2B48C ); /// /// Teal color. /// - public static readonly Color Teal = Color.FromBgra(0xFF008080); + public static readonly Color Teal = Color.FromBgra( 0xFF008080 ); /// /// Thistle color. /// - public static readonly Color Thistle = Color.FromBgra(0xFFD8BFD8); + public static readonly Color Thistle = Color.FromBgra( 0xFFD8BFD8 ); /// /// Tomato color. /// - public static readonly Color Tomato = Color.FromBgra(0xFFFF6347); + public static readonly Color Tomato = Color.FromBgra( 0xFFFF6347 ); /// /// Turquoise color. /// - public static readonly Color Turquoise = Color.FromBgra(0xFF40E0D0); + public static readonly Color Turquoise = Color.FromBgra( 0xFF40E0D0 ); /// /// Violet color. /// - public static readonly Color Violet = Color.FromBgra(0xFFEE82EE); + public static readonly Color Violet = Color.FromBgra( 0xFFEE82EE ); /// /// Wheat color. /// - public static readonly Color Wheat = Color.FromBgra(0xFFF5DEB3); + public static readonly Color Wheat = Color.FromBgra( 0xFFF5DEB3 ); /// /// White color. /// - public static readonly Color White = Color.FromBgra(0xFFFFFFFF); + public static readonly Color White = Color.FromBgra( 0xFFFFFFFF ); /// /// WhiteSmoke color. /// - public static readonly Color WhiteSmoke = Color.FromBgra(0xFFF5F5F5); + public static readonly Color WhiteSmoke = Color.FromBgra( 0xFFF5F5F5 ); /// /// Yellow color. /// - public static readonly Color Yellow = Color.FromBgra(0xFFFFFF00); + public static readonly Color Yellow = Color.FromBgra( 0xFFFFFF00 ); /// /// YellowGreen color. /// - public static readonly Color YellowGreen = Color.FromBgra(0xFF9ACD32); + public static readonly Color YellowGreen = Color.FromBgra( 0xFF9ACD32 ); } } diff --git a/math/Color.cs b/math/Color.cs index f94e958..e23bdda 100644 --- a/math/Color.cs +++ b/math/Color.cs @@ -10,15 +10,15 @@ namespace math /// /// Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A). /// - [DataContract(Name = "Color")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Size = 4)] + [DataContract( Name = "Color" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Size = 4 )] public partial struct Color : IEquatable { /// /// The red component of the color. /// - [DataMember(Order = 0)] + [DataMember( Order = 0 )] public byte R; /// @@ -43,7 +43,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Color(byte value) + public Color( byte value ) { A = R = G = B = value; } @@ -52,9 +52,9 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Color(float value) + public Color( float value ) { - A = R = G = B = ToByte(value); + A = R = G = B = ToByte( value ); } /// @@ -64,7 +64,7 @@ namespace math /// The green component of the color. /// The blue component of the color. /// The alpha component of the color. - public Color(byte red, byte green, byte blue, byte alpha) + public Color( byte red, byte green, byte blue, byte alpha ) { R = red; G = green; @@ -78,7 +78,7 @@ namespace math /// The red component of the color. /// The green component of the color. /// The blue component of the color. - public Color(byte red, byte green, byte blue) + public Color( byte red, byte green, byte blue ) { R = red; G = green; @@ -93,12 +93,12 @@ namespace math /// The green component of the color. /// The blue component of the color. /// The alpha component of the color. - public Color(float red, float green, float blue, float alpha) + public Color( float red, float green, float blue, float alpha ) { - R = ToByte(red); - G = ToByte(green); - B = ToByte(blue); - A = ToByte(alpha); + R = ToByte( red ); + G = ToByte( green ); + B = ToByte( blue ); + A = ToByte( alpha ); } /// @@ -107,11 +107,11 @@ namespace math /// The red component of the color. /// The green component of the color. /// The blue component of the color. - public Color(float red, float green, float blue) + public Color( float red, float green, float blue ) { - R = ToByte(red); - G = ToByte(green); - B = ToByte(blue); + R = ToByte( red ); + G = ToByte( green ); + B = ToByte( blue ); A = 255; } @@ -119,12 +119,12 @@ namespace math /// Initializes a new instance of the struct. /// /// The red, green, blue, and alpha components of the color. - public Color(Vec4 value) + public Color( Vec4 value ) { - R = ToByte(value.X); - G = ToByte(value.Y); - B = ToByte(value.Z); - A = ToByte(value.W); + R = ToByte( value.X ); + G = ToByte( value.Y ); + B = ToByte( value.Z ); + A = ToByte( value.W ); } /// @@ -132,23 +132,23 @@ namespace math /// /// The red, green, and blue components of the color. /// The alpha component of the color. - public Color(Vec3 value, float alpha) + public Color( Vec3 value, float alpha ) { - R = ToByte(value.X); - G = ToByte(value.Y); - B = ToByte(value.Z); - A = ToByte(alpha); + R = ToByte( value.X ); + G = ToByte( value.Y ); + B = ToByte( value.Z ); + A = ToByte( alpha ); } /// /// Initializes a new instance of the struct. Alpha is set to 255. /// /// The red, green, and blue components of the color. - public Color(Vec3 value) + public Color( Vec3 value ) { - R = ToByte(value.X); - G = ToByte(value.Y); - B = ToByte(value.Z); + R = ToByte( value.X ); + G = ToByte( value.Y ); + B = ToByte( value.Z ); A = 255; } @@ -156,24 +156,24 @@ namespace math /// Initializes a new instance of the struct. /// /// A packed integer containing all four color components in RGBA order. - public Color(uint rgba) + public Color( uint rgba ) { - A = (byte)((rgba >> 24) & 255); - B = (byte)((rgba >> 16) & 255); - G = (byte)((rgba >> 8) & 255); - R = (byte)(rgba & 255); + A = (byte)( ( rgba >> 24 ) & 255 ); + B = (byte)( ( rgba >> 16 ) & 255 ); + G = (byte)( ( rgba >> 8 ) & 255 ); + R = (byte)( rgba & 255 ); } /// /// Initializes a new instance of the struct. /// /// A packed integer containing all four color components in RGBA order. - public Color(int rgba) + public Color( int rgba ) { - A = (byte)((rgba >> 24) & 255); - B = (byte)((rgba >> 16) & 255); - G = (byte)((rgba >> 8) & 255); - R = (byte)(rgba & 255); + A = (byte)( ( rgba >> 24 ) & 255 ); + B = (byte)( ( rgba >> 16 ) & 255 ); + G = (byte)( ( rgba >> 8 ) & 255 ); + R = (byte)( rgba & 255 ); } /// @@ -182,17 +182,17 @@ namespace math /// The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Color(float[] values) + public Color( float[] values ) { - if (values == null) - throw new ArgumentNullException(nameof(values)); - if (values.Length != 4) - throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for Color."); + if( values == null ) + throw new ArgumentNullException( nameof( values ) ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( nameof( values ), "There must be four and only four input values for Color." ); - R = ToByte(values[0]); - G = ToByte(values[1]); - B = ToByte(values[2]); - A = ToByte(values[3]); + R = ToByte( values[0] ); + G = ToByte( values[1] ); + B = ToByte( values[2] ); + A = ToByte( values[3] ); } /// @@ -201,12 +201,12 @@ namespace math /// The values to assign to the alpha, red, green, and blue components of the color. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Color(byte[] values) + public Color( byte[] values ) { - if (values == null) - throw new ArgumentNullException(nameof(values)); - if (values.Length != 4) - throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for Color."); + if( values == null ) + throw new ArgumentNullException( nameof( values ) ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( nameof( values ), "There must be four and only four input values for Color." ); R = values[0]; G = values[1]; @@ -225,26 +225,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return R; - case 1: return G; - case 2: return B; - case 3: return A; + case 0: + return R; + case 1: + return G; + case 2: + return B; + case 3: + return A; } - throw new ArgumentOutOfRangeException(nameof(index), "Indices for Color run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for Color run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: R = value; break; - case 1: G = value; break; - case 2: B = value; break; - case 3: A = value; break; - default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Color run from 0 to 3, inclusive."); + case 0: + R = value; + break; + case 1: + G = value; + break; + case 2: + B = value; + break; + case 3: + A = value; + break; + default: + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for Color run from 0 to 3, inclusive." ); } } } @@ -311,7 +324,7 @@ namespace math /// A three component vector containing the red, green, and blue components of the color. public Vec3 ToVector3() { - return new Vec3(R / 255.0f, G / 255.0f, B / 255.0f); + return new Vec3( R / 255.0f, G / 255.0f, B / 255.0f ); } /// @@ -320,7 +333,7 @@ namespace math /// A three component color containing the red, green, and blue components of the color. public Color3 ToColor3() { - return new Color3(R / 255.0f, G / 255.0f, B / 255.0f); + return new Color3( R / 255.0f, G / 255.0f, B / 255.0f ); } /// @@ -329,7 +342,7 @@ namespace math /// A four component vector containing all four color components. public Vec4 ToVector4() { - return new Vec4(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f); + return new Vec4( R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f ); } /// @@ -356,13 +369,17 @@ namespace math max = r; min = r; - if (g > max) max = g; - if (b > max) max = b; + if( g > max ) + max = g; + if( b > max ) + max = b; - if (g < min) min = g; - if (b < min) min = b; + if( g < min ) + min = g; + if( b < min ) + min = b; - return (max + min) / 2; + return ( max + min ) / 2; } /// @@ -371,7 +388,7 @@ namespace math /// The Hue-Saturation-Brightness (HSB) saturation for this public float GetHue() { - if (R == G && G == B) + if( R == G && G == B ) return 0; // 0 makes as good an UNDEFINED value as any float r = R / 255.0f; @@ -385,29 +402,33 @@ namespace math max = r; min = r; - if (g > max) max = g; - if (b > max) max = b; + if( g > max ) + max = g; + if( b > max ) + max = b; - if (g < min) min = g; - if (b < min) min = b; + if( g < min ) + min = g; + if( b < min ) + min = b; delta = max - min; - if (r == max) + if( r == max ) { - hue = (g - b) / delta; + hue = ( g - b ) / delta; } - else if (g == max) + else if( g == max ) { - hue = 2 + (b - r) / delta; + hue = 2 + ( b - r ) / delta; } - else if (b == max) + else if( b == max ) { - hue = 4 + (r - g) / delta; + hue = 4 + ( r - g ) / delta; } hue *= 60; - if (hue < 0.0f) + if( hue < 0.0f ) { hue += 360.0f; } @@ -430,25 +451,29 @@ namespace math max = r; min = r; - if (g > max) max = g; - if (b > max) max = b; + if( g > max ) + max = g; + if( b > max ) + max = b; - if (g < min) min = g; - if (b < min) min = b; + if( g < min ) + min = g; + if( b < min ) + min = b; // if max == min, then there is no color and // the saturation is zero. - if (max != min) + if( max != min ) { - l = (max + min) / 2; + l = ( max + min ) / 2; - if (l <= .5) + if( l <= .5 ) { - s = (max - min) / (max + min); + s = ( max - min ) / ( max + min ); } else { - s = (max - min) / (2 - max - min); + s = ( max - min ) / ( 2 - max - min ); } } return s; @@ -460,12 +485,12 @@ namespace math /// The first color to add. /// The second color to add. /// When the method completes, completes the sum of the two colors. - public static void Add(ref Color left, ref Color right, out Color result) + public static void Add( ref Color left, ref Color right, out Color result ) { - result.A = (byte)(left.A + right.A); - result.R = (byte)(left.R + right.R); - result.G = (byte)(left.G + right.G); - result.B = (byte)(left.B + right.B); + result.A = (byte)( left.A + right.A ); + result.R = (byte)( left.R + right.R ); + result.G = (byte)( left.G + right.G ); + result.B = (byte)( left.B + right.B ); } /// @@ -474,9 +499,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static Color Add(Color left, Color right) + public static Color Add( Color left, Color right ) { - return new Color((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A)); + return new Color( (byte)( left.R + right.R ), (byte)( left.G + right.G ), (byte)( left.B + right.B ), (byte)( left.A + right.A ) ); } /// @@ -485,12 +510,12 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// WHen the method completes, contains the difference of the two colors. - public static void Subtract(ref Color left, ref Color right, out Color result) + public static void Subtract( ref Color left, ref Color right, out Color result ) { - result.A = (byte)(left.A - right.A); - result.R = (byte)(left.R - right.R); - result.G = (byte)(left.G - right.G); - result.B = (byte)(left.B - right.B); + result.A = (byte)( left.A - right.A ); + result.R = (byte)( left.R - right.R ); + result.G = (byte)( left.G - right.G ); + result.B = (byte)( left.B - right.B ); } /// @@ -499,9 +524,9 @@ namespace math /// The first color to subtract. /// The second color to subtract /// The difference of the two colors. - public static Color Subtract(Color left, Color right) + public static Color Subtract( Color left, Color right ) { - return new Color((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A)); + return new Color( (byte)( left.R - right.R ), (byte)( left.G - right.G ), (byte)( left.B - right.B ), (byte)( left.A - right.A ) ); } /// @@ -510,12 +535,12 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// When the method completes, contains the modulated color. - public static void Modulate(ref Color left, ref Color right, out Color result) + public static void Modulate( ref Color left, ref Color right, out Color result ) { - result.A = (byte)(left.A * right.A / 255); - result.R = (byte)(left.R * right.R / 255); - result.G = (byte)(left.G * right.G / 255); - result.B = (byte)(left.B * right.B / 255); + result.A = (byte)( left.A * right.A / 255 ); + result.R = (byte)( left.R * right.R / 255 ); + result.G = (byte)( left.G * right.G / 255 ); + result.B = (byte)( left.B * right.B / 255 ); } /// @@ -524,9 +549,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static Color Modulate(Color left, Color right) + public static Color Modulate( Color left, Color right ) { - return new Color((byte)(left.R * right.R / 255), (byte)(left.G * right.G / 255), (byte)(left.B * right.B / 255), (byte)(left.A * right.A / 255)); + return new Color( (byte)( left.R * right.R / 255 ), (byte)( left.G * right.G / 255 ), (byte)( left.B * right.B / 255 ), (byte)( left.A * right.A / 255 ) ); } /// @@ -535,12 +560,12 @@ namespace math /// The color to scale. /// The amount by which to scale. /// When the method completes, contains the scaled color. - public static void Scale(ref Color value, float scale, out Color result) + public static void Scale( ref Color value, float scale, out Color result ) { - result.A = (byte)(value.A * scale); - result.R = (byte)(value.R * scale); - result.G = (byte)(value.G * scale); - result.B = (byte)(value.B * scale); + result.A = (byte)( value.A * scale ); + result.R = (byte)( value.R * scale ); + result.G = (byte)( value.G * scale ); + result.B = (byte)( value.B * scale ); } /// @@ -549,9 +574,9 @@ namespace math /// The color to scale. /// The amount by which to scale. /// The scaled color. - public static Color Scale(Color value, float scale) + public static Color Scale( Color value, float scale ) { - return new Color((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale)); + return new Color( (byte)( value.R * scale ), (byte)( value.G * scale ), (byte)( value.B * scale ), (byte)( value.A * scale ) ); } /// @@ -559,12 +584,12 @@ namespace math /// /// The color to negate. /// When the method completes, contains the negated color. - public static void Negate(ref Color value, out Color result) + public static void Negate( ref Color value, out Color result ) { - result.A = (byte)(255 - value.A); - result.R = (byte)(255 - value.R); - result.G = (byte)(255 - value.G); - result.B = (byte)(255 - value.B); + result.A = (byte)( 255 - value.A ); + result.R = (byte)( 255 - value.R ); + result.G = (byte)( 255 - value.G ); + result.B = (byte)( 255 - value.B ); } /// @@ -572,9 +597,9 @@ namespace math /// /// The color to negate. /// The negated color. - public static Color Negate(Color value) + public static Color Negate( Color value ) { - return new Color((byte)(255 - value.R), (byte)(255 - value.G), (byte)(255 - value.B), (byte)(255 - value.A)); + return new Color( (byte)( 255 - value.R ), (byte)( 255 - value.G ), (byte)( 255 - value.B ), (byte)( 255 - value.A ) ); } /// @@ -584,25 +609,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Color value, ref Color min, ref Color max, out Color result) + public static void Clamp( ref Color value, ref Color min, ref Color max, out Color result ) { byte alpha = value.A; - alpha = (alpha > max.A) ? max.A : alpha; - alpha = (alpha < min.A) ? min.A : alpha; + alpha = ( alpha > max.A ) ? max.A : alpha; + alpha = ( alpha < min.A ) ? min.A : alpha; byte red = value.R; - red = (red > max.R) ? max.R : red; - red = (red < min.R) ? min.R : red; + red = ( red > max.R ) ? max.R : red; + red = ( red < min.R ) ? min.R : red; byte green = value.G; - green = (green > max.G) ? max.G : green; - green = (green < min.G) ? min.G : green; + green = ( green > max.G ) ? max.G : green; + green = ( green < min.G ) ? min.G : green; byte blue = value.B; - blue = (blue > max.B) ? max.B : blue; - blue = (blue < min.B) ? min.B : blue; + blue = ( blue > max.B ) ? max.B : blue; + blue = ( blue < min.B ) ? min.B : blue; - result = new Color(red, green, blue, alpha); + result = new Color( red, green, blue, alpha ); } /// @@ -610,9 +635,9 @@ namespace math /// /// A packed integer containing all four color components in BGRA order /// A color. - public static Color FromBgra(int color) + public static Color FromBgra( int color ) { - return new Color((byte)((color >> 16) & 255), (byte)((color >> 8) & 255), (byte)(color & 255), (byte)((color >> 24) & 255)); + return new Color( (byte)( ( color >> 16 ) & 255 ), (byte)( ( color >> 8 ) & 255 ), (byte)( color & 255 ), (byte)( ( color >> 24 ) & 255 ) ); } /// @@ -620,9 +645,9 @@ namespace math /// /// A packed integer containing all four color components in BGRA order /// A color. - public static Color FromBgra(uint color) + public static Color FromBgra( uint color ) { - return FromBgra(unchecked((int)color)); + return FromBgra( unchecked((int)color) ); } /// @@ -630,9 +655,9 @@ namespace math /// /// A packed integer containing all four color components in ABGR order /// A color. - public static Color FromAbgr(int color) + public static Color FromAbgr( int color ) { - return new Color((byte)(color >> 24), (byte)(color >> 16), (byte)(color >> 8), (byte)color); + return new Color( (byte)( color >> 24 ), (byte)( color >> 16 ), (byte)( color >> 8 ), (byte)color ); } /// @@ -640,9 +665,9 @@ namespace math /// /// A packed integer containing all four color components in ABGR order /// A color. - public static Color FromAbgr(uint color) + public static Color FromAbgr( uint color ) { - return FromAbgr(unchecked((int)color)); + return FromAbgr( unchecked((int)color) ); } /// @@ -650,9 +675,9 @@ namespace math /// /// A packed integer containing all four color components in RGBA order /// A color. - public static Color FromRgba(int color) + public static Color FromRgba( int color ) { - return new Color(color); + return new Color( color ); } /// @@ -660,9 +685,9 @@ namespace math /// /// A packed integer containing all four color components in RGBA order /// A color. - public static Color FromRgba(uint color) + public static Color FromRgba( uint color ) { - return new Color(color); + return new Color( color ); } /// @@ -672,10 +697,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Color Clamp(Color value, Color min, Color max) + public static Color Clamp( Color value, Color min, Color max ) { Color result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -687,14 +712,14 @@ namespace math /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two colors. /// - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Color start, ref Color end, float amount, out Color result) + public static void Lerp( ref Color start, ref Color end, float amount, out Color result ) { - result.R = MathUtil.Lerp(start.R, end.R, amount); - result.G = MathUtil.Lerp(start.G, end.G, amount); - result.B = MathUtil.Lerp(start.B, end.B, amount); - result.A = MathUtil.Lerp(start.A, end.A, amount); + result.R = MathUtil.Lerp( start.R, end.R, amount ); + result.G = MathUtil.Lerp( start.G, end.G, amount ); + result.B = MathUtil.Lerp( start.B, end.B, amount ); + result.A = MathUtil.Lerp( start.A, end.A, amount ); } /// @@ -705,12 +730,12 @@ namespace math /// Value between 0 and 1 indicating the weight of . /// The linear interpolation of the two colors. /// - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Color Lerp(Color start, Color end, float amount) + public static Color Lerp( Color start, Color end, float amount ) { Color result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -721,10 +746,10 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two colors. - public static void SmoothStep(ref Color start, ref Color end, float amount, out Color result) + public static void SmoothStep( ref Color start, ref Color end, float amount, out Color result ) { - amount = MathUtil.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + amount = MathUtil.SmoothStep( amount ); + Lerp( ref start, ref end, amount, out result ); } /// @@ -734,10 +759,10 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two colors. - public static Color SmoothStep(Color start, Color end, float amount) + public static Color SmoothStep( Color start, Color end, float amount ) { Color result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -747,12 +772,12 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the largest components of the source colors. - public static void Max(ref Color left, ref Color right, out Color result) + public static void Max( ref Color left, ref Color right, out Color result ) { - result.A = (left.A > right.A) ? left.A : right.A; - result.R = (left.R > right.R) ? left.R : right.R; - result.G = (left.G > right.G) ? left.G : right.G; - result.B = (left.B > right.B) ? left.B : right.B; + result.A = ( left.A > right.A ) ? left.A : right.A; + result.R = ( left.R > right.R ) ? left.R : right.R; + result.G = ( left.G > right.G ) ? left.G : right.G; + result.B = ( left.B > right.B ) ? left.B : right.B; } /// @@ -761,10 +786,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the largest components of the source colors. - public static Color Max(Color left, Color right) + public static Color Max( Color left, Color right ) { Color result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -774,12 +799,12 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the smallest components of the source colors. - public static void Min(ref Color left, ref Color right, out Color result) + public static void Min( ref Color left, ref Color right, out Color result ) { - result.A = (left.A < right.A) ? left.A : right.A; - result.R = (left.R < right.R) ? left.R : right.R; - result.G = (left.G < right.G) ? left.G : right.G; - result.B = (left.B < right.B) ? left.B : right.B; + result.A = ( left.A < right.A ) ? left.A : right.A; + result.R = ( left.R < right.R ) ? left.R : right.R; + result.G = ( left.G < right.G ) ? left.G : right.G; + result.B = ( left.B < right.B ) ? left.B : right.B; } /// @@ -788,10 +813,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the smallest components of the source colors. - public static Color Min(Color left, Color right) + public static Color Min( Color left, Color right ) { Color result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -801,12 +826,12 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// When the method completes, contains the adjusted color. - public static void AdjustContrast(ref Color value, float contrast, out Color result) + public static void AdjustContrast( ref Color value, float contrast, out Color result ) { result.A = value.A; - result.R = ToByte(0.5f + contrast * (value.R / 255.0f - 0.5f)); - result.G = ToByte(0.5f + contrast * (value.G / 255.0f - 0.5f)); - result.B = ToByte(0.5f + contrast * (value.B / 255.0f - 0.5f)); + result.R = ToByte( 0.5f + contrast * ( value.R / 255.0f - 0.5f ) ); + result.G = ToByte( 0.5f + contrast * ( value.G / 255.0f - 0.5f ) ); + result.B = ToByte( 0.5f + contrast * ( value.B / 255.0f - 0.5f ) ); } /// @@ -815,13 +840,13 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// The adjusted color. - public static Color AdjustContrast(Color value, float contrast) + public static Color AdjustContrast( Color value, float contrast ) { return new Color( - ToByte(0.5f + contrast * (value.R / 255.0f - 0.5f)), - ToByte(0.5f + contrast * (value.G / 255.0f - 0.5f)), - ToByte(0.5f + contrast * (value.B / 255.0f - 0.5f)), - value.A); + ToByte( 0.5f + contrast * ( value.R / 255.0f - 0.5f ) ), + ToByte( 0.5f + contrast * ( value.G / 255.0f - 0.5f ) ), + ToByte( 0.5f + contrast * ( value.B / 255.0f - 0.5f ) ), + value.A ); } /// @@ -830,14 +855,14 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// When the method completes, contains the adjusted color. - public static void AdjustSaturation(ref Color value, float saturation, out Color result) + public static void AdjustSaturation( ref Color value, float saturation, out Color result ) { float grey = value.R / 255.0f * 0.2125f + value.G / 255.0f * 0.7154f + value.B / 255.0f * 0.0721f; result.A = value.A; - result.R = ToByte(grey + saturation * (value.R / 255.0f - grey)); - result.G = ToByte(grey + saturation * (value.G / 255.0f - grey)); - result.B = ToByte(grey + saturation * (value.B / 255.0f - grey)); + result.R = ToByte( grey + saturation * ( value.R / 255.0f - grey ) ); + result.G = ToByte( grey + saturation * ( value.G / 255.0f - grey ) ); + result.B = ToByte( grey + saturation * ( value.B / 255.0f - grey ) ); } /// @@ -846,15 +871,15 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// The adjusted color. - public static Color AdjustSaturation(Color value, float saturation) + public static Color AdjustSaturation( Color value, float saturation ) { float grey = value.R / 255.0f * 0.2125f + value.G / 255.0f * 0.7154f + value.B / 255.0f * 0.0721f; return new Color( - ToByte(grey + saturation * (value.R / 255.0f - grey)), - ToByte(grey + saturation * (value.G / 255.0f - grey)), - ToByte(grey + saturation * (value.B / 255.0f - grey)), - value.A); + ToByte( grey + saturation * ( value.R / 255.0f - grey ) ), + ToByte( grey + saturation * ( value.G / 255.0f - grey ) ), + ToByte( grey + saturation * ( value.B / 255.0f - grey ) ), + value.A ); } /// @@ -863,9 +888,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static Color operator +(Color left, Color right) + public static Color operator +( Color left, Color right ) { - return new Color((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A)); + return new Color( (byte)( left.R + right.R ), (byte)( left.G + right.G ), (byte)( left.B + right.B ), (byte)( left.A + right.A ) ); } /// @@ -873,7 +898,7 @@ namespace math /// /// The color to assert (unchanged). /// The asserted (unchanged) color. - public static Color operator +(Color value) + public static Color operator +( Color value ) { return value; } @@ -884,9 +909,9 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// The difference of the two colors. - public static Color operator -(Color left, Color right) + public static Color operator -( Color left, Color right ) { - return new Color((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A)); + return new Color( (byte)( left.R - right.R ), (byte)( left.G - right.G ), (byte)( left.B - right.B ), (byte)( left.A - right.A ) ); } /// @@ -894,9 +919,9 @@ namespace math /// /// The color to negate. /// A negated color. - public static Color operator -(Color value) + public static Color operator -( Color value ) { - return new Color(-value.R, -value.G, -value.B, -value.A); + return new Color( -value.R, -value.G, -value.B, -value.A ); } /// @@ -905,9 +930,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static Color operator *(float scale, Color value) + public static Color operator *( float scale, Color value ) { - return new Color((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale)); + return new Color( (byte)( value.R * scale ), (byte)( value.G * scale ), (byte)( value.B * scale ), (byte)( value.A * scale ) ); } /// @@ -916,9 +941,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static Color operator *(Color value, float scale) + public static Color operator *( Color value, float scale ) { - return new Color((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale)); + return new Color( (byte)( value.R * scale ), (byte)( value.G * scale ), (byte)( value.B * scale ), (byte)( value.A * scale ) ); } /// @@ -927,9 +952,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static Color operator *(Color left, Color right) + public static Color operator *( Color left, Color right ) { - return new Color((byte)(left.R * right.R / 255.0f), (byte)(left.G * right.G / 255.0f), (byte)(left.B * right.B / 255.0f), (byte)(left.A * right.A / 255.0f)); + return new Color( (byte)( left.R * right.R / 255.0f ), (byte)( left.G * right.G / 255.0f ), (byte)( left.B * right.B / 255.0f ), (byte)( left.A * right.A / 255.0f ) ); } /// @@ -938,9 +963,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Color left, Color right) + public static bool operator ==( Color left, Color right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -949,9 +974,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Color left, Color right) + public static bool operator !=( Color left, Color right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -959,7 +984,7 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color3(Color value) + public static explicit operator Color3( Color value ) { return value.ToColor3(); } @@ -969,9 +994,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Color value) + public static explicit operator Vec3( Color value ) { - return new Vec3(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f); + return new Vec3( value.R / 255.0f, value.G / 255.0f, value.B / 255.0f ); } /// @@ -979,9 +1004,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Color value) + public static explicit operator Vec4( Color value ) { - return new Vec4(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); + return new Vec4( value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f ); } /// @@ -990,7 +1015,7 @@ namespace math /// The result of the conversion. public Color4 ToColor4() { - return new Color4(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f); + return new Color4( R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f ); } /// @@ -998,7 +1023,7 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Color4(Color value) + public static implicit operator Color4( Color value ) { return value.ToColor4(); } @@ -1008,9 +1033,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color(Vec3 value) + public static explicit operator Color( Vec3 value ) { - return new Color(value.X, value.Y, value.Z, 1.0f); + return new Color( value.X, value.Y, value.Z, 1.0f ); } /// @@ -1018,9 +1043,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color(Color3 value) + public static explicit operator Color( Color3 value ) { - return new Color(value.R, value.G, value.B, 1.0f); + return new Color( value.R, value.G, value.B, 1.0f ); } /// @@ -1028,9 +1053,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color(Vec4 value) + public static explicit operator Color( Vec4 value ) { - return new Color(value.X, value.Y, value.Z, value.W); + return new Color( value.X, value.Y, value.Z, value.W ); } /// @@ -1038,9 +1063,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color(Color4 value) + public static explicit operator Color( Color4 value ) { - return new Color(value.R, value.G, value.B, value.A); + return new Color( value.R, value.G, value.B, value.A ); } /// @@ -1050,7 +1075,7 @@ namespace math /// /// The result of the conversion. /// - public static explicit operator int(Color value) + public static explicit operator int( Color value ) { return value.ToRgba(); } @@ -1062,9 +1087,9 @@ namespace math /// /// The result of the conversion. /// - public static explicit operator Color(int value) + public static explicit operator Color( int value ) { - return new Color(value); + return new Color( value ); } /// @@ -1075,14 +1100,14 @@ namespace math /// public override string ToString() { - return ColorExtensions.RgbaToString(ToRgba()); + return ColorExtensions.RgbaToString( ToRgba() ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1096,7 +1121,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Color other) + public bool Equals( Color other ) { return R == other.R && G == other.G && B == other.B && A == other.A; } @@ -1108,21 +1133,21 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (!ReferenceEquals(value.GetType(), typeof(Color))) + if( !ReferenceEquals( value.GetType(), typeof( Color ) ) ) return false; - return Equals((Color)value); + return Equals( (Color)value ); } - private static byte ToByte(float component) + private static byte ToByte( float component ) { - var value = (int)(component * 255.0f); - return (byte)(value < 0 ? 0 : value > 255 ? 255 : value); + var value = (int)( component * 255.0f ); + return (byte)( value < 0 ? 0 : value > 255 ? 255 : value ); } } } diff --git a/math/Color3.cs b/math/Color3.cs index 86a2e04..ddf4552 100644 --- a/math/Color3.cs +++ b/math/Color3.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -36,9 +36,9 @@ namespace math /// /// Represents a color in the form of rgb. /// - [DataContract( Name = "Color3")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Color3" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Color3 : IEquatable, IFormattable { private const string ToStringFormat = "R:{0} G:{1} B:{2}"; @@ -65,7 +65,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Color3(float value) + public Color3( float value ) { R = G = B = value; } @@ -76,7 +76,7 @@ namespace math /// The red component of the color. /// The green component of the color. /// The blue component of the color. - public Color3(float red, float green, float blue) + public Color3( float red, float green, float blue ) { R = red; G = green; @@ -87,7 +87,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The red, green, and blue components of the color. - public Color3(Vec3 value) + public Color3( Vec3 value ) { R = value.X; G = value.Y; @@ -99,11 +99,11 @@ namespace math /// /// A packed integer containing all three color components. /// The alpha component is ignored. - public Color3(int rgb) + public Color3( int rgb ) { - B = ((rgb >> 16) & 255) / 255.0f; - G = ((rgb >> 8) & 255) / 255.0f; - R = (rgb & 255) / 255.0f; + B = ( ( rgb >> 16 ) & 255 ) / 255.0f; + G = ( ( rgb >> 8 ) & 255 ) / 255.0f; + R = ( rgb & 255 ) / 255.0f; } /// @@ -111,11 +111,11 @@ namespace math /// /// A packed unsigned integer containing all three color components. /// The alpha component is ignored. - public Color3(uint rgb) + public Color3( uint rgb ) { - B = ((rgb >> 16) & 255) / 255.0f; - G = ((rgb >> 8) & 255) / 255.0f; - R = (rgb & 255) / 255.0f; + B = ( ( rgb >> 16 ) & 255 ) / 255.0f; + G = ( ( rgb >> 8 ) & 255 ) / 255.0f; + R = ( rgb & 255 ) / 255.0f; } /// @@ -124,12 +124,12 @@ namespace math /// The values to assign to the red, green, and blue components of the color. This must be an array with three elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Color3(float[] values) + public Color3( float[] values ) { - if (values == null) - throw new ArgumentNullException(nameof(values)); - if (values.Length != 3) - throw new ArgumentOutOfRangeException(nameof(values), "There must be three and only three input values for Color3."); + if( values == null ) + throw new ArgumentNullException( nameof( values ) ); + if( values.Length != 3 ) + throw new ArgumentOutOfRangeException( nameof( values ), "There must be three and only three input values for Color3." ); R = values[0]; G = values[1]; @@ -147,24 +147,34 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return R; - case 1: return G; - case 2: return B; + case 0: + return R; + case 1: + return G; + case 2: + return B; } - throw new ArgumentOutOfRangeException(nameof(index), "Indices for Color3 run from 0 to 2, inclusive."); + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for Color3 run from 0 to 2, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: R = value; break; - case 1: G = value; break; - case 2: B = value; break; - default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Color3 run from 0 to 2, inclusive."); + case 0: + R = value; + break; + case 1: + G = value; + break; + case 2: + B = value; + break; + default: + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for Color3 run from 0 to 2, inclusive." ); } } } @@ -177,9 +187,9 @@ namespace math public int ToRgb() { uint a = 255; - uint r = (uint)(R * 255.0f); - uint g = (uint)(G * 255.0f); - uint b = (uint)(B * 255.0f); + uint r = (uint)( R * 255.0f ); + uint g = (uint)( G * 255.0f ); + uint b = (uint)( B * 255.0f ); uint value = r; value += g << 8; @@ -193,11 +203,11 @@ namespace math /// Raises the exponent for each components. /// /// The exponent. - public void Pow(float exponent) + public void Pow( float exponent ) { - R = (float)Math.Pow(R, exponent); - G = (float)Math.Pow(G, exponent); - B = (float)Math.Pow(B, exponent); + R = (float)Math.Pow( R, exponent ); + G = (float)Math.Pow( G, exponent ); + B = (float)Math.Pow( B, exponent ); } /// @@ -206,7 +216,7 @@ namespace math /// A three component vector containing the red, green, and blue components of the color. public Vec3 ToVector3() { - return new Vec3(R, G, B); + return new Vec3( R, G, B ); } /// @@ -224,7 +234,7 @@ namespace math /// The first color to add. /// The second color to add. /// When the method completes, completes the sum of the two colors. - public static void Add(ref Color3 left, ref Color3 right, out Color3 result) + public static void Add( ref Color3 left, ref Color3 right, out Color3 result ) { result.R = left.R + right.R; result.G = left.G + right.G; @@ -237,9 +247,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static Color3 Add(Color3 left, Color3 right) + public static Color3 Add( Color3 left, Color3 right ) { - return new Color3(left.R + right.R, left.G + right.G, left.B + right.B); + return new Color3( left.R + right.R, left.G + right.G, left.B + right.B ); } /// @@ -248,7 +258,7 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// WHen the method completes, contains the difference of the two colors. - public static void Subtract(ref Color3 left, ref Color3 right, out Color3 result) + public static void Subtract( ref Color3 left, ref Color3 right, out Color3 result ) { result.R = left.R - right.R; result.G = left.G - right.G; @@ -261,9 +271,9 @@ namespace math /// The first color to subtract. /// The second color to subtract /// The difference of the two colors. - public static Color3 Subtract(Color3 left, Color3 right) + public static Color3 Subtract( Color3 left, Color3 right ) { - return new Color3(left.R - right.R, left.G - right.G, left.B - right.B); + return new Color3( left.R - right.R, left.G - right.G, left.B - right.B ); } /// @@ -272,7 +282,7 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// When the method completes, contains the modulated color. - public static void Modulate(ref Color3 left, ref Color3 right, out Color3 result) + public static void Modulate( ref Color3 left, ref Color3 right, out Color3 result ) { result.R = left.R * right.R; result.G = left.G * right.G; @@ -285,9 +295,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static Color3 Modulate(Color3 left, Color3 right) + public static Color3 Modulate( Color3 left, Color3 right ) { - return new Color3(left.R * right.R, left.G * right.G, left.B * right.B); + return new Color3( left.R * right.R, left.G * right.G, left.B * right.B ); } /// @@ -296,7 +306,7 @@ namespace math /// The color to scale. /// The amount by which to scale. /// When the method completes, contains the scaled color. - public static void Scale(ref Color3 value, float scale, out Color3 result) + public static void Scale( ref Color3 value, float scale, out Color3 result ) { result.R = value.R * scale; result.G = value.G * scale; @@ -309,9 +319,9 @@ namespace math /// The color to scale. /// The amount by which to scale. /// The scaled color. - public static Color3 Scale(Color3 value, float scale) + public static Color3 Scale( Color3 value, float scale ) { - return new Color3(value.R * scale, value.G * scale, value.B * scale); + return new Color3( value.R * scale, value.G * scale, value.B * scale ); } /// @@ -319,7 +329,7 @@ namespace math /// /// The color to negate. /// When the method completes, contains the negated color. - public static void Negate(ref Color3 value, out Color3 result) + public static void Negate( ref Color3 value, out Color3 result ) { result.R = 1.0f - value.R; result.G = 1.0f - value.G; @@ -331,9 +341,9 @@ namespace math /// /// The color to negate. /// The negated color. - public static Color3 Negate(Color3 value) + public static Color3 Negate( Color3 value ) { - return new Color3(1.0f - value.R, 1.0f - value.G, 1.0f - value.B); + return new Color3( 1.0f - value.R, 1.0f - value.G, 1.0f - value.B ); } /// @@ -343,21 +353,21 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Color3 value, ref Color3 min, ref Color3 max, out Color3 result) + public static void Clamp( ref Color3 value, ref Color3 min, ref Color3 max, out Color3 result ) { float red = value.R; - red = (red > max.R) ? max.R : red; - red = (red < min.R) ? min.R : red; + red = ( red > max.R ) ? max.R : red; + red = ( red < min.R ) ? min.R : red; float green = value.G; - green = (green > max.G) ? max.G : green; - green = (green < min.G) ? min.G : green; + green = ( green > max.G ) ? max.G : green; + green = ( green < min.G ) ? min.G : green; float blue = value.B; - blue = (blue > max.B) ? max.B : blue; - blue = (blue < min.B) ? min.B : blue; + blue = ( blue > max.B ) ? max.B : blue; + blue = ( blue < min.B ) ? min.B : blue; - result = new Color3(red, green, blue); + result = new Color3( red, green, blue ); } /// @@ -367,10 +377,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Color3 Clamp(Color3 value, Color3 min, Color3 max) + public static Color3 Clamp( Color3 value, Color3 min, Color3 max ) { Color3 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -384,13 +394,13 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Color3 start, ref Color3 end, float amount, out Color3 result) + public static void Lerp( ref Color3 start, ref Color3 end, float amount, out Color3 result ) { - result.R = start.R + amount * (end.R - start.R); - result.G = start.G + amount * (end.G - start.G); - result.B = start.B + amount * (end.B - start.B); + result.R = start.R + amount * ( end.R - start.R ); + result.G = start.G + amount * ( end.G - start.G ); + result.B = start.B + amount * ( end.B - start.B ); } /// @@ -403,14 +413,14 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Color3 Lerp(Color3 start, Color3 end, float amount) + public static Color3 Lerp( Color3 start, Color3 end, float amount ) { return new Color3( - start.R + amount * (end.R - start.R), - start.G + amount * (end.G - start.G), - start.B + amount * (end.B - start.B)); + start.R + amount * ( end.R - start.R ), + start.G + amount * ( end.G - start.G ), + start.B + amount * ( end.B - start.B ) ); } /// @@ -420,14 +430,14 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two colors. - public static void SmoothStep(ref Color3 start, ref Color3 end, float amount, out Color3 result) + public static void SmoothStep( ref Color3 start, ref Color3 end, float amount, out Color3 result ) { - amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0f ) ? 1.0f : ( ( amount < 0.0f ) ? 0.0f : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.R = start.R + ((end.R - start.R) * amount); - result.G = start.G + ((end.G - start.G) * amount); - result.B = start.B + ((end.B - start.B) * amount); + result.R = start.R + ( ( end.R - start.R ) * amount ); + result.G = start.G + ( ( end.G - start.G ) * amount ); + result.B = start.B + ( ( end.B - start.B ) * amount ); } /// @@ -437,15 +447,15 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two colors. - public static Color3 SmoothStep(Color3 start, Color3 end, float amount) + public static Color3 SmoothStep( Color3 start, Color3 end, float amount ) { - amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0f ) ? 1.0f : ( ( amount < 0.0f ) ? 0.0f : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); return new Color3( - start.R + ((end.R - start.R) * amount), - start.G + ((end.G - start.G) * amount), - start.B + ((end.B - start.B) * amount)); + start.R + ( ( end.R - start.R ) * amount ), + start.G + ( ( end.G - start.G ) * amount ), + start.B + ( ( end.B - start.B ) * amount ) ); } /// @@ -454,11 +464,11 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the largest components of the source colorss. - public static void Max(ref Color3 left, ref Color3 right, out Color3 result) + public static void Max( ref Color3 left, ref Color3 right, out Color3 result ) { - result.R = (left.R > right.R) ? left.R : right.R; - result.G = (left.G > right.G) ? left.G : right.G; - result.B = (left.B > right.B) ? left.B : right.B; + result.R = ( left.R > right.R ) ? left.R : right.R; + result.G = ( left.G > right.G ) ? left.G : right.G; + result.B = ( left.B > right.B ) ? left.B : right.B; } /// @@ -467,10 +477,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the largest components of the source colors. - public static Color3 Max(Color3 left, Color3 right) + public static Color3 Max( Color3 left, Color3 right ) { Color3 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -480,11 +490,11 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the smallest components of the source colors. - public static void Min(ref Color3 left, ref Color3 right, out Color3 result) + public static void Min( ref Color3 left, ref Color3 right, out Color3 result ) { - result.R = (left.R < right.R) ? left.R : right.R; - result.G = (left.G < right.G) ? left.G : right.G; - result.B = (left.B < right.B) ? left.B : right.B; + result.R = ( left.R < right.R ) ? left.R : right.R; + result.G = ( left.G < right.G ) ? left.G : right.G; + result.B = ( left.B < right.B ) ? left.B : right.B; } /// @@ -493,10 +503,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the smallest components of the source colors. - public static Color3 Min(Color3 left, Color3 right) + public static Color3 Min( Color3 left, Color3 right ) { Color3 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -506,11 +516,11 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// When the method completes, contains the adjusted color. - public static void AdjustContrast(ref Color3 value, float contrast, out Color3 result) + public static void AdjustContrast( ref Color3 value, float contrast, out Color3 result ) { - result.R = 0.5f + contrast * (value.R - 0.5f); - result.G = 0.5f + contrast * (value.G - 0.5f); - result.B = 0.5f + contrast * (value.B - 0.5f); + result.R = 0.5f + contrast * ( value.R - 0.5f ); + result.G = 0.5f + contrast * ( value.G - 0.5f ); + result.B = 0.5f + contrast * ( value.B - 0.5f ); } /// @@ -519,12 +529,12 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// The adjusted color. - public static Color3 AdjustContrast(Color3 value, float contrast) + public static Color3 AdjustContrast( Color3 value, float contrast ) { return new Color3( - 0.5f + contrast * (value.R - 0.5f), - 0.5f + contrast * (value.G - 0.5f), - 0.5f + contrast * (value.B - 0.5f)); + 0.5f + contrast * ( value.R - 0.5f ), + 0.5f + contrast * ( value.G - 0.5f ), + 0.5f + contrast * ( value.B - 0.5f ) ); } /// @@ -533,13 +543,13 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// When the method completes, contains the adjusted color. - public static void AdjustSaturation(ref Color3 value, float saturation, out Color3 result) + public static void AdjustSaturation( ref Color3 value, float saturation, out Color3 result ) { float grey = value.R * 0.2125f + value.G * 0.7154f + value.B * 0.0721f; - result.R = grey + saturation * (value.R - grey); - result.G = grey + saturation * (value.G - grey); - result.B = grey + saturation * (value.B - grey); + result.R = grey + saturation * ( value.R - grey ); + result.G = grey + saturation * ( value.G - grey ); + result.B = grey + saturation * ( value.B - grey ); } /// @@ -548,14 +558,14 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// The adjusted color. - public static Color3 AdjustSaturation(Color3 value, float saturation) + public static Color3 AdjustSaturation( Color3 value, float saturation ) { float grey = value.R * 0.2125f + value.G * 0.7154f + value.B * 0.0721f; return new Color3( - grey + saturation * (value.R - grey), - grey + saturation * (value.G - grey), - grey + saturation * (value.B - grey)); + grey + saturation * ( value.R - grey ), + grey + saturation * ( value.G - grey ), + grey + saturation * ( value.B - grey ) ); } /// @@ -564,7 +574,7 @@ namespace math /// A color3 in sRGB space. public Color3 ToSRgb() { - return new Color3(MathUtil.LinearToSRgb(R), MathUtil.LinearToSRgb(G), MathUtil.LinearToSRgb(B)); + return new Color3( MathUtil.LinearToSRgb( R ), MathUtil.LinearToSRgb( G ), MathUtil.LinearToSRgb( B ) ); } /// @@ -573,7 +583,7 @@ namespace math /// Color3. public Color3 ToLinear() { - return new Color3(MathUtil.SRgbToLinear(R), MathUtil.SRgbToLinear(G), MathUtil.SRgbToLinear(B)); + return new Color3( MathUtil.SRgbToLinear( R ), MathUtil.SRgbToLinear( G ), MathUtil.SRgbToLinear( B ) ); } /// @@ -582,9 +592,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static Color3 operator +(Color3 left, Color3 right) + public static Color3 operator +( Color3 left, Color3 right ) { - return new Color3(left.R + right.R, left.G + right.G, left.B + right.B); + return new Color3( left.R + right.R, left.G + right.G, left.B + right.B ); } /// @@ -592,7 +602,7 @@ namespace math /// /// The color to assert (unchange). /// The asserted (unchanged) color. - public static Color3 operator +(Color3 value) + public static Color3 operator +( Color3 value ) { return value; } @@ -603,9 +613,9 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// The difference of the two colors. - public static Color3 operator -(Color3 left, Color3 right) + public static Color3 operator -( Color3 left, Color3 right ) { - return new Color3(left.R - right.R, left.G - right.G, left.B - right.B); + return new Color3( left.R - right.R, left.G - right.G, left.B - right.B ); } /// @@ -613,9 +623,9 @@ namespace math /// /// The color to negate. /// A negated color. - public static Color3 operator -(Color3 value) + public static Color3 operator -( Color3 value ) { - return new Color3(-value.R, -value.G, -value.B); + return new Color3( -value.R, -value.G, -value.B ); } /// @@ -624,9 +634,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static Color3 operator *(float scale, Color3 value) + public static Color3 operator *( float scale, Color3 value ) { - return new Color3(value.R * scale, value.G * scale, value.B * scale); + return new Color3( value.R * scale, value.G * scale, value.B * scale ); } /// @@ -635,9 +645,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static Color3 operator *(Color3 value, float scale) + public static Color3 operator *( Color3 value, float scale ) { - return new Color3(value.R * scale, value.G * scale, value.B * scale); + return new Color3( value.R * scale, value.G * scale, value.B * scale ); } /// @@ -646,9 +656,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static Color3 operator *(Color3 left, Color3 right) + public static Color3 operator *( Color3 left, Color3 right ) { - return new Color3(left.R * right.R, left.G * right.G, left.B * right.B); + return new Color3( left.R * right.R, left.G * right.G, left.B * right.B ); } /// @@ -657,9 +667,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Color3 left, Color3 right) + public static bool operator ==( Color3 left, Color3 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -668,9 +678,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Color3 left, Color3 right) + public static bool operator !=( Color3 left, Color3 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -678,9 +688,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color4(Color3 value) + public static explicit operator Color4( Color3 value ) { - return new Color4(value.R, value.G, value.B, 1.0f); + return new Color4( value.R, value.G, value.B, 1.0f ); } /// @@ -688,9 +698,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Color3 value) + public static explicit operator Vec3( Color3 value ) { - return new Vec3(value.R, value.G, value.B); + return new Vec3( value.R, value.G, value.B ); } /// @@ -698,9 +708,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color3(Vec3 value) + public static explicit operator Color3( Vec3 value ) { - return new Color3(value.X, value.Y, value.Z); + return new Color3( value.X, value.Y, value.Z ); } /// @@ -708,9 +718,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color3(int value) + public static explicit operator Color3( int value ) { - return new Color3(value); + return new Color3( value ); } /// @@ -721,7 +731,7 @@ namespace math /// public override string ToString() { - return ToString(CultureInfo.CurrentCulture); + return ToString( CultureInfo.CurrentCulture ); } /// @@ -730,7 +740,7 @@ namespace math /// An equivalent with an opaque alpha. public Color4 ToColor4() { - return new Color4(R, G, B, 1.0f); + return new Color4( R, G, B, 1.0f ); } /// @@ -740,9 +750,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - return ToString(format, CultureInfo.CurrentCulture); + return ToString( format, CultureInfo.CurrentCulture ); } /// @@ -752,9 +762,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, ToStringFormat, R, G, B); + return string.Format( formatProvider, ToStringFormat, R, G, B ); } /// @@ -765,22 +775,22 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, ToStringFormat, - R.ToString(format, formatProvider), - G.ToString(format, formatProvider), - B.ToString(format, formatProvider)); + return string.Format( formatProvider, ToStringFormat, + R.ToString( format, formatProvider ), + G.ToString( format, formatProvider ), + B.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -794,7 +804,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Color3 other) + public bool Equals( Color3 other ) { return R == other.R && G == other.G && B == other.B; } @@ -806,15 +816,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Color3)value); + return Equals( (Color3)value ); } #if SlimDX1xInterop diff --git a/math/Color4.cs b/math/Color4.cs index 319380e..9912099 100644 --- a/math/Color4.cs +++ b/math/Color4.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -36,9 +36,9 @@ namespace math /// /// Represents a color in the form of rgba. /// - [DataContract( Name = "Color4")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Color4" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Color4 : IEquatable, IFormattable { private const string ToStringFormat = "A:{0} R:{1} G:{2} B:{3}"; @@ -46,12 +46,12 @@ namespace math /// /// The Black color (0, 0, 0, 1). /// - public static readonly Color4 Black = new Color4(0.0f, 0.0f, 0.0f, 1.0f); + public static readonly Color4 Black = new Color4( 0.0f, 0.0f, 0.0f, 1.0f ); /// /// The White color (1, 1, 1, 1). /// - public static readonly Color4 White = new Color4(1.0f, 1.0f, 1.0f, 1.0f); + public static readonly Color4 White = new Color4( 1.0f, 1.0f, 1.0f, 1.0f ); /// /// The red component of the color. @@ -81,7 +81,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Color4(float value) + public Color4( float value ) { A = R = G = B = value; } @@ -93,7 +93,7 @@ namespace math /// The green component of the color. /// The blue component of the color. /// The alpha component of the color. - public Color4(float red, float green, float blue, float alpha) + public Color4( float red, float green, float blue, float alpha ) { R = red; G = green; @@ -105,7 +105,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The red, green, blue, and alpha components of the color. - public Color4(Vec4 value) + public Color4( Vec4 value ) { R = value.X; G = value.Y; @@ -118,7 +118,7 @@ namespace math /// /// The red, green, and blue components of the color. /// The alpha component of the color. - public Color4(Vec3 value, float alpha) + public Color4( Vec3 value, float alpha ) { R = value.X; G = value.Y; @@ -130,24 +130,24 @@ namespace math /// Initializes a new instance of the struct. /// /// A packed integer containing all four color components in RGBA order. - public Color4(uint rgba) + public Color4( uint rgba ) { - A = ((rgba >> 24) & 255) / 255.0f; - B = ((rgba >> 16) & 255) / 255.0f; - G = ((rgba >> 8) & 255) / 255.0f; - R = (rgba & 255) / 255.0f; + A = ( ( rgba >> 24 ) & 255 ) / 255.0f; + B = ( ( rgba >> 16 ) & 255 ) / 255.0f; + G = ( ( rgba >> 8 ) & 255 ) / 255.0f; + R = ( rgba & 255 ) / 255.0f; } /// /// Initializes a new instance of the struct. /// /// A packed integer containing all four color components in RGBA order. - public Color4(int rgba) + public Color4( int rgba ) { - A = ((rgba >> 24) & 255) / 255.0f; - B = ((rgba >> 16) & 255) / 255.0f; - G = ((rgba >> 8) & 255) / 255.0f; - R = (rgba & 255) / 255.0f; + A = ( ( rgba >> 24 ) & 255 ) / 255.0f; + B = ( ( rgba >> 16 ) & 255 ) / 255.0f; + G = ( ( rgba >> 8 ) & 255 ) / 255.0f; + R = ( rgba & 255 ) / 255.0f; } /// @@ -156,12 +156,12 @@ namespace math /// The values to assign to the red, green, blue, and alpha components of the color. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Color4(float[] values) + public Color4( float[] values ) { - if (values == null) - throw new ArgumentNullException(nameof(values)); - if (values.Length != 4) - throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for Color4."); + if( values == null ) + throw new ArgumentNullException( nameof( values ) ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( nameof( values ), "There must be four and only four input values for Color4." ); R = values[0]; G = values[1]; @@ -173,7 +173,7 @@ namespace math /// Initializes a new instance of the struct. /// /// used to initialize the color. - public Color4(Color3 color) + public Color4( Color3 color ) { R = color.R; G = color.G; @@ -185,7 +185,7 @@ namespace math /// Initializes a new instance of the struct. /// /// used to initialize the color. - public Color4(Color color) + public Color4( Color color ) { R = color.R / 255.0f; G = color.G / 255.0f; @@ -197,7 +197,7 @@ namespace math /// Initializes a new instance of the struct. /// /// used to initialize the color. - public Color4(ColorBGRA color) + public Color4( ColorBGRA color ) { R = color.R / 255.0f; G = color.G / 255.0f; @@ -210,7 +210,7 @@ namespace math /// /// used to initialize the color. /// The alpha component of the color. - public Color4(Color3 color, float alpha) + public Color4( Color3 color, float alpha ) { R = color.R; G = color.G; @@ -229,26 +229,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return R; - case 1: return G; - case 2: return B; - case 3: return A; + case 0: + return R; + case 1: + return G; + case 2: + return B; + case 3: + return A; } - throw new ArgumentOutOfRangeException(nameof(index), "Indices for Color4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for Color4 run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: R = value; break; - case 1: G = value; break; - case 2: B = value; break; - case 3: A = value; break; - default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for Color4 run from 0 to 3, inclusive."); + case 0: + R = value; + break; + case 1: + G = value; + break; + case 2: + B = value; + break; + case 3: + A = value; + break; + default: + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for Color4 run from 0 to 3, inclusive." ); } } } @@ -259,10 +272,10 @@ namespace math /// A packed integer containing all four color components. public int ToBgra() { - uint a = (uint)(A * 255.0f) & 255; - uint r = (uint)(R * 255.0f) & 255; - uint g = (uint)(G * 255.0f) & 255; - uint b = (uint)(B * 255.0f) & 255; + uint a = (uint)( A * 255.0f ) & 255; + uint r = (uint)( R * 255.0f ) & 255; + uint g = (uint)( G * 255.0f ) & 255; + uint b = (uint)( B * 255.0f ) & 255; uint value = b; value |= g << 8; @@ -275,12 +288,12 @@ namespace math /// /// Converts the color into a packed integer. /// - public void ToBgra(out byte r, out byte g, out byte b, out byte a) + public void ToBgra( out byte r, out byte g, out byte b, out byte a ) { - a = (byte)(A * 255.0f); - r = (byte)(R * 255.0f); - g = (byte)(G * 255.0f); - b = (byte)(B * 255.0f); + a = (byte)( A * 255.0f ); + r = (byte)( R * 255.0f ); + g = (byte)( G * 255.0f ); + b = (byte)( B * 255.0f ); } /// @@ -289,10 +302,10 @@ namespace math /// A packed integer containing all four color components. public int ToRgba() { - uint a = (uint)(A * 255.0f) & 255; - uint r = (uint)(R * 255.0f) & 255; - uint g = (uint)(G * 255.0f) & 255; - uint b = (uint)(B * 255.0f) & 255; + uint a = (uint)( A * 255.0f ) & 255; + uint r = (uint)( R * 255.0f ) & 255; + uint g = (uint)( G * 255.0f ) & 255; + uint b = (uint)( B * 255.0f ) & 255; uint value = r; value |= g << 8; @@ -308,7 +321,7 @@ namespace math /// A three component vector containing the red, green, and blue components of the color. public Vec3 ToVector3() { - return new Vec3(R, G, B); + return new Vec3( R, G, B ); } /// @@ -317,7 +330,7 @@ namespace math /// A four component vector containing all four color components. public Vec4 ToVector4() { - return new Vec4(R, G, B, A); + return new Vec4( R, G, B, A ); } /// @@ -335,7 +348,7 @@ namespace math /// A color3 in sRGB space. public Color4 ToSRgb() { - return new Color4(MathUtil.LinearToSRgb(R), MathUtil.LinearToSRgb(G), MathUtil.LinearToSRgb(B), A); + return new Color4( MathUtil.LinearToSRgb( R ), MathUtil.LinearToSRgb( G ), MathUtil.LinearToSRgb( B ), A ); } /// @@ -344,7 +357,7 @@ namespace math /// A color4 in linear space. public Color4 ToLinear() { - return new Color4(MathUtil.SRgbToLinear(R), MathUtil.SRgbToLinear(G), MathUtil.SRgbToLinear(B), A); + return new Color4( MathUtil.SRgbToLinear( R ), MathUtil.SRgbToLinear( G ), MathUtil.SRgbToLinear( B ), A ); } /// @@ -353,7 +366,7 @@ namespace math /// The first color to add. /// The second color to add. /// When the method completes, completes the sum of the two colors. - public static void Add(ref Color4 left, ref Color4 right, out Color4 result) + public static void Add( ref Color4 left, ref Color4 right, out Color4 result ) { result.A = left.A + right.A; result.R = left.R + right.R; @@ -367,9 +380,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static Color4 Add(Color4 left, Color4 right) + public static Color4 Add( Color4 left, Color4 right ) { - return new Color4(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A); + return new Color4( left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A ); } /// @@ -378,7 +391,7 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// WHen the method completes, contains the difference of the two colors. - public static void Subtract(ref Color4 left, ref Color4 right, out Color4 result) + public static void Subtract( ref Color4 left, ref Color4 right, out Color4 result ) { result.A = left.A - right.A; result.R = left.R - right.R; @@ -392,9 +405,9 @@ namespace math /// The first color to subtract. /// The second color to subtract /// The difference of the two colors. - public static Color4 Subtract(Color4 left, Color4 right) + public static Color4 Subtract( Color4 left, Color4 right ) { - return new Color4(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A); + return new Color4( left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A ); } /// @@ -403,7 +416,7 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// When the method completes, contains the modulated color. - public static void Modulate(ref Color4 left, ref Color4 right, out Color4 result) + public static void Modulate( ref Color4 left, ref Color4 right, out Color4 result ) { result.A = left.A * right.A; result.R = left.R * right.R; @@ -417,9 +430,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static Color4 Modulate(Color4 left, Color4 right) + public static Color4 Modulate( Color4 left, Color4 right ) { - return new Color4(left.R * right.R, left.G * right.G, left.B * right.B, left.A * right.A); + return new Color4( left.R * right.R, left.G * right.G, left.B * right.B, left.A * right.A ); } /// @@ -428,7 +441,7 @@ namespace math /// The color to scale. /// The amount by which to scale. /// When the method completes, contains the scaled color. - public static void Scale(ref Color4 value, float scale, out Color4 result) + public static void Scale( ref Color4 value, float scale, out Color4 result ) { result.A = value.A * scale; result.R = value.R * scale; @@ -442,9 +455,9 @@ namespace math /// The color to scale. /// The amount by which to scale. /// The scaled color. - public static Color4 Scale(Color4 value, float scale) + public static Color4 Scale( Color4 value, float scale ) { - return new Color4(value.R * scale, value.G * scale, value.B * scale, value.A * scale); + return new Color4( value.R * scale, value.G * scale, value.B * scale, value.A * scale ); } /// @@ -452,7 +465,7 @@ namespace math /// /// The color to negate. /// When the method completes, contains the negated color. - public static void Negate(ref Color4 value, out Color4 result) + public static void Negate( ref Color4 value, out Color4 result ) { result.A = 1.0f - value.A; result.R = 1.0f - value.R; @@ -465,9 +478,9 @@ namespace math /// /// The color to negate. /// The negated color. - public static Color4 Negate(Color4 value) + public static Color4 Negate( Color4 value ) { - return new Color4(1.0f - value.R, 1.0f - value.G, 1.0f - value.B, 1.0f - value.A); + return new Color4( 1.0f - value.R, 1.0f - value.G, 1.0f - value.B, 1.0f - value.A ); } /// @@ -477,25 +490,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Color4 value, ref Color4 min, ref Color4 max, out Color4 result) + public static void Clamp( ref Color4 value, ref Color4 min, ref Color4 max, out Color4 result ) { float alpha = value.A; - alpha = (alpha > max.A) ? max.A : alpha; - alpha = (alpha < min.A) ? min.A : alpha; + alpha = ( alpha > max.A ) ? max.A : alpha; + alpha = ( alpha < min.A ) ? min.A : alpha; float red = value.R; - red = (red > max.R) ? max.R : red; - red = (red < min.R) ? min.R : red; + red = ( red > max.R ) ? max.R : red; + red = ( red < min.R ) ? min.R : red; float green = value.G; - green = (green > max.G) ? max.G : green; - green = (green < min.G) ? min.G : green; + green = ( green > max.G ) ? max.G : green; + green = ( green < min.G ) ? min.G : green; float blue = value.B; - blue = (blue > max.B) ? max.B : blue; - blue = (blue < min.B) ? min.B : blue; + blue = ( blue > max.B ) ? max.B : blue; + blue = ( blue < min.B ) ? min.B : blue; - result = new Color4(red, green, blue, alpha); + result = new Color4( red, green, blue, alpha ); } /// @@ -505,10 +518,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Color4 Clamp(Color4 value, Color4 min, Color4 max) + public static Color4 Clamp( Color4 value, Color4 min, Color4 max ) { Color4 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -520,14 +533,14 @@ namespace math /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two colors. /// - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Color4 start, ref Color4 end, float amount, out Color4 result) + public static void Lerp( ref Color4 start, ref Color4 end, float amount, out Color4 result ) { - result.R = MathUtil.Lerp(start.R, end.R, amount); - result.G = MathUtil.Lerp(start.G, end.G, amount); - result.B = MathUtil.Lerp(start.B, end.B, amount); - result.A = MathUtil.Lerp(start.A, end.A, amount); + result.R = MathUtil.Lerp( start.R, end.R, amount ); + result.G = MathUtil.Lerp( start.G, end.G, amount ); + result.B = MathUtil.Lerp( start.B, end.B, amount ); + result.A = MathUtil.Lerp( start.A, end.A, amount ); } /// @@ -538,12 +551,12 @@ namespace math /// Value between 0 and 1 indicating the weight of . /// The linear interpolation of the two colors. /// - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Color4 Lerp(Color4 start, Color4 end, float amount) + public static Color4 Lerp( Color4 start, Color4 end, float amount ) { Color4 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -554,10 +567,10 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two colors. - public static void SmoothStep(ref Color4 start, ref Color4 end, float amount, out Color4 result) + public static void SmoothStep( ref Color4 start, ref Color4 end, float amount, out Color4 result ) { - amount = MathUtil.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + amount = MathUtil.SmoothStep( amount ); + Lerp( ref start, ref end, amount, out result ); } /// @@ -567,10 +580,10 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two colors. - public static Color4 SmoothStep(Color4 start, Color4 end, float amount) + public static Color4 SmoothStep( Color4 start, Color4 end, float amount ) { Color4 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -580,12 +593,12 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the largest components of the source colors. - public static void Max(ref Color4 left, ref Color4 right, out Color4 result) + public static void Max( ref Color4 left, ref Color4 right, out Color4 result ) { - result.A = (left.A > right.A) ? left.A : right.A; - result.R = (left.R > right.R) ? left.R : right.R; - result.G = (left.G > right.G) ? left.G : right.G; - result.B = (left.B > right.B) ? left.B : right.B; + result.A = ( left.A > right.A ) ? left.A : right.A; + result.R = ( left.R > right.R ) ? left.R : right.R; + result.G = ( left.G > right.G ) ? left.G : right.G; + result.B = ( left.B > right.B ) ? left.B : right.B; } /// @@ -594,10 +607,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the largest components of the source colors. - public static Color4 Max(Color4 left, Color4 right) + public static Color4 Max( Color4 left, Color4 right ) { Color4 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -607,12 +620,12 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the smallest components of the source colors. - public static void Min(ref Color4 left, ref Color4 right, out Color4 result) + public static void Min( ref Color4 left, ref Color4 right, out Color4 result ) { - result.A = (left.A < right.A) ? left.A : right.A; - result.R = (left.R < right.R) ? left.R : right.R; - result.G = (left.G < right.G) ? left.G : right.G; - result.B = (left.B < right.B) ? left.B : right.B; + result.A = ( left.A < right.A ) ? left.A : right.A; + result.R = ( left.R < right.R ) ? left.R : right.R; + result.G = ( left.G < right.G ) ? left.G : right.G; + result.B = ( left.B < right.B ) ? left.B : right.B; } /// @@ -621,10 +634,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the smallest components of the source colors. - public static Color4 Min(Color4 left, Color4 right) + public static Color4 Min( Color4 left, Color4 right ) { Color4 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -634,12 +647,12 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// When the method completes, contains the adjusted color. - public static void AdjustContrast(ref Color4 value, float contrast, out Color4 result) + public static void AdjustContrast( ref Color4 value, float contrast, out Color4 result ) { result.A = value.A; - result.R = 0.5f + contrast * (value.R - 0.5f); - result.G = 0.5f + contrast * (value.G - 0.5f); - result.B = 0.5f + contrast * (value.B - 0.5f); + result.R = 0.5f + contrast * ( value.R - 0.5f ); + result.G = 0.5f + contrast * ( value.G - 0.5f ); + result.B = 0.5f + contrast * ( value.B - 0.5f ); } /// @@ -648,13 +661,13 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// The adjusted color. - public static Color4 AdjustContrast(Color4 value, float contrast) + public static Color4 AdjustContrast( Color4 value, float contrast ) { return new Color4( - 0.5f + contrast * (value.R - 0.5f), - 0.5f + contrast * (value.G - 0.5f), - 0.5f + contrast * (value.B - 0.5f), - value.A); + 0.5f + contrast * ( value.R - 0.5f ), + 0.5f + contrast * ( value.G - 0.5f ), + 0.5f + contrast * ( value.B - 0.5f ), + value.A ); } /// @@ -663,14 +676,14 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// When the method completes, contains the adjusted color. - public static void AdjustSaturation(ref Color4 value, float saturation, out Color4 result) + public static void AdjustSaturation( ref Color4 value, float saturation, out Color4 result ) { float grey = value.R * 0.2125f + value.G * 0.7154f + value.B * 0.0721f; result.A = value.A; - result.R = grey + saturation * (value.R - grey); - result.G = grey + saturation * (value.G - grey); - result.B = grey + saturation * (value.B - grey); + result.R = grey + saturation * ( value.R - grey ); + result.G = grey + saturation * ( value.G - grey ); + result.B = grey + saturation * ( value.B - grey ); } /// @@ -679,15 +692,15 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// The adjusted color. - public static Color4 AdjustSaturation(Color4 value, float saturation) + public static Color4 AdjustSaturation( Color4 value, float saturation ) { float grey = value.R * 0.2125f + value.G * 0.7154f + value.B * 0.0721f; return new Color4( - grey + saturation * (value.R - grey), - grey + saturation * (value.G - grey), - grey + saturation * (value.B - grey), - value.A); + grey + saturation * ( value.R - grey ), + grey + saturation * ( value.G - grey ), + grey + saturation * ( value.B - grey ), + value.A ); } /// @@ -695,9 +708,9 @@ namespace math /// /// The color to premultiply. /// A color with premultiplied alpha. - public static Color4 PremultiplyAlpha(Color4 value) + public static Color4 PremultiplyAlpha( Color4 value ) { - return new Color4(value.R * value.A, value.G * value.A, value.B * value.A, value.A); + return new Color4( value.R * value.A, value.G * value.A, value.B * value.A, value.A ); } /// @@ -706,9 +719,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static Color4 operator +(Color4 left, Color4 right) + public static Color4 operator +( Color4 left, Color4 right ) { - return new Color4(left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A); + return new Color4( left.R + right.R, left.G + right.G, left.B + right.B, left.A + right.A ); } /// @@ -716,7 +729,7 @@ namespace math /// /// The color to assert (unchanged). /// The asserted (unchanged) color. - public static Color4 operator +(Color4 value) + public static Color4 operator +( Color4 value ) { return value; } @@ -727,9 +740,9 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// The difference of the two colors. - public static Color4 operator -(Color4 left, Color4 right) + public static Color4 operator -( Color4 left, Color4 right ) { - return new Color4(left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A); + return new Color4( left.R - right.R, left.G - right.G, left.B - right.B, left.A - right.A ); } /// @@ -737,9 +750,9 @@ namespace math /// /// The color to negate. /// A negated color. - public static Color4 operator -(Color4 value) + public static Color4 operator -( Color4 value ) { - return new Color4(-value.R, -value.G, -value.B, -value.A); + return new Color4( -value.R, -value.G, -value.B, -value.A ); } /// @@ -748,9 +761,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static Color4 operator *(float scale, Color4 value) + public static Color4 operator *( float scale, Color4 value ) { - return new Color4(value.R * scale, value.G * scale, value.B * scale, value.A * scale); + return new Color4( value.R * scale, value.G * scale, value.B * scale, value.A * scale ); } /// @@ -759,9 +772,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static Color4 operator *(Color4 value, float scale) + public static Color4 operator *( Color4 value, float scale ) { - return new Color4(value.R * scale, value.G * scale, value.B * scale, value.A * scale); + return new Color4( value.R * scale, value.G * scale, value.B * scale, value.A * scale ); } /// @@ -770,9 +783,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static Color4 operator *(Color4 left, Color4 right) + public static Color4 operator *( Color4 left, Color4 right ) { - return new Color4(left.R * right.R, left.G * right.G, left.B * right.B, left.A * right.A); + return new Color4( left.R * right.R, left.G * right.G, left.B * right.B, left.A * right.A ); } /// @@ -781,9 +794,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Color4 left, Color4 right) + public static bool operator ==( Color4 left, Color4 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -792,9 +805,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Color4 left, Color4 right) + public static bool operator !=( Color4 left, Color4 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -802,9 +815,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color3(Color4 value) + public static explicit operator Color3( Color4 value ) { - return new Color3(value.R, value.G, value.B); + return new Color3( value.R, value.G, value.B ); } /// @@ -812,9 +825,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Color4 value) + public static explicit operator Vec3( Color4 value ) { - return new Vec3(value.R, value.G, value.B); + return new Vec3( value.R, value.G, value.B ); } /// @@ -822,9 +835,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Vec4(Color4 value) + public static implicit operator Vec4( Color4 value ) { - return new Vec4(value.R, value.G, value.B, value.A); + return new Vec4( value.R, value.G, value.B, value.A ); } /// @@ -832,9 +845,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color4(Vec3 value) + public static explicit operator Color4( Vec3 value ) { - return new Color4(value.X, value.Y, value.Z, 1.0f); + return new Color4( value.X, value.Y, value.Z, 1.0f ); } /// @@ -842,9 +855,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color4(Vec4 value) + public static explicit operator Color4( Vec4 value ) { - return new Color4(value.X, value.Y, value.Z, value.W); + return new Color4( value.X, value.Y, value.Z, value.W ); } /// @@ -852,9 +865,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color4(ColorBGRA value) + public static explicit operator Color4( ColorBGRA value ) { - return new Color4(value); + return new Color4( value ); } /// @@ -862,9 +875,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator ColorBGRA(Color4 value) + public static explicit operator ColorBGRA( Color4 value ) { - return new ColorBGRA(value.R, value.G, value.B, value.A); + return new ColorBGRA( value.R, value.G, value.B, value.A ); } /// @@ -874,7 +887,7 @@ namespace math /// /// The result of the conversion. /// - public static explicit operator int(Color4 value) + public static explicit operator int( Color4 value ) { return value.ToRgba(); } @@ -886,9 +899,9 @@ namespace math /// /// The result of the conversion. /// - public static explicit operator Color4(int value) + public static explicit operator Color4( int value ) { - return new Color4(value); + return new Color4( value ); } /// @@ -897,7 +910,7 @@ namespace math /// An equivalent , discarding the alpha channel. public Color3 ToColor3() { - return new Color3(R, G, B); + return new Color3( R, G, B ); } /// @@ -908,7 +921,7 @@ namespace math /// public override string ToString() { - return ToString(CultureInfo.CurrentCulture); + return ToString( CultureInfo.CurrentCulture ); } /// @@ -918,9 +931,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - return ToString(format, CultureInfo.CurrentCulture); + return ToString( format, CultureInfo.CurrentCulture ); } /// @@ -930,9 +943,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, ToStringFormat, A, R, G, B); + return string.Format( formatProvider, ToStringFormat, A, R, G, B ); } /// @@ -943,23 +956,23 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, ToStringFormat, - A.ToString(format, formatProvider), - R.ToString(format, formatProvider), - G.ToString(format, formatProvider), - B.ToString(format, formatProvider)); + return string.Format( formatProvider, ToStringFormat, + A.ToString( format, formatProvider ), + R.ToString( format, formatProvider ), + G.ToString( format, formatProvider ), + B.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -973,7 +986,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Color4 other) + public bool Equals( Color4 other ) { return A == other.A && R == other.R && G == other.G && B == other.B; } @@ -985,15 +998,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (!ReferenceEquals(value.GetType(), typeof(Color4))) + if( !ReferenceEquals( value.GetType(), typeof( Color4 ) ) ) return false; - return Equals((Color4)value); + return Equals( (Color4)value ); } } } diff --git a/math/ColorBGRA.cs b/math/ColorBGRA.cs index bccda8f..dcd452b 100644 --- a/math/ColorBGRA.cs +++ b/math/ColorBGRA.cs @@ -10,9 +10,9 @@ namespace math /// /// Represents a 32-bit color (4 bytes) in the form of BGRA (in byte order: B, G, R, A). /// - [DataContract( Name = "ColorBGRA")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Size = 4)] + [DataContract( Name = "ColorBGRA" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Size = 4 )] public partial struct ColorBGRA : IEquatable, IFormattable { private const string ToStringFormat = "A:{0} R:{1} G:{2} B:{3}"; @@ -45,7 +45,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public ColorBGRA(byte value) + public ColorBGRA( byte value ) { A = R = G = B = value; } @@ -54,9 +54,9 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public ColorBGRA(float value) + public ColorBGRA( float value ) { - A = R = G = B = ToByte(value); + A = R = G = B = ToByte( value ); } /// @@ -66,7 +66,7 @@ namespace math /// The green component of the color. /// The blue component of the color. /// The alpha component of the color. - public ColorBGRA(byte red, byte green, byte blue, byte alpha) + public ColorBGRA( byte red, byte green, byte blue, byte alpha ) { R = red; G = green; @@ -81,24 +81,24 @@ namespace math /// The green component of the color. /// The blue component of the color. /// The alpha component of the color. - public ColorBGRA(float red, float green, float blue, float alpha) + public ColorBGRA( float red, float green, float blue, float alpha ) { - R = ToByte(red); - G = ToByte(green); - B = ToByte(blue); - A = ToByte(alpha); + R = ToByte( red ); + G = ToByte( green ); + B = ToByte( blue ); + A = ToByte( alpha ); } /// /// Initializes a new instance of the struct. /// /// The red, green, blue, and alpha components of the color. - public ColorBGRA(Vec4 value) + public ColorBGRA( Vec4 value ) { - R = ToByte(value.X); - G = ToByte(value.Y); - B = ToByte(value.Z); - A = ToByte(value.W); + R = ToByte( value.X ); + G = ToByte( value.Y ); + B = ToByte( value.Z ); + A = ToByte( value.W ); } /// @@ -106,36 +106,36 @@ namespace math /// /// The red, green, and blue components of the color. /// The alpha component of the color. - public ColorBGRA(Vec3 value, float alpha) + public ColorBGRA( Vec3 value, float alpha ) { - R = ToByte(value.X); - G = ToByte(value.Y); - B = ToByte(value.Z); - A = ToByte(alpha); + R = ToByte( value.X ); + G = ToByte( value.Y ); + B = ToByte( value.Z ); + A = ToByte( alpha ); } /// /// Initializes a new instance of the struct. /// /// A packed integer containing all four color components in BGRA order. - public ColorBGRA(uint bgra) + public ColorBGRA( uint bgra ) { - A = (byte)((bgra >> 24) & 255); - R = (byte)((bgra >> 16) & 255); - G = (byte)((bgra >> 8) & 255); - B = (byte)(bgra & 255); + A = (byte)( ( bgra >> 24 ) & 255 ); + R = (byte)( ( bgra >> 16 ) & 255 ); + G = (byte)( ( bgra >> 8 ) & 255 ); + B = (byte)( bgra & 255 ); } /// /// Initializes a new instance of the struct. /// /// A packed integer containing all four color components in BGRA. - public ColorBGRA(int bgra) + public ColorBGRA( int bgra ) { - A = (byte)((bgra >> 24) & 255); - R = (byte)((bgra >> 16) & 255); - G = (byte)((bgra >> 8) & 255); - B = (byte)(bgra & 255); + A = (byte)( ( bgra >> 24 ) & 255 ); + R = (byte)( ( bgra >> 16 ) & 255 ); + G = (byte)( ( bgra >> 8 ) & 255 ); + B = (byte)( bgra & 255 ); } /// @@ -144,17 +144,17 @@ namespace math /// The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public ColorBGRA(float[] values) + public ColorBGRA( float[] values ) { - if (values == null) - throw new ArgumentNullException(nameof(values)); - if (values.Length != 4) - throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for ColorBGRA."); + if( values == null ) + throw new ArgumentNullException( nameof( values ) ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( nameof( values ), "There must be four and only four input values for ColorBGRA." ); - B = ToByte(values[0]); - G = ToByte(values[1]); - R = ToByte(values[2]); - A = ToByte(values[3]); + B = ToByte( values[0] ); + G = ToByte( values[1] ); + R = ToByte( values[2] ); + A = ToByte( values[3] ); } /// @@ -163,12 +163,12 @@ namespace math /// The values to assign to the red, green, and blue, alpha components of the color. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public ColorBGRA(byte[] values) + public ColorBGRA( byte[] values ) { - if (values == null) - throw new ArgumentNullException(nameof(values)); - if (values.Length != 4) - throw new ArgumentOutOfRangeException(nameof(values), "There must be four and only four input values for ColorBGRA."); + if( values == null ) + throw new ArgumentNullException( nameof( values ) ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( nameof( values ), "There must be four and only four input values for ColorBGRA." ); B = values[0]; G = values[1]; @@ -187,26 +187,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return B; - case 1: return G; - case 2: return R; - case 3: return A; + case 0: + return B; + case 1: + return G; + case 2: + return R; + case 3: + return A; } - throw new ArgumentOutOfRangeException(nameof(index), "Indices for ColorBGRA run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for ColorBGRA run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: B = value; break; - case 1: G = value; break; - case 2: R = value; break; - case 3: A = value; break; - default: throw new ArgumentOutOfRangeException(nameof(index), "Indices for ColorBGRA run from 0 to 3, inclusive."); + case 0: + B = value; + break; + case 1: + G = value; + break; + case 2: + R = value; + break; + case 3: + A = value; + break; + default: + throw new ArgumentOutOfRangeException( nameof( index ), "Indices for ColorBGRA run from 0 to 3, inclusive." ); } } } @@ -245,7 +258,7 @@ namespace math /// A three component vector containing the red, green, and blue components of the color. public Vec3 ToVector3() { - return new Vec3(R / 255.0f, G / 255.0f, B / 255.0f); + return new Vec3( R / 255.0f, G / 255.0f, B / 255.0f ); } /// @@ -254,7 +267,7 @@ namespace math /// A three component color containing the red, green, and blue components of the color. public Color3 ToColor3() { - return new Color3(R / 255.0f, G / 255.0f, B / 255.0f); + return new Color3( R / 255.0f, G / 255.0f, B / 255.0f ); } /// @@ -263,7 +276,7 @@ namespace math /// A four component vector containing all four color components. public Vec4 ToVector4() { - return new Vec4(R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f); + return new Vec4( R / 255.0f, G / 255.0f, B / 255.0f, A / 255.0f ); } /// @@ -290,13 +303,17 @@ namespace math max = r; min = r; - if (g > max) max = g; - if (b > max) max = b; + if( g > max ) + max = g; + if( b > max ) + max = b; - if (g < min) min = g; - if (b < min) min = b; + if( g < min ) + min = g; + if( b < min ) + min = b; - return (max + min) / 2; + return ( max + min ) / 2; } /// @@ -305,7 +322,7 @@ namespace math /// The Hue-Saturation-Brightness (HSB) saturation for this public float GetHue() { - if (R == G && G == B) + if( R == G && G == B ) return 0; // 0 makes as good an UNDEFINED value as any float r = R / 255.0f; @@ -319,29 +336,33 @@ namespace math max = r; min = r; - if (g > max) max = g; - if (b > max) max = b; + if( g > max ) + max = g; + if( b > max ) + max = b; - if (g < min) min = g; - if (b < min) min = b; + if( g < min ) + min = g; + if( b < min ) + min = b; delta = max - min; - if (r == max) + if( r == max ) { - hue = (g - b) / delta; + hue = ( g - b ) / delta; } - else if (g == max) + else if( g == max ) { - hue = 2 + (b - r) / delta; + hue = 2 + ( b - r ) / delta; } - else if (b == max) + else if( b == max ) { - hue = 4 + (r - g) / delta; + hue = 4 + ( r - g ) / delta; } hue *= 60; - if (hue < 0.0f) + if( hue < 0.0f ) { hue += 360.0f; } @@ -364,25 +385,29 @@ namespace math max = r; min = r; - if (g > max) max = g; - if (b > max) max = b; + if( g > max ) + max = g; + if( b > max ) + max = b; - if (g < min) min = g; - if (b < min) min = b; + if( g < min ) + min = g; + if( b < min ) + min = b; // if max == min, then there is no color and // the saturation is zero. - if (max != min) + if( max != min ) { - l = (max + min) / 2; + l = ( max + min ) / 2; - if (l <= .5) + if( l <= .5 ) { - s = (max - min) / (max + min); + s = ( max - min ) / ( max + min ); } else { - s = (max - min) / (2 - max - min); + s = ( max - min ) / ( 2 - max - min ); } } return s; @@ -393,9 +418,9 @@ namespace math /// /// A packed integer containing all four color components in BGRA order /// A color. - public static ColorBGRA FromBgra(int color) + public static ColorBGRA FromBgra( int color ) { - return new ColorBGRA(color); + return new ColorBGRA( color ); } /// @@ -403,9 +428,9 @@ namespace math /// /// A packed integer containing all four color components in BGRA order /// A color. - public static ColorBGRA FromBgra(uint color) + public static ColorBGRA FromBgra( uint color ) { - return new ColorBGRA(color); + return new ColorBGRA( color ); } /// @@ -413,9 +438,9 @@ namespace math /// /// A packed integer containing all four color components in RGBA order /// A color. - public static ColorBGRA FromRgba(int color) + public static ColorBGRA FromRgba( int color ) { - return new ColorBGRA((byte)(color & 255), (byte)((color >> 8) & 255), (byte)((color >> 16) & 255), (byte)((color >> 24) & 255)); + return new ColorBGRA( (byte)( color & 255 ), (byte)( ( color >> 8 ) & 255 ), (byte)( ( color >> 16 ) & 255 ), (byte)( ( color >> 24 ) & 255 ) ); } /// @@ -423,9 +448,9 @@ namespace math /// /// A packed integer containing all four color components in RGBA order /// A color. - public static ColorBGRA FromRgba(uint color) + public static ColorBGRA FromRgba( uint color ) { - return FromRgba(unchecked((int)color)); + return FromRgba( unchecked((int)color) ); } /// @@ -434,12 +459,12 @@ namespace math /// The first color to add. /// The second color to add. /// When the method completes, completes the sum of the two colors. - public static void Add(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result) + public static void Add( ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result ) { - result.A = (byte)(left.A + right.A); - result.R = (byte)(left.R + right.R); - result.G = (byte)(left.G + right.G); - result.B = (byte)(left.B + right.B); + result.A = (byte)( left.A + right.A ); + result.R = (byte)( left.R + right.R ); + result.G = (byte)( left.G + right.G ); + result.B = (byte)( left.B + right.B ); } /// @@ -448,9 +473,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static ColorBGRA Add(ColorBGRA left, ColorBGRA right) + public static ColorBGRA Add( ColorBGRA left, ColorBGRA right ) { - return new ColorBGRA((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A)); + return new ColorBGRA( (byte)( left.R + right.R ), (byte)( left.G + right.G ), (byte)( left.B + right.B ), (byte)( left.A + right.A ) ); } /// @@ -459,12 +484,12 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// WHen the method completes, contains the difference of the two colors. - public static void Subtract(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result) + public static void Subtract( ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result ) { - result.A = (byte)(left.A - right.A); - result.R = (byte)(left.R - right.R); - result.G = (byte)(left.G - right.G); - result.B = (byte)(left.B - right.B); + result.A = (byte)( left.A - right.A ); + result.R = (byte)( left.R - right.R ); + result.G = (byte)( left.G - right.G ); + result.B = (byte)( left.B - right.B ); } /// @@ -473,9 +498,9 @@ namespace math /// The first color to subtract. /// The second color to subtract /// The difference of the two colors. - public static ColorBGRA Subtract(ColorBGRA left, ColorBGRA right) + public static ColorBGRA Subtract( ColorBGRA left, ColorBGRA right ) { - return new ColorBGRA((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A)); + return new ColorBGRA( (byte)( left.R - right.R ), (byte)( left.G - right.G ), (byte)( left.B - right.B ), (byte)( left.A - right.A ) ); } /// @@ -484,12 +509,12 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// When the method completes, contains the modulated color. - public static void Modulate(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result) + public static void Modulate( ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result ) { - result.A = (byte)(left.A * right.A / 255); - result.R = (byte)(left.R * right.R / 255); - result.G = (byte)(left.G * right.G / 255); - result.B = (byte)(left.B * right.B / 255); + result.A = (byte)( left.A * right.A / 255 ); + result.R = (byte)( left.R * right.R / 255 ); + result.G = (byte)( left.G * right.G / 255 ); + result.B = (byte)( left.B * right.B / 255 ); } /// @@ -498,9 +523,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static ColorBGRA Modulate(ColorBGRA left, ColorBGRA right) + public static ColorBGRA Modulate( ColorBGRA left, ColorBGRA right ) { - return new ColorBGRA((byte)((left.R * right.R) / 255), (byte)((left.G * right.G) / 255), (byte)((left.B * right.B) / 255), (byte)((left.A * right.A) / 255)); + return new ColorBGRA( (byte)( ( left.R * right.R ) / 255 ), (byte)( ( left.G * right.G ) / 255 ), (byte)( ( left.B * right.B ) / 255 ), (byte)( ( left.A * right.A ) / 255 ) ); } /// @@ -509,12 +534,12 @@ namespace math /// The color to scale. /// The amount by which to scale. /// When the method completes, contains the scaled color. - public static void Scale(ref ColorBGRA value, float scale, out ColorBGRA result) + public static void Scale( ref ColorBGRA value, float scale, out ColorBGRA result ) { - result.A = (byte)(value.A * scale); - result.R = (byte)(value.R * scale); - result.G = (byte)(value.G * scale); - result.B = (byte)(value.B * scale); + result.A = (byte)( value.A * scale ); + result.R = (byte)( value.R * scale ); + result.G = (byte)( value.G * scale ); + result.B = (byte)( value.B * scale ); } /// @@ -523,9 +548,9 @@ namespace math /// The color to scale. /// The amount by which to scale. /// The scaled color. - public static ColorBGRA Scale(ColorBGRA value, float scale) + public static ColorBGRA Scale( ColorBGRA value, float scale ) { - return new ColorBGRA((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale)); + return new ColorBGRA( (byte)( value.R * scale ), (byte)( value.G * scale ), (byte)( value.B * scale ), (byte)( value.A * scale ) ); } /// @@ -533,12 +558,12 @@ namespace math /// /// The color to negate. /// When the method completes, contains the negated color. - public static void Negate(ref ColorBGRA value, out ColorBGRA result) + public static void Negate( ref ColorBGRA value, out ColorBGRA result ) { - result.A = (byte)(255 - value.A); - result.R = (byte)(255 - value.R); - result.G = (byte)(255 - value.G); - result.B = (byte)(255 - value.B); + result.A = (byte)( 255 - value.A ); + result.R = (byte)( 255 - value.R ); + result.G = (byte)( 255 - value.G ); + result.B = (byte)( 255 - value.B ); } /// @@ -546,9 +571,9 @@ namespace math /// /// The color to negate. /// The negated color. - public static ColorBGRA Negate(ColorBGRA value) + public static ColorBGRA Negate( ColorBGRA value ) { - return new ColorBGRA((byte)(255 - value.R), (byte)(255 - value.G), (byte)(255 - value.B), (byte)(255 - value.A)); + return new ColorBGRA( (byte)( 255 - value.R ), (byte)( 255 - value.G ), (byte)( 255 - value.B ), (byte)( 255 - value.A ) ); } /// @@ -558,25 +583,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref ColorBGRA value, ref ColorBGRA min, ref ColorBGRA max, out ColorBGRA result) + public static void Clamp( ref ColorBGRA value, ref ColorBGRA min, ref ColorBGRA max, out ColorBGRA result ) { byte alpha = value.A; - alpha = (alpha > max.A) ? max.A : alpha; - alpha = (alpha < min.A) ? min.A : alpha; + alpha = ( alpha > max.A ) ? max.A : alpha; + alpha = ( alpha < min.A ) ? min.A : alpha; byte red = value.R; - red = (red > max.R) ? max.R : red; - red = (red < min.R) ? min.R : red; + red = ( red > max.R ) ? max.R : red; + red = ( red < min.R ) ? min.R : red; byte green = value.G; - green = (green > max.G) ? max.G : green; - green = (green < min.G) ? min.G : green; + green = ( green > max.G ) ? max.G : green; + green = ( green < min.G ) ? min.G : green; byte blue = value.B; - blue = (blue > max.B) ? max.B : blue; - blue = (blue < min.B) ? min.B : blue; + blue = ( blue > max.B ) ? max.B : blue; + blue = ( blue < min.B ) ? min.B : blue; - result = new ColorBGRA(red, green, blue, alpha); + result = new ColorBGRA( red, green, blue, alpha ); } /// @@ -586,10 +611,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static ColorBGRA Clamp(ColorBGRA value, ColorBGRA min, ColorBGRA max) + public static ColorBGRA Clamp( ColorBGRA value, ColorBGRA min, ColorBGRA max ) { ColorBGRA result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -601,14 +626,14 @@ namespace math /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the linear interpolation of the two colors. /// - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result) + public static void Lerp( ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result ) { - result.B = MathUtil.Lerp(start.B, end.B, amount); - result.G = MathUtil.Lerp(start.G, end.G, amount); - result.R = MathUtil.Lerp(start.R, end.R, amount); - result.A = MathUtil.Lerp(start.A, end.A, amount); + result.B = MathUtil.Lerp( start.B, end.B, amount ); + result.G = MathUtil.Lerp( start.G, end.G, amount ); + result.R = MathUtil.Lerp( start.R, end.R, amount ); + result.A = MathUtil.Lerp( start.A, end.A, amount ); } /// @@ -619,12 +644,12 @@ namespace math /// Value between 0 and 1 indicating the weight of . /// The linear interpolation of the two colors. /// - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static ColorBGRA Lerp(ColorBGRA start, ColorBGRA end, float amount) + public static ColorBGRA Lerp( ColorBGRA start, ColorBGRA end, float amount ) { ColorBGRA result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -635,10 +660,10 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two colors. - public static void SmoothStep(ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result) + public static void SmoothStep( ref ColorBGRA start, ref ColorBGRA end, float amount, out ColorBGRA result ) { - amount = MathUtil.SmoothStep(amount); - Lerp(ref start, ref end, amount, out result); + amount = MathUtil.SmoothStep( amount ); + Lerp( ref start, ref end, amount, out result ); } /// @@ -648,10 +673,10 @@ namespace math /// End color. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two colors. - public static ColorBGRA SmoothStep(ColorBGRA start, ColorBGRA end, float amount) + public static ColorBGRA SmoothStep( ColorBGRA start, ColorBGRA end, float amount ) { ColorBGRA result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -661,12 +686,12 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the largest components of the source colorss. - public static void Max(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result) + public static void Max( ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result ) { - result.A = (left.A > right.A) ? left.A : right.A; - result.R = (left.R > right.R) ? left.R : right.R; - result.G = (left.G > right.G) ? left.G : right.G; - result.B = (left.B > right.B) ? left.B : right.B; + result.A = ( left.A > right.A ) ? left.A : right.A; + result.R = ( left.R > right.R ) ? left.R : right.R; + result.G = ( left.G > right.G ) ? left.G : right.G; + result.B = ( left.B > right.B ) ? left.B : right.B; } /// @@ -675,10 +700,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the largest components of the source colors. - public static ColorBGRA Max(ColorBGRA left, ColorBGRA right) + public static ColorBGRA Max( ColorBGRA left, ColorBGRA right ) { ColorBGRA result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -688,12 +713,12 @@ namespace math /// The first source color. /// The second source color. /// When the method completes, contains an new color composed of the smallest components of the source colors. - public static void Min(ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result) + public static void Min( ref ColorBGRA left, ref ColorBGRA right, out ColorBGRA result ) { - result.A = (left.A < right.A) ? left.A : right.A; - result.R = (left.R < right.R) ? left.R : right.R; - result.G = (left.G < right.G) ? left.G : right.G; - result.B = (left.B < right.B) ? left.B : right.B; + result.A = ( left.A < right.A ) ? left.A : right.A; + result.R = ( left.R < right.R ) ? left.R : right.R; + result.G = ( left.G < right.G ) ? left.G : right.G; + result.B = ( left.B < right.B ) ? left.B : right.B; } /// @@ -702,10 +727,10 @@ namespace math /// The first source color. /// The second source color. /// A color containing the smallest components of the source colors. - public static ColorBGRA Min(ColorBGRA left, ColorBGRA right) + public static ColorBGRA Min( ColorBGRA left, ColorBGRA right ) { ColorBGRA result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -715,12 +740,12 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// When the method completes, contains the adjusted color. - public static void AdjustContrast(ref ColorBGRA value, float contrast, out ColorBGRA result) + public static void AdjustContrast( ref ColorBGRA value, float contrast, out ColorBGRA result ) { result.A = value.A; - result.R = ToByte(0.5f + contrast * (value.R / 255.0f - 0.5f)); - result.G = ToByte(0.5f + contrast * (value.G / 255.0f - 0.5f)); - result.B = ToByte(0.5f + contrast * (value.B / 255.0f - 0.5f)); + result.R = ToByte( 0.5f + contrast * ( value.R / 255.0f - 0.5f ) ); + result.G = ToByte( 0.5f + contrast * ( value.G / 255.0f - 0.5f ) ); + result.B = ToByte( 0.5f + contrast * ( value.B / 255.0f - 0.5f ) ); } /// @@ -729,13 +754,13 @@ namespace math /// The color whose contrast is to be adjusted. /// The amount by which to adjust the contrast. /// The adjusted color. - public static ColorBGRA AdjustContrast(ColorBGRA value, float contrast) + public static ColorBGRA AdjustContrast( ColorBGRA value, float contrast ) { return new ColorBGRA( - ToByte(0.5f + contrast * (value.R / 255.0f - 0.5f)), - ToByte(0.5f + contrast * (value.G / 255.0f - 0.5f)), - ToByte(0.5f + contrast * (value.B / 255.0f - 0.5f)), - value.A); + ToByte( 0.5f + contrast * ( value.R / 255.0f - 0.5f ) ), + ToByte( 0.5f + contrast * ( value.G / 255.0f - 0.5f ) ), + ToByte( 0.5f + contrast * ( value.B / 255.0f - 0.5f ) ), + value.A ); } /// @@ -744,14 +769,14 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// When the method completes, contains the adjusted color. - public static void AdjustSaturation(ref ColorBGRA value, float saturation, out ColorBGRA result) + public static void AdjustSaturation( ref ColorBGRA value, float saturation, out ColorBGRA result ) { float grey = value.R / 255.0f * 0.2125f + value.G / 255.0f * 0.7154f + value.B / 255.0f * 0.0721f; result.A = value.A; - result.R = ToByte(grey + saturation * (value.R / 255.0f - grey)); - result.G = ToByte(grey + saturation * (value.G / 255.0f - grey)); - result.B = ToByte(grey + saturation * (value.B / 255.0f - grey)); + result.R = ToByte( grey + saturation * ( value.R / 255.0f - grey ) ); + result.G = ToByte( grey + saturation * ( value.G / 255.0f - grey ) ); + result.B = ToByte( grey + saturation * ( value.B / 255.0f - grey ) ); } /// @@ -760,15 +785,15 @@ namespace math /// The color whose saturation is to be adjusted. /// The amount by which to adjust the saturation. /// The adjusted color. - public static ColorBGRA AdjustSaturation(ColorBGRA value, float saturation) + public static ColorBGRA AdjustSaturation( ColorBGRA value, float saturation ) { float grey = value.R / 255.0f * 0.2125f + value.G / 255.0f * 0.7154f + value.B / 255.0f * 0.0721f; return new ColorBGRA( - ToByte(grey + saturation * (value.R / 255.0f - grey)), - ToByte(grey + saturation * (value.G / 255.0f - grey)), - ToByte(grey + saturation * (value.B / 255.0f - grey)), - value.A); + ToByte( grey + saturation * ( value.R / 255.0f - grey ) ), + ToByte( grey + saturation * ( value.G / 255.0f - grey ) ), + ToByte( grey + saturation * ( value.B / 255.0f - grey ) ), + value.A ); } /// @@ -777,9 +802,9 @@ namespace math /// The first color to add. /// The second color to add. /// The sum of the two colors. - public static ColorBGRA operator +(ColorBGRA left, ColorBGRA right) + public static ColorBGRA operator +( ColorBGRA left, ColorBGRA right ) { - return new ColorBGRA((byte)(left.R + right.R), (byte)(left.G + right.G), (byte)(left.B + right.B), (byte)(left.A + right.A)); + return new ColorBGRA( (byte)( left.R + right.R ), (byte)( left.G + right.G ), (byte)( left.B + right.B ), (byte)( left.A + right.A ) ); } /// @@ -787,7 +812,7 @@ namespace math /// /// The color to assert (unchange). /// The asserted (unchanged) color. - public static ColorBGRA operator +(ColorBGRA value) + public static ColorBGRA operator +( ColorBGRA value ) { return value; } @@ -798,9 +823,9 @@ namespace math /// The first color to subtract. /// The second color to subtract. /// The difference of the two colors. - public static ColorBGRA operator -(ColorBGRA left, ColorBGRA right) + public static ColorBGRA operator -( ColorBGRA left, ColorBGRA right ) { - return new ColorBGRA((byte)(left.R - right.R), (byte)(left.G - right.G), (byte)(left.B - right.B), (byte)(left.A - right.A)); + return new ColorBGRA( (byte)( left.R - right.R ), (byte)( left.G - right.G ), (byte)( left.B - right.B ), (byte)( left.A - right.A ) ); } /// @@ -808,9 +833,9 @@ namespace math /// /// The color to negate. /// A negated color. - public static ColorBGRA operator -(ColorBGRA value) + public static ColorBGRA operator -( ColorBGRA value ) { - return new ColorBGRA(-value.R, -value.G, -value.B, -value.A); + return new ColorBGRA( -value.R, -value.G, -value.B, -value.A ); } /// @@ -819,9 +844,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static ColorBGRA operator *(float scale, ColorBGRA value) + public static ColorBGRA operator *( float scale, ColorBGRA value ) { - return new ColorBGRA((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale)); + return new ColorBGRA( (byte)( value.R * scale ), (byte)( value.G * scale ), (byte)( value.B * scale ), (byte)( value.A * scale ) ); } /// @@ -830,9 +855,9 @@ namespace math /// The factor by which to scale the color. /// The color to scale. /// The scaled color. - public static ColorBGRA operator *(ColorBGRA value, float scale) + public static ColorBGRA operator *( ColorBGRA value, float scale ) { - return new ColorBGRA((byte)(value.R * scale), (byte)(value.G * scale), (byte)(value.B * scale), (byte)(value.A * scale)); + return new ColorBGRA( (byte)( value.R * scale ), (byte)( value.G * scale ), (byte)( value.B * scale ), (byte)( value.A * scale ) ); } /// @@ -841,9 +866,9 @@ namespace math /// The first color to modulate. /// The second color to modulate. /// The modulated color. - public static ColorBGRA operator *(ColorBGRA left, ColorBGRA right) + public static ColorBGRA operator *( ColorBGRA left, ColorBGRA right ) { - return new ColorBGRA((byte)(left.R * right.R / 255.0f), (byte)(left.G * right.G / 255.0f), (byte)(left.B * right.B / 255.0f), (byte)(left.A * right.A / 255.0f)); + return new ColorBGRA( (byte)( left.R * right.R / 255.0f ), (byte)( left.G * right.G / 255.0f ), (byte)( left.B * right.B / 255.0f ), (byte)( left.A * right.A / 255.0f ) ); } /// @@ -852,9 +877,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(ColorBGRA left, ColorBGRA right) + public static bool operator ==( ColorBGRA left, ColorBGRA right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -863,9 +888,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(ColorBGRA left, ColorBGRA right) + public static bool operator !=( ColorBGRA left, ColorBGRA right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -873,9 +898,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color3(ColorBGRA value) + public static explicit operator Color3( ColorBGRA value ) { - return new Color3(value.R, value.G, value.B); + return new Color3( value.R, value.G, value.B ); } /// @@ -883,9 +908,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(ColorBGRA value) + public static explicit operator Vec3( ColorBGRA value ) { - return new Vec3(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f); + return new Vec3( value.R / 255.0f, value.G / 255.0f, value.B / 255.0f ); } /// @@ -893,9 +918,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(ColorBGRA value) + public static explicit operator Vec4( ColorBGRA value ) { - return new Vec4(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); + return new Vec4( value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f ); } /// @@ -903,9 +928,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Color4(ColorBGRA value) + public static explicit operator Color4( ColorBGRA value ) { - return new Color4(value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f); + return new Color4( value.R / 255.0f, value.G / 255.0f, value.B / 255.0f, value.A / 255.0f ); } /// @@ -913,9 +938,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator ColorBGRA(Vec3 value) + public static explicit operator ColorBGRA( Vec3 value ) { - return new ColorBGRA(value.X / 255.0f, value.Y / 255.0f, value.Z / 255.0f, 1.0f); + return new ColorBGRA( value.X / 255.0f, value.Y / 255.0f, value.Z / 255.0f, 1.0f ); } /// @@ -923,9 +948,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator ColorBGRA(Color3 value) + public static explicit operator ColorBGRA( Color3 value ) { - return new ColorBGRA(value.R, value.G, value.B, 1.0f); + return new ColorBGRA( value.R, value.G, value.B, 1.0f ); } /// @@ -933,9 +958,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator ColorBGRA(Vec4 value) + public static explicit operator ColorBGRA( Vec4 value ) { - return new ColorBGRA(value.X, value.Y, value.Z, value.W); + return new ColorBGRA( value.X, value.Y, value.Z, value.W ); } /// @@ -943,9 +968,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator ColorBGRA(Color4 value) + public static explicit operator ColorBGRA( Color4 value ) { - return new ColorBGRA(value.R, value.G, value.B, value.A); + return new ColorBGRA( value.R, value.G, value.B, value.A ); } /// @@ -953,9 +978,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator ColorBGRA(Color value) + public static implicit operator ColorBGRA( Color value ) { - return new ColorBGRA(value.R, value.G, value.B, value.A); + return new ColorBGRA( value.R, value.G, value.B, value.A ); } /// @@ -963,9 +988,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Color(ColorBGRA value) + public static implicit operator Color( ColorBGRA value ) { - return new Color(value.R, value.G, value.B, value.A); + return new Color( value.R, value.G, value.B, value.A ); } /// @@ -975,7 +1000,7 @@ namespace math /// /// The result of the conversion. /// - public static explicit operator int(ColorBGRA value) + public static explicit operator int( ColorBGRA value ) { return value.ToBgra(); } @@ -987,9 +1012,9 @@ namespace math /// /// The result of the conversion. /// - public static explicit operator ColorBGRA(int value) + public static explicit operator ColorBGRA( int value ) { - return new ColorBGRA(value); + return new ColorBGRA( value ); } /// @@ -1000,7 +1025,7 @@ namespace math /// public override string ToString() { - return ToString(CultureInfo.CurrentCulture); + return ToString( CultureInfo.CurrentCulture ); } /// @@ -1010,9 +1035,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - return ToString(format, CultureInfo.CurrentCulture); + return ToString( format, CultureInfo.CurrentCulture ); } /// @@ -1022,9 +1047,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, ToStringFormat, A, R, G, B); + return string.Format( formatProvider, ToStringFormat, A, R, G, B ); } /// @@ -1035,23 +1060,23 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, ToStringFormat, - A.ToString(format, formatProvider), - R.ToString(format, formatProvider), - G.ToString(format, formatProvider), - B.ToString(format, formatProvider)); + return string.Format( formatProvider, ToStringFormat, + A.ToString( format, formatProvider ), + R.ToString( format, formatProvider ), + G.ToString( format, formatProvider ), + B.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1065,7 +1090,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(ColorBGRA other) + public bool Equals( ColorBGRA other ) { return R == other.R && G == other.G && B == other.B && A == other.A; } @@ -1077,21 +1102,21 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (!ReferenceEquals(value.GetType(), typeof(ColorBGRA))) + if( !ReferenceEquals( value.GetType(), typeof( ColorBGRA ) ) ) return false; - return Equals((ColorBGRA)value); + return Equals( (ColorBGRA)value ); } - private static byte ToByte(float component) + private static byte ToByte( float component ) { - var value = (int)(component * 255.0f); - return (byte)(value < 0 ? 0 : value > 255 ? 255 : value); + var value = (int)( component * 255.0f ); + return (byte)( value < 0 ? 0 : value > 255 ? 255 : value ); } } } diff --git a/math/ColorExtensions.cs b/math/ColorExtensions.cs index 0e891d9..d45556a 100644 --- a/math/ColorExtensions.cs +++ b/math/ColorExtensions.cs @@ -16,9 +16,9 @@ namespace math /// /// The string to convert. /// True if the string can be converted, false otherwise. - public static bool CanConvertStringToRgba([CanBeNull] string stringColor) + public static bool CanConvertStringToRgba( [CanBeNull] string stringColor ) { - return stringColor?.StartsWith("#") ?? false; + return stringColor?.StartsWith( "#" ) ?? false; } /// @@ -26,36 +26,36 @@ namespace math /// /// The string to convert. /// The converted RGBA value. - public static uint StringToRgba([CanBeNull] string stringColor) + public static uint StringToRgba( [CanBeNull] string stringColor ) { var intValue = 0xFF000000; - if (stringColor != null) + if( stringColor != null ) { - if (stringColor.StartsWith("#")) + if( stringColor.StartsWith( "#" ) ) { - if (stringColor.Length == "#000".Length && uint.TryParse(stringColor.Substring(1, 3), NumberStyles.HexNumber, null, out intValue)) + if( stringColor.Length == "#000".Length && uint.TryParse( stringColor.Substring( 1, 3 ), NumberStyles.HexNumber, null, out intValue ) ) { - intValue = ((intValue & 0x00F) << 16) - | ((intValue & 0x00F) << 20) - | ((intValue & 0x0F0) << 4) - | ((intValue & 0x0F0) << 8) - | ((intValue & 0xF00) >> 4) - | ((intValue & 0xF00) >> 8) - | (0xFF000000); + intValue = ( ( intValue & 0x00F ) << 16 ) + | ( ( intValue & 0x00F ) << 20 ) + | ( ( intValue & 0x0F0 ) << 4 ) + | ( ( intValue & 0x0F0 ) << 8 ) + | ( ( intValue & 0xF00 ) >> 4 ) + | ( ( intValue & 0xF00 ) >> 8 ) + | ( 0xFF000000 ); } - if (stringColor.Length == "#000000".Length && uint.TryParse(stringColor.Substring(1, 6), NumberStyles.HexNumber, null, out intValue)) + if( stringColor.Length == "#000000".Length && uint.TryParse( stringColor.Substring( 1, 6 ), NumberStyles.HexNumber, null, out intValue ) ) { - intValue = ((intValue & 0x000000FF) << 16) - | (intValue & 0x0000FF00) - | ((intValue & 0x00FF0000) >> 16) - | (0xFF000000); + intValue = ( ( intValue & 0x000000FF ) << 16 ) + | ( intValue & 0x0000FF00 ) + | ( ( intValue & 0x00FF0000 ) >> 16 ) + | ( 0xFF000000 ); } - if (stringColor.Length == "#00000000".Length && uint.TryParse(stringColor.Substring(1, 8), NumberStyles.HexNumber, null, out intValue)) + if( stringColor.Length == "#00000000".Length && uint.TryParse( stringColor.Substring( 1, 8 ), NumberStyles.HexNumber, null, out intValue ) ) { - intValue = ((intValue & 0x000000FF) << 16) - | (intValue & 0x0000FF00) - | ((intValue & 0x00FF0000) >> 16) - | (intValue & 0xFF000000); + intValue = ( ( intValue & 0x000000FF ) << 16 ) + | ( intValue & 0x0000FF00 ) + | ( ( intValue & 0x00FF0000 ) >> 16 ) + | ( intValue & 0xFF000000 ); } } } @@ -68,11 +68,11 @@ namespace math /// The RGB value to convert. /// The converted string. [NotNull] - public static string RgbToString(int value) + public static string RgbToString( int value ) { - var r = (value & 0x000000FF); - var g = (value & 0x0000FF00) >> 8; - var b = (value & 0x00FF0000) >> 16; + var r = ( value & 0x000000FF ); + var g = ( value & 0x0000FF00 ) >> 8; + var b = ( value & 0x00FF0000 ) >> 16; return $"#{r:X2}{g:X2}{b:X2}"; } @@ -82,12 +82,12 @@ namespace math /// The RGBA value to convert. /// The converted string. [NotNull] - public static string RgbaToString(int value) + public static string RgbaToString( int value ) { - var r = (value & 0x000000FF); - var g = (value & 0x0000FF00) >> 8; - var b = (value & 0x00FF0000) >> 16; - var a = (value & 0xFF000000) >> 24; + var r = ( value & 0x000000FF ); + var g = ( value & 0x0000FF00 ) >> 8; + var b = ( value & 0x00FF0000 ) >> 16; + var a = ( value & 0xFF000000 ) >> 24; return $"#{a:X2}{r:X2}{g:X2}{b:X2}"; } } diff --git a/math/ColorHSV.cs b/math/ColorHSV.cs index b328943..9c3abe1 100644 --- a/math/ColorHSV.cs +++ b/math/ColorHSV.cs @@ -10,8 +10,8 @@ namespace math /// /// Represents a color in the form of Hue, Saturation, Value, Alpha. /// - [DataContract( Name = "ColorHSV")] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "ColorHSV" )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct ColorHSV : IEquatable, IFormattable { private const string ToStringFormat = "Hue:{0} Saturation:{1} Value:{2} Alpha:{3}"; @@ -47,7 +47,7 @@ namespace math /// The s. /// The v. /// A. - public ColorHSV(float h, float s, float v, float a) + public ColorHSV( float h, float s, float v, float a ) { H = h; S = s; @@ -64,25 +64,25 @@ namespace math float hdiv = H / 60; int hi = (int)hdiv; float f = hdiv - hi; - - float p = V * (1 - S); - float q = V * (1 - (S * f)); - float t = V * (1 - (S * (1 - f))); - switch (hi) + float p = V * ( 1 - S ); + float q = V * ( 1 - ( S * f ) ); + float t = V * ( 1 - ( S * ( 1 - f ) ) ); + + switch( hi ) { case 0: - return new Color4(V, t, p, A); + return new Color4( V, t, p, A ); case 1: - return new Color4(q, V, p, A); + return new Color4( q, V, p, A ); case 2: - return new Color4(p, V, t, A); + return new Color4( p, V, t, A ); case 3: - return new Color4(p, q, V, A); + return new Color4( p, q, V, A ); case 4: - return new Color4(t, p, V, A); + return new Color4( t, p, V, A ); default: - return new Color4(V, p, q, A); + return new Color4( V, p, q, A ); } } @@ -91,45 +91,47 @@ namespace math /// /// The color. /// A HSV color - public static ColorHSV FromColor(Color4 color) + public static ColorHSV FromColor( Color4 color ) { - float max = Math.Max(color.R, Math.Max(color.G, color.B)); - float min = Math.Min(color.R, Math.Min(color.G, color.B)); + float max = Math.Max( color.R, Math.Max( color.G, color.B ) ); + float min = Math.Min( color.R, Math.Min( color.G, color.B ) ); float delta = max - min; float h = 0.0f; - if (delta > 0.0f) + if( delta > 0.0f ) { - if (color.R >= max) - h = (color.G - color.B) / delta; - else if (color.G >= max) - h = (color.B - color.R) / delta + 2.0f; + if( color.R >= max ) + h = ( color.G - color.B ) / delta; + else if( color.G >= max ) + h = ( color.B - color.R ) / delta + 2.0f; else - h = (color.R - color.G) / delta + 4.0f; + h = ( color.R - color.G ) / delta + 4.0f; h *= 60.0f; - if (h < 0) + if( h < 0 ) h += 360f; } - float s = MathUtil.IsZero(max) ? 0.0f : delta / max; + float s = MathUtil.IsZero( max ) ? 0.0f : delta / max; - return new ColorHSV(h, s, max, color.A); + return new ColorHSV( h, s, max, color.A ); } /// - public bool Equals(ColorHSV other) + public bool Equals( ColorHSV other ) { - return other.H.Equals(H) && other.S.Equals(S) && other.V.Equals(V) && other.A.Equals(A); + return other.H.Equals( H ) && other.S.Equals( S ) && other.V.Equals( V ) && other.A.Equals( A ); } /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != typeof(ColorHSV)) return false; - return Equals((ColorHSV)obj); + if( ReferenceEquals( null, obj ) ) + return false; + if( obj.GetType() != typeof( ColorHSV ) ) + return false; + return Equals( (ColorHSV)obj ); } /// @@ -138,9 +140,9 @@ namespace math unchecked { int result = H.GetHashCode(); - result = (result * 397) ^ S.GetHashCode(); - result = (result * 397) ^ V.GetHashCode(); - result = (result * 397) ^ A.GetHashCode(); + result = ( result * 397 ) ^ S.GetHashCode(); + result = ( result * 397 ) ^ V.GetHashCode(); + result = ( result * 397 ) ^ A.GetHashCode(); return result; } } @@ -153,7 +155,7 @@ namespace math /// public override string ToString() { - return ToString(CultureInfo.CurrentCulture); + return ToString( CultureInfo.CurrentCulture ); } /// @@ -163,9 +165,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - return ToString(format, CultureInfo.CurrentCulture); + return ToString( format, CultureInfo.CurrentCulture ); } /// @@ -175,9 +177,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, ToStringFormat, H, S, V, A); + return string.Format( formatProvider, ToStringFormat, H, S, V, A ); } /// @@ -188,16 +190,16 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, ToStringFormat, - H.ToString(format, formatProvider), - S.ToString(format, formatProvider), - V.ToString(format, formatProvider), - A.ToString(format, formatProvider)); + return string.Format( formatProvider, ToStringFormat, + H.ToString( format, formatProvider ), + S.ToString( format, formatProvider ), + V.ToString( format, formatProvider ), + A.ToString( format, formatProvider ) ); } } } diff --git a/math/ContainmentType.cs b/math/ContainmentType.cs index bcd3288..a334f96 100644 --- a/math/ContainmentType.cs +++ b/math/ContainmentType.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 diff --git a/math/DataMemberIgnoreAttribute.cs b/math/DataMemberIgnoreAttribute.cs index 6ef7956..5e35127 100644 --- a/math/DataMemberIgnoreAttribute.cs +++ b/math/DataMemberIgnoreAttribute.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -33,4 +33,4 @@ namespace math internal class DataMemberIgnoreAttribute : Attribute { } -} \ No newline at end of file +} diff --git a/math/DataStyleAttribute.cs b/math/DataStyleAttribute.cs index d586604..d2758ee 100644 --- a/math/DataStyleAttribute.cs +++ b/math/DataStyleAttribute.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -50,4 +50,4 @@ namespace math } } -} \ No newline at end of file +} diff --git a/math/Double2.cs b/math/Double2.cs index f437776..6c36b27 100644 --- a/math/Double2.cs +++ b/math/Double2.cs @@ -13,9 +13,9 @@ namespace math /// /// Represents a two dimensional mathematical vector with double-precision floats. /// - [DataContract( Name = "double2")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "double2" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Double2 : IEquatable, IFormattable { /// @@ -31,17 +31,17 @@ namespace math /// /// The X unit (1, 0). /// - public static readonly Double2 UnitX = new Double2(1.0, 0.0); + public static readonly Double2 UnitX = new Double2( 1.0, 0.0 ); /// /// The Y unit (0, 1). /// - public static readonly Double2 UnitY = new Double2(0.0, 1.0); + public static readonly Double2 UnitY = new Double2( 0.0, 1.0 ); /// /// A with all of its components set to one. /// - public static readonly Double2 One = new Double2(1.0, 1.0); + public static readonly Double2 One = new Double2( 1.0, 1.0 ); /// /// The X component of the vector. @@ -59,7 +59,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Double2(double value) + public Double2( double value ) { X = value; Y = value; @@ -70,7 +70,7 @@ namespace math /// /// Initial value for the X component of the vector. /// Initial value for the Y component of the vector. - public Double2(double x, double y) + public Double2( double x, double y ) { X = x; Y = y; @@ -82,12 +82,12 @@ namespace math /// The values to assign to the X and Y components of the vector. This must be an array with two elements. /// Thrown when is null. /// Thrown when contains more or less than two elements. - public Double2(double[] values) + public Double2( double[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 2) - throw new ArgumentOutOfRangeException("values", "There must be two and only two input values for Double2."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 2 ) + throw new ArgumentOutOfRangeException( "values", "There must be two and only two input values for Double2." ); X = values[0]; Y = values[1]; @@ -97,7 +97,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The Vector2 to construct the Double2 from. - public Double2(Vec2 v) + public Double2( Vec2 v ) { X = v.X; Y = v.Y; @@ -108,7 +108,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -122,22 +122,29 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; + case 0: + return X; + case 1: + return Y; } - throw new ArgumentOutOfRangeException("index", "Indices for Double2 run from 0 to 1, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Double2 run from 0 to 1, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Double2 run from 0 to 1, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Double2 run from 0 to 1, inclusive." ); } } } @@ -150,10 +157,10 @@ namespace math /// may be preferred when only the relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public double Length() { - return (double)Math.Sqrt((X * X) + (Y * Y)); + return (double)Math.Sqrt( ( X * X ) + ( Y * Y ) ); } /// @@ -164,20 +171,20 @@ namespace math /// This method may be preferred to when only a relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public double LengthSquared() { - return (X * X) + (Y * Y); + return ( X * X ) + ( Y * Y ); } /// /// Converts the vector into a unit vector. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public void Normalize() { double length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { double inv = 1.0 / length; X *= inv; @@ -200,10 +207,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Add(ref Double2 left, ref Double2 right, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Add( ref Double2 left, ref Double2 right, out Double2 result ) { - result = new Double2(left.X + right.X, left.Y + right.Y); + result = new Double2( left.X + right.X, left.Y + right.Y ); } /// @@ -212,10 +219,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Add(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Add( Double2 left, Double2 right ) { - return new Double2(left.X + right.X, left.Y + right.Y); + return new Double2( left.X + right.X, left.Y + right.Y ); } /// @@ -224,10 +231,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Subtract(ref Double2 left, ref Double2 right, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Subtract( ref Double2 left, ref Double2 right, out Double2 result ) { - result = new Double2(left.X - right.X, left.Y - right.Y); + result = new Double2( left.X - right.X, left.Y - right.Y ); } /// @@ -236,10 +243,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Subtract(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Subtract( Double2 left, Double2 right ) { - return new Double2(left.X - right.X, left.Y - right.Y); + return new Double2( left.X - right.X, left.Y - right.Y ); } /// @@ -248,10 +255,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Multiply(ref Double2 value, double scale, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Multiply( ref Double2 value, double scale, out Double2 result ) { - result = new Double2(value.X * scale, value.Y * scale); + result = new Double2( value.X * scale, value.Y * scale ); } /// @@ -260,22 +267,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Multiply(Double2 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Multiply( Double2 value, double scale ) { - return new Double2(value.X * scale, value.Y * scale); + return new Double2( value.X * scale, value.Y * scale ); } - + /// /// Modulates a vector with another by performing component-wise multiplication. /// /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Modulate(ref Double2 left, ref Double2 right, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Modulate( ref Double2 left, ref Double2 right, out Double2 result ) { - result = new Double2(left.X * right.X, left.Y * right.Y); + result = new Double2( left.X * right.X, left.Y * right.Y ); } /// @@ -284,10 +291,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Modulate(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Modulate( Double2 left, Double2 right ) { - return new Double2(left.X * right.X, left.Y * right.Y); + return new Double2( left.X * right.X, left.Y * right.Y ); } /// @@ -296,10 +303,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Divide(ref Double2 value, double scale, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Divide( ref Double2 value, double scale, out Double2 result ) { - result = new Double2(value.X / scale, value.Y / scale); + result = new Double2( value.X / scale, value.Y / scale ); } /// @@ -308,22 +315,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Divide(Double2 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Divide( Double2 value, double scale ) { - return new Double2(value.X / scale, value.Y / scale); + return new Double2( value.X / scale, value.Y / scale ); } - + /// /// Demodulates a vector with another by performing component-wise division. /// /// The first vector to demodulate. /// The second vector to demodulate. /// When the method completes, contains the demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Demodulate(ref Double2 left, ref Double2 right, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Demodulate( ref Double2 left, ref Double2 right, out Double2 result ) { - result = new Double2(left.X / right.X, left.Y / right.Y); + result = new Double2( left.X / right.X, left.Y / right.Y ); } /// @@ -332,10 +339,10 @@ namespace math /// The first vector to demodulate. /// The second vector to demodulate. /// The demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Demodulate(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Demodulate( Double2 left, Double2 right ) { - return new Double2(left.X / right.X, left.Y / right.Y); + return new Double2( left.X / right.X, left.Y / right.Y ); } /// @@ -343,10 +350,10 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Negate(ref Double2 value, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Negate( ref Double2 value, out Double2 result ) { - result = new Double2(-value.X, -value.Y); + result = new Double2( -value.X, -value.Y ); } /// @@ -354,10 +361,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Negate(Double2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Negate( Double2 value ) { - return new Double2(-value.X, -value.Y); + return new Double2( -value.X, -value.Y ); } /// @@ -369,10 +376,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 2D Cartesian coordinates of the specified point. - public static void Barycentric(ref Double2 value1, ref Double2 value2, ref Double2 value3, double amount1, double amount2, out Double2 result) + public static void Barycentric( ref Double2 value1, ref Double2 value2, ref Double2 value3, double amount1, double amount2, out Double2 result ) { - result = new Double2((value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)), - (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y))); + result = new Double2( ( value1.X + ( amount1 * ( value2.X - value1.X ) ) ) + ( amount2 * ( value3.X - value1.X ) ), + ( value1.Y + ( amount1 * ( value2.Y - value1.Y ) ) ) + ( amount2 * ( value3.Y - value1.Y ) ) ); } /// @@ -384,10 +391,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 2D Cartesian coordinates of the specified point. - public static Double2 Barycentric(Double2 value1, Double2 value2, Double2 value3, double amount1, double amount2) + public static Double2 Barycentric( Double2 value1, Double2 value2, Double2 value3, double amount1, double amount2 ) { Double2 result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -398,17 +405,17 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Double2 value, ref Double2 min, ref Double2 max, out Double2 result) + public static void Clamp( ref Double2 value, ref Double2 min, ref Double2 max, out Double2 result ) { double x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; double y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; - result = new Double2(x, y); + result = new Double2( x, y ); } /// @@ -418,10 +425,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Double2 Clamp(Double2 value, Double2 min, Double2 max) + public static Double2 Clamp( Double2 value, Double2 min, Double2 max ) { Double2 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -435,12 +442,12 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static void Distance(ref Double2 value1, ref Double2 value2, out double result) + public static void Distance( ref Double2 value1, ref Double2 value2, out double result ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; - result = (double)Math.Sqrt((x * x) + (y * y)); + result = (double)Math.Sqrt( ( x * x ) + ( y * y ) ); } /// @@ -453,12 +460,12 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static double Distance(Double2 value1, Double2 value2) + public static double Distance( Double2 value1, Double2 value2 ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; - return (double)Math.Sqrt((x * x) + (y * y)); + return (double)Math.Sqrt( ( x * x ) + ( y * y ) ); } /// @@ -467,19 +474,19 @@ namespace math /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Double2 value1, ref Double2 value2, out double result) + public static void DistanceSquared( ref Double2 value1, ref Double2 value2, out double result ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; - result = (x * x) + (y * y); + result = ( x * x ) + ( y * y ); } /// @@ -488,19 +495,19 @@ namespace math /// The first vector. /// The second vector. /// The squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static double DistanceSquared(Double2 value1, Double2 value2) + public static double DistanceSquared( Double2 value1, Double2 value2 ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; - return (x * x) + (y * y); + return ( x * x ) + ( y * y ); } /// @@ -509,10 +516,10 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Double2 left, ref Double2 right, out double result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Dot( ref Double2 left, ref Double2 right, out double result ) { - result = (left.X * right.X) + (left.Y * right.Y); + result = ( left.X * right.X ) + ( left.Y * right.Y ); } /// @@ -521,10 +528,10 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Dot(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static double Dot( Double2 left, Double2 right ) { - return (left.X * right.X) + (left.Y * right.Y); + return ( left.X * right.X ) + ( left.Y * right.Y ); } /// @@ -532,8 +539,8 @@ namespace math /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(ref Double2 value, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Normalize( ref Double2 value, out Double2 result ) { result = value; result.Normalize(); @@ -544,8 +551,8 @@ namespace math /// /// The vector to normalize. /// The normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Normalize(Double2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Normalize( Double2 value ) { value.Normalize(); return value; @@ -561,12 +568,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Double2 start, ref Double2 end, double amount, out Double2 result) + public static void Lerp( ref Double2 start, ref Double2 end, double amount, out Double2 result ) { - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); } /// @@ -579,12 +586,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Double2 Lerp(Double2 start, Double2 end, double amount) + public static Double2 Lerp( Double2 start, Double2 end, double amount ) { Double2 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -595,13 +602,13 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Double2 start, ref Double2 end, double amount, out Double2 result) + public static void SmoothStep( ref Double2 start, ref Double2 end, double amount, out Double2 result ) { - amount = (amount > 1.0) ? 1.0 : ((amount < 0.0) ? 0.0 : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0 ) ? 1.0 : ( ( amount < 0.0 ) ? 0.0 : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); } /// @@ -611,10 +618,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Double2 SmoothStep(Double2 start, Double2 end, double amount) + public static Double2 SmoothStep( Double2 start, Double2 end, double amount ) { Double2 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -627,17 +634,17 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Double2 value1, ref Double2 tangent1, ref Double2 value2, ref Double2 tangent2, double amount, out Double2 result) + public static void Hermite( ref Double2 value1, ref Double2 tangent1, ref Double2 value2, ref Double2 tangent2, double amount, out Double2 result ) { double squared = amount * amount; double cubed = amount * squared; - double part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0; - double part2 = (-2.0f * cubed) + (3.0f * squared); - double part3 = (cubed - (2.0f * squared)) + amount; + double part1 = ( ( 2.0f * cubed ) - ( 3.0f * squared ) ) + 1.0; + double part2 = ( -2.0f * cubed ) + ( 3.0f * squared ); + double part3 = ( cubed - ( 2.0f * squared ) ) + amount; double part4 = cubed - squared; - result.X = (((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4); - result.Y = (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4); + result.X = ( ( ( value1.X * part1 ) + ( value2.X * part2 ) ) + ( tangent1.X * part3 ) ) + ( tangent2.X * part4 ); + result.Y = ( ( ( value1.Y * part1 ) + ( value2.Y * part2 ) ) + ( tangent1.Y * part3 ) ) + ( tangent2.Y * part4 ); } /// @@ -649,10 +656,10 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// The result of the Hermite spline interpolation. - public static Double2 Hermite(Double2 value1, Double2 tangent1, Double2 value2, Double2 tangent2, double amount) + public static Double2 Hermite( Double2 value1, Double2 tangent1, Double2 value2, Double2 tangent2, double amount ) { Double2 result; - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + Hermite( ref value1, ref tangent1, ref value2, ref tangent2, amount, out result ); return result; } @@ -665,18 +672,18 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Double2 value1, ref Double2 value2, ref Double2 value3, ref Double2 value4, double amount, out Double2 result) + public static void CatmullRom( ref Double2 value1, ref Double2 value2, ref Double2 value3, ref Double2 value4, double amount, out Double2 result ) { double squared = amount * amount; double cubed = amount * squared; - result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) + - (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) + - ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed)); + result.X = 0.5f * ( ( ( ( 2.0f * value2.X ) + ( ( -value1.X + value3.X ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.X ) - ( 5.0f * value2.X ) ) + ( 4.0f * value3.X ) ) - value4.X ) * squared ) ) + + ( ( ( ( -value1.X + ( 3.0f * value2.X ) ) - ( 3.0f * value3.X ) ) + value4.X ) * cubed ) ); - result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) + - (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) + - ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed)); + result.Y = 0.5f * ( ( ( ( 2.0f * value2.Y ) + ( ( -value1.Y + value3.Y ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.Y ) - ( 5.0f * value2.Y ) ) + ( 4.0f * value3.Y ) ) - value4.Y ) * squared ) ) + + ( ( ( ( -value1.Y + ( 3.0f * value2.Y ) ) - ( 3.0f * value3.Y ) ) + value4.Y ) * cubed ) ); } /// @@ -688,10 +695,10 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// A vector that is the result of the Catmull-Rom interpolation. - public static Double2 CatmullRom(Double2 value1, Double2 value2, Double2 value3, Double2 value4, double amount) + public static Double2 CatmullRom( Double2 value1, Double2 value2, Double2 value3, Double2 value4, double amount ) { Double2 result; - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result); + CatmullRom( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -701,11 +708,11 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Max(ref Double2 left, ref Double2 right, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Max( ref Double2 left, ref Double2 right, out Double2 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; } /// @@ -714,11 +721,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Max(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Max( Double2 left, Double2 right ) { Double2 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -728,11 +735,11 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Min(ref Double2 left, ref Double2 right, out Double2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Min( ref Double2 left, ref Double2 right, out Double2 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; } /// @@ -741,42 +748,42 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 Min(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 Min( Double2 left, Double2 right ) { Double2 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// When the method completes, contains the reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Double2 vector, ref Double2 normal, out Double2 result) + public static void Reflect( ref Double2 vector, ref Double2 normal, out Double2 result ) { - double dot = (vector.X * normal.X) + (vector.Y * normal.Y); + double dot = ( vector.X * normal.X ) + ( vector.Y * normal.Y ); - result.X = vector.X - ((2.0f * dot) * normal.X); - result.Y = vector.Y - ((2.0f * dot) * normal.Y); + result.X = vector.X - ( ( 2.0f * dot ) * normal.X ); + result.Y = vector.Y - ( ( 2.0f * dot ) * normal.Y ); } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// The reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static Double2 Reflect(Double2 vector, Double2 normal) + public static Double2 Reflect( Double2 vector, Double2 normal ) { Double2 result; - Reflect(ref vector, ref normal, out result); + Reflect( ref vector, ref normal, out result ); return result; } @@ -796,7 +803,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthogonalize(Double2[] destination, params Double2[] source) + public static void Orthogonalize( Double2[] destination, params Double2[] source ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -805,20 +812,20 @@ namespace math //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3 //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Double2 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= (Double2.Dot(destination[r], newvector) / Double2.Dot(destination[r], destination[r])) * destination[r]; + newvector -= ( Double2.Dot( destination[r], newvector ) / Double2.Dot( destination[r], destination[r] ) ) * destination[r]; } destination[i] = newvector; @@ -841,7 +848,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthonormalize(Double2[] destination, params Double2[] source) + public static void Orthonormalize( Double2[] destination, params Double2[] source ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -852,20 +859,20 @@ namespace math //q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3| //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Double2 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= Double2.Dot(destination[r], newvector) * destination[r]; + newvector -= Double2.Dot( destination[r], newvector ) * destination[r]; } newvector.Normalize(); @@ -879,7 +886,7 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Double2 vector, ref Quaternion rotation, out Double2 result) + public static void Transform( ref Double2 vector, ref Quaternion rotation, out Double2 result ) { double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -890,7 +897,7 @@ namespace math double yy = rotation.Y * y; double zz = rotation.Z * z; - result = new Double2((vector.X * (1.0 - yy - zz)) + (vector.Y * (xy - wz)), (vector.X * (xy + wz)) + (vector.Y * (1.0 - xx - zz))); + result = new Double2( ( vector.X * ( 1.0 - yy - zz ) ) + ( vector.Y * ( xy - wz ) ), ( vector.X * ( xy + wz ) ) + ( vector.Y * ( 1.0 - xx - zz ) ) ); } /// @@ -899,10 +906,10 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// The transformed . - public static Double2 Transform(Double2 vector, Quaternion rotation) + public static Double2 Transform( Double2 vector, Quaternion rotation ) { Double2 result; - Transform(ref vector, ref rotation, out result); + Transform( ref vector, ref rotation, out result ); return result; } @@ -915,14 +922,14 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Double2[] source, ref Quaternion rotation, Double2[] destination) + public static void Transform( Double2[] source, ref Quaternion rotation, Double2[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -933,16 +940,16 @@ namespace math double yy = rotation.Y * y; double zz = rotation.Z * z; - double num1 = (1.0 - yy - zz); - double num2 = (xy - wz); - double num3 = (xy + wz); - double num4 = (1.0 - xx - zz); + double num1 = ( 1.0 - yy - zz ); + double num2 = ( xy - wz ); + double num3 = ( xy + wz ); + double num4 = ( 1.0 - xx - zz ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { destination[i] = new Double2( - (source[i].X * num1) + (source[i].Y * num2), - (source[i].X * num3) + (source[i].Y * num4)); + ( source[i].X * num1 ) + ( source[i].Y * num2 ), + ( source[i].X * num3 ) + ( source[i].Y * num4 ) ); } } @@ -952,13 +959,13 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double2 vector, ref Matrix transform, out Double4 result) + public static void Transform( ref Double2 vector, ref Matrix transform, out Double4 result ) { result = new Double4( - (vector.X * transform.M11) + (vector.Y * transform.M21) + transform.M41, - (vector.X * transform.M12) + (vector.Y * transform.M22) + transform.M42, - (vector.X * transform.M13) + (vector.Y * transform.M23) + transform.M43, - (vector.X * transform.M14) + (vector.Y * transform.M24) + transform.M44); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + transform.M41, + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + transform.M42, + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + transform.M43, + ( vector.X * transform.M14 ) + ( vector.Y * transform.M24 ) + transform.M44 ); } /// @@ -967,10 +974,10 @@ namespace math /// The source vector. /// The transformation . /// The transformed . - public static Double4 Transform(Double2 vector, Matrix transform) + public static Double4 Transform( Double2 vector, Matrix transform ) { Double4 result; - Transform(ref vector, ref transform, out result); + Transform( ref vector, ref transform, out result ); return result; } @@ -982,18 +989,18 @@ namespace math /// The array for which the transformed vectors are stored. /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Double2[] source, ref Matrix transform, Double4[] destination) + public static void Transform( Double2[] source, ref Matrix transform, Double4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - Transform(ref source[i], ref transform, out destination[i]); + Transform( ref source[i], ref transform, out destination[i] ); } } @@ -1010,15 +1017,15 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Double2 coordinate, ref Matrix transform, out Double2 result) + public static void TransformCoordinate( ref Double2 coordinate, ref Matrix transform, out Double2 result ) { Double4 vector = new Double4(); - vector.X = (coordinate.X * transform.M11) + (coordinate.Y * transform.M21) + transform.M41; - vector.Y = (coordinate.X * transform.M12) + (coordinate.Y * transform.M22) + transform.M42; - vector.Z = (coordinate.X * transform.M13) + (coordinate.Y * transform.M23) + transform.M43; - vector.W = 1f / ((coordinate.X * transform.M14) + (coordinate.Y * transform.M24) + transform.M44); + vector.X = ( coordinate.X * transform.M11 ) + ( coordinate.Y * transform.M21 ) + transform.M41; + vector.Y = ( coordinate.X * transform.M12 ) + ( coordinate.Y * transform.M22 ) + transform.M42; + vector.Z = ( coordinate.X * transform.M13 ) + ( coordinate.Y * transform.M23 ) + transform.M43; + vector.W = 1f / ( ( coordinate.X * transform.M14 ) + ( coordinate.Y * transform.M24 ) + transform.M44 ); - result = new Double2(vector.X * vector.W, vector.Y * vector.W); + result = new Double2( vector.X * vector.W, vector.Y * vector.W ); } /// @@ -1034,10 +1041,10 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static Double2 TransformCoordinate(Double2 coordinate, Matrix transform) + public static Double2 TransformCoordinate( Double2 coordinate, Matrix transform ) { Double2 result; - TransformCoordinate(ref coordinate, ref transform, out result); + TransformCoordinate( ref coordinate, ref transform, out result ); return result; } @@ -1057,18 +1064,18 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(Double2[] source, ref Matrix transform, Double2[] destination) + public static void TransformCoordinate( Double2[] source, ref Matrix transform, Double2[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformCoordinate(ref source[i], ref transform, out destination[i]); + TransformCoordinate( ref source[i], ref transform, out destination[i] ); } } @@ -1085,11 +1092,11 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Double2 normal, ref Matrix transform, out Double2 result) + public static void TransformNormal( ref Double2 normal, ref Matrix transform, out Double2 result ) { result = new Double2( - (normal.X * transform.M11) + (normal.Y * transform.M21), - (normal.X * transform.M12) + (normal.Y * transform.M22)); + ( normal.X * transform.M11 ) + ( normal.Y * transform.M21 ), + ( normal.X * transform.M12 ) + ( normal.Y * transform.M22 ) ); } /// @@ -1105,10 +1112,10 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static Double2 TransformNormal(Double2 normal, Matrix transform) + public static Double2 TransformNormal( Double2 normal, Matrix transform ) { Double2 result; - TransformNormal(ref normal, ref transform, out result); + TransformNormal( ref normal, ref transform, out result ); return result; } @@ -1128,18 +1135,18 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(Double2[] source, ref Matrix transform, Double2[] destination) + public static void TransformNormal( Double2[] source, ref Matrix transform, Double2[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformNormal(ref source[i], ref transform, out destination[i]); + TransformNormal( ref source[i], ref transform, out destination[i] ); } } @@ -1149,10 +1156,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator +(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator +( Double2 left, Double2 right ) { - return new Double2(left.X + right.X, left.Y + right.Y); + return new Double2( left.X + right.X, left.Y + right.Y ); } /// @@ -1160,8 +1167,8 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator +(Double2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator +( Double2 value ) { return value; } @@ -1172,10 +1179,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator -(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator -( Double2 left, Double2 right ) { - return new Double2(left.X - right.X, left.Y - right.Y); + return new Double2( left.X - right.X, left.Y - right.Y ); } /// @@ -1183,10 +1190,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator -(Double2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator -( Double2 value ) { - return new Double2(-value.X, -value.Y); + return new Double2( -value.X, -value.Y ); } /// @@ -1195,10 +1202,10 @@ namespace math /// The first vector to multiply. /// The second vector to multiply. /// The multiplication of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator *(Double2 left, Double2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator *( Double2 left, Double2 right ) { - return new Double2(left.X * right.X, left.Y * right.Y); + return new Double2( left.X * right.X, left.Y * right.Y ); } /// @@ -1207,10 +1214,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator *(double scale, Double2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator *( double scale, Double2 value ) { - return new Double2(value.X * scale, value.Y * scale); + return new Double2( value.X * scale, value.Y * scale ); } /// @@ -1219,10 +1226,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator *(Double2 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator *( Double2 value, double scale ) { - return new Double2(value.X * scale, value.Y * scale); + return new Double2( value.X * scale, value.Y * scale ); } /// @@ -1231,10 +1238,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator /(Double2 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator /( Double2 value, double scale ) { - return new Double2(value.X / scale, value.Y / scale); + return new Double2( value.X / scale, value.Y / scale ); } /// @@ -1243,10 +1250,10 @@ namespace math /// The numerator. /// The value. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator /(double numerator, Double2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator /( double numerator, Double2 value ) { - return new Double2(numerator / value.X, numerator / value.Y); + return new Double2( numerator / value.X, numerator / value.Y ); } /// @@ -1255,10 +1262,10 @@ namespace math /// The vector to scale. /// The by. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double2 operator /(Double2 value, Double2 by) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double2 operator /( Double2 value, Double2 by ) { - return new Double2(value.X / by.X, value.Y / by.Y); + return new Double2( value.X / by.X, value.Y / by.Y ); } /// @@ -1267,9 +1274,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Double2 left, Double2 right) + public static bool operator ==( Double2 left, Double2 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1278,9 +1285,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Double2 left, Double2 right) + public static bool operator !=( Double2 left, Double2 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1288,9 +1295,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Double2 value) + public static explicit operator Vec2( Double2 value ) { - return new Vec2((float)value.X, (float)value.Y); + return new Vec2( (float)value.X, (float)value.Y ); } /// @@ -1298,9 +1305,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Double2(Vec2 value) + public static implicit operator Double2( Vec2 value ) { - return new Double2(value); + return new Double2( value ); } /// @@ -1308,9 +1315,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Half2(Double2 value) + public static explicit operator Half2( Double2 value ) { - return new Half2((Half)value.X, (Half)value.Y); + return new Half2( (Half)value.X, (Half)value.Y ); } /// @@ -1318,9 +1325,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double2(Half2 value) + public static explicit operator Double2( Half2 value ) { - return new Double2(value.X, value.Y); + return new Double2( value.X, value.Y ); } /// @@ -1328,9 +1335,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double3(Double2 value) + public static explicit operator Double3( Double2 value ) { - return new Double3(value, 0.0); + return new Double3( value, 0.0 ); } /// @@ -1338,9 +1345,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double4(Double2 value) + public static explicit operator Double4( Double2 value ) { - return new Double4(value, 0.0, 0.0); + return new Double4( value, 0.0, 0.0 ); } /// @@ -1351,7 +1358,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y ); } /// @@ -1361,12 +1368,12 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString(format, CultureInfo.CurrentCulture), Y.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString( format, CultureInfo.CurrentCulture ), Y.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1376,9 +1383,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1}", X, Y); + return string.Format( formatProvider, "X:{0} Y:{1}", X, Y ); } /// @@ -1389,19 +1396,19 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - ToString(formatProvider); + if( format == null ) + ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1}", X.ToString(format, formatProvider), Y.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1}", X.ToString( format, formatProvider ), Y.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1415,10 +1422,10 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Double2 other) + public bool Equals( Double2 other ) { - return ((double)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (double)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance); + return ( (double)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (double)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance ); } /// @@ -1428,15 +1435,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Double2)value); + return Equals( (Double2)value ); } #if WPFInterop diff --git a/math/Double3.cs b/math/Double3.cs index 6f267e8..897590e 100644 --- a/math/Double3.cs +++ b/math/Double3.cs @@ -13,9 +13,9 @@ namespace math /// /// Represents a three dimensional mathematical vector with double-precision floats. /// - [DataContract( Name = "double3")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "double3" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Double3 : IEquatable, IFormattable { /// @@ -31,22 +31,22 @@ namespace math /// /// The X unit (1, 0, 0). /// - public static readonly Double3 UnitX = new Double3(1.0, 0.0, 0.0); + public static readonly Double3 UnitX = new Double3( 1.0, 0.0, 0.0 ); /// /// The Y unit (0, 1, 0). /// - public static readonly Double3 UnitY = new Double3(0.0, 1.0, 0.0); + public static readonly Double3 UnitY = new Double3( 0.0, 1.0, 0.0 ); /// /// The Z unit (0, 0, 1). /// - public static readonly Double3 UnitZ = new Double3(0.0, 0.0, 1.0); + public static readonly Double3 UnitZ = new Double3( 0.0, 0.0, 1.0 ); /// /// A with all of its components set to one. /// - public static readonly Double3 One = new Double3(1.0, 1.0, 1.0); + public static readonly Double3 One = new Double3( 1.0, 1.0, 1.0 ); /// /// The X component of the vector. @@ -70,7 +70,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Double3(double value) + public Double3( double value ) { X = value; Y = value; @@ -83,7 +83,7 @@ namespace math /// Initial value for the X component of the vector. /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. - public Double3(double x, double y, double z) + public Double3( double x, double y, double z ) { X = x; Y = y; @@ -95,7 +95,7 @@ namespace math /// /// A vector containing the values with which to initialize the X and Y components. /// Initial value for the Z component of the vector. - public Double3(Double2 value, double z) + public Double3( Double2 value, double z ) { X = value.X; Y = value.Y; @@ -108,12 +108,12 @@ namespace math /// The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements. /// Thrown when is null. /// Thrown when contains more or less than three elements. - public Double3(double[] values) + public Double3( double[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 3) - throw new ArgumentOutOfRangeException("values", "There must be three and only three input values for Double3."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 3 ) + throw new ArgumentOutOfRangeException( "values", "There must be three and only three input values for Double3." ); X = values[0]; Y = values[1]; @@ -124,7 +124,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The Vector3 to construct the Double3 from. - public Double3(Vec3 v) + public Double3( Vec3 v ) { X = v.X; Y = v.Y; @@ -136,7 +136,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) + (Z * Z) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) + ( Z * Z ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -150,24 +150,34 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; - case 2: return Z; + case 0: + return X; + case 1: + return Y; + case 2: + return Z; } - throw new ArgumentOutOfRangeException("index", "Indices for Double3 run from 0 to 2, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Double3 run from 0 to 2, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - case 2: Z = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Double3 run from 0 to 2, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + case 2: + Z = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Double3 run from 0 to 2, inclusive." ); } } } @@ -180,10 +190,10 @@ namespace math /// may be preferred when only the relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public double Length() { - return (double)Math.Sqrt((X * X) + (Y * Y) + (Z * Z)); + return (double)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) ); } /// @@ -194,20 +204,20 @@ namespace math /// This method may be preferred to when only a relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public double LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z); + return ( X * X ) + ( Y * Y ) + ( Z * Z ); } /// /// Converts the vector into a unit vector. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public void Normalize() { double length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { double inv = 1.0 / length; X *= inv; @@ -220,11 +230,11 @@ namespace math /// Raises the exponent for each components. /// /// The exponent. - public void Pow(double exponent) + public void Pow( double exponent ) { - X = (double)Math.Pow(X, exponent); - Y = (double)Math.Pow(Y, exponent); - Z = (double)Math.Pow(Z, exponent); + X = (double)Math.Pow( X, exponent ); + Y = (double)Math.Pow( Y, exponent ); + Z = (double)Math.Pow( Z, exponent ); } /// @@ -242,10 +252,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Add(ref Double3 left, ref Double3 right, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Add( ref Double3 left, ref Double3 right, out Double3 result ) { - result = new Double3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + result = new Double3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -254,10 +264,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Add(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Add( Double3 left, Double3 right ) { - return new Double3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + return new Double3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -266,10 +276,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Subtract(ref Double3 left, ref Double3 right, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Subtract( ref Double3 left, ref Double3 right, out Double3 result ) { - result = new Double3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + result = new Double3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -278,10 +288,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Subtract(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Subtract( Double3 left, Double3 right ) { - return new Double3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + return new Double3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -290,10 +300,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Multiply(ref Double3 value, double scale, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Multiply( ref Double3 value, double scale, out Double3 result ) { - result = new Double3(value.X * scale, value.Y * scale, value.Z * scale); + result = new Double3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -302,22 +312,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Multiply(Double3 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Multiply( Double3 value, double scale ) { - return new Double3(value.X * scale, value.Y * scale, value.Z * scale); + return new Double3( value.X * scale, value.Y * scale, value.Z * scale ); } - + /// /// Modulates a vector with another by performing component-wise multiplication. /// /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Modulate(ref Double3 left, ref Double3 right, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Modulate( ref Double3 left, ref Double3 right, out Double3 result ) { - result = new Double3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + result = new Double3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -326,10 +336,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Modulate(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Modulate( Double3 left, Double3 right ) { - return new Double3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + return new Double3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -338,10 +348,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Divide(ref Double3 value, double scale, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Divide( ref Double3 value, double scale, out Double3 result ) { - result = new Double3(value.X / scale, value.Y / scale, value.Z / scale); + result = new Double3( value.X / scale, value.Y / scale, value.Z / scale ); } /// @@ -350,22 +360,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Divide(Double3 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Divide( Double3 value, double scale ) { - return new Double3(value.X / scale, value.Y / scale, value.Z / scale); + return new Double3( value.X / scale, value.Y / scale, value.Z / scale ); } - + /// /// Demodulates a vector with another by performing component-wise division. /// /// The first vector to demodulate. /// The second vector to demodulate. /// When the method completes, contains the demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Demodulate(ref Double3 left, ref Double3 right, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Demodulate( ref Double3 left, ref Double3 right, out Double3 result ) { - result = new Double3(left.X / right.X, left.Y / right.Y, left.Z / right.Z); + result = new Double3( left.X / right.X, left.Y / right.Y, left.Z / right.Z ); } /// @@ -374,10 +384,10 @@ namespace math /// The first vector to demodulate. /// The second vector to demodulate. /// The demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Demodulate(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Demodulate( Double3 left, Double3 right ) { - return new Double3(left.X / right.X, left.Y / right.Y, left.Z / right.Z); + return new Double3( left.X / right.X, left.Y / right.Y, left.Z / right.Z ); } /// @@ -385,10 +395,10 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Negate(ref Double3 value, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Negate( ref Double3 value, out Double3 result ) { - result = new Double3(-value.X, -value.Y, -value.Z); + result = new Double3( -value.X, -value.Y, -value.Z ); } /// @@ -396,10 +406,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Negate(Double3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Negate( Double3 value ) { - return new Double3(-value.X, -value.Y, -value.Z); + return new Double3( -value.X, -value.Y, -value.Z ); } /// @@ -411,11 +421,11 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 3D Cartesian coordinates of the specified point. - public static void Barycentric(ref Double3 value1, ref Double3 value2, ref Double3 value3, double amount1, double amount2, out Double3 result) + public static void Barycentric( ref Double3 value1, ref Double3 value2, ref Double3 value3, double amount1, double amount2, out Double3 result ) { - result = new Double3((value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)), - (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y)), - (value1.Z + (amount1 * (value2.Z - value1.Z))) + (amount2 * (value3.Z - value1.Z))); + result = new Double3( ( value1.X + ( amount1 * ( value2.X - value1.X ) ) ) + ( amount2 * ( value3.X - value1.X ) ), + ( value1.Y + ( amount1 * ( value2.Y - value1.Y ) ) ) + ( amount2 * ( value3.Y - value1.Y ) ), + ( value1.Z + ( amount1 * ( value2.Z - value1.Z ) ) ) + ( amount2 * ( value3.Z - value1.Z ) ) ); } /// @@ -427,10 +437,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 3D Cartesian coordinates of the specified point. - public static Double3 Barycentric(Double3 value1, Double3 value2, Double3 value3, double amount1, double amount2) + public static Double3 Barycentric( Double3 value1, Double3 value2, Double3 value3, double amount1, double amount2 ) { Double3 result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -441,21 +451,21 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Double3 value, ref Double3 min, ref Double3 max, out Double3 result) + public static void Clamp( ref Double3 value, ref Double3 min, ref Double3 max, out Double3 result ) { double x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; double y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; double z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; - result = new Double3(x, y, z); + result = new Double3( x, y, z ); } /// @@ -465,10 +475,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Double3 Clamp(Double3 value, Double3 min, Double3 max) + public static Double3 Clamp( Double3 value, Double3 min, Double3 max ) { Double3 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -478,12 +488,12 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains he cross product of the two vectors. - public static void Cross(ref Double3 left, ref Double3 right, out Double3 result) + public static void Cross( ref Double3 left, ref Double3 right, out Double3 result ) { result = new Double3( - (left.Y * right.Z) - (left.Z * right.Y), - (left.Z * right.X) - (left.X * right.Z), - (left.X * right.Y) - (left.Y * right.X)); + ( left.Y * right.Z ) - ( left.Z * right.Y ), + ( left.Z * right.X ) - ( left.X * right.Z ), + ( left.X * right.Y ) - ( left.Y * right.X ) ); } /// @@ -492,10 +502,10 @@ namespace math /// First source vector. /// Second source vector. /// The cross product of the two vectors. - public static Double3 Cross(Double3 left, Double3 right) + public static Double3 Cross( Double3 left, Double3 right ) { Double3 result; - Cross(ref left, ref right, out result); + Cross( ref left, ref right, out result ); return result; } @@ -509,13 +519,13 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static void Distance(ref Double3 value1, ref Double3 value2, out double result) + public static void Distance( ref Double3 value1, ref Double3 value2, out double result ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; - result = (double)Math.Sqrt((x * x) + (y * y) + (z * z)); + result = (double)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) ); } /// @@ -528,13 +538,13 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static double Distance(Double3 value1, Double3 value2) + public static double Distance( Double3 value1, Double3 value2 ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; - return (double)Math.Sqrt((x * x) + (y * y) + (z * z)); + return (double)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) ); } /// @@ -543,20 +553,20 @@ namespace math /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Double3 value1, ref Double3 value2, out double result) + public static void DistanceSquared( ref Double3 value1, ref Double3 value2, out double result ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; - result = (x * x) + (y * y) + (z * z); + result = ( x * x ) + ( y * y ) + ( z * z ); } /// @@ -565,20 +575,20 @@ namespace math /// The first vector. /// The second vector. /// The squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static double DistanceSquared(Double3 value1, Double3 value2) + public static double DistanceSquared( Double3 value1, Double3 value2 ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; - return (x * x) + (y * y) + (z * z); + return ( x * x ) + ( y * y ) + ( z * z ); } /// @@ -587,10 +597,10 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Double3 left, ref Double3 right, out double result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Dot( ref Double3 left, ref Double3 right, out double result ) { - result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); + result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ); } /// @@ -599,10 +609,10 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Dot(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static double Dot( Double3 left, Double3 right ) { - return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); + return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ); } /// @@ -610,8 +620,8 @@ namespace math /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(ref Double3 value, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Normalize( ref Double3 value, out Double3 result ) { result = value; result.Normalize(); @@ -622,8 +632,8 @@ namespace math /// /// The vector to normalize. /// The normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Normalize(Double3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Normalize( Double3 value ) { value.Normalize(); return value; @@ -639,13 +649,13 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Double3 start, ref Double3 end, double amount, out Double3 result) + public static void Lerp( ref Double3 start, ref Double3 end, double amount, out Double3 result ) { - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); } /// @@ -658,12 +668,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Double3 Lerp(Double3 start, Double3 end, double amount) + public static Double3 Lerp( Double3 start, Double3 end, double amount ) { Double3 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -674,14 +684,14 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Double3 start, ref Double3 end, double amount, out Double3 result) + public static void SmoothStep( ref Double3 start, ref Double3 end, double amount, out Double3 result ) { - amount = (amount > 1.0) ? 1.0 : ((amount < 0.0) ? 0.0 : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0 ) ? 1.0 : ( ( amount < 0.0 ) ? 0.0 : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); } /// @@ -691,10 +701,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Double3 SmoothStep(Double3 start, Double3 end, double amount) + public static Double3 SmoothStep( Double3 start, Double3 end, double amount ) { Double3 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -707,18 +717,18 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Double3 value1, ref Double3 tangent1, ref Double3 value2, ref Double3 tangent2, double amount, out Double3 result) + public static void Hermite( ref Double3 value1, ref Double3 tangent1, ref Double3 value2, ref Double3 tangent2, double amount, out Double3 result ) { double squared = amount * amount; double cubed = amount * squared; - double part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0; - double part2 = (-2.0f * cubed) + (3.0f * squared); - double part3 = (cubed - (2.0f * squared)) + amount; + double part1 = ( ( 2.0f * cubed ) - ( 3.0f * squared ) ) + 1.0; + double part2 = ( -2.0f * cubed ) + ( 3.0f * squared ); + double part3 = ( cubed - ( 2.0f * squared ) ) + amount; double part4 = cubed - squared; - result.X = (((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4); - result.Y = (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4); - result.Z = (((value1.Z * part1) + (value2.Z * part2)) + (tangent1.Z * part3)) + (tangent2.Z * part4); + result.X = ( ( ( value1.X * part1 ) + ( value2.X * part2 ) ) + ( tangent1.X * part3 ) ) + ( tangent2.X * part4 ); + result.Y = ( ( ( value1.Y * part1 ) + ( value2.Y * part2 ) ) + ( tangent1.Y * part3 ) ) + ( tangent2.Y * part4 ); + result.Z = ( ( ( value1.Z * part1 ) + ( value2.Z * part2 ) ) + ( tangent1.Z * part3 ) ) + ( tangent2.Z * part4 ); } /// @@ -730,10 +740,10 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// The result of the Hermite spline interpolation. - public static Double3 Hermite(Double3 value1, Double3 tangent1, Double3 value2, Double3 tangent2, double amount) + public static Double3 Hermite( Double3 value1, Double3 tangent1, Double3 value2, Double3 tangent2, double amount ) { Double3 result; - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + Hermite( ref value1, ref tangent1, ref value2, ref tangent2, amount, out result ); return result; } @@ -746,22 +756,22 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Double3 value1, ref Double3 value2, ref Double3 value3, ref Double3 value4, double amount, out Double3 result) + public static void CatmullRom( ref Double3 value1, ref Double3 value2, ref Double3 value3, ref Double3 value4, double amount, out Double3 result ) { double squared = amount * amount; double cubed = amount * squared; - result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) + - (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) + - ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed)); + result.X = 0.5f * ( ( ( ( 2.0f * value2.X ) + ( ( -value1.X + value3.X ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.X ) - ( 5.0f * value2.X ) ) + ( 4.0f * value3.X ) ) - value4.X ) * squared ) ) + + ( ( ( ( -value1.X + ( 3.0f * value2.X ) ) - ( 3.0f * value3.X ) ) + value4.X ) * cubed ) ); - result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) + - (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) + - ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed)); + result.Y = 0.5f * ( ( ( ( 2.0f * value2.Y ) + ( ( -value1.Y + value3.Y ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.Y ) - ( 5.0f * value2.Y ) ) + ( 4.0f * value3.Y ) ) - value4.Y ) * squared ) ) + + ( ( ( ( -value1.Y + ( 3.0f * value2.Y ) ) - ( 3.0f * value3.Y ) ) + value4.Y ) * cubed ) ); - result.Z = 0.5f * ((((2.0f * value2.Z) + ((-value1.Z + value3.Z) * amount)) + - (((((2.0f * value1.Z) - (5.0f * value2.Z)) + (4.0f * value3.Z)) - value4.Z) * squared)) + - ((((-value1.Z + (3.0f * value2.Z)) - (3.0f * value3.Z)) + value4.Z) * cubed)); + result.Z = 0.5f * ( ( ( ( 2.0f * value2.Z ) + ( ( -value1.Z + value3.Z ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.Z ) - ( 5.0f * value2.Z ) ) + ( 4.0f * value3.Z ) ) - value4.Z ) * squared ) ) + + ( ( ( ( -value1.Z + ( 3.0f * value2.Z ) ) - ( 3.0f * value3.Z ) ) + value4.Z ) * cubed ) ); } /// @@ -773,10 +783,10 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// A vector that is the result of the Catmull-Rom interpolation. - public static Double3 CatmullRom(Double3 value1, Double3 value2, Double3 value3, Double3 value4, double amount) + public static Double3 CatmullRom( Double3 value1, Double3 value2, Double3 value3, Double3 value4, double amount ) { Double3 result; - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result); + CatmullRom( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -786,12 +796,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Max(ref Double3 left, ref Double3 right, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Max( ref Double3 left, ref Double3 right, out Double3 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; } /// @@ -800,11 +810,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Max(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Max( Double3 left, Double3 right ) { Double3 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -814,12 +824,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Min(ref Double3 left, ref Double3 right, out Double3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Min( ref Double3 left, ref Double3 right, out Double3 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; } /// @@ -828,16 +838,16 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 Min(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 Min( Double3 left, Double3 right ) { Double3 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } /// - /// Projects a 3D vector from object space into screen space. + /// Projects a 3D vector from object space into screen space. /// /// The vector to project. /// The X position of the viewport. @@ -848,16 +858,16 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in screen space. - public static void Project(ref Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result) + public static void Project( ref Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result ) { Double3 v; - TransformCoordinate(ref vector, ref worldViewProjection, out v); + TransformCoordinate( ref vector, ref worldViewProjection, out v ); - result = new Double3(((1.0 + v.X) * 0.5f * width) + x, ((1.0 - v.Y) * 0.5f * height) + y, (v.Z * (maxZ - minZ)) + minZ); + result = new Double3( ( ( 1.0 + v.X ) * 0.5f * width ) + x, ( ( 1.0 - v.Y ) * 0.5f * height ) + y, ( v.Z * ( maxZ - minZ ) ) + minZ ); } /// - /// Projects a 3D vector from object space into screen space. + /// Projects a 3D vector from object space into screen space. /// /// The vector to project. /// The X position of the viewport. @@ -868,15 +878,15 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// The vector in screen space. - public static Double3 Project(Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, Matrix worldViewProjection) + public static Double3 Project( Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, Matrix worldViewProjection ) { Double3 result; - Project(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result); + Project( ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result ); return result; } /// - /// Projects a 3D vector from screen space into object space. + /// Projects a 3D vector from screen space into object space. /// /// The vector to project. /// The X position of the viewport. @@ -887,21 +897,21 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in object space. - public static void Unproject(ref Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result) + public static void Unproject( ref Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, ref Matrix worldViewProjection, out Double3 result ) { Double3 v = new Double3(); Matrix matrix; - Matrix.Invert(ref worldViewProjection, out matrix); + Matrix.Invert( ref worldViewProjection, out matrix ); - v.X = (((vector.X - x) / width) * 2.0f) - 1.0; - v.Y = -((((vector.Y - y) / height) * 2.0f) - 1.0); - v.Z = (vector.Z - minZ) / (maxZ - minZ); + v.X = ( ( ( vector.X - x ) / width ) * 2.0f ) - 1.0; + v.Y = -( ( ( ( vector.Y - y ) / height ) * 2.0f ) - 1.0 ); + v.Z = ( vector.Z - minZ ) / ( maxZ - minZ ); - TransformCoordinate(ref v, ref matrix, out result); + TransformCoordinate( ref v, ref matrix, out result ); } /// - /// Projects a 3D vector from screen space into object space. + /// Projects a 3D vector from screen space into object space. /// /// The vector to project. /// The X position of the viewport. @@ -912,42 +922,42 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// The vector in object space. - public static Double3 Unproject(Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, Matrix worldViewProjection) + public static Double3 Unproject( Double3 vector, double x, double y, double width, double height, double minZ, double maxZ, Matrix worldViewProjection ) { Double3 result; - Unproject(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result); + Unproject( ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result ); return result; } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// When the method completes, contains the reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Double3 vector, ref Double3 normal, out Double3 result) + public static void Reflect( ref Double3 vector, ref Double3 normal, out Double3 result ) { - double dot = (vector.X * normal.X) + (vector.Y * normal.Y) + (vector.Z * normal.Z); + double dot = ( vector.X * normal.X ) + ( vector.Y * normal.Y ) + ( vector.Z * normal.Z ); - result.X = vector.X - ((2.0f * dot) * normal.X); - result.Y = vector.Y - ((2.0f * dot) * normal.Y); - result.Z = vector.Z - ((2.0f * dot) * normal.Z); + result.X = vector.X - ( ( 2.0f * dot ) * normal.X ); + result.Y = vector.Y - ( ( 2.0f * dot ) * normal.Y ); + result.Z = vector.Z - ( ( 2.0f * dot ) * normal.Z ); } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// The reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static Double3 Reflect(Double3 vector, Double3 normal) + public static Double3 Reflect( Double3 vector, Double3 normal ) { Double3 result; - Reflect(ref vector, ref normal, out result); + Reflect( ref vector, ref normal, out result ); return result; } @@ -967,7 +977,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthogonalize(Double3[] destination, params Double3[] source) + public static void Orthogonalize( Double3[] destination, params Double3[] source ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -976,20 +986,20 @@ namespace math //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3 //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Double3 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= (Double3.Dot(destination[r], newvector) / Double3.Dot(destination[r], destination[r])) * destination[r]; + newvector -= ( Double3.Dot( destination[r], newvector ) / Double3.Dot( destination[r], destination[r] ) ) * destination[r]; } destination[i] = newvector; @@ -1012,7 +1022,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthonormalize(Double3[] destination, params Double3[] source) + public static void Orthonormalize( Double3[] destination, params Double3[] source ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -1023,20 +1033,20 @@ namespace math //q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3| //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Double3 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= Double3.Dot(destination[r], newvector) * destination[r]; + newvector -= Double3.Dot( destination[r], newvector ) * destination[r]; } newvector.Normalize(); @@ -1050,7 +1060,7 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Quaternion rotation, out Double3 result) + public static void Transform( ref Double3 vector, ref Quaternion rotation, out Double3 result ) { double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -1066,9 +1076,9 @@ namespace math double zz = rotation.Z * z; result = new Double3( - ((vector.X * ((1.0 - yy) - zz)) + (vector.Y * (xy - wz))) + (vector.Z * (xz + wy)), - ((vector.X * (xy + wz)) + (vector.Y * ((1.0 - xx) - zz))) + (vector.Z * (yz - wx)), - ((vector.X * (xz - wy)) + (vector.Y * (yz + wx))) + (vector.Z * ((1.0 - xx) - yy))); + ( ( vector.X * ( ( 1.0 - yy ) - zz ) ) + ( vector.Y * ( xy - wz ) ) ) + ( vector.Z * ( xz + wy ) ), + ( ( vector.X * ( xy + wz ) ) + ( vector.Y * ( ( 1.0 - xx ) - zz ) ) ) + ( vector.Z * ( yz - wx ) ), + ( ( vector.X * ( xz - wy ) ) + ( vector.Y * ( yz + wx ) ) ) + ( vector.Z * ( ( 1.0 - xx ) - yy ) ) ); } /// @@ -1077,10 +1087,10 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// The transformed . - public static Double3 Transform(Double3 vector, Quaternion rotation) + public static Double3 Transform( Double3 vector, Quaternion rotation ) { Double3 result; - Transform(ref vector, ref rotation, out result); + Transform( ref vector, ref rotation, out result ); return result; } @@ -1093,14 +1103,14 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Double3[] source, ref Quaternion rotation, Double3[] destination) + public static void Transform( Double3[] source, ref Quaternion rotation, Double3[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -1115,22 +1125,22 @@ namespace math double yz = rotation.Y * z; double zz = rotation.Z * z; - double num1 = ((1.0 - yy) - zz); - double num2 = (xy - wz); - double num3 = (xz + wy); - double num4 = (xy + wz); - double num5 = ((1.0 - xx) - zz); - double num6 = (yz - wx); - double num7 = (xz - wy); - double num8 = (yz + wx); - double num9 = ((1.0 - xx) - yy); + double num1 = ( ( 1.0 - yy ) - zz ); + double num2 = ( xy - wz ); + double num3 = ( xz + wy ); + double num4 = ( xy + wz ); + double num5 = ( ( 1.0 - xx ) - zz ); + double num6 = ( yz - wx ); + double num7 = ( xz - wy ); + double num8 = ( yz + wx ); + double num9 = ( ( 1.0 - xx ) - yy ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { destination[i] = new Double3( - ((source[i].X * num1) + (source[i].Y * num2)) + (source[i].Z * num3), - ((source[i].X * num4) + (source[i].Y * num5)) + (source[i].Z * num6), - ((source[i].X * num7) + (source[i].Y * num8)) + (source[i].Z * num9)); + ( ( source[i].X * num1 ) + ( source[i].Y * num2 ) ) + ( source[i].Z * num3 ), + ( ( source[i].X * num4 ) + ( source[i].Y * num5 ) ) + ( source[i].Z * num6 ), + ( ( source[i].X * num7 ) + ( source[i].Y * num8 ) ) + ( source[i].Z * num9 ) ); } } @@ -1140,13 +1150,13 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Matrix transform, out Double4 result) + public static void Transform( ref Double3 vector, ref Matrix transform, out Double4 result ) { result = new Double4( - (vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31) + transform.M41, - (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32) + transform.M42, - (vector.X * transform.M13) + (vector.Y * transform.M23) + (vector.Z * transform.M33) + transform.M43, - (vector.X * transform.M14) + (vector.Y * transform.M24) + (vector.Z * transform.M34) + transform.M44); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + ( vector.Z * transform.M31 ) + transform.M41, + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + ( vector.Z * transform.M32 ) + transform.M42, + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + ( vector.Z * transform.M33 ) + transform.M43, + ( vector.X * transform.M14 ) + ( vector.Y * transform.M24 ) + ( vector.Z * transform.M34 ) + transform.M44 ); } /// @@ -1155,12 +1165,12 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double3 vector, ref Matrix transform, out Double3 result) + public static void Transform( ref Double3 vector, ref Matrix transform, out Double3 result ) { result = new Double3( - (vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31) + transform.M41, - (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32) + transform.M42, - (vector.X * transform.M13) + (vector.Y * transform.M23) + (vector.Z * transform.M33) + transform.M43); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + ( vector.Z * transform.M31 ) + transform.M41, + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + ( vector.Z * transform.M32 ) + transform.M42, + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + ( vector.Z * transform.M33 ) + transform.M43 ); } /// @@ -1169,10 +1179,10 @@ namespace math /// The source vector. /// The transformation . /// The transformed . - public static Double4 Transform(Double3 vector, Matrix transform) + public static Double4 Transform( Double3 vector, Matrix transform ) { Double4 result; - Transform(ref vector, ref transform, out result); + Transform( ref vector, ref transform, out result ); return result; } @@ -1184,18 +1194,18 @@ namespace math /// The array for which the transformed vectors are stored. /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Double3[] source, ref Matrix transform, Double4[] destination) + public static void Transform( Double3[] source, ref Matrix transform, Double4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - Transform(ref source[i], ref transform, out destination[i]); + Transform( ref source[i], ref transform, out destination[i] ); } } @@ -1212,13 +1222,13 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Double3 coordinate, ref Matrix transform, out Double3 result) + public static void TransformCoordinate( ref Double3 coordinate, ref Matrix transform, out Double3 result ) { - var invW = 1f / ((coordinate.X * transform.M14) + (coordinate.Y * transform.M24) + (coordinate.Z * transform.M34) + transform.M44); + var invW = 1f / ( ( coordinate.X * transform.M14 ) + ( coordinate.Y * transform.M24 ) + ( coordinate.Z * transform.M34 ) + transform.M44 ); result = new Double3( - ((coordinate.X * transform.M11) + (coordinate.Y * transform.M21) + (coordinate.Z * transform.M31) + transform.M41) * invW, - ((coordinate.X * transform.M12) + (coordinate.Y * transform.M22) + (coordinate.Z * transform.M32) + transform.M42) * invW, - ((coordinate.X * transform.M13) + (coordinate.Y * transform.M23) + (coordinate.Z * transform.M33) + transform.M43) * invW); + ( ( coordinate.X * transform.M11 ) + ( coordinate.Y * transform.M21 ) + ( coordinate.Z * transform.M31 ) + transform.M41 ) * invW, + ( ( coordinate.X * transform.M12 ) + ( coordinate.Y * transform.M22 ) + ( coordinate.Z * transform.M32 ) + transform.M42 ) * invW, + ( ( coordinate.X * transform.M13 ) + ( coordinate.Y * transform.M23 ) + ( coordinate.Z * transform.M33 ) + transform.M43 ) * invW ); } /// @@ -1234,10 +1244,10 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static Double3 TransformCoordinate(Double3 coordinate, Matrix transform) + public static Double3 TransformCoordinate( Double3 coordinate, Matrix transform ) { Double3 result; - TransformCoordinate(ref coordinate, ref transform, out result); + TransformCoordinate( ref coordinate, ref transform, out result ); return result; } @@ -1257,18 +1267,18 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(Double3[] source, ref Matrix transform, Double3[] destination) + public static void TransformCoordinate( Double3[] source, ref Matrix transform, Double3[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformCoordinate(ref source[i], ref transform, out destination[i]); + TransformCoordinate( ref source[i], ref transform, out destination[i] ); } } @@ -1285,12 +1295,12 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Double3 normal, ref Matrix transform, out Double3 result) + public static void TransformNormal( ref Double3 normal, ref Matrix transform, out Double3 result ) { result = new Double3( - (normal.X * transform.M11) + (normal.Y * transform.M21) + (normal.Z * transform.M31), - (normal.X * transform.M12) + (normal.Y * transform.M22) + (normal.Z * transform.M32), - (normal.X * transform.M13) + (normal.Y * transform.M23) + (normal.Z * transform.M33)); + ( normal.X * transform.M11 ) + ( normal.Y * transform.M21 ) + ( normal.Z * transform.M31 ), + ( normal.X * transform.M12 ) + ( normal.Y * transform.M22 ) + ( normal.Z * transform.M32 ), + ( normal.X * transform.M13 ) + ( normal.Y * transform.M23 ) + ( normal.Z * transform.M33 ) ); } /// @@ -1306,10 +1316,10 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static Double3 TransformNormal(Double3 normal, Matrix transform) + public static Double3 TransformNormal( Double3 normal, Matrix transform ) { Double3 result; - TransformNormal(ref normal, ref transform, out result); + TransformNormal( ref normal, ref transform, out result ); return result; } @@ -1329,18 +1339,18 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(Double3[] source, ref Matrix transform, Double3[] destination) + public static void TransformNormal( Double3[] source, ref Matrix transform, Double3[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformNormal(ref source[i], ref transform, out destination[i]); + TransformNormal( ref source[i], ref transform, out destination[i] ); } } @@ -1349,22 +1359,22 @@ namespace math /// /// The input rotation as quaternion /// The equivation yaw/pitch/roll rotation - public static Double3 RotationYawPitchRoll(Quaternion quaternion) + public static Double3 RotationYawPitchRoll( Quaternion quaternion ) { Vec3 yawPitchRoll; - Quaternion.RotationYawPitchRoll(ref quaternion, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z); + Quaternion.RotationYawPitchRoll( ref quaternion, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z ); return yawPitchRoll; } /// - /// Calculate the yaw/pitch/roll rotation equivalent to the provided quaterion. + /// Calculate the yaw/pitch/roll rotation equivalent to the provided quaterion. /// /// The input rotation as quaternion /// The equivation yaw/pitch/roll rotation - public static void RotationYawPitchRoll(ref Quaternion quaternion, out Double3 yawPitchRoll) + public static void RotationYawPitchRoll( ref Quaternion quaternion, out Double3 yawPitchRoll ) { Vec3 yawPitchRollV; - Quaternion.RotationYawPitchRoll(ref quaternion, out yawPitchRollV.X, out yawPitchRollV.Y, out yawPitchRollV.Z); + Quaternion.RotationYawPitchRoll( ref quaternion, out yawPitchRollV.X, out yawPitchRollV.Y, out yawPitchRollV.Z ); yawPitchRoll = yawPitchRollV; } @@ -1374,10 +1384,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator +(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator +( Double3 left, Double3 right ) { - return new Double3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + return new Double3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -1385,8 +1395,8 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator +(Double3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator +( Double3 value ) { return value; } @@ -1397,10 +1407,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator -(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator -( Double3 left, Double3 right ) { - return new Double3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + return new Double3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -1408,10 +1418,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator -(Double3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator -( Double3 value ) { - return new Double3(-value.X, -value.Y, -value.Z); + return new Double3( -value.X, -value.Y, -value.Z ); } /// @@ -1420,10 +1430,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator *(double scale, Double3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator *( double scale, Double3 value ) { - return new Double3(value.X * scale, value.Y * scale, value.Z * scale); + return new Double3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -1432,10 +1442,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator *(Double3 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator *( Double3 value, double scale ) { - return new Double3(value.X * scale, value.Y * scale, value.Z * scale); + return new Double3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -1444,10 +1454,10 @@ namespace math /// The first vector to multiply. /// The second vector to multiply. /// The multiplication of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator *(Double3 left, Double3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator *( Double3 left, Double3 right ) { - return new Double3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + return new Double3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -1456,10 +1466,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The vector offset. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator +(Double3 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator +( Double3 value, double scale ) { - return new Double3(value.X + scale, value.Y + scale, value.Z + scale); + return new Double3( value.X + scale, value.Y + scale, value.Z + scale ); } /// @@ -1468,10 +1478,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The vector offset. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator -(Double3 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator -( Double3 value, double scale ) { - return new Double3(value.X - scale, value.Y - scale, value.Z - scale); + return new Double3( value.X - scale, value.Y - scale, value.Z - scale ); } /// @@ -1480,10 +1490,10 @@ namespace math /// The numerator. /// The value. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator /(double numerator, Double3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator /( double numerator, Double3 value ) { - return new Double3(numerator / value.X, numerator / value.Y, numerator / value.Z); + return new Double3( numerator / value.X, numerator / value.Y, numerator / value.Z ); } /// @@ -1492,10 +1502,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator /(Double3 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator /( Double3 value, double scale ) { - return new Double3(value.X / scale, value.Y / scale, value.Z / scale); + return new Double3( value.X / scale, value.Y / scale, value.Z / scale ); } /// @@ -1504,10 +1514,10 @@ namespace math /// The vector to scale. /// The by. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double3 operator /(Double3 value, Double3 by) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double3 operator /( Double3 value, Double3 by ) { - return new Double3(value.X / by.X, value.Y / by.Y, value.Z / by.Z); + return new Double3( value.X / by.X, value.Y / by.Y, value.Z / by.Z ); } /// @@ -1516,9 +1526,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Double3 left, Double3 right) + public static bool operator ==( Double3 left, Double3 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1527,9 +1537,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Double3 left, Double3 right) + public static bool operator !=( Double3 left, Double3 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1537,9 +1547,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Double3 value) + public static explicit operator Vec3( Double3 value ) { - return new Vec3((float)value.X, (float)value.Y, (float)value.Z); + return new Vec3( (float)value.X, (float)value.Y, (float)value.Z ); } /// @@ -1547,9 +1557,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Double3(Vec3 value) + public static implicit operator Double3( Vec3 value ) { - return new Double3(value); + return new Double3( value ); } /// @@ -1557,9 +1567,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Half3(Double3 value) + public static explicit operator Half3( Double3 value ) { - return new Half3((Half)value.X, (Half)value.Y, (Half)value.Z); + return new Half3( (Half)value.X, (Half)value.Y, (Half)value.Z ); } /// @@ -1567,9 +1577,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double3(Half3 value) + public static explicit operator Double3( Half3 value ) { - return new Double3(value.X, value.Y, value.Z); + return new Double3( value.X, value.Y, value.Z ); } /// @@ -1577,9 +1587,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double2(Double3 value) + public static explicit operator Double2( Double3 value ) { - return new Double2(value.X, value.Y); + return new Double2( value.X, value.Y ); } /// @@ -1587,9 +1597,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double4(Double3 value) + public static explicit operator Double4( Double3 value ) { - return new Double4(value, 0.0); + return new Double4( value, 0.0 ); } /// @@ -1599,9 +1609,9 @@ namespace math /// The right vector. /// The epsilon. /// true if left and right are near another 3D, false otherwise - public static bool NearEqual(Double3 left, Double3 right, Double3 epsilon) + public static bool NearEqual( Double3 left, Double3 right, Double3 epsilon ) { - return NearEqual(ref left, ref right, ref epsilon); + return NearEqual( ref left, ref right, ref epsilon ); } /// @@ -1611,11 +1621,11 @@ namespace math /// The right vector. /// The epsilon. /// true if left and right are near another 3D, false otherwise - public static bool NearEqual(ref Double3 left, ref Double3 right, ref Double3 epsilon) + public static bool NearEqual( ref Double3 left, ref Double3 right, ref Double3 epsilon ) { - return MathUtil.WithinEpsilon((float)left.X, (float)right.X, (float)epsilon.X) && - MathUtil.WithinEpsilon((float)left.Y, (float)right.Y, (float)epsilon.Y) && - MathUtil.WithinEpsilon((float)left.Z, (float)right.Z, (float)epsilon.Z); + return MathUtil.WithinEpsilon( (float)left.X, (float)right.X, (float)epsilon.X ) && + MathUtil.WithinEpsilon( (float)left.Y, (float)right.Y, (float)epsilon.Y ) && + MathUtil.WithinEpsilon( (float)left.Z, (float)right.Z, (float)epsilon.Z ); } /// @@ -1626,7 +1636,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z ); } /// @@ -1636,13 +1646,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), Z.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1652,9 +1662,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z ); } /// @@ -1665,20 +1675,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1692,11 +1702,11 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Double3 other) + public bool Equals( Double3 other ) { - return ((double)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (double)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance && - (double)Math.Abs(other.Z - Z) < MathUtil.ZeroTolerance); + return ( (double)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (double)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance && + (double)Math.Abs( other.Z - Z ) < MathUtil.ZeroTolerance ); } /// @@ -1706,15 +1716,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Double3)value); + return Equals( (Double3)value ); } diff --git a/math/Double4.cs b/math/Double4.cs index 36b5adb..afe367c 100644 --- a/math/Double4.cs +++ b/math/Double4.cs @@ -13,9 +13,9 @@ namespace math /// /// Represents a four dimensional mathematical vector with double-precision floats. /// - [DataContract( Name = "double4")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "double4" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Double4 : IEquatable, IFormattable { /// @@ -31,27 +31,27 @@ namespace math /// /// The X unit (1, 0, 0, 0). /// - public static readonly Double4 UnitX = new Double4(1.0, 0.0, 0.0, 0.0); + public static readonly Double4 UnitX = new Double4( 1.0, 0.0, 0.0, 0.0 ); /// /// The Y unit (0, 1, 0, 0). /// - public static readonly Double4 UnitY = new Double4(0.0, 1.0, 0.0, 0.0); + public static readonly Double4 UnitY = new Double4( 0.0, 1.0, 0.0, 0.0 ); /// /// The Z unit (0, 0, 1, 0). /// - public static readonly Double4 UnitZ = new Double4(0.0, 0.0, 1.0, 0.0); + public static readonly Double4 UnitZ = new Double4( 0.0, 0.0, 1.0, 0.0 ); /// /// The W unit (0, 0, 0, 1). /// - public static readonly Double4 UnitW = new Double4(0.0, 0.0, 0.0, 1.0); + public static readonly Double4 UnitW = new Double4( 0.0, 0.0, 0.0, 1.0 ); /// /// A with all of its components set to one. /// - public static readonly Double4 One = new Double4(1.0, 1.0, 1.0, 1.0); + public static readonly Double4 One = new Double4( 1.0, 1.0, 1.0, 1.0 ); /// /// The X component of the vector. @@ -81,7 +81,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Double4(double value) + public Double4( double value ) { X = value; Y = value; @@ -96,7 +96,7 @@ namespace math /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. /// Initial value for the W component of the vector. - public Double4(double x, double y, double z, double w) + public Double4( double x, double y, double z, double w ) { X = x; Y = y; @@ -109,7 +109,7 @@ namespace math /// /// A vector containing the values with which to initialize the X, Y, and Z components. /// Initial value for the W component of the vector. - public Double4(Double3 value, double w) + public Double4( Double3 value, double w ) { X = value.X; Y = value.Y; @@ -123,7 +123,7 @@ namespace math /// A vector containing the values with which to initialize the X and Y components. /// Initial value for the Z component of the vector. /// Initial value for the W component of the vector. - public Double4(Double2 value, double z, double w) + public Double4( Double2 value, double z, double w ) { X = value.X; Y = value.Y; @@ -137,12 +137,12 @@ namespace math /// The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Double4(double[] values) + public Double4( double[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 4) - throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for Double4."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( "values", "There must be four and only four input values for Double4." ); X = values[0]; Y = values[1]; @@ -154,7 +154,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The Vector4 to construct the Double4 from. - public Double4(Vec4 v) + public Double4( Vec4 v ) { X = v.X; Y = v.Y; @@ -167,7 +167,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) + (Z * Z) + (W * W) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -181,26 +181,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; - case 2: return Z; - case 3: return W; + case 0: + return X; + case 1: + return Y; + case 2: + return Z; + case 3: + return W; } - throw new ArgumentOutOfRangeException("index", "Indices for Double4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Double4 run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - case 2: Z = value; break; - case 3: W = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Double4 run from 0 to 3, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + case 2: + Z = value; + break; + case 3: + W = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Double4 run from 0 to 3, inclusive." ); } } } @@ -213,10 +226,10 @@ namespace math /// may be preferred when only the relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public double Length() { - return (double)Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); + return (double)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) ); } /// @@ -227,20 +240,20 @@ namespace math /// This method may be preferred to when only a relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public double LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z) + (W * W); + return ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ); } /// /// Converts the vector into a unit vector. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public void Normalize() { double length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { double inverse = 1.0 / length; X *= inverse; @@ -254,12 +267,12 @@ namespace math /// Raises the exponent for each components. /// /// The exponent. - public void Pow(double exponent) + public void Pow( double exponent ) { - X = (double)Math.Pow(X, exponent); - Y = (double)Math.Pow(Y, exponent); - Z = (double)Math.Pow(Z, exponent); - W = (double)Math.Pow(W, exponent); + X = (double)Math.Pow( X, exponent ); + Y = (double)Math.Pow( Y, exponent ); + Z = (double)Math.Pow( Z, exponent ); + W = (double)Math.Pow( W, exponent ); } /// @@ -277,10 +290,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Add(ref Double4 left, ref Double4 right, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Add( ref Double4 left, ref Double4 right, out Double4 result ) { - result = new Double4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + result = new Double4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -289,10 +302,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Add(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Add( Double4 left, Double4 right ) { - return new Double4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new Double4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -301,10 +314,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Subtract(ref Double4 left, ref Double4 right, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Subtract( ref Double4 left, ref Double4 right, out Double4 result ) { - result = new Double4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + result = new Double4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -313,10 +326,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Subtract(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Subtract( Double4 left, Double4 right ) { - return new Double4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new Double4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -325,10 +338,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Multiply(ref Double4 value, double scale, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Multiply( ref Double4 value, double scale, out Double4 result ) { - result = new Double4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + result = new Double4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -337,10 +350,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Multiply(Double4 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Multiply( Double4 value, double scale ) { - return new Double4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Double4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -349,10 +362,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Modulate(ref Double4 left, ref Double4 right, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Modulate( ref Double4 left, ref Double4 right, out Double4 result ) { - result = new Double4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + result = new Double4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -361,10 +374,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Modulate(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Modulate( Double4 left, Double4 right ) { - return new Double4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + return new Double4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -373,10 +386,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Divide(ref Double4 value, double scale, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Divide( ref Double4 value, double scale, out Double4 result ) { - result = new Double4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + result = new Double4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -385,22 +398,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Divide(Double4 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Divide( Double4 value, double scale ) { - return new Double4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new Double4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } - + /// /// Demodulates a vector with another by performing component-wise division. /// /// The first vector to demodulate. /// The second vector to demodulate. /// When the method completes, contains the demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Demodulate(ref Double4 left, ref Double4 right, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Demodulate( ref Double4 left, ref Double4 right, out Double4 result ) { - result = new Double4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); + result = new Double4( left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W ); } /// @@ -409,10 +422,10 @@ namespace math /// The first vector to demodulate. /// The second vector to demodulate. /// The demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Demodulate(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Demodulate( Double4 left, Double4 right ) { - return new Double4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); + return new Double4( left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W ); } /// @@ -420,10 +433,10 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Negate(ref Double4 value, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Negate( ref Double4 value, out Double4 result ) { - result = new Double4(-value.X, -value.Y, -value.Z, -value.W); + result = new Double4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -431,10 +444,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Negate(Double4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Negate( Double4 value ) { - return new Double4(-value.X, -value.Y, -value.Z, -value.W); + return new Double4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -446,12 +459,12 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Double4 value1, ref Double4 value2, ref Double4 value3, double amount1, double amount2, out Double4 result) + public static void Barycentric( ref Double4 value1, ref Double4 value2, ref Double4 value3, double amount1, double amount2, out Double4 result ) { - result = new Double4((value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)), - (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y)), - (value1.Z + (amount1 * (value2.Z - value1.Z))) + (amount2 * (value3.Z - value1.Z)), - (value1.W + (amount1 * (value2.W - value1.W))) + (amount2 * (value3.W - value1.W))); + result = new Double4( ( value1.X + ( amount1 * ( value2.X - value1.X ) ) ) + ( amount2 * ( value3.X - value1.X ) ), + ( value1.Y + ( amount1 * ( value2.Y - value1.Y ) ) ) + ( amount2 * ( value3.Y - value1.Y ) ), + ( value1.Z + ( amount1 * ( value2.Z - value1.Z ) ) ) + ( amount2 * ( value3.Z - value1.Z ) ), + ( value1.W + ( amount1 * ( value2.W - value1.W ) ) ) + ( amount2 * ( value3.W - value1.W ) ) ); } /// @@ -463,10 +476,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 4D Cartesian coordinates of the specified point. - public static Double4 Barycentric(Double4 value1, Double4 value2, Double4 value3, double amount1, double amount2) + public static Double4 Barycentric( Double4 value1, Double4 value2, Double4 value3, double amount1, double amount2 ) { Double4 result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -477,25 +490,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Double4 value, ref Double4 min, ref Double4 max, out Double4 result) + public static void Clamp( ref Double4 value, ref Double4 min, ref Double4 max, out Double4 result ) { double x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; double y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; double z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; double w = value.W; - w = (w > max.W) ? max.W : w; - w = (w < min.W) ? min.W : w; + w = ( w > max.W ) ? max.W : w; + w = ( w < min.W ) ? min.W : w; - result = new Double4(x, y, z, w); + result = new Double4( x, y, z, w ); } /// @@ -505,10 +518,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Double4 Clamp(Double4 value, Double4 min, Double4 max) + public static Double4 Clamp( Double4 value, Double4 min, Double4 max ) { Double4 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -522,14 +535,14 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static void Distance(ref Double4 value1, ref Double4 value2, out double result) + public static void Distance( ref Double4 value1, ref Double4 value2, out double result ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; double w = value1.W - value2.W; - result = (double)Math.Sqrt((x * x) + (y * y) + (z * z) + (w * w)); + result = (double)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ) ); } /// @@ -542,14 +555,14 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static double Distance(Double4 value1, Double4 value2) + public static double Distance( Double4 value1, Double4 value2 ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; double w = value1.W - value2.W; - return (double)Math.Sqrt((x * x) + (y * y) + (z * z) + (w * w)); + return (double)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ) ); } /// @@ -558,21 +571,21 @@ namespace math /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Double4 value1, ref Double4 value2, out double result) + public static void DistanceSquared( ref Double4 value1, ref Double4 value2, out double result ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; double w = value1.W - value2.W; - result = (x * x) + (y * y) + (z * z) + (w * w); + result = ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ); } /// @@ -581,21 +594,21 @@ namespace math /// The first vector. /// The second vector. /// The squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static double DistanceSquared(Double4 value1, Double4 value2) + public static double DistanceSquared( Double4 value1, Double4 value2 ) { double x = value1.X - value2.X; double y = value1.Y - value2.Y; double z = value1.Z - value2.Z; double w = value1.W - value2.W; - return (x * x) + (y * y) + (z * z) + (w * w); + return ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ); } /// @@ -604,10 +617,10 @@ namespace math /// First source vector /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Double4 left, ref Double4 right, out double result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Dot( ref Double4 left, ref Double4 right, out double result ) { - result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W); + result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ) + ( left.W * right.W ); } /// @@ -616,10 +629,10 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static double Dot(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static double Dot( Double4 left, Double4 right ) { - return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W); + return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ) + ( left.W * right.W ); } /// @@ -627,8 +640,8 @@ namespace math /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(ref Double4 value, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Normalize( ref Double4 value, out Double4 result ) { Double4 temp = value; result = temp; @@ -640,8 +653,8 @@ namespace math /// /// The vector to normalize. /// The normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Normalize(Double4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Normalize( Double4 value ) { value.Normalize(); return value; @@ -657,14 +670,14 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Double4 start, ref Double4 end, double amount, out Double4 result) + public static void Lerp( ref Double4 start, ref Double4 end, double amount, out Double4 result ) { - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); - result.W = start.W + ((end.W - start.W) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); + result.W = start.W + ( ( end.W - start.W ) * amount ); } /// @@ -677,12 +690,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Double4 Lerp(Double4 start, Double4 end, double amount) + public static Double4 Lerp( Double4 start, Double4 end, double amount ) { Double4 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -693,15 +706,15 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Double4 start, ref Double4 end, double amount, out Double4 result) + public static void SmoothStep( ref Double4 start, ref Double4 end, double amount, out Double4 result ) { - amount = (amount > 1.0) ? 1.0 : ((amount < 0.0) ? 0.0 : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0 ) ? 1.0 : ( ( amount < 0.0 ) ? 0.0 : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); - result.W = start.W + ((end.W - start.W) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); + result.W = start.W + ( ( end.W - start.W ) * amount ); } /// @@ -711,10 +724,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Double4 SmoothStep(Double4 start, Double4 end, double amount) + public static Double4 SmoothStep( Double4 start, Double4 end, double amount ) { Double4 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -727,19 +740,19 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Double4 value1, ref Double4 tangent1, ref Double4 value2, ref Double4 tangent2, double amount, out Double4 result) + public static void Hermite( ref Double4 value1, ref Double4 tangent1, ref Double4 value2, ref Double4 tangent2, double amount, out Double4 result ) { double squared = amount * amount; double cubed = amount * squared; - double part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0; - double part2 = (-2.0f * cubed) + (3.0f * squared); - double part3 = (cubed - (2.0f * squared)) + amount; + double part1 = ( ( 2.0f * cubed ) - ( 3.0f * squared ) ) + 1.0; + double part2 = ( -2.0f * cubed ) + ( 3.0f * squared ); + double part3 = ( cubed - ( 2.0f * squared ) ) + amount; double part4 = cubed - squared; - result = new Double4((((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4), - (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4), - (((value1.Z * part1) + (value2.Z * part2)) + (tangent1.Z * part3)) + (tangent2.Z * part4), - (((value1.W * part1) + (value2.W * part2)) + (tangent1.W * part3)) + (tangent2.W * part4)); + result = new Double4( ( ( ( value1.X * part1 ) + ( value2.X * part2 ) ) + ( tangent1.X * part3 ) ) + ( tangent2.X * part4 ), + ( ( ( value1.Y * part1 ) + ( value2.Y * part2 ) ) + ( tangent1.Y * part3 ) ) + ( tangent2.Y * part4 ), + ( ( ( value1.Z * part1 ) + ( value2.Z * part2 ) ) + ( tangent1.Z * part3 ) ) + ( tangent2.Z * part4 ), + ( ( ( value1.W * part1 ) + ( value2.W * part2 ) ) + ( tangent1.W * part3 ) ) + ( tangent2.W * part4 ) ); } /// @@ -751,10 +764,10 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// The result of the Hermite spline interpolation. - public static Double4 Hermite(Double4 value1, Double4 tangent1, Double4 value2, Double4 tangent2, double amount) + public static Double4 Hermite( Double4 value1, Double4 tangent1, Double4 value2, Double4 tangent2, double amount ) { Double4 result; - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + Hermite( ref value1, ref tangent1, ref value2, ref tangent2, amount, out result ); return result; } @@ -767,15 +780,15 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Double4 value1, ref Double4 value2, ref Double4 value3, ref Double4 value4, double amount, out Double4 result) + public static void CatmullRom( ref Double4 value1, ref Double4 value2, ref Double4 value3, ref Double4 value4, double amount, out Double4 result ) { double squared = amount * amount; double cubed = amount * squared; - result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) + (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) + ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed)); - result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) + (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) + ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed)); - result.Z = 0.5f * ((((2.0f * value2.Z) + ((-value1.Z + value3.Z) * amount)) + (((((2.0f * value1.Z) - (5.0f * value2.Z)) + (4.0f * value3.Z)) - value4.Z) * squared)) + ((((-value1.Z + (3.0f * value2.Z)) - (3.0f * value3.Z)) + value4.Z) * cubed)); - result.W = 0.5f * ((((2.0f * value2.W) + ((-value1.W + value3.W) * amount)) + (((((2.0f * value1.W) - (5.0f * value2.W)) + (4.0f * value3.W)) - value4.W) * squared)) + ((((-value1.W + (3.0f * value2.W)) - (3.0f * value3.W)) + value4.W) * cubed)); + result.X = 0.5f * ( ( ( ( 2.0f * value2.X ) + ( ( -value1.X + value3.X ) * amount ) ) + ( ( ( ( ( 2.0f * value1.X ) - ( 5.0f * value2.X ) ) + ( 4.0f * value3.X ) ) - value4.X ) * squared ) ) + ( ( ( ( -value1.X + ( 3.0f * value2.X ) ) - ( 3.0f * value3.X ) ) + value4.X ) * cubed ) ); + result.Y = 0.5f * ( ( ( ( 2.0f * value2.Y ) + ( ( -value1.Y + value3.Y ) * amount ) ) + ( ( ( ( ( 2.0f * value1.Y ) - ( 5.0f * value2.Y ) ) + ( 4.0f * value3.Y ) ) - value4.Y ) * squared ) ) + ( ( ( ( -value1.Y + ( 3.0f * value2.Y ) ) - ( 3.0f * value3.Y ) ) + value4.Y ) * cubed ) ); + result.Z = 0.5f * ( ( ( ( 2.0f * value2.Z ) + ( ( -value1.Z + value3.Z ) * amount ) ) + ( ( ( ( ( 2.0f * value1.Z ) - ( 5.0f * value2.Z ) ) + ( 4.0f * value3.Z ) ) - value4.Z ) * squared ) ) + ( ( ( ( -value1.Z + ( 3.0f * value2.Z ) ) - ( 3.0f * value3.Z ) ) + value4.Z ) * cubed ) ); + result.W = 0.5f * ( ( ( ( 2.0f * value2.W ) + ( ( -value1.W + value3.W ) * amount ) ) + ( ( ( ( ( 2.0f * value1.W ) - ( 5.0f * value2.W ) ) + ( 4.0f * value3.W ) ) - value4.W ) * squared ) ) + ( ( ( ( -value1.W + ( 3.0f * value2.W ) ) - ( 3.0f * value3.W ) ) + value4.W ) * cubed ) ); } /// @@ -787,10 +800,10 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// A vector that is the result of the Catmull-Rom interpolation. - public static Double4 CatmullRom(Double4 value1, Double4 value2, Double4 value3, Double4 value4, double amount) + public static Double4 CatmullRom( Double4 value1, Double4 value2, Double4 value3, Double4 value4, double amount ) { Double4 result; - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result); + CatmullRom( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -800,13 +813,13 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Max(ref Double4 left, ref Double4 right, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Max( ref Double4 left, ref Double4 right, out Double4 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; - result.W = (left.W > right.W) ? left.W : right.W; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; + result.W = ( left.W > right.W ) ? left.W : right.W; } /// @@ -815,11 +828,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Max(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Max( Double4 left, Double4 right ) { Double4 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -829,13 +842,13 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Min(ref Double4 left, ref Double4 right, out Double4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Min( ref Double4 left, ref Double4 right, out Double4 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; - result.W = (left.W < right.W) ? left.W : right.W; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; + result.W = ( left.W < right.W ) ? left.W : right.W; } /// @@ -844,11 +857,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 Min(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 Min( Double4 left, Double4 right ) { Double4 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -868,7 +881,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthogonalize(Double4[] destination, params Double4[] source) + public static void Orthogonalize( Double4[] destination, params Double4[] source ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -877,20 +890,20 @@ namespace math //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3 //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Double4 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= (Double4.Dot(destination[r], newvector) / Double4.Dot(destination[r], destination[r])) * destination[r]; + newvector -= ( Double4.Dot( destination[r], newvector ) / Double4.Dot( destination[r], destination[r] ) ) * destination[r]; } destination[i] = newvector; @@ -913,7 +926,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthonormalize(Double4[] destination, params Double4[] source) + public static void Orthonormalize( Double4[] destination, params Double4[] source ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -924,20 +937,20 @@ namespace math //q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3| //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Double4 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= Double4.Dot(destination[r], newvector) * destination[r]; + newvector -= Double4.Dot( destination[r], newvector ) * destination[r]; } newvector.Normalize(); @@ -951,7 +964,7 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Double4 vector, ref Quaternion rotation, out Double4 result) + public static void Transform( ref Double4 vector, ref Quaternion rotation, out Double4 result ) { double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -967,10 +980,10 @@ namespace math double zz = rotation.Z * z; result = new Double4( - ((vector.X * ((1.0 - yy) - zz)) + (vector.Y * (xy - wz))) + (vector.Z * (xz + wy)), - ((vector.X * (xy + wz)) + (vector.Y * ((1.0 - xx) - zz))) + (vector.Z * (yz - wx)), - ((vector.X * (xz - wy)) + (vector.Y * (yz + wx))) + (vector.Z * ((1.0 - xx) - yy)), - vector.W); + ( ( vector.X * ( ( 1.0 - yy ) - zz ) ) + ( vector.Y * ( xy - wz ) ) ) + ( vector.Z * ( xz + wy ) ), + ( ( vector.X * ( xy + wz ) ) + ( vector.Y * ( ( 1.0 - xx ) - zz ) ) ) + ( vector.Z * ( yz - wx ) ), + ( ( vector.X * ( xz - wy ) ) + ( vector.Y * ( yz + wx ) ) ) + ( vector.Z * ( ( 1.0 - xx ) - yy ) ), + vector.W ); } /// @@ -979,10 +992,10 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// The transformed . - public static Double4 Transform(Double4 vector, Quaternion rotation) + public static Double4 Transform( Double4 vector, Quaternion rotation ) { Double4 result; - Transform(ref vector, ref rotation, out result); + Transform( ref vector, ref rotation, out result ); return result; } @@ -995,14 +1008,14 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Double4[] source, ref Quaternion rotation, Double4[] destination) + public static void Transform( Double4[] source, ref Quaternion rotation, Double4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); double x = rotation.X + rotation.X; double y = rotation.Y + rotation.Y; @@ -1017,23 +1030,23 @@ namespace math double yz = rotation.Y * z; double zz = rotation.Z * z; - double num1 = ((1.0 - yy) - zz); - double num2 = (xy - wz); - double num3 = (xz + wy); - double num4 = (xy + wz); - double num5 = ((1.0 - xx) - zz); - double num6 = (yz - wx); - double num7 = (xz - wy); - double num8 = (yz + wx); - double num9 = ((1.0 - xx) - yy); + double num1 = ( ( 1.0 - yy ) - zz ); + double num2 = ( xy - wz ); + double num3 = ( xz + wy ); + double num4 = ( xy + wz ); + double num5 = ( ( 1.0 - xx ) - zz ); + double num6 = ( yz - wx ); + double num7 = ( xz - wy ); + double num8 = ( yz + wx ); + double num9 = ( ( 1.0 - xx ) - yy ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { destination[i] = new Double4( - ((source[i].X * num1) + (source[i].Y * num2)) + (source[i].Z * num3), - ((source[i].X * num4) + (source[i].Y * num5)) + (source[i].Z * num6), - ((source[i].X * num7) + (source[i].Y * num8)) + (source[i].Z * num9), - source[i].W); + ( ( source[i].X * num1 ) + ( source[i].Y * num2 ) ) + ( source[i].Z * num3 ), + ( ( source[i].X * num4 ) + ( source[i].Y * num5 ) ) + ( source[i].Z * num6 ), + ( ( source[i].X * num7 ) + ( source[i].Y * num8 ) ) + ( source[i].Z * num9 ), + source[i].W ); } } @@ -1043,13 +1056,13 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Double4 vector, ref Matrix transform, out Double4 result) + public static void Transform( ref Double4 vector, ref Matrix transform, out Double4 result ) { result = new Double4( - (vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31) + (vector.W * transform.M41), - (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32) + (vector.W * transform.M42), - (vector.X * transform.M13) + (vector.Y * transform.M23) + (vector.Z * transform.M33) + (vector.W * transform.M43), - (vector.X * transform.M14) + (vector.Y * transform.M24) + (vector.Z * transform.M34) + (vector.W * transform.M44)); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + ( vector.Z * transform.M31 ) + ( vector.W * transform.M41 ), + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + ( vector.Z * transform.M32 ) + ( vector.W * transform.M42 ), + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + ( vector.Z * transform.M33 ) + ( vector.W * transform.M43 ), + ( vector.X * transform.M14 ) + ( vector.Y * transform.M24 ) + ( vector.Z * transform.M34 ) + ( vector.W * transform.M44 ) ); } /// @@ -1058,10 +1071,10 @@ namespace math /// The source vector. /// The transformation . /// The transformed . - public static Double4 Transform(Double4 vector, Matrix transform) + public static Double4 Transform( Double4 vector, Matrix transform ) { Double4 result; - Transform(ref vector, ref transform, out result); + Transform( ref vector, ref transform, out result ); return result; } @@ -1074,18 +1087,18 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Double4[] source, ref Matrix transform, Double4[] destination) + public static void Transform( Double4[] source, ref Matrix transform, Double4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - Transform(ref source[i], ref transform, out destination[i]); + Transform( ref source[i], ref transform, out destination[i] ); } } @@ -1095,10 +1108,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator +(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator +( Double4 left, Double4 right ) { - return new Double4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new Double4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -1106,8 +1119,8 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator +(Double4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator +( Double4 value ) { return value; } @@ -1118,10 +1131,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator -(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator -( Double4 left, Double4 right ) { - return new Double4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new Double4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -1129,10 +1142,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator -(Double4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator -( Double4 value ) { - return new Double4(-value.X, -value.Y, -value.Z, -value.W); + return new Double4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -1141,10 +1154,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator *(double scale, Double4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator *( double scale, Double4 value ) { - return new Double4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Double4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -1153,10 +1166,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator *(Double4 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator *( Double4 value, double scale ) { - return new Double4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Double4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -1165,10 +1178,10 @@ namespace math /// The first vector to multiply. /// The second vector to multiply. /// The multiplication of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator *(Double4 left, Double4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator *( Double4 left, Double4 right ) { - return new Double4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + return new Double4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -1177,10 +1190,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator /(Double4 value, double scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator /( Double4 value, double scale ) { - return new Double4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new Double4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -1189,10 +1202,10 @@ namespace math /// The numerator. /// The value. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator /(double numerator, Double4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator /( double numerator, Double4 value ) { - return new Double4(numerator / value.X, numerator / value.Y, numerator / value.Z, numerator / value.W); + return new Double4( numerator / value.X, numerator / value.Y, numerator / value.Z, numerator / value.W ); } /// @@ -1201,10 +1214,10 @@ namespace math /// The vector to scale. /// The by. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Double4 operator /(Double4 value, Double4 by) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Double4 operator /( Double4 value, Double4 by ) { - return new Double4(value.X / by.X, value.Y / by.Y, value.Z / by.Z, value.W / by.W); + return new Double4( value.X / by.X, value.Y / by.Y, value.Z / by.Z, value.W / by.W ); } /// @@ -1213,9 +1226,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Double4 left, Double4 right) + public static bool operator ==( Double4 left, Double4 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1224,9 +1237,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Double4 left, Double4 right) + public static bool operator !=( Double4 left, Double4 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1234,9 +1247,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Double4 value) + public static explicit operator Vec4( Double4 value ) { - return new Vec4((float)value.X, (float)value.Y, (float)value.Z, (float)value.W); + return new Vec4( (float)value.X, (float)value.Y, (float)value.Z, (float)value.W ); } /// @@ -1244,9 +1257,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Double4(Vec4 value) + public static implicit operator Double4( Vec4 value ) { - return new Double4(value); + return new Double4( value ); } /// @@ -1254,9 +1267,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Half4(Double4 value) + public static explicit operator Half4( Double4 value ) { - return new Half4((Half)value.X, (Half)value.Y, (Half)value.Z, (Half)value.W); + return new Half4( (Half)value.X, (Half)value.Y, (Half)value.Z, (Half)value.W ); } /// @@ -1264,9 +1277,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double4(Half4 value) + public static explicit operator Double4( Half4 value ) { - return new Double4(value.X, value.Y, value.Z, value.W); + return new Double4( value.X, value.Y, value.Z, value.W ); } /// @@ -1274,9 +1287,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double2(Double4 value) + public static explicit operator Double2( Double4 value ) { - return new Double2(value.X, value.Y); + return new Double2( value.X, value.Y ); } /// @@ -1284,9 +1297,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Double3(Double4 value) + public static explicit operator Double3( Double4 value ) { - return new Double3(value.X, value.Y, value.Z); + return new Double3( value.X, value.Y, value.Z ); } /// @@ -1297,7 +1310,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -1307,13 +1320,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(format, CultureInfo.CurrentCulture), W.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), Z.ToString( format, CultureInfo.CurrentCulture ), W.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1323,9 +1336,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -1336,20 +1349,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - ToString(formatProvider); + if( format == null ) + ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider), W.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ), W.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1363,12 +1376,12 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Double4 other) + public bool Equals( Double4 other ) { - return ((double)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (double)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance && - (double)Math.Abs(other.Z - Z) < MathUtil.ZeroTolerance && - (double)Math.Abs(other.W - W) < MathUtil.ZeroTolerance); + return ( (double)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (double)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance && + (double)Math.Abs( other.Z - Z ) < MathUtil.ZeroTolerance && + (double)Math.Abs( other.W - W ) < MathUtil.ZeroTolerance ); } /// @@ -1378,15 +1391,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Double4)value); + return Equals( (Double4)value ); } #if WPFInterop diff --git a/math/GuillotinePacker.cs b/math/GuillotinePacker.cs index 62359a6..59d76cb 100644 --- a/math/GuillotinePacker.cs +++ b/math/GuillotinePacker.cs @@ -21,7 +21,7 @@ namespace math /// /// The index of the rectangle /// The rectangle found - public delegate void InsertRectangleCallback(int cascadeIndex, ref Rectangle rectangle); + public delegate void InsertRectangleCallback( int cascadeIndex, ref Rectangle rectangle ); /// /// Current width used by the packer. @@ -38,10 +38,10 @@ namespace math /// /// The width. /// The height. - public void Clear(int width, int height) + public void Clear( int width, int height ) { freeRectangles.Clear(); - freeRectangles.Add(new Rectangle { X = 0, Y = 0, Width = width, Height = height }); + freeRectangles.Add( new Rectangle { X = 0, Y = 0, Width = width, Height = height } ); Width = width; Height = height; @@ -52,16 +52,16 @@ namespace math /// public virtual void Clear() { - Clear(Width, Height); + Clear( Width, Height ); } /// /// Frees the specified old rectangle. /// /// The old rectangle. - public void Free(ref Rectangle oldRectangle) + public void Free( ref Rectangle oldRectangle ) { - freeRectangles.Add(oldRectangle); + freeRectangles.Add( oldRectangle ); } /// @@ -71,9 +71,9 @@ namespace math /// Height requested /// Fill with the rectangle if it was successfully inserted. /// true if it was successfully inserted. - public bool Insert(int width, int height, ref Rectangle bestRectangle) + public bool Insert( int width, int height, ref Rectangle bestRectangle ) { - return Insert(width, height, freeRectangles, ref bestRectangle); + return Insert( width, height, freeRectangles, ref bestRectangle ); } /// @@ -84,48 +84,48 @@ namespace math /// The number of rectangle to fit. /// A callback called for each rectangle successfully fitted. /// true if all rectangles were successfully fitted. - public bool TryInsert(int width, int height, int count, InsertRectangleCallback inserted) + public bool TryInsert( int width, int height, int count, InsertRectangleCallback inserted ) { var bestRectangle = new Rectangle(); tempFreeRectangles.Clear(); - foreach (var freeRectangle in freeRectangles) + foreach( var freeRectangle in freeRectangles ) { - tempFreeRectangles.Add(freeRectangle); + tempFreeRectangles.Add( freeRectangle ); } - for (var i = 0; i < count; ++i) + for( var i = 0; i < count; ++i ) { - if (!Insert(width, height, tempFreeRectangles, ref bestRectangle)) + if( !Insert( width, height, tempFreeRectangles, ref bestRectangle ) ) { tempFreeRectangles.Clear(); return false; } - inserted(i, ref bestRectangle); + inserted( i, ref bestRectangle ); } // if the insertion went well, use the new configuration freeRectangles.Clear(); - foreach (var tempFreeRectangle in tempFreeRectangles) + foreach( var tempFreeRectangle in tempFreeRectangles ) { - freeRectangles.Add(tempFreeRectangle); + freeRectangles.Add( tempFreeRectangle ); } tempFreeRectangles.Clear(); return true; } - private static bool Insert(int width, int height, List freeRectanglesList, ref Rectangle bestRectangle) + private static bool Insert( int width, int height, List freeRectanglesList, ref Rectangle bestRectangle ) { // Info on algorithm: http://clb.demon.fi/files/RectangleBinPack.pdf int bestScore = int.MaxValue; int freeRectangleIndex = -1; // Find space for new rectangle - for (int i = 0; i < freeRectanglesList.Count; ++i) + for( int i = 0; i < freeRectanglesList.Count; ++i ) { var currentFreeRectangle = freeRectanglesList[i]; - if (width == currentFreeRectangle.Width && height == currentFreeRectangle.Height) + if( width == currentFreeRectangle.Width && height == currentFreeRectangle.Height ) { // Perfect fit bestRectangle.X = currentFreeRectangle.X; @@ -135,12 +135,12 @@ namespace math freeRectangleIndex = i; break; } - if (width <= currentFreeRectangle.Width && height <= currentFreeRectangle.Height) + if( width <= currentFreeRectangle.Width && height <= currentFreeRectangle.Height ) { // Can fit inside // Use "BAF" heuristic (best area fit) var score = currentFreeRectangle.Width * currentFreeRectangle.Height - width * height; - if (score < bestScore) + if( score < bestScore ) { bestRectangle.X = currentFreeRectangle.X; bestRectangle.Y = currentFreeRectangle.Y; @@ -153,7 +153,7 @@ namespace math } // No space could be found - if (freeRectangleIndex == -1) + if( freeRectangleIndex == -1 ) return false; var freeRectangle = freeRectanglesList[freeRectangleIndex]; @@ -161,21 +161,21 @@ namespace math // Choose an axis to split (trying to minimize the smaller area "MINAS") int w = freeRectangle.Width - bestRectangle.Width; int h = freeRectangle.Height - bestRectangle.Height; - var splitHorizontal = (bestRectangle.Width * h > w * bestRectangle.Height); + var splitHorizontal = ( bestRectangle.Width * h > w * bestRectangle.Height ); // Form the two new rectangles. var bottom = new Rectangle { X = freeRectangle.X, Y = freeRectangle.Y + bestRectangle.Height, Width = splitHorizontal ? freeRectangle.Width : bestRectangle.Width, Height = h }; var right = new Rectangle { X = freeRectangle.X + bestRectangle.Width, Y = freeRectangle.Y, Width = w, Height = splitHorizontal ? bestRectangle.Height : freeRectangle.Height }; - if (bottom.Width > 0 && bottom.Height > 0) - freeRectanglesList.Add(bottom); - if (right.Width > 0 && right.Height > 0) - freeRectanglesList.Add(right); + if( bottom.Width > 0 && bottom.Height > 0 ) + freeRectanglesList.Add( bottom ); + if( right.Width > 0 && right.Height > 0 ) + freeRectanglesList.Add( right ); // Remove previously selected freeRectangle - if (freeRectangleIndex != freeRectanglesList.Count - 1) + if( freeRectangleIndex != freeRectanglesList.Count - 1 ) freeRectanglesList[freeRectangleIndex] = freeRectanglesList[freeRectanglesList.Count - 1]; - freeRectanglesList.RemoveAt(freeRectanglesList.Count - 1); + freeRectanglesList.RemoveAt( freeRectanglesList.Count - 1 ); return true; } diff --git a/math/Half.cs b/math/Half.cs index fd46fdc..5791e0b 100644 --- a/math/Half.cs +++ b/math/Half.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -33,7 +33,7 @@ namespace math /// A half precision (16 bit) floating point value. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 2)] + [StructLayout( LayoutKind.Sequential, Pack = 2 )] public struct Half { private ushort value; @@ -107,9 +107,9 @@ namespace math /// Initializes a new instance of the structure. /// /// The floating point value that should be stored in 16 bit format. - public Half(float value) + public Half( float value ) { - this.value = HalfUtils.Pack(value); + this.value = HalfUtils.Pack( value ); } /// @@ -126,11 +126,11 @@ namespace math /// /// The values to be converted. /// An array of converted values. - public static float[] ConvertToFloat(Half[] values) - { + public static float[] ConvertToFloat( Half[] values ) + { float[] results = new float[values.Length]; - for (int i = 0; i < results.Length; i++) - results[i] = HalfUtils.Unpack(values[i].RawValue); + for( int i = 0; i < results.Length; i++ ) + results[i] = HalfUtils.Unpack( values[i].RawValue ); return results; } @@ -139,11 +139,11 @@ namespace math /// /// The values to be converted. /// An array of converted values. - public static Half[] ConvertToHalf(float[] values) + public static Half[] ConvertToHalf( float[] values ) { Half[] results = new Half[values.Length]; - for (int i = 0; i < results.Length; i++) - results[i] = new Half(values[i]); + for( int i = 0; i < results.Length; i++ ) + results[i] = new Half( values[i] ); return results; } @@ -152,9 +152,9 @@ namespace math /// /// The value to be converted. /// The converted value. - public static explicit operator Half(float value) + public static explicit operator Half( float value ) { - return new Half(value); + return new Half( value ); } /// @@ -162,9 +162,9 @@ namespace math /// /// The value to be converted. /// The converted value. - public static implicit operator float(Half value) + public static implicit operator float( Half value ) { - return HalfUtils.Unpack(value.value); + return HalfUtils.Unpack( value.value ); } /// @@ -174,7 +174,7 @@ namespace math /// The second value to compare. /// /// true if has the same value as ; otherwise, false. - public static bool operator ==(Half left, Half right) + public static bool operator ==( Half left, Half right ) { return left.value == right.value; } @@ -186,7 +186,7 @@ namespace math /// The second value to compare. /// /// true if has a different value than ; otherwise, false. - public static bool operator !=(Half left, Half right) + public static bool operator !=( Half left, Half right ) { return left.value != right.value; } @@ -198,7 +198,7 @@ namespace math public override string ToString() { float num = this; - return num.ToString(CultureInfo.CurrentCulture); + return num.ToString( CultureInfo.CurrentCulture ); } /// @@ -208,7 +208,7 @@ namespace math public override int GetHashCode() { ushort num = value; - return ((num * 3) / 2) ^ num; + return ( ( num * 3 ) / 2 ) ^ num; } /// @@ -217,9 +217,9 @@ namespace math /// The first value. /// The second value. /// - /// true if is the same instance as or + /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half value1, ref Half value2) + public static bool Equals( ref Half value1, ref Half value2 ) { return value1.value == value2.value; } @@ -230,7 +230,7 @@ namespace math /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public bool Equals(Half other) + public bool Equals( Half other ) { return other.value == value; } @@ -241,13 +241,13 @@ namespace math /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (obj == null) + if( obj == null ) { return false; } - if (obj.GetType() != GetType()) + if( obj.GetType() != GetType() ) { return false; } diff --git a/math/Half2.cs b/math/Half2.cs index b25015f..154a0fe 100644 --- a/math/Half2.cs +++ b/math/Half2.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -32,7 +32,7 @@ namespace math /// Represents a two dimensional mathematical vector with half-precision floats. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 2)] + [StructLayout( LayoutKind.Sequential, Pack = 2 )] public struct Half2 : IEquatable { /// @@ -52,7 +52,7 @@ namespace math /// /// The X component. /// The Y component. - public Half2(Half x, Half y) + public Half2( Half x, Half y ) { this.X = x; this.Y = y; @@ -62,7 +62,7 @@ namespace math /// Initializes a new instance of the structure. /// /// The value to set for both the X and Y components. - public Half2(Half value) + public Half2( Half value ) { this.X = value; this.Y = value; @@ -73,7 +73,7 @@ namespace math /// /// The X component. /// The Y component. - public Half2(float x, float y) + public Half2( float x, float y ) { this.X = (Half)x; this.Y = (Half)y; @@ -83,7 +83,7 @@ namespace math /// Initializes a new instance of the structure. /// /// The value to set for both the X and Y components. - public Half2(float value) + public Half2( float value ) { this.X = (Half)value; this.Y = (Half)value; @@ -96,9 +96,9 @@ namespace math /// The second value to compare. /// /// true if has the same value as ; otherwise, false. - public static bool operator ==(Half2 left, Half2 right) + public static bool operator ==( Half2 left, Half2 right ) { - return Equals(ref left, ref right); + return Equals( ref left, ref right ); } /// @@ -108,10 +108,10 @@ namespace math /// The second value to compare. /// /// true if has a different value than ; otherwise, false. - [return: MarshalAs(UnmanagedType.U1)] - public static bool operator !=(Half2 left, Half2 right) + [return: MarshalAs( UnmanagedType.U1 )] + public static bool operator !=( Half2 left, Half2 right ) { - return !Equals(ref left, ref right); + return !Equals( ref left, ref right ); } /// @@ -120,50 +120,50 @@ namespace math /// A 32-bit signed integer hash code. public override int GetHashCode() { - return (this.Y.GetHashCode() + this.X.GetHashCode()); + return ( this.Y.GetHashCode() + this.X.GetHashCode() ); } /// - /// Determines whether the specified object instances are considered equal. + /// Determines whether the specified object instances are considered equal. /// /// The first value. /// The second value. /// - /// true if is the same instance as or + /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half2 value1, ref Half2 value2) + public static bool Equals( ref Half2 value1, ref Half2 value2 ) { - return ((value1.X == value2.X) && (value1.Y == value2.Y)); + return ( ( value1.X == value2.X ) && ( value1.Y == value2.Y ) ); } /// - /// Returns a value that indicates whether the current instance is equal to the specified object. + /// Returns a value that indicates whether the current instance is equal to the specified object. /// /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public bool Equals(Half2 other) + public bool Equals( Half2 other ) { - return ((this.X == other.X) && (this.Y == other.Y)); + return ( ( this.X == other.X ) && ( this.Y == other.Y ) ); } /// - /// Returns a value that indicates whether the current instance is equal to a specified object. + /// Returns a value that indicates whether the current instance is equal to a specified object. /// /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (obj == null) + if( obj == null ) { return false; } - if (obj.GetType() != GetType()) + if( obj.GetType() != GetType() ) { return false; } - return this.Equals((Half2)obj); + return this.Equals( (Half2)obj ); } /// @@ -171,9 +171,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Half2(Vec2 value) + public static explicit operator Half2( Vec2 value ) { - return new Half2((Half)value.X, (Half)value.Y); + return new Half2( (Half)value.X, (Half)value.Y ); } /// @@ -181,9 +181,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Half2 value) + public static explicit operator Vec2( Half2 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } } } diff --git a/math/Half3.cs b/math/Half3.cs index 72cc68c..8966a45 100644 --- a/math/Half3.cs +++ b/math/Half3.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -32,7 +32,7 @@ namespace math /// Represents a three dimensional mathematical vector with half-precision floats. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 2)] + [StructLayout( LayoutKind.Sequential, Pack = 2 )] public struct Half3 : IEquatable { /// @@ -59,7 +59,7 @@ namespace math /// The X component. /// The Y component. /// The Z component. - public Half3(Half x, Half y, Half z) + public Half3( Half x, Half y, Half z ) { this.X = x; this.Y = y; @@ -70,7 +70,7 @@ namespace math /// Initializes a new instance of the structure. /// /// The value to set for the X, Y, and Z components. - public Half3(Half value) + public Half3( Half value ) { this.X = value; this.Y = value; @@ -83,7 +83,7 @@ namespace math /// The X component. /// The Y component. /// The Z component. - public Half3(float x, float y, float z) + public Half3( float x, float y, float z ) { this.X = (Half)x; this.Y = (Half)y; @@ -94,7 +94,7 @@ namespace math /// Initializes a new instance of the structure. /// /// The value to set for the X, Y, and Z components. - public Half3(float value) + public Half3( float value ) { this.X = (Half)value; this.Y = (Half)value; @@ -108,9 +108,9 @@ namespace math /// The second value to compare. /// /// true if has the same value as ; otherwise, false. - public static bool operator ==(Half3 left, Half3 right) + public static bool operator ==( Half3 left, Half3 right ) { - return Equals(ref left, ref right); + return Equals( ref left, ref right ); } /// @@ -120,10 +120,10 @@ namespace math /// The second value to compare. /// /// true if has a different value than ; otherwise, false. - [return: MarshalAs(UnmanagedType.U1)] - public static bool operator !=(Half3 left, Half3 right) + [return: MarshalAs( UnmanagedType.U1 )] + public static bool operator !=( Half3 left, Half3 right ) { - return !Equals(ref left, ref right); + return !Equals( ref left, ref right ); } /// @@ -133,31 +133,31 @@ namespace math public override int GetHashCode() { int num = this.Z.GetHashCode() + this.Y.GetHashCode(); - return (this.X.GetHashCode() + num); + return ( this.X.GetHashCode() + num ); } /// - /// Determines whether the specified object instances are considered equal. + /// Determines whether the specified object instances are considered equal. /// /// The first value. /// The second value. /// - /// true if is the same instance as or + /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half3 value1, ref Half3 value2) + public static bool Equals( ref Half3 value1, ref Half3 value2 ) { - return (((value1.X == value2.X) && (value1.Y == value2.Y)) && (value1.Z == value2.Z)); + return ( ( ( value1.X == value2.X ) && ( value1.Y == value2.Y ) ) && ( value1.Z == value2.Z ) ); } /// - /// Returns a value that indicates whether the current instance is equal to the specified object. + /// Returns a value that indicates whether the current instance is equal to the specified object. /// /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public bool Equals(Half3 other) + public bool Equals( Half3 other ) { - return (((this.X == other.X) && (this.Y == other.Y)) && (this.Z == other.Z)); + return ( ( ( this.X == other.X ) && ( this.Y == other.Y ) ) && ( this.Z == other.Z ) ); } /// @@ -165,9 +165,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Half3(Vec3 value) + public static explicit operator Half3( Vec3 value ) { - return new Half3((Half)value.X, (Half)value.Y, (Half)value.Z); + return new Half3( (Half)value.X, (Half)value.Y, (Half)value.Z ); } /// @@ -175,28 +175,28 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Half3 value) + public static explicit operator Vec3( Half3 value ) { - return new Vec3(value.X, value.Y, value.Z); + return new Vec3( value.X, value.Y, value.Z ); } /// - /// Returns a value that indicates whether the current instance is equal to a specified object. + /// Returns a value that indicates whether the current instance is equal to a specified object. /// /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (obj == null) + if( obj == null ) { return false; } - if (obj.GetType() != GetType()) + if( obj.GetType() != GetType() ) { return false; } - return this.Equals((Half3)obj); + return this.Equals( (Half3)obj ); } } } diff --git a/math/Half4.cs b/math/Half4.cs index 165dc96..b4a97bc 100644 --- a/math/Half4.cs +++ b/math/Half4.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -33,7 +33,7 @@ namespace math /// Represents a four dimensional mathematical vector with half-precision floats. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 2)] + [StructLayout( LayoutKind.Sequential, Pack = 2 )] public struct Half4 : IEquatable { /// @@ -67,7 +67,7 @@ namespace math /// The Y component. /// The Z component. /// The W component. - public Half4(Half x, Half y, Half z, Half w) + public Half4( Half x, Half y, Half z, Half w ) { this.X = x; this.Y = y; @@ -79,7 +79,7 @@ namespace math /// Initializes a new instance of the structure. /// /// The value to set for the X, Y, Z, and W components. - public Half4(Half value) + public Half4( Half value ) { this.X = value; this.Y = value; @@ -94,9 +94,9 @@ namespace math /// The second value to compare. /// /// true if has the same value as ; otherwise, false. - public static bool operator ==(Half4 left, Half4 right) + public static bool operator ==( Half4 left, Half4 right ) { - return Equals(ref left, ref right); + return Equals( ref left, ref right ); } /// @@ -106,9 +106,9 @@ namespace math /// The second value to compare. /// /// true if has a different value than ; otherwise, false. - public static bool operator !=(Half4 left, Half4 right) + public static bool operator !=( Half4 left, Half4 right ) { - return !Equals(ref left, ref right); + return !Equals( ref left, ref right ); } /// @@ -119,31 +119,31 @@ namespace math { int num2 = this.W.GetHashCode() + this.Z.GetHashCode(); int num = this.Y.GetHashCode() + num2; - return (this.X.GetHashCode() + num); + return ( this.X.GetHashCode() + num ); } /// - /// Determines whether the specified object instances are considered equal. + /// Determines whether the specified object instances are considered equal. /// /// The first value. /// The second value. /// - /// true if is the same instance as or + /// true if is the same instance as or /// if both are null references or if value1.Equals(value2) returns true; otherwise, false. - public static bool Equals(ref Half4 value1, ref Half4 value2) + public static bool Equals( ref Half4 value1, ref Half4 value2 ) { - return (((value1.X == value2.X) && (value1.Y == value2.Y)) && ((value1.Z == value2.Z) && (value1.W == value2.W))); + return ( ( ( value1.X == value2.X ) && ( value1.Y == value2.Y ) ) && ( ( value1.Z == value2.Z ) && ( value1.W == value2.W ) ) ); } /// - /// Returns a value that indicates whether the current instance is equal to the specified object. + /// Returns a value that indicates whether the current instance is equal to the specified object. /// /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public bool Equals(Half4 other) + public bool Equals( Half4 other ) { - return (((this.X == other.X) && (this.Y == other.Y)) && ((this.Z == other.Z) && (this.W == other.W))); + return ( ( ( this.X == other.X ) && ( this.Y == other.Y ) ) && ( ( this.Z == other.Z ) && ( this.W == other.W ) ) ); } /// @@ -151,9 +151,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Half4(Vec4 value) + public static explicit operator Half4( Vec4 value ) { - return new Half4((Half)value.X, (Half)value.Y, (Half)value.Z, (Half)value.W); + return new Half4( (Half)value.X, (Half)value.Y, (Half)value.Z, (Half)value.W ); } /// @@ -161,28 +161,28 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Half4 value) + public static explicit operator Vec4( Half4 value ) { - return new Vec4(value.X, value.Y, value.Z, value.W); + return new Vec4( value.X, value.Y, value.Z, value.W ); } /// - /// Returns a value that indicates whether the current instance is equal to a specified object. + /// Returns a value that indicates whether the current instance is equal to a specified object. /// /// Object to make the comparison with. /// /// true if the current instance is equal to the specified object; false otherwise. - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (obj == null) + if( obj == null ) { return false; } - if (obj.GetType() != GetType()) + if( obj.GetType() != GetType() ) { return false; } - return this.Equals((Half4)obj); + return this.Equals( (Half4)obj ); } } } diff --git a/math/HalfUtils.cs b/math/HalfUtils.cs index 75496f3..5f9e198 100644 --- a/math/HalfUtils.cs +++ b/math/HalfUtils.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -31,12 +31,12 @@ namespace math /// internal class HalfUtils { - [StructLayout(LayoutKind.Explicit, Pack = 4)] + [StructLayout( LayoutKind.Explicit, Pack = 4 )] private struct FloatToUint { - [FieldOffset(0)] + [FieldOffset( 0 )] public uint UIntValue; - [FieldOffset(0)] + [FieldOffset( 0 )] public float FloatValue; } @@ -45,10 +45,10 @@ namespace math /// /// The packed value. /// The float representation of the packed value. - public static float Unpack(ushort h) + public static float Unpack( ushort h ) { var conv = new FloatToUint(); - conv.UIntValue = HalfToFloatMantissaTable[HalfToFloatOffsetTable[h >> 10] + (((uint)h) & 0x3ff)] + HalfToFloatExponentTable[h >> 10]; + conv.UIntValue = HalfToFloatMantissaTable[HalfToFloatOffsetTable[h >> 10] + ( ( (uint)h ) & 0x3ff )] + HalfToFloatExponentTable[h >> 10]; return conv.FloatValue; } @@ -57,11 +57,11 @@ namespace math /// /// The float value. /// The packed representation of the float value. - public static ushort Pack(float f) + public static ushort Pack( float f ) { FloatToUint conv = new FloatToUint(); conv.FloatValue = f; - return (ushort)(FloatToHalfBaseTable[(conv.UIntValue >> 23) & 0x1ff] + ((conv.UIntValue & 0x007fffff) >> FloatToHalfShiftTable[(conv.UIntValue >> 23) & 0x1ff])); + return (ushort)( FloatToHalfBaseTable[( conv.UIntValue >> 23 ) & 0x1ff] + ( ( conv.UIntValue & 0x007fffff ) >> FloatToHalfShiftTable[( conv.UIntValue >> 23 ) & 0x1ff] ) ); } private static readonly uint[] HalfToFloatMantissaTable = new uint[2048]; @@ -84,12 +84,12 @@ namespace math HalfToFloatMantissaTable[0] = 0; // Transform subnormal to normalized - for (i = 1; i < 1024; i++) + for( i = 1; i < 1024; i++ ) { - uint m = ((uint)i) << 13; + uint m = ( (uint)i ) << 13; uint e = 0; - while ((m & 0x00800000) == 0) + while( ( m & 0x00800000 ) == 0 ) { e -= 0x00800000; m <<= 1; @@ -100,20 +100,20 @@ namespace math } // Normal case - for (i = 1024; i < 2048; i++) - HalfToFloatMantissaTable[i] = 0x38000000 + (((uint)(i - 1024)) << 13); + for( i = 1024; i < 2048; i++ ) + HalfToFloatMantissaTable[i] = 0x38000000 + ( ( (uint)( i - 1024 ) ) << 13 ); // Exponent table // 0 => 0 HalfToFloatExponentTable[0] = 0; - for (i = 1; i < 63; i++) + for( i = 1; i < 63; i++ ) { - if (i < 31) // Positive Numbers - HalfToFloatExponentTable[i] = ((uint)i) << 23; + if( i < 31 ) // Positive Numbers + HalfToFloatExponentTable[i] = ( (uint)i ) << 23; else // Negative Numbers - HalfToFloatExponentTable[i] = 0x80000000 + (((uint)(i - 32)) << 23); + HalfToFloatExponentTable[i] = 0x80000000 + ( ( (uint)( i - 32 ) ) << 23 ); } HalfToFloatExponentTable[31] = 0x47800000; HalfToFloatExponentTable[32] = 0x80000000; @@ -121,39 +121,39 @@ namespace math // Offset table HalfToFloatOffsetTable[0] = 0; - for (i = 1; i < 64; i++) + for( i = 1; i < 64; i++ ) HalfToFloatOffsetTable[i] = 1024; HalfToFloatOffsetTable[32] = 0; // ------------------------------------------------------------------- // Float to Half tables // ------------------------------------------------------------------- - - for (i = 0; i < 256; i++) + + for( i = 0; i < 256; i++ ) { int e = i - 127; - if (e < -24) + if( e < -24 ) { // Very small numbers map to zero FloatToHalfBaseTable[i | 0x000] = 0x0000; FloatToHalfBaseTable[i | 0x100] = 0x8000; FloatToHalfShiftTable[i | 0x000] = 24; FloatToHalfShiftTable[i | 0x100] = 24; } - else if (e < -14) + else if( e < -14 ) { // Small numbers map to denorms - FloatToHalfBaseTable[i | 0x000] = (ushort)((0x0400 >> (-e - 14))); - FloatToHalfBaseTable[i | 0x100] = (ushort)((0x0400 >> (-e - 14)) | 0x8000); - FloatToHalfShiftTable[i | 0x000] = (byte)(-e - 1); - FloatToHalfShiftTable[i | 0x100] = (byte)(-e - 1); + FloatToHalfBaseTable[i | 0x000] = (ushort)( ( 0x0400 >> ( -e - 14 ) ) ); + FloatToHalfBaseTable[i | 0x100] = (ushort)( ( 0x0400 >> ( -e - 14 ) ) | 0x8000 ); + FloatToHalfShiftTable[i | 0x000] = (byte)( -e - 1 ); + FloatToHalfShiftTable[i | 0x100] = (byte)( -e - 1 ); } - else if (e <= 15) + else if( e <= 15 ) { // Normal numbers just lose precision - FloatToHalfBaseTable[i | 0x000] = (ushort)(((e + 15) << 10)); - FloatToHalfBaseTable[i | 0x100] = (ushort)(((e + 15) << 10) | 0x8000); + FloatToHalfBaseTable[i | 0x000] = (ushort)( ( ( e + 15 ) << 10 ) ); + FloatToHalfBaseTable[i | 0x100] = (ushort)( ( ( e + 15 ) << 10 ) | 0x8000 ); FloatToHalfShiftTable[i | 0x000] = 13; FloatToHalfShiftTable[i | 0x100] = 13; } - else if (e < 128) + else if( e < 128 ) { // Large numbers map to Infinity FloatToHalfBaseTable[i | 0x000] = 0x7C00; FloatToHalfBaseTable[i | 0x100] = 0xFC00; diff --git a/math/Int2.cs b/math/Int2.cs index 533ad6e..fbc9613 100644 --- a/math/Int2.cs +++ b/math/Int2.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -36,9 +36,9 @@ namespace math /// /// Represents a three dimensional mathematical vector. /// - [DataContract( Name = "Int2")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Int2" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Int2 : IEquatable, IFormattable { /// @@ -54,17 +54,17 @@ namespace math /// /// The X unit (1, 0, 0). /// - public static readonly Int2 UnitX = new Int2(1, 0); + public static readonly Int2 UnitX = new Int2( 1, 0 ); /// /// The Y unit (0, 1, 0). /// - public static readonly Int2 UnitY = new Int2(0, 1); + public static readonly Int2 UnitY = new Int2( 0, 1 ); /// /// A with all of its components set to one. /// - public static readonly Int2 One = new Int2(1, 1); + public static readonly Int2 One = new Int2( 1, 1 ); /// /// The X component of the vector. @@ -82,7 +82,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Int2(int value) + public Int2( int value ) { X = value; Y = value; @@ -93,7 +93,7 @@ namespace math /// /// Initial value for the X component of the vector. /// Initial value for the Y component of the vector. - public Int2(int x, int y) + public Int2( int x, int y ) { X = x; Y = y; @@ -103,7 +103,7 @@ namespace math /// Initializes a new instance of the struct. /// /// A vector containing the values with which to initialize the X and Y components. - public Int2(Vec2 value) + public Int2( Vec2 value ) { X = (int)value.X; Y = (int)value.Y; @@ -115,12 +115,12 @@ namespace math /// The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements. /// Thrown when is null. /// Thrown when contains more or less than three elements. - public Int2(int[] values) + public Int2( int[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 2) - throw new ArgumentOutOfRangeException("values", "There must be two and only two input values for Int2."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 2 ) + throw new ArgumentOutOfRangeException( "values", "There must be two and only two input values for Int2." ); X = values[0]; Y = values[1]; @@ -137,22 +137,29 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; + case 0: + return X; + case 1: + return Y; } - throw new ArgumentOutOfRangeException("index", "Indices for Int2 run from 0 to 1, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Int2 run from 0 to 1, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Int2 run from 0 to 1, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Int2 run from 0 to 1, inclusive." ); } } } @@ -167,7 +174,7 @@ namespace math /// public int Length() { - return (int)Math.Sqrt((X * X) + (Y * Y)); + return (int)Math.Sqrt( ( X * X ) + ( Y * Y ) ); } /// @@ -180,17 +187,17 @@ namespace math /// public int LengthSquared() { - return (X * X) + (Y * Y); + return ( X * X ) + ( Y * Y ); } /// /// Raises the exponent for each components. /// /// The exponent. - public void Pow(int exponent) + public void Pow( int exponent ) { - X = (int)Math.Pow(X, exponent); - Y = (int)Math.Pow(Y, exponent); + X = (int)Math.Pow( X, exponent ); + Y = (int)Math.Pow( Y, exponent ); } /// @@ -208,9 +215,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Int2 left, ref Int2 right, out Int2 result) + public static void Add( ref Int2 left, ref Int2 right, out Int2 result ) { - result = new Int2(left.X + right.X, left.Y + right.Y); + result = new Int2( left.X + right.X, left.Y + right.Y ); } /// @@ -219,9 +226,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static Int2 Add(Int2 left, Int2 right) + public static Int2 Add( Int2 left, Int2 right ) { - return new Int2(left.X + right.X, left.Y + right.Y); + return new Int2( left.X + right.X, left.Y + right.Y ); } /// @@ -230,9 +237,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Int2 left, ref Int2 right, out Int2 result) + public static void Subtract( ref Int2 left, ref Int2 right, out Int2 result ) { - result = new Int2(left.X - right.X, left.Y - right.Y); + result = new Int2( left.X - right.X, left.Y - right.Y ); } /// @@ -241,9 +248,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static Int2 Subtract(Int2 left, Int2 right) + public static Int2 Subtract( Int2 left, Int2 right ) { - return new Int2(left.X - right.X, left.Y - right.Y); + return new Int2( left.X - right.X, left.Y - right.Y ); } /// @@ -252,9 +259,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Int2 value, int scale, out Int2 result) + public static void Multiply( ref Int2 value, int scale, out Int2 result ) { - result = new Int2(value.X * scale, value.Y * scale); + result = new Int2( value.X * scale, value.Y * scale ); } /// @@ -263,9 +270,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int2 Multiply(Int2 value, int scale) + public static Int2 Multiply( Int2 value, int scale ) { - return new Int2(value.X * scale, value.Y * scale); + return new Int2( value.X * scale, value.Y * scale ); } /// @@ -274,9 +281,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - public static void Modulate(ref Int2 left, ref Int2 right, out Int2 result) + public static void Modulate( ref Int2 left, ref Int2 right, out Int2 result ) { - result = new Int2(left.X * right.X, left.Y * right.Y); + result = new Int2( left.X * right.X, left.Y * right.Y ); } /// @@ -285,9 +292,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - public static Int2 Modulate(Int2 left, Int2 right) + public static Int2 Modulate( Int2 left, Int2 right ) { - return new Int2(left.X * right.X, left.Y * right.Y); + return new Int2( left.X * right.X, left.Y * right.Y ); } /// @@ -296,9 +303,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Int2 value, int scale, out Int2 result) + public static void Divide( ref Int2 value, int scale, out Int2 result ) { - result = new Int2(value.X / scale, value.Y / scale); + result = new Int2( value.X / scale, value.Y / scale ); } /// @@ -307,9 +314,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int2 Divide(Int2 value, int scale) + public static Int2 Divide( Int2 value, int scale ) { - return new Int2(value.X / scale, value.Y / scale); + return new Int2( value.X / scale, value.Y / scale ); } /// @@ -317,9 +324,9 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Int2 value, out Int2 result) + public static void Negate( ref Int2 value, out Int2 result ) { - result = new Int2(-value.X, -value.Y); + result = new Int2( -value.X, -value.Y ); } /// @@ -327,9 +334,9 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - public static Int2 Negate(Int2 value) + public static Int2 Negate( Int2 value ) { - return new Int2(-value.X, -value.Y); + return new Int2( -value.X, -value.Y ); } /// @@ -339,17 +346,17 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Int2 value, ref Int2 min, ref Int2 max, out Int2 result) + public static void Clamp( ref Int2 value, ref Int2 min, ref Int2 max, out Int2 result ) { int x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; int y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; - result = new Int2(x, y); + result = new Int2( x, y ); } /// @@ -359,10 +366,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Int2 Clamp(Int2 value, Int2 min, Int2 max) + public static Int2 Clamp( Int2 value, Int2 min, Int2 max ) { Int2 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -372,9 +379,9 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Int2 left, ref Int2 right, out int result) + public static void Dot( ref Int2 left, ref Int2 right, out int result ) { - result = (left.X * right.X) + (left.Y * right.Y); + result = ( left.X * right.X ) + ( left.Y * right.Y ); } /// @@ -383,9 +390,9 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static int Dot(Int2 left, Int2 right) + public static int Dot( Int2 left, Int2 right ) { - return (left.X * right.X) + (left.Y * right.Y); + return ( left.X * right.X ) + ( left.Y * right.Y ); } /// @@ -398,12 +405,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Int2 start, ref Int2 end, float amount, out Int2 result) + public static void Lerp( ref Int2 start, ref Int2 end, float amount, out Int2 result ) { - result.X = (int)(start.X + ((end.X - start.X) * amount)); - result.Y = (int)(start.Y + ((end.Y - start.Y) * amount)); + result.X = (int)( start.X + ( ( end.X - start.X ) * amount ) ); + result.Y = (int)( start.Y + ( ( end.Y - start.Y ) * amount ) ); } /// @@ -416,12 +423,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Int2 Lerp(Int2 start, Int2 end, float amount) + public static Int2 Lerp( Int2 start, Int2 end, float amount ) { Int2 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -432,13 +439,13 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Int2 start, ref Int2 end, float amount, out Int2 result) + public static void SmoothStep( ref Int2 start, ref Int2 end, float amount, out Int2 result ) { - amount = (amount > 1) ? 1 : ((amount < 0) ? 0 : amount); - amount = (amount * amount) * (3 - (2 * amount)); + amount = ( amount > 1 ) ? 1 : ( ( amount < 0 ) ? 0 : amount ); + amount = ( amount * amount ) * ( 3 - ( 2 * amount ) ); - result.X = (int)(start.X + ((end.X - start.X) * amount)); - result.Y = (int)(start.Y + ((end.Y - start.Y) * amount)); + result.X = (int)( start.X + ( ( end.X - start.X ) * amount ) ); + result.Y = (int)( start.Y + ( ( end.Y - start.Y ) * amount ) ); } /// @@ -448,10 +455,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Int2 SmoothStep(Int2 start, Int2 end, float amount) + public static Int2 SmoothStep( Int2 start, Int2 end, float amount ) { Int2 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -461,10 +468,10 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Int2 left, ref Int2 right, out Int2 result) + public static void Max( ref Int2 left, ref Int2 right, out Int2 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; } /// @@ -473,10 +480,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - public static Int2 Max(Int2 left, Int2 right) + public static Int2 Max( Int2 left, Int2 right ) { Int2 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -486,10 +493,10 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Int2 left, ref Int2 right, out Int2 result) + public static void Min( ref Int2 left, ref Int2 right, out Int2 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; } /// @@ -498,10 +505,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - public static Int2 Min(Int2 left, Int2 right) + public static Int2 Min( Int2 left, Int2 right ) { Int2 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -511,9 +518,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static Int2 operator +(Int2 left, Int2 right) + public static Int2 operator +( Int2 left, Int2 right ) { - return new Int2(left.X + right.X, left.Y + right.Y); + return new Int2( left.X + right.X, left.Y + right.Y ); } /// @@ -521,7 +528,7 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - public static Int2 operator +(Int2 value) + public static Int2 operator +( Int2 value ) { return value; } @@ -532,9 +539,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static Int2 operator -(Int2 left, Int2 right) + public static Int2 operator -( Int2 left, Int2 right ) { - return new Int2(left.X - right.X, left.Y - right.Y); + return new Int2( left.X - right.X, left.Y - right.Y ); } /// @@ -542,9 +549,9 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - public static Int2 operator -(Int2 value) + public static Int2 operator -( Int2 value ) { - return new Int2(-value.X, -value.Y); + return new Int2( -value.X, -value.Y ); } /// @@ -553,9 +560,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int2 operator *(float scale, Int2 value) + public static Int2 operator *( float scale, Int2 value ) { - return new Int2((int)(value.X * scale), (int)(value.Y * scale)); + return new Int2( (int)( value.X * scale ), (int)( value.Y * scale ) ); } /// @@ -564,9 +571,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int2 operator *(Int2 value, float scale) + public static Int2 operator *( Int2 value, float scale ) { - return new Int2((int)(value.X * scale), (int)(value.Y * scale)); + return new Int2( (int)( value.X * scale ), (int)( value.Y * scale ) ); } /// @@ -575,9 +582,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int2 operator /(Int2 value, float scale) + public static Int2 operator /( Int2 value, float scale ) { - return new Int2((int)(value.X / scale), (int)(value.Y / scale)); + return new Int2( (int)( value.X / scale ), (int)( value.Y / scale ) ); } /// @@ -586,9 +593,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Int2 left, Int2 right) + public static bool operator ==( Int2 left, Int2 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -597,9 +604,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Int2 left, Int2 right) + public static bool operator !=( Int2 left, Int2 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -607,9 +614,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Int2 value) + public static explicit operator Vec2( Int2 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } /// @@ -617,9 +624,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Int2 value) + public static explicit operator Vec4( Int2 value ) { - return new Vec4(value.X, value.Y, 0, 0); + return new Vec4( value.X, value.Y, 0, 0 ); } /// @@ -630,7 +637,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y ); } /// @@ -640,12 +647,12 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString(format, CultureInfo.CurrentCulture), Y.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString( format, CultureInfo.CurrentCulture ), Y.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -655,9 +662,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1}", X, Y); + return string.Format( formatProvider, "X:{0} Y:{1}", X, Y ); } /// @@ -668,19 +675,19 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1}", X.ToString(format, formatProvider), Y.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1}", X.ToString( format, formatProvider ), Y.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -694,10 +701,10 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Int2 other) + public bool Equals( Int2 other ) { - return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance); + return ( (float)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance ); } /// @@ -707,15 +714,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Int2)value); + return Equals( (Int2)value ); } #if WPFInterop /// diff --git a/math/Int3.cs b/math/Int3.cs index 12d54cf..8ce2ac4 100644 --- a/math/Int3.cs +++ b/math/Int3.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -36,9 +36,9 @@ namespace math /// /// Represents a three dimensional mathematical vector. /// - [DataContract( Name = "Int3")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Int3" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Int3 : IEquatable, IFormattable { /// @@ -54,22 +54,22 @@ namespace math /// /// The X unit (1, 0, 0). /// - public static readonly Int3 UnitX = new Int3(1, 0, 0); + public static readonly Int3 UnitX = new Int3( 1, 0, 0 ); /// /// The Y unit (0, 1, 0). /// - public static readonly Int3 UnitY = new Int3(0, 1, 0); + public static readonly Int3 UnitY = new Int3( 0, 1, 0 ); /// /// The Z unit (0, 0, 1). /// - public static readonly Int3 UnitZ = new Int3(0, 0, 1); + public static readonly Int3 UnitZ = new Int3( 0, 0, 1 ); /// /// A with all of its components set to one. /// - public static readonly Int3 One = new Int3(1, 1, 1); + public static readonly Int3 One = new Int3( 1, 1, 1 ); /// /// The X component of the vector. @@ -93,7 +93,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Int3(int value) + public Int3( int value ) { X = value; Y = value; @@ -106,7 +106,7 @@ namespace math /// Initial value for the X component of the vector. /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. - public Int3(int x, int y, int z) + public Int3( int x, int y, int z ) { X = x; Y = y; @@ -118,7 +118,7 @@ namespace math /// /// A vector containing the values with which to initialize the X and Y components. /// Initial value for the Z component of the vector. - public Int3(Vec2 value, int z) + public Int3( Vec2 value, int z ) { X = (int)value.X; Y = (int)value.Y; @@ -131,12 +131,12 @@ namespace math /// The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements. /// Thrown when is null. /// Thrown when contains more or less than three elements. - public Int3(int[] values) + public Int3( int[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 3) - throw new ArgumentOutOfRangeException("values", "There must be three and only three input values for Int3."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 3 ) + throw new ArgumentOutOfRangeException( "values", "There must be three and only three input values for Int3." ); X = values[0]; Y = values[1]; @@ -154,24 +154,34 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; - case 2: return Z; + case 0: + return X; + case 1: + return Y; + case 2: + return Z; } - throw new ArgumentOutOfRangeException("index", "Indices for Int3 run from 0 to 2, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Int3 run from 0 to 2, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - case 2: Z = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Int3 run from 0 to 2, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + case 2: + Z = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Int3 run from 0 to 2, inclusive." ); } } } @@ -186,7 +196,7 @@ namespace math /// public int Length() { - return (int)Math.Sqrt((X * X) + (Y * Y) + (Z * Z)); + return (int)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) ); } /// @@ -199,18 +209,18 @@ namespace math /// public int LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z); + return ( X * X ) + ( Y * Y ) + ( Z * Z ); } /// /// Raises the exponent for each components. /// /// The exponent. - public void Pow(int exponent) + public void Pow( int exponent ) { - X = (int)Math.Pow(X, exponent); - Y = (int)Math.Pow(Y, exponent); - Z = (int)Math.Pow(Z, exponent); + X = (int)Math.Pow( X, exponent ); + Y = (int)Math.Pow( Y, exponent ); + Z = (int)Math.Pow( Z, exponent ); } /// @@ -228,9 +238,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Int3 left, ref Int3 right, out Int3 result) + public static void Add( ref Int3 left, ref Int3 right, out Int3 result ) { - result = new Int3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + result = new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -239,9 +249,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static Int3 Add(Int3 left, Int3 right) + public static Int3 Add( Int3 left, Int3 right ) { - return new Int3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + return new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -250,9 +260,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Int3 left, ref Int3 right, out Int3 result) + public static void Subtract( ref Int3 left, ref Int3 right, out Int3 result ) { - result = new Int3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + result = new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -261,9 +271,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static Int3 Subtract(Int3 left, Int3 right) + public static Int3 Subtract( Int3 left, Int3 right ) { - return new Int3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + return new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -272,9 +282,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Int3 value, int scale, out Int3 result) + public static void Multiply( ref Int3 value, int scale, out Int3 result ) { - result = new Int3(value.X * scale, value.Y * scale, value.Z * scale); + result = new Int3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -283,9 +293,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int3 Multiply(Int3 value, int scale) + public static Int3 Multiply( Int3 value, int scale ) { - return new Int3(value.X * scale, value.Y * scale, value.Z * scale); + return new Int3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -294,9 +304,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - public static void Modulate(ref Int3 left, ref Int3 right, out Int3 result) + public static void Modulate( ref Int3 left, ref Int3 right, out Int3 result ) { - result = new Int3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + result = new Int3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -305,9 +315,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - public static Int3 Modulate(Int3 left, Int3 right) + public static Int3 Modulate( Int3 left, Int3 right ) { - return new Int3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + return new Int3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -316,9 +326,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Int3 value, int scale, out Int3 result) + public static void Divide( ref Int3 value, int scale, out Int3 result ) { - result = new Int3(value.X / scale, value.Y / scale, value.Z / scale); + result = new Int3( value.X / scale, value.Y / scale, value.Z / scale ); } /// @@ -327,9 +337,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int3 Divide(Int3 value, int scale) + public static Int3 Divide( Int3 value, int scale ) { - return new Int3(value.X / scale, value.Y / scale, value.Z / scale); + return new Int3( value.X / scale, value.Y / scale, value.Z / scale ); } /// @@ -337,9 +347,9 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Int3 value, out Int3 result) + public static void Negate( ref Int3 value, out Int3 result ) { - result = new Int3(-value.X, -value.Y, -value.Z); + result = new Int3( -value.X, -value.Y, -value.Z ); } /// @@ -347,9 +357,9 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - public static Int3 Negate(Int3 value) + public static Int3 Negate( Int3 value ) { - return new Int3(-value.X, -value.Y, -value.Z); + return new Int3( -value.X, -value.Y, -value.Z ); } /// @@ -359,21 +369,21 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Int3 value, ref Int3 min, ref Int3 max, out Int3 result) + public static void Clamp( ref Int3 value, ref Int3 min, ref Int3 max, out Int3 result ) { int x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; int y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; int z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; - result = new Int3(x, y, z); + result = new Int3( x, y, z ); } /// @@ -383,10 +393,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Int3 Clamp(Int3 value, Int3 min, Int3 max) + public static Int3 Clamp( Int3 value, Int3 min, Int3 max ) { Int3 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -396,9 +406,9 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - public static void Dot(ref Int3 left, ref Int3 right, out int result) + public static void Dot( ref Int3 left, ref Int3 right, out int result ) { - result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); + result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ); } /// @@ -407,9 +417,9 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - public static int Dot(Int3 left, Int3 right) + public static int Dot( Int3 left, Int3 right ) { - return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); + return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ); } /// @@ -422,13 +432,13 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Int3 start, ref Int3 end, float amount, out Int3 result) + public static void Lerp( ref Int3 start, ref Int3 end, float amount, out Int3 result ) { - result.X = (int)(start.X + ((end.X - start.X) * amount)); - result.Y = (int)(start.Y + ((end.Y - start.Y) * amount)); - result.Z = (int)(start.Z + ((end.Z - start.Z) * amount)); + result.X = (int)( start.X + ( ( end.X - start.X ) * amount ) ); + result.Y = (int)( start.Y + ( ( end.Y - start.Y ) * amount ) ); + result.Z = (int)( start.Z + ( ( end.Z - start.Z ) * amount ) ); } /// @@ -441,12 +451,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Int3 Lerp(Int3 start, Int3 end, float amount) + public static Int3 Lerp( Int3 start, Int3 end, float amount ) { Int3 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -457,14 +467,14 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Int3 start, ref Int3 end, float amount, out Int3 result) + public static void SmoothStep( ref Int3 start, ref Int3 end, float amount, out Int3 result ) { - amount = (amount > 1) ? 1 : ((amount < 0) ? 0 : amount); - amount = (amount * amount) * (3 - (2 * amount)); + amount = ( amount > 1 ) ? 1 : ( ( amount < 0 ) ? 0 : amount ); + amount = ( amount * amount ) * ( 3 - ( 2 * amount ) ); - result.X = (int)(start.X + ((end.X - start.X) * amount)); - result.Y = (int)(start.Y + ((end.Y - start.Y) * amount)); - result.Z = (int)(start.Z + ((end.Z - start.Z) * amount)); + result.X = (int)( start.X + ( ( end.X - start.X ) * amount ) ); + result.Y = (int)( start.Y + ( ( end.Y - start.Y ) * amount ) ); + result.Z = (int)( start.Z + ( ( end.Z - start.Z ) * amount ) ); } /// @@ -474,10 +484,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Int3 SmoothStep(Int3 start, Int3 end, float amount) + public static Int3 SmoothStep( Int3 start, Int3 end, float amount ) { Int3 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -487,11 +497,11 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Int3 left, ref Int3 right, out Int3 result) + public static void Max( ref Int3 left, ref Int3 right, out Int3 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; } /// @@ -500,10 +510,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - public static Int3 Max(Int3 left, Int3 right) + public static Int3 Max( Int3 left, Int3 right ) { Int3 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -513,11 +523,11 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Int3 left, ref Int3 right, out Int3 result) + public static void Min( ref Int3 left, ref Int3 right, out Int3 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; } /// @@ -526,22 +536,22 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - public static Int3 Min(Int3 left, Int3 right) + public static Int3 Min( Int3 left, Int3 right ) { Int3 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } - + /// /// Adds two vectors. /// /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static Int3 operator +(Int3 left, Int3 right) + public static Int3 operator +( Int3 left, Int3 right ) { - return new Int3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + return new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -549,7 +559,7 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - public static Int3 operator +(Int3 value) + public static Int3 operator +( Int3 value ) { return value; } @@ -560,9 +570,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static Int3 operator -(Int3 left, Int3 right) + public static Int3 operator -( Int3 left, Int3 right ) { - return new Int3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + return new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -570,9 +580,9 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - public static Int3 operator -(Int3 value) + public static Int3 operator -( Int3 value ) { - return new Int3(-value.X, -value.Y, -value.Z); + return new Int3( -value.X, -value.Y, -value.Z ); } /// @@ -581,9 +591,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int3 operator *(float scale, Int3 value) + public static Int3 operator *( float scale, Int3 value ) { - return new Int3((int)(value.X * scale), (int)(value.Y * scale), (int)(value.Z * scale)); + return new Int3( (int)( value.X * scale ), (int)( value.Y * scale ), (int)( value.Z * scale ) ); } /// @@ -592,9 +602,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int3 operator *(Int3 value, float scale) + public static Int3 operator *( Int3 value, float scale ) { - return new Int3((int)(value.X * scale), (int)(value.Y * scale), (int)(value.Z * scale)); + return new Int3( (int)( value.X * scale ), (int)( value.Y * scale ), (int)( value.Z * scale ) ); } /// @@ -603,9 +613,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int3 operator /(Int3 value, float scale) + public static Int3 operator /( Int3 value, float scale ) { - return new Int3((int)(value.X / scale), (int)(value.Y / scale), (int)(value.Z / scale)); + return new Int3( (int)( value.X / scale ), (int)( value.Y / scale ), (int)( value.Z / scale ) ); } /// @@ -614,9 +624,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Int3 left, Int3 right) + public static bool operator ==( Int3 left, Int3 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -625,9 +635,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Int3 left, Int3 right) + public static bool operator !=( Int3 left, Int3 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -635,9 +645,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Int3 value) + public static explicit operator Vec2( Int3 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } /// @@ -645,9 +655,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Int3 value) + public static explicit operator Vec3( Int3 value ) { - return new Vec3(value.X, value.Y, value.Z); + return new Vec3( value.X, value.Y, value.Z ); } /// @@ -655,9 +665,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Int3 value) + public static explicit operator Vec4( Int3 value ) { - return new Vec4(value.X, value.Y, value.Z, 0); + return new Vec4( value.X, value.Y, value.Z, 0 ); } /// @@ -668,7 +678,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z ); } /// @@ -678,13 +688,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), Z.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -694,9 +704,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z ); } /// @@ -707,20 +717,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -734,11 +744,11 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Int3 other) + public bool Equals( Int3 other ) { - return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Z - Z) < MathUtil.ZeroTolerance); + return ( (float)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Z - Z ) < MathUtil.ZeroTolerance ); } /// @@ -748,15 +758,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Int3)value); + return Equals( (Int3)value ); } #if WPFInterop /// diff --git a/math/Int4.cs b/math/Int4.cs index 86c4d12..bd1b957 100644 --- a/math/Int4.cs +++ b/math/Int4.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -30,9 +30,9 @@ namespace math /// /// Represents a four dimensional mathematical vector. /// - [DataContract( Name = "Int4")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Int4" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Int4 : IEquatable, IFormattable { /// @@ -48,27 +48,27 @@ namespace math /// /// The X unit (1, 0, 0, 0). /// - public static readonly Int4 UnitX = new Int4(1, 0, 0, 0); + public static readonly Int4 UnitX = new Int4( 1, 0, 0, 0 ); /// /// The Y unit (0, 1, 0, 0). /// - public static readonly Int4 UnitY = new Int4(0, 1, 0, 0); + public static readonly Int4 UnitY = new Int4( 0, 1, 0, 0 ); /// /// The Z unit (0, 0, 1, 0). /// - public static readonly Int4 UnitZ = new Int4(0, 0, 1, 0); + public static readonly Int4 UnitZ = new Int4( 0, 0, 1, 0 ); /// /// The W unit (0, 0, 0, 1). /// - public static readonly Int4 UnitW = new Int4(0, 0, 0, 1); + public static readonly Int4 UnitW = new Int4( 0, 0, 0, 1 ); /// /// A with all of its components set to one. /// - public static readonly Int4 One = new Int4(1, 1, 1, 1); + public static readonly Int4 One = new Int4( 1, 1, 1, 1 ); /// /// The X component of the vector. @@ -98,7 +98,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Int4(int value) + public Int4( int value ) { X = value; Y = value; @@ -113,7 +113,7 @@ namespace math /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. /// Initial value for the W component of the vector. - public Int4(int x, int y, int z, int w) + public Int4( int x, int y, int z, int w ) { X = x; Y = y; @@ -127,12 +127,12 @@ namespace math /// The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Int4(int[] values) + public Int4( int[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 4) - throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for Int4."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( "values", "There must be four and only four input values for Int4." ); X = values[0]; Y = values[1]; @@ -151,7 +151,7 @@ namespace math { get { - switch (index) + switch( index ) { case 0: return X; @@ -163,12 +163,12 @@ namespace math return W; } - throw new ArgumentOutOfRangeException("index", "Indices for Int4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Int4 run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { case 0: X = value; @@ -183,7 +183,7 @@ namespace math W = value; break; default: - throw new ArgumentOutOfRangeException("index", "Indices for Int4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Int4 run from 0 to 3, inclusive." ); } } } @@ -198,7 +198,7 @@ namespace math /// public int Length() { - return (int)Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); + return (int)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) ); } /// @@ -211,7 +211,7 @@ namespace math /// public int LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z) + (W * W); + return ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ); } /// @@ -229,9 +229,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref Int4 left, ref Int4 right, out Int4 result) + public static void Add( ref Int4 left, ref Int4 right, out Int4 result ) { - result = new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + result = new Int4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -240,9 +240,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static Int4 Add(Int4 left, Int4 right) + public static Int4 Add( Int4 left, Int4 right ) { - return new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new Int4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -251,9 +251,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref Int4 left, ref Int4 right, out Int4 result) + public static void Subtract( ref Int4 left, ref Int4 right, out Int4 result ) { - result = new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + result = new Int4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -262,9 +262,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static Int4 Subtract(Int4 left, Int4 right) + public static Int4 Subtract( Int4 left, Int4 right ) { - return new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new Int4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -273,9 +273,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref Int4 value, int scale, out Int4 result) + public static void Multiply( ref Int4 value, int scale, out Int4 result ) { - result = new Int4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + result = new Int4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -284,9 +284,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int4 Multiply(Int4 value, int scale) + public static Int4 Multiply( Int4 value, int scale ) { - return new Int4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Int4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -295,9 +295,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - public static void Modulate(ref Int4 left, ref Int4 right, out Int4 result) + public static void Modulate( ref Int4 left, ref Int4 right, out Int4 result ) { - result = new Int4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + result = new Int4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -306,9 +306,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - public static Int4 Modulate(Int4 left, Int4 right) + public static Int4 Modulate( Int4 left, Int4 right ) { - return new Int4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + return new Int4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -317,9 +317,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref Int4 value, int scale, out Int4 result) + public static void Divide( ref Int4 value, int scale, out Int4 result ) { - result = new Int4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + result = new Int4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -328,9 +328,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int4 Divide(Int4 value, int scale) + public static Int4 Divide( Int4 value, int scale ) { - return new Int4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new Int4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -338,9 +338,9 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - public static void Negate(ref Int4 value, out Int4 result) + public static void Negate( ref Int4 value, out Int4 result ) { - result = new Int4(-value.X, -value.Y, -value.Z, -value.W); + result = new Int4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -348,9 +348,9 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - public static Int4 Negate(Int4 value) + public static Int4 Negate( Int4 value ) { - return new Int4(-value.X, -value.Y, -value.Z, -value.W); + return new Int4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -360,25 +360,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Int4 value, ref Int4 min, ref Int4 max, out Int4 result) + public static void Clamp( ref Int4 value, ref Int4 min, ref Int4 max, out Int4 result ) { int x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; int y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; int z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; int w = value.W; - w = (w > max.W) ? max.W : w; - w = (w < min.W) ? min.W : w; + w = ( w > max.W ) ? max.W : w; + w = ( w < min.W ) ? min.W : w; - result = new Int4(x, y, z, w); + result = new Int4( x, y, z, w ); } /// @@ -388,10 +388,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Int4 Clamp(Int4 value, Int4 min, Int4 max) + public static Int4 Clamp( Int4 value, Int4 min, Int4 max ) { Int4 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -401,12 +401,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref Int4 left, ref Int4 right, out Int4 result) + public static void Max( ref Int4 left, ref Int4 right, out Int4 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; - result.W = (left.W > right.W) ? left.W : right.W; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; + result.W = ( left.W > right.W ) ? left.W : right.W; } /// @@ -415,10 +415,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - public static Int4 Max(Int4 left, Int4 right) + public static Int4 Max( Int4 left, Int4 right ) { Int4 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -428,12 +428,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref Int4 left, ref Int4 right, out Int4 result) + public static void Min( ref Int4 left, ref Int4 right, out Int4 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; - result.W = (left.W < right.W) ? left.W : right.W; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; + result.W = ( left.W < right.W ) ? left.W : right.W; } /// @@ -442,10 +442,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - public static Int4 Min(Int4 left, Int4 right) + public static Int4 Min( Int4 left, Int4 right ) { Int4 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -455,9 +455,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static Int4 operator +(Int4 left, Int4 right) + public static Int4 operator +( Int4 left, Int4 right ) { - return new Int4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new Int4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -465,7 +465,7 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - public static Int4 operator +(Int4 value) + public static Int4 operator +( Int4 value ) { return value; } @@ -476,9 +476,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static Int4 operator -(Int4 left, Int4 right) + public static Int4 operator -( Int4 left, Int4 right ) { - return new Int4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new Int4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -486,9 +486,9 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - public static Int4 operator -(Int4 value) + public static Int4 operator -( Int4 value ) { - return new Int4(-value.X, -value.Y, -value.Z, -value.W); + return new Int4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -497,9 +497,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int4 operator *(int scale, Int4 value) + public static Int4 operator *( int scale, Int4 value ) { - return new Int4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Int4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -508,9 +508,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int4 operator *(Int4 value, int scale) + public static Int4 operator *( Int4 value, int scale ) { - return new Int4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Int4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -519,9 +519,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static Int4 operator /(Int4 value, int scale) + public static Int4 operator /( Int4 value, int scale ) { - return new Int4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new Int4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -530,9 +530,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Int4 left, Int4 right) + public static bool operator ==( Int4 left, Int4 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -541,9 +541,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Int4 left, Int4 right) + public static bool operator !=( Int4 left, Int4 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -551,9 +551,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Int4 value) + public static explicit operator Vec2( Int4 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } /// @@ -561,9 +561,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Int4 value) + public static explicit operator Vec3( Int4 value ) { - return new Vec3(value.X, value.Y, value.Z); + return new Vec3( value.X, value.Y, value.Z ); } /// @@ -571,9 +571,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Int4 value) + public static explicit operator Vec4( Int4 value ) { - return new Vec4(value.X, value.Y, value.Z, value.W); + return new Vec4( value.X, value.Y, value.Z, value.W ); } /// @@ -584,7 +584,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -594,16 +594,16 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", - X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), - Z.ToString(format, CultureInfo.CurrentCulture), - W.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", + X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), + Z.ToString( format, CultureInfo.CurrentCulture ), + W.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -613,9 +613,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -626,21 +626,21 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - ToString(formatProvider); + if( format == null ) + ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider), - W.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ), + W.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -654,7 +654,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Int4 other) + public bool Equals( Int4 other ) { return other.X == X && other.Y == Y && other.Z == Z && other.W == W; } @@ -666,15 +666,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Int4)value); + return Equals( (Int4)value ); } /// @@ -682,9 +682,9 @@ namespace math /// /// The input. /// The result of the conversion. - public static implicit operator Int4(int[] input) + public static implicit operator Int4( int[] input ) { - return new Int4(input); + return new Int4( input ); } /// @@ -692,7 +692,7 @@ namespace math /// /// The input. /// The result of the conversion. - public static implicit operator int[](Int4 input) + public static implicit operator int[]( Int4 input ) { return input.ToArray(); } diff --git a/math/MathUtil.cs b/math/MathUtil.cs index 7edd459..de88e4e 100644 --- a/math/MathUtil.cs +++ b/math/MathUtil.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -56,17 +56,17 @@ namespace math /// /// A value specifying the approximation of 2π which is 360 degrees. /// - public const float TwoPi = (float)(2 * Math.PI); + public const float TwoPi = (float)( 2 * Math.PI ); /// /// A value specifying the approximation of π/2 which is 90 degrees. /// - public const float PiOverTwo = (float)(Math.PI / 2); + public const float PiOverTwo = (float)( Math.PI / 2 ); /// /// A value specifying the approximation of π/4 which is 45 degrees. /// - public const float PiOverFour = (float)(Math.PI / 4); + public const float PiOverFour = (float)( Math.PI / 4 ); /// /// Checks if a and b are almost equals, taking into account the magnitude of floating point numbers (unlike method). See Remarks. @@ -76,14 +76,14 @@ namespace math /// The right value to compare. /// true if a almost equal to b, false otherwise /// - /// The code is using the technique described by Bruce Dawson in - /// Comparing Floating point numbers 2012 edition. + /// The code is using the technique described by Bruce Dawson in + /// Comparing Floating point numbers 2012 edition. /// - public static unsafe bool NearEqual(float a, float b) + public static unsafe bool NearEqual( float a, float b ) { // Check if the numbers are really close -- needed // when comparing numbers near zero. - if (IsZero(a - b)) + if( IsZero( a - b ) ) return true; // Original from Bruce Dawson: http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ @@ -91,16 +91,16 @@ namespace math int bInt = *(int*)&b; // Different signs means they do not match. - if ((aInt < 0) != (bInt < 0)) + if( ( aInt < 0 ) != ( bInt < 0 ) ) return false; // Find the difference in ULPs. - int ulp = Math.Abs(aInt - bInt); + int ulp = Math.Abs( aInt - bInt ); // Choose of maxUlp = 4 // according to http://code.google.com/p/googletest/source/browse/trunk/include/gtest/internal/gtest-internal.h const int maxUlp = 4; - return (ulp <= maxUlp); + return ( ulp <= maxUlp ); } /// @@ -108,9 +108,9 @@ namespace math /// /// The floating value. /// true if the specified value is close to zero (0.0f); otherwise, false. - public static bool IsZero(float a) + public static bool IsZero( float a ) { - return Math.Abs(a) < ZeroTolerance; + return Math.Abs( a ) < ZeroTolerance; } /// @@ -118,9 +118,9 @@ namespace math /// /// The floating value. /// true if the specified value is close to zero (0.0f); otherwise, false. - public static bool IsZero(double a) + public static bool IsZero( double a ) { - return Math.Abs(a) < ZeroToleranceDouble; + return Math.Abs( a ) < ZeroToleranceDouble; } /// @@ -128,9 +128,9 @@ namespace math /// /// The floating value. /// true if the specified value is close to one (1.0f); otherwise, false. - public static bool IsOne(float a) + public static bool IsOne( float a ) { - return IsZero(a - 1.0f); + return IsZero( a - 1.0f ); } /// @@ -140,10 +140,10 @@ namespace math /// The right value to compare. /// Epsilon value /// true if a almost equal to b within a float epsilon, false otherwise - public static bool WithinEpsilon(float a, float b, float epsilon) + public static bool WithinEpsilon( float a, float b, float epsilon ) { float num = a - b; - return ((-epsilon <= num) && (num <= epsilon)); + return ( ( -epsilon <= num ) && ( num <= epsilon ) ); } /// @@ -153,10 +153,10 @@ namespace math /// The value to fill the array with. /// The size of the array to create. /// A new one-dimensional array of the specified type with the specified length and filled with the specified value. - public static T[] Array(T value, int length) + public static T[] Array( T value, int length ) { var result = new T[length]; - for (var i = 0; i < length; i++) + for( var i = 0; i < length; i++ ) result[i] = value; return result; @@ -167,7 +167,7 @@ namespace math /// /// The value to convert. /// The converted value. - public static float RevolutionsToDegrees(float revolution) + public static float RevolutionsToDegrees( float revolution ) { return revolution * 360.0f; } @@ -177,7 +177,7 @@ namespace math /// /// The value to convert. /// The converted value. - public static float RevolutionsToRadians(float revolution) + public static float RevolutionsToRadians( float revolution ) { return revolution * TwoPi; } @@ -187,7 +187,7 @@ namespace math /// /// The value to convert. /// The converted value. - public static float RevolutionsToGradians(float revolution) + public static float RevolutionsToGradians( float revolution ) { return revolution * 400.0f; } @@ -197,7 +197,7 @@ namespace math /// /// The value to convert. /// The converted value. - public static float DegreesToRevolutions(float degree) + public static float DegreesToRevolutions( float degree ) { return degree / 360.0f; } @@ -207,9 +207,9 @@ namespace math /// /// The value to convert. /// The converted value. - public static float DegreesToRadians(float degree) + public static float DegreesToRadians( float degree ) { - return degree * (Pi / 180.0f); + return degree * ( Pi / 180.0f ); } /// @@ -217,7 +217,7 @@ namespace math /// /// The value to convert. /// The converted value. - public static float RadiansToRevolutions(float radian) + public static float RadiansToRevolutions( float radian ) { return radian / TwoPi; } @@ -227,9 +227,9 @@ namespace math /// /// The value to convert. /// The converted value. - public static float RadiansToGradians(float radian) + public static float RadiansToGradians( float radian ) { - return radian * (200.0f / Pi); + return radian * ( 200.0f / Pi ); } /// @@ -237,7 +237,7 @@ namespace math /// /// The value to convert. /// The converted value. - public static float GradiansToRevolutions(float gradian) + public static float GradiansToRevolutions( float gradian ) { return gradian / 400.0f; } @@ -247,9 +247,9 @@ namespace math /// /// The value to convert. /// The converted value. - public static float GradiansToDegrees(float gradian) + public static float GradiansToDegrees( float gradian ) { - return gradian * (9.0f / 10.0f); + return gradian * ( 9.0f / 10.0f ); } /// @@ -257,9 +257,9 @@ namespace math /// /// The value to convert. /// The converted value. - public static float GradiansToRadians(float gradian) + public static float GradiansToRadians( float gradian ) { - return gradian * (Pi / 200.0f); + return gradian * ( Pi / 200.0f ); } /// @@ -267,9 +267,9 @@ namespace math /// /// The value to convert. /// The converted value. - public static float RadiansToDegrees(float radian) + public static float RadiansToDegrees( float radian ) { - return radian * (180.0f / Pi); + return radian * ( 180.0f / Pi ); } /// @@ -279,7 +279,7 @@ namespace math /// The min. /// The max. /// The result of clamping a value between min and max - public static float Clamp(float value, float min, float max) + public static float Clamp( float value, float min, float max ) { return value < min ? min : value > max ? max : value; } @@ -291,7 +291,7 @@ namespace math /// The min. /// The max. /// The result of clamping a value between min and max - public static double Clamp(double value, double min, double max) + public static double Clamp( double value, double min, double max ) { return value < min ? min : value > max ? max : value; } @@ -303,7 +303,7 @@ namespace math /// The min. /// The max. /// The result of clamping a value between min and max - public static int Clamp(int value, int min, int max) + public static int Clamp( int value, int min, int max ) { return value < min ? min : value > max ? max : value; } @@ -315,11 +315,11 @@ namespace math /// Maximum value that takes place in inverse-interpolation. /// Value to get inverse interpolation. /// Returns an inverse-linearly interpolated coeficient. - public static float InverseLerp(float min, float max, float value) + public static float InverseLerp( float min, float max, float value ) { - if (IsZero(Math.Abs(max - min))) + if( IsZero( Math.Abs( max - min ) ) ) return float.NaN; - return (value - min) / (max - min); + return ( value - min ) / ( max - min ); } /// @@ -329,11 +329,11 @@ namespace math /// Maximum value that takes place in inverse-interpolation. /// Value to get inverse interpolation. /// Returns an inverse-linearly interpolated coeficient. - public static double InverseLerp(double min, double max, double value) + public static double InverseLerp( double min, double max, double value ) { - if (IsZero(Math.Abs(max - min))) + if( IsZero( Math.Abs( max - min ) ) ) return double.NaN; - return (value - min) / (max - min); + return ( value - min ) / ( max - min ); } /// @@ -347,9 +347,9 @@ namespace math /// Value to interpolate to. /// Interpolation amount. /// The result of linear interpolation of values based on the amount. - public static double Lerp(double from, double to, double amount) + public static double Lerp( double from, double to, double amount ) { - return (1 - amount) * from + amount * to; + return ( 1 - amount ) * from + amount * to; } /// @@ -363,9 +363,9 @@ namespace math /// Value to interpolate to. /// Interpolation amount. /// The result of linear interpolation of values based on the amount. - public static float Lerp(float from, float to, float amount) + public static float Lerp( float from, float to, float amount ) { - return (1 - amount) * from + amount * to; + return ( 1 - amount ) * from + amount * to; } /// @@ -379,9 +379,9 @@ namespace math /// Value to interpolate to. /// Interpolation amount. /// The result of linear interpolation of values based on the amount. - public static byte Lerp(byte from, byte to, float amount) + public static byte Lerp( byte from, byte to, float amount ) { - return (byte)Lerp((float)from, (float)to, amount); + return (byte)Lerp( (float)from, (float)to, amount ); } /// @@ -391,11 +391,11 @@ namespace math /// See https://en.wikipedia.org/wiki/Smoothstep /// /// Value between 0 and 1 indicating interpolation amount. - public static float SmoothStep(float amount) + public static float SmoothStep( float amount ) { - return (amount <= 0) ? 0 - : (amount >= 1) ? 1 - : amount * amount * (3 - (2 * amount)); + return ( amount <= 0 ) ? 0 + : ( amount >= 1 ) ? 1 + : amount * amount * ( 3 - ( 2 * amount ) ); } /// @@ -405,11 +405,11 @@ namespace math /// See https://en.wikipedia.org/wiki/Smoothstep /// /// Value between 0 and 1 indicating interpolation amount. - public static float SmootherStep(float amount) + public static float SmootherStep( float amount ) { - return (amount <= 0) ? 0 - : (amount >= 1) ? 1 - : amount * amount * amount * (amount * ((amount * 6) - 15) + 10); + return ( amount <= 0 ) ? 0 + : ( amount >= 1 ) ? 1 + : amount * amount * amount * ( amount * ( ( amount * 6 ) - 15 ) + 10 ); } /// @@ -419,7 +419,7 @@ namespace math /// The minimum value of the range. /// The maximum value of the range. /// true if value is inside the specified range; otherwise, false. - public static bool IsInRange(float value, float min, float max) + public static bool IsInRange( float value, float min, float max ) { return min <= value && value <= max; } @@ -431,7 +431,7 @@ namespace math /// The minimum value of the range. /// The maximum value of the range. /// true if value is inside the specified range; otherwise, false. - public static bool IsInRange(int value, int min, int max) + public static bool IsInRange( int value, int min, int max ) { return min <= value && value <= max; } @@ -441,9 +441,9 @@ namespace math /// /// The x. /// true if the specified x is pow2; otherwise, false. - public static bool IsPow2(int x) + public static bool IsPow2( int x ) { - return ((x != 0) && (x & (x - 1)) == 0); + return ( ( x != 0 ) && ( x & ( x - 1 ) ) == 0 ); } /// @@ -451,10 +451,11 @@ namespace math /// /// The sRGB value. /// A linear value. - public static float SRgbToLinear(float sRgbValue) + public static float SRgbToLinear( float sRgbValue ) { - if (sRgbValue < 0.04045f) return sRgbValue / 12.92f; - return (float)Math.Pow((sRgbValue + 0.055) / 1.055, 2.4); + if( sRgbValue < 0.04045f ) + return sRgbValue / 12.92f; + return (float)Math.Pow( ( sRgbValue + 0.055 ) / 1.055, 2.4 ); } /// @@ -462,10 +463,11 @@ namespace math /// /// The linear value. /// The encoded sRGB value. - public static float LinearToSRgb(float linearValue) + public static float LinearToSRgb( float linearValue ) { - if (linearValue < 0.0031308f) return linearValue * 12.92f; - return (float)(1.055 * Math.Pow(linearValue, 1 / 2.4) - 0.055); + if( linearValue < 0.0031308f ) + return linearValue * 12.92f; + return (float)( 1.055 * Math.Pow( linearValue, 1 / 2.4 ) - 0.055 ); } /// @@ -473,9 +475,9 @@ namespace math /// /// The input float /// Log2(x) - public static float Log2(float x) + public static float Log2( float x ) { - return (float)Math.Log(x) / 0.6931471805599453f; + return (float)Math.Log( x ) / 0.6931471805599453f; } /// @@ -483,11 +485,11 @@ namespace math /// /// The input integer /// the log2(i) rounded to lower integer - public static int Log2(int i) + public static int Log2( int i ) { var r = 0; - while ((i >>= 1) != 0) + while( ( i >>= 1 ) != 0 ) ++r; return r; @@ -499,9 +501,9 @@ namespace math /// The size. /// System.Int32. /// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 - public static int NextPowerOfTwo(int x) + public static int NextPowerOfTwo( int x ) { - if (x < 0) + if( x < 0 ) return 0; x--; @@ -518,27 +520,27 @@ namespace math /// /// The size. /// System.Int32. - public static float NextPowerOfTwo(float size) + public static float NextPowerOfTwo( float size ) { - return (float)Math.Pow(2, Math.Ceiling(Math.Log(size, 2))); + return (float)Math.Pow( 2, Math.Ceiling( Math.Log( size, 2 ) ) ); } /// /// Get the previous power of two of the provided integer. /// /// The value - public static int PreviousPowerOfTwo(int size) + public static int PreviousPowerOfTwo( int size ) { - return 1 << (int)Math.Floor(Math.Log(size, 2)); + return 1 << (int)Math.Floor( Math.Log( size, 2 ) ); } /// /// Get the previous power of two of the provided float. /// /// The value - public static float PreviousPowerOfTwo(float size) + public static float PreviousPowerOfTwo( float size ) { - return (float)Math.Pow(2, Math.Floor(Math.Log(size, 2))); + return (float)Math.Pow( 2, Math.Floor( Math.Log( size, 2 ) ) ); } /// @@ -547,11 +549,11 @@ namespace math /// The value. /// The alignment. /// Aligned value (multiple of alignment). - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int AlignUp(int value, int alignment) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static int AlignUp( int value, int alignment ) { int mask = alignment - 1; - return (value + mask) & ~mask; + return ( value + mask ) & ~mask; } /// @@ -560,8 +562,8 @@ namespace math /// The value. /// The alignment. /// Aligned value (multiple of alignment). - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int AlignDown(int value, int alignment) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static int AlignDown( int value, int alignment ) { int mask = alignment - 1; return value & ~mask; @@ -573,10 +575,10 @@ namespace math /// The value. /// The alignment. /// true if the specified value is aligned; otherwise, false. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsAligned(int value, int alignment) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static bool IsAligned( int value, int alignment ) { - return (value & (alignment - 1)) == 0; + return ( value & ( alignment - 1 ) ) == 0; } /// @@ -585,11 +587,11 @@ namespace math /// The value to snap. /// The interval gap. /// The nearest interval to the provided value. - public static float Snap(float value, float gap) + public static float Snap( float value, float gap ) { - if (gap == 0) + if( gap == 0 ) return value; - return (float)Math.Round((value / gap), MidpointRounding.AwayFromZero) * gap; + return (float)Math.Round( ( value / gap ), MidpointRounding.AwayFromZero ) * gap; } /// @@ -598,11 +600,11 @@ namespace math /// The value to snap. /// The interval gap. /// The nearest interval to the provided value. - public static double Snap(double value, double gap) + public static double Snap( double value, double gap ) { - if (gap == 0) + if( gap == 0 ) return value; - return Math.Round((value / gap), MidpointRounding.AwayFromZero) * gap; + return Math.Round( ( value / gap ), MidpointRounding.AwayFromZero ) * gap; } /// @@ -611,13 +613,13 @@ namespace math /// The vector to snap. /// The interval gap. /// A vector which components are snapped to the nearest interval. - public static Vec2 Snap(Vec2 value, float gap) + public static Vec2 Snap( Vec2 value, float gap ) { - if (gap == 0) + if( gap == 0 ) return value; return new Vec2( - (float)Math.Round((value.X / gap), MidpointRounding.AwayFromZero) * gap, - (float)Math.Round((value.Y / gap), MidpointRounding.AwayFromZero) * gap); + (float)Math.Round( ( value.X / gap ), MidpointRounding.AwayFromZero ) * gap, + (float)Math.Round( ( value.Y / gap ), MidpointRounding.AwayFromZero ) * gap ); } /// @@ -626,14 +628,14 @@ namespace math /// The vector to snap. /// The interval gap. /// A vector which components are snapped to the nearest interval. - public static Vec3 Snap(Vec3 value, float gap) + public static Vec3 Snap( Vec3 value, float gap ) { - if (gap == 0) + if( gap == 0 ) return value; return new Vec3( - (float)Math.Round((value.X / gap), MidpointRounding.AwayFromZero) * gap, - (float)Math.Round((value.Y / gap), MidpointRounding.AwayFromZero) * gap, - (float)Math.Round((value.Z / gap), MidpointRounding.AwayFromZero) * gap); + (float)Math.Round( ( value.X / gap ), MidpointRounding.AwayFromZero ) * gap, + (float)Math.Round( ( value.Y / gap ), MidpointRounding.AwayFromZero ) * gap, + (float)Math.Round( ( value.Z / gap ), MidpointRounding.AwayFromZero ) * gap ); } /// @@ -642,15 +644,15 @@ namespace math /// The vector to snap. /// The interval gap. /// A vector which components are snapped to the nearest interval. - public static Vec4 Snap(Vec4 value, float gap) + public static Vec4 Snap( Vec4 value, float gap ) { - if (gap == 0) + if( gap == 0 ) return value; return new Vec4( - (float)Math.Round((value.X / gap), MidpointRounding.AwayFromZero) * gap, - (float)Math.Round((value.Y / gap), MidpointRounding.AwayFromZero) * gap, - (float)Math.Round((value.Z / gap), MidpointRounding.AwayFromZero) * gap, - (float)Math.Round((value.W / gap), MidpointRounding.AwayFromZero) * gap); + (float)Math.Round( ( value.X / gap ), MidpointRounding.AwayFromZero ) * gap, + (float)Math.Round( ( value.Y / gap ), MidpointRounding.AwayFromZero ) * gap, + (float)Math.Round( ( value.Z / gap ), MidpointRounding.AwayFromZero ) * gap, + (float)Math.Round( ( value.W / gap ), MidpointRounding.AwayFromZero ) * gap ); } } } diff --git a/math/Matrix.cs b/math/Matrix.cs index 7378e38..74448a2 100644 --- a/math/Matrix.cs +++ b/math/Matrix.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -39,9 +39,9 @@ namespace math /// /// Represents a 4x4 mathematical matrix. /// - [DataContract( Name = "float4x4")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "float4x4" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Matrix : IEquatable, IFormattable { /// @@ -78,7 +78,7 @@ namespace math /// Value at row 4 column 1 of the matrix. /// public float M41; - + /// /// Value at row 1 column 2 of the matrix. /// @@ -103,7 +103,7 @@ namespace math /// Value at row 1 column 3 of the matrix. /// public float M13; - + /// /// Value at row 2 column 3 of the matrix. /// @@ -118,7 +118,7 @@ namespace math /// Value at row 4 column 3 of the matrix. /// public float M43; - + /// /// Value at row 1 column 4 of the matrix. /// @@ -143,7 +143,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Matrix(float value) + public Matrix( float value ) { M11 = M21 = M31 = M41 = M12 = M22 = M32 = M42 = @@ -170,15 +170,27 @@ namespace math /// The value to assign at row 4 column 2 of the matrix. /// The value to assign at row 4 column 3 of the matrix. /// The value to assign at row 4 column 4 of the matrix. - public Matrix(float M11, float M12, float M13, float M14, + public Matrix( float M11, float M12, float M13, float M14, float M21, float M22, float M23, float M24, float M31, float M32, float M33, float M34, - float M41, float M42, float M43, float M44) + float M41, float M42, float M43, float M44 ) { - this.M11 = M11; this.M12 = M12; this.M13 = M13; this.M14 = M14; - this.M21 = M21; this.M22 = M22; this.M23 = M23; this.M24 = M24; - this.M31 = M31; this.M32 = M32; this.M33 = M33; this.M34 = M34; - this.M41 = M41; this.M42 = M42; this.M43 = M43; this.M44 = M44; + this.M11 = M11; + this.M12 = M12; + this.M13 = M13; + this.M14 = M14; + this.M21 = M21; + this.M22 = M22; + this.M23 = M23; + this.M24 = M24; + this.M31 = M31; + this.M32 = M32; + this.M33 = M33; + this.M34 = M34; + this.M41 = M41; + this.M42 = M42; + this.M43 = M43; + this.M44 = M44; } /// @@ -187,12 +199,12 @@ namespace math /// The values to assign to the components of the matrix. This must be an array with sixteen elements. /// Thrown when is null. /// Thrown when contains more or less than sixteen elements. - public Matrix(float[] values) + public Matrix( float[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 16) - throw new ArgumentOutOfRangeException("values", "There must be sixteen and only sixteen input values for Matrix."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 16 ) + throw new ArgumentOutOfRangeException( "values", "There must be sixteen and only sixteen input values for Matrix." ); M11 = values[0]; M12 = values[1]; @@ -221,7 +233,7 @@ namespace math [DataMemberIgnore] public Vec4 Row1 { - get { return new Vec4(M11, M12, M13, M14); } + get { return new Vec4( M11, M12, M13, M14 ); } set { M11 = value.X; M12 = value.Y; M13 = value.Z; M14 = value.W; } } @@ -231,7 +243,7 @@ namespace math [DataMemberIgnore] public Vec4 Row2 { - get { return new Vec4(M21, M22, M23, M24); } + get { return new Vec4( M21, M22, M23, M24 ); } set { M21 = value.X; M22 = value.Y; M23 = value.Z; M24 = value.W; } } @@ -241,7 +253,7 @@ namespace math [DataMemberIgnore] public Vec4 Row3 { - get { return new Vec4(M31, M32, M33, M34); } + get { return new Vec4( M31, M32, M33, M34 ); } set { M31 = value.X; M32 = value.Y; M33 = value.Z; M34 = value.W; } } @@ -251,7 +263,7 @@ namespace math [DataMemberIgnore] public Vec4 Row4 { - get { return new Vec4(M41, M42, M43, M44); } + get { return new Vec4( M41, M42, M43, M44 ); } set { M41 = value.X; M42 = value.Y; M43 = value.Z; M44 = value.W; } } @@ -261,7 +273,7 @@ namespace math [DataMemberIgnore] public Vec4 Column1 { - get { return new Vec4(M11, M21, M31, M41); } + get { return new Vec4( M11, M21, M31, M41 ); } set { M11 = value.X; M21 = value.Y; M31 = value.Z; M41 = value.W; } } @@ -271,7 +283,7 @@ namespace math [DataMemberIgnore] public Vec4 Column2 { - get { return new Vec4(M12, M22, M32, M42); } + get { return new Vec4( M12, M22, M32, M42 ); } set { M12 = value.X; M22 = value.Y; M32 = value.Z; M42 = value.W; } } @@ -281,7 +293,7 @@ namespace math [DataMemberIgnore] public Vec4 Column3 { - get { return new Vec4(M13, M23, M33, M43); } + get { return new Vec4( M13, M23, M33, M43 ); } set { M13 = value.X; M23 = value.Y; M33 = value.Z; M43 = value.W; } } @@ -291,7 +303,7 @@ namespace math [DataMemberIgnore] public Vec4 Column4 { - get { return new Vec4(M14, M24, M34, M44); } + get { return new Vec4( M14, M24, M34, M44 ); } set { M14 = value.X; M24 = value.Y; M34 = value.Z; M44 = value.W; } } @@ -301,7 +313,7 @@ namespace math [DataMemberIgnore] public Vec3 TranslationVector { - get { return new Vec3(M41, M42, M43); } + get { return new Vec3( M41, M42, M43 ); } set { M41 = value.X; M42 = value.Y; M43 = value.Z; } } @@ -312,7 +324,7 @@ namespace math [DataMemberIgnore] public Vec3 ScaleVector { - get { return new Vec3(M11, M22, M33); } + get { return new Vec3( M11, M22, M33 ); } set { M11 = value.X; M22 = value.Y; M33 = value.Z; } } @@ -322,7 +334,7 @@ namespace math [DataMemberIgnore] public Vec3 Up { - get { return new Vec3(M21, M22, M23); } + get { return new Vec3( M21, M22, M23 ); } set { M21 = value.X; M22 = value.Y; M23 = value.Z; } } @@ -332,7 +344,7 @@ namespace math [DataMemberIgnore] public Vec3 Down { - get { return new Vec3(-M21, -M22, -M23); } + get { return new Vec3( -M21, -M22, -M23 ); } set { M21 = -value.X; M22 = -value.Y; M23 = -value.Z; } } @@ -342,7 +354,7 @@ namespace math [DataMemberIgnore] public Vec3 Right { - get { return new Vec3(M11, M12, M13); } + get { return new Vec3( M11, M12, M13 ); } set { M11 = value.X; M12 = value.Y; M13 = value.Z; } } @@ -352,7 +364,7 @@ namespace math [DataMemberIgnore] public Vec3 Left { - get { return new Vec3(-M11, -M12, -M13); } + get { return new Vec3( -M11, -M12, -M13 ); } set { M11 = -value.X; M12 = -value.Y; M13 = -value.Z; } } @@ -362,7 +374,7 @@ namespace math [DataMemberIgnore] public Vec3 Forward { - get { return new Vec3(-M31, -M32, -M33); } + get { return new Vec3( -M31, -M32, -M33 ); } set { M31 = -value.X; M32 = -value.Y; M33 = -value.Z; } } @@ -372,7 +384,7 @@ namespace math [DataMemberIgnore] public Vec3 Backward { - get { return new Vec3(M31, M32, M33); } + get { return new Vec3( M31, M32, M33 ); } set { M31 = value.X; M32 = value.Y; M33 = value.Z; } } @@ -384,7 +396,7 @@ namespace math /// public bool IsIdentity { - get { return this.Equals(Identity); } + get { return this.Equals( Identity ); } } /// @@ -398,50 +410,99 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return M11; - case 1: return M12; - case 2: return M13; - case 3: return M14; - case 4: return M21; - case 5: return M22; - case 6: return M23; - case 7: return M24; - case 8: return M31; - case 9: return M32; - case 10: return M33; - case 11: return M34; - case 12: return M41; - case 13: return M42; - case 14: return M43; - case 15: return M44; + case 0: + return M11; + case 1: + return M12; + case 2: + return M13; + case 3: + return M14; + case 4: + return M21; + case 5: + return M22; + case 6: + return M23; + case 7: + return M24; + case 8: + return M31; + case 9: + return M32; + case 10: + return M33; + case 11: + return M34; + case 12: + return M41; + case 13: + return M42; + case 14: + return M43; + case 15: + return M44; } - throw new ArgumentOutOfRangeException("index", "Indices for Matrix run from 0 to 15, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Matrix run from 0 to 15, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: M11 = value; break; - case 1: M12 = value; break; - case 2: M13 = value; break; - case 3: M14 = value; break; - case 4: M21 = value; break; - case 5: M22 = value; break; - case 6: M23 = value; break; - case 7: M24 = value; break; - case 8: M31 = value; break; - case 9: M32 = value; break; - case 10: M33 = value; break; - case 11: M34 = value; break; - case 12: M41 = value; break; - case 13: M42 = value; break; - case 14: M43 = value; break; - case 15: M44 = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Matrix run from 0 to 15, inclusive."); + case 0: + M11 = value; + break; + case 1: + M12 = value; + break; + case 2: + M13 = value; + break; + case 3: + M14 = value; + break; + case 4: + M21 = value; + break; + case 5: + M22 = value; + break; + case 6: + M23 = value; + break; + case 7: + M24 = value; + break; + case 8: + M31 = value; + break; + case 9: + M32 = value; + break; + case 10: + M33 = value; + break; + case 11: + M34 = value; + break; + case 12: + M41 = value; + break; + case 13: + M42 = value; + break; + case 14: + M43 = value; + break; + case 15: + M44 = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Matrix run from 0 to 15, inclusive." ); } } } @@ -458,22 +519,22 @@ namespace math { get { - if (row < 0 || row > 3) - throw new ArgumentOutOfRangeException("row", "Rows and columns for matrices run from 0 to 3, inclusive."); - if (column < 0 || column > 3) - throw new ArgumentOutOfRangeException("column", "Rows and columns for matrices run from 0 to 3, inclusive."); + if( row < 0 || row > 3 ) + throw new ArgumentOutOfRangeException( "row", "Rows and columns for matrices run from 0 to 3, inclusive." ); + if( column < 0 || column > 3 ) + throw new ArgumentOutOfRangeException( "column", "Rows and columns for matrices run from 0 to 3, inclusive." ); - return this[(row * 4) + column]; + return this[( row * 4 ) + column]; } set { - if (row < 0 || row > 3) - throw new ArgumentOutOfRangeException("row", "Rows and columns for matrices run from 0 to 3, inclusive."); - if (column < 0 || column > 3) - throw new ArgumentOutOfRangeException("column", "Rows and columns for matrices run from 0 to 3, inclusive."); + if( row < 0 || row > 3 ) + throw new ArgumentOutOfRangeException( "row", "Rows and columns for matrices run from 0 to 3, inclusive." ); + if( column < 0 || column > 3 ) + throw new ArgumentOutOfRangeException( "column", "Rows and columns for matrices run from 0 to 3, inclusive." ); - this[(row * 4) + column] = value; + this[( row * 4 ) + column] = value; } } @@ -483,16 +544,16 @@ namespace math /// The determinant of the matrix. public float Determinant() { - float temp1 = (M33 * M44) - (M34 * M43); - float temp2 = (M32 * M44) - (M34 * M42); - float temp3 = (M32 * M43) - (M33 * M42); - float temp4 = (M31 * M44) - (M34 * M41); - float temp5 = (M31 * M43) - (M33 * M41); - float temp6 = (M31 * M42) - (M32 * M41); + float temp1 = ( M33 * M44 ) - ( M34 * M43 ); + float temp2 = ( M32 * M44 ) - ( M34 * M42 ); + float temp3 = ( M32 * M43 ) - ( M33 * M42 ); + float temp4 = ( M31 * M44 ) - ( M34 * M41 ); + float temp5 = ( M31 * M43 ) - ( M33 * M41 ); + float temp6 = ( M31 * M42 ) - ( M32 * M41 ); - return ((((M11 * (((M22 * temp1) - (M23 * temp2)) + (M24 * temp3))) - (M12 * (((M21 * temp1) - - (M23 * temp4)) + (M24 * temp5)))) + (M13 * (((M21 * temp2) - (M22 * temp4)) + (M24 * temp6)))) - - (M14 * (((M21 * temp3) - (M22 * temp5)) + (M23 * temp6)))); + return ( ( ( ( M11 * ( ( ( M22 * temp1 ) - ( M23 * temp2 ) ) + ( M24 * temp3 ) ) ) - ( M12 * ( ( ( M21 * temp1 ) - + ( M23 * temp4 ) ) + ( M24 * temp5 ) ) ) ) + ( M13 * ( ( ( M21 * temp2 ) - ( M22 * temp4 ) ) + ( M24 * temp6 ) ) ) ) - + ( M14 * ( ( ( M21 * temp3 ) - ( M22 * temp5 ) ) + ( M23 * temp6 ) ) ) ); } /// @@ -500,7 +561,7 @@ namespace math /// public void Invert() { - Invert(ref this, out this); + Invert( ref this, out this ); } /// @@ -510,14 +571,26 @@ namespace math { float temp; - temp = M21; M21 = M12; M12 = temp; - temp = M31; M31 = M13; M13 = temp; - temp = M41; M41 = M14; M14 = temp; + temp = M21; + M21 = M12; + M12 = temp; + temp = M31; + M31 = M13; + M13 = temp; + temp = M41; + M41 = M14; + M14 = temp; - temp = M32; M32 = M23; M23 = temp; - temp = M42; M42 = M24; M24 = temp; + temp = M32; + M32 = M23; + M23 = temp; + temp = M42; + M42 = M24; + M24 = temp; - temp = M43; M43 = M34; M34 = temp; + temp = M43; + M43 = M34; + M34 = temp; } /// @@ -536,7 +609,7 @@ namespace math /// public void Orthogonalize() { - Orthogonalize(ref this, out this); + Orthogonalize( ref this, out this ); } /// @@ -557,7 +630,7 @@ namespace math /// public void Orthonormalize() { - Orthonormalize(ref this, out this); + Orthonormalize( ref this, out this ); } /// @@ -565,27 +638,27 @@ namespace math /// /// When the method completes, contains the orthonormalized matrix of the decomposition. /// When the method completes, contains the right triangular matrix of the decomposition. - public void DecomposeQR(out Matrix Q, out Matrix R) + public void DecomposeQR( out Matrix Q, out Matrix R ) { Matrix temp = this; temp.Transpose(); - Orthonormalize(ref temp, out Q); + Orthonormalize( ref temp, out Q ); Q.Transpose(); R = new Matrix(); - R.M11 = Vec4.Dot(Q.Column1, Column1); - R.M12 = Vec4.Dot(Q.Column1, Column2); - R.M13 = Vec4.Dot(Q.Column1, Column3); - R.M14 = Vec4.Dot(Q.Column1, Column4); + R.M11 = Vec4.Dot( Q.Column1, Column1 ); + R.M12 = Vec4.Dot( Q.Column1, Column2 ); + R.M13 = Vec4.Dot( Q.Column1, Column3 ); + R.M14 = Vec4.Dot( Q.Column1, Column4 ); - R.M22 = Vec4.Dot(Q.Column2, Column2); - R.M23 = Vec4.Dot(Q.Column2, Column3); - R.M24 = Vec4.Dot(Q.Column2, Column4); + R.M22 = Vec4.Dot( Q.Column2, Column2 ); + R.M23 = Vec4.Dot( Q.Column2, Column3 ); + R.M24 = Vec4.Dot( Q.Column2, Column4 ); - R.M33 = Vec4.Dot(Q.Column3, Column3); - R.M34 = Vec4.Dot(Q.Column3, Column4); + R.M33 = Vec4.Dot( Q.Column3, Column3 ); + R.M34 = Vec4.Dot( Q.Column3, Column4 ); - R.M44 = Vec4.Dot(Q.Column4, Column4); + R.M44 = Vec4.Dot( Q.Column4, Column4 ); } /// @@ -593,24 +666,24 @@ namespace math /// /// When the method completes, contains the lower triangular matrix of the decomposition. /// When the method completes, contains the orthonormalized matrix of the decomposition. - public void DecomposeLQ(out Matrix L, out Matrix Q) + public void DecomposeLQ( out Matrix L, out Matrix Q ) { - Orthonormalize(ref this, out Q); + Orthonormalize( ref this, out Q ); L = new Matrix(); - L.M11 = Vec4.Dot(Q.Row1, Row1); - - L.M21 = Vec4.Dot(Q.Row1, Row2); - L.M22 = Vec4.Dot(Q.Row2, Row2); - - L.M31 = Vec4.Dot(Q.Row1, Row3); - L.M32 = Vec4.Dot(Q.Row2, Row3); - L.M33 = Vec4.Dot(Q.Row3, Row3); - - L.M41 = Vec4.Dot(Q.Row1, Row4); - L.M42 = Vec4.Dot(Q.Row2, Row4); - L.M43 = Vec4.Dot(Q.Row3, Row4); - L.M44 = Vec4.Dot(Q.Row4, Row4); + L.M11 = Vec4.Dot( Q.Row1, Row1 ); + + L.M21 = Vec4.Dot( Q.Row1, Row2 ); + L.M22 = Vec4.Dot( Q.Row2, Row2 ); + + L.M31 = Vec4.Dot( Q.Row1, Row3 ); + L.M32 = Vec4.Dot( Q.Row2, Row3 ); + L.M33 = Vec4.Dot( Q.Row3, Row3 ); + + L.M41 = Vec4.Dot( Q.Row1, Row4 ); + L.M42 = Vec4.Dot( Q.Row2, Row4 ); + L.M43 = Vec4.Dot( Q.Row3, Row4 ); + L.M44 = Vec4.Dot( Q.Row4, Row4 ); } /// @@ -619,20 +692,20 @@ namespace math /// The yaw. /// The pitch. /// The roll. - public void Decompose(out float yaw, out float pitch, out float roll) + public void Decompose( out float yaw, out float pitch, out float roll ) { - pitch = (float)Math.Asin(-M32); + pitch = (float)Math.Asin( -M32 ); // Hardcoded constant - burn him, he's a witch - // double threshold = 0.001; - double test = Math.Cos(pitch); - if (test > MathUtil.ZeroTolerance) + // double threshold = 0.001; + double test = Math.Cos( pitch ); + if( test > MathUtil.ZeroTolerance ) { - roll = (float)Math.Atan2(M12, M22); - yaw = (float)Math.Atan2(M31, M33); + roll = (float)Math.Atan2( M12, M22 ); + yaw = (float)Math.Atan2( M31, M33 ); } else { - roll = (float)Math.Atan2(-M21, M11); + roll = (float)Math.Atan2( -M21, M11 ); yaw = 0.0f; } } @@ -642,18 +715,18 @@ namespace math /// Matrix.RotationX(rotation.X) * Matrix.RotationY(rotation.Y) * Matrix.RotationZ(rotation.Z) should represent the same rotation. /// /// The vector containing the 3 rotations angles to be applied in order. - public void DecomposeXYZ(out Vec3 rotation) + public void DecomposeXYZ( out Vec3 rotation ) { - rotation.Y = (float)Math.Asin(-M13); - double test = Math.Cos(rotation.Y); - if (test > 1e-6f) + rotation.Y = (float)Math.Asin( -M13 ); + double test = Math.Cos( rotation.Y ); + if( test > 1e-6f ) { - rotation.Z = (float)Math.Atan2(M12, M11); - rotation.X = (float)Math.Atan2(M23, M33); + rotation.Z = (float)Math.Atan2( M12, M11 ); + rotation.X = (float)Math.Atan2( M23, M33 ); } else { - rotation.Z = (float)Math.Atan2(-M21, M31); + rotation.Z = (float)Math.Atan2( -M21, M31 ); rotation.X = 0.0f; } } @@ -665,7 +738,7 @@ namespace math /// When the method completes, contains the translation component of the decomposed matrix. /// true if a rotation exist for this matrix, false otherwise. /// This method is designed to decompose an SRT transformation matrix only. - public bool Decompose(out Vec3 scale, out Vec3 translation) + public bool Decompose( out Vec3 scale, out Vec3 translation ) { //Source: Unknown //References: http://www.gamedev.net/community/forums/topic.asp?topic_id=441695 @@ -676,14 +749,14 @@ namespace math translation.Z = this.M43; //Scaling is the length of the rows. - scale.X = (float)Math.Sqrt((M11 * M11) + (M12 * M12) + (M13 * M13)); - scale.Y = (float)Math.Sqrt((M21 * M21) + (M22 * M22) + (M23 * M23)); - scale.Z = (float)Math.Sqrt((M31 * M31) + (M32 * M32) + (M33 * M33)); + scale.X = (float)Math.Sqrt( ( M11 * M11 ) + ( M12 * M12 ) + ( M13 * M13 ) ); + scale.Y = (float)Math.Sqrt( ( M21 * M21 ) + ( M22 * M22 ) + ( M23 * M23 ) ); + scale.Z = (float)Math.Sqrt( ( M31 * M31 ) + ( M32 * M32 ) + ( M33 * M33 ) ); //If any of the scaling factors are zero, than the rotation matrix can not exist. - if (Math.Abs(scale.X) < MathUtil.ZeroTolerance || - Math.Abs(scale.Y) < MathUtil.ZeroTolerance || - Math.Abs(scale.Z) < MathUtil.ZeroTolerance) + if( Math.Abs( scale.X ) < MathUtil.ZeroTolerance || + Math.Abs( scale.Y ) < MathUtil.ZeroTolerance || + Math.Abs( scale.Z ) < MathUtil.ZeroTolerance ) { return false; } @@ -700,11 +773,11 @@ namespace math /// /// This method is designed to decompose an SRT transformation matrix only. /// - public bool Decompose(out Vec3 scale, out Quaternion rotation, out Vec3 translation) + public bool Decompose( out Vec3 scale, out Quaternion rotation, out Vec3 translation ) { Matrix rotationMatrix; - Decompose(out scale, out rotationMatrix, out translation); - Quaternion.RotationMatrix(ref rotationMatrix, out rotation); + Decompose( out scale, out rotationMatrix, out translation ); + Quaternion.RotationMatrix( ref rotationMatrix, out rotation ); return true; } @@ -717,7 +790,7 @@ namespace math /// /// This method is designed to decompose an SRT transformation matrix only. /// - public bool Decompose(out Vec3 scale, out Matrix rotation, out Vec3 translation) + public bool Decompose( out Vec3 scale, out Matrix rotation, out Vec3 translation ) { //Source: Unknown //References: http://www.gamedev.net/community/forums/topic.asp?topic_id=441695 @@ -728,23 +801,23 @@ namespace math translation.Z = this.M43; //Scaling is the length of the rows. - scale.X = (float)Math.Sqrt((M11 * M11) + (M12 * M12) + (M13 * M13)); - scale.Y = (float)Math.Sqrt((M21 * M21) + (M22 * M22) + (M23 * M23)); - scale.Z = (float)Math.Sqrt((M31 * M31) + (M32 * M32) + (M33 * M33)); + scale.X = (float)Math.Sqrt( ( M11 * M11 ) + ( M12 * M12 ) + ( M13 * M13 ) ); + scale.Y = (float)Math.Sqrt( ( M21 * M21 ) + ( M22 * M22 ) + ( M23 * M23 ) ); + scale.Z = (float)Math.Sqrt( ( M31 * M31 ) + ( M32 * M32 ) + ( M33 * M33 ) ); //If any of the scaling factors are zero, than the rotation matrix can not exist. - if (Math.Abs(scale.X) < MathUtil.ZeroTolerance || - Math.Abs(scale.Y) < MathUtil.ZeroTolerance || - Math.Abs(scale.Z) < MathUtil.ZeroTolerance) + if( Math.Abs( scale.X ) < MathUtil.ZeroTolerance || + Math.Abs( scale.Y ) < MathUtil.ZeroTolerance || + Math.Abs( scale.Z ) < MathUtil.ZeroTolerance ) { rotation = Matrix.Identity; return false; } // Calculate an perfect orthonormal matrix (no reflections) - var at = new Vec3(M31 / scale.Z, M32 / scale.Z, M33 / scale.Z); - var up = Vec3.Cross(at, new Vec3(M11 / scale.X, M12 / scale.X, M13 / scale.X)); - var right = Vec3.Cross(up, at); + var at = new Vec3( M31 / scale.Z, M32 / scale.Z, M33 / scale.Z ); + var up = Vec3.Cross( at, new Vec3( M11 / scale.X, M12 / scale.X, M13 / scale.X ) ); + var right = Vec3.Cross( up, at ); rotation = Identity; rotation.Right = right; @@ -752,9 +825,9 @@ namespace math rotation.Backward = at; // In case of reflexions - scale.X = Vec3.Dot(right, Right) > 0.0f ? scale.X : -scale.X; - scale.Y = Vec3.Dot(up, Up) > 0.0f ? scale.Y : -scale.Y; - scale.Z = Vec3.Dot(at, Backward) > 0.0f ? scale.Z : -scale.Z; + scale.X = Vec3.Dot( right, Right ) > 0.0f ? scale.X : -scale.X; + scale.Y = Vec3.Dot( up, Up ) > 0.0f ? scale.Y : -scale.Y; + scale.Z = Vec3.Dot( at, Backward ) > 0.0f ? scale.Z : -scale.Z; return true; } @@ -764,18 +837,18 @@ namespace math /// /// The first row to exchange. This is an index of the row starting at zero. /// The second row to exchange. This is an index of the row starting at zero. - public void ExchangeRows(int firstRow, int secondRow) + public void ExchangeRows( int firstRow, int secondRow ) { - if (firstRow < 0) - throw new ArgumentOutOfRangeException("firstRow", "The parameter firstRow must be greater than or equal to zero."); - if (firstRow > 3) - throw new ArgumentOutOfRangeException("firstRow", "The parameter firstRow must be less than or equal to three."); - if (secondRow < 0) - throw new ArgumentOutOfRangeException("secondRow", "The parameter secondRow must be greater than or equal to zero."); - if (secondRow > 3) - throw new ArgumentOutOfRangeException("secondRow", "The parameter secondRow must be less than or equal to three."); + if( firstRow < 0 ) + throw new ArgumentOutOfRangeException( "firstRow", "The parameter firstRow must be greater than or equal to zero." ); + if( firstRow > 3 ) + throw new ArgumentOutOfRangeException( "firstRow", "The parameter firstRow must be less than or equal to three." ); + if( secondRow < 0 ) + throw new ArgumentOutOfRangeException( "secondRow", "The parameter secondRow must be greater than or equal to zero." ); + if( secondRow > 3 ) + throw new ArgumentOutOfRangeException( "secondRow", "The parameter secondRow must be less than or equal to three." ); - if (firstRow == secondRow) + if( firstRow == secondRow ) return; float temp0 = this[secondRow, 0]; @@ -799,18 +872,18 @@ namespace math /// /// The first column to exchange. /// The second column to exchange. - public void ExchangeColumns(int firstColumn, int secondColumn) + public void ExchangeColumns( int firstColumn, int secondColumn ) { - if (firstColumn < 0) - throw new ArgumentOutOfRangeException("firstColumn", "The parameter firstColumn must be greater than or equal to zero."); - if (firstColumn > 3) - throw new ArgumentOutOfRangeException("firstColumn", "The parameter firstColumn must be less than or equal to three."); - if (secondColumn < 0) - throw new ArgumentOutOfRangeException("secondColumn", "The parameter secondColumn must be greater than or equal to zero."); - if (secondColumn > 3) - throw new ArgumentOutOfRangeException("secondColumn", "The parameter secondColumn must be less than or equal to three."); + if( firstColumn < 0 ) + throw new ArgumentOutOfRangeException( "firstColumn", "The parameter firstColumn must be greater than or equal to zero." ); + if( firstColumn > 3 ) + throw new ArgumentOutOfRangeException( "firstColumn", "The parameter firstColumn must be less than or equal to three." ); + if( secondColumn < 0 ) + throw new ArgumentOutOfRangeException( "secondColumn", "The parameter secondColumn must be greater than or equal to zero." ); + if( secondColumn > 3 ) + throw new ArgumentOutOfRangeException( "secondColumn", "The parameter secondColumn must be less than or equal to three." ); - if (firstColumn == secondColumn) + if( firstColumn == secondColumn ) return; float temp0 = this[0, secondColumn]; @@ -844,7 +917,7 @@ namespace math /// The first matrix to add. /// The second matrix to add. /// When the method completes, contains the sum of the two matrices. - public static void Add(ref Matrix left, ref Matrix right, out Matrix result) + public static void Add( ref Matrix left, ref Matrix right, out Matrix result ) { result.M11 = left.M11 + right.M11; result.M21 = left.M21 + right.M21; @@ -870,10 +943,10 @@ namespace math /// The first matrix to add. /// The second matrix to add. /// The sum of the two matrices. - public static Matrix Add(Matrix left, Matrix right) + public static Matrix Add( Matrix left, Matrix right ) { Matrix result; - Add(ref left, ref right, out result); + Add( ref left, ref right, out result ); return result; } @@ -883,7 +956,7 @@ namespace math /// The first matrix to subtract. /// The second matrix to subtract. /// When the method completes, contains the difference between the two matrices. - public static void Subtract(ref Matrix left, ref Matrix right, out Matrix result) + public static void Subtract( ref Matrix left, ref Matrix right, out Matrix result ) { result.M11 = left.M11 - right.M11; result.M21 = left.M21 - right.M21; @@ -909,10 +982,10 @@ namespace math /// The first matrix to subtract. /// The second matrix to subtract. /// The difference between the two matrices. - public static Matrix Subtract(Matrix left, Matrix right) + public static Matrix Subtract( Matrix left, Matrix right ) { Matrix result; - Subtract(ref left, ref right, out result); + Subtract( ref left, ref right, out result ); return result; } @@ -922,7 +995,7 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// When the method completes, contains the scaled matrix. - public static void Multiply(ref Matrix left, float right, out Matrix result) + public static void Multiply( ref Matrix left, float right, out Matrix result ) { result.M11 = left.M11 * right; result.M21 = left.M21 * right; @@ -948,10 +1021,10 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// The scaled matrix. - public static Matrix Multiply(Matrix left, float right) + public static Matrix Multiply( Matrix left, float right ) { Matrix result; - Multiply(ref left, right, out result); + Multiply( ref left, right, out result ); return result; } @@ -961,24 +1034,24 @@ namespace math /// The first matrix to multiply. /// The second matrix to multiply. /// The product of the two matrices. - public static void MultiplyTo(ref Matrix left, ref Matrix right, out Matrix result) + public static void MultiplyTo( ref Matrix left, ref Matrix right, out Matrix result ) { - result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41); - result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41); - result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41); - result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41); - result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42); - result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42); - result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42); - result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42); - result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43); - result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43); - result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43); - result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43); - result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44); - result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44); - result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44); - result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44); + result.M11 = ( left.M11 * right.M11 ) + ( left.M12 * right.M21 ) + ( left.M13 * right.M31 ) + ( left.M14 * right.M41 ); + result.M21 = ( left.M21 * right.M11 ) + ( left.M22 * right.M21 ) + ( left.M23 * right.M31 ) + ( left.M24 * right.M41 ); + result.M31 = ( left.M31 * right.M11 ) + ( left.M32 * right.M21 ) + ( left.M33 * right.M31 ) + ( left.M34 * right.M41 ); + result.M41 = ( left.M41 * right.M11 ) + ( left.M42 * right.M21 ) + ( left.M43 * right.M31 ) + ( left.M44 * right.M41 ); + result.M12 = ( left.M11 * right.M12 ) + ( left.M12 * right.M22 ) + ( left.M13 * right.M32 ) + ( left.M14 * right.M42 ); + result.M22 = ( left.M21 * right.M12 ) + ( left.M22 * right.M22 ) + ( left.M23 * right.M32 ) + ( left.M24 * right.M42 ); + result.M32 = ( left.M31 * right.M12 ) + ( left.M32 * right.M22 ) + ( left.M33 * right.M32 ) + ( left.M34 * right.M42 ); + result.M42 = ( left.M41 * right.M12 ) + ( left.M42 * right.M22 ) + ( left.M43 * right.M32 ) + ( left.M44 * right.M42 ); + result.M13 = ( left.M11 * right.M13 ) + ( left.M12 * right.M23 ) + ( left.M13 * right.M33 ) + ( left.M14 * right.M43 ); + result.M23 = ( left.M21 * right.M13 ) + ( left.M22 * right.M23 ) + ( left.M23 * right.M33 ) + ( left.M24 * right.M43 ); + result.M33 = ( left.M31 * right.M13 ) + ( left.M32 * right.M23 ) + ( left.M33 * right.M33 ) + ( left.M34 * right.M43 ); + result.M43 = ( left.M41 * right.M13 ) + ( left.M42 * right.M23 ) + ( left.M43 * right.M33 ) + ( left.M44 * right.M43 ); + result.M14 = ( left.M11 * right.M14 ) + ( left.M12 * right.M24 ) + ( left.M13 * right.M34 ) + ( left.M14 * right.M44 ); + result.M24 = ( left.M21 * right.M14 ) + ( left.M22 * right.M24 ) + ( left.M23 * right.M34 ) + ( left.M24 * right.M44 ); + result.M34 = ( left.M31 * right.M14 ) + ( left.M32 * right.M24 ) + ( left.M33 * right.M34 ) + ( left.M34 * right.M44 ); + result.M44 = ( left.M41 * right.M14 ) + ( left.M42 * right.M24 ) + ( left.M43 * right.M34 ) + ( left.M44 * right.M44 ); } /// @@ -987,24 +1060,24 @@ namespace math /// The first matrix to multiply. /// The second matrix to multiply. /// The product of the two matrices. - public static void Multiply(ref Matrix left, ref Matrix right, out Matrix result) + public static void Multiply( ref Matrix left, ref Matrix right, out Matrix result ) { - result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41); - result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41); - result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41); - result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41); - result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42); - result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42); - result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42); - result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42); - result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43); - result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43); - result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43); - result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43); - result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44); - result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44); - result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44); - result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44); + result.M11 = ( left.M11 * right.M11 ) + ( left.M12 * right.M21 ) + ( left.M13 * right.M31 ) + ( left.M14 * right.M41 ); + result.M21 = ( left.M21 * right.M11 ) + ( left.M22 * right.M21 ) + ( left.M23 * right.M31 ) + ( left.M24 * right.M41 ); + result.M31 = ( left.M31 * right.M11 ) + ( left.M32 * right.M21 ) + ( left.M33 * right.M31 ) + ( left.M34 * right.M41 ); + result.M41 = ( left.M41 * right.M11 ) + ( left.M42 * right.M21 ) + ( left.M43 * right.M31 ) + ( left.M44 * right.M41 ); + result.M12 = ( left.M11 * right.M12 ) + ( left.M12 * right.M22 ) + ( left.M13 * right.M32 ) + ( left.M14 * right.M42 ); + result.M22 = ( left.M21 * right.M12 ) + ( left.M22 * right.M22 ) + ( left.M23 * right.M32 ) + ( left.M24 * right.M42 ); + result.M32 = ( left.M31 * right.M12 ) + ( left.M32 * right.M22 ) + ( left.M33 * right.M32 ) + ( left.M34 * right.M42 ); + result.M42 = ( left.M41 * right.M12 ) + ( left.M42 * right.M22 ) + ( left.M43 * right.M32 ) + ( left.M44 * right.M42 ); + result.M13 = ( left.M11 * right.M13 ) + ( left.M12 * right.M23 ) + ( left.M13 * right.M33 ) + ( left.M14 * right.M43 ); + result.M23 = ( left.M21 * right.M13 ) + ( left.M22 * right.M23 ) + ( left.M23 * right.M33 ) + ( left.M24 * right.M43 ); + result.M33 = ( left.M31 * right.M13 ) + ( left.M32 * right.M23 ) + ( left.M33 * right.M33 ) + ( left.M34 * right.M43 ); + result.M43 = ( left.M41 * right.M13 ) + ( left.M42 * right.M23 ) + ( left.M43 * right.M33 ) + ( left.M44 * right.M43 ); + result.M14 = ( left.M11 * right.M14 ) + ( left.M12 * right.M24 ) + ( left.M13 * right.M34 ) + ( left.M14 * right.M44 ); + result.M24 = ( left.M21 * right.M14 ) + ( left.M22 * right.M24 ) + ( left.M23 * right.M34 ) + ( left.M24 * right.M44 ); + result.M34 = ( left.M31 * right.M14 ) + ( left.M32 * right.M24 ) + ( left.M33 * right.M34 ) + ( left.M34 * right.M44 ); + result.M44 = ( left.M41 * right.M14 ) + ( left.M42 * right.M24 ) + ( left.M43 * right.M34 ) + ( left.M44 * right.M44 ); } /// @@ -1013,24 +1086,24 @@ namespace math /// The first matrix to multiply. /// The second matrix to multiply. /// The product of the two matrices. - public static void MultiplyRef(ref Matrix left, ref Matrix right, ref Matrix result) + public static void MultiplyRef( ref Matrix left, ref Matrix right, ref Matrix result ) { - result.M11 = (left.M11 * right.M11) + (left.M12 * right.M21) + (left.M13 * right.M31) + (left.M14 * right.M41); - result.M21 = (left.M21 * right.M11) + (left.M22 * right.M21) + (left.M23 * right.M31) + (left.M24 * right.M41); - result.M31 = (left.M31 * right.M11) + (left.M32 * right.M21) + (left.M33 * right.M31) + (left.M34 * right.M41); - result.M41 = (left.M41 * right.M11) + (left.M42 * right.M21) + (left.M43 * right.M31) + (left.M44 * right.M41); - result.M12 = (left.M11 * right.M12) + (left.M12 * right.M22) + (left.M13 * right.M32) + (left.M14 * right.M42); - result.M22 = (left.M21 * right.M12) + (left.M22 * right.M22) + (left.M23 * right.M32) + (left.M24 * right.M42); - result.M32 = (left.M31 * right.M12) + (left.M32 * right.M22) + (left.M33 * right.M32) + (left.M34 * right.M42); - result.M42 = (left.M41 * right.M12) + (left.M42 * right.M22) + (left.M43 * right.M32) + (left.M44 * right.M42); - result.M13 = (left.M11 * right.M13) + (left.M12 * right.M23) + (left.M13 * right.M33) + (left.M14 * right.M43); - result.M23 = (left.M21 * right.M13) + (left.M22 * right.M23) + (left.M23 * right.M33) + (left.M24 * right.M43); - result.M33 = (left.M31 * right.M13) + (left.M32 * right.M23) + (left.M33 * right.M33) + (left.M34 * right.M43); - result.M43 = (left.M41 * right.M13) + (left.M42 * right.M23) + (left.M43 * right.M33) + (left.M44 * right.M43); - result.M14 = (left.M11 * right.M14) + (left.M12 * right.M24) + (left.M13 * right.M34) + (left.M14 * right.M44); - result.M24 = (left.M21 * right.M14) + (left.M22 * right.M24) + (left.M23 * right.M34) + (left.M24 * right.M44); - result.M34 = (left.M31 * right.M14) + (left.M32 * right.M24) + (left.M33 * right.M34) + (left.M34 * right.M44); - result.M44 = (left.M41 * right.M14) + (left.M42 * right.M24) + (left.M43 * right.M34) + (left.M44 * right.M44); + result.M11 = ( left.M11 * right.M11 ) + ( left.M12 * right.M21 ) + ( left.M13 * right.M31 ) + ( left.M14 * right.M41 ); + result.M21 = ( left.M21 * right.M11 ) + ( left.M22 * right.M21 ) + ( left.M23 * right.M31 ) + ( left.M24 * right.M41 ); + result.M31 = ( left.M31 * right.M11 ) + ( left.M32 * right.M21 ) + ( left.M33 * right.M31 ) + ( left.M34 * right.M41 ); + result.M41 = ( left.M41 * right.M11 ) + ( left.M42 * right.M21 ) + ( left.M43 * right.M31 ) + ( left.M44 * right.M41 ); + result.M12 = ( left.M11 * right.M12 ) + ( left.M12 * right.M22 ) + ( left.M13 * right.M32 ) + ( left.M14 * right.M42 ); + result.M22 = ( left.M21 * right.M12 ) + ( left.M22 * right.M22 ) + ( left.M23 * right.M32 ) + ( left.M24 * right.M42 ); + result.M32 = ( left.M31 * right.M12 ) + ( left.M32 * right.M22 ) + ( left.M33 * right.M32 ) + ( left.M34 * right.M42 ); + result.M42 = ( left.M41 * right.M12 ) + ( left.M42 * right.M22 ) + ( left.M43 * right.M32 ) + ( left.M44 * right.M42 ); + result.M13 = ( left.M11 * right.M13 ) + ( left.M12 * right.M23 ) + ( left.M13 * right.M33 ) + ( left.M14 * right.M43 ); + result.M23 = ( left.M21 * right.M13 ) + ( left.M22 * right.M23 ) + ( left.M23 * right.M33 ) + ( left.M24 * right.M43 ); + result.M33 = ( left.M31 * right.M13 ) + ( left.M32 * right.M23 ) + ( left.M33 * right.M33 ) + ( left.M34 * right.M43 ); + result.M43 = ( left.M41 * right.M13 ) + ( left.M42 * right.M23 ) + ( left.M43 * right.M33 ) + ( left.M44 * right.M43 ); + result.M14 = ( left.M11 * right.M14 ) + ( left.M12 * right.M24 ) + ( left.M13 * right.M34 ) + ( left.M14 * right.M44 ); + result.M24 = ( left.M21 * right.M14 ) + ( left.M22 * right.M24 ) + ( left.M23 * right.M34 ) + ( left.M24 * right.M44 ); + result.M34 = ( left.M31 * right.M14 ) + ( left.M32 * right.M24 ) + ( left.M33 * right.M34 ) + ( left.M34 * right.M44 ); + result.M44 = ( left.M41 * right.M14 ) + ( left.M42 * right.M24 ) + ( left.M43 * right.M34 ) + ( left.M44 * right.M44 ); } /// @@ -1039,10 +1112,10 @@ namespace math /// The first matrix to multiply. /// The second matrix to multiply. /// The product of the two matrices. - public static Matrix Multiply(Matrix left, Matrix right) + public static Matrix Multiply( Matrix left, Matrix right ) { Matrix result; - Multiply(ref left, ref right, out result); + Multiply( ref left, ref right, out result ); return result; } @@ -1052,7 +1125,7 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// When the method completes, contains the scaled matrix. - public static void Divide(ref Matrix left, float right, out Matrix result) + public static void Divide( ref Matrix left, float right, out Matrix result ) { float inv = 1.0f / right; @@ -1080,10 +1153,10 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// The scaled matrix. - public static Matrix Divide(Matrix left, float right) + public static Matrix Divide( Matrix left, float right ) { Matrix result; - Divide(ref left, right, out result); + Divide( ref left, right, out result ); return result; } @@ -1093,7 +1166,7 @@ namespace math /// The first matrix to divide. /// The second matrix to divide. /// When the method completes, contains the quotient of the two matrices. - public static void Divide(ref Matrix left, ref Matrix right, out Matrix result) + public static void Divide( ref Matrix left, ref Matrix right, out Matrix result ) { result.M11 = left.M11 / right.M11; result.M21 = left.M21 / right.M21; @@ -1119,10 +1192,10 @@ namespace math /// The first matrix to divide. /// The second matrix to divide. /// The quotient of the two matrices. - public static Matrix Divide(Matrix left, Matrix right) + public static Matrix Divide( Matrix left, Matrix right ) { Matrix result; - Divide(ref left, ref right, out result); + Divide( ref left, ref right, out result ); return result; } @@ -1133,21 +1206,21 @@ namespace math /// The exponent to raise the matrix to. /// When the method completes, contains the exponential matrix. /// Thrown when the is negative. - public static void Exponent(ref Matrix value, int exponent, out Matrix result) + public static void Exponent( ref Matrix value, int exponent, out Matrix result ) { //Source: http://rosettacode.org //Refrence: http://rosettacode.org/wiki/Matrix-exponentiation_operator - if (exponent < 0) - throw new ArgumentOutOfRangeException("exponent", "The exponent can not be negative."); + if( exponent < 0 ) + throw new ArgumentOutOfRangeException( "exponent", "The exponent can not be negative." ); - if (exponent == 0) + if( exponent == 0 ) { result = Matrix.Identity; return; } - if (exponent == 1) + if( exponent == 1 ) { result = value; return; @@ -1156,14 +1229,14 @@ namespace math Matrix identity = Matrix.Identity; Matrix temp = value; - while (true) + while( true ) { - if ((exponent & 1) != 0) + if( ( exponent & 1 ) != 0 ) identity = identity * temp; exponent /= 2; - if (exponent > 0) + if( exponent > 0 ) temp *= temp; else break; @@ -1179,10 +1252,10 @@ namespace math /// The exponent to raise the matrix to. /// The exponential matrix. /// Thrown when the is negative. - public static Matrix Exponent(Matrix value, int exponent) + public static Matrix Exponent( Matrix value, int exponent ) { Matrix result; - Exponent(ref value, exponent, out result); + Exponent( ref value, exponent, out result ); return result; } @@ -1191,7 +1264,7 @@ namespace math /// /// The matrix to be negated. /// When the method completes, contains the negated matrix. - public static void Negate(ref Matrix value, out Matrix result) + public static void Negate( ref Matrix value, out Matrix result ) { result.M11 = -value.M11; result.M21 = -value.M21; @@ -1216,10 +1289,10 @@ namespace math /// /// The matrix to be negated. /// The negated matrix. - public static Matrix Negate(Matrix value) + public static Matrix Negate( Matrix value ) { Matrix result; - Negate(ref value, out result); + Negate( ref value, out result ); return result; } @@ -1233,26 +1306,26 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Matrix start, ref Matrix end, float amount, out Matrix result) + public static void Lerp( ref Matrix start, ref Matrix end, float amount, out Matrix result ) { - result.M11 = start.M11 + ((end.M11 - start.M11) * amount); - result.M21 = start.M21 + ((end.M21 - start.M21) * amount); - result.M31 = start.M31 + ((end.M31 - start.M31) * amount); - result.M41 = start.M41 + ((end.M41 - start.M41) * amount); - result.M12 = start.M12 + ((end.M12 - start.M12) * amount); - result.M22 = start.M22 + ((end.M22 - start.M22) * amount); - result.M32 = start.M32 + ((end.M32 - start.M32) * amount); - result.M42 = start.M42 + ((end.M42 - start.M42) * amount); - result.M13 = start.M13 + ((end.M13 - start.M13) * amount); - result.M23 = start.M23 + ((end.M23 - start.M23) * amount); - result.M33 = start.M33 + ((end.M33 - start.M33) * amount); - result.M43 = start.M43 + ((end.M43 - start.M43) * amount); - result.M14 = start.M14 + ((end.M14 - start.M14) * amount); - result.M24 = start.M24 + ((end.M24 - start.M24) * amount); - result.M34 = start.M34 + ((end.M34 - start.M34) * amount); - result.M44 = start.M44 + ((end.M44 - start.M44) * amount); + result.M11 = start.M11 + ( ( end.M11 - start.M11 ) * amount ); + result.M21 = start.M21 + ( ( end.M21 - start.M21 ) * amount ); + result.M31 = start.M31 + ( ( end.M31 - start.M31 ) * amount ); + result.M41 = start.M41 + ( ( end.M41 - start.M41 ) * amount ); + result.M12 = start.M12 + ( ( end.M12 - start.M12 ) * amount ); + result.M22 = start.M22 + ( ( end.M22 - start.M22 ) * amount ); + result.M32 = start.M32 + ( ( end.M32 - start.M32 ) * amount ); + result.M42 = start.M42 + ( ( end.M42 - start.M42 ) * amount ); + result.M13 = start.M13 + ( ( end.M13 - start.M13 ) * amount ); + result.M23 = start.M23 + ( ( end.M23 - start.M23 ) * amount ); + result.M33 = start.M33 + ( ( end.M33 - start.M33 ) * amount ); + result.M43 = start.M43 + ( ( end.M43 - start.M43 ) * amount ); + result.M14 = start.M14 + ( ( end.M14 - start.M14 ) * amount ); + result.M24 = start.M24 + ( ( end.M24 - start.M24 ) * amount ); + result.M34 = start.M34 + ( ( end.M34 - start.M34 ) * amount ); + result.M44 = start.M44 + ( ( end.M44 - start.M44 ) * amount ); } /// @@ -1265,12 +1338,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Matrix Lerp(Matrix start, Matrix end, float amount) + public static Matrix Lerp( Matrix start, Matrix end, float amount ) { Matrix result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -1281,27 +1354,27 @@ namespace math /// End matrix. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two matrices. - public static void SmoothStep(ref Matrix start, ref Matrix end, float amount, out Matrix result) + public static void SmoothStep( ref Matrix start, ref Matrix end, float amount, out Matrix result ) { - amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0f ) ? 1.0f : ( ( amount < 0.0f ) ? 0.0f : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.M11 = start.M11 + ((end.M11 - start.M11) * amount); - result.M21 = start.M21 + ((end.M21 - start.M21) * amount); - result.M31 = start.M31 + ((end.M31 - start.M31) * amount); - result.M41 = start.M41 + ((end.M41 - start.M41) * amount); - result.M12 = start.M12 + ((end.M12 - start.M12) * amount); - result.M22 = start.M22 + ((end.M22 - start.M22) * amount); - result.M32 = start.M32 + ((end.M32 - start.M32) * amount); - result.M42 = start.M42 + ((end.M42 - start.M42) * amount); - result.M13 = start.M13 + ((end.M13 - start.M13) * amount); - result.M23 = start.M23 + ((end.M23 - start.M23) * amount); - result.M33 = start.M33 + ((end.M33 - start.M33) * amount); - result.M43 = start.M43 + ((end.M43 - start.M43) * amount); - result.M14 = start.M14 + ((end.M14 - start.M14) * amount); - result.M24 = start.M24 + ((end.M24 - start.M24) * amount); - result.M34 = start.M34 + ((end.M34 - start.M34) * amount); - result.M44 = start.M44 + ((end.M44 - start.M44) * amount); + result.M11 = start.M11 + ( ( end.M11 - start.M11 ) * amount ); + result.M21 = start.M21 + ( ( end.M21 - start.M21 ) * amount ); + result.M31 = start.M31 + ( ( end.M31 - start.M31 ) * amount ); + result.M41 = start.M41 + ( ( end.M41 - start.M41 ) * amount ); + result.M12 = start.M12 + ( ( end.M12 - start.M12 ) * amount ); + result.M22 = start.M22 + ( ( end.M22 - start.M22 ) * amount ); + result.M32 = start.M32 + ( ( end.M32 - start.M32 ) * amount ); + result.M42 = start.M42 + ( ( end.M42 - start.M42 ) * amount ); + result.M13 = start.M13 + ( ( end.M13 - start.M13 ) * amount ); + result.M23 = start.M23 + ( ( end.M23 - start.M23 ) * amount ); + result.M33 = start.M33 + ( ( end.M33 - start.M33 ) * amount ); + result.M43 = start.M43 + ( ( end.M43 - start.M43 ) * amount ); + result.M14 = start.M14 + ( ( end.M14 - start.M14 ) * amount ); + result.M24 = start.M24 + ( ( end.M24 - start.M24 ) * amount ); + result.M34 = start.M34 + ( ( end.M34 - start.M34 ) * amount ); + result.M44 = start.M44 + ( ( end.M44 - start.M44 ) * amount ); } /// @@ -1311,10 +1384,10 @@ namespace math /// End matrix. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two matrices. - public static Matrix SmoothStep(Matrix start, Matrix end, float amount) + public static Matrix SmoothStep( Matrix start, Matrix end, float amount ) { Matrix result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -1323,7 +1396,7 @@ namespace math /// /// The matrix whose transpose is to be calculated. /// When the method completes, contains the transpose of the specified matrix. - public static void Transpose(ref Matrix value, out Matrix result) + public static void Transpose( ref Matrix value, out Matrix result ) { result = new Matrix( value.M11, @@ -1341,7 +1414,7 @@ namespace math value.M14, value.M24, value.M34, - value.M44); + value.M44 ); } /// @@ -1349,7 +1422,7 @@ namespace math /// /// The matrix whose transpose is to be calculated. /// The transpose of the specified matrix. - public static Matrix Transpose(Matrix value) + public static Matrix Transpose( Matrix value ) { value.Transpose(); return value; @@ -1360,14 +1433,14 @@ namespace math /// /// The matrix whose inverse is to be calculated. /// When the method completes, contains the inverse of the specified matrix. - public static void Invert(ref Matrix value, out Matrix result) + public static void Invert( ref Matrix value, out Matrix result ) { - float b0 = (value.M31 * value.M42) - (value.M32 * value.M41); - float b1 = (value.M31 * value.M43) - (value.M33 * value.M41); - float b2 = (value.M34 * value.M41) - (value.M31 * value.M44); - float b3 = (value.M32 * value.M43) - (value.M33 * value.M42); - float b4 = (value.M34 * value.M42) - (value.M32 * value.M44); - float b5 = (value.M33 * value.M44) - (value.M34 * value.M43); + float b0 = ( value.M31 * value.M42 ) - ( value.M32 * value.M41 ); + float b1 = ( value.M31 * value.M43 ) - ( value.M33 * value.M41 ); + float b2 = ( value.M34 * value.M41 ) - ( value.M31 * value.M44 ); + float b3 = ( value.M32 * value.M43 ) - ( value.M33 * value.M42 ); + float b4 = ( value.M34 * value.M42 ) - ( value.M32 * value.M44 ); + float b5 = ( value.M33 * value.M44 ) - ( value.M34 * value.M43 ); float d11 = value.M22 * b5 + value.M23 * b4 + value.M24 * b3; float d12 = value.M21 * b5 + value.M23 * b2 + value.M24 * b1; @@ -1375,7 +1448,7 @@ namespace math float d14 = value.M21 * b3 + value.M22 * -b1 + value.M23 * b0; float det = value.M11 * d11 - value.M12 * d12 + value.M13 * d13 - value.M14 * d14; - if (Math.Abs(det) == 0.0f) + if( Math.Abs( det ) == 0.0f ) { result = Matrix.Zero; return; @@ -1383,12 +1456,12 @@ namespace math det = 1f / det; - float a0 = (value.M11 * value.M22) - (value.M12 * value.M21); - float a1 = (value.M11 * value.M23) - (value.M13 * value.M21); - float a2 = (value.M14 * value.M21) - (value.M11 * value.M24); - float a3 = (value.M12 * value.M23) - (value.M13 * value.M22); - float a4 = (value.M14 * value.M22) - (value.M12 * value.M24); - float a5 = (value.M13 * value.M24) - (value.M14 * value.M23); + float a0 = ( value.M11 * value.M22 ) - ( value.M12 * value.M21 ); + float a1 = ( value.M11 * value.M23 ) - ( value.M13 * value.M21 ); + float a2 = ( value.M14 * value.M21 ) - ( value.M11 * value.M24 ); + float a3 = ( value.M12 * value.M23 ) - ( value.M13 * value.M22 ); + float a4 = ( value.M14 * value.M22 ) - ( value.M12 * value.M24 ); + float a5 = ( value.M13 * value.M24 ) - ( value.M14 * value.M23 ); float d21 = value.M12 * b5 + value.M13 * b4 + value.M14 * b3; float d22 = value.M11 * b5 + value.M13 * b2 + value.M14 * b1; @@ -1405,10 +1478,22 @@ namespace math float d43 = value.M31 * -a4 + value.M32 * a2 + value.M34 * a0; float d44 = value.M31 * a3 + value.M32 * -a1 + value.M33 * a0; - result.M11 = +d11 * det; result.M12 = -d21 * det; result.M13 = +d31 * det; result.M14 = -d41 * det; - result.M21 = -d12 * det; result.M22 = +d22 * det; result.M23 = -d32 * det; result.M24 = +d42 * det; - result.M31 = +d13 * det; result.M32 = -d23 * det; result.M33 = +d33 * det; result.M34 = -d43 * det; - result.M41 = -d14 * det; result.M42 = +d24 * det; result.M43 = -d34 * det; result.M44 = +d44 * det; + result.M11 = +d11 * det; + result.M12 = -d21 * det; + result.M13 = +d31 * det; + result.M14 = -d41 * det; + result.M21 = -d12 * det; + result.M22 = +d22 * det; + result.M23 = -d32 * det; + result.M24 = +d42 * det; + result.M31 = +d13 * det; + result.M32 = -d23 * det; + result.M33 = +d33 * det; + result.M34 = -d43 * det; + result.M41 = -d14 * det; + result.M42 = +d24 * det; + result.M43 = -d34 * det; + result.M44 = +d44 * det; } /// @@ -1416,7 +1501,7 @@ namespace math /// /// The matrix whose inverse is to be calculated. /// The inverse of the specified matrix. - public static Matrix Invert(Matrix value) + public static Matrix Invert( Matrix value ) { value.Invert(); return value; @@ -1438,7 +1523,7 @@ namespace math /// If you wish for this operation to be performed on the columns, first transpose the /// input and than transpose the output. /// - public static void Orthogonalize(ref Matrix value, out Matrix result) + public static void Orthogonalize( ref Matrix value, out Matrix result ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -1449,14 +1534,14 @@ namespace math //By separating the above algorithm into multiple lines, we actually increase accuracy. result = value; - result.Row2 = result.Row2 - (Vec4.Dot(result.Row1, result.Row2) / Vec4.Dot(result.Row1, result.Row1)) * result.Row1; + result.Row2 = result.Row2 - ( Vec4.Dot( result.Row1, result.Row2 ) / Vec4.Dot( result.Row1, result.Row1 ) ) * result.Row1; - result.Row3 = result.Row3 - (Vec4.Dot(result.Row1, result.Row3) / Vec4.Dot(result.Row1, result.Row1)) * result.Row1; - result.Row3 = result.Row3 - (Vec4.Dot(result.Row2, result.Row3) / Vec4.Dot(result.Row2, result.Row2)) * result.Row2; + result.Row3 = result.Row3 - ( Vec4.Dot( result.Row1, result.Row3 ) / Vec4.Dot( result.Row1, result.Row1 ) ) * result.Row1; + result.Row3 = result.Row3 - ( Vec4.Dot( result.Row2, result.Row3 ) / Vec4.Dot( result.Row2, result.Row2 ) ) * result.Row2; - result.Row4 = result.Row4 - (Vec4.Dot(result.Row1, result.Row4) / Vec4.Dot(result.Row1, result.Row1)) * result.Row1; - result.Row4 = result.Row4 - (Vec4.Dot(result.Row2, result.Row4) / Vec4.Dot(result.Row2, result.Row2)) * result.Row2; - result.Row4 = result.Row4 - (Vec4.Dot(result.Row3, result.Row4) / Vec4.Dot(result.Row3, result.Row3)) * result.Row3; + result.Row4 = result.Row4 - ( Vec4.Dot( result.Row1, result.Row4 ) / Vec4.Dot( result.Row1, result.Row1 ) ) * result.Row1; + result.Row4 = result.Row4 - ( Vec4.Dot( result.Row2, result.Row4 ) / Vec4.Dot( result.Row2, result.Row2 ) ) * result.Row2; + result.Row4 = result.Row4 - ( Vec4.Dot( result.Row3, result.Row4 ) / Vec4.Dot( result.Row3, result.Row3 ) ) * result.Row3; } /// @@ -1475,10 +1560,10 @@ namespace math /// If you wish for this operation to be performed on the columns, first transpose the /// input and than transpose the output. /// - public static Matrix Orthogonalize(Matrix value) + public static Matrix Orthogonalize( Matrix value ) { Matrix result; - Orthogonalize(ref value, out result); + Orthogonalize( ref value, out result ); return result; } @@ -1500,7 +1585,7 @@ namespace math /// If you wish for this operation to be performed on the columns, first transpose the /// input and than transpose the output. /// - public static void Orthonormalize(ref Matrix value, out Matrix result) + public static void Orthonormalize( ref Matrix value, out Matrix result ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -1513,19 +1598,19 @@ namespace math //By separating the above algorithm into multiple lines, we actually increase accuracy. result = value; - result.Row1 = Vec4.Normalize(result.Row1); + result.Row1 = Vec4.Normalize( result.Row1 ); - result.Row2 = result.Row2 - Vec4.Dot(result.Row1, result.Row2) * result.Row1; - result.Row2 = Vec4.Normalize(result.Row2); + result.Row2 = result.Row2 - Vec4.Dot( result.Row1, result.Row2 ) * result.Row1; + result.Row2 = Vec4.Normalize( result.Row2 ); - result.Row3 = result.Row3 - Vec4.Dot(result.Row1, result.Row3) * result.Row1; - result.Row3 = result.Row3 - Vec4.Dot(result.Row2, result.Row3) * result.Row2; - result.Row3 = Vec4.Normalize(result.Row3); + result.Row3 = result.Row3 - Vec4.Dot( result.Row1, result.Row3 ) * result.Row1; + result.Row3 = result.Row3 - Vec4.Dot( result.Row2, result.Row3 ) * result.Row2; + result.Row3 = Vec4.Normalize( result.Row3 ); - result.Row4 = result.Row4 - Vec4.Dot(result.Row1, result.Row4) * result.Row1; - result.Row4 = result.Row4 - Vec4.Dot(result.Row2, result.Row4) * result.Row2; - result.Row4 = result.Row4 - Vec4.Dot(result.Row3, result.Row4) * result.Row3; - result.Row4 = Vec4.Normalize(result.Row4); + result.Row4 = result.Row4 - Vec4.Dot( result.Row1, result.Row4 ) * result.Row1; + result.Row4 = result.Row4 - Vec4.Dot( result.Row2, result.Row4 ) * result.Row2; + result.Row4 = result.Row4 - Vec4.Dot( result.Row3, result.Row4 ) * result.Row3; + result.Row4 = Vec4.Normalize( result.Row4 ); } /// @@ -1546,10 +1631,10 @@ namespace math /// If you wish for this operation to be performed on the columns, first transpose the /// input and than transpose the output. /// - public static Matrix Orthonormalize(Matrix value) + public static Matrix Orthonormalize( Matrix value ) { Matrix result; - Orthonormalize(ref value, out result); + Orthonormalize( ref value, out result ); return result; } @@ -1564,7 +1649,7 @@ namespace math /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static void UpperTriangularForm(ref Matrix value, out Matrix result) + public static void UpperTriangularForm( ref Matrix value, out Matrix result ) { //Adapted from the row echelon code. result = value; @@ -1572,37 +1657,37 @@ namespace math int rowcount = 4; int columncount = 4; - for (int r = 0; r < rowcount; ++r) + for( int r = 0; r < rowcount; ++r ) { - if (columncount <= lead) + if( columncount <= lead ) return; int i = r; - while (Math.Abs(result[i, lead]) < MathUtil.ZeroTolerance) + while( Math.Abs( result[i, lead] ) < MathUtil.ZeroTolerance ) { i++; - if (i == rowcount) + if( i == rowcount ) { i = r; lead++; - if (lead == columncount) + if( lead == columncount ) return; } } - if (i != r) + if( i != r ) { - result.ExchangeRows(i, r); + result.ExchangeRows( i, r ); } float multiplier = 1f / result[r, lead]; - for (; i < rowcount; ++i) + for( ; i < rowcount; ++i ) { - if (i != r) + if( i != r ) { result[i, 0] -= result[r, 0] * multiplier * result[i, lead]; result[i, 1] -= result[r, 1] * multiplier * result[i, lead]; @@ -1626,10 +1711,10 @@ namespace math /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static Matrix UpperTriangularForm(Matrix value) + public static Matrix UpperTriangularForm( Matrix value ) { Matrix result; - UpperTriangularForm(ref value, out result); + UpperTriangularForm( ref value, out result ); return result; } @@ -1644,47 +1729,47 @@ namespace math /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static void LowerTriangularForm(ref Matrix value, out Matrix result) + public static void LowerTriangularForm( ref Matrix value, out Matrix result ) { //Adapted from the row echelon code. Matrix temp = value; - Matrix.Transpose(ref temp, out result); + Matrix.Transpose( ref temp, out result ); int lead = 0; int rowcount = 4; int columncount = 4; - for (int r = 0; r < rowcount; ++r) + for( int r = 0; r < rowcount; ++r ) { - if (columncount <= lead) + if( columncount <= lead ) return; int i = r; - while (Math.Abs(result[i, lead]) < MathUtil.ZeroTolerance) + while( Math.Abs( result[i, lead] ) < MathUtil.ZeroTolerance ) { i++; - if (i == rowcount) + if( i == rowcount ) { i = r; lead++; - if (lead == columncount) + if( lead == columncount ) return; } } - if (i != r) + if( i != r ) { - result.ExchangeRows(i, r); + result.ExchangeRows( i, r ); } float multiplier = 1f / result[r, lead]; - for (; i < rowcount; ++i) + for( ; i < rowcount; ++i ) { - if (i != r) + if( i != r ) { result[i, 0] -= result[r, 0] * multiplier * result[i, lead]; result[i, 1] -= result[r, 1] * multiplier * result[i, lead]; @@ -1696,7 +1781,7 @@ namespace math lead++; } - Matrix.Transpose(ref result, out result); + Matrix.Transpose( ref result, out result ); } /// @@ -1710,10 +1795,10 @@ namespace math /// of linear equations, than this often means that either no solution exists or an infinite /// number of solutions exist. /// - public static Matrix LowerTriangularForm(Matrix value) + public static Matrix LowerTriangularForm( Matrix value ) { Matrix result; - LowerTriangularForm(ref value, out result); + LowerTriangularForm( ref value, out result ); return result; } @@ -1722,7 +1807,7 @@ namespace math /// /// The matrix to put into row echelon form. /// When the method completes, contains the row echelon form of the matrix. - public static void RowEchelonForm(ref Matrix value, out Matrix result) + public static void RowEchelonForm( ref Matrix value, out Matrix result ) { //Source: Wikipedia psuedo code //Reference: http://en.wikipedia.org/wiki/Row_echelon_form#Pseudocode @@ -1732,30 +1817,30 @@ namespace math int rowcount = 4; int columncount = 4; - for (int r = 0; r < rowcount; ++r) + for( int r = 0; r < rowcount; ++r ) { - if (columncount <= lead) + if( columncount <= lead ) return; int i = r; - while (Math.Abs(result[i, lead]) < MathUtil.ZeroTolerance) + while( Math.Abs( result[i, lead] ) < MathUtil.ZeroTolerance ) { i++; - if (i == rowcount) + if( i == rowcount ) { i = r; lead++; - if (lead == columncount) + if( lead == columncount ) return; } } - if (i != r) + if( i != r ) { - result.ExchangeRows(i, r); + result.ExchangeRows( i, r ); } float multiplier = 1f / result[r, lead]; @@ -1764,9 +1849,9 @@ namespace math result[r, 2] *= multiplier; result[r, 3] *= multiplier; - for (; i < rowcount; ++i) + for( ; i < rowcount; ++i ) { - if (i != r) + if( i != r ) { result[i, 0] -= result[r, 0] * result[i, lead]; result[i, 1] -= result[r, 1] * result[i, lead]; @@ -1784,10 +1869,10 @@ namespace math /// /// The matrix to put into row echelon form. /// When the method completes, contains the row echelon form of the matrix. - public static Matrix RowEchelonForm(Matrix value) + public static Matrix RowEchelonForm( Matrix value ) { Matrix result; - RowEchelonForm(ref value, out result); + RowEchelonForm( ref value, out result ); return result; } @@ -1808,7 +1893,7 @@ namespace math /// the will contain the solution for the system. It is up to the user /// to analyze both the input and the result to determine if a solution really exists. /// - public static void ReducedRowEchelonForm(ref Matrix value, ref Vec4 augment, out Matrix result, out Vec4 augmentResult) + public static void ReducedRowEchelonForm( ref Matrix value, ref Vec4 augment, out Matrix result, out Vec4 augmentResult ) { //Source: http://rosettacode.org //Reference: http://rosettacode.org/wiki/Reduced_row_echelon_form @@ -1843,28 +1928,28 @@ namespace math int rowcount = 4; int columncount = 5; - for (int r = 0; r < rowcount; r++) + for( int r = 0; r < rowcount; r++ ) { - if (columncount <= lead) + if( columncount <= lead ) break; int i = r; - while (matrix[i, lead] == 0) + while( matrix[i, lead] == 0 ) { i++; - if (i == rowcount) + if( i == rowcount ) { i = r; lead++; - if (columncount == lead) + if( columncount == lead ) break; } } - for (int j = 0; j < columncount; j++) + for( int j = 0; j < columncount; j++ ) { float temp = matrix[r, j]; matrix[r, j] = matrix[i, j]; @@ -1873,17 +1958,18 @@ namespace math float div = matrix[r, lead]; - for (int j = 0; j < columncount; j++) + for( int j = 0; j < columncount; j++ ) { matrix[r, j] /= div; } - for (int j = 0; j < rowcount; j++) + for( int j = 0; j < rowcount; j++ ) { - if (j != r) + if( j != r ) { float sub = matrix[j, lead]; - for (int k = 0; k < columncount; k++) matrix[j, k] -= (sub * matrix[r, k]); + for( int k = 0; k < columncount; k++ ) + matrix[j, k] -= ( sub * matrix[r, k] ); } } @@ -1924,21 +2010,21 @@ namespace math /// The up vector of the camera. /// The forward vector of the camera. /// When the method completes, contains the created billboard matrix. - public static void Billboard(ref Vec3 objectPosition, ref Vec3 cameraPosition, ref Vec3 cameraUpVector, ref Vec3 cameraForwardVector, out Matrix result) + public static void Billboard( ref Vec3 objectPosition, ref Vec3 cameraPosition, ref Vec3 cameraUpVector, ref Vec3 cameraForwardVector, out Matrix result ) { Vec3 crossed; Vec3 final; Vec3 difference = objectPosition - cameraPosition; float lengthSq = difference.LengthSquared(); - if (lengthSq < MathUtil.ZeroTolerance) + if( lengthSq < MathUtil.ZeroTolerance ) difference = -cameraForwardVector; else - difference *= (float)(1.0 / Math.Sqrt(lengthSq)); + difference *= (float)( 1.0 / Math.Sqrt( lengthSq ) ); - Vec3.Cross(ref cameraUpVector, ref difference, out crossed); + Vec3.Cross( ref cameraUpVector, ref difference, out crossed ); crossed.Normalize(); - Vec3.Cross(ref difference, ref crossed, out final); + Vec3.Cross( ref difference, ref crossed, out final ); result.M11 = crossed.X; result.M12 = crossed.Y; @@ -1966,10 +2052,10 @@ namespace math /// The up vector of the camera. /// The forward vector of the camera. /// The created billboard matrix. - public static Matrix Billboard(Vec3 objectPosition, Vec3 cameraPosition, Vec3 cameraUpVector, Vec3 cameraForwardVector) + public static Matrix Billboard( Vec3 objectPosition, Vec3 cameraPosition, Vec3 cameraUpVector, Vec3 cameraForwardVector ) { Matrix result; - Billboard(ref objectPosition, ref cameraPosition, ref cameraUpVector, ref cameraForwardVector, out result); + Billboard( ref objectPosition, ref cameraPosition, ref cameraUpVector, ref cameraForwardVector, out result ); return result; } @@ -1980,21 +2066,29 @@ namespace math /// The camera look-at target. /// The camera's up vector. /// When the method completes, contains the created look-at matrix. - public static void LookAtLH(ref Vec3 eye, ref Vec3 target, ref Vec3 up, out Matrix result) + public static void LookAtLH( ref Vec3 eye, ref Vec3 target, ref Vec3 up, out Matrix result ) { Vec3 xaxis, yaxis, zaxis; - Vec3.Subtract(ref target, ref eye, out zaxis); zaxis.Normalize(); - Vec3.Cross(ref up, ref zaxis, out xaxis); xaxis.Normalize(); - Vec3.Cross(ref zaxis, ref xaxis, out yaxis); + Vec3.Subtract( ref target, ref eye, out zaxis ); + zaxis.Normalize(); + Vec3.Cross( ref up, ref zaxis, out xaxis ); + xaxis.Normalize(); + Vec3.Cross( ref zaxis, ref xaxis, out yaxis ); result = Matrix.Identity; - result.M11 = xaxis.X; result.M21 = xaxis.Y; result.M31 = xaxis.Z; - result.M12 = yaxis.X; result.M22 = yaxis.Y; result.M32 = yaxis.Z; - result.M13 = zaxis.X; result.M23 = zaxis.Y; result.M33 = zaxis.Z; + result.M11 = xaxis.X; + result.M21 = xaxis.Y; + result.M31 = xaxis.Z; + result.M12 = yaxis.X; + result.M22 = yaxis.Y; + result.M32 = yaxis.Z; + result.M13 = zaxis.X; + result.M23 = zaxis.Y; + result.M33 = zaxis.Z; - Vec3.Dot(ref xaxis, ref eye, out result.M41); - Vec3.Dot(ref yaxis, ref eye, out result.M42); - Vec3.Dot(ref zaxis, ref eye, out result.M43); + Vec3.Dot( ref xaxis, ref eye, out result.M41 ); + Vec3.Dot( ref yaxis, ref eye, out result.M42 ); + Vec3.Dot( ref zaxis, ref eye, out result.M43 ); result.M41 = -result.M41; result.M42 = -result.M42; @@ -2008,10 +2102,10 @@ namespace math /// The camera look-at target. /// The camera's up vector. /// The created look-at matrix. - public static Matrix LookAtLH(Vec3 eye, Vec3 target, Vec3 up) + public static Matrix LookAtLH( Vec3 eye, Vec3 target, Vec3 up ) { Matrix result; - LookAtLH(ref eye, ref target, ref up, out result); + LookAtLH( ref eye, ref target, ref up, out result ); return result; } @@ -2022,21 +2116,29 @@ namespace math /// The camera look-at target. /// The camera's up vector. /// When the method completes, contains the created look-at matrix. - public static void LookAtRH(ref Vec3 eye, ref Vec3 target, ref Vec3 up, out Matrix result) + public static void LookAtRH( ref Vec3 eye, ref Vec3 target, ref Vec3 up, out Matrix result ) { Vec3 xaxis, yaxis, zaxis; - Vec3.Subtract(ref eye, ref target, out zaxis); zaxis.Normalize(); - Vec3.Cross(ref up, ref zaxis, out xaxis); xaxis.Normalize(); - Vec3.Cross(ref zaxis, ref xaxis, out yaxis); + Vec3.Subtract( ref eye, ref target, out zaxis ); + zaxis.Normalize(); + Vec3.Cross( ref up, ref zaxis, out xaxis ); + xaxis.Normalize(); + Vec3.Cross( ref zaxis, ref xaxis, out yaxis ); result = Matrix.Identity; - result.M11 = xaxis.X; result.M21 = xaxis.Y; result.M31 = xaxis.Z; - result.M12 = yaxis.X; result.M22 = yaxis.Y; result.M32 = yaxis.Z; - result.M13 = zaxis.X; result.M23 = zaxis.Y; result.M33 = zaxis.Z; + result.M11 = xaxis.X; + result.M21 = xaxis.Y; + result.M31 = xaxis.Z; + result.M12 = yaxis.X; + result.M22 = yaxis.Y; + result.M32 = yaxis.Z; + result.M13 = zaxis.X; + result.M23 = zaxis.Y; + result.M33 = zaxis.Z; - Vec3.Dot(ref xaxis, ref eye, out result.M41); - Vec3.Dot(ref yaxis, ref eye, out result.M42); - Vec3.Dot(ref zaxis, ref eye, out result.M43); + Vec3.Dot( ref xaxis, ref eye, out result.M41 ); + Vec3.Dot( ref yaxis, ref eye, out result.M42 ); + Vec3.Dot( ref zaxis, ref eye, out result.M43 ); result.M41 = -result.M41; result.M42 = -result.M42; @@ -2050,10 +2152,10 @@ namespace math /// The camera look-at target. /// The camera's up vector. /// The created look-at matrix. - public static Matrix LookAtRH(Vec3 eye, Vec3 target, Vec3 up) + public static Matrix LookAtRH( Vec3 eye, Vec3 target, Vec3 up ) { Matrix result; - LookAtRH(ref eye, ref target, ref up, out result); + LookAtRH( ref eye, ref target, ref up, out result ); return result; } @@ -2065,12 +2167,12 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void OrthoLH(float width, float height, float znear, float zfar, out Matrix result) + public static void OrthoLH( float width, float height, float znear, float zfar, out Matrix result ) { float halfWidth = width * 0.5f; float halfHeight = height * 0.5f; - OrthoOffCenterLH(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result); + OrthoOffCenterLH( -halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result ); } /// @@ -2081,10 +2183,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix OrthoLH(float width, float height, float znear, float zfar) + public static Matrix OrthoLH( float width, float height, float znear, float zfar ) { Matrix result; - OrthoLH(width, height, znear, zfar, out result); + OrthoLH( width, height, znear, zfar, out result ); return result; } @@ -2096,12 +2198,12 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void OrthoRH(float width, float height, float znear, float zfar, out Matrix result) + public static void OrthoRH( float width, float height, float znear, float zfar, out Matrix result ) { float halfWidth = width * 0.5f; float halfHeight = height * 0.5f; - OrthoOffCenterRH(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result); + OrthoOffCenterRH( -halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result ); } /// @@ -2112,10 +2214,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix OrthoRH(float width, float height, float znear, float zfar) + public static Matrix OrthoRH( float width, float height, float znear, float zfar ) { Matrix result; - OrthoRH(width, height, znear, zfar, out result); + OrthoRH( width, height, znear, zfar, out result ); return result; } @@ -2129,16 +2231,16 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void OrthoOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix result) + public static void OrthoOffCenterLH( float left, float right, float bottom, float top, float znear, float zfar, out Matrix result ) { - float zRange = 1.0f / (zfar - znear); + float zRange = 1.0f / ( zfar - znear ); result = Matrix.Identity; - result.M11 = 2.0f / (right - left); - result.M22 = 2.0f / (top - bottom); + result.M11 = 2.0f / ( right - left ); + result.M22 = 2.0f / ( top - bottom ); result.M33 = zRange; - result.M41 = (left + right) / (left - right); - result.M42 = (top + bottom) / (bottom - top); + result.M41 = ( left + right ) / ( left - right ); + result.M42 = ( top + bottom ) / ( bottom - top ); result.M43 = -znear * zRange; } @@ -2152,10 +2254,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix OrthoOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar) + public static Matrix OrthoOffCenterLH( float left, float right, float bottom, float top, float znear, float zfar ) { Matrix result; - OrthoOffCenterLH(left, right, bottom, top, znear, zfar, out result); + OrthoOffCenterLH( left, right, bottom, top, znear, zfar, out result ); return result; } @@ -2169,9 +2271,9 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void OrthoOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix result) + public static void OrthoOffCenterRH( float left, float right, float bottom, float top, float znear, float zfar, out Matrix result ) { - OrthoOffCenterLH(left, right, bottom, top, znear, zfar, out result); + OrthoOffCenterLH( left, right, bottom, top, znear, zfar, out result ); result.M33 *= -1.0f; } @@ -2185,10 +2287,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix OrthoOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar) + public static Matrix OrthoOffCenterRH( float left, float right, float bottom, float top, float znear, float zfar ) { Matrix result; - OrthoOffCenterRH(left, right, bottom, top, znear, zfar, out result); + OrthoOffCenterRH( left, right, bottom, top, znear, zfar, out result ); return result; } @@ -2200,12 +2302,12 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void PerspectiveLH(float width, float height, float znear, float zfar, out Matrix result) + public static void PerspectiveLH( float width, float height, float znear, float zfar, out Matrix result ) { float halfWidth = width * 0.5f; float halfHeight = height * 0.5f; - PerspectiveOffCenterLH(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result); + PerspectiveOffCenterLH( -halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result ); } /// @@ -2216,10 +2318,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix PerspectiveLH(float width, float height, float znear, float zfar) + public static Matrix PerspectiveLH( float width, float height, float znear, float zfar ) { Matrix result; - PerspectiveLH(width, height, znear, zfar, out result); + PerspectiveLH( width, height, znear, zfar, out result ); return result; } @@ -2231,12 +2333,12 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void PerspectiveRH(float width, float height, float znear, float zfar, out Matrix result) + public static void PerspectiveRH( float width, float height, float znear, float zfar, out Matrix result ) { float halfWidth = width * 0.5f; float halfHeight = height * 0.5f; - PerspectiveOffCenterRH(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result); + PerspectiveOffCenterRH( -halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result ); } /// @@ -2247,10 +2349,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix PerspectiveRH(float width, float height, float znear, float zfar) + public static Matrix PerspectiveRH( float width, float height, float znear, float zfar ) { Matrix result; - PerspectiveRH(width, height, znear, zfar, out result); + PerspectiveRH( width, height, znear, zfar, out result ); return result; } @@ -2262,15 +2364,15 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void PerspectiveFovLH(float fov, float aspect, float znear, float zfar, out Matrix result) + public static void PerspectiveFovLH( float fov, float aspect, float znear, float zfar, out Matrix result ) { - float yScale = (float)(1.0 / Math.Tan(fov * 0.5f)); + float yScale = (float)( 1.0 / Math.Tan( fov * 0.5f ) ); float xScale = yScale / aspect; float halfWidth = znear / xScale; float halfHeight = znear / yScale; - PerspectiveOffCenterLH(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result); + PerspectiveOffCenterLH( -halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result ); } /// @@ -2281,10 +2383,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix PerspectiveFovLH(float fov, float aspect, float znear, float zfar) + public static Matrix PerspectiveFovLH( float fov, float aspect, float znear, float zfar ) { Matrix result; - PerspectiveFovLH(fov, aspect, znear, zfar, out result); + PerspectiveFovLH( fov, aspect, znear, zfar, out result ); return result; } @@ -2296,15 +2398,15 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void PerspectiveFovRH(float fov, float aspect, float znear, float zfar, out Matrix result) + public static void PerspectiveFovRH( float fov, float aspect, float znear, float zfar, out Matrix result ) { - float yScale = (float)(1.0 / Math.Tan(fov * 0.5f)); + float yScale = (float)( 1.0 / Math.Tan( fov * 0.5f ) ); float xScale = yScale / aspect; float halfWidth = znear / xScale; float halfHeight = znear / yScale; - PerspectiveOffCenterRH(-halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result); + PerspectiveOffCenterRH( -halfWidth, halfWidth, -halfHeight, halfHeight, znear, zfar, out result ); } /// @@ -2315,10 +2417,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix PerspectiveFovRH(float fov, float aspect, float znear, float zfar) + public static Matrix PerspectiveFovRH( float fov, float aspect, float znear, float zfar ) { Matrix result; - PerspectiveFovRH(fov, aspect, znear, zfar, out result); + PerspectiveFovRH( fov, aspect, znear, zfar, out result ); return result; } @@ -2332,15 +2434,15 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void PerspectiveOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix result) + public static void PerspectiveOffCenterLH( float left, float right, float bottom, float top, float znear, float zfar, out Matrix result ) { - float zRange = zfar / (zfar - znear); + float zRange = zfar / ( zfar - znear ); result = new Matrix(); - result.M11 = 2.0f * znear / (right - left); - result.M22 = 2.0f * znear / (top - bottom); - result.M31 = (left + right) / (left - right); - result.M32 = (top + bottom) / (bottom - top); + result.M11 = 2.0f * znear / ( right - left ); + result.M22 = 2.0f * znear / ( top - bottom ); + result.M31 = ( left + right ) / ( left - right ); + result.M32 = ( top + bottom ) / ( bottom - top ); result.M33 = zRange; result.M34 = 1.0f; result.M43 = -znear * zRange; @@ -2356,10 +2458,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix PerspectiveOffCenterLH(float left, float right, float bottom, float top, float znear, float zfar) + public static Matrix PerspectiveOffCenterLH( float left, float right, float bottom, float top, float znear, float zfar ) { Matrix result; - PerspectiveOffCenterLH(left, right, bottom, top, znear, zfar, out result); + PerspectiveOffCenterLH( left, right, bottom, top, znear, zfar, out result ); return result; } @@ -2373,9 +2475,9 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// When the method completes, contains the created projection matrix. - public static void PerspectiveOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar, out Matrix result) + public static void PerspectiveOffCenterRH( float left, float right, float bottom, float top, float znear, float zfar, out Matrix result ) { - PerspectiveOffCenterLH(left, right, bottom, top, znear, zfar, out result); + PerspectiveOffCenterLH( left, right, bottom, top, znear, zfar, out result ); result.M31 *= -1.0f; result.M32 *= -1.0f; result.M33 *= -1.0f; @@ -2392,10 +2494,10 @@ namespace math /// Minimum z-value of the viewing volume. /// Maximum z-value of the viewing volume. /// The created projection matrix. - public static Matrix PerspectiveOffCenterRH(float left, float right, float bottom, float top, float znear, float zfar) + public static Matrix PerspectiveOffCenterRH( float left, float right, float bottom, float top, float znear, float zfar ) { Matrix result; - PerspectiveOffCenterRH(left, right, bottom, top, znear, zfar, out result); + PerspectiveOffCenterRH( left, right, bottom, top, znear, zfar, out result ); return result; } @@ -2404,7 +2506,7 @@ namespace math /// /// The plane for which the reflection occurs. This parameter is assumed to be normalized. /// When the method completes, contains the reflection matrix. - public static void Reflection(ref Plane plane, out Matrix result) + public static void Reflection( ref Plane plane, out Matrix result ) { float x = plane.Normal.X; float y = plane.Normal.Y; @@ -2413,17 +2515,17 @@ namespace math float y2 = -2.0f * y; float z2 = -2.0f * z; - result.M11 = (x2 * x) + 1.0f; + result.M11 = ( x2 * x ) + 1.0f; result.M12 = y2 * x; result.M13 = z2 * x; result.M14 = 0.0f; result.M21 = x2 * y; - result.M22 = (y2 * y) + 1.0f; + result.M22 = ( y2 * y ) + 1.0f; result.M23 = z2 * y; result.M24 = 0.0f; result.M31 = x2 * z; result.M32 = y2 * z; - result.M33 = (z2 * z) + 1.0f; + result.M33 = ( z2 * z ) + 1.0f; result.M34 = 0.0f; result.M41 = x2 * plane.D; result.M42 = y2 * plane.D; @@ -2436,10 +2538,10 @@ namespace math /// /// The plane for which the reflection occurs. This parameter is assumed to be normalized. /// The reflection matrix. - public static Matrix Reflection(Plane plane) + public static Matrix Reflection( Plane plane ) { Matrix result; - Reflection(ref plane, out result); + Reflection( ref plane, out result ); return result; } @@ -2450,32 +2552,32 @@ namespace math /// W component is 1, the light is a point light. /// The plane onto which to project the geometry as a shadow. This parameter is assumed to be normalized. /// When the method completes, contains the shadow matrix. - public static void Shadow(ref Vec4 light, ref Plane plane, out Matrix result) - { - float dot = (plane.Normal.X * light.X) + (plane.Normal.Y * light.Y) + (plane.Normal.Z * light.Z) + (plane.D * light.W); + public static void Shadow( ref Vec4 light, ref Plane plane, out Matrix result ) + { + float dot = ( plane.Normal.X * light.X ) + ( plane.Normal.Y * light.Y ) + ( plane.Normal.Z * light.Z ) + ( plane.D * light.W ); float x = -plane.Normal.X; float y = -plane.Normal.Y; float z = -plane.Normal.Z; float d = -plane.D; - - result.M11 = (x * light.X) + dot; + + result.M11 = ( x * light.X ) + dot; result.M21 = y * light.X; result.M31 = z * light.X; result.M41 = d * light.X; result.M12 = x * light.Y; - result.M22 = (y * light.Y) + dot; + result.M22 = ( y * light.Y ) + dot; result.M32 = z * light.Y; result.M42 = d * light.Y; result.M13 = x * light.Z; result.M23 = y * light.Z; - result.M33 = (z * light.Z) + dot; + result.M33 = ( z * light.Z ) + dot; result.M43 = d * light.Z; result.M14 = x * light.W; result.M24 = y * light.W; result.M34 = z * light.W; - result.M44 = (d * light.W) + dot; + result.M44 = ( d * light.W ) + dot; } - + /// /// Creates a matrix that flattens geometry into a shadow. /// @@ -2483,10 +2585,10 @@ namespace math /// W component is 1, the light is a point light. /// The plane onto which to project the geometry as a shadow. This parameter is assumed to be normalized. /// The shadow matrix. - public static Matrix Shadow(Vec4 light, Plane plane) + public static Matrix Shadow( Vec4 light, Plane plane ) { Matrix result; - Shadow(ref light, ref plane, out result); + Shadow( ref light, ref plane, out result ); return result; } @@ -2495,9 +2597,9 @@ namespace math /// /// Scaling factor for all three axes. /// When the method completes, contains the created scaling matrix. - public static void Scaling(ref Vec3 scale, out Matrix result) + public static void Scaling( ref Vec3 scale, out Matrix result ) { - Scaling(scale.X, scale.Y, scale.Z, out result); + Scaling( scale.X, scale.Y, scale.Z, out result ); } /// @@ -2505,10 +2607,10 @@ namespace math /// /// Scaling factor for all three axes. /// The created scaling matrix. - public static Matrix Scaling(Vec3 scale) + public static Matrix Scaling( Vec3 scale ) { Matrix result; - Scaling(ref scale, out result); + Scaling( ref scale, out result ); return result; } @@ -2519,7 +2621,7 @@ namespace math /// Scaling factor that is applied along the y-axis. /// Scaling factor that is applied along the z-axis. /// When the method completes, contains the created scaling matrix. - public static void Scaling(float x, float y, float z, out Matrix result) + public static void Scaling( float x, float y, float z, out Matrix result ) { result = Matrix.Identity; result.M11 = x; @@ -2534,10 +2636,10 @@ namespace math /// Scaling factor that is applied along the y-axis. /// Scaling factor that is applied along the z-axis. /// The created scaling matrix. - public static Matrix Scaling(float x, float y, float z) + public static Matrix Scaling( float x, float y, float z ) { Matrix result; - Scaling(x, y, z, out result); + Scaling( x, y, z, out result ); return result; } @@ -2546,7 +2648,7 @@ namespace math /// /// The uniform scale that is applied along all axis. /// When the method completes, contains the created scaling matrix. - public static void Scaling(float scale, out Matrix result) + public static void Scaling( float scale, out Matrix result ) { result = Matrix.Identity; result.M11 = result.M22 = result.M33 = scale; @@ -2557,10 +2659,10 @@ namespace math /// /// The uniform scale that is applied along all axis. /// The created scaling matrix. - public static Matrix Scaling(float scale) + public static Matrix Scaling( float scale ) { Matrix result; - Scaling(scale, out result); + Scaling( scale, out result ); return result; } @@ -2569,10 +2671,10 @@ namespace math /// /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// When the method completes, contains the created rotation matrix. - public static void RotationX(float angle, out Matrix result) + public static void RotationX( float angle, out Matrix result ) { - float cos = (float)Math.Cos(angle); - float sin = (float)Math.Sin(angle); + float cos = (float)Math.Cos( angle ); + float sin = (float)Math.Sin( angle ); result = Matrix.Identity; result.M22 = cos; @@ -2586,10 +2688,10 @@ namespace math /// /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// The created rotation matrix. - public static Matrix RotationX(float angle) + public static Matrix RotationX( float angle ) { Matrix result; - RotationX(angle, out result); + RotationX( angle, out result ); return result; } @@ -2598,10 +2700,10 @@ namespace math /// /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// When the method completes, contains the created rotation matrix. - public static void RotationY(float angle, out Matrix result) + public static void RotationY( float angle, out Matrix result ) { - float cos = (float)Math.Cos(angle); - float sin = (float)Math.Sin(angle); + float cos = (float)Math.Cos( angle ); + float sin = (float)Math.Sin( angle ); result = Matrix.Identity; result.M11 = cos; @@ -2615,10 +2717,10 @@ namespace math /// /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// The created rotation matrix. - public static Matrix RotationY(float angle) + public static Matrix RotationY( float angle ) { Matrix result; - RotationY(angle, out result); + RotationY( angle, out result ); return result; } @@ -2627,10 +2729,10 @@ namespace math /// /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// When the method completes, contains the created rotation matrix. - public static void RotationZ(float angle, out Matrix result) + public static void RotationZ( float angle, out Matrix result ) { - float cos = (float)Math.Cos(angle); - float sin = (float)Math.Sin(angle); + float cos = (float)Math.Cos( angle ); + float sin = (float)Math.Sin( angle ); result = Matrix.Identity; result.M11 = cos; @@ -2644,10 +2746,10 @@ namespace math /// /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// The created rotation matrix. - public static Matrix RotationZ(float angle) + public static Matrix RotationZ( float angle ) { Matrix result; - RotationZ(angle, out result); + RotationZ( angle, out result ); return result; } @@ -2657,13 +2759,13 @@ namespace math /// The axis around which to rotate. This parameter is assumed to be normalized. /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// When the method completes, contains the created rotation matrix. - public static void RotationAxis(ref Vec3 axis, float angle, out Matrix result) + public static void RotationAxis( ref Vec3 axis, float angle, out Matrix result ) { float x = axis.X; float y = axis.Y; float z = axis.Z; - float cos = (float)Math.Cos(angle); - float sin = (float)Math.Sin(angle); + float cos = (float)Math.Cos( angle ); + float sin = (float)Math.Sin( angle ); float xx = x * x; float yy = y * y; float zz = z * z; @@ -2672,15 +2774,15 @@ namespace math float yz = y * z; result = Matrix.Identity; - result.M11 = xx + (cos * (1.0f - xx)); - result.M12 = (xy - (cos * xy)) + (sin * z); - result.M13 = (xz - (cos * xz)) - (sin * y); - result.M21 = (xy - (cos * xy)) - (sin * z); - result.M22 = yy + (cos * (1.0f - yy)); - result.M23 = (yz - (cos * yz)) + (sin * x); - result.M31 = (xz - (cos * xz)) + (sin * y); - result.M32 = (yz - (cos * yz)) - (sin * x); - result.M33 = zz + (cos * (1.0f - zz)); + result.M11 = xx + ( cos * ( 1.0f - xx ) ); + result.M12 = ( xy - ( cos * xy ) ) + ( sin * z ); + result.M13 = ( xz - ( cos * xz ) ) - ( sin * y ); + result.M21 = ( xy - ( cos * xy ) ) - ( sin * z ); + result.M22 = yy + ( cos * ( 1.0f - yy ) ); + result.M23 = ( yz - ( cos * yz ) ) + ( sin * x ); + result.M31 = ( xz - ( cos * xz ) ) + ( sin * y ); + result.M32 = ( yz - ( cos * yz ) ) - ( sin * x ); + result.M33 = zz + ( cos * ( 1.0f - zz ) ); } /// @@ -2689,10 +2791,10 @@ namespace math /// The axis around which to rotate. This parameter is assumed to be normalized. /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// The created rotation matrix. - public static Matrix RotationAxis(Vec3 axis, float angle) + public static Matrix RotationAxis( Vec3 axis, float angle ) { Matrix result; - RotationAxis(ref axis, angle, out result); + RotationAxis( ref axis, angle, out result ); return result; } @@ -2701,7 +2803,7 @@ namespace math /// /// The quaternion to use to build the matrix. /// The created rotation matrix. - public static void RotationQuaternion(ref Quaternion rotation, out Matrix result) + public static void RotationQuaternion( ref Quaternion rotation, out Matrix result ) { float xx = rotation.X * rotation.X; float yy = rotation.Y * rotation.Y; @@ -2714,15 +2816,15 @@ namespace math float xw = rotation.X * rotation.W; result = Matrix.Identity; - result.M11 = 1.0f - (2.0f * (yy + zz)); - result.M12 = 2.0f * (xy + zw); - result.M13 = 2.0f * (zx - yw); - result.M21 = 2.0f * (xy - zw); - result.M22 = 1.0f - (2.0f * (zz + xx)); - result.M23 = 2.0f * (yz + xw); - result.M31 = 2.0f * (zx + yw); - result.M32 = 2.0f * (yz - xw); - result.M33 = 1.0f - (2.0f * (yy + xx)); + result.M11 = 1.0f - ( 2.0f * ( yy + zz ) ); + result.M12 = 2.0f * ( xy + zw ); + result.M13 = 2.0f * ( zx - yw ); + result.M21 = 2.0f * ( xy - zw ); + result.M22 = 1.0f - ( 2.0f * ( zz + xx ) ); + result.M23 = 2.0f * ( yz + xw ); + result.M31 = 2.0f * ( zx + yw ); + result.M32 = 2.0f * ( yz - xw ); + result.M33 = 1.0f - ( 2.0f * ( yy + xx ) ); } /// @@ -2732,7 +2834,7 @@ namespace math /// Angle of rotation in radians. Angles are measured clockwise when looking along the rotation axis toward the origin. /// The translation. /// When the method completes, contains the created rotation matrix. - public static void Transformation(ref Vec3 scaling, ref Quaternion rotation, ref Vec3 translation, out Matrix result) + public static void Transformation( ref Vec3 scaling, ref Quaternion rotation, ref Vec3 translation, out Matrix result ) { // Equivalent to: //result = @@ -2753,15 +2855,15 @@ namespace math float yz = rotation.Y * rotation.Z; float xw = rotation.X * rotation.W; - result.M11 = 1.0f - (2.0f * (yy + zz)); - result.M12 = 2.0f * (xy + zw); - result.M13 = 2.0f * (zx - yw); - result.M21 = 2.0f * (xy - zw); - result.M22 = 1.0f - (2.0f * (zz + xx)); - result.M23 = 2.0f * (yz + xw); - result.M31 = 2.0f * (zx + yw); - result.M32 = 2.0f * (yz - xw); - result.M33 = 1.0f - (2.0f * (yy + xx)); + result.M11 = 1.0f - ( 2.0f * ( yy + zz ) ); + result.M12 = 2.0f * ( xy + zw ); + result.M13 = 2.0f * ( zx - yw ); + result.M21 = 2.0f * ( xy - zw ); + result.M22 = 1.0f - ( 2.0f * ( zz + xx ) ); + result.M23 = 2.0f * ( yz + xw ); + result.M31 = 2.0f * ( zx + yw ); + result.M32 = 2.0f * ( yz - xw ); + result.M33 = 1.0f - ( 2.0f * ( yy + xx ) ); // Position result.M41 = translation.X; @@ -2769,19 +2871,19 @@ namespace math result.M43 = translation.Z; // Scale - if (scaling.X != 1.0f) + if( scaling.X != 1.0f ) { result.M11 *= scaling.X; result.M12 *= scaling.X; result.M13 *= scaling.X; } - if (scaling.Y != 1.0f) + if( scaling.Y != 1.0f ) { result.M21 *= scaling.Y; result.M22 *= scaling.Y; result.M23 *= scaling.Y; } - if (scaling.Z != 1.0f) + if( scaling.Z != 1.0f ) { result.M31 *= scaling.Z; result.M32 *= scaling.Z; @@ -2799,10 +2901,10 @@ namespace math /// /// The quaternion to use to build the matrix. /// The created rotation matrix. - public static Matrix RotationQuaternion(Quaternion rotation) + public static Matrix RotationQuaternion( Quaternion rotation ) { Matrix result; - RotationQuaternion(ref rotation, out result); + RotationQuaternion( ref rotation, out result ); return result; } @@ -2813,11 +2915,11 @@ namespace math /// Pitch around the x-axis, in radians. /// Roll around the z-axis, in radians. /// When the method completes, contains the created rotation matrix. - public static void RotationYawPitchRoll(float yaw, float pitch, float roll, out Matrix result) + public static void RotationYawPitchRoll( float yaw, float pitch, float roll, out Matrix result ) { Quaternion quaternion = new Quaternion(); - Quaternion.RotationYawPitchRoll(yaw, pitch, roll, out quaternion); - RotationQuaternion(ref quaternion, out result); + Quaternion.RotationYawPitchRoll( yaw, pitch, roll, out quaternion ); + RotationQuaternion( ref quaternion, out result ); } /// @@ -2827,10 +2929,10 @@ namespace math /// Pitch around the x-axis, in radians. /// Roll around the z-axis, in radians. /// The created rotation matrix. - public static Matrix RotationYawPitchRoll(float yaw, float pitch, float roll) + public static Matrix RotationYawPitchRoll( float yaw, float pitch, float roll ) { Matrix result; - RotationYawPitchRoll(yaw, pitch, roll, out result); + RotationYawPitchRoll( yaw, pitch, roll, out result ); return result; } @@ -2839,9 +2941,9 @@ namespace math /// /// The offset for all three coordinate planes. /// When the method completes, contains the created translation matrix. - public static void Translation(ref Vec3 value, out Matrix result) + public static void Translation( ref Vec3 value, out Matrix result ) { - Translation(value.X, value.Y, value.Z, out result); + Translation( value.X, value.Y, value.Z, out result ); } /// @@ -2849,10 +2951,10 @@ namespace math /// /// The offset for all three coordinate planes. /// The created translation matrix. - public static Matrix Translation(Vec3 value) + public static Matrix Translation( Vec3 value ) { Matrix result; - Translation(ref value, out result); + Translation( ref value, out result ); return result; } @@ -2863,7 +2965,7 @@ namespace math /// Y-coordinate offset. /// Z-coordinate offset. /// When the method completes, contains the created translation matrix. - public static void Translation(float x, float y, float z, out Matrix result) + public static void Translation( float x, float y, float z, out Matrix result ) { result = Matrix.Identity; result.M41 = x; @@ -2878,10 +2980,10 @@ namespace math /// Y-coordinate offset. /// Z-coordinate offset. /// The created translation matrix. - public static Matrix Translation(float x, float y, float z) + public static Matrix Translation( float x, float y, float z ) { Matrix result; - Translation(x, y, z, out result); + Translation( x, y, z, out result ); return result; } @@ -2892,9 +2994,9 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation(float scaling, ref Quaternion rotation, ref Vec3 translation, out Matrix result) + public static void AffineTransformation( float scaling, ref Quaternion rotation, ref Vec3 translation, out Matrix result ) { - result = Scaling(scaling) * RotationQuaternion(rotation) * Translation(translation); + result = Scaling( scaling ) * RotationQuaternion( rotation ) * Translation( translation ); } /// @@ -2904,10 +3006,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// The created affine transformation matrix. - public static Matrix AffineTransformation(float scaling, Quaternion rotation, Vec3 translation) + public static Matrix AffineTransformation( float scaling, Quaternion rotation, Vec3 translation ) { Matrix result; - AffineTransformation(scaling, ref rotation, ref translation, out result); + AffineTransformation( scaling, ref rotation, ref translation, out result ); return result; } @@ -2919,10 +3021,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation(float scaling, ref Vec3 rotationCenter, ref Quaternion rotation, ref Vec3 translation, out Matrix result) + public static void AffineTransformation( float scaling, ref Vec3 rotationCenter, ref Quaternion rotation, ref Vec3 translation, out Matrix result ) { - result = Scaling(scaling) * Translation(-rotationCenter) * RotationQuaternion(rotation) * - Translation(rotationCenter) * Translation(translation); + result = Scaling( scaling ) * Translation( -rotationCenter ) * RotationQuaternion( rotation ) * + Translation( rotationCenter ) * Translation( translation ); } /// @@ -2933,10 +3035,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// The created affine transformation matrix. - public static Matrix AffineTransformation(float scaling, Vec3 rotationCenter, Quaternion rotation, Vec3 translation) + public static Matrix AffineTransformation( float scaling, Vec3 rotationCenter, Quaternion rotation, Vec3 translation ) { Matrix result; - AffineTransformation(scaling, ref rotationCenter, ref rotation, ref translation, out result); + AffineTransformation( scaling, ref rotationCenter, ref rotation, ref translation, out result ); return result; } @@ -2947,9 +3049,9 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation2D(float scaling, float rotation, ref Vec2 translation, out Matrix result) + public static void AffineTransformation2D( float scaling, float rotation, ref Vec2 translation, out Matrix result ) { - result = Scaling(scaling, scaling, 1.0f) * RotationZ(rotation) * Translation((Vec3)translation); + result = Scaling( scaling, scaling, 1.0f ) * RotationZ( rotation ) * Translation( (Vec3)translation ); } /// @@ -2959,10 +3061,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// The created affine transformation matrix. - public static Matrix AffineTransformation2D(float scaling, float rotation, Vec2 translation) + public static Matrix AffineTransformation2D( float scaling, float rotation, Vec2 translation ) { Matrix result; - AffineTransformation2D(scaling, rotation, ref translation, out result); + AffineTransformation2D( scaling, rotation, ref translation, out result ); return result; } @@ -2974,10 +3076,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created affine transformation matrix. - public static void AffineTransformation2D(float scaling, ref Vec2 rotationCenter, float rotation, ref Vec2 translation, out Matrix result) + public static void AffineTransformation2D( float scaling, ref Vec2 rotationCenter, float rotation, ref Vec2 translation, out Matrix result ) { - result = Scaling(scaling, scaling, 1.0f) * Translation((Vec3)(-rotationCenter)) * RotationZ(rotation) * - Translation((Vec3)rotationCenter) * Translation((Vec3)translation); + result = Scaling( scaling, scaling, 1.0f ) * Translation( (Vec3)( -rotationCenter ) ) * RotationZ( rotation ) * + Translation( (Vec3)rotationCenter ) * Translation( (Vec3)translation ); } /// @@ -2988,10 +3090,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// The created affine transformation matrix. - public static Matrix AffineTransformation2D(float scaling, Vec2 rotationCenter, float rotation, Vec2 translation) + public static Matrix AffineTransformation2D( float scaling, Vec2 rotationCenter, float rotation, Vec2 translation ) { Matrix result; - AffineTransformation2D(scaling, ref rotationCenter, rotation, ref translation, out result); + AffineTransformation2D( scaling, ref rotationCenter, rotation, ref translation, out result ); return result; } @@ -3005,12 +3107,12 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created transformation matrix. - public static void Transformation(ref Vec3 scalingCenter, ref Quaternion scalingRotation, ref Vec3 scaling, ref Vec3 rotationCenter, ref Quaternion rotation, ref Vec3 translation, out Matrix result) + public static void Transformation( ref Vec3 scalingCenter, ref Quaternion scalingRotation, ref Vec3 scaling, ref Vec3 rotationCenter, ref Quaternion rotation, ref Vec3 translation, out Matrix result ) { - Matrix sr = RotationQuaternion(scalingRotation); + Matrix sr = RotationQuaternion( scalingRotation ); - result = Translation(-scalingCenter) * Transpose(sr) * Scaling(scaling) * sr * Translation(scalingCenter) * Translation(-rotationCenter) * - RotationQuaternion(rotation) * Translation(rotationCenter) * Translation(translation); + result = Translation( -scalingCenter ) * Transpose( sr ) * Scaling( scaling ) * sr * Translation( scalingCenter ) * Translation( -rotationCenter ) * + RotationQuaternion( rotation ) * Translation( rotationCenter ) * Translation( translation ); } /// @@ -3023,10 +3125,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// The created transformation matrix. - public static Matrix Transformation(Vec3 scalingCenter, Quaternion scalingRotation, Vec3 scaling, Vec3 rotationCenter, Quaternion rotation, Vec3 translation) + public static Matrix Transformation( Vec3 scalingCenter, Quaternion scalingRotation, Vec3 scaling, Vec3 rotationCenter, Quaternion rotation, Vec3 translation ) { Matrix result; - Transformation(ref scalingCenter, ref scalingRotation, ref scaling, ref rotationCenter, ref rotation, ref translation, out result); + Transformation( ref scalingCenter, ref scalingRotation, ref scaling, ref rotationCenter, ref rotation, ref translation, out result ); return result; } @@ -3040,10 +3142,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// When the method completes, contains the created transformation matrix. - public static void Transformation2D(ref Vec2 scalingCenter, float scalingRotation, ref Vec2 scaling, ref Vec2 rotationCenter, float rotation, ref Vec2 translation, out Matrix result) + public static void Transformation2D( ref Vec2 scalingCenter, float scalingRotation, ref Vec2 scaling, ref Vec2 rotationCenter, float rotation, ref Vec2 translation, out Matrix result ) { - result = Translation((Vec3)(-scalingCenter)) * RotationZ(-scalingRotation) * Scaling((Vec3)scaling) * RotationZ(scalingRotation) * Translation((Vec3)scalingCenter) * - Translation((Vec3)(-rotationCenter)) * RotationZ(rotation) * Translation((Vec3)rotationCenter) * Translation((Vec3)translation); + result = Translation( (Vec3)( -scalingCenter ) ) * RotationZ( -scalingRotation ) * Scaling( (Vec3)scaling ) * RotationZ( scalingRotation ) * Translation( (Vec3)scalingCenter ) * + Translation( (Vec3)( -rotationCenter ) ) * RotationZ( rotation ) * Translation( (Vec3)rotationCenter ) * Translation( (Vec3)translation ); result.M33 = 1f; result.M44 = 1f; @@ -3059,10 +3161,10 @@ namespace math /// The rotation of the transformation. /// The translation factor of the transformation. /// The created transformation matrix. - public static Matrix Transformation2D(Vec2 scalingCenter, float scalingRotation, Vec2 scaling, Vec2 rotationCenter, float rotation, Vec2 translation) + public static Matrix Transformation2D( Vec2 scalingCenter, float scalingRotation, Vec2 scaling, Vec2 rotationCenter, float rotation, Vec2 translation ) { Matrix result; - Transformation2D(ref scalingCenter, scalingRotation, ref scaling, ref rotationCenter, rotation, ref translation, out result); + Transformation2D( ref scalingCenter, scalingRotation, ref scaling, ref rotationCenter, rotation, ref translation, out result ); return result; } @@ -3072,14 +3174,14 @@ namespace math /// The source matrix. /// The number of columns. /// The number of rows. - public unsafe void CopyMatrixFrom(float* src, int columns, int rows) + public unsafe void CopyMatrixFrom( float* src, int columns, int rows ) { - fixed (void* pDest = &this) + fixed( void* pDest = &this ) { var dest = (float*)pDest; - for (int i = 0; i < rows; ++i) + for( int i = 0; i < rows; ++i ) { - for (int j = 0; j < columns; ++j) + for( int j = 0; j < columns; ++j ) { dest[j] = src[j]; } @@ -3095,15 +3197,15 @@ namespace math /// The SRC. /// The columns. /// The rows. - public unsafe void TransposeMatrixFrom(float* src, int columns, int rows) + public unsafe void TransposeMatrixFrom( float* src, int columns, int rows ) { - fixed (void* pDest = &this) + fixed( void* pDest = &this ) { var dest = (float*)pDest; - for (int i = 0; i < rows; ++i) + for( int i = 0; i < rows; ++i ) { int sourceIndex = i; - for (int j = 0; j < columns; ++j) + for( int j = 0; j < columns; ++j ) { dest[j] = src[sourceIndex]; sourceIndex += rows; @@ -3119,10 +3221,10 @@ namespace math /// The first matrix to add. /// The second matrix to add. /// The sum of the two matricies. - public static Matrix operator +(Matrix left, Matrix right) + public static Matrix operator +( Matrix left, Matrix right ) { Matrix result; - Add(ref left, ref right, out result); + Add( ref left, ref right, out result ); return result; } @@ -3131,7 +3233,7 @@ namespace math /// /// The matrix to assert (unchange). /// The asserted (unchanged) matrix. - public static Matrix operator +(Matrix value) + public static Matrix operator +( Matrix value ) { return value; } @@ -3142,10 +3244,10 @@ namespace math /// The first matrix to subtract. /// The second matrix to subtract. /// The difference between the two matricies. - public static Matrix operator -(Matrix left, Matrix right) + public static Matrix operator -( Matrix left, Matrix right ) { Matrix result; - Subtract(ref left, ref right, out result); + Subtract( ref left, ref right, out result ); return result; } @@ -3154,10 +3256,10 @@ namespace math /// /// The matrix to negate. /// The negated matrix. - public static Matrix operator -(Matrix value) + public static Matrix operator -( Matrix value ) { Matrix result; - Negate(ref value, out result); + Negate( ref value, out result ); return result; } @@ -3167,10 +3269,10 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// The scaled matrix. - public static Matrix operator *(float left, Matrix right) + public static Matrix operator *( float left, Matrix right ) { Matrix result; - Multiply(ref right, left, out result); + Multiply( ref right, left, out result ); return result; } @@ -3180,10 +3282,10 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// The scaled matrix. - public static Matrix operator *(Matrix left, float right) + public static Matrix operator *( Matrix left, float right ) { Matrix result; - Multiply(ref left, right, out result); + Multiply( ref left, right, out result ); return result; } @@ -3193,10 +3295,10 @@ namespace math /// The first matrix to multiply. /// The second matrix to multiply. /// The product of the two matricies. - public static Matrix operator *(Matrix left, Matrix right) + public static Matrix operator *( Matrix left, Matrix right ) { Matrix result; - Multiply(ref left, ref right, out result); + Multiply( ref left, ref right, out result ); return result; } @@ -3206,10 +3308,10 @@ namespace math /// The matrix to scale. /// The amount by which to scale. /// The scaled matrix. - public static Matrix operator /(Matrix left, float right) + public static Matrix operator /( Matrix left, float right ) { Matrix result; - Divide(ref left, right, out result); + Divide( ref left, right, out result ); return result; } @@ -3219,10 +3321,10 @@ namespace math /// The first matrix to divide. /// The second matrix to divide. /// The quotient of the two matricies. - public static Matrix operator /(Matrix left, Matrix right) + public static Matrix operator /( Matrix left, Matrix right ) { Matrix result; - Divide(ref left, ref right, out result); + Divide( ref left, ref right, out result ); return result; } @@ -3232,9 +3334,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Matrix left, Matrix right) + public static bool operator ==( Matrix left, Matrix right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -3243,9 +3345,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Matrix left, Matrix right) + public static bool operator !=( Matrix left, Matrix right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -3256,8 +3358,8 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", - M11, M12, M13, M14, M21, M22, M23, M24, M31, M32, M33, M34, M41, M42, M43, M44); + return string.Format( CultureInfo.CurrentCulture, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", + M11, M12, M13, M14, M21, M22, M23, M24, M31, M32, M33, M34, M41, M42, M43, M44 ); } /// @@ -3267,16 +3369,16 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(format, CultureInfo.CurrentCulture, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", - M11.ToString(format, CultureInfo.CurrentCulture), M12.ToString(format, CultureInfo.CurrentCulture), M13.ToString(format, CultureInfo.CurrentCulture), M14.ToString(format, CultureInfo.CurrentCulture), - M21.ToString(format, CultureInfo.CurrentCulture), M22.ToString(format, CultureInfo.CurrentCulture), M23.ToString(format, CultureInfo.CurrentCulture), M24.ToString(format, CultureInfo.CurrentCulture), - M31.ToString(format, CultureInfo.CurrentCulture), M32.ToString(format, CultureInfo.CurrentCulture), M33.ToString(format, CultureInfo.CurrentCulture), M34.ToString(format, CultureInfo.CurrentCulture), - M41.ToString(format, CultureInfo.CurrentCulture), M42.ToString(format, CultureInfo.CurrentCulture), M43.ToString(format, CultureInfo.CurrentCulture), M44.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( format, CultureInfo.CurrentCulture, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", + M11.ToString( format, CultureInfo.CurrentCulture ), M12.ToString( format, CultureInfo.CurrentCulture ), M13.ToString( format, CultureInfo.CurrentCulture ), M14.ToString( format, CultureInfo.CurrentCulture ), + M21.ToString( format, CultureInfo.CurrentCulture ), M22.ToString( format, CultureInfo.CurrentCulture ), M23.ToString( format, CultureInfo.CurrentCulture ), M24.ToString( format, CultureInfo.CurrentCulture ), + M31.ToString( format, CultureInfo.CurrentCulture ), M32.ToString( format, CultureInfo.CurrentCulture ), M33.ToString( format, CultureInfo.CurrentCulture ), M34.ToString( format, CultureInfo.CurrentCulture ), + M41.ToString( format, CultureInfo.CurrentCulture ), M42.ToString( format, CultureInfo.CurrentCulture ), M43.ToString( format, CultureInfo.CurrentCulture ), M44.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -3286,13 +3388,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", - M11.ToString(formatProvider), M12.ToString(formatProvider), M13.ToString(formatProvider), M14.ToString(formatProvider), - M21.ToString(formatProvider), M22.ToString(formatProvider), M23.ToString(formatProvider), M24.ToString(formatProvider), - M31.ToString(formatProvider), M32.ToString(formatProvider), M33.ToString(formatProvider), M34.ToString(formatProvider), - M41.ToString(formatProvider), M42.ToString(formatProvider), M43.ToString(formatProvider), M44.ToString(formatProvider)); + return string.Format( formatProvider, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", + M11.ToString( formatProvider ), M12.ToString( formatProvider ), M13.ToString( formatProvider ), M14.ToString( formatProvider ), + M21.ToString( formatProvider ), M22.ToString( formatProvider ), M23.ToString( formatProvider ), M24.ToString( formatProvider ), + M31.ToString( formatProvider ), M32.ToString( formatProvider ), M33.ToString( formatProvider ), M34.ToString( formatProvider ), + M41.ToString( formatProvider ), M42.ToString( formatProvider ), M43.ToString( formatProvider ), M44.ToString( formatProvider ) ); } /// @@ -3303,23 +3405,23 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(format, formatProvider, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", - M11.ToString(format, formatProvider), M12.ToString(format, formatProvider), M13.ToString(format, formatProvider), M14.ToString(format, formatProvider), - M21.ToString(format, formatProvider), M22.ToString(format, formatProvider), M23.ToString(format, formatProvider), M24.ToString(format, formatProvider), - M31.ToString(format, formatProvider), M32.ToString(format, formatProvider), M33.ToString(format, formatProvider), M34.ToString(format, formatProvider), - M41.ToString(format, formatProvider), M42.ToString(format, formatProvider), M43.ToString(format, formatProvider), M44.ToString(format, formatProvider)); + return string.Format( format, formatProvider, "[M11:{0} M12:{1} M13:{2} M14:{3}] [M21:{4} M22:{5} M23:{6} M24:{7}] [M31:{8} M32:{9} M33:{10} M34:{11}] [M41:{12} M42:{13} M43:{14} M44:{15}]", + M11.ToString( format, formatProvider ), M12.ToString( format, formatProvider ), M13.ToString( format, formatProvider ), M14.ToString( format, formatProvider ), + M21.ToString( format, formatProvider ), M22.ToString( format, formatProvider ), M23.ToString( format, formatProvider ), M24.ToString( format, formatProvider ), + M31.ToString( format, formatProvider ), M32.ToString( format, formatProvider ), M33.ToString( format, formatProvider ), M34.ToString( format, formatProvider ), + M41.ToString( format, formatProvider ), M42.ToString( format, formatProvider ), M43.ToString( format, formatProvider ), M44.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -3336,27 +3438,27 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Matrix other) + public bool Equals( Matrix other ) { - return (Math.Abs(other.M11 - M11) < MathUtil.ZeroTolerance && - Math.Abs(other.M12 - M12) < MathUtil.ZeroTolerance && - Math.Abs(other.M13 - M13) < MathUtil.ZeroTolerance && - Math.Abs(other.M14 - M14) < MathUtil.ZeroTolerance && + return ( Math.Abs( other.M11 - M11 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M12 - M12 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M13 - M13 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M14 - M14 ) < MathUtil.ZeroTolerance && - Math.Abs(other.M21 - M21) < MathUtil.ZeroTolerance && - Math.Abs(other.M22 - M22) < MathUtil.ZeroTolerance && - Math.Abs(other.M23 - M23) < MathUtil.ZeroTolerance && - Math.Abs(other.M24 - M24) < MathUtil.ZeroTolerance && + Math.Abs( other.M21 - M21 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M22 - M22 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M23 - M23 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M24 - M24 ) < MathUtil.ZeroTolerance && - Math.Abs(other.M31 - M31) < MathUtil.ZeroTolerance && - Math.Abs(other.M32 - M32) < MathUtil.ZeroTolerance && - Math.Abs(other.M33 - M33) < MathUtil.ZeroTolerance && - Math.Abs(other.M34 - M34) < MathUtil.ZeroTolerance && + Math.Abs( other.M31 - M31 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M32 - M32 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M33 - M33 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M34 - M34 ) < MathUtil.ZeroTolerance && - Math.Abs(other.M41 - M41) < MathUtil.ZeroTolerance && - Math.Abs(other.M42 - M42) < MathUtil.ZeroTolerance && - Math.Abs(other.M43 - M43) < MathUtil.ZeroTolerance && - Math.Abs(other.M44 - M44) < MathUtil.ZeroTolerance); + Math.Abs( other.M41 - M41 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M42 - M42 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M43 - M43 ) < MathUtil.ZeroTolerance && + Math.Abs( other.M44 - M44 ) < MathUtil.ZeroTolerance ); } /// @@ -3366,15 +3468,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Matrix)value); + return Equals( (Matrix)value ); } #if SlimDX1xInterop diff --git a/math/Plane.cs b/math/Plane.cs index cddf129..481361b 100644 --- a/math/Plane.cs +++ b/math/Plane.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -37,7 +37,7 @@ namespace math /// Represents a plane in three dimensional space. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Plane : IEquatable, IFormattable { /// @@ -54,7 +54,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Plane(float value) + public Plane( float value ) { Normal.X = Normal.Y = Normal.Z = D = value; } @@ -66,7 +66,7 @@ namespace math /// The Y component of the normal. /// The Z component of the normal. /// The distance of the plane along its normal from the origin. - public Plane(float a, float b, float c, float d) + public Plane( float a, float b, float c, float d ) { Normal.X = a; Normal.Y = b; @@ -79,10 +79,10 @@ namespace math /// /// Any point that lies along the plane. /// The normal vector to the plane. - public Plane(Vec3 point, Vec3 normal) + public Plane( Vec3 point, Vec3 normal ) { this.Normal = normal; - this.D = Vec3.Dot(normal, point); + this.D = Vec3.Dot( normal, point ); } /// @@ -90,7 +90,7 @@ namespace math /// /// The normal of the plane. /// The distance of the plane along its normal from the origin - public Plane(Vec3 value, float d) + public Plane( Vec3 value, float d ) { Normal = value; D = d; @@ -102,7 +102,7 @@ namespace math /// First point of a triangle defining the plane. /// Second point of a triangle defining the plane. /// Third point of a triangle defining the plane. - public Plane(Vec3 point1, Vec3 point2, Vec3 point3) + public Plane( Vec3 point1, Vec3 point2, Vec3 point3 ) { float x1 = point2.X - point1.X; float y1 = point2.Y - point1.Y; @@ -110,15 +110,15 @@ namespace math float x2 = point3.X - point1.X; float y2 = point3.Y - point1.Y; float z2 = point3.Z - point1.Z; - float yz = (y1 * z2) - (z1 * y2); - float xz = (z1 * x2) - (x1 * z2); - float xy = (x1 * y2) - (y1 * x2); - float invPyth = 1.0f / (float)(Math.Sqrt((yz * yz) + (xz * xz) + (xy * xy))); + float yz = ( y1 * z2 ) - ( z1 * y2 ); + float xz = ( z1 * x2 ) - ( x1 * z2 ); + float xy = ( x1 * y2 ) - ( y1 * x2 ); + float invPyth = 1.0f / (float)( Math.Sqrt( ( yz * yz ) + ( xz * xz ) + ( xy * xy ) ) ); Normal.X = yz * invPyth; Normal.Y = xz * invPyth; Normal.Z = xy * invPyth; - D = -((Normal.X * point1.X) + (Normal.Y * point1.Y) + (Normal.Z * point1.Z)); + D = -( ( Normal.X * point1.X ) + ( Normal.Y * point1.Y ) + ( Normal.Z * point1.Z ) ); } /// @@ -127,12 +127,12 @@ namespace math /// The values to assign to the A, B, C, and D components of the plane. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Plane(float[] values) + public Plane( float[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 4) - throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for Plane."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( "values", "There must be four and only four input values for Plane." ); Normal.X = values[0]; Normal.Y = values[1]; @@ -151,26 +151,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return Normal.X; - case 1: return Normal.Y; - case 2: return Normal.Z; - case 3: return D; + case 0: + return Normal.X; + case 1: + return Normal.Y; + case 2: + return Normal.Z; + case 3: + return D; } - throw new ArgumentOutOfRangeException("index", "Indices for Plane run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Plane run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: Normal.X = value; break; - case 1: Normal.Y = value; break; - case 2: Normal.Z = value; break; - case 3: D = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Plane run from 0 to 3, inclusive."); + case 0: + Normal.X = value; + break; + case 1: + Normal.Y = value; + break; + case 2: + Normal.Z = value; + break; + case 3: + D = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Plane run from 0 to 3, inclusive." ); } } } @@ -191,7 +204,7 @@ namespace math /// public void Normalize() { - float magnitude = 1.0f / (float)(Math.Sqrt((Normal.X * Normal.X) + (Normal.Y * Normal.Y) + (Normal.Z * Normal.Z))); + float magnitude = 1.0f / (float)( Math.Sqrt( ( Normal.X * Normal.X ) + ( Normal.Y * Normal.Y ) + ( Normal.Z * Normal.Z ) ) ); Normal.X *= magnitude; Normal.Y *= magnitude; @@ -213,9 +226,9 @@ namespace math /// /// The point to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Vec3 point) + public PlaneIntersectionType Intersects( ref Vec3 point ) { - return CollisionHelper.PlaneIntersectsPoint(ref this, ref point); + return CollisionHelper.PlaneIntersectsPoint( ref this, ref point ); } /// @@ -223,10 +236,10 @@ namespace math /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects( ref Ray ray ) { float distance; - return CollisionHelper.RayIntersectsPlane(ref ray, ref this, out distance); + return CollisionHelper.RayIntersectsPlane( ref ray, ref this, out distance ); } /// @@ -236,9 +249,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out float distance) + public bool Intersects( ref Ray ray, out float distance ) { - return CollisionHelper.RayIntersectsPlane(ref ray, ref this, out distance); + return CollisionHelper.RayIntersectsPlane( ref ray, ref this, out distance ); } /// @@ -248,9 +261,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vec3 point) + public bool Intersects( ref Ray ray, out Vec3 point ) { - return CollisionHelper.RayIntersectsPlane(ref ray, ref this, out point); + return CollisionHelper.RayIntersectsPlane( ref ray, ref this, out point ); } /// @@ -258,9 +271,9 @@ namespace math /// /// The plane to test. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane) + public bool Intersects( ref Plane plane ) { - return CollisionHelper.PlaneIntersectsPlane(ref this, ref plane); + return CollisionHelper.PlaneIntersectsPlane( ref this, ref plane ); } /// @@ -270,9 +283,9 @@ namespace math /// When the method completes, contains the line of intersection /// as a , or a zero ray if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane, out Ray line) + public bool Intersects( ref Plane plane, out Ray line ) { - return CollisionHelper.PlaneIntersectsPlane(ref this, ref plane, out line); + return CollisionHelper.PlaneIntersectsPlane( ref this, ref plane, out line ); } /// @@ -282,9 +295,9 @@ namespace math /// The second vertex of the triagnle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public PlaneIntersectionType Intersects( ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { - return CollisionHelper.PlaneIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3); + return CollisionHelper.PlaneIntersectsTriangle( ref this, ref vertex1, ref vertex2, ref vertex3 ); } /// @@ -292,9 +305,9 @@ namespace math /// /// The box to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref BoundingBox box) + public PlaneIntersectionType Intersects( ref BoundingBox box ) { - return CollisionHelper.PlaneIntersectsBox(ref this, ref box); + return CollisionHelper.PlaneIntersectsBox( ref this, ref box ); } /// @@ -302,9 +315,9 @@ namespace math /// /// The sphere to test. /// Whether the two objects intersected. - public PlaneIntersectionType Intersects(ref BoundingSphere sphere) + public PlaneIntersectionType Intersects( ref BoundingSphere sphere ) { - return CollisionHelper.PlaneIntersectsSphere(ref this, ref sphere); + return CollisionHelper.PlaneIntersectsSphere( ref this, ref sphere ); } /// @@ -313,7 +326,7 @@ namespace math /// The plane to scale. /// The amount by which to scale the plane. /// When the method completes, contains the scaled plane. - public static void Multiply(ref Plane value, float scale, out Plane result) + public static void Multiply( ref Plane value, float scale, out Plane result ) { result.Normal.X = value.Normal.X * scale; result.Normal.Y = value.Normal.Y * scale; @@ -327,9 +340,9 @@ namespace math /// The plane to scale. /// The amount by which to scale the plane. /// The scaled plane. - public static Plane Multiply(Plane value, float scale) + public static Plane Multiply( Plane value, float scale ) { - return new Plane(value.Normal.X * scale, value.Normal.Y * scale, value.Normal.Z * scale, value.D * scale); + return new Plane( value.Normal.X * scale, value.Normal.Y * scale, value.Normal.Z * scale, value.D * scale ); } /// @@ -338,9 +351,9 @@ namespace math /// The source plane. /// The source vector. /// When the method completes, contains the dot product of the specified plane and vector. - public static void Dot(ref Plane left, ref Vec4 right, out float result) + public static void Dot( ref Plane left, ref Vec4 right, out float result ) { - result = (left.Normal.X * right.X) + (left.Normal.Y * right.Y) + (left.Normal.Z * right.Z) + (left.D * right.W); + result = ( left.Normal.X * right.X ) + ( left.Normal.Y * right.Y ) + ( left.Normal.Z * right.Z ) + ( left.D * right.W ); } /// @@ -349,9 +362,9 @@ namespace math /// The source plane. /// The source vector. /// The dot product of the specified plane and vector. - public static float Dot(Plane left, Vec4 right) + public static float Dot( Plane left, Vec4 right ) { - return (left.Normal.X * right.X) + (left.Normal.Y * right.Y) + (left.Normal.Z * right.Z) + (left.D * right.W); + return ( left.Normal.X * right.X ) + ( left.Normal.Y * right.Y ) + ( left.Normal.Z * right.Z ) + ( left.D * right.W ); } /// @@ -360,9 +373,9 @@ namespace math /// The source plane. /// The source vector. /// When the method completes, contains the dot product of a specified vector and the normal of the Plane plus the distance value of the plane. - public static void DotCoordinate(ref Plane left, ref Vec3 right, out float result) + public static void DotCoordinate( ref Plane left, ref Vec3 right, out float result ) { - result = (left.Normal.X * right.X) + (left.Normal.Y * right.Y) + (left.Normal.Z * right.Z) + left.D; + result = ( left.Normal.X * right.X ) + ( left.Normal.Y * right.Y ) + ( left.Normal.Z * right.Z ) + left.D; } /// @@ -371,9 +384,9 @@ namespace math /// The source plane. /// The source vector. /// The dot product of a specified vector and the normal of the Plane plus the distance value of the plane. - public static float DotCoordinate(Plane left, Vec3 right) + public static float DotCoordinate( Plane left, Vec3 right ) { - return (left.Normal.X * right.X) + (left.Normal.Y * right.Y) + (left.Normal.Z * right.Z) + left.D; + return ( left.Normal.X * right.X ) + ( left.Normal.Y * right.Y ) + ( left.Normal.Z * right.Z ) + left.D; } /// @@ -382,9 +395,9 @@ namespace math /// The source plane. /// The source vector. /// When the method completes, contains the dot product of the specified vector and the normal of the plane. - public static void DotNormal(ref Plane left, ref Vec3 right, out float result) + public static void DotNormal( ref Plane left, ref Vec3 right, out float result ) { - result = (left.Normal.X * right.X) + (left.Normal.Y * right.Y) + (left.Normal.Z * right.Z); + result = ( left.Normal.X * right.X ) + ( left.Normal.Y * right.Y ) + ( left.Normal.Z * right.Z ); } /// @@ -393,9 +406,9 @@ namespace math /// The source plane. /// The source vector. /// The dot product of the specified vector and the normal of the plane. - public static float DotNormal(Plane left, Vec3 right) + public static float DotNormal( Plane left, Vec3 right ) { - return (left.Normal.X * right.X) + (left.Normal.Y * right.Y) + (left.Normal.Z * right.Z); + return ( left.Normal.X * right.X ) + ( left.Normal.Y * right.Y ) + ( left.Normal.Z * right.Z ); } /// @@ -404,14 +417,14 @@ namespace math /// The plane to project the point to. /// The point to project. /// The projected point. - public static void Project(ref Plane plane, ref Vec3 point, out Vec3 result) + public static void Project( ref Plane plane, ref Vec3 point, out Vec3 result ) { float distance; - DotCoordinate(ref plane, ref point, out distance); + DotCoordinate( ref plane, ref point, out distance ); // compute: point - distance * plane.Normal - Vec3.Multiply(ref plane.Normal, distance, out result); - Vec3.Subtract(ref point, ref result, out result); + Vec3.Multiply( ref plane.Normal, distance, out result ); + Vec3.Subtract( ref point, ref result, out result ); } /// @@ -420,10 +433,10 @@ namespace math /// The plane to project the point to. /// The point to project. /// The projected point. - public static Vec3 Project(Plane plane, Vec3 point) + public static Vec3 Project( Plane plane, Vec3 point ) { Vec3 result; - Project(ref plane, ref point, out result); + Project( ref plane, ref point, out result ); return result; } @@ -432,9 +445,9 @@ namespace math /// /// The source plane. /// When the method completes, contains the normalized plane. - public static void Normalize(ref Plane plane, out Plane result) + public static void Normalize( ref Plane plane, out Plane result ) { - float magnitude = 1.0f / (float)(Math.Sqrt((plane.Normal.X * plane.Normal.X) + (plane.Normal.Y * plane.Normal.Y) + (plane.Normal.Z * plane.Normal.Z))); + float magnitude = 1.0f / (float)( Math.Sqrt( ( plane.Normal.X * plane.Normal.X ) + ( plane.Normal.Y * plane.Normal.Y ) + ( plane.Normal.Z * plane.Normal.Z ) ) ); result.Normal.X = plane.Normal.X * magnitude; result.Normal.Y = plane.Normal.Y * magnitude; @@ -447,10 +460,10 @@ namespace math /// /// The source plane. /// The normalized plane. - public static Plane Normalize(Plane plane) + public static Plane Normalize( Plane plane ) { - float magnitude = 1.0f / (float)(Math.Sqrt((plane.Normal.X * plane.Normal.X) + (plane.Normal.Y * plane.Normal.Y) + (plane.Normal.Z * plane.Normal.Z))); - return new Plane(plane.Normal.X * magnitude, plane.Normal.Y * magnitude, plane.Normal.Z * magnitude, plane.D * magnitude); + float magnitude = 1.0f / (float)( Math.Sqrt( ( plane.Normal.X * plane.Normal.X ) + ( plane.Normal.Y * plane.Normal.Y ) + ( plane.Normal.Z * plane.Normal.Z ) ) ); + return new Plane( plane.Normal.X * magnitude, plane.Normal.Y * magnitude, plane.Normal.Z * magnitude, plane.D * magnitude ); } /// @@ -458,7 +471,7 @@ namespace math /// /// The source plane. /// When the method completes, contains the flipped plane. - public static void Negate(ref Plane plane, out Plane result) + public static void Negate( ref Plane plane, out Plane result ) { result.Normal.X = -plane.Normal.X; result.Normal.Y = -plane.Normal.Y; @@ -471,10 +484,10 @@ namespace math /// /// The source plane. /// The flipped plane. - public static Plane Negate(Plane plane) + public static Plane Negate( Plane plane ) { - float magnitude = 1.0f / (float)(Math.Sqrt((plane.Normal.X * plane.Normal.X) + (plane.Normal.Y * plane.Normal.Y) + (plane.Normal.Z * plane.Normal.Z))); - return new Plane(plane.Normal.X * magnitude, plane.Normal.Y * magnitude, plane.Normal.Z * magnitude, plane.D * magnitude); + float magnitude = 1.0f / (float)( Math.Sqrt( ( plane.Normal.X * plane.Normal.X ) + ( plane.Normal.Y * plane.Normal.Y ) + ( plane.Normal.Z * plane.Normal.Z ) ) ); + return new Plane( plane.Normal.X * magnitude, plane.Normal.Y * magnitude, plane.Normal.Z * magnitude, plane.D * magnitude ); } /// @@ -483,7 +496,7 @@ namespace math /// The normalized source plane. /// The quaternion rotation. /// When the method completes, contains the transformed plane. - public static void Transform(ref Plane plane, ref Quaternion rotation, out Plane result) + public static void Transform( ref Plane plane, ref Quaternion rotation, out Plane result ) { float x2 = rotation.X + rotation.X; float y2 = rotation.Y + rotation.Y; @@ -502,9 +515,9 @@ namespace math float y = plane.Normal.Y; float z = plane.Normal.Z; - result.Normal.X = ((x * ((1.0f - yy) - zz)) + (y * (xy - wz))) + (z * (xz + wy)); - result.Normal.Y = ((x * (xy + wz)) + (y * ((1.0f - xx) - zz))) + (z * (yz - wx)); - result.Normal.Z = ((x * (xz - wy)) + (y * (yz + wx))) + (z * ((1.0f - xx) - yy)); + result.Normal.X = ( ( x * ( ( 1.0f - yy ) - zz ) ) + ( y * ( xy - wz ) ) ) + ( z * ( xz + wy ) ); + result.Normal.Y = ( ( x * ( xy + wz ) ) + ( y * ( ( 1.0f - xx ) - zz ) ) ) + ( z * ( yz - wx ) ); + result.Normal.Z = ( ( x * ( xz - wy ) ) + ( y * ( yz + wx ) ) ) + ( z * ( ( 1.0f - xx ) - yy ) ); result.D = plane.D; } @@ -514,7 +527,7 @@ namespace math /// The normalized source plane. /// The quaternion rotation. /// The transformed plane. - public static Plane Transform(Plane plane, Quaternion rotation) + public static Plane Transform( Plane plane, Quaternion rotation ) { Plane result; float x2 = rotation.X + rotation.X; @@ -534,9 +547,9 @@ namespace math float y = plane.Normal.Y; float z = plane.Normal.Z; - result.Normal.X = ((x * ((1.0f - yy) - zz)) + (y * (xy - wz))) + (z * (xz + wy)); - result.Normal.Y = ((x * (xy + wz)) + (y * ((1.0f - xx) - zz))) + (z * (yz - wx)); - result.Normal.Z = ((x * (xz - wy)) + (y * (yz + wx))) + (z * ((1.0f - xx) - yy)); + result.Normal.X = ( ( x * ( ( 1.0f - yy ) - zz ) ) + ( y * ( xy - wz ) ) ) + ( z * ( xz + wy ) ); + result.Normal.Y = ( ( x * ( xy + wz ) ) + ( y * ( ( 1.0f - xx ) - zz ) ) ) + ( z * ( yz - wx ) ); + result.Normal.Z = ( ( x * ( xz - wy ) ) + ( y * ( yz + wx ) ) ) + ( z * ( ( 1.0f - xx ) - yy ) ); result.D = plane.D; return result; @@ -548,10 +561,10 @@ namespace math /// The array of normalized planes to transform. /// The quaternion rotation. /// Thrown when is null. - public static void Transform(Plane[] planes, ref Quaternion rotation) + public static void Transform( Plane[] planes, ref Quaternion rotation ) { - if (planes == null) - throw new ArgumentNullException("planes"); + if( planes == null ) + throw new ArgumentNullException( "planes" ); float x2 = rotation.X + rotation.X; float y2 = rotation.Y + rotation.Y; @@ -566,7 +579,7 @@ namespace math float yz = rotation.Y * z2; float zz = rotation.Z * z2; - for (int i = 0; i < planes.Length; ++i) + for( int i = 0; i < planes.Length; ++i ) { float x = planes[i].Normal.X; float y = planes[i].Normal.Y; @@ -576,9 +589,9 @@ namespace math * Note: * Factor common arithmetic out of loop. */ - planes[i].Normal.X = ((x * ((1.0f - yy) - zz)) + (y * (xy - wz))) + (z * (xz + wy)); - planes[i].Normal.Y = ((x * (xy + wz)) + (y * ((1.0f - xx) - zz))) + (z * (yz - wx)); - planes[i].Normal.Z = ((x * (xz - wy)) + (y * (yz + wx))) + (z * ((1.0f - xx) - yy)); + planes[i].Normal.X = ( ( x * ( ( 1.0f - yy ) - zz ) ) + ( y * ( xy - wz ) ) ) + ( z * ( xz + wy ) ); + planes[i].Normal.Y = ( ( x * ( xy + wz ) ) + ( y * ( ( 1.0f - xx ) - zz ) ) ) + ( z * ( yz - wx ) ); + planes[i].Normal.Z = ( ( x * ( xz - wy ) ) + ( y * ( yz + wx ) ) ) + ( z * ( ( 1.0f - xx ) - yy ) ); } } @@ -588,7 +601,7 @@ namespace math /// The normalized source plane. /// The transformation matrix. /// When the method completes, contains the transformed plane. - public static void Transform(ref Plane plane, ref Matrix transformation, out Plane result) + public static void Transform( ref Plane plane, ref Matrix transformation, out Plane result ) { float x = plane.Normal.X; float y = plane.Normal.Y; @@ -596,12 +609,12 @@ namespace math float d = plane.D; Matrix inverse; - Matrix.Invert(ref transformation, out inverse); + Matrix.Invert( ref transformation, out inverse ); - result.Normal.X = (((x * inverse.M11) + (y * inverse.M12)) + (z * inverse.M13)) + (d * inverse.M14); - result.Normal.Y = (((x * inverse.M21) + (y * inverse.M22)) + (z * inverse.M23)) + (d * inverse.M24); - result.Normal.Z = (((x * inverse.M31) + (y * inverse.M32)) + (z * inverse.M33)) + (d * inverse.M34); - result.D = (((x * inverse.M41) + (y * inverse.M42)) + (z * inverse.M43)) + (d * inverse.M44); + result.Normal.X = ( ( ( x * inverse.M11 ) + ( y * inverse.M12 ) ) + ( z * inverse.M13 ) ) + ( d * inverse.M14 ); + result.Normal.Y = ( ( ( x * inverse.M21 ) + ( y * inverse.M22 ) ) + ( z * inverse.M23 ) ) + ( d * inverse.M24 ); + result.Normal.Z = ( ( ( x * inverse.M31 ) + ( y * inverse.M32 ) ) + ( z * inverse.M33 ) ) + ( d * inverse.M34 ); + result.D = ( ( ( x * inverse.M41 ) + ( y * inverse.M42 ) ) + ( z * inverse.M43 ) ) + ( d * inverse.M44 ); } /// @@ -610,7 +623,7 @@ namespace math /// The normalized source plane. /// The transformation matrix. /// When the method completes, contains the transformed plane. - public static Plane Transform(Plane plane, Matrix transformation) + public static Plane Transform( Plane plane, Matrix transformation ) { Plane result; float x = plane.Normal.X; @@ -619,10 +632,10 @@ namespace math float d = plane.D; transformation.Invert(); - result.Normal.X = (((x * transformation.M11) + (y * transformation.M12)) + (z * transformation.M13)) + (d * transformation.M14); - result.Normal.Y = (((x * transformation.M21) + (y * transformation.M22)) + (z * transformation.M23)) + (d * transformation.M24); - result.Normal.Z = (((x * transformation.M31) + (y * transformation.M32)) + (z * transformation.M33)) + (d * transformation.M34); - result.D = (((x * transformation.M41) + (y * transformation.M42)) + (z * transformation.M43)) + (d * transformation.M44); + result.Normal.X = ( ( ( x * transformation.M11 ) + ( y * transformation.M12 ) ) + ( z * transformation.M13 ) ) + ( d * transformation.M14 ); + result.Normal.Y = ( ( ( x * transformation.M21 ) + ( y * transformation.M22 ) ) + ( z * transformation.M23 ) ) + ( d * transformation.M24 ); + result.Normal.Z = ( ( ( x * transformation.M31 ) + ( y * transformation.M32 ) ) + ( z * transformation.M33 ) ) + ( d * transformation.M34 ); + result.D = ( ( ( x * transformation.M41 ) + ( y * transformation.M42 ) ) + ( z * transformation.M43 ) ) + ( d * transformation.M44 ); return result; } @@ -633,17 +646,17 @@ namespace math /// The array of normalized planes to transform. /// The transformation matrix. /// Thrown when is null. - public static void Transform(Plane[] planes, ref Matrix transformation) + public static void Transform( Plane[] planes, ref Matrix transformation ) { - if (planes == null) - throw new ArgumentNullException("planes"); + if( planes == null ) + throw new ArgumentNullException( "planes" ); Matrix inverse; - Matrix.Invert(ref transformation, out inverse); + Matrix.Invert( ref transformation, out inverse ); - for (int i = 0; i < planes.Length; ++i) + for( int i = 0; i < planes.Length; ++i ) { - Transform(ref planes[i], ref transformation, out planes[i]); + Transform( ref planes[i], ref transformation, out planes[i] ); } } @@ -653,9 +666,9 @@ namespace math /// The amount by which to scale the plane. /// The plane to scale. /// The scaled plane. - public static Plane operator *(float scale, Plane plane) + public static Plane operator *( float scale, Plane plane ) { - return new Plane(plane.Normal.X * scale, plane.Normal.Y * scale, plane.Normal.Z * scale, plane.D * scale); + return new Plane( plane.Normal.X * scale, plane.Normal.Y * scale, plane.Normal.Z * scale, plane.D * scale ); } /// @@ -664,18 +677,18 @@ namespace math /// The plane to scale. /// The amount by which to scale the plane. /// The scaled plane. - public static Plane operator *(Plane plane, float scale) + public static Plane operator *( Plane plane, float scale ) { - return new Plane(plane.Normal.X * scale, plane.Normal.Y * scale, plane.Normal.Z * scale, plane.D * scale); + return new Plane( plane.Normal.X * scale, plane.Normal.Y * scale, plane.Normal.Z * scale, plane.D * scale ); } /// /// Negates a plane by negating all its coefficients, which result in a plane in opposite direction. /// /// The negated plane. - public static Plane operator -(Plane plane) + public static Plane operator -( Plane plane ) { - return new Plane(-plane.Normal.X, -plane.Normal.Y, -plane.Normal.Z, -plane.D); + return new Plane( -plane.Normal.X, -plane.Normal.Y, -plane.Normal.Z, -plane.D ); } /// @@ -684,9 +697,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Plane left, Plane right) + public static bool operator ==( Plane left, Plane right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -695,9 +708,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Plane left, Plane right) + public static bool operator !=( Plane left, Plane right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -708,7 +721,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "A:{0} B:{1} C:{2} D:{3}", Normal.X, Normal.Y, Normal.Z, D); + return string.Format( CultureInfo.CurrentCulture, "A:{0} B:{1} C:{2} D:{3}", Normal.X, Normal.Y, Normal.Z, D ); } /// @@ -718,10 +731,10 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - return string.Format(CultureInfo.CurrentCulture, "A:{0} B:{1} C:{2} D:{3}", Normal.X.ToString(format, CultureInfo.CurrentCulture), - Normal.Y.ToString(format, CultureInfo.CurrentCulture), Normal.Z.ToString(format, CultureInfo.CurrentCulture), D.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "A:{0} B:{1} C:{2} D:{3}", Normal.X.ToString( format, CultureInfo.CurrentCulture ), + Normal.Y.ToString( format, CultureInfo.CurrentCulture ), Normal.Z.ToString( format, CultureInfo.CurrentCulture ), D.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -731,9 +744,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "A:{0} B:{1} C:{2} D:{3}", Normal.X, Normal.Y, Normal.Z, D); + return string.Format( formatProvider, "A:{0} B:{1} C:{2} D:{3}", Normal.X, Normal.Y, Normal.Z, D ); } /// @@ -744,17 +757,17 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - return string.Format(formatProvider, "A:{0} B:{1} C:{2} D:{3}", Normal.X.ToString(format, formatProvider), - Normal.Y.ToString(format, formatProvider), Normal.Z.ToString(format, formatProvider), D.ToString(format, formatProvider)); + return string.Format( formatProvider, "A:{0} B:{1} C:{2} D:{3}", Normal.X.ToString( format, formatProvider ), + Normal.Y.ToString( format, formatProvider ), Normal.Z.ToString( format, formatProvider ), D.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -768,7 +781,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Plane value) + public bool Equals( Plane value ) { return Normal == value.Normal && D == value.D; } @@ -780,15 +793,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Plane)value); + return Equals( (Plane)value ); } #if SlimDX1xInterop diff --git a/math/PlaneIntersectionType.cs b/math/PlaneIntersectionType.cs index c863bed..5216974 100644 --- a/math/PlaneIntersectionType.cs +++ b/math/PlaneIntersectionType.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 diff --git a/math/Point.cs b/math/Point.cs index 5160c39..68f543f 100644 --- a/math/Point.cs +++ b/math/Point.cs @@ -32,20 +32,20 @@ namespace math /// A 2D point. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Point : IEquatable { /// /// A point with (0,0) coordinates. /// - public static readonly Point Zero = new Point(0, 0); + public static readonly Point Zero = new Point( 0, 0 ); /// /// Initializes a new instance of the struct. /// /// The x. /// The y. - public Point(int x, int y) + public Point( int x, int y ) { X = x; Y = y; @@ -70,17 +70,19 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Point other) + public bool Equals( Point other ) { return other.X == X && other.Y == Y; } /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != typeof(Point)) return false; - return Equals((Point)obj); + if( ReferenceEquals( null, obj ) ) + return false; + if( obj.GetType() != typeof( Point ) ) + return false; + return Equals( (Point)obj ); } /// @@ -88,7 +90,7 @@ namespace math { unchecked { - return (X * 397) ^ Y; + return ( X * 397 ) ^ Y; } } @@ -100,9 +102,9 @@ namespace math /// /// The result of the operator. /// - public static bool operator ==(Point left, Point right) + public static bool operator ==( Point left, Point right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -113,15 +115,15 @@ namespace math /// /// The result of the operator. /// - public static bool operator !=(Point left, Point right) + public static bool operator !=( Point left, Point right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// public override string ToString() { - return string.Format("({0},{1})", X, Y); + return string.Format( "({0},{1})", X, Y ); } /// @@ -129,9 +131,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Point(Vec2 value) + public static explicit operator Point( Vec2 value ) { - return new Point((int)value.X, (int)value.Y); + return new Point( (int)value.X, (int)value.Y ); } /// @@ -139,9 +141,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static implicit operator Vec2(Point value) + public static implicit operator Vec2( Point value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } - } + } } diff --git a/math/Quaternion.cs b/math/Quaternion.cs index 6d476d6..5b3284b 100644 --- a/math/Quaternion.cs +++ b/math/Quaternion.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -36,9 +36,9 @@ namespace math /// /// Represents a four dimensional mathematical quaternion. /// - [DataContract( Name = "quaternion")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "quaternion" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Quaternion : IEquatable, IFormattable { /// @@ -54,12 +54,12 @@ namespace math /// /// A with all of its components set to one. /// - public static readonly Quaternion One = new Quaternion(1.0f, 1.0f, 1.0f, 1.0f); + public static readonly Quaternion One = new Quaternion( 1.0f, 1.0f, 1.0f, 1.0f ); /// /// The identity (0, 0, 0, 1). /// - public static readonly Quaternion Identity = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); + public static readonly Quaternion Identity = new Quaternion( 0.0f, 0.0f, 0.0f, 1.0f ); /// /// The X component of the quaternion. @@ -85,7 +85,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Quaternion(float value) + public Quaternion( float value ) { X = value; Y = value; @@ -97,7 +97,7 @@ namespace math /// Initializes a new instance of the struct. /// /// A vector containing the values with which to initialize the components. - public Quaternion(Vec4 value) + public Quaternion( Vec4 value ) { X = value.X; Y = value.Y; @@ -110,7 +110,7 @@ namespace math /// /// A vector containing the values with which to initialize the X, Y, and Z components. /// Initial value for the W component of the quaternion. - public Quaternion(Vec3 value, float w) + public Quaternion( Vec3 value, float w ) { X = value.X; Y = value.Y; @@ -124,7 +124,7 @@ namespace math /// A vector containing the values with which to initialize the X and Y components. /// Initial value for the Z component of the quaternion. /// Initial value for the W component of the quaternion. - public Quaternion(Vec2 value, float z, float w) + public Quaternion( Vec2 value, float z, float w ) { X = value.X; Y = value.Y; @@ -139,7 +139,7 @@ namespace math /// Initial value for the Y component of the quaternion. /// Initial value for the Z component of the quaternion. /// Initial value for the W component of the quaternion. - public Quaternion(float x, float y, float z, float w) + public Quaternion( float x, float y, float z, float w ) { X = x; Y = y; @@ -153,12 +153,12 @@ namespace math /// The values to assign to the X, Y, Z, and W components of the quaternion. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Quaternion(float[] values) + public Quaternion( float[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 4) - throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for Quaternion."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( "values", "There must be four and only four input values for Quaternion." ); X = values[0]; Y = values[1]; @@ -174,7 +174,7 @@ namespace math /// public bool IsIdentity { - get { return this.Equals(Identity); } + get { return this.Equals( Identity ); } } /// @@ -182,7 +182,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) + (Z * Z) + (W * W) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -193,11 +193,11 @@ namespace math { get { - float length = (X * X) + (Y * Y) + (Z * Z); - if (length < MathUtil.ZeroTolerance) + float length = ( X * X ) + ( Y * Y ) + ( Z * Z ); + if( length < MathUtil.ZeroTolerance ) return 0.0f; - return (float)(2.0 * Math.Acos(W)); + return (float)( 2.0 * Math.Acos( W ) ); } } @@ -209,12 +209,12 @@ namespace math { get { - float length = (X * X) + (Y * Y) + (Z * Z); - if (length < MathUtil.ZeroTolerance) + float length = ( X * X ) + ( Y * Y ) + ( Z * Z ); + if( length < MathUtil.ZeroTolerance ) return Vec3.UnitX; float inv = 1.0f / length; - return new Vec3(X * inv, Y * inv, Z * inv); + return new Vec3( X * inv, Y * inv, Z * inv ); } } @@ -226,7 +226,7 @@ namespace math get { Vec3 yawPitchRoll; - RotationYawPitchRoll(ref this, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z); + RotationYawPitchRoll( ref this, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z ); return yawPitchRoll; } } @@ -242,26 +242,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; - case 2: return Z; - case 3: return W; + case 0: + return X; + case 1: + return Y; + case 2: + return Z; + case 3: + return W; } - throw new ArgumentOutOfRangeException("index", "Indices for Quaternion run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Quaternion run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - case 2: Z = value; break; - case 3: W = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Quaternion run from 0 to 3, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + case 2: + Z = value; + break; + case 3: + W = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Quaternion run from 0 to 3, inclusive." ); } } } @@ -282,7 +295,7 @@ namespace math public void Invert() { float lengthSq = LengthSquared(); - if (lengthSq > MathUtil.ZeroTolerance) + if( lengthSq > MathUtil.ZeroTolerance ) { lengthSq = 1.0f / lengthSq; @@ -303,7 +316,7 @@ namespace math /// public float Length() { - return (float)Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); + return (float)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) ); } /// @@ -316,7 +329,7 @@ namespace math /// public float LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z) + (W * W); + return ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ); } /// @@ -325,7 +338,7 @@ namespace math public void Normalize() { float length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { float inverse = 1.0f / length; X *= inverse; @@ -350,7 +363,7 @@ namespace math /// The first quaternion to add. /// The second quaternion to add. /// When the method completes, contains the sum of the two quaternions. - public static void Add(ref Quaternion left, ref Quaternion right, out Quaternion result) + public static void Add( ref Quaternion left, ref Quaternion right, out Quaternion result ) { result.X = left.X + right.X; result.Y = left.Y + right.Y; @@ -364,10 +377,10 @@ namespace math /// The first quaternion to add. /// The second quaternion to add. /// The sum of the two quaternions. - public static Quaternion Add(Quaternion left, Quaternion right) + public static Quaternion Add( Quaternion left, Quaternion right ) { Quaternion result; - Add(ref left, ref right, out result); + Add( ref left, ref right, out result ); return result; } @@ -377,7 +390,7 @@ namespace math /// The first quaternion to subtract. /// The second quaternion to subtract. /// When the method completes, contains the difference of the two quaternions. - public static void Subtract(ref Quaternion left, ref Quaternion right, out Quaternion result) + public static void Subtract( ref Quaternion left, ref Quaternion right, out Quaternion result ) { result.X = left.X - right.X; result.Y = left.Y - right.Y; @@ -391,10 +404,10 @@ namespace math /// The first quaternion to subtract. /// The second quaternion to subtract. /// The difference of the two quaternions. - public static Quaternion Subtract(Quaternion left, Quaternion right) + public static Quaternion Subtract( Quaternion left, Quaternion right ) { Quaternion result; - Subtract(ref left, ref right, out result); + Subtract( ref left, ref right, out result ); return result; } @@ -404,7 +417,7 @@ namespace math /// The quaternion to scale. /// The amount by which to scale the quaternion. /// When the method completes, contains the scaled quaternion. - public static void Multiply(ref Quaternion value, float scale, out Quaternion result) + public static void Multiply( ref Quaternion value, float scale, out Quaternion result ) { result.X = value.X * scale; result.Y = value.Y * scale; @@ -418,10 +431,10 @@ namespace math /// The quaternion to scale. /// The amount by which to scale the quaternion. /// The scaled quaternion. - public static Quaternion Multiply(Quaternion value, float scale) + public static Quaternion Multiply( Quaternion value, float scale ) { Quaternion result; - Multiply(ref value, scale, out result); + Multiply( ref value, scale, out result ); return result; } @@ -431,7 +444,7 @@ namespace math /// The first quaternion to modulate. /// The second quaternion to modulate. /// When the moethod completes, contains the modulated quaternion. - public static void Multiply(ref Quaternion left, ref Quaternion right, out Quaternion result) + public static void Multiply( ref Quaternion left, ref Quaternion right, out Quaternion result ) { float lx = left.X; float ly = left.Y; @@ -442,10 +455,10 @@ namespace math float rz = right.Z; float rw = right.W; - result.X = (rx * lw + lx * rw + ry * lz) - (rz * ly); - result.Y = (ry * lw + ly * rw + rz * lx) - (rx * lz); - result.Z = (rz * lw + lz * rw + rx * ly) - (ry * lx); - result.W = (rw * lw) - (rx * lx + ry * ly + rz * lz); + result.X = ( rx * lw + lx * rw + ry * lz ) - ( rz * ly ); + result.Y = ( ry * lw + ly * rw + rz * lx ) - ( rx * lz ); + result.Z = ( rz * lw + lz * rw + rx * ly ) - ( ry * lx ); + result.W = ( rw * lw ) - ( rx * lx + ry * ly + rz * lz ); } /// @@ -454,19 +467,19 @@ namespace math /// The first quaternion to modulate. /// The second quaternion to modulate. /// The modulated quaternion. - public static Quaternion Multiply(Quaternion left, Quaternion right) + public static Quaternion Multiply( Quaternion left, Quaternion right ) { Quaternion result; - Multiply(ref left, ref right, out result); + Multiply( ref left, ref right, out result ); return result; } - + /// /// Reverses the direction of a given quaternion. /// /// The quaternion to negate. /// When the method completes, contains a quaternion facing in the opposite direction. - public static void Negate(ref Quaternion value, out Quaternion result) + public static void Negate( ref Quaternion value, out Quaternion result ) { result.X = -value.X; result.Y = -value.Y; @@ -479,10 +492,10 @@ namespace math /// /// The quaternion to negate. /// A quaternion facing in the opposite direction. - public static Quaternion Negate(Quaternion value) + public static Quaternion Negate( Quaternion value ) { Quaternion result; - Negate(ref value, out result); + Negate( ref value, out result ); return result; } @@ -495,12 +508,12 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains a new containing the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, float amount1, float amount2, out Quaternion result) + public static void Barycentric( ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, float amount1, float amount2, out Quaternion result ) { Quaternion start, end; - Slerp(ref value1, ref value2, amount1 + amount2, out start); - Slerp(ref value1, ref value3, amount1 + amount2, out end); - Slerp(ref start, ref end, amount2 / (amount1 + amount2), out result); + Slerp( ref value1, ref value2, amount1 + amount2, out start ); + Slerp( ref value1, ref value3, amount1 + amount2, out end ); + Slerp( ref start, ref end, amount2 / ( amount1 + amount2 ), out result ); } /// @@ -512,10 +525,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 4D Cartesian coordinates of the specified point. - public static Quaternion Barycentric(Quaternion value1, Quaternion value2, Quaternion value3, float amount1, float amount2) + public static Quaternion Barycentric( Quaternion value1, Quaternion value2, Quaternion value3, float amount1, float amount2 ) { Quaternion result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -524,7 +537,7 @@ namespace math /// /// The quaternion to conjugate. /// When the method completes, contains the conjugated quaternion. - public static void Conjugate(ref Quaternion value, out Quaternion result) + public static void Conjugate( ref Quaternion value, out Quaternion result ) { result.X = -value.X; result.Y = -value.Y; @@ -537,10 +550,10 @@ namespace math /// /// The quaternion to conjugate. /// The conjugated quaternion. - public static Quaternion Conjugate(Quaternion value) + public static Quaternion Conjugate( Quaternion value ) { Quaternion result; - Conjugate(ref value, out result); + Conjugate( ref value, out result ); return result; } @@ -550,9 +563,9 @@ namespace math /// First source quaternion. /// Second source quaternion. /// When the method completes, contains the dot product of the two quaternions. - public static void Dot(ref Quaternion left, ref Quaternion right, out float result) + public static void Dot( ref Quaternion left, ref Quaternion right, out float result ) { - result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W); + result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ) + ( left.W * right.W ); } /// @@ -561,9 +574,9 @@ namespace math /// First source quaternion. /// Second source quaternion. /// The dot product of the two quaternions. - public static float Dot(Quaternion left, Quaternion right) + public static float Dot( Quaternion left, Quaternion right ) { - return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W); + return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ) + ( left.W * right.W ); } /// @@ -571,12 +584,12 @@ namespace math /// /// The quaternion to exponentiate. /// When the method completes, contains the exponentiated quaternion. - public static void Exponential(ref Quaternion value, out Quaternion result) + public static void Exponential( ref Quaternion value, out Quaternion result ) { - float angle = (float)Math.Sqrt((value.X * value.X) + (value.Y * value.Y) + (value.Z * value.Z)); - float sin = (float)Math.Sin(angle); + float angle = (float)Math.Sqrt( ( value.X * value.X ) + ( value.Y * value.Y ) + ( value.Z * value.Z ) ); + float sin = (float)Math.Sin( angle ); - if (Math.Abs(sin) >= MathUtil.ZeroTolerance) + if( Math.Abs( sin ) >= MathUtil.ZeroTolerance ) { float coeff = sin / angle; result.X = coeff * value.X; @@ -588,7 +601,7 @@ namespace math result = value; } - result.W = (float)Math.Cos(angle); + result.W = (float)Math.Cos( angle ); } /// @@ -596,10 +609,10 @@ namespace math /// /// The quaternion to exponentiate. /// The exponentiated quaternion. - public static Quaternion Exponential(Quaternion value) + public static Quaternion Exponential( Quaternion value ) { Quaternion result; - Exponential(ref value, out result); + Exponential( ref value, out result ); return result; } @@ -608,7 +621,7 @@ namespace math /// /// The quaternion to conjugate and renormalize. /// When the method completes, contains the conjugated and renormalized quaternion. - public static void Invert(ref Quaternion value, out Quaternion result) + public static void Invert( ref Quaternion value, out Quaternion result ) { result = value; result.Invert(); @@ -619,10 +632,10 @@ namespace math /// /// The quaternion to conjugate and renormalize. /// The conjugated and renormalized quaternion. - public static Quaternion Invert(Quaternion value) + public static Quaternion Invert( Quaternion value ) { Quaternion result; - Invert(ref value, out result); + Invert( ref value, out result ); return result; } @@ -636,25 +649,25 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Quaternion start, ref Quaternion end, float amount, out Quaternion result) + public static void Lerp( ref Quaternion start, ref Quaternion end, float amount, out Quaternion result ) { float inverse = 1.0f - amount; - if (Dot(start, end) >= 0.0f) + if( Dot( start, end ) >= 0.0f ) { - result.X = (inverse * start.X) + (amount * end.X); - result.Y = (inverse * start.Y) + (amount * end.Y); - result.Z = (inverse * start.Z) + (amount * end.Z); - result.W = (inverse * start.W) + (amount * end.W); + result.X = ( inverse * start.X ) + ( amount * end.X ); + result.Y = ( inverse * start.Y ) + ( amount * end.Y ); + result.Z = ( inverse * start.Z ) + ( amount * end.Z ); + result.W = ( inverse * start.W ) + ( amount * end.W ); } else { - result.X = (inverse * start.X) - (amount * end.X); - result.Y = (inverse * start.Y) - (amount * end.Y); - result.Z = (inverse * start.Z) - (amount * end.Z); - result.W = (inverse * start.W) - (amount * end.W); + result.X = ( inverse * start.X ) - ( amount * end.X ); + result.Y = ( inverse * start.Y ) - ( amount * end.Y ); + result.Z = ( inverse * start.Z ) - ( amount * end.Z ); + result.W = ( inverse * start.W ) - ( amount * end.W ); } result.Normalize(); @@ -670,12 +683,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Quaternion Lerp(Quaternion start, Quaternion end, float amount) + public static Quaternion Lerp( Quaternion start, Quaternion end, float amount ) { Quaternion result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -684,14 +697,14 @@ namespace math /// /// The quaternion whose logarithm will be calculated. /// When the method completes, contains the natural logarithm of the quaternion. - public static void Logarithm(ref Quaternion value, out Quaternion result) + public static void Logarithm( ref Quaternion value, out Quaternion result ) { - if (Math.Abs(value.W) < 1.0) + if( Math.Abs( value.W ) < 1.0 ) { - float angle = (float)Math.Acos(value.W); - float sin = (float)Math.Sin(angle); + float angle = (float)Math.Acos( value.W ); + float sin = (float)Math.Sin( angle ); - if (Math.Abs(sin) >= MathUtil.ZeroTolerance) + if( Math.Abs( sin ) >= MathUtil.ZeroTolerance ) { float coeff = angle / sin; result.X = value.X * coeff; @@ -716,10 +729,10 @@ namespace math /// /// The quaternion whose logarithm will be calculated. /// The natural logarithm of the quaternion. - public static Quaternion Logarithm(Quaternion value) + public static Quaternion Logarithm( Quaternion value ) { Quaternion result; - Logarithm(ref value, out result); + Logarithm( ref value, out result ); return result; } @@ -728,7 +741,7 @@ namespace math /// /// The quaternion to normalize. /// When the method completes, contains the normalized quaternion. - public static void Normalize(ref Quaternion value, out Quaternion result) + public static void Normalize( ref Quaternion value, out Quaternion result ) { Quaternion temp = value; result = temp; @@ -740,7 +753,7 @@ namespace math /// /// The quaternion to normalize. /// The normalized quaternion. - public static Quaternion Normalize(Quaternion value) + public static Quaternion Normalize( Quaternion value ) { value.Normalize(); return value; @@ -750,10 +763,10 @@ namespace math /// Rotates a Vector3 by the specified quaternion rotation. /// /// The vector to rotate. - public void Rotate(ref Vec3 vector) + public void Rotate( ref Vec3 vector ) { - var pureQuaternion = new Quaternion(vector, 0); - pureQuaternion = Conjugate(this) * pureQuaternion * this; + var pureQuaternion = new Quaternion( vector, 0 ); + pureQuaternion = Conjugate( this ) * pureQuaternion * this; vector.X = pureQuaternion.X; vector.Y = pureQuaternion.Y; @@ -766,14 +779,14 @@ namespace math /// The axis of rotation. /// The angle of rotation. /// When the method completes, contains the newly created quaternion. - public static void RotationAxis(ref Vec3 axis, float angle, out Quaternion result) + public static void RotationAxis( ref Vec3 axis, float angle, out Quaternion result ) { Vec3 normalized; - Vec3.Normalize(ref axis, out normalized); + Vec3.Normalize( ref axis, out normalized ); float half = angle * 0.5f; - float sin = (float)Math.Sin(half); - float cos = (float)Math.Cos(half); + float sin = (float)Math.Sin( half ); + float cos = (float)Math.Cos( half ); result.X = normalized.X * sin; result.Y = normalized.Y * sin; @@ -787,10 +800,10 @@ namespace math /// The axis of rotation. /// The angle of rotation. /// The newly created quaternion. - public static Quaternion RotationAxis(Vec3 axis, float angle) + public static Quaternion RotationAxis( Vec3 axis, float angle ) { Quaternion result; - RotationAxis(ref axis, angle, out result); + RotationAxis( ref axis, angle, out result ); return result; } @@ -799,51 +812,51 @@ namespace math /// /// The rotation matrix. /// When the method completes, contains the newly created quaternion. - public static void RotationMatrix(ref Matrix matrix, out Quaternion result) + public static void RotationMatrix( ref Matrix matrix, out Quaternion result ) { float sqrt; float half; float scale = matrix.M11 + matrix.M22 + matrix.M33; - if (scale > 0.0f) + if( scale > 0.0f ) { - sqrt = (float)Math.Sqrt(scale + 1.0f); + sqrt = (float)Math.Sqrt( scale + 1.0f ); result.W = sqrt * 0.5f; sqrt = 0.5f / sqrt; - result.X = (matrix.M23 - matrix.M32) * sqrt; - result.Y = (matrix.M31 - matrix.M13) * sqrt; - result.Z = (matrix.M12 - matrix.M21) * sqrt; + result.X = ( matrix.M23 - matrix.M32 ) * sqrt; + result.Y = ( matrix.M31 - matrix.M13 ) * sqrt; + result.Z = ( matrix.M12 - matrix.M21 ) * sqrt; } - else if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) + else if( ( matrix.M11 >= matrix.M22 ) && ( matrix.M11 >= matrix.M33 ) ) { - sqrt = (float)Math.Sqrt(1.0f + matrix.M11 - matrix.M22 - matrix.M33); + sqrt = (float)Math.Sqrt( 1.0f + matrix.M11 - matrix.M22 - matrix.M33 ); half = 0.5f / sqrt; result.X = 0.5f * sqrt; - result.Y = (matrix.M12 + matrix.M21) * half; - result.Z = (matrix.M13 + matrix.M31) * half; - result.W = (matrix.M23 - matrix.M32) * half; + result.Y = ( matrix.M12 + matrix.M21 ) * half; + result.Z = ( matrix.M13 + matrix.M31 ) * half; + result.W = ( matrix.M23 - matrix.M32 ) * half; } - else if (matrix.M22 > matrix.M33) + else if( matrix.M22 > matrix.M33 ) { - sqrt = (float)Math.Sqrt(1.0f + matrix.M22 - matrix.M11 - matrix.M33); + sqrt = (float)Math.Sqrt( 1.0f + matrix.M22 - matrix.M11 - matrix.M33 ); half = 0.5f / sqrt; - result.X = (matrix.M21 + matrix.M12) * half; + result.X = ( matrix.M21 + matrix.M12 ) * half; result.Y = 0.5f * sqrt; - result.Z = (matrix.M32 + matrix.M23) * half; - result.W = (matrix.M31 - matrix.M13) * half; + result.Z = ( matrix.M32 + matrix.M23 ) * half; + result.W = ( matrix.M31 - matrix.M13 ) * half; } else { - sqrt = (float)Math.Sqrt(1.0f + matrix.M33 - matrix.M11 - matrix.M22); + sqrt = (float)Math.Sqrt( 1.0f + matrix.M33 - matrix.M11 - matrix.M22 ); half = 0.5f / sqrt; - result.X = (matrix.M31 + matrix.M13) * half; - result.Y = (matrix.M32 + matrix.M23) * half; + result.X = ( matrix.M31 + matrix.M13 ) * half; + result.Y = ( matrix.M32 + matrix.M23 ) * half; result.Z = 0.5f * sqrt; - result.W = (matrix.M12 - matrix.M21) * half; + result.W = ( matrix.M12 - matrix.M21 ) * half; } } @@ -852,10 +865,10 @@ namespace math /// /// The rotation matrix. /// The newly created quaternion. - public static Quaternion RotationMatrix(Matrix matrix) + public static Quaternion RotationMatrix( Matrix matrix ) { Quaternion result; - RotationMatrix(ref matrix, out result); + RotationMatrix( ref matrix, out result ); return result; } @@ -864,10 +877,10 @@ namespace math /// /// Angle of rotation in radians. /// When the method completes, contains the newly created quaternion. - public static void RotationX(float angle, out Quaternion result) + public static void RotationX( float angle, out Quaternion result ) { float halfAngle = angle * 0.5f; - result = new Quaternion((float)Math.Sin(halfAngle), 0.0f, 0.0f, (float)Math.Cos(halfAngle)); + result = new Quaternion( (float)Math.Sin( halfAngle ), 0.0f, 0.0f, (float)Math.Cos( halfAngle ) ); } /// @@ -875,10 +888,10 @@ namespace math /// /// Angle of rotation in radians. /// The created rotation quaternion. - public static Quaternion RotationX(float angle) + public static Quaternion RotationX( float angle ) { Quaternion result; - RotationX(angle, out result); + RotationX( angle, out result ); return result; } @@ -887,10 +900,10 @@ namespace math /// /// Angle of rotation in radians. /// When the method completes, contains the newly created quaternion. - public static void RotationY(float angle, out Quaternion result) + public static void RotationY( float angle, out Quaternion result ) { float halfAngle = angle * 0.5f; - result = new Quaternion(0.0f, (float)Math.Sin(halfAngle), 0.0f, (float)Math.Cos(halfAngle)); + result = new Quaternion( 0.0f, (float)Math.Sin( halfAngle ), 0.0f, (float)Math.Cos( halfAngle ) ); } /// @@ -898,10 +911,10 @@ namespace math /// /// Angle of rotation in radians. /// The created rotation quaternion. - public static Quaternion RotationY(float angle) + public static Quaternion RotationY( float angle ) { Quaternion result; - RotationY(angle, out result); + RotationY( angle, out result ); return result; } @@ -910,10 +923,10 @@ namespace math /// /// Angle of rotation in radians. /// When the method completes, contains the newly created quaternion. - public static void RotationZ(float angle, out Quaternion result) + public static void RotationZ( float angle, out Quaternion result ) { float halfAngle = angle * 0.5f; - result = new Quaternion(0.0f, 0.0f, (float)Math.Sin(halfAngle), (float)Math.Cos(halfAngle)); + result = new Quaternion( 0.0f, 0.0f, (float)Math.Sin( halfAngle ), (float)Math.Cos( halfAngle ) ); } /// @@ -921,10 +934,10 @@ namespace math /// /// Angle of rotation in radians. /// The created rotation quaternion. - public static Quaternion RotationZ(float angle) + public static Quaternion RotationZ( float angle ) { Quaternion result; - RotationZ(angle, out result); + RotationZ( angle, out result ); return result; } @@ -935,7 +948,7 @@ namespace math /// The yaw component /// The pitch component /// The roll component - public static void RotationYawPitchRoll(ref Quaternion rotation, out float yaw, out float pitch, out float roll) + public static void RotationYawPitchRoll( ref Quaternion rotation, out float yaw, out float pitch, out float roll ) { // Equivalent to: // Matrix rotationMatrix; @@ -952,16 +965,16 @@ namespace math var yz = rotation.Y * rotation.Z; var xw = rotation.X * rotation.W; - pitch = (float)Math.Asin(2.0f * (xw - yz)); - double test = Math.Cos(pitch); - if (test > MathUtil.ZeroTolerance) + pitch = (float)Math.Asin( 2.0f * ( xw - yz ) ); + double test = Math.Cos( pitch ); + if( test > MathUtil.ZeroTolerance ) { - roll = (float)Math.Atan2(2.0f * (xy + zw), 1.0f - (2.0f * (zz + xx))); - yaw = (float)Math.Atan2(2.0f * (zx + yw), 1.0f - (2.0f * (yy + xx))); + roll = (float)Math.Atan2( 2.0f * ( xy + zw ), 1.0f - ( 2.0f * ( zz + xx ) ) ); + yaw = (float)Math.Atan2( 2.0f * ( zx + yw ), 1.0f - ( 2.0f * ( yy + xx ) ) ); } else { - roll = (float)Math.Atan2(-2.0f * (xy - zw), 1.0f - (2.0f * (yy + zz))); + roll = (float)Math.Atan2( -2.0f * ( xy - zw ), 1.0f - ( 2.0f * ( yy + zz ) ) ); yaw = 0.0f; } } @@ -973,26 +986,26 @@ namespace math /// The pitch of rotation in radians. /// The roll of rotation in radians. /// When the method completes, contains the newly created quaternion. - public static void RotationYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result) + public static void RotationYawPitchRoll( float yaw, float pitch, float roll, out Quaternion result ) { var halfRoll = roll * 0.5f; var halfPitch = pitch * 0.5f; var halfYaw = yaw * 0.5f; - - var sinRoll = (float)Math.Sin(halfRoll); - var cosRoll = (float)Math.Cos(halfRoll); - var sinPitch = (float)Math.Sin(halfPitch); - var cosPitch = (float)Math.Cos(halfPitch); - var sinYaw = (float)Math.Sin(halfYaw); - var cosYaw = (float)Math.Cos(halfYaw); + + var sinRoll = (float)Math.Sin( halfRoll ); + var cosRoll = (float)Math.Cos( halfRoll ); + var sinPitch = (float)Math.Sin( halfPitch ); + var cosPitch = (float)Math.Cos( halfPitch ); + var sinYaw = (float)Math.Sin( halfYaw ); + var cosYaw = (float)Math.Cos( halfYaw ); var cosYawPitch = cosYaw * cosPitch; var sinYawPitch = sinYaw * sinPitch; - result.X = (cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll); - result.Y = (sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll); - result.Z = (cosYawPitch * sinRoll) - (sinYawPitch * cosRoll); - result.W = (cosYawPitch * cosRoll) + (sinYawPitch * sinRoll); + result.X = ( cosYaw * sinPitch * cosRoll ) + ( sinYaw * cosPitch * sinRoll ); + result.Y = ( sinYaw * cosPitch * cosRoll ) - ( cosYaw * sinPitch * sinRoll ); + result.Z = ( cosYawPitch * sinRoll ) - ( sinYawPitch * cosRoll ); + result.W = ( cosYawPitch * cosRoll ) + ( sinYawPitch * sinRoll ); } /// @@ -1002,10 +1015,10 @@ namespace math /// The pitch of rotation. /// The roll of rotation. /// The newly created quaternion. - public static Quaternion RotationYawPitchRoll(float yaw, float pitch, float roll) + public static Quaternion RotationYawPitchRoll( float yaw, float pitch, float roll ) { Quaternion result; - RotationYawPitchRoll(yaw, pitch, roll, out result); + RotationYawPitchRoll( yaw, pitch, roll, out result ); return result; } @@ -1015,10 +1028,10 @@ namespace math /// The source vector of the transformation. /// The target vector of the transformation. /// The resulting quaternion corresponding to the transformation of the source vector to the target vector. - public static Quaternion BetweenDirections(Vec3 source, Vec3 target) + public static Quaternion BetweenDirections( Vec3 source, Vec3 target ) { Quaternion result; - BetweenDirections(ref source, ref target, out result); + BetweenDirections( ref source, ref target, out result ); return result; } @@ -1028,23 +1041,23 @@ namespace math /// The source vector of the transformation. /// The target vector of the transformation. /// The resulting quaternion corresponding to the transformation of the source vector to the target vector. - public static void BetweenDirections(ref Vec3 source, ref Vec3 target, out Quaternion result) + public static void BetweenDirections( ref Vec3 source, ref Vec3 target, out Quaternion result ) { - var norms = (float)Math.Sqrt(source.LengthSquared() * target.LengthSquared()); - var real = norms + Vec3.Dot(source, target); - if (real < MathUtil.ZeroTolerance * norms) + var norms = (float)Math.Sqrt( source.LengthSquared() * target.LengthSquared() ); + var real = norms + Vec3.Dot( source, target ); + if( real < MathUtil.ZeroTolerance * norms ) { // If source and target are exactly opposite, rotate 180 degrees around an arbitrary orthogonal axis. // Axis normalisation can happen later, when we normalise the quaternion. - result = Math.Abs(source.X) > Math.Abs(source.Z) - ? new Quaternion(-source.Y, source.X, 0.0f, 0.0f) - : new Quaternion(0.0f, -source.Z, source.Y, 0.0f); + result = Math.Abs( source.X ) > Math.Abs( source.Z ) + ? new Quaternion( -source.Y, source.X, 0.0f, 0.0f ) + : new Quaternion( 0.0f, -source.Z, source.Y, 0.0f ); } else { // Otherwise, build quaternion the standard way. - var axis = Vec3.Cross(source, target); - result = new Quaternion(axis, real); + var axis = Vec3.Cross( source, target ); + result = new Quaternion( axis, real ); } result.Normalize(); } @@ -1056,30 +1069,30 @@ namespace math /// End quaternion. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the spherical linear interpolation of the two quaternions. - public static void Slerp(ref Quaternion start, ref Quaternion end, float amount, out Quaternion result) + public static void Slerp( ref Quaternion start, ref Quaternion end, float amount, out Quaternion result ) { float opposite; float inverse; - float dot = Dot(start, end); + float dot = Dot( start, end ); - if (Math.Abs(dot) > 1.0f - MathUtil.ZeroTolerance) + if( Math.Abs( dot ) > 1.0f - MathUtil.ZeroTolerance ) { inverse = 1.0f - amount; - opposite = amount * Math.Sign(dot); + opposite = amount * Math.Sign( dot ); } else { - float acos = (float)Math.Acos(Math.Abs(dot)); - float invSin = (float)(1.0 / Math.Sin(acos)); + float acos = (float)Math.Acos( Math.Abs( dot ) ); + float invSin = (float)( 1.0 / Math.Sin( acos ) ); - inverse = (float)Math.Sin((1.0f - amount) * acos) * invSin; - opposite = (float)Math.Sin(amount * acos) * invSin * Math.Sign(dot); + inverse = (float)Math.Sin( ( 1.0f - amount ) * acos ) * invSin; + opposite = (float)Math.Sin( amount * acos ) * invSin * Math.Sign( dot ); } - result.X = (inverse * start.X) + (opposite * end.X); - result.Y = (inverse * start.Y) + (opposite * end.Y); - result.Z = (inverse * start.Z) + (opposite * end.Z); - result.W = (inverse * start.W) + (opposite * end.W); + result.X = ( inverse * start.X ) + ( opposite * end.X ); + result.Y = ( inverse * start.Y ) + ( opposite * end.Y ); + result.Z = ( inverse * start.Z ) + ( opposite * end.Z ); + result.W = ( inverse * start.W ) + ( opposite * end.W ); } /// @@ -1089,10 +1102,10 @@ namespace math /// End quaternion. /// Value between 0 and 1 indicating the weight of . /// The spherical linear interpolation of the two quaternions. - public static Quaternion Slerp(Quaternion start, Quaternion end, float amount) + public static Quaternion Slerp( Quaternion start, Quaternion end, float amount ) { Quaternion result; - Slerp(ref start, ref end, amount, out result); + Slerp( ref start, ref end, amount, out result ); return result; } @@ -1105,12 +1118,12 @@ namespace math /// Fourth source quaternion. /// Value between 0 and 1 indicating the weight of interpolation. /// When the method completes, contains the spherical quadrangle interpolation of the quaternions. - public static void Squad(ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, ref Quaternion value4, float amount, out Quaternion result) + public static void Squad( ref Quaternion value1, ref Quaternion value2, ref Quaternion value3, ref Quaternion value4, float amount, out Quaternion result ) { Quaternion start, end; - Slerp(ref value1, ref value4, amount, out start); - Slerp(ref value2, ref value3, amount, out end); - Slerp(ref start, ref end, 2.0f * amount * (1.0f - amount), out result); + Slerp( ref value1, ref value4, amount, out start ); + Slerp( ref value2, ref value3, amount, out end ); + Slerp( ref start, ref end, 2.0f * amount * ( 1.0f - amount ), out result ); } /// @@ -1122,10 +1135,10 @@ namespace math /// Fourth source quaternion. /// Value between 0 and 1 indicating the weight of interpolation. /// The spherical quadrangle interpolation of the quaternions. - public static Quaternion Squad(Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4, float amount) + public static Quaternion Squad( Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4, float amount ) { Quaternion result; - Squad(ref value1, ref value2, ref value3, ref value4, amount, out result); + Squad( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -1137,20 +1150,20 @@ namespace math /// Third source quaternion. /// Fourth source quaternion. /// An array of three quaternions that represent control points for spherical quadrangle interpolation. - public static Quaternion[] SquadSetup(Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4) + public static Quaternion[] SquadSetup( Quaternion value1, Quaternion value2, Quaternion value3, Quaternion value4 ) { - Quaternion q0 = (value1 + value2).LengthSquared() < (value1 - value2).LengthSquared() ? -value1 : value1; - Quaternion q2 = (value2 + value3).LengthSquared() < (value2 - value3).LengthSquared() ? -value3 : value3; - Quaternion q3 = (value3 + value4).LengthSquared() < (value3 - value4).LengthSquared() ? -value4 : value4; + Quaternion q0 = ( value1 + value2 ).LengthSquared() < ( value1 - value2 ).LengthSquared() ? -value1 : value1; + Quaternion q2 = ( value2 + value3 ).LengthSquared() < ( value2 - value3 ).LengthSquared() ? -value3 : value3; + Quaternion q3 = ( value3 + value4 ).LengthSquared() < ( value3 - value4 ).LengthSquared() ? -value4 : value4; Quaternion q1 = value2; Quaternion q1Exp, q2Exp; - Exponential(ref q1, out q1Exp); - Exponential(ref q2, out q2Exp); + Exponential( ref q1, out q1Exp ); + Exponential( ref q2, out q2Exp ); Quaternion[] results = new Quaternion[3]; - results[0] = q1 * Exponential(-0.25f * (Logarithm(q1Exp * q2) + Logarithm(q1Exp * q0))); - results[1] = q2 * Exponential(-0.25f * (Logarithm(q2Exp * q3) + Logarithm(q2Exp * q1))); + results[0] = q1 * Exponential( -0.25f * ( Logarithm( q1Exp * q2 ) + Logarithm( q1Exp * q0 ) ) ); + results[1] = q2 * Exponential( -0.25f * ( Logarithm( q2Exp * q3 ) + Logarithm( q2Exp * q1 ) ) ); results[2] = q2; return results; @@ -1162,10 +1175,10 @@ namespace math /// The first quaternion to add. /// The second quaternion to add. /// The sum of the two quaternions. - public static Quaternion operator +(Quaternion left, Quaternion right) + public static Quaternion operator +( Quaternion left, Quaternion right ) { Quaternion result; - Add(ref left, ref right, out result); + Add( ref left, ref right, out result ); return result; } @@ -1175,10 +1188,10 @@ namespace math /// The first quaternion to subtract. /// The second quaternion to subtract. /// The difference of the two quaternions. - public static Quaternion operator -(Quaternion left, Quaternion right) + public static Quaternion operator -( Quaternion left, Quaternion right ) { Quaternion result; - Subtract(ref left, ref right, out result); + Subtract( ref left, ref right, out result ); return result; } @@ -1187,10 +1200,10 @@ namespace math /// /// The quaternion to negate. /// A quaternion facing in the opposite direction. - public static Quaternion operator -(Quaternion value) + public static Quaternion operator -( Quaternion value ) { Quaternion result; - Negate(ref value, out result); + Negate( ref value, out result ); return result; } @@ -1200,10 +1213,10 @@ namespace math /// The quaternion to scale. /// The amount by which to scale the quaternion. /// The scaled quaternion. - public static Quaternion operator *(float scale, Quaternion value) + public static Quaternion operator *( float scale, Quaternion value ) { Quaternion result; - Multiply(ref value, scale, out result); + Multiply( ref value, scale, out result ); return result; } @@ -1213,10 +1226,10 @@ namespace math /// The quaternion to scale. /// The amount by which to scale the quaternion. /// The scaled quaternion. - public static Quaternion operator *(Quaternion value, float scale) + public static Quaternion operator *( Quaternion value, float scale ) { Quaternion result; - Multiply(ref value, scale, out result); + Multiply( ref value, scale, out result ); return result; } @@ -1226,10 +1239,10 @@ namespace math /// The first quaternion to multiply. /// The second quaternion to multiply. /// The multiplied quaternion. - public static Quaternion operator *(Quaternion left, Quaternion right) + public static Quaternion operator *( Quaternion left, Quaternion right ) { Quaternion result; - Multiply(ref left, ref right, out result); + Multiply( ref left, ref right, out result ); return result; } @@ -1239,9 +1252,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Quaternion left, Quaternion right) + public static bool operator ==( Quaternion left, Quaternion right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1250,9 +1263,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Quaternion left, Quaternion right) + public static bool operator !=( Quaternion left, Quaternion right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1263,7 +1276,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -1273,13 +1286,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(format, CultureInfo.CurrentCulture), W.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), Z.ToString( format, CultureInfo.CurrentCulture ), W.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1289,9 +1302,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -1302,20 +1315,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider), W.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ), W.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1329,12 +1342,12 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Quaternion other) + public bool Equals( Quaternion other ) { - return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Z - Z) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.W - W) < MathUtil.ZeroTolerance); + return ( (float)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Z - Z ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.W - W ) < MathUtil.ZeroTolerance ); } /// @@ -1344,15 +1357,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Quaternion)value); + return Equals( (Quaternion)value ); } #if SlimDX1xInterop diff --git a/math/RandomSeed.cs b/math/RandomSeed.cs index b14b01e..a799ce3 100644 --- a/math/RandomSeed.cs +++ b/math/RandomSeed.cs @@ -31,24 +31,24 @@ namespace math /// Initializes a new instance of the struct from a target uint. /// /// The seed value to initialize the deterministic random generator. - public RandomSeed(uint seed) + public RandomSeed( uint seed ) { - this.seed = (seed & UnderflowGuard); + this.seed = ( seed & UnderflowGuard ); } /// /// Get a deterministic double value between 0 and 1 based on the seed /// /// Deterministic pseudo-random value between 0 and 1 - public double GetDouble(uint offset) - { - var dRand = (double)(unchecked(seed + offset)); // We want it to overflow + public double GetDouble( uint offset ) + { + var dRand = (double)( unchecked(seed + offset) ); // We want it to overflow - var dotProduct = Math.Cos(dRand) * GelfondConst + Math.Sin(dRand) * GelfondSchneiderConst; + var dotProduct = Math.Cos( dRand ) * GelfondConst + Math.Sin( dRand ) * GelfondSchneiderConst; var denominator = 1e-7 + 256 * dotProduct; var remainder = Numerator % denominator; - return (remainder - Math.Floor(remainder)); + return ( remainder - Math.Floor( remainder ) ); } /// @@ -56,6 +56,6 @@ namespace math /// The calculations are still made as doubles to prevent underflow errors. /// /// Deterministic pseudo-random value between 0 and 1 - public float GetFloat(uint offset) => (float)GetDouble(offset); + public float GetFloat( uint offset ) => (float)GetDouble( offset ); } } diff --git a/math/Ray.cs b/math/Ray.cs index 62041e3..047a9ad 100644 --- a/math/Ray.cs +++ b/math/Ray.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -37,7 +37,7 @@ namespace math /// Represents a three dimensional line based on a point in space and a direction. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Ray : IEquatable, IFormattable { /// @@ -55,7 +55,7 @@ namespace math /// /// The position in three dimensional space of the origin of the ray. /// The normalized direction of the ray. - public Ray(Vec3 position, Vec3 direction) + public Ray( Vec3 position, Vec3 direction ) { this.Position = position; this.Direction = direction; @@ -66,9 +66,9 @@ namespace math /// /// The point to test. /// Whether the two objects intersected. - public bool Intersects(ref Vec3 point) + public bool Intersects( ref Vec3 point ) { - return CollisionHelper.RayIntersectsPoint(ref this, ref point); + return CollisionHelper.RayIntersectsPoint( ref this, ref point ); } /// @@ -76,10 +76,10 @@ namespace math /// /// The ray to test. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray) + public bool Intersects( ref Ray ray ) { Vec3 point; - return CollisionHelper.RayIntersectsRay(ref this, ref ray, out point); + return CollisionHelper.RayIntersectsRay( ref this, ref ray, out point ); } /// @@ -89,9 +89,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Ray ray, out Vec3 point) + public bool Intersects( ref Ray ray, out Vec3 point ) { - return CollisionHelper.RayIntersectsRay(ref this, ref ray, out point); + return CollisionHelper.RayIntersectsRay( ref this, ref ray, out point ); } /// @@ -99,10 +99,10 @@ namespace math /// /// The plane to test /// Whether the two objects intersected. - public bool Intersects(ref Plane plane) + public bool Intersects( ref Plane plane ) { float distance; - return CollisionHelper.RayIntersectsPlane(ref this, ref plane, out distance); + return CollisionHelper.RayIntersectsPlane( ref this, ref plane, out distance ); } /// @@ -112,9 +112,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane, out float distance) + public bool Intersects( ref Plane plane, out float distance ) { - return CollisionHelper.RayIntersectsPlane(ref this, ref plane, out distance); + return CollisionHelper.RayIntersectsPlane( ref this, ref plane, out distance ); } /// @@ -124,9 +124,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Plane plane, out Vec3 point) + public bool Intersects( ref Plane plane, out Vec3 point ) { - return CollisionHelper.RayIntersectsPlane(ref this, ref plane, out point); + return CollisionHelper.RayIntersectsPlane( ref this, ref plane, out point ); } /// @@ -136,10 +136,10 @@ namespace math /// The second vertex of the triangle to test. /// The third vertex of the triangle to test. /// Whether the two objects intersected. - public bool Intersects(ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3) + public bool Intersects( ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3 ) { float distance; - return CollisionHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out distance); + return CollisionHelper.RayIntersectsTriangle( ref this, ref vertex1, ref vertex2, ref vertex3, out distance ); } /// @@ -151,9 +151,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out float distance) + public bool Intersects( ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out float distance ) { - return CollisionHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out distance); + return CollisionHelper.RayIntersectsTriangle( ref this, ref vertex1, ref vertex2, ref vertex3, out distance ); } /// @@ -165,9 +165,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out Vec3 point) + public bool Intersects( ref Vec3 vertex1, ref Vec3 vertex2, ref Vec3 vertex3, out Vec3 point ) { - return CollisionHelper.RayIntersectsTriangle(ref this, ref vertex1, ref vertex2, ref vertex3, out point); + return CollisionHelper.RayIntersectsTriangle( ref this, ref vertex1, ref vertex2, ref vertex3, out point ); } /// @@ -175,10 +175,10 @@ namespace math /// /// The box to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box) + public bool Intersects( ref BoundingBox box ) { float distance; - return CollisionHelper.RayIntersectsBox(ref this, ref box, out distance); + return CollisionHelper.RayIntersectsBox( ref this, ref box, out distance ); } /// @@ -188,9 +188,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box, out float distance) + public bool Intersects( ref BoundingBox box, out float distance ) { - return CollisionHelper.RayIntersectsBox(ref this, ref box, out distance); + return CollisionHelper.RayIntersectsBox( ref this, ref box, out distance ); } /// @@ -200,9 +200,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingBox box, out Vec3 point) + public bool Intersects( ref BoundingBox box, out Vec3 point ) { - return CollisionHelper.RayIntersectsBox(ref this, ref box, out point); + return CollisionHelper.RayIntersectsBox( ref this, ref box, out point ); } /// @@ -210,10 +210,10 @@ namespace math /// /// The sphere to test. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere) + public bool Intersects( ref BoundingSphere sphere ) { float distance; - return CollisionHelper.RayIntersectsSphere(ref this, ref sphere, out distance); + return CollisionHelper.RayIntersectsSphere( ref this, ref sphere, out distance ); } /// @@ -223,9 +223,9 @@ namespace math /// When the method completes, contains the distance of the intersection, /// or 0 if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere, out float distance) + public bool Intersects( ref BoundingSphere sphere, out float distance ) { - return CollisionHelper.RayIntersectsSphere(ref this, ref sphere, out distance); + return CollisionHelper.RayIntersectsSphere( ref this, ref sphere, out distance ); } /// @@ -235,9 +235,9 @@ namespace math /// When the method completes, contains the point of intersection, /// or if there was no intersection. /// Whether the two objects intersected. - public bool Intersects(ref BoundingSphere sphere, out Vec3 point) + public bool Intersects( ref BoundingSphere sphere, out Vec3 point ) { - return CollisionHelper.RayIntersectsSphere(ref this, ref sphere, out point); + return CollisionHelper.RayIntersectsSphere( ref this, ref sphere, out point ); } /// @@ -246,9 +246,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Ray left, Ray right) + public static bool operator ==( Ray left, Ray right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -257,9 +257,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Ray left, Ray right) + public static bool operator !=( Ray left, Ray right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -270,7 +270,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "Position:{0} Direction:{1}", Position.ToString(), Direction.ToString()); + return string.Format( CultureInfo.CurrentCulture, "Position:{0} Direction:{1}", Position.ToString(), Direction.ToString() ); } /// @@ -280,10 +280,10 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - return string.Format(CultureInfo.CurrentCulture, "Position:{0} Direction:{1}", Position.ToString(format, CultureInfo.CurrentCulture), - Direction.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "Position:{0} Direction:{1}", Position.ToString( format, CultureInfo.CurrentCulture ), + Direction.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -293,9 +293,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "Position:{0} Direction:{1}", Position.ToString(), Direction.ToString()); + return string.Format( formatProvider, "Position:{0} Direction:{1}", Position.ToString(), Direction.ToString() ); } /// @@ -306,17 +306,17 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - return string.Format(formatProvider, "Position:{0} Direction:{1}", Position.ToString(format, formatProvider), - Direction.ToString(format, formatProvider)); + return string.Format( formatProvider, "Position:{0} Direction:{1}", Position.ToString( format, formatProvider ), + Direction.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -330,7 +330,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Ray value) + public bool Equals( Ray value ) { return Position == value.Position && Direction == value.Direction; } @@ -342,15 +342,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Ray)value); + return Equals( (Ray)value ); } #if SlimDX1xInterop diff --git a/math/Rectangle.cs b/math/Rectangle.cs index 3010acd..2252b13 100644 --- a/math/Rectangle.cs +++ b/math/Rectangle.cs @@ -31,9 +31,9 @@ namespace math /// /// A rectangle structure defining X,Y,Width,Height. /// - [DataContract( Name = "Rectangle")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Rectangle" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Rectangle : IEquatable { /// @@ -53,7 +53,7 @@ namespace math /// The top. /// The width. /// The height. - public Rectangle(int x, int y, int width, int height) + public Rectangle( int x, int y, int width, int height ) { this.X = x; this.Y = y; @@ -142,7 +142,7 @@ namespace math { get { - return new Point(X, Y); + return new Point( X, Y ); } set { @@ -162,7 +162,7 @@ namespace math { get { - return new Point(X + (Width / 2), Y + (Height / 2)); + return new Point( X + ( Width / 2 ), Y + ( Height / 2 ) ); } } @@ -176,7 +176,7 @@ namespace math { get { - return (Width == 0) && (Height == 0) && (X == 0) && (Y == 0); + return ( Width == 0 ) && ( Height == 0 ) && ( X == 0 ) && ( Y == 0 ); } } @@ -189,7 +189,7 @@ namespace math { get { - return new Size2(Width, Height); + return new Size2( Width, Height ); } set { @@ -202,37 +202,37 @@ namespace math /// Gets the position of the top-left corner of the rectangle. /// /// The top-left corner of the rectangle. - public Point TopLeft { get { return new Point(Left, Top); } } + public Point TopLeft { get { return new Point( Left, Top ); } } /// /// Gets the position of the top-right corner of the rectangle. /// /// The top-right corner of the rectangle. - public Point TopRight { get { return new Point(Right, Top); } } + public Point TopRight { get { return new Point( Right, Top ); } } /// /// Gets the position of the bottom-left corner of the rectangle. /// /// The bottom-left corner of the rectangle. - public Point BottomLeft { get { return new Point(Left, Bottom); } } + public Point BottomLeft { get { return new Point( Left, Bottom ); } } /// /// Gets the position of the bottom-right corner of the rectangle. /// /// The bottom-right corner of the rectangle. - public Point BottomRight { get { return new Point(Right, Bottom); } } + public Point BottomRight { get { return new Point( Right, Bottom ); } } /// Changes the position of the rectangle. /// The values to adjust the position of the rectangle by. - public void Offset(Point amount) + public void Offset( Point amount ) { - Offset(amount.X, amount.Y); + Offset( amount.X, amount.Y ); } /// Changes the position of the rectangle. /// Change in the x-position. /// Change in the y-position. - public void Offset(int offsetX, int offsetY) + public void Offset( int offsetX, int offsetY ) { X += offsetX; Y += offsetY; @@ -241,7 +241,7 @@ namespace math /// Pushes the edges of the rectangle out by the horizontal and vertical values specified. /// Value to push the sides out by. /// Value to push the top and bottom out by. - public void Inflate(int horizontalAmount, int verticalAmount) + public void Inflate( int horizontalAmount, int verticalAmount ) { X -= horizontalAmount; Y -= verticalAmount; @@ -252,43 +252,43 @@ namespace math /// Determines whether this rectangle contains a specified point represented by its x- and y-coordinates. /// The x-coordinate of the specified point. /// The y-coordinate of the specified point. - public bool Contains(int x, int y) + public bool Contains( int x, int y ) { - return (X <= x) && (x < Right) && (Y <= y) && (y < Bottom); + return ( X <= x ) && ( x < Right ) && ( Y <= y ) && ( y < Bottom ); } /// Determines whether this rectangle contains a specified Point. /// The Point to evaluate. - public bool Contains(Point value) + public bool Contains( Point value ) { bool result; - Contains(ref value, out result); + Contains( ref value, out result ); return result; } /// Determines whether this rectangle contains a specified Point. /// The Point to evaluate. /// [OutAttribute] true if the specified Point is contained within this rectangle; false otherwise. - public void Contains(ref Point value, out bool result) + public void Contains( ref Point value, out bool result ) { - result = (X <= value.X) && (value.X < Right) && (Y <= value.Y) && (value.Y < Bottom); + result = ( X <= value.X ) && ( value.X < Right ) && ( Y <= value.Y ) && ( value.Y < Bottom ); } /// Determines whether this rectangle entirely contains a specified rectangle. /// The rectangle to evaluate. - public bool Contains(Rectangle value) + public bool Contains( Rectangle value ) { bool result; - Contains(ref value, out result); + Contains( ref value, out result ); return result; } /// Determines whether this rectangle entirely contains a specified rectangle. /// The rectangle to evaluate. /// [OutAttribute] On exit, is true if this rectangle entirely contains the specified rectangle, or false if not. - public void Contains(ref Rectangle value, out bool result) + public void Contains( ref Rectangle value, out bool result ) { - result = (X <= value.X) && (value.Right <= Right) && (Y <= value.Y) && (value.Bottom <= Bottom); + result = ( X <= value.X ) && ( value.Right <= Right ) && ( Y <= value.Y ) && ( value.Bottom <= Bottom ); } /// @@ -297,9 +297,9 @@ namespace math /// X point coordinate. /// Y point coordinate. /// true if point is inside , otherwise false. - public bool Contains(float x, float y) + public bool Contains( float x, float y ) { - return (x >= this.X && x <= Right && y >= this.Y && y <= Bottom); + return ( x >= this.X && x <= Right && y >= this.Y && y <= Bottom ); } /// @@ -307,9 +307,9 @@ namespace math /// /// Coordinate . /// true if is inside , otherwise false. - public bool Contains(Vec2 vector2D) + public bool Contains( Vec2 vector2D ) { - return Contains(vector2D.X, vector2D.Y); + return Contains( vector2D.X, vector2D.Y ); } /// @@ -317,17 +317,17 @@ namespace math /// /// Coordinate . /// true if is inside , otherwise false. - public bool Contains(Int2 int2) + public bool Contains( Int2 int2 ) { - return Contains(int2.X, int2.Y); + return Contains( int2.X, int2.Y ); } /// Determines whether a specified rectangle intersects with this rectangle. /// The rectangle to evaluate. - public bool Intersects(Rectangle value) + public bool Intersects( Rectangle value ) { bool result; - Intersects(ref value, out result); + Intersects( ref value, out result ); return result; } @@ -336,9 +336,9 @@ namespace math /// /// The rectangle to evaluate /// [OutAttribute] true if the specified rectangle intersects with this one; false otherwise. - public void Intersects(ref Rectangle value, out bool result) + public void Intersects( ref Rectangle value, out bool result ) { - result = (value.X < Right) && (X < value.Right) && (value.Y < Bottom) && (Y < value.Bottom); + result = ( value.X < Right ) && ( X < value.Right ) && ( value.Y < Bottom ) && ( Y < value.Bottom ); } /// @@ -347,10 +347,10 @@ namespace math /// The first rectangle to compare. /// The second rectangle to compare. /// The intersection rectangle. - public static Rectangle Intersect(Rectangle value1, Rectangle value2) + public static Rectangle Intersect( Rectangle value1, Rectangle value2 ) { Rectangle result; - Intersect(ref value1, ref value2, out result); + Intersect( ref value1, ref value2, out result ); return result; } @@ -358,33 +358,33 @@ namespace math /// The first rectangle to compare. /// The second rectangle to compare. /// [OutAttribute] The area where the two first parameters overlap. - public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result) + public static void Intersect( ref Rectangle value1, ref Rectangle value2, out Rectangle result ) { - int newLeft = (value1.X > value2.X) ? value1.X : value2.X; - int newTop = (value1.Y > value2.Y) ? value1.Y : value2.Y; - int newRight = (value1.Right < value2.Right) ? value1.Right : value2.Right; - int newBottom = (value1.Bottom < value2.Bottom) ? value1.Bottom : value2.Bottom; - if ((newRight > newLeft) && (newBottom > newTop)) + int newLeft = ( value1.X > value2.X ) ? value1.X : value2.X; + int newTop = ( value1.Y > value2.Y ) ? value1.Y : value2.Y; + int newRight = ( value1.Right < value2.Right ) ? value1.Right : value2.Right; + int newBottom = ( value1.Bottom < value2.Bottom ) ? value1.Bottom : value2.Bottom; + if( ( newRight > newLeft ) && ( newBottom > newTop ) ) { - result = new Rectangle(newLeft, newTop, newRight - newLeft, newBottom - newTop); + result = new Rectangle( newLeft, newTop, newRight - newLeft, newBottom - newTop ); } else { result = Empty; } } - + /// /// Creates a new rectangle that incorporate the provided point to the given rectangle. /// /// The original rectangle. /// The point to incorporate. /// The union rectangle. - public static Rectangle Union(Rectangle rectangle, Int2 point) + public static Rectangle Union( Rectangle rectangle, Int2 point ) { Rectangle result; - var rect = new Rectangle(point.X, point.Y, 1, 1); - Union(ref rectangle, ref rect, out result); + var rect = new Rectangle( point.X, point.Y, 1, 1 ); + Union( ref rectangle, ref rect, out result ); return result; } @@ -394,10 +394,10 @@ namespace math /// The first rectangle to contain. /// The second rectangle to contain. /// The union rectangle. - public static Rectangle Union(Rectangle value1, Rectangle value2) + public static Rectangle Union( Rectangle value1, Rectangle value2 ) { Rectangle result; - Union(ref value1, ref value2, out result); + Union( ref value1, ref value2, out result ); return result; } @@ -407,13 +407,13 @@ namespace math /// The first rectangle to contain. /// The second rectangle to contain. /// [OutAttribute] The rectangle that must be the union of the first two rectangles. - public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result) + public static void Union( ref Rectangle value1, ref Rectangle value2, out Rectangle result ) { - var left = Math.Min(value1.Left, value2.Left); - var right = Math.Max(value1.Right, value2.Right); - var top = Math.Min(value1.Top, value2.Top); - var bottom = Math.Max(value1.Bottom, value2.Bottom); - result = new Rectangle(left, top, right - left, bottom - top); + var left = Math.Min( value1.Left, value2.Left ); + var right = Math.Max( value1.Right, value2.Right ); + var top = Math.Min( value1.Top, value2.Top ); + var bottom = Math.Max( value1.Bottom, value2.Bottom ); + result = new Rectangle( left, top, right - left, bottom - top ); } /// @@ -423,11 +423,13 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != typeof(Rectangle)) return false; - return Equals((Rectangle)obj); + if( ReferenceEquals( null, obj ) ) + return false; + if( obj.GetType() != typeof( Rectangle ) ) + return false; + return Equals( (Rectangle)obj ); } /// @@ -437,7 +439,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Rectangle other) + public bool Equals( Rectangle other ) { return other.X == this.X && other.Y == this.Y && other.Width == Width && other.Height == Height; } @@ -453,9 +455,9 @@ namespace math unchecked { int result = X; - result = (result * 397) ^ Y; - result = (result * 397) ^ Width; - result = (result * 397) ^ Height; + result = ( result * 397 ) ^ Y; + result = ( result * 397 ) ^ Width; + result = ( result * 397 ) ^ Height; return result; } } @@ -466,9 +468,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator ==(Rectangle left, Rectangle right) + public static bool operator ==( Rectangle left, Rectangle right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -477,9 +479,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator !=(Rectangle left, Rectangle right) + public static bool operator !=( Rectangle left, Rectangle right ) { - return !(left == right); + return !( left == right ); } /// @@ -488,15 +490,15 @@ namespace math /// Performs direct converstion from int to float. /// The source value. /// The converted structure. - public static implicit operator RectangleF(Rectangle value) + public static implicit operator RectangleF( Rectangle value ) { - return new RectangleF(value.X, value.Y, value.Width, value.Height); + return new RectangleF( value.X, value.Y, value.Width, value.Height ); } /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Width:{2} Height:{3}", X, Y, Width, Height); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Width:{2} Height:{3}", X, Y, Width, Height ); } } } diff --git a/math/RectangleF.cs b/math/RectangleF.cs index 3714884..8aee112 100644 --- a/math/RectangleF.cs +++ b/math/RectangleF.cs @@ -31,9 +31,9 @@ namespace math /// /// Define a RectangleF. /// - [DataContract( Name = "RectangleF")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "RectangleF" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct RectangleF : IEquatable { /// @@ -53,7 +53,7 @@ namespace math /// The top. /// The width. /// The height. - public RectangleF(float x, float y, float width, float height) + public RectangleF( float x, float y, float width, float height ) { this.X = x; this.Y = y; @@ -151,7 +151,7 @@ namespace math { get { - return new Vec2(X, Y); + return new Vec2( X, Y ); } set { @@ -171,7 +171,7 @@ namespace math { get { - return new Vec2(X + (Width / 2), Y + (Height / 2)); + return new Vec2( X + ( Width / 2 ), Y + ( Height / 2 ) ); } } @@ -185,7 +185,7 @@ namespace math { get { - return (Width == 0.0f) && (Height == 0.0f) && (X == 0.0f) && (Y == 0.0f); + return ( Width == 0.0f ) && ( Height == 0.0f ) && ( X == 0.0f ) && ( Y == 0.0f ); } } @@ -198,7 +198,7 @@ namespace math { get { - return new Size2F(Width, Height); + return new Size2F( Width, Height ); } set { @@ -211,44 +211,44 @@ namespace math /// Gets the position of the top-left corner of the rectangle. /// /// The top-left corner of the rectangle. - public Vec2 TopLeft { get { return new Vec2(X, Y); } } + public Vec2 TopLeft { get { return new Vec2( X, Y ); } } /// /// Gets the position of the top-right corner of the rectangle. /// /// The top-right corner of the rectangle. - public Vec2 TopRight { get { return new Vec2(Right, Y); } } + public Vec2 TopRight { get { return new Vec2( Right, Y ); } } /// /// Gets the position of the bottom-left corner of the rectangle. /// /// The bottom-left corner of the rectangle. - public Vec2 BottomLeft { get { return new Vec2(X, Bottom); } } + public Vec2 BottomLeft { get { return new Vec2( X, Bottom ); } } /// /// Gets the position of the bottom-right corner of the rectangle. /// /// The bottom-right corner of the rectangle. - public Vec2 BottomRight { get { return new Vec2(Right, Bottom); } } + public Vec2 BottomRight { get { return new Vec2( Right, Bottom ); } } /// Changes the position of the rectangle. /// The values to adjust the position of the rectangle by. - public void Offset(Point amount) + public void Offset( Point amount ) { - Offset(amount.X, amount.Y); + Offset( amount.X, amount.Y ); } /// Changes the position of the rectangle. /// The values to adjust the position of the rectangle by. - public void Offset(Vec2 amount) + public void Offset( Vec2 amount ) { - Offset(amount.X, amount.Y); + Offset( amount.X, amount.Y ); } /// Changes the position of the rectangle. /// Change in the x-position. /// Change in the y-position. - public void Offset(float offsetX, float offsetY) + public void Offset( float offsetX, float offsetY ) { X += offsetX; Y += offsetY; @@ -257,7 +257,7 @@ namespace math /// Pushes the edges of the rectangle out by the horizontal and vertical values specified. /// Value to push the sides out by. /// Value to push the top and bottom out by. - public void Inflate(float horizontalAmount, float verticalAmount) + public void Inflate( float horizontalAmount, float verticalAmount ) { X -= horizontalAmount; Y -= verticalAmount; @@ -268,24 +268,24 @@ namespace math /// Determines whether this rectangle contains a specified Point. /// The Point to evaluate. /// [OutAttribute] true if the specified Point is contained within this rectangle; false otherwise. - public void Contains(ref Vec2 value, out bool result) + public void Contains( ref Vec2 value, out bool result ) { - result = (X <= value.X) && (value.X < Right) && (Y <= value.Y) && (value.Y < Bottom); + result = ( X <= value.X ) && ( value.X < Right ) && ( Y <= value.Y ) && ( value.Y < Bottom ); } /// Determines whether this rectangle entirely contains a specified rectangle. /// The rectangle to evaluate. - public bool Contains(Rectangle value) + public bool Contains( Rectangle value ) { - return (X <= value.X) && (value.Right <= Right) && (Y <= value.Y) && (value.Bottom <= Bottom); + return ( X <= value.X ) && ( value.Right <= Right ) && ( Y <= value.Y ) && ( value.Bottom <= Bottom ); } /// Determines whether this rectangle entirely contains a specified rectangle. /// The rectangle to evaluate. /// [OutAttribute] On exit, is true if this rectangle entirely contains the specified rectangle, or false if not. - public void Contains(ref RectangleF value, out bool result) + public void Contains( ref RectangleF value, out bool result ) { - result = (X <= value.X) && (value.Right <= Right) && (Y <= value.Y) && (value.Bottom <= Bottom); + result = ( X <= value.X ) && ( value.Right <= Right ) && ( Y <= value.Y ) && ( value.Bottom <= Bottom ); } /// @@ -294,9 +294,9 @@ namespace math /// X point coordinate. /// Y point coordinate. /// true if point is inside , otherwise false. - public bool Contains(float x, float y) + public bool Contains( float x, float y ) { - return (x >= this.X && x <= Right && y >= this.Y && y <= Bottom); + return ( x >= this.X && x <= Right && y >= this.Y && y <= Bottom ); } /// @@ -304,9 +304,9 @@ namespace math /// /// Coordinate . /// true if is inside , otherwise false. - public bool Contains(Vec2 vector2D) + public bool Contains( Vec2 vector2D ) { - return Contains(vector2D.X, vector2D.Y); + return Contains( vector2D.X, vector2D.Y ); } /// @@ -314,9 +314,9 @@ namespace math /// /// Coordinate . /// true if is inside , otherwise false. - public bool Contains(Int2 int2) + public bool Contains( Int2 int2 ) { - return Contains(int2.X, int2.Y); + return Contains( int2.X, int2.Y ); } /// @@ -324,17 +324,17 @@ namespace math /// /// Coordinate . /// true if is inside , otherwise false. - public bool Contains(Point point) + public bool Contains( Point point ) { - return Contains(point.X, point.Y); + return Contains( point.X, point.Y ); } /// Determines whether a specified rectangle intersects with this rectangle. /// The rectangle to evaluate. - public bool Intersects(RectangleF value) + public bool Intersects( RectangleF value ) { bool result; - Intersects(ref value, out result); + Intersects( ref value, out result ); return result; } @@ -343,9 +343,9 @@ namespace math /// /// The rectangle to evaluate /// [OutAttribute] true if the specified rectangle intersects with this one; false otherwise. - public void Intersects(ref RectangleF value, out bool result) + public void Intersects( ref RectangleF value, out bool result ) { - result = (value.X < Right) && (X < value.Right) && (value.Y < Bottom) && (Y < value.Bottom); + result = ( value.X < Right ) && ( X < value.Right ) && ( value.Y < Bottom ) && ( Y < value.Bottom ); } /// @@ -354,10 +354,10 @@ namespace math /// The first Rectangle to compare. /// The second Rectangle to compare. /// The intersection rectangle. - public static RectangleF Intersect(RectangleF value1, RectangleF value2) + public static RectangleF Intersect( RectangleF value1, RectangleF value2 ) { RectangleF result; - Intersect(ref value1, ref value2, out result); + Intersect( ref value1, ref value2, out result ); return result; } @@ -365,15 +365,15 @@ namespace math /// The first rectangle to compare. /// The second rectangle to compare. /// [OutAttribute] The area where the two first parameters overlap. - public static void Intersect(ref RectangleF value1, ref RectangleF value2, out RectangleF result) + public static void Intersect( ref RectangleF value1, ref RectangleF value2, out RectangleF result ) { - float newLeft = (value1.X > value2.X) ? value1.X : value2.X; - float newTop = (value1.Y > value2.Y) ? value1.Y : value2.Y; - float newRight = (value1.Right < value2.Right) ? value1.Right : value2.Right; - float newBottom = (value1.Bottom < value2.Bottom) ? value1.Bottom : value2.Bottom; - if ((newRight > newLeft) && (newBottom > newTop)) + float newLeft = ( value1.X > value2.X ) ? value1.X : value2.X; + float newTop = ( value1.Y > value2.Y ) ? value1.Y : value2.Y; + float newRight = ( value1.Right < value2.Right ) ? value1.Right : value2.Right; + float newBottom = ( value1.Bottom < value2.Bottom ) ? value1.Bottom : value2.Bottom; + if( ( newRight > newLeft ) && ( newBottom > newTop ) ) { - result = new RectangleF(newLeft, newTop, newRight - newLeft, newBottom - newTop); + result = new RectangleF( newLeft, newTop, newRight - newLeft, newBottom - newTop ); } else { @@ -387,10 +387,10 @@ namespace math /// The first rectangle to contain. /// The second rectangle to contain. /// The union rectangle. - public static RectangleF Union(RectangleF value1, RectangleF value2) + public static RectangleF Union( RectangleF value1, RectangleF value2 ) { RectangleF result; - Union(ref value1, ref value2, out result); + Union( ref value1, ref value2, out result ); return result; } @@ -400,13 +400,13 @@ namespace math /// The first rectangle to contain. /// The second rectangle to contain. /// [OutAttribute] The rectangle that must be the union of the first two rectangles. - public static void Union(ref RectangleF value1, ref RectangleF value2, out RectangleF result) + public static void Union( ref RectangleF value1, ref RectangleF value2, out RectangleF result ) { - var left = Math.Min(value1.Left, value2.Left); - var right = Math.Max(value1.Right, value2.Right); - var top = Math.Min(value1.Top, value2.Top); - var bottom = Math.Max(value1.Bottom, value2.Bottom); - result = new RectangleF(left, top, right - left, bottom - top); + var left = Math.Min( value1.Left, value2.Left ); + var right = Math.Max( value1.Right, value2.Right ); + var top = Math.Min( value1.Top, value2.Top ); + var bottom = Math.Max( value1.Bottom, value2.Bottom ); + result = new RectangleF( left, top, right - left, bottom - top ); } /// @@ -416,20 +416,22 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != typeof(RectangleF)) return false; - return Equals((RectangleF)obj); + if( ReferenceEquals( null, obj ) ) + return false; + if( obj.GetType() != typeof( RectangleF ) ) + return false; + return Equals( (RectangleF)obj ); } /// - public bool Equals(RectangleF other) + public bool Equals( RectangleF other ) { - return MathUtil.NearEqual(other.Left, Left) && - MathUtil.NearEqual(other.Right, Right) && - MathUtil.NearEqual(other.Top, Top) && - MathUtil.NearEqual(other.Bottom, Bottom); + return MathUtil.NearEqual( other.Left, Left ) && + MathUtil.NearEqual( other.Right, Right ) && + MathUtil.NearEqual( other.Top, Top ) && + MathUtil.NearEqual( other.Bottom, Bottom ); } /// @@ -443,9 +445,9 @@ namespace math unchecked { int result = X.GetHashCode(); - result = (result * 397) ^ Y.GetHashCode(); - result = (result * 397) ^ Width.GetHashCode(); - result = (result * 397) ^ Height.GetHashCode(); + result = ( result * 397 ) ^ Y.GetHashCode(); + result = ( result * 397 ) ^ Width.GetHashCode(); + result = ( result * 397 ) ^ Height.GetHashCode(); return result; } } @@ -456,9 +458,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator ==(RectangleF left, RectangleF right) + public static bool operator ==( RectangleF left, RectangleF right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -467,9 +469,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator !=(RectangleF left, RectangleF right) + public static bool operator !=( RectangleF left, RectangleF right ) { - return !(left == right); + return !( left == right ); } /// @@ -478,15 +480,15 @@ namespace math /// Performs direct float to int conversion, any fractional data is truncated. /// The source value. /// A converted structure. - public static explicit operator Rectangle(RectangleF value) + public static explicit operator Rectangle( RectangleF value ) { - return new Rectangle((int)value.X, (int)value.Y, (int)value.Width, (int)value.Height); + return new Rectangle( (int)value.X, (int)value.Y, (int)value.Width, (int)value.Height ); } /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Width:{2} Height:{3}", X, Y, Width, Height); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Width:{2} Height:{3}", X, Y, Width, Height ); } } } diff --git a/math/Size2.cs b/math/Size2.cs index 8fe8c6a..87d2579 100644 --- a/math/Size2.cs +++ b/math/Size2.cs @@ -30,15 +30,15 @@ namespace math /// /// Defines a 2D rectangular size (width,height). /// - [DataContract( Name = "!Size2")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "!Size2" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Size2 : IEquatable { /// /// A zero size with (width, height) = (0,0) /// - public static readonly Size2 Zero = new Size2(0, 0); + public static readonly Size2 Zero = new Size2( 0, 0 ); /// /// A zero size with (width, height) = (0,0) @@ -50,7 +50,7 @@ namespace math /// /// The x. /// The y. - public Size2(int width, int height) + public Size2( int width, int height ) { Width = width; Height = height; @@ -75,17 +75,19 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Size2 other) + public bool Equals( Size2 other ) { return other.Width == Width && other.Height == Height; } /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != typeof(Size2)) return false; - return Equals((Size2)obj); + if( ReferenceEquals( null, obj ) ) + return false; + if( obj.GetType() != typeof( Size2 ) ) + return false; + return Equals( (Size2)obj ); } /// @@ -93,7 +95,7 @@ namespace math { unchecked { - return (Width * 397) ^ Height; + return ( Width * 397 ) ^ Height; } } @@ -105,9 +107,9 @@ namespace math /// /// The result of the operator. /// - public static bool operator ==(Size2 left, Size2 right) + public static bool operator ==( Size2 left, Size2 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -118,15 +120,15 @@ namespace math /// /// The result of the operator. /// - public static bool operator !=(Size2 left, Size2 right) + public static bool operator !=( Size2 left, Size2 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// public override string ToString() { - return string.Format("({0},{1})", Width, Height); + return string.Format( "({0},{1})", Width, Height ); } } } diff --git a/math/Size2F.cs b/math/Size2F.cs index 3045958..d551c49 100644 --- a/math/Size2F.cs +++ b/math/Size2F.cs @@ -30,15 +30,15 @@ namespace math /// /// Defines a 2D rectangular size (width,height). /// - [DataContract( Name = "Size2F")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "Size2F" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Size2F : IEquatable { /// /// A zero size with (width, height) = (0,0) /// - public static readonly Size2F Zero = new Size2F(0, 0); + public static readonly Size2F Zero = new Size2F( 0, 0 ); /// /// A zero size with (width, height) = (0,0) @@ -50,7 +50,7 @@ namespace math /// /// The x. /// The y. - public Size2F(float width, float height) + public Size2F( float width, float height ) { Width = width; Height = height; @@ -75,17 +75,19 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Size2F other) + public bool Equals( Size2F other ) { return other.Width == Width && other.Height == Height; } /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - if (obj.GetType() != typeof(Size2F)) return false; - return Equals((Size2F)obj); + if( ReferenceEquals( null, obj ) ) + return false; + if( obj.GetType() != typeof( Size2F ) ) + return false; + return Equals( (Size2F)obj ); } /// @@ -93,7 +95,7 @@ namespace math { unchecked { - return (Width.GetHashCode() * 397) ^ Height.GetHashCode(); + return ( Width.GetHashCode() * 397 ) ^ Height.GetHashCode(); } } @@ -105,9 +107,9 @@ namespace math /// /// The result of the operator. /// - public static bool operator ==(Size2F left, Size2F right) + public static bool operator ==( Size2F left, Size2F right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -118,15 +120,15 @@ namespace math /// /// The result of the operator. /// - public static bool operator !=(Size2F left, Size2F right) + public static bool operator !=( Size2F left, Size2F right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// public override string ToString() { - return string.Format("({0},{1})", Width, Height); + return string.Format( "({0},{1})", Width, Height ); } } } diff --git a/math/Size3.cs b/math/Size3.cs index 8eb40b3..23f2439 100644 --- a/math/Size3.cs +++ b/math/Size3.cs @@ -30,20 +30,20 @@ namespace math /// /// Structure providing Width, Height and Depth. /// - [DataContract( Name = "!Size3")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential)] + [DataContract( Name = "!Size3" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential )] public struct Size3 : IEquatable, IComparable { /// /// A zero size with (width, height, depth) = (0,0,0) /// - public static readonly Size3 Zero = new Size3(0, 0, 0); + public static readonly Size3 Zero = new Size3( 0, 0, 0 ); /// /// A one size with (width, height, depth) = (1,1,1) /// - public static readonly Size3 One = new Size3(1, 1, 1); + public static readonly Size3 One = new Size3( 1, 1, 1 ); /// /// A zero size with (width, height, depth) = (0,0,0) @@ -56,7 +56,7 @@ namespace math /// The x. /// The y. /// The depth. - public Size3(int width, int height, int depth) + public Size3( int width, int height, int depth ) { Width = width; Height = height; @@ -93,16 +93,17 @@ namespace math } /// - public bool Equals(Size3 other) + public bool Equals( Size3 other ) { return Width == other.Width && Height == other.Height && Depth == other.Depth; } /// - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (ReferenceEquals(null, obj)) return false; - return obj is Size3 && Equals((Size3)obj); + if( ReferenceEquals( null, obj ) ) + return false; + return obj is Size3 && Equals( (Size3)obj ); } /// @@ -111,22 +112,22 @@ namespace math unchecked { int hashCode = Width; - hashCode = (hashCode * 397) ^ Height; - hashCode = (hashCode * 397) ^ Depth; + hashCode = ( hashCode * 397 ) ^ Height; + hashCode = ( hashCode * 397 ) ^ Depth; return hashCode; } } /// - public int CompareTo(Size3 other) + public int CompareTo( Size3 other ) { - return Math.Sign(this.VolumeSize - other.VolumeSize); + return Math.Sign( this.VolumeSize - other.VolumeSize ); } /// public override string ToString() { - return string.Format("({0},{1},{2})", Width, Height, Depth); + return string.Format( "({0},{1},{2})", Width, Height, Depth ); } /// @@ -135,9 +136,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator <(Size3 left, Size3 right) + public static bool operator <( Size3 left, Size3 right ) { - return left.CompareTo(right) < 0; + return left.CompareTo( right ) < 0; } /// @@ -146,9 +147,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator <=(Size3 left, Size3 right) + public static bool operator <=( Size3 left, Size3 right ) { - return left.CompareTo(right) <= 0; + return left.CompareTo( right ) <= 0; } /// @@ -157,9 +158,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator >(Size3 left, Size3 right) + public static bool operator >( Size3 left, Size3 right ) { - return left.CompareTo(right) > 0; + return left.CompareTo( right ) > 0; } /// @@ -168,9 +169,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator >=(Size3 left, Size3 right) + public static bool operator >=( Size3 left, Size3 right ) { - return left.CompareTo(right) >= 0; + return left.CompareTo( right ) >= 0; } /// @@ -179,9 +180,9 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator ==(Size3 left, Size3 right) + public static bool operator ==( Size3 left, Size3 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -190,23 +191,23 @@ namespace math /// The left. /// The right. /// The result of the operator. - public static bool operator !=(Size3 left, Size3 right) + public static bool operator !=( Size3 left, Size3 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// /// Calculates the next up mip-level (*2) of this size. /// /// A next up mip-level Size3. - public Size3 Up2(int count = 1) + public Size3 Up2( int count = 1 ) { - if (count < 0) + if( count < 0 ) { - throw new ArgumentOutOfRangeException("count", "Must be >= 0"); + throw new ArgumentOutOfRangeException( "count", "Must be >= 0" ); } - return new Size3(Math.Max(1, Width << count), Math.Max(1, Height << count), Math.Max(1, Depth << count)); + return new Size3( Math.Max( 1, Width << count ), Math.Max( 1, Height << count ), Math.Max( 1, Depth << count ) ); } /// @@ -214,14 +215,14 @@ namespace math /// /// The count. /// A next down mip-level Size3. - public Size3 Down2(int count = 1) + public Size3 Down2( int count = 1 ) { - if (count < 0) + if( count < 0 ) { - throw new ArgumentOutOfRangeException("count", "Must be >= 0"); + throw new ArgumentOutOfRangeException( "count", "Must be >= 0" ); } - return new Size3(Math.Max(1, Width >> count), Math.Max(1, Height >> count), Math.Max(1, Depth >> count)); + return new Size3( Math.Max( 1, Width >> count ), Math.Max( 1, Height >> count ), Math.Max( 1, Depth >> count ) ); } /// @@ -229,7 +230,7 @@ namespace math /// /// The direction < 0 then , > 0 then , else this unchanged. /// Size3. - public Size3 Mip(int direction) + public Size3 Mip( int direction ) { return direction == 0 ? this : direction < 0 ? Down2() : Up2(); } diff --git a/math/SphericalHarmonics.cs b/math/SphericalHarmonics.cs index 8205c55..e3d31a0 100644 --- a/math/SphericalHarmonics.cs +++ b/math/SphericalHarmonics.cs @@ -16,14 +16,14 @@ namespace math /// A representation of a sphere of values via Spherical Harmonics (SH). /// /// The type of data contained by the sphere - [DataContract( Name = "SphericalHarmonicsGeneric")] + [DataContract( Name = "SphericalHarmonicsGeneric" )] public abstract class SphericalHarmonics { /// /// The maximum order supported. /// public const int MaximumOrder = 5; - + private int order; /// @@ -35,10 +35,10 @@ namespace math get { return order; } internal set { - if (order>5) - throw new NotSupportedException("Only orders inferior or equal to 5 are supported"); - - order = Math.Max(1, value); + if( order > 5 ) + throw new NotSupportedException( "Only orders inferior or equal to 5 are supported" ); + + order = Math.Max( 1, value ); } } @@ -59,7 +59,7 @@ namespace math /// Initializes a new instance of the class. /// /// The order of the harmonics - protected SphericalHarmonics(int order) + protected SphericalHarmonics( int order ) { this.order = order; Coefficients = new TDataType[order * order]; @@ -70,7 +70,7 @@ namespace math /// /// The direction /// The value of the spherical harmonics in the direction - public abstract TDataType Evaluate(Vec3 direction); + public abstract TDataType Evaluate( Vec3 direction ); /// /// Returns the coefficient x{l,m} of the spherical harmonics (the {l,m} spherical coordinate corresponding to the spherical base Y{l,m}). @@ -82,28 +82,28 @@ namespace math { get { - CheckIndicesValidity(l, m, order); - return Coefficients[LmToCoefficientIndex(l, m)]; + CheckIndicesValidity( l, m, order ); + return Coefficients[LmToCoefficientIndex( l, m )]; } set { - CheckIndicesValidity(l, m, order); - Coefficients[LmToCoefficientIndex(l, m)] = value; + CheckIndicesValidity( l, m, order ); + Coefficients[LmToCoefficientIndex( l, m )] = value; } } // ReSharper disable UnusedParameter.Local - private static void CheckIndicesValidity(int l, int m, int maxOrder) + private static void CheckIndicesValidity( int l, int m, int maxOrder ) // ReSharper restore UnusedParameter.Local { - if (l > maxOrder - 1) - throw new IndexOutOfRangeException($"'l' parameter should be between '0' and '{maxOrder-1}' (order-1)."); + if( l > 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'."); + if( Math.Abs( m ) > l ) + throw new IndexOutOfRangeException( "'m' parameter should be between '-l' and '+l'." ); } - private static int LmToCoefficientIndex(int l, int m) + private static int LmToCoefficientIndex( int l, int m ) { return l * l + l + m; } @@ -112,7 +112,7 @@ namespace math /// /// A spherical harmonics representation of a cubemap. /// - [DataContract( Name = "SphericalHarmonics")] + [DataContract( Name = "SphericalHarmonics" )] public class SphericalHarmonics : SphericalHarmonics { private readonly float[] baseValues; @@ -120,7 +120,7 @@ namespace math private const float Pi4 = 4 * MathUtil.Pi; private const float Pi16 = 16 * MathUtil.Pi; private const float Pi64 = 64 * MathUtil.Pi; - private static readonly float SqrtPi = (float)Math.Sqrt(MathUtil.Pi); + private static readonly float SqrtPi = (float)Math.Sqrt( MathUtil.Pi ); /// /// Base coefficients for SH. @@ -169,8 +169,8 @@ namespace math /// Initializes a new instance of the class. /// /// The order of the harmonics - public SphericalHarmonics(int order) - : base(order) + public SphericalHarmonics( int order ) + : base( order ) { baseValues = new float[order * order]; } @@ -180,60 +180,60 @@ namespace math /// /// The direction to evaluate. /// The color computed for this direction. - public override Color3 Evaluate(Vec3 direction) + public override Color3 Evaluate( Vec3 direction ) { var x = direction.X; var y = direction.Y; var z = direction.Z; - var x2 = x*x; - var y2 = y*y; - var z2 = z*z; + var x2 = x * x; + var y2 = y * y; + var z2 = z * z; - var z3 = (float)Math.Pow(z, 3.0); + var z3 = (float)Math.Pow( z, 3.0 ); - var x4 = (float)Math.Pow(x, 4.0); - var y4 = (float)Math.Pow(y, 4.0); - var z4 = (float)Math.Pow(z, 4.0); + var x4 = (float)Math.Pow( x, 4.0 ); + var y4 = (float)Math.Pow( y, 4.0 ); + var z4 = (float)Math.Pow( z, 4.0 ); //Equations based on data from: http://ppsloan.org/publications/StupidSH36.pdf - baseValues[ 0] = 1/(2*SqrtPi); + baseValues[0] = 1 / ( 2 * SqrtPi ); - if (Order > 1) + if( Order > 1 ) { - baseValues[ 1] = -(float)Math.Sqrt(3/Pi4)*y; - baseValues[ 2] = (float)Math.Sqrt(3/Pi4)*z; - baseValues[ 3] = -(float)Math.Sqrt(3/Pi4)*x; - - if (Order > 2) + baseValues[1] = -(float)Math.Sqrt( 3 / Pi4 ) * y; + baseValues[2] = (float)Math.Sqrt( 3 / Pi4 ) * z; + baseValues[3] = -(float)Math.Sqrt( 3 / Pi4 ) * x; + + if( Order > 2 ) { - baseValues[ 4] = (float)Math.Sqrt(15/Pi4)*y*x; - baseValues[ 5] = -(float)Math.Sqrt(15/Pi4)*y*z; - baseValues[ 6] = (float)Math.Sqrt(5/Pi16)*(3*z2-1); - baseValues[ 7] = -(float)Math.Sqrt(15/Pi4)*x*z; - baseValues[ 8] = (float)Math.Sqrt(15/Pi16)*(x2-y2); - - if (Order > 3) + baseValues[4] = (float)Math.Sqrt( 15 / Pi4 ) * y * x; + baseValues[5] = -(float)Math.Sqrt( 15 / Pi4 ) * y * z; + baseValues[6] = (float)Math.Sqrt( 5 / Pi16 ) * ( 3 * z2 - 1 ); + baseValues[7] = -(float)Math.Sqrt( 15 / Pi4 ) * x * z; + baseValues[8] = (float)Math.Sqrt( 15 / Pi16 ) * ( x2 - y2 ); + + if( Order > 3 ) { - baseValues[ 9] = -(float)Math.Sqrt( 70/Pi64)*y*(3*x2-y2); - baseValues[10] = (float)Math.Sqrt(105/ Pi4)*y*x*z; - baseValues[11] = -(float)Math.Sqrt( 42/Pi64)*y*(-1+5*z2); - baseValues[12] = (float)Math.Sqrt( 7/Pi16)*(5*z3-3*z); - baseValues[13] = -(float)Math.Sqrt( 42/Pi64)*x*(-1+5*z2); - baseValues[14] = (float)Math.Sqrt(105/Pi16)*(x2-y2)*z; - baseValues[15] = -(float)Math.Sqrt( 70/Pi64)*x*(x2-3*y2); - - if (Order > 4) + baseValues[9] = -(float)Math.Sqrt( 70 / Pi64 ) * y * ( 3 * x2 - y2 ); + baseValues[10] = (float)Math.Sqrt( 105 / Pi4 ) * y * x * z; + baseValues[11] = -(float)Math.Sqrt( 42 / Pi64 ) * y * ( -1 + 5 * z2 ); + baseValues[12] = (float)Math.Sqrt( 7 / Pi16 ) * ( 5 * z3 - 3 * z ); + baseValues[13] = -(float)Math.Sqrt( 42 / Pi64 ) * x * ( -1 + 5 * z2 ); + baseValues[14] = (float)Math.Sqrt( 105 / Pi16 ) * ( x2 - y2 ) * z; + baseValues[15] = -(float)Math.Sqrt( 70 / Pi64 ) * x * ( x2 - 3 * y2 ); + + if( Order > 4 ) { - baseValues[16] = 3*(float)Math.Sqrt(35/Pi16)*x*y*(x2-y2); - baseValues[17] = -3*(float)Math.Sqrt(70/Pi64)*y*z*(3*x2-y2); - baseValues[18] = 3*(float)Math.Sqrt( 5/Pi16)*y*x*(-1+7*z2); - baseValues[19] = -3*(float)Math.Sqrt(10/Pi64)*y*z*(-3+7*z2); - baseValues[20] = (105*z4-90*z2+9)/(16*SqrtPi); - baseValues[21] = -3*(float)Math.Sqrt(10/Pi64)*x*z*(-3+7*z2); - baseValues[22] = 3*(float)Math.Sqrt( 5/Pi64)*(x2-y2)*(-1+7*z2); - baseValues[23] = -3*(float)Math.Sqrt(70/Pi64)*x*z*(x2-3*y2); - baseValues[24] = 3*(float)Math.Sqrt(35/(4*Pi64))*(x4-6*y2*x2+y4); + baseValues[16] = 3 * (float)Math.Sqrt( 35 / Pi16 ) * x * y * ( x2 - y2 ); + baseValues[17] = -3 * (float)Math.Sqrt( 70 / Pi64 ) * y * z * ( 3 * x2 - y2 ); + baseValues[18] = 3 * (float)Math.Sqrt( 5 / Pi16 ) * y * x * ( -1 + 7 * z2 ); + baseValues[19] = -3 * (float)Math.Sqrt( 10 / Pi64 ) * y * z * ( -3 + 7 * z2 ); + baseValues[20] = ( 105 * z4 - 90 * z2 + 9 ) / ( 16 * SqrtPi ); + baseValues[21] = -3 * (float)Math.Sqrt( 10 / Pi64 ) * x * z * ( -3 + 7 * z2 ); + baseValues[22] = 3 * (float)Math.Sqrt( 5 / Pi64 ) * ( x2 - y2 ) * ( -1 + 7 * z2 ); + baseValues[23] = -3 * (float)Math.Sqrt( 70 / Pi64 ) * x * z * ( x2 - 3 * y2 ); + baseValues[24] = 3 * (float)Math.Sqrt( 35 / ( 4 * Pi64 ) ) * ( x4 - 6 * y2 * x2 + y4 ); } } } @@ -241,7 +241,7 @@ namespace math var data = new Color3(); - for (int i = 0; i < baseValues.Length; i++) + for( int i = 0; i < baseValues.Length; i++ ) data += Coefficients[i] * baseValues[i]; return data; diff --git a/math/UInt4.cs b/math/UInt4.cs index 72d7ea9..a86c471 100644 --- a/math/UInt4.cs +++ b/math/UInt4.cs @@ -2,17 +2,17 @@ // Distributed under the MIT license. See the LICENSE.md file in the project root for more information. // // Copyright (c) 2010-2011 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 @@ -31,7 +31,7 @@ namespace math /// Represents a four dimensional mathematical vector. /// [DataContract] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct UInt4 : IEquatable, IFormattable { /// @@ -47,27 +47,27 @@ namespace math /// /// The X unit (1, 0, 0, 0). /// - public static readonly UInt4 UnitX = new UInt4(1, 0, 0, 0); + public static readonly UInt4 UnitX = new UInt4( 1, 0, 0, 0 ); /// /// The Y unit (0, 1, 0, 0). /// - public static readonly UInt4 UnitY = new UInt4(0, 1, 0, 0); + public static readonly UInt4 UnitY = new UInt4( 0, 1, 0, 0 ); /// /// The Z unit (0, 0, 1, 0). /// - public static readonly UInt4 UnitZ = new UInt4(0, 0, 1, 0); + public static readonly UInt4 UnitZ = new UInt4( 0, 0, 1, 0 ); /// /// The W unit (0, 0, 0, 1). /// - public static readonly UInt4 UnitW = new UInt4(0, 0, 0, 1); + public static readonly UInt4 UnitW = new UInt4( 0, 0, 0, 1 ); /// /// A with all of its components set to one. /// - public static readonly UInt4 One = new UInt4(1, 1, 1, 1); + public static readonly UInt4 One = new UInt4( 1, 1, 1, 1 ); /// /// The X component of the vector. @@ -93,7 +93,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public UInt4(uint value) + public UInt4( uint value ) { X = value; Y = value; @@ -108,7 +108,7 @@ namespace math /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. /// Initial value for the W component of the vector. - public UInt4(uint x, uint y, uint z, uint w) + public UInt4( uint x, uint y, uint z, uint w ) { X = x; Y = y; @@ -122,12 +122,12 @@ namespace math /// The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public UInt4(uint[] values) + public UInt4( uint[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 4) - throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for UInt4."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( "values", "There must be four and only four input values for UInt4." ); X = values[0]; Y = values[1]; @@ -146,7 +146,7 @@ namespace math { get { - switch (index) + switch( index ) { case 0: return X; @@ -158,12 +158,12 @@ namespace math return W; } - throw new ArgumentOutOfRangeException("index", "Indices for UInt4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for UInt4 run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { case 0: X = value; @@ -178,7 +178,7 @@ namespace math W = value; break; default: - throw new ArgumentOutOfRangeException("index", "Indices for UInt4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for UInt4 run from 0 to 3, inclusive." ); } } } @@ -198,9 +198,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - public static void Add(ref UInt4 left, ref UInt4 right, out UInt4 result) + public static void Add( ref UInt4 left, ref UInt4 right, out UInt4 result ) { - result = new UInt4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + result = new UInt4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -209,9 +209,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static UInt4 Add(UInt4 left, UInt4 right) + public static UInt4 Add( UInt4 left, UInt4 right ) { - return new UInt4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new UInt4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -220,9 +220,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - public static void Subtract(ref UInt4 left, ref UInt4 right, out UInt4 result) + public static void Subtract( ref UInt4 left, ref UInt4 right, out UInt4 result ) { - result = new UInt4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + result = new UInt4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -231,9 +231,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static UInt4 Subtract(UInt4 left, UInt4 right) + public static UInt4 Subtract( UInt4 left, UInt4 right ) { - return new UInt4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new UInt4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -242,9 +242,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Multiply(ref UInt4 value, uint scale, out UInt4 result) + public static void Multiply( ref UInt4 value, uint scale, out UInt4 result ) { - result = new UInt4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + result = new UInt4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -253,9 +253,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static UInt4 Multiply(UInt4 value, uint scale) + public static UInt4 Multiply( UInt4 value, uint scale ) { - return new UInt4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new UInt4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -264,9 +264,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - public static void Modulate(ref UInt4 left, ref UInt4 right, out UInt4 result) + public static void Modulate( ref UInt4 left, ref UInt4 right, out UInt4 result ) { - result = new UInt4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + result = new UInt4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -275,9 +275,9 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - public static UInt4 Modulate(UInt4 left, UInt4 right) + public static UInt4 Modulate( UInt4 left, UInt4 right ) { - return new UInt4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + return new UInt4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -286,9 +286,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - public static void Divide(ref UInt4 value, uint scale, out UInt4 result) + public static void Divide( ref UInt4 value, uint scale, out UInt4 result ) { - result = new UInt4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + result = new UInt4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -297,9 +297,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static UInt4 Divide(UInt4 value, uint scale) + public static UInt4 Divide( UInt4 value, uint scale ) { - return new UInt4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new UInt4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -309,25 +309,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref UInt4 value, ref UInt4 min, ref UInt4 max, out UInt4 result) + public static void Clamp( ref UInt4 value, ref UInt4 min, ref UInt4 max, out UInt4 result ) { uint x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; uint y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; uint z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; uint w = value.W; - w = (w > max.W) ? max.W : w; - w = (w < min.W) ? min.W : w; + w = ( w > max.W ) ? max.W : w; + w = ( w < min.W ) ? min.W : w; - result = new UInt4(x, y, z, w); + result = new UInt4( x, y, z, w ); } /// @@ -337,10 +337,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static UInt4 Clamp(UInt4 value, UInt4 min, UInt4 max) + public static UInt4 Clamp( UInt4 value, UInt4 min, UInt4 max ) { UInt4 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -350,12 +350,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - public static void Max(ref UInt4 left, ref UInt4 right, out UInt4 result) + public static void Max( ref UInt4 left, ref UInt4 right, out UInt4 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; - result.W = (left.W > right.W) ? left.W : right.W; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; + result.W = ( left.W > right.W ) ? left.W : right.W; } /// @@ -364,10 +364,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - public static UInt4 Max(UInt4 left, UInt4 right) + public static UInt4 Max( UInt4 left, UInt4 right ) { UInt4 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -377,12 +377,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - public static void Min(ref UInt4 left, ref UInt4 right, out UInt4 result) + public static void Min( ref UInt4 left, ref UInt4 right, out UInt4 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; - result.W = (left.W < right.W) ? left.W : right.W; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; + result.W = ( left.W < right.W ) ? left.W : right.W; } /// @@ -391,10 +391,10 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - public static UInt4 Min(UInt4 left, UInt4 right) + public static UInt4 Min( UInt4 left, UInt4 right ) { UInt4 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -404,9 +404,9 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - public static UInt4 operator +(UInt4 left, UInt4 right) + public static UInt4 operator +( UInt4 left, UInt4 right ) { - return new UInt4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new UInt4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -414,7 +414,7 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - public static UInt4 operator +(UInt4 value) + public static UInt4 operator +( UInt4 value ) { return value; } @@ -425,9 +425,9 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - public static UInt4 operator -(UInt4 left, UInt4 right) + public static UInt4 operator -( UInt4 left, UInt4 right ) { - return new UInt4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new UInt4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -436,9 +436,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static UInt4 operator *(uint scale, UInt4 value) + public static UInt4 operator *( uint scale, UInt4 value ) { - return new UInt4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new UInt4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -447,9 +447,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static UInt4 operator *(UInt4 value, uint scale) + public static UInt4 operator *( UInt4 value, uint scale ) { - return new UInt4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new UInt4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -458,9 +458,9 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - public static UInt4 operator /(UInt4 value, uint scale) + public static UInt4 operator /( UInt4 value, uint scale ) { - return new UInt4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new UInt4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -469,9 +469,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(UInt4 left, UInt4 right) + public static bool operator ==( UInt4 left, UInt4 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -480,9 +480,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(UInt4 left, UInt4 right) + public static bool operator !=( UInt4 left, UInt4 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -490,9 +490,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(UInt4 value) + public static explicit operator Vec2( UInt4 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } /// @@ -500,9 +500,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(UInt4 value) + public static explicit operator Vec3( UInt4 value ) { - return new Vec3(value.X, value.Y, value.Z); + return new Vec3( value.X, value.Y, value.Z ); } /// @@ -510,9 +510,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(UInt4 value) + public static explicit operator Vec4( UInt4 value ) { - return new Vec4(value.X, value.Y, value.Z, value.W); + return new Vec4( value.X, value.Y, value.Z, value.W ); } /// @@ -523,7 +523,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -533,16 +533,16 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", - X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), - Z.ToString(format, CultureInfo.CurrentCulture), - W.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", + X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), + Z.ToString( format, CultureInfo.CurrentCulture ), + W.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -552,9 +552,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -565,21 +565,21 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - ToString(formatProvider); + if( format == null ) + ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider), - W.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ), + W.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -593,7 +593,7 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(UInt4 other) + public bool Equals( UInt4 other ) { return other.X == X && other.Y == Y && other.Z == Z && other.W == W; } @@ -605,15 +605,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((UInt4)value); + return Equals( (UInt4)value ); } /// @@ -621,9 +621,9 @@ namespace math /// /// The input. /// The result of the conversion. - public static implicit operator UInt4(uint[] input) + public static implicit operator UInt4( uint[] input ) { - return new UInt4(input); + return new UInt4( input ); } /// @@ -631,7 +631,7 @@ namespace math /// /// The input. /// The result of the conversion. - public static implicit operator uint[](UInt4 input) + public static implicit operator uint[]( UInt4 input ) { return input.ToArray(); } diff --git a/math/Vector2.cs b/math/Vector2.cs index b2dc55a..24ba295 100644 --- a/math/Vector2.cs +++ b/math/Vector2.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -37,9 +37,9 @@ namespace math /// /// Represents a two dimensional mathematical vector. /// - [DataContract( Name = "float2")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "float2" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Vec2 : IEquatable, IFormattable { /// @@ -55,17 +55,17 @@ namespace math /// /// The X unit (1, 0). /// - public static readonly Vec2 UnitX = new Vec2(1.0f, 0.0f); + public static readonly Vec2 UnitX = new Vec2( 1.0f, 0.0f ); /// /// The Y unit (0, 1). /// - public static readonly Vec2 UnitY = new Vec2(0.0f, 1.0f); + public static readonly Vec2 UnitY = new Vec2( 0.0f, 1.0f ); /// /// A with all of its components set to one. /// - public static readonly Vec2 One = new Vec2(1.0f, 1.0f); + public static readonly Vec2 One = new Vec2( 1.0f, 1.0f ); /// /// The X component of the vector. @@ -83,7 +83,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Vec2(float value) + public Vec2( float value ) { X = value; Y = value; @@ -94,7 +94,7 @@ namespace math /// /// Initial value for the X component of the vector. /// Initial value for the Y component of the vector. - public Vec2(float x, float y) + public Vec2( float x, float y ) { X = x; Y = y; @@ -106,12 +106,12 @@ namespace math /// The values to assign to the X and Y components of the vector. This must be an array with two elements. /// Thrown when is null. /// Thrown when contains more or less than two elements. - public Vec2(float[] values) + public Vec2( float[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 2) - throw new ArgumentOutOfRangeException("values", "There must be two and only two input values for Vector2."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 2 ) + throw new ArgumentOutOfRangeException( "values", "There must be two and only two input values for Vector2." ); X = values[0]; Y = values[1]; @@ -122,7 +122,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -136,22 +136,29 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; + case 0: + return X; + case 1: + return Y; } - throw new ArgumentOutOfRangeException("index", "Indices for Vector2 run from 0 to 1, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Vector2 run from 0 to 1, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Vector2 run from 0 to 1, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Vector2 run from 0 to 1, inclusive." ); } } } @@ -164,10 +171,10 @@ namespace math /// may be preferred when only the relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public float Length() { - return (float)Math.Sqrt((X * X) + (Y * Y)); + return (float)Math.Sqrt( ( X * X ) + ( Y * Y ) ); } /// @@ -178,20 +185,20 @@ namespace math /// This method may be preferred to when only a relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public float LengthSquared() { - return (X * X) + (Y * Y); + return ( X * X ) + ( Y * Y ); } /// /// Converts the vector into a unit vector. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public void Normalize() { float length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { float inv = 1.0f / length; X *= inv; @@ -214,10 +221,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Add(ref Vec2 left, ref Vec2 right, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Add( ref Vec2 left, ref Vec2 right, out Vec2 result ) { - result = new Vec2(left.X + right.X, left.Y + right.Y); + result = new Vec2( left.X + right.X, left.Y + right.Y ); } /// @@ -226,10 +233,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Add(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Add( Vec2 left, Vec2 right ) { - return new Vec2(left.X + right.X, left.Y + right.Y); + return new Vec2( left.X + right.X, left.Y + right.Y ); } /// @@ -238,10 +245,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Subtract(ref Vec2 left, ref Vec2 right, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Subtract( ref Vec2 left, ref Vec2 right, out Vec2 result ) { - result = new Vec2(left.X - right.X, left.Y - right.Y); + result = new Vec2( left.X - right.X, left.Y - right.Y ); } /// @@ -250,10 +257,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Subtract(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Subtract( Vec2 left, Vec2 right ) { - return new Vec2(left.X - right.X, left.Y - right.Y); + return new Vec2( left.X - right.X, left.Y - right.Y ); } /// @@ -262,10 +269,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Multiply(ref Vec2 value, float scale, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Multiply( ref Vec2 value, float scale, out Vec2 result ) { - result = new Vec2(value.X * scale, value.Y * scale); + result = new Vec2( value.X * scale, value.Y * scale ); } /// @@ -274,22 +281,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Multiply(Vec2 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Multiply( Vec2 value, float scale ) { - return new Vec2(value.X * scale, value.Y * scale); + return new Vec2( value.X * scale, value.Y * scale ); } - + /// /// Modulates a vector with another by performing component-wise multiplication. /// /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Modulate(ref Vec2 left, ref Vec2 right, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Modulate( ref Vec2 left, ref Vec2 right, out Vec2 result ) { - result = new Vec2(left.X * right.X, left.Y * right.Y); + result = new Vec2( left.X * right.X, left.Y * right.Y ); } /// @@ -298,10 +305,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Modulate(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Modulate( Vec2 left, Vec2 right ) { - return new Vec2(left.X * right.X, left.Y * right.Y); + return new Vec2( left.X * right.X, left.Y * right.Y ); } /// @@ -310,10 +317,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Divide(ref Vec2 value, float scale, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Divide( ref Vec2 value, float scale, out Vec2 result ) { - result = new Vec2(value.X / scale, value.Y / scale); + result = new Vec2( value.X / scale, value.Y / scale ); } /// @@ -322,22 +329,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Divide(Vec2 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Divide( Vec2 value, float scale ) { - return new Vec2(value.X / scale, value.Y / scale); + return new Vec2( value.X / scale, value.Y / scale ); } - + /// /// Demodulates a vector with another by performing component-wise division. /// /// The first vector to demodulate. /// The second vector to demodulate. /// When the method completes, contains the demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Demodulate(ref Vec2 left, ref Vec2 right, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Demodulate( ref Vec2 left, ref Vec2 right, out Vec2 result ) { - result = new Vec2(left.X / right.X, left.Y / right.Y); + result = new Vec2( left.X / right.X, left.Y / right.Y ); } /// @@ -346,10 +353,10 @@ namespace math /// The first vector to demodulate. /// The second vector to demodulate. /// The demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Demodulate(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Demodulate( Vec2 left, Vec2 right ) { - return new Vec2(left.X / right.X, left.Y / right.Y); + return new Vec2( left.X / right.X, left.Y / right.Y ); } /// @@ -357,10 +364,10 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Negate(ref Vec2 value, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Negate( ref Vec2 value, out Vec2 result ) { - result = new Vec2(-value.X, -value.Y); + result = new Vec2( -value.X, -value.Y ); } /// @@ -368,10 +375,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Negate(Vec2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Negate( Vec2 value ) { - return new Vec2(-value.X, -value.Y); + return new Vec2( -value.X, -value.Y ); } /// @@ -383,11 +390,11 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 2D Cartesian coordinates of the specified point. - public static void Barycentric(ref Vec2 value1, ref Vec2 value2, ref Vec2 value3, float amount1, float amount2, out Vec2 result) + public static void Barycentric( ref Vec2 value1, ref Vec2 value2, ref Vec2 value3, float amount1, float amount2, out Vec2 result ) { result = new Vec2( - (value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)), - (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y))); + ( value1.X + ( amount1 * ( value2.X - value1.X ) ) ) + ( amount2 * ( value3.X - value1.X ) ), + ( value1.Y + ( amount1 * ( value2.Y - value1.Y ) ) ) + ( amount2 * ( value3.Y - value1.Y ) ) ); } /// @@ -399,10 +406,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 2D Cartesian coordinates of the specified point. - public static Vec2 Barycentric(Vec2 value1, Vec2 value2, Vec2 value3, float amount1, float amount2) + public static Vec2 Barycentric( Vec2 value1, Vec2 value2, Vec2 value3, float amount1, float amount2 ) { Vec2 result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -413,17 +420,17 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Vec2 value, ref Vec2 min, ref Vec2 max, out Vec2 result) + public static void Clamp( ref Vec2 value, ref Vec2 min, ref Vec2 max, out Vec2 result ) { float x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; float y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; - result = new Vec2(x, y); + result = new Vec2( x, y ); } /// @@ -433,10 +440,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Vec2 Clamp(Vec2 value, Vec2 min, Vec2 max) + public static Vec2 Clamp( Vec2 value, Vec2 min, Vec2 max ) { Vec2 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -450,12 +457,12 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static void Distance(ref Vec2 value1, ref Vec2 value2, out float result) + public static void Distance( ref Vec2 value1, ref Vec2 value2, out float result ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; - result = (float)Math.Sqrt((x * x) + (y * y)); + result = (float)Math.Sqrt( ( x * x ) + ( y * y ) ); } /// @@ -468,12 +475,12 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static float Distance(Vec2 value1, Vec2 value2) + public static float Distance( Vec2 value1, Vec2 value2 ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; - return (float)Math.Sqrt((x * x) + (y * y)); + return (float)Math.Sqrt( ( x * x ) + ( y * y ) ); } /// @@ -482,19 +489,19 @@ namespace math /// The first vector. /// The second vector /// When the method completes, contains the squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Vec2 value1, ref Vec2 value2, out float result) + public static void DistanceSquared( ref Vec2 value1, ref Vec2 value2, out float result ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; - result = (x * x) + (y * y); + result = ( x * x ) + ( y * y ); } /// @@ -503,19 +510,19 @@ namespace math /// The first vector. /// The second vector. /// The squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static float DistanceSquared(Vec2 value1, Vec2 value2) + public static float DistanceSquared( Vec2 value1, Vec2 value2 ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; - return (x * x) + (y * y); + return ( x * x ) + ( y * y ); } /// @@ -524,10 +531,10 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Vec2 left, ref Vec2 right, out float result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Dot( ref Vec2 left, ref Vec2 right, out float result ) { - result = (left.X * right.X) + (left.Y * right.Y); + result = ( left.X * right.X ) + ( left.Y * right.Y ); } /// @@ -536,10 +543,10 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static float Dot( Vec2 left, Vec2 right ) { - return (left.X * right.X) + (left.Y * right.Y); + return ( left.X * right.X ) + ( left.Y * right.Y ); } /// @@ -547,8 +554,8 @@ namespace math /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(ref Vec2 value, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Normalize( ref Vec2 value, out Vec2 result ) { result = value; result.Normalize(); @@ -559,8 +566,8 @@ namespace math /// /// The vector to normalize. /// The normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Normalize(Vec2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Normalize( Vec2 value ) { value.Normalize(); return value; @@ -576,12 +583,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Vec2 start, ref Vec2 end, float amount, out Vec2 result) + public static void Lerp( ref Vec2 start, ref Vec2 end, float amount, out Vec2 result ) { - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); } /// @@ -594,12 +601,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Vec2 Lerp(Vec2 start, Vec2 end, float amount) + public static Vec2 Lerp( Vec2 start, Vec2 end, float amount ) { Vec2 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -610,13 +617,13 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Vec2 start, ref Vec2 end, float amount, out Vec2 result) + public static void SmoothStep( ref Vec2 start, ref Vec2 end, float amount, out Vec2 result ) { - amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0f ) ? 1.0f : ( ( amount < 0.0f ) ? 0.0f : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); } /// @@ -626,10 +633,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Vec2 SmoothStep(Vec2 start, Vec2 end, float amount) + public static Vec2 SmoothStep( Vec2 start, Vec2 end, float amount ) { Vec2 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -642,17 +649,17 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Vec2 value1, ref Vec2 tangent1, ref Vec2 value2, ref Vec2 tangent2, float amount, out Vec2 result) + public static void Hermite( ref Vec2 value1, ref Vec2 tangent1, ref Vec2 value2, ref Vec2 tangent2, float amount, out Vec2 result ) { float squared = amount * amount; float cubed = amount * squared; - float part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0f; - float part2 = (-2.0f * cubed) + (3.0f * squared); - float part3 = (cubed - (2.0f * squared)) + amount; + float part1 = ( ( 2.0f * cubed ) - ( 3.0f * squared ) ) + 1.0f; + float part2 = ( -2.0f * cubed ) + ( 3.0f * squared ); + float part3 = ( cubed - ( 2.0f * squared ) ) + amount; float part4 = cubed - squared; - result.X = (((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4); - result.Y = (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4); + result.X = ( ( ( value1.X * part1 ) + ( value2.X * part2 ) ) + ( tangent1.X * part3 ) ) + ( tangent2.X * part4 ); + result.Y = ( ( ( value1.Y * part1 ) + ( value2.Y * part2 ) ) + ( tangent1.Y * part3 ) ) + ( tangent2.Y * part4 ); } /// @@ -664,10 +671,10 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// The result of the Hermite spline interpolation. - public static Vec2 Hermite(Vec2 value1, Vec2 tangent1, Vec2 value2, Vec2 tangent2, float amount) + public static Vec2 Hermite( Vec2 value1, Vec2 tangent1, Vec2 value2, Vec2 tangent2, float amount ) { Vec2 result; - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + Hermite( ref value1, ref tangent1, ref value2, ref tangent2, amount, out result ); return result; } @@ -680,18 +687,18 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Vec2 value1, ref Vec2 value2, ref Vec2 value3, ref Vec2 value4, float amount, out Vec2 result) + public static void CatmullRom( ref Vec2 value1, ref Vec2 value2, ref Vec2 value3, ref Vec2 value4, float amount, out Vec2 result ) { float squared = amount * amount; float cubed = amount * squared; - result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) + - (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) + - ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed)); + result.X = 0.5f * ( ( ( ( 2.0f * value2.X ) + ( ( -value1.X + value3.X ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.X ) - ( 5.0f * value2.X ) ) + ( 4.0f * value3.X ) ) - value4.X ) * squared ) ) + + ( ( ( ( -value1.X + ( 3.0f * value2.X ) ) - ( 3.0f * value3.X ) ) + value4.X ) * cubed ) ); - result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) + - (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) + - ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed)); + result.Y = 0.5f * ( ( ( ( 2.0f * value2.Y ) + ( ( -value1.Y + value3.Y ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.Y ) - ( 5.0f * value2.Y ) ) + ( 4.0f * value3.Y ) ) - value4.Y ) * squared ) ) + + ( ( ( ( -value1.Y + ( 3.0f * value2.Y ) ) - ( 3.0f * value3.Y ) ) + value4.Y ) * cubed ) ); } /// @@ -703,10 +710,10 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// A vector that is the result of the Catmull-Rom interpolation. - public static Vec2 CatmullRom(Vec2 value1, Vec2 value2, Vec2 value3, Vec2 value4, float amount) + public static Vec2 CatmullRom( Vec2 value1, Vec2 value2, Vec2 value3, Vec2 value4, float amount ) { Vec2 result; - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result); + CatmullRom( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -716,11 +723,11 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Max(ref Vec2 left, ref Vec2 right, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Max( ref Vec2 left, ref Vec2 right, out Vec2 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; } /// @@ -729,11 +736,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Max(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Max( Vec2 left, Vec2 right ) { Vec2 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -743,11 +750,11 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Min(ref Vec2 left, ref Vec2 right, out Vec2 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Min( ref Vec2 left, ref Vec2 right, out Vec2 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; } /// @@ -756,42 +763,42 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 Min(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 Min( Vec2 left, Vec2 right ) { Vec2 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// When the method completes, contains the reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Vec2 vector, ref Vec2 normal, out Vec2 result) + public static void Reflect( ref Vec2 vector, ref Vec2 normal, out Vec2 result ) { - float dot = (vector.X * normal.X) + (vector.Y * normal.Y); + float dot = ( vector.X * normal.X ) + ( vector.Y * normal.Y ); - result.X = vector.X - ((2.0f * dot) * normal.X); - result.Y = vector.Y - ((2.0f * dot) * normal.Y); + result.X = vector.X - ( ( 2.0f * dot ) * normal.X ); + result.Y = vector.Y - ( ( 2.0f * dot ) * normal.Y ); } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// The reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static Vec2 Reflect(Vec2 vector, Vec2 normal) + public static Vec2 Reflect( Vec2 vector, Vec2 normal ) { Vec2 result; - Reflect(ref vector, ref normal, out result); + Reflect( ref vector, ref normal, out result ); return result; } @@ -811,7 +818,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthogonalize(Vec2[] destination, params Vec2[] source) + public static void Orthogonalize( Vec2[] destination, params Vec2[] source ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -820,20 +827,20 @@ namespace math //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3 //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Vec2 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= (Vec2.Dot(destination[r], newvector) / Vec2.Dot(destination[r], destination[r])) * destination[r]; + newvector -= ( Vec2.Dot( destination[r], newvector ) / Vec2.Dot( destination[r], destination[r] ) ) * destination[r]; } destination[i] = newvector; @@ -856,7 +863,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthonormalize(Vec2[] destination, params Vec2[] source) + public static void Orthonormalize( Vec2[] destination, params Vec2[] source ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -867,20 +874,20 @@ namespace math //q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3| //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Vec2 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= Vec2.Dot(destination[r], newvector) * destination[r]; + newvector -= Vec2.Dot( destination[r], newvector ) * destination[r]; } newvector.Normalize(); @@ -894,7 +901,7 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Vec2 vector, ref Quaternion rotation, out Vec2 result) + public static void Transform( ref Vec2 vector, ref Quaternion rotation, out Vec2 result ) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -905,7 +912,7 @@ namespace math float yy = rotation.Y * y; float zz = rotation.Z * z; - result = new Vec2((vector.X * (1.0f - yy - zz)) + (vector.Y * (xy - wz)), (vector.X * (xy + wz)) + (vector.Y * (1.0f - xx - zz))); + result = new Vec2( ( vector.X * ( 1.0f - yy - zz ) ) + ( vector.Y * ( xy - wz ) ), ( vector.X * ( xy + wz ) ) + ( vector.Y * ( 1.0f - xx - zz ) ) ); } /// @@ -914,10 +921,10 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// The transformed . - public static Vec2 Transform(Vec2 vector, Quaternion rotation) + public static Vec2 Transform( Vec2 vector, Quaternion rotation ) { Vec2 result; - Transform(ref vector, ref rotation, out result); + Transform( ref vector, ref rotation, out result ); return result; } @@ -930,14 +937,14 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Vec2[] source, ref Quaternion rotation, Vec2[] destination) + public static void Transform( Vec2[] source, ref Quaternion rotation, Vec2[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -948,16 +955,16 @@ namespace math float yy = rotation.Y * y; float zz = rotation.Z * z; - float num1 = (1.0f - yy - zz); - float num2 = (xy - wz); - float num3 = (xy + wz); - float num4 = (1.0f - xx - zz); + float num1 = ( 1.0f - yy - zz ); + float num2 = ( xy - wz ); + float num3 = ( xy + wz ); + float num4 = ( 1.0f - xx - zz ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { destination[i] = new Vec2( - (source[i].X * num1) + (source[i].Y * num2), - (source[i].X * num3) + (source[i].Y * num4)); + ( source[i].X * num1 ) + ( source[i].Y * num2 ), + ( source[i].X * num3 ) + ( source[i].Y * num4 ) ); } } @@ -967,13 +974,13 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vec2 vector, ref Matrix transform, out Vec4 result) + public static void Transform( ref Vec2 vector, ref Matrix transform, out Vec4 result ) { result = new Vec4( - (vector.X * transform.M11) + (vector.Y * transform.M21) + transform.M41, - (vector.X * transform.M12) + (vector.Y * transform.M22) + transform.M42, - (vector.X * transform.M13) + (vector.Y * transform.M23) + transform.M43, - (vector.X * transform.M14) + (vector.Y * transform.M24) + transform.M44); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + transform.M41, + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + transform.M42, + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + transform.M43, + ( vector.X * transform.M14 ) + ( vector.Y * transform.M24 ) + transform.M44 ); } /// @@ -982,10 +989,10 @@ namespace math /// The source vector. /// The transformation . /// The transformed . - public static Vec4 Transform(Vec2 vector, Matrix transform) + public static Vec4 Transform( Vec2 vector, Matrix transform ) { Vec4 result; - Transform(ref vector, ref transform, out result); + Transform( ref vector, ref transform, out result ); return result; } @@ -997,18 +1004,18 @@ namespace math /// The array for which the transformed vectors are stored. /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Vec2[] source, ref Matrix transform, Vec4[] destination) + public static void Transform( Vec2[] source, ref Matrix transform, Vec4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - Transform(ref source[i], ref transform, out destination[i]); + Transform( ref source[i], ref transform, out destination[i] ); } } @@ -1025,15 +1032,15 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Vec2 coordinate, ref Matrix transform, out Vec2 result) + public static void TransformCoordinate( ref Vec2 coordinate, ref Matrix transform, out Vec2 result ) { Vec4 vector = new Vec4(); - vector.X = (coordinate.X * transform.M11) + (coordinate.Y * transform.M21) + transform.M41; - vector.Y = (coordinate.X * transform.M12) + (coordinate.Y * transform.M22) + transform.M42; - vector.Z = (coordinate.X * transform.M13) + (coordinate.Y * transform.M23) + transform.M43; - vector.W = 1f / ((coordinate.X * transform.M14) + (coordinate.Y * transform.M24) + transform.M44); + vector.X = ( coordinate.X * transform.M11 ) + ( coordinate.Y * transform.M21 ) + transform.M41; + vector.Y = ( coordinate.X * transform.M12 ) + ( coordinate.Y * transform.M22 ) + transform.M42; + vector.Z = ( coordinate.X * transform.M13 ) + ( coordinate.Y * transform.M23 ) + transform.M43; + vector.W = 1f / ( ( coordinate.X * transform.M14 ) + ( coordinate.Y * transform.M24 ) + transform.M44 ); - result = new Vec2(vector.X * vector.W, vector.Y * vector.W); + result = new Vec2( vector.X * vector.W, vector.Y * vector.W ); } /// @@ -1049,10 +1056,10 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static Vec2 TransformCoordinate(Vec2 coordinate, Matrix transform) + public static Vec2 TransformCoordinate( Vec2 coordinate, Matrix transform ) { Vec2 result; - TransformCoordinate(ref coordinate, ref transform, out result); + TransformCoordinate( ref coordinate, ref transform, out result ); return result; } @@ -1072,18 +1079,18 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(Vec2[] source, ref Matrix transform, Vec2[] destination) + public static void TransformCoordinate( Vec2[] source, ref Matrix transform, Vec2[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformCoordinate(ref source[i], ref transform, out destination[i]); + TransformCoordinate( ref source[i], ref transform, out destination[i] ); } } @@ -1100,11 +1107,11 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Vec2 normal, ref Matrix transform, out Vec2 result) + public static void TransformNormal( ref Vec2 normal, ref Matrix transform, out Vec2 result ) { result = new Vec2( - (normal.X * transform.M11) + (normal.Y * transform.M21), - (normal.X * transform.M12) + (normal.Y * transform.M22)); + ( normal.X * transform.M11 ) + ( normal.Y * transform.M21 ), + ( normal.X * transform.M12 ) + ( normal.Y * transform.M22 ) ); } /// @@ -1120,10 +1127,10 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static Vec2 TransformNormal(Vec2 normal, Matrix transform) + public static Vec2 TransformNormal( Vec2 normal, Matrix transform ) { Vec2 result; - TransformNormal(ref normal, ref transform, out result); + TransformNormal( ref normal, ref transform, out result ); return result; } @@ -1143,18 +1150,18 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(Vec2[] source, ref Matrix transform, Vec2[] destination) + public static void TransformNormal( Vec2[] source, ref Matrix transform, Vec2[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformNormal(ref source[i], ref transform, out destination[i]); + TransformNormal( ref source[i], ref transform, out destination[i] ); } } @@ -1164,10 +1171,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator +(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator +( Vec2 left, Vec2 right ) { - return new Vec2(left.X + right.X, left.Y + right.Y); + return new Vec2( left.X + right.X, left.Y + right.Y ); } /// @@ -1175,8 +1182,8 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator +(Vec2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator +( Vec2 value ) { return value; } @@ -1187,10 +1194,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator -(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator -( Vec2 left, Vec2 right ) { - return new Vec2(left.X - right.X, left.Y - right.Y); + return new Vec2( left.X - right.X, left.Y - right.Y ); } /// @@ -1198,10 +1205,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator -(Vec2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator -( Vec2 value ) { - return new Vec2(-value.X, -value.Y); + return new Vec2( -value.X, -value.Y ); } /// @@ -1210,10 +1217,10 @@ namespace math /// The first vector to multiply. /// The second vector to multiply. /// The multiplication of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator *(Vec2 left, Vec2 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator *( Vec2 left, Vec2 right ) { - return new Vec2(left.X * right.X, left.Y * right.Y); + return new Vec2( left.X * right.X, left.Y * right.Y ); } /// @@ -1222,10 +1229,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator *(float scale, Vec2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator *( float scale, Vec2 value ) { - return new Vec2(value.X * scale, value.Y * scale); + return new Vec2( value.X * scale, value.Y * scale ); } /// @@ -1234,10 +1241,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator *(Vec2 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator *( Vec2 value, float scale ) { - return new Vec2(value.X * scale, value.Y * scale); + return new Vec2( value.X * scale, value.Y * scale ); } /// @@ -1246,10 +1253,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator /(Vec2 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator /( Vec2 value, float scale ) { - return new Vec2(value.X / scale, value.Y / scale); + return new Vec2( value.X / scale, value.Y / scale ); } /// @@ -1258,10 +1265,10 @@ namespace math /// The numerator. /// The value. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator /(float numerator, Vec2 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator /( float numerator, Vec2 value ) { - return new Vec2(numerator / value.X, numerator / value.Y); + return new Vec2( numerator / value.X, numerator / value.Y ); } /// @@ -1270,10 +1277,10 @@ namespace math /// The vector to scale. /// The by. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec2 operator /(Vec2 value, Vec2 by) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec2 operator /( Vec2 value, Vec2 by ) { - return new Vec2(value.X / by.X, value.Y / by.Y); + return new Vec2( value.X / by.X, value.Y / by.Y ); } /// @@ -1282,9 +1289,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Vec2 left, Vec2 right) + public static bool operator ==( Vec2 left, Vec2 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1293,9 +1300,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Vec2 left, Vec2 right) + public static bool operator !=( Vec2 left, Vec2 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1303,9 +1310,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Vec2 value) + public static explicit operator Vec3( Vec2 value ) { - return new Vec3(value, 0.0f); + return new Vec3( value, 0.0f ); } /// @@ -1313,9 +1320,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Vec2 value) + public static explicit operator Vec4( Vec2 value ) { - return new Vec4(value, 0.0f, 0.0f); + return new Vec4( value, 0.0f, 0.0f ); } /// @@ -1326,7 +1333,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1}", X, Y ); } /// @@ -1336,12 +1343,12 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString(format, CultureInfo.CurrentCulture), Y.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1}", X.ToString( format, CultureInfo.CurrentCulture ), Y.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1351,9 +1358,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1}", X, Y); + return string.Format( formatProvider, "X:{0} Y:{1}", X, Y ); } /// @@ -1364,19 +1371,19 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - ToString(formatProvider); + if( format == null ) + ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1}", X.ToString(format, formatProvider), Y.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1}", X.ToString( format, formatProvider ), Y.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1390,10 +1397,10 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Vec2 other) + public bool Equals( Vec2 other ) { - return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance); + return ( (float)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance ); } /// @@ -1403,15 +1410,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Vec2)value); + return Equals( (Vec2)value ); } #if WPFInterop diff --git a/math/Vector3.cs b/math/Vector3.cs index 3f11f06..20120fa 100644 --- a/math/Vector3.cs +++ b/math/Vector3.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -38,9 +38,9 @@ namespace math /// /// Represents a three dimensional mathematical vector. /// - [DataContract( Name = "float3")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "float3" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Vec3 : IEquatable, IFormattable { /// @@ -56,22 +56,22 @@ namespace math /// /// The X unit (1, 0, 0). /// - public static readonly Vec3 UnitX = new Vec3(1.0f, 0.0f, 0.0f); + public static readonly Vec3 UnitX = new Vec3( 1.0f, 0.0f, 0.0f ); /// /// The Y unit (0, 1, 0). /// - public static readonly Vec3 UnitY = new Vec3(0.0f, 1.0f, 0.0f); + public static readonly Vec3 UnitY = new Vec3( 0.0f, 1.0f, 0.0f ); /// /// The Z unit (0, 0, 1). /// - public static readonly Vec3 UnitZ = new Vec3(0.0f, 0.0f, 1.0f); + public static readonly Vec3 UnitZ = new Vec3( 0.0f, 0.0f, 1.0f ); /// /// A with all of its components set to one. /// - public static readonly Vec3 One = new Vec3(1.0f, 1.0f, 1.0f); + public static readonly Vec3 One = new Vec3( 1.0f, 1.0f, 1.0f ); /// /// The X component of the vector. @@ -95,7 +95,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Vec3(float value) + public Vec3( float value ) { X = value; Y = value; @@ -108,7 +108,7 @@ namespace math /// Initial value for the X component of the vector. /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. - public Vec3(float x, float y, float z) + public Vec3( float x, float y, float z ) { X = x; Y = y; @@ -120,7 +120,7 @@ namespace math /// /// A vector containing the values with which to initialize the X and Y components. /// Initial value for the Z component of the vector. - public Vec3(Vec2 value, float z) + public Vec3( Vec2 value, float z ) { X = value.X; Y = value.Y; @@ -133,12 +133,12 @@ namespace math /// The values to assign to the X, Y, and Z components of the vector. This must be an array with three elements. /// Thrown when is null. /// Thrown when contains more or less than three elements. - public Vec3(float[] values) + public Vec3( float[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 3) - throw new ArgumentOutOfRangeException("values", "There must be three and only three input values for Vector3."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 3 ) + throw new ArgumentOutOfRangeException( "values", "There must be three and only three input values for Vector3." ); X = values[0]; Y = values[1]; @@ -150,7 +150,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) + (Z * Z) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) + ( Z * Z ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -164,24 +164,34 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; - case 2: return Z; + case 0: + return X; + case 1: + return Y; + case 2: + return Z; } - throw new ArgumentOutOfRangeException("index", "Indices for Vector3 run from 0 to 2, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Vector3 run from 0 to 2, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - case 2: Z = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Vector3 run from 0 to 2, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + case 2: + Z = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Vector3 run from 0 to 2, inclusive." ); } } } @@ -194,10 +204,10 @@ namespace math /// may be preferred when only the relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public float Length() { - return (float)Math.Sqrt((X * X) + (Y * Y) + (Z * Z)); + return (float)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) ); } /// @@ -208,20 +218,20 @@ namespace math /// This method may be preferred to when only a relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public float LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z); + return ( X * X ) + ( Y * Y ) + ( Z * Z ); } /// /// Converts the vector into a unit vector. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public void Normalize() { float length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { float inv = 1.0f / length; X *= inv; @@ -234,11 +244,11 @@ namespace math /// Raises the exponent for each components. /// /// The exponent. - public void Pow(float exponent) + public void Pow( float exponent ) { - X = (float)Math.Pow(X, exponent); - Y = (float)Math.Pow(Y, exponent); - Z = (float)Math.Pow(Z, exponent); + X = (float)Math.Pow( X, exponent ); + Y = (float)Math.Pow( Y, exponent ); + Z = (float)Math.Pow( Z, exponent ); } /// @@ -256,10 +266,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Add(ref Vec3 left, ref Vec3 right, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Add( ref Vec3 left, ref Vec3 right, out Vec3 result ) { - result = new Vec3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + result = new Vec3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -268,10 +278,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Add(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Add( Vec3 left, Vec3 right ) { - return new Vec3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + return new Vec3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -280,10 +290,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Subtract(ref Vec3 left, ref Vec3 right, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Subtract( ref Vec3 left, ref Vec3 right, out Vec3 result ) { - result = new Vec3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + result = new Vec3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -292,10 +302,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Subtract(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Subtract( Vec3 left, Vec3 right ) { - return new Vec3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + return new Vec3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -304,10 +314,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Multiply(ref Vec3 value, float scale, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Multiply( ref Vec3 value, float scale, out Vec3 result ) { - result = new Vec3(value.X * scale, value.Y * scale, value.Z * scale); + result = new Vec3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -316,22 +326,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Multiply(Vec3 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Multiply( Vec3 value, float scale ) { - return new Vec3(value.X * scale, value.Y * scale, value.Z * scale); + return new Vec3( value.X * scale, value.Y * scale, value.Z * scale ); } - + /// /// Modulates a vector with another by performing component-wise multiplication. /// /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Modulate(ref Vec3 left, ref Vec3 right, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Modulate( ref Vec3 left, ref Vec3 right, out Vec3 result ) { - result = new Vec3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + result = new Vec3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -340,10 +350,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Modulate(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Modulate( Vec3 left, Vec3 right ) { - return new Vec3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + return new Vec3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -352,10 +362,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Divide(ref Vec3 value, float scale, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Divide( ref Vec3 value, float scale, out Vec3 result ) { - result = new Vec3(value.X / scale, value.Y / scale, value.Z / scale); + result = new Vec3( value.X / scale, value.Y / scale, value.Z / scale ); } /// @@ -364,22 +374,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Divide(Vec3 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Divide( Vec3 value, float scale ) { - return new Vec3(value.X / scale, value.Y / scale, value.Z / scale); + return new Vec3( value.X / scale, value.Y / scale, value.Z / scale ); } - + /// /// Demodulates a vector with another by performing component-wise division. /// /// The first vector to demodulate. /// The second vector to demodulate. /// When the method completes, contains the demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Demodulate(ref Vec3 left, ref Vec3 right, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Demodulate( ref Vec3 left, ref Vec3 right, out Vec3 result ) { - result = new Vec3(left.X / right.X, left.Y / right.Y, left.Z / right.Z); + result = new Vec3( left.X / right.X, left.Y / right.Y, left.Z / right.Z ); } /// @@ -388,10 +398,10 @@ namespace math /// The first vector to demodulate. /// The second vector to demodulate. /// The demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Demodulate(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Demodulate( Vec3 left, Vec3 right ) { - return new Vec3(left.X / right.X, left.Y / right.Y, left.Z / right.Z); + return new Vec3( left.X / right.X, left.Y / right.Y, left.Z / right.Z ); } /// @@ -399,10 +409,10 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Negate(ref Vec3 value, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Negate( ref Vec3 value, out Vec3 result ) { - result = new Vec3(-value.X, -value.Y, -value.Z); + result = new Vec3( -value.X, -value.Y, -value.Z ); } /// @@ -410,10 +420,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Negate(Vec3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Negate( Vec3 value ) { - return new Vec3(-value.X, -value.Y, -value.Z); + return new Vec3( -value.X, -value.Y, -value.Z ); } /// @@ -425,12 +435,12 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 3D Cartesian coordinates of the specified point. - public static void Barycentric(ref Vec3 value1, ref Vec3 value2, ref Vec3 value3, float amount1, float amount2, out Vec3 result) + public static void Barycentric( ref Vec3 value1, ref Vec3 value2, ref Vec3 value3, float amount1, float amount2, out Vec3 result ) { result = new Vec3( - (value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)), - (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y)), - (value1.Z + (amount1 * (value2.Z - value1.Z))) + (amount2 * (value3.Z - value1.Z))); + ( value1.X + ( amount1 * ( value2.X - value1.X ) ) ) + ( amount2 * ( value3.X - value1.X ) ), + ( value1.Y + ( amount1 * ( value2.Y - value1.Y ) ) ) + ( amount2 * ( value3.Y - value1.Y ) ), + ( value1.Z + ( amount1 * ( value2.Z - value1.Z ) ) ) + ( amount2 * ( value3.Z - value1.Z ) ) ); } /// @@ -442,10 +452,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 3D Cartesian coordinates of the specified point. - public static Vec3 Barycentric(Vec3 value1, Vec3 value2, Vec3 value3, float amount1, float amount2) + public static Vec3 Barycentric( Vec3 value1, Vec3 value2, Vec3 value3, float amount1, float amount2 ) { Vec3 result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -456,21 +466,21 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Vec3 value, ref Vec3 min, ref Vec3 max, out Vec3 result) + public static void Clamp( ref Vec3 value, ref Vec3 min, ref Vec3 max, out Vec3 result ) { float x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; float y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; float z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; - result = new Vec3(x, y, z); + result = new Vec3( x, y, z ); } /// @@ -480,10 +490,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Vec3 Clamp(Vec3 value, Vec3 min, Vec3 max) + public static Vec3 Clamp( Vec3 value, Vec3 min, Vec3 max ) { Vec3 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -493,12 +503,12 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains he cross product of the two vectors. - public static void Cross(ref Vec3 left, ref Vec3 right, out Vec3 result) + public static void Cross( ref Vec3 left, ref Vec3 right, out Vec3 result ) { result = new Vec3( - (left.Y * right.Z) - (left.Z * right.Y), - (left.Z * right.X) - (left.X * right.Z), - (left.X * right.Y) - (left.Y * right.X)); + ( left.Y * right.Z ) - ( left.Z * right.Y ), + ( left.Z * right.X ) - ( left.X * right.Z ), + ( left.X * right.Y ) - ( left.Y * right.X ) ); } /// @@ -507,10 +517,10 @@ namespace math /// First source vector. /// Second source vector. /// The cross product of the two vectors. - public static Vec3 Cross(Vec3 left, Vec3 right) + public static Vec3 Cross( Vec3 left, Vec3 right ) { Vec3 result; - Cross(ref left, ref right, out result); + Cross( ref left, ref right, out result ); return result; } @@ -524,13 +534,13 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static void Distance(ref Vec3 value1, ref Vec3 value2, out float result) + public static void Distance( ref Vec3 value1, ref Vec3 value2, out float result ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; - result = (float)Math.Sqrt((x * x) + (y * y) + (z * z)); + result = (float)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) ); } /// @@ -543,13 +553,13 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static float Distance(Vec3 value1, Vec3 value2) + public static float Distance( Vec3 value1, Vec3 value2 ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; - return (float)Math.Sqrt((x * x) + (y * y) + (z * z)); + return (float)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) ); } /// @@ -558,20 +568,20 @@ namespace math /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Vec3 value1, ref Vec3 value2, out float result) + public static void DistanceSquared( ref Vec3 value1, ref Vec3 value2, out float result ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; - result = (x * x) + (y * y) + (z * z); + result = ( x * x ) + ( y * y ) + ( z * z ); } /// @@ -580,20 +590,20 @@ namespace math /// The first vector. /// The second vector. /// The squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static float DistanceSquared(Vec3 value1, Vec3 value2) + public static float DistanceSquared( Vec3 value1, Vec3 value2 ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; - return (x * x) + (y * y) + (z * z); + return ( x * x ) + ( y * y ) + ( z * z ); } /// @@ -602,10 +612,10 @@ namespace math /// First source vector. /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Vec3 left, ref Vec3 right, out float result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Dot( ref Vec3 left, ref Vec3 right, out float result ) { - result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); + result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ); } /// @@ -614,10 +624,10 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static float Dot( Vec3 left, Vec3 right ) { - return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z); + return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ); } /// @@ -625,8 +635,8 @@ namespace math /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(ref Vec3 value, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Normalize( ref Vec3 value, out Vec3 result ) { result = value; result.Normalize(); @@ -637,8 +647,8 @@ namespace math /// /// The vector to normalize. /// The normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Normalize(Vec3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Normalize( Vec3 value ) { value.Normalize(); return value; @@ -654,13 +664,13 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Vec3 start, ref Vec3 end, float amount, out Vec3 result) + public static void Lerp( ref Vec3 start, ref Vec3 end, float amount, out Vec3 result ) { - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); } /// @@ -673,12 +683,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Vec3 Lerp(Vec3 start, Vec3 end, float amount) + public static Vec3 Lerp( Vec3 start, Vec3 end, float amount ) { Vec3 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -689,14 +699,14 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Vec3 start, ref Vec3 end, float amount, out Vec3 result) + public static void SmoothStep( ref Vec3 start, ref Vec3 end, float amount, out Vec3 result ) { - amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0f ) ? 1.0f : ( ( amount < 0.0f ) ? 0.0f : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); } /// @@ -706,10 +716,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Vec3 SmoothStep(Vec3 start, Vec3 end, float amount) + public static Vec3 SmoothStep( Vec3 start, Vec3 end, float amount ) { Vec3 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -722,18 +732,18 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Vec3 value1, ref Vec3 tangent1, ref Vec3 value2, ref Vec3 tangent2, float amount, out Vec3 result) + public static void Hermite( ref Vec3 value1, ref Vec3 tangent1, ref Vec3 value2, ref Vec3 tangent2, float amount, out Vec3 result ) { float squared = amount * amount; float cubed = amount * squared; - float part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0f; - float part2 = (-2.0f * cubed) + (3.0f * squared); - float part3 = (cubed - (2.0f * squared)) + amount; + float part1 = ( ( 2.0f * cubed ) - ( 3.0f * squared ) ) + 1.0f; + float part2 = ( -2.0f * cubed ) + ( 3.0f * squared ); + float part3 = ( cubed - ( 2.0f * squared ) ) + amount; float part4 = cubed - squared; - result.X = (((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4); - result.Y = (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4); - result.Z = (((value1.Z * part1) + (value2.Z * part2)) + (tangent1.Z * part3)) + (tangent2.Z * part4); + result.X = ( ( ( value1.X * part1 ) + ( value2.X * part2 ) ) + ( tangent1.X * part3 ) ) + ( tangent2.X * part4 ); + result.Y = ( ( ( value1.Y * part1 ) + ( value2.Y * part2 ) ) + ( tangent1.Y * part3 ) ) + ( tangent2.Y * part4 ); + result.Z = ( ( ( value1.Z * part1 ) + ( value2.Z * part2 ) ) + ( tangent1.Z * part3 ) ) + ( tangent2.Z * part4 ); } /// @@ -745,10 +755,10 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// The result of the Hermite spline interpolation. - public static Vec3 Hermite(Vec3 value1, Vec3 tangent1, Vec3 value2, Vec3 tangent2, float amount) + public static Vec3 Hermite( Vec3 value1, Vec3 tangent1, Vec3 value2, Vec3 tangent2, float amount ) { Vec3 result; - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + Hermite( ref value1, ref tangent1, ref value2, ref tangent2, amount, out result ); return result; } @@ -761,22 +771,22 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Vec3 value1, ref Vec3 value2, ref Vec3 value3, ref Vec3 value4, float amount, out Vec3 result) + public static void CatmullRom( ref Vec3 value1, ref Vec3 value2, ref Vec3 value3, ref Vec3 value4, float amount, out Vec3 result ) { float squared = amount * amount; float cubed = amount * squared; - result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) + - (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) + - ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed)); + result.X = 0.5f * ( ( ( ( 2.0f * value2.X ) + ( ( -value1.X + value3.X ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.X ) - ( 5.0f * value2.X ) ) + ( 4.0f * value3.X ) ) - value4.X ) * squared ) ) + + ( ( ( ( -value1.X + ( 3.0f * value2.X ) ) - ( 3.0f * value3.X ) ) + value4.X ) * cubed ) ); - result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) + - (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) + - ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed)); + result.Y = 0.5f * ( ( ( ( 2.0f * value2.Y ) + ( ( -value1.Y + value3.Y ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.Y ) - ( 5.0f * value2.Y ) ) + ( 4.0f * value3.Y ) ) - value4.Y ) * squared ) ) + + ( ( ( ( -value1.Y + ( 3.0f * value2.Y ) ) - ( 3.0f * value3.Y ) ) + value4.Y ) * cubed ) ); - result.Z = 0.5f * ((((2.0f * value2.Z) + ((-value1.Z + value3.Z) * amount)) + - (((((2.0f * value1.Z) - (5.0f * value2.Z)) + (4.0f * value3.Z)) - value4.Z) * squared)) + - ((((-value1.Z + (3.0f * value2.Z)) - (3.0f * value3.Z)) + value4.Z) * cubed)); + result.Z = 0.5f * ( ( ( ( 2.0f * value2.Z ) + ( ( -value1.Z + value3.Z ) * amount ) ) + + ( ( ( ( ( 2.0f * value1.Z ) - ( 5.0f * value2.Z ) ) + ( 4.0f * value3.Z ) ) - value4.Z ) * squared ) ) + + ( ( ( ( -value1.Z + ( 3.0f * value2.Z ) ) - ( 3.0f * value3.Z ) ) + value4.Z ) * cubed ) ); } /// @@ -788,10 +798,10 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// A vector that is the result of the Catmull-Rom interpolation. - public static Vec3 CatmullRom(Vec3 value1, Vec3 value2, Vec3 value3, Vec3 value4, float amount) + public static Vec3 CatmullRom( Vec3 value1, Vec3 value2, Vec3 value3, Vec3 value4, float amount ) { Vec3 result; - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result); + CatmullRom( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -801,12 +811,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Max(ref Vec3 left, ref Vec3 right, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Max( ref Vec3 left, ref Vec3 right, out Vec3 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; } /// @@ -815,11 +825,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Max(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Max( Vec3 left, Vec3 right ) { Vec3 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -829,12 +839,12 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Min(ref Vec3 left, ref Vec3 right, out Vec3 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Min( ref Vec3 left, ref Vec3 right, out Vec3 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; } /// @@ -843,16 +853,16 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 Min(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 Min( Vec3 left, Vec3 right ) { Vec3 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } /// - /// Projects a 3D vector from object space into screen space. + /// Projects a 3D vector from object space into screen space. /// /// The vector to project. /// The X position of the viewport. @@ -863,16 +873,16 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in screen space. - public static void Project(ref Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vec3 result) + public static void Project( ref Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vec3 result ) { Vec3 v; - TransformCoordinate(ref vector, ref worldViewProjection, out v); + TransformCoordinate( ref vector, ref worldViewProjection, out v ); - result = new Vec3(((1.0f + v.X) * 0.5f * width) + x, ((1.0f - v.Y) * 0.5f * height) + y, (v.Z * (maxZ - minZ)) + minZ); + result = new Vec3( ( ( 1.0f + v.X ) * 0.5f * width ) + x, ( ( 1.0f - v.Y ) * 0.5f * height ) + y, ( v.Z * ( maxZ - minZ ) ) + minZ ); } /// - /// Projects a 3D vector from object space into screen space. + /// Projects a 3D vector from object space into screen space. /// /// The vector to project. /// The X position of the viewport. @@ -883,15 +893,15 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// The vector in screen space. - public static Vec3 Project(Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection) + public static Vec3 Project( Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection ) { Vec3 result; - Project(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result); + Project( ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result ); return result; } /// - /// Projects a 3D vector from screen space into object space. + /// Projects a 3D vector from screen space into object space. /// /// The vector to project. /// The X position of the viewport. @@ -902,21 +912,21 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// When the method completes, contains the vector in object space. - public static void Unproject(ref Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vec3 result) + public static void Unproject( ref Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, ref Matrix worldViewProjection, out Vec3 result ) { Vec3 v = new Vec3(); Matrix matrix; - Matrix.Invert(ref worldViewProjection, out matrix); + Matrix.Invert( ref worldViewProjection, out matrix ); - v.X = (((vector.X - x) / width) * 2.0f) - 1.0f; - v.Y = -((((vector.Y - y) / height) * 2.0f) - 1.0f); - v.Z = (vector.Z - minZ) / (maxZ - minZ); + v.X = ( ( ( vector.X - x ) / width ) * 2.0f ) - 1.0f; + v.Y = -( ( ( ( vector.Y - y ) / height ) * 2.0f ) - 1.0f ); + v.Z = ( vector.Z - minZ ) / ( maxZ - minZ ); - TransformCoordinate(ref v, ref matrix, out result); + TransformCoordinate( ref v, ref matrix, out result ); } /// - /// Projects a 3D vector from screen space into object space. + /// Projects a 3D vector from screen space into object space. /// /// The vector to project. /// The X position of the viewport. @@ -927,42 +937,42 @@ namespace math /// The maximum depth of the viewport. /// The combined world-view-projection matrix. /// The vector in object space. - public static Vec3 Unproject(Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection) + public static Vec3 Unproject( Vec3 vector, float x, float y, float width, float height, float minZ, float maxZ, Matrix worldViewProjection ) { Vec3 result; - Unproject(ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result); + Unproject( ref vector, x, y, width, height, minZ, maxZ, ref worldViewProjection, out result ); return result; } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// When the method completes, contains the reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static void Reflect(ref Vec3 vector, ref Vec3 normal, out Vec3 result) + public static void Reflect( ref Vec3 vector, ref Vec3 normal, out Vec3 result ) { - float dot = (vector.X * normal.X) + (vector.Y * normal.Y) + (vector.Z * normal.Z); + float dot = ( vector.X * normal.X ) + ( vector.Y * normal.Y ) + ( vector.Z * normal.Z ); - result.X = vector.X - ((2.0f * dot) * normal.X); - result.Y = vector.Y - ((2.0f * dot) * normal.Y); - result.Z = vector.Z - ((2.0f * dot) * normal.Z); + result.X = vector.X - ( ( 2.0f * dot ) * normal.X ); + result.Y = vector.Y - ( ( 2.0f * dot ) * normal.Y ); + result.Z = vector.Z - ( ( 2.0f * dot ) * normal.Z ); } /// - /// Returns the reflection of a vector off a surface that has the specified normal. + /// Returns the reflection of a vector off a surface that has the specified normal. /// /// The source vector. /// Normal of the surface. /// The reflected vector. - /// Reflect only gives the direction of a reflection off a surface, it does not determine + /// Reflect only gives the direction of a reflection off a surface, it does not determine /// whether the original vector was close enough to the surface to hit it. - public static Vec3 Reflect(Vec3 vector, Vec3 normal) + public static Vec3 Reflect( Vec3 vector, Vec3 normal ) { Vec3 result; - Reflect(ref vector, ref normal, out result); + Reflect( ref vector, ref normal, out result ); return result; } @@ -982,7 +992,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthogonalize(Vec3[] destination, params Vec3[] source) + public static void Orthogonalize( Vec3[] destination, params Vec3[] source ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -991,20 +1001,20 @@ namespace math //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3 //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Vec3 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= (Vec3.Dot(destination[r], newvector) / Vec3.Dot(destination[r], destination[r])) * destination[r]; + newvector -= ( Vec3.Dot( destination[r], newvector ) / Vec3.Dot( destination[r], destination[r] ) ) * destination[r]; } destination[i] = newvector; @@ -1027,7 +1037,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthonormalize(Vec3[] destination, params Vec3[] source) + public static void Orthonormalize( Vec3[] destination, params Vec3[] source ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -1038,20 +1048,20 @@ namespace math //q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3| //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Vec3 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= Vec3.Dot(destination[r], newvector) * destination[r]; + newvector -= Vec3.Dot( destination[r], newvector ) * destination[r]; } newvector.Normalize(); @@ -1065,7 +1075,7 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Vec3 vector, ref Quaternion rotation, out Vec3 result) + public static void Transform( ref Vec3 vector, ref Quaternion rotation, out Vec3 result ) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1081,9 +1091,9 @@ namespace math float zz = rotation.Z * z; result = new Vec3( - ((vector.X * ((1.0f - yy) - zz)) + (vector.Y * (xy - wz))) + (vector.Z * (xz + wy)), - ((vector.X * (xy + wz)) + (vector.Y * ((1.0f - xx) - zz))) + (vector.Z * (yz - wx)), - ((vector.X * (xz - wy)) + (vector.Y * (yz + wx))) + (vector.Z * ((1.0f - xx) - yy))); + ( ( vector.X * ( ( 1.0f - yy ) - zz ) ) + ( vector.Y * ( xy - wz ) ) ) + ( vector.Z * ( xz + wy ) ), + ( ( vector.X * ( xy + wz ) ) + ( vector.Y * ( ( 1.0f - xx ) - zz ) ) ) + ( vector.Z * ( yz - wx ) ), + ( ( vector.X * ( xz - wy ) ) + ( vector.Y * ( yz + wx ) ) ) + ( vector.Z * ( ( 1.0f - xx ) - yy ) ) ); } /// @@ -1092,10 +1102,10 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// The transformed . - public static Vec3 Transform(Vec3 vector, Quaternion rotation) + public static Vec3 Transform( Vec3 vector, Quaternion rotation ) { Vec3 result; - Transform(ref vector, ref rotation, out result); + Transform( ref vector, ref rotation, out result ); return result; } @@ -1108,14 +1118,14 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Vec3[] source, ref Quaternion rotation, Vec3[] destination) + public static void Transform( Vec3[] source, ref Quaternion rotation, Vec3[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1130,22 +1140,22 @@ namespace math float yz = rotation.Y * z; float zz = rotation.Z * z; - float num1 = ((1.0f - yy) - zz); - float num2 = (xy - wz); - float num3 = (xz + wy); - float num4 = (xy + wz); - float num5 = ((1.0f - xx) - zz); - float num6 = (yz - wx); - float num7 = (xz - wy); - float num8 = (yz + wx); - float num9 = ((1.0f - xx) - yy); + float num1 = ( ( 1.0f - yy ) - zz ); + float num2 = ( xy - wz ); + float num3 = ( xz + wy ); + float num4 = ( xy + wz ); + float num5 = ( ( 1.0f - xx ) - zz ); + float num6 = ( yz - wx ); + float num7 = ( xz - wy ); + float num8 = ( yz + wx ); + float num9 = ( ( 1.0f - xx ) - yy ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { destination[i] = new Vec3( - ((source[i].X * num1) + (source[i].Y * num2)) + (source[i].Z * num3), - ((source[i].X * num4) + (source[i].Y * num5)) + (source[i].Z * num6), - ((source[i].X * num7) + (source[i].Y * num8)) + (source[i].Z * num9)); + ( ( source[i].X * num1 ) + ( source[i].Y * num2 ) ) + ( source[i].Z * num3 ), + ( ( source[i].X * num4 ) + ( source[i].Y * num5 ) ) + ( source[i].Z * num6 ), + ( ( source[i].X * num7 ) + ( source[i].Y * num8 ) ) + ( source[i].Z * num9 ) ); } } @@ -1155,13 +1165,13 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vec3 vector, ref Matrix transform, out Vec4 result) + public static void Transform( ref Vec3 vector, ref Matrix transform, out Vec4 result ) { result = new Vec4( - (vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31) + transform.M41, - (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32) + transform.M42, - (vector.X * transform.M13) + (vector.Y * transform.M23) + (vector.Z * transform.M33) + transform.M43, - (vector.X * transform.M14) + (vector.Y * transform.M24) + (vector.Z * transform.M34) + transform.M44); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + ( vector.Z * transform.M31 ) + transform.M41, + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + ( vector.Z * transform.M32 ) + transform.M42, + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + ( vector.Z * transform.M33 ) + transform.M43, + ( vector.X * transform.M14 ) + ( vector.Y * transform.M24 ) + ( vector.Z * transform.M34 ) + transform.M44 ); } /// @@ -1170,12 +1180,12 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vec3 vector, ref Matrix transform, out Vec3 result) + public static void Transform( ref Vec3 vector, ref Matrix transform, out Vec3 result ) { result = new Vec3( - (vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31) + transform.M41, - (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32) + transform.M42, - (vector.X * transform.M13) + (vector.Y * transform.M23) + (vector.Z * transform.M33) + transform.M43); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + ( vector.Z * transform.M31 ) + transform.M41, + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + ( vector.Z * transform.M32 ) + transform.M42, + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + ( vector.Z * transform.M33 ) + transform.M43 ); } /// @@ -1184,10 +1194,10 @@ namespace math /// The source vector. /// The transformation . /// The transformed . - public static Vec4 Transform(Vec3 vector, Matrix transform) + public static Vec4 Transform( Vec3 vector, Matrix transform ) { Vec4 result; - Transform(ref vector, ref transform, out result); + Transform( ref vector, ref transform, out result ); return result; } @@ -1199,18 +1209,18 @@ namespace math /// The array for which the transformed vectors are stored. /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Vec3[] source, ref Matrix transform, Vec4[] destination) + public static void Transform( Vec3[] source, ref Matrix transform, Vec4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - Transform(ref source[i], ref transform, out destination[i]); + Transform( ref source[i], ref transform, out destination[i] ); } } @@ -1227,13 +1237,13 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(ref Vec3 coordinate, ref Matrix transform, out Vec3 result) + public static void TransformCoordinate( ref Vec3 coordinate, ref Matrix transform, out Vec3 result ) { - var invW = 1f / ((coordinate.X * transform.M14) + (coordinate.Y * transform.M24) + (coordinate.Z * transform.M34) + transform.M44); + var invW = 1f / ( ( coordinate.X * transform.M14 ) + ( coordinate.Y * transform.M24 ) + ( coordinate.Z * transform.M34 ) + transform.M44 ); result = new Vec3( - ((coordinate.X * transform.M11) + (coordinate.Y * transform.M21) + (coordinate.Z * transform.M31) + transform.M41) * invW, - ((coordinate.X * transform.M12) + (coordinate.Y * transform.M22) + (coordinate.Z * transform.M32) + transform.M42) * invW, - ((coordinate.X * transform.M13) + (coordinate.Y * transform.M23) + (coordinate.Z * transform.M33) + transform.M43) * invW); + ( ( coordinate.X * transform.M11 ) + ( coordinate.Y * transform.M21 ) + ( coordinate.Z * transform.M31 ) + transform.M41 ) * invW, + ( ( coordinate.X * transform.M12 ) + ( coordinate.Y * transform.M22 ) + ( coordinate.Z * transform.M32 ) + transform.M42 ) * invW, + ( ( coordinate.X * transform.M13 ) + ( coordinate.Y * transform.M23 ) + ( coordinate.Z * transform.M33 ) + transform.M43 ) * invW ); } /// @@ -1249,10 +1259,10 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static Vec3 TransformCoordinate(Vec3 coordinate, Matrix transform) + public static Vec3 TransformCoordinate( Vec3 coordinate, Matrix transform ) { Vec3 result; - TransformCoordinate(ref coordinate, ref transform, out result); + TransformCoordinate( ref coordinate, ref transform, out result ); return result; } @@ -1272,18 +1282,18 @@ namespace math /// therefore makes the vector homogeneous. The homogeneous vector is often prefered when working /// with coordinates as the w component can safely be ignored. /// - public static void TransformCoordinate(Vec3[] source, ref Matrix transform, Vec3[] destination) + public static void TransformCoordinate( Vec3[] source, ref Matrix transform, Vec3[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformCoordinate(ref source[i], ref transform, out destination[i]); + TransformCoordinate( ref source[i], ref transform, out destination[i] ); } } @@ -1300,12 +1310,12 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(ref Vec3 normal, ref Matrix transform, out Vec3 result) + public static void TransformNormal( ref Vec3 normal, ref Matrix transform, out Vec3 result ) { result = new Vec3( - (normal.X * transform.M11) + (normal.Y * transform.M21) + (normal.Z * transform.M31), - (normal.X * transform.M12) + (normal.Y * transform.M22) + (normal.Z * transform.M32), - (normal.X * transform.M13) + (normal.Y * transform.M23) + (normal.Z * transform.M33)); + ( normal.X * transform.M11 ) + ( normal.Y * transform.M21 ) + ( normal.Z * transform.M31 ), + ( normal.X * transform.M12 ) + ( normal.Y * transform.M22 ) + ( normal.Z * transform.M32 ), + ( normal.X * transform.M13 ) + ( normal.Y * transform.M23 ) + ( normal.Z * transform.M33 ) ); } /// @@ -1321,10 +1331,10 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static Vec3 TransformNormal(Vec3 normal, Matrix transform) + public static Vec3 TransformNormal( Vec3 normal, Matrix transform ) { Vec3 result; - TransformNormal(ref normal, ref transform, out result); + TransformNormal( ref normal, ref transform, out result ); return result; } @@ -1344,18 +1354,18 @@ namespace math /// apply. This is often prefered for normal vectors as normals purely represent direction /// rather than location because normal vectors should not be translated. /// - public static void TransformNormal(Vec3[] source, ref Matrix transform, Vec3[] destination) + public static void TransformNormal( Vec3[] source, ref Matrix transform, Vec3[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - TransformNormal(ref source[i], ref transform, out destination[i]); + TransformNormal( ref source[i], ref transform, out destination[i] ); } } @@ -1364,21 +1374,21 @@ namespace math /// /// The input rotation as quaternion /// The equivation yaw/pitch/roll rotation - public static Vec3 RotationYawPitchRoll(Quaternion quaternion) + public static Vec3 RotationYawPitchRoll( Quaternion quaternion ) { Vec3 yawPitchRoll; - Quaternion.RotationYawPitchRoll(ref quaternion, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z); + Quaternion.RotationYawPitchRoll( ref quaternion, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z ); return yawPitchRoll; } /// - /// Calculate the yaw/pitch/roll rotation equivalent to the provided quaterion. + /// Calculate the yaw/pitch/roll rotation equivalent to the provided quaterion. /// /// The input rotation as quaternion /// The equivation yaw/pitch/roll rotation - public static void RotationYawPitchRoll(ref Quaternion quaternion, out Vec3 yawPitchRoll) + public static void RotationYawPitchRoll( ref Quaternion quaternion, out Vec3 yawPitchRoll ) { - Quaternion.RotationYawPitchRoll(ref quaternion, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z); + Quaternion.RotationYawPitchRoll( ref quaternion, out yawPitchRoll.X, out yawPitchRoll.Y, out yawPitchRoll.Z ); } /// @@ -1387,10 +1397,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator +(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator +( Vec3 left, Vec3 right ) { - return new Vec3(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + return new Vec3( left.X + right.X, left.Y + right.Y, left.Z + right.Z ); } /// @@ -1398,8 +1408,8 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator +(Vec3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator +( Vec3 value ) { return value; } @@ -1410,10 +1420,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator -(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator -( Vec3 left, Vec3 right ) { - return new Vec3(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + return new Vec3( left.X - right.X, left.Y - right.Y, left.Z - right.Z ); } /// @@ -1421,10 +1431,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator -(Vec3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator -( Vec3 value ) { - return new Vec3(-value.X, -value.Y, -value.Z); + return new Vec3( -value.X, -value.Y, -value.Z ); } /// @@ -1433,10 +1443,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator *(float scale, Vec3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator *( float scale, Vec3 value ) { - return new Vec3(value.X * scale, value.Y * scale, value.Z * scale); + return new Vec3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -1445,10 +1455,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator *(Vec3 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator *( Vec3 value, float scale ) { - return new Vec3(value.X * scale, value.Y * scale, value.Z * scale); + return new Vec3( value.X * scale, value.Y * scale, value.Z * scale ); } /// @@ -1457,10 +1467,10 @@ namespace math /// The first vector to multiply. /// The second vector to multiply. /// The multiplication of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator *(Vec3 left, Vec3 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator *( Vec3 left, Vec3 right ) { - return new Vec3(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + return new Vec3( left.X * right.X, left.Y * right.Y, left.Z * right.Z ); } /// @@ -1469,10 +1479,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The vector offset. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator +(Vec3 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator +( Vec3 value, float scale ) { - return new Vec3(value.X + scale, value.Y + scale, value.Z + scale); + return new Vec3( value.X + scale, value.Y + scale, value.Z + scale ); } /// @@ -1481,10 +1491,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The vector offset. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator -(Vec3 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator -( Vec3 value, float scale ) { - return new Vec3(value.X - scale, value.Y - scale, value.Z - scale); + return new Vec3( value.X - scale, value.Y - scale, value.Z - scale ); } /// @@ -1493,10 +1503,10 @@ namespace math /// The numerator. /// The value. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator /(float numerator, Vec3 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator /( float numerator, Vec3 value ) { - return new Vec3(numerator / value.X, numerator / value.Y, numerator / value.Z); + return new Vec3( numerator / value.X, numerator / value.Y, numerator / value.Z ); } /// @@ -1505,10 +1515,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator /(Vec3 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator /( Vec3 value, float scale ) { - return new Vec3(value.X / scale, value.Y / scale, value.Z / scale); + return new Vec3( value.X / scale, value.Y / scale, value.Z / scale ); } /// @@ -1517,10 +1527,10 @@ namespace math /// The vector to scale. /// The by. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec3 operator /(Vec3 value, Vec3 by) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec3 operator /( Vec3 value, Vec3 by ) { - return new Vec3(value.X / by.X, value.Y / by.Y, value.Z / by.Z); + return new Vec3( value.X / by.X, value.Y / by.Y, value.Z / by.Z ); } /// @@ -1529,9 +1539,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Vec3 left, Vec3 right) + public static bool operator ==( Vec3 left, Vec3 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1540,9 +1550,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Vec3 left, Vec3 right) + public static bool operator !=( Vec3 left, Vec3 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1550,9 +1560,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Vec3 value) + public static explicit operator Vec2( Vec3 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } /// @@ -1560,9 +1570,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec4(Vec3 value) + public static explicit operator Vec4( Vec3 value ) { - return new Vec4(value, 0.0f); + return new Vec4( value, 0.0f ); } /// @@ -1572,9 +1582,9 @@ namespace math /// The right vector. /// The epsilon. /// true if left and right are near another 3D, false otherwise - public static bool NearEqual(Vec3 left, Vec3 right, Vec3 epsilon) + public static bool NearEqual( Vec3 left, Vec3 right, Vec3 epsilon ) { - return NearEqual(ref left, ref right, ref epsilon); + return NearEqual( ref left, ref right, ref epsilon ); } /// @@ -1584,11 +1594,11 @@ namespace math /// The right vector. /// The epsilon. /// true if left and right are near another 3D, false otherwise - public static bool NearEqual(ref Vec3 left, ref Vec3 right, ref Vec3 epsilon) + public static bool NearEqual( ref Vec3 left, ref Vec3 right, ref Vec3 epsilon ) { - return MathUtil.WithinEpsilon(left.X, right.X, epsilon.X) && - MathUtil.WithinEpsilon(left.Y, right.Y, epsilon.Y) && - MathUtil.WithinEpsilon(left.Z, right.Z, epsilon.Z); + return MathUtil.WithinEpsilon( left.X, right.X, epsilon.X ) && + MathUtil.WithinEpsilon( left.Y, right.Y, epsilon.Y ) && + MathUtil.WithinEpsilon( left.Z, right.Z, epsilon.Z ); } /// @@ -1599,7 +1609,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z ); } /// @@ -1609,13 +1619,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), Z.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1625,9 +1635,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z ); } /// @@ -1638,20 +1648,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - return ToString(formatProvider); + if( format == null ) + return ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1665,11 +1675,11 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Vec3 other) + public bool Equals( Vec3 other ) { - return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Z - Z) < MathUtil.ZeroTolerance); + return ( (float)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Z - Z ) < MathUtil.ZeroTolerance ); } /// @@ -1679,15 +1689,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Vec3)value); + return Equals( (Vec3)value ); } #if WPFInterop diff --git a/math/Vector4.cs b/math/Vector4.cs index 2a77438..c28968c 100644 --- a/math/Vector4.cs +++ b/math/Vector4.cs @@ -7,17 +7,17 @@ // ----------------------------------------------------------------------------- /* * 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 @@ -37,9 +37,9 @@ namespace math /// /// Represents a four dimensional mathematical vector. /// - [DataContract( Name = "float4")] - [DataStyle(DataStyle.Compact)] - [StructLayout(LayoutKind.Sequential, Pack = 4)] + [DataContract( Name = "float4" )] + [DataStyle( DataStyle.Compact )] + [StructLayout( LayoutKind.Sequential, Pack = 4 )] public struct Vec4 : IEquatable, IFormattable { /// @@ -55,27 +55,27 @@ namespace math /// /// The X unit (1, 0, 0, 0). /// - public static readonly Vec4 UnitX = new Vec4(1.0f, 0.0f, 0.0f, 0.0f); + public static readonly Vec4 UnitX = new Vec4( 1.0f, 0.0f, 0.0f, 0.0f ); /// /// The Y unit (0, 1, 0, 0). /// - public static readonly Vec4 UnitY = new Vec4(0.0f, 1.0f, 0.0f, 0.0f); + public static readonly Vec4 UnitY = new Vec4( 0.0f, 1.0f, 0.0f, 0.0f ); /// /// The Z unit (0, 0, 1, 0). /// - public static readonly Vec4 UnitZ = new Vec4(0.0f, 0.0f, 1.0f, 0.0f); + public static readonly Vec4 UnitZ = new Vec4( 0.0f, 0.0f, 1.0f, 0.0f ); /// /// The W unit (0, 0, 0, 1). /// - public static readonly Vec4 UnitW = new Vec4(0.0f, 0.0f, 0.0f, 1.0f); + public static readonly Vec4 UnitW = new Vec4( 0.0f, 0.0f, 0.0f, 1.0f ); /// /// A with all of its components set to one. /// - public static readonly Vec4 One = new Vec4(1.0f, 1.0f, 1.0f, 1.0f); + public static readonly Vec4 One = new Vec4( 1.0f, 1.0f, 1.0f, 1.0f ); /// /// The X component of the vector. @@ -105,7 +105,7 @@ namespace math /// Initializes a new instance of the struct. /// /// The value that will be assigned to all components. - public Vec4(float value) + public Vec4( float value ) { X = value; Y = value; @@ -120,7 +120,7 @@ namespace math /// Initial value for the Y component of the vector. /// Initial value for the Z component of the vector. /// Initial value for the W component of the vector. - public Vec4(float x, float y, float z, float w) + public Vec4( float x, float y, float z, float w ) { X = x; Y = y; @@ -133,7 +133,7 @@ namespace math /// /// A vector containing the values with which to initialize the X, Y, and Z components. /// Initial value for the W component of the vector. - public Vec4(Vec3 value, float w) + public Vec4( Vec3 value, float w ) { X = value.X; Y = value.Y; @@ -147,7 +147,7 @@ namespace math /// A vector containing the values with which to initialize the X and Y components. /// Initial value for the Z component of the vector. /// Initial value for the W component of the vector. - public Vec4(Vec2 value, float z, float w) + public Vec4( Vec2 value, float z, float w ) { X = value.X; Y = value.Y; @@ -161,12 +161,12 @@ namespace math /// The values to assign to the X, Y, Z, and W components of the vector. This must be an array with four elements. /// Thrown when is null. /// Thrown when contains more or less than four elements. - public Vec4(float[] values) + public Vec4( float[] values ) { - if (values == null) - throw new ArgumentNullException("values"); - if (values.Length != 4) - throw new ArgumentOutOfRangeException("values", "There must be four and only four input values for Vector4."); + if( values == null ) + throw new ArgumentNullException( "values" ); + if( values.Length != 4 ) + throw new ArgumentOutOfRangeException( "values", "There must be four and only four input values for Vector4." ); X = values[0]; Y = values[1]; @@ -179,7 +179,7 @@ namespace math /// public bool IsNormalized { - get { return Math.Abs((X * X) + (Y * Y) + (Z * Z) + (W * W) - 1f) < MathUtil.ZeroTolerance; } + get { return Math.Abs( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) - 1f ) < MathUtil.ZeroTolerance; } } /// @@ -193,26 +193,39 @@ namespace math { get { - switch (index) + switch( index ) { - case 0: return X; - case 1: return Y; - case 2: return Z; - case 3: return W; + case 0: + return X; + case 1: + return Y; + case 2: + return Z; + case 3: + return W; } - throw new ArgumentOutOfRangeException("index", "Indices for Vector4 run from 0 to 3, inclusive."); + throw new ArgumentOutOfRangeException( "index", "Indices for Vector4 run from 0 to 3, inclusive." ); } set { - switch (index) + switch( index ) { - case 0: X = value; break; - case 1: Y = value; break; - case 2: Z = value; break; - case 3: W = value; break; - default: throw new ArgumentOutOfRangeException("index", "Indices for Vector4 run from 0 to 3, inclusive."); + case 0: + X = value; + break; + case 1: + Y = value; + break; + case 2: + Z = value; + break; + case 3: + W = value; + break; + default: + throw new ArgumentOutOfRangeException( "index", "Indices for Vector4 run from 0 to 3, inclusive." ); } } } @@ -225,10 +238,10 @@ namespace math /// may be preferred when only the relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public float Length() { - return (float)Math.Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W)); + return (float)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ) ); } /// @@ -239,20 +252,20 @@ namespace math /// This method may be preferred to when only a relative length is needed /// and speed is of the essence. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public float LengthSquared() { - return (X * X) + (Y * Y) + (Z * Z) + (W * W); + return ( X * X ) + ( Y * Y ) + ( Z * Z ) + ( W * W ); } /// /// Converts the vector into a unit vector. /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl( MethodImplOptions.AggressiveInlining )] public void Normalize() { float length = Length(); - if (length > MathUtil.ZeroTolerance) + if( length > MathUtil.ZeroTolerance ) { float inverse = 1.0f / length; X *= inverse; @@ -266,12 +279,12 @@ namespace math /// Raises the exponent for each components. /// /// The exponent. - public void Pow(float exponent) + public void Pow( float exponent ) { - X = (float)Math.Pow(X, exponent); - Y = (float)Math.Pow(Y, exponent); - Z = (float)Math.Pow(Z, exponent); - W = (float)Math.Pow(W, exponent); + X = (float)Math.Pow( X, exponent ); + Y = (float)Math.Pow( Y, exponent ); + Z = (float)Math.Pow( Z, exponent ); + W = (float)Math.Pow( W, exponent ); } /// @@ -289,10 +302,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// When the method completes, contains the sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Add(ref Vec4 left, ref Vec4 right, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Add( ref Vec4 left, ref Vec4 right, out Vec4 result ) { - result = new Vec4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + result = new Vec4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -301,10 +314,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Add(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Add( Vec4 left, Vec4 right ) { - return new Vec4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new Vec4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -313,10 +326,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// When the method completes, contains the difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Subtract(ref Vec4 left, ref Vec4 right, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Subtract( ref Vec4 left, ref Vec4 right, out Vec4 result ) { - result = new Vec4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + result = new Vec4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -325,10 +338,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Subtract(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Subtract( Vec4 left, Vec4 right ) { - return new Vec4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new Vec4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -337,10 +350,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Multiply(ref Vec4 value, float scale, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Multiply( ref Vec4 value, float scale, out Vec4 result ) { - result = new Vec4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + result = new Vec4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -349,10 +362,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Multiply(Vec4 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Multiply( Vec4 value, float scale ) { - return new Vec4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Vec4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -361,10 +374,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// When the method completes, contains the modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Modulate(ref Vec4 left, ref Vec4 right, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Modulate( ref Vec4 left, ref Vec4 right, out Vec4 result ) { - result = new Vec4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + result = new Vec4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -373,10 +386,10 @@ namespace math /// The first vector to modulate. /// The second vector to modulate. /// The modulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Modulate(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Modulate( Vec4 left, Vec4 right ) { - return new Vec4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + return new Vec4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -385,10 +398,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// When the method completes, contains the scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Divide(ref Vec4 value, float scale, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Divide( ref Vec4 value, float scale, out Vec4 result ) { - result = new Vec4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + result = new Vec4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -397,22 +410,22 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Divide(Vec4 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Divide( Vec4 value, float scale ) { - return new Vec4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new Vec4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } - + /// /// Demodulates a vector with another by performing component-wise division. /// /// The first vector to demodulate. /// The second vector to demodulate. /// When the method completes, contains the demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Demodulate(ref Vec4 left, ref Vec4 right, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Demodulate( ref Vec4 left, ref Vec4 right, out Vec4 result ) { - result = new Vec4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); + result = new Vec4( left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W ); } /// @@ -421,10 +434,10 @@ namespace math /// The first vector to demodulate. /// The second vector to demodulate. /// The demodulated vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Demodulate(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Demodulate( Vec4 left, Vec4 right ) { - return new Vec4(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); + return new Vec4( left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W ); } /// @@ -432,10 +445,10 @@ namespace math /// /// The vector to negate. /// When the method completes, contains a vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Negate(ref Vec4 value, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Negate( ref Vec4 value, out Vec4 result ) { - result = new Vec4(-value.X, -value.Y, -value.Z, -value.W); + result = new Vec4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -443,10 +456,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Negate(Vec4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Negate( Vec4 value ) { - return new Vec4(-value.X, -value.Y, -value.Z, -value.W); + return new Vec4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -458,13 +471,13 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// When the method completes, contains the 4D Cartesian coordinates of the specified point. - public static void Barycentric(ref Vec4 value1, ref Vec4 value2, ref Vec4 value3, float amount1, float amount2, out Vec4 result) + public static void Barycentric( ref Vec4 value1, ref Vec4 value2, ref Vec4 value3, float amount1, float amount2, out Vec4 result ) { result = new Vec4( - (value1.X + (amount1 * (value2.X - value1.X))) + (amount2 * (value3.X - value1.X)), - (value1.Y + (amount1 * (value2.Y - value1.Y))) + (amount2 * (value3.Y - value1.Y)), - (value1.Z + (amount1 * (value2.Z - value1.Z))) + (amount2 * (value3.Z - value1.Z)), - (value1.W + (amount1 * (value2.W - value1.W))) + (amount2 * (value3.W - value1.W))); + ( value1.X + ( amount1 * ( value2.X - value1.X ) ) ) + ( amount2 * ( value3.X - value1.X ) ), + ( value1.Y + ( amount1 * ( value2.Y - value1.Y ) ) ) + ( amount2 * ( value3.Y - value1.Y ) ), + ( value1.Z + ( amount1 * ( value2.Z - value1.Z ) ) ) + ( amount2 * ( value3.Z - value1.Z ) ), + ( value1.W + ( amount1 * ( value2.W - value1.W ) ) ) + ( amount2 * ( value3.W - value1.W ) ) ); } /// @@ -476,10 +489,10 @@ namespace math /// Barycentric coordinate b2, which expresses the weighting factor toward vertex 2 (specified in ). /// Barycentric coordinate b3, which expresses the weighting factor toward vertex 3 (specified in ). /// A new containing the 4D Cartesian coordinates of the specified point. - public static Vec4 Barycentric(Vec4 value1, Vec4 value2, Vec4 value3, float amount1, float amount2) + public static Vec4 Barycentric( Vec4 value1, Vec4 value2, Vec4 value3, float amount1, float amount2 ) { Vec4 result; - Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result); + Barycentric( ref value1, ref value2, ref value3, amount1, amount2, out result ); return result; } @@ -490,25 +503,25 @@ namespace math /// The minimum value. /// The maximum value. /// When the method completes, contains the clamped value. - public static void Clamp(ref Vec4 value, ref Vec4 min, ref Vec4 max, out Vec4 result) + public static void Clamp( ref Vec4 value, ref Vec4 min, ref Vec4 max, out Vec4 result ) { float x = value.X; - x = (x > max.X) ? max.X : x; - x = (x < min.X) ? min.X : x; + x = ( x > max.X ) ? max.X : x; + x = ( x < min.X ) ? min.X : x; float y = value.Y; - y = (y > max.Y) ? max.Y : y; - y = (y < min.Y) ? min.Y : y; + y = ( y > max.Y ) ? max.Y : y; + y = ( y < min.Y ) ? min.Y : y; float z = value.Z; - z = (z > max.Z) ? max.Z : z; - z = (z < min.Z) ? min.Z : z; + z = ( z > max.Z ) ? max.Z : z; + z = ( z < min.Z ) ? min.Z : z; float w = value.W; - w = (w > max.W) ? max.W : w; - w = (w < min.W) ? min.W : w; + w = ( w > max.W ) ? max.W : w; + w = ( w < min.W ) ? min.W : w; - result = new Vec4(x, y, z, w); + result = new Vec4( x, y, z, w ); } /// @@ -518,10 +531,10 @@ namespace math /// The minimum value. /// The maximum value. /// The clamped value. - public static Vec4 Clamp(Vec4 value, Vec4 min, Vec4 max) + public static Vec4 Clamp( Vec4 value, Vec4 min, Vec4 max ) { Vec4 result; - Clamp(ref value, ref min, ref max, out result); + Clamp( ref value, ref min, ref max, out result ); return result; } @@ -535,14 +548,14 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static void Distance(ref Vec4 value1, ref Vec4 value2, out float result) + public static void Distance( ref Vec4 value1, ref Vec4 value2, out float result ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; float w = value1.W - value2.W; - result = (float)Math.Sqrt((x * x) + (y * y) + (z * z) + (w * w)); + result = (float)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ) ); } /// @@ -555,14 +568,14 @@ namespace math /// may be preferred when only the relative distance is needed /// and speed is of the essence. /// - public static float Distance(Vec4 value1, Vec4 value2) + public static float Distance( Vec4 value1, Vec4 value2 ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; float w = value1.W - value2.W; - return (float)Math.Sqrt((x * x) + (y * y) + (z * z) + (w * w)); + return (float)Math.Sqrt( ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ) ); } /// @@ -571,21 +584,21 @@ namespace math /// The first vector. /// The second vector. /// When the method completes, contains the squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static void DistanceSquared(ref Vec4 value1, ref Vec4 value2, out float result) + public static void DistanceSquared( ref Vec4 value1, ref Vec4 value2, out float result ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; float w = value1.W - value2.W; - result = (x * x) + (y * y) + (z * z) + (w * w); + result = ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ); } /// @@ -594,21 +607,21 @@ namespace math /// The first vector. /// The second vector. /// The squared distance between the two vectors. - /// Distance squared is the value before taking the square root. - /// Distance squared can often be used in place of distance if relative comparisons are being made. - /// For example, consider three points A, B, and C. To determine whether B or C is further from A, - /// compare the distance between A and B to the distance between A and C. Calculating the two distances - /// involves two square roots, which are computationally expensive. However, using distance squared + /// Distance squared is the value before taking the square root. + /// Distance squared can often be used in place of distance if relative comparisons are being made. + /// For example, consider three points A, B, and C. To determine whether B or C is further from A, + /// compare the distance between A and B to the distance between A and C. Calculating the two distances + /// involves two square roots, which are computationally expensive. However, using distance squared /// provides the same information and avoids calculating two square roots. /// - public static float DistanceSquared(Vec4 value1, Vec4 value2) + public static float DistanceSquared( Vec4 value1, Vec4 value2 ) { float x = value1.X - value2.X; float y = value1.Y - value2.Y; float z = value1.Z - value2.Z; float w = value1.W - value2.W; - return (x * x) + (y * y) + (z * z) + (w * w); + return ( x * x ) + ( y * y ) + ( z * z ) + ( w * w ); } /// @@ -617,10 +630,10 @@ namespace math /// First source vector /// Second source vector. /// When the method completes, contains the dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Dot(ref Vec4 left, ref Vec4 right, out float result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Dot( ref Vec4 left, ref Vec4 right, out float result ) { - result = (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W); + result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ) + ( left.W * right.W ); } /// @@ -629,10 +642,10 @@ namespace math /// First source vector. /// Second source vector. /// The dot product of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static float Dot( Vec4 left, Vec4 right ) { - return (left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W); + return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z ) + ( left.W * right.W ); } /// @@ -640,8 +653,8 @@ namespace math /// /// The vector to normalize. /// When the method completes, contains the normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Normalize(ref Vec4 value, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Normalize( ref Vec4 value, out Vec4 result ) { Vec4 temp = value; result = temp; @@ -653,8 +666,8 @@ namespace math /// /// The vector to normalize. /// The normalized vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Normalize(Vec4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Normalize( Vec4 value ) { value.Normalize(); return value; @@ -670,14 +683,14 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static void Lerp(ref Vec4 start, ref Vec4 end, float amount, out Vec4 result) + public static void Lerp( ref Vec4 start, ref Vec4 end, float amount, out Vec4 result ) { - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); - result.W = start.W + ((end.W - start.W) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); + result.W = start.W + ( ( end.W - start.W ) * amount ); } /// @@ -690,12 +703,12 @@ namespace math /// /// This method performs the linear interpolation based on the following formula. /// start + (end - start) * amount - /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. + /// Passing a value of 0 will cause to be returned; a value of 1 will cause to be returned. /// - public static Vec4 Lerp(Vec4 start, Vec4 end, float amount) + public static Vec4 Lerp( Vec4 start, Vec4 end, float amount ) { Vec4 result; - Lerp(ref start, ref end, amount, out result); + Lerp( ref start, ref end, amount, out result ); return result; } @@ -706,15 +719,15 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// When the method completes, contains the cubic interpolation of the two vectors. - public static void SmoothStep(ref Vec4 start, ref Vec4 end, float amount, out Vec4 result) + public static void SmoothStep( ref Vec4 start, ref Vec4 end, float amount, out Vec4 result ) { - amount = (amount > 1.0f) ? 1.0f : ((amount < 0.0f) ? 0.0f : amount); - amount = (amount * amount) * (3.0f - (2.0f * amount)); + amount = ( amount > 1.0f ) ? 1.0f : ( ( amount < 0.0f ) ? 0.0f : amount ); + amount = ( amount * amount ) * ( 3.0f - ( 2.0f * amount ) ); - result.X = start.X + ((end.X - start.X) * amount); - result.Y = start.Y + ((end.Y - start.Y) * amount); - result.Z = start.Z + ((end.Z - start.Z) * amount); - result.W = start.W + ((end.W - start.W) * amount); + result.X = start.X + ( ( end.X - start.X ) * amount ); + result.Y = start.Y + ( ( end.Y - start.Y ) * amount ); + result.Z = start.Z + ( ( end.Z - start.Z ) * amount ); + result.W = start.W + ( ( end.W - start.W ) * amount ); } /// @@ -724,10 +737,10 @@ namespace math /// End vector. /// Value between 0 and 1 indicating the weight of . /// The cubic interpolation of the two vectors. - public static Vec4 SmoothStep(Vec4 start, Vec4 end, float amount) + public static Vec4 SmoothStep( Vec4 start, Vec4 end, float amount ) { Vec4 result; - SmoothStep(ref start, ref end, amount, out result); + SmoothStep( ref start, ref end, amount, out result ); return result; } @@ -740,20 +753,20 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// When the method completes, contains the result of the Hermite spline interpolation. - public static void Hermite(ref Vec4 value1, ref Vec4 tangent1, ref Vec4 value2, ref Vec4 tangent2, float amount, out Vec4 result) + public static void Hermite( ref Vec4 value1, ref Vec4 tangent1, ref Vec4 value2, ref Vec4 tangent2, float amount, out Vec4 result ) { float squared = amount * amount; float cubed = amount * squared; - float part1 = ((2.0f * cubed) - (3.0f * squared)) + 1.0f; - float part2 = (-2.0f * cubed) + (3.0f * squared); - float part3 = (cubed - (2.0f * squared)) + amount; + float part1 = ( ( 2.0f * cubed ) - ( 3.0f * squared ) ) + 1.0f; + float part2 = ( -2.0f * cubed ) + ( 3.0f * squared ); + float part3 = ( cubed - ( 2.0f * squared ) ) + amount; float part4 = cubed - squared; result = new Vec4( - (((value1.X * part1) + (value2.X * part2)) + (tangent1.X * part3)) + (tangent2.X * part4), - (((value1.Y * part1) + (value2.Y * part2)) + (tangent1.Y * part3)) + (tangent2.Y * part4), - (((value1.Z * part1) + (value2.Z * part2)) + (tangent1.Z * part3)) + (tangent2.Z * part4), - (((value1.W * part1) + (value2.W * part2)) + (tangent1.W * part3)) + (tangent2.W * part4)); + ( ( ( value1.X * part1 ) + ( value2.X * part2 ) ) + ( tangent1.X * part3 ) ) + ( tangent2.X * part4 ), + ( ( ( value1.Y * part1 ) + ( value2.Y * part2 ) ) + ( tangent1.Y * part3 ) ) + ( tangent2.Y * part4 ), + ( ( ( value1.Z * part1 ) + ( value2.Z * part2 ) ) + ( tangent1.Z * part3 ) ) + ( tangent2.Z * part4 ), + ( ( ( value1.W * part1 ) + ( value2.W * part2 ) ) + ( tangent1.W * part3 ) ) + ( tangent2.W * part4 ) ); } /// @@ -765,10 +778,10 @@ namespace math /// Second source tangent vector. /// Weighting factor. /// The result of the Hermite spline interpolation. - public static Vec4 Hermite(Vec4 value1, Vec4 tangent1, Vec4 value2, Vec4 tangent2, float amount) + public static Vec4 Hermite( Vec4 value1, Vec4 tangent1, Vec4 value2, Vec4 tangent2, float amount ) { Vec4 result; - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + Hermite( ref value1, ref tangent1, ref value2, ref tangent2, amount, out result ); return result; } @@ -781,15 +794,15 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// When the method completes, contains the result of the Catmull-Rom interpolation. - public static void CatmullRom(ref Vec4 value1, ref Vec4 value2, ref Vec4 value3, ref Vec4 value4, float amount, out Vec4 result) + public static void CatmullRom( ref Vec4 value1, ref Vec4 value2, ref Vec4 value3, ref Vec4 value4, float amount, out Vec4 result ) { float squared = amount * amount; float cubed = amount * squared; - result.X = 0.5f * ((((2.0f * value2.X) + ((-value1.X + value3.X) * amount)) + (((((2.0f * value1.X) - (5.0f * value2.X)) + (4.0f * value3.X)) - value4.X) * squared)) + ((((-value1.X + (3.0f * value2.X)) - (3.0f * value3.X)) + value4.X) * cubed)); - result.Y = 0.5f * ((((2.0f * value2.Y) + ((-value1.Y + value3.Y) * amount)) + (((((2.0f * value1.Y) - (5.0f * value2.Y)) + (4.0f * value3.Y)) - value4.Y) * squared)) + ((((-value1.Y + (3.0f * value2.Y)) - (3.0f * value3.Y)) + value4.Y) * cubed)); - result.Z = 0.5f * ((((2.0f * value2.Z) + ((-value1.Z + value3.Z) * amount)) + (((((2.0f * value1.Z) - (5.0f * value2.Z)) + (4.0f * value3.Z)) - value4.Z) * squared)) + ((((-value1.Z + (3.0f * value2.Z)) - (3.0f * value3.Z)) + value4.Z) * cubed)); - result.W = 0.5f * ((((2.0f * value2.W) + ((-value1.W + value3.W) * amount)) + (((((2.0f * value1.W) - (5.0f * value2.W)) + (4.0f * value3.W)) - value4.W) * squared)) + ((((-value1.W + (3.0f * value2.W)) - (3.0f * value3.W)) + value4.W) * cubed)); + result.X = 0.5f * ( ( ( ( 2.0f * value2.X ) + ( ( -value1.X + value3.X ) * amount ) ) + ( ( ( ( ( 2.0f * value1.X ) - ( 5.0f * value2.X ) ) + ( 4.0f * value3.X ) ) - value4.X ) * squared ) ) + ( ( ( ( -value1.X + ( 3.0f * value2.X ) ) - ( 3.0f * value3.X ) ) + value4.X ) * cubed ) ); + result.Y = 0.5f * ( ( ( ( 2.0f * value2.Y ) + ( ( -value1.Y + value3.Y ) * amount ) ) + ( ( ( ( ( 2.0f * value1.Y ) - ( 5.0f * value2.Y ) ) + ( 4.0f * value3.Y ) ) - value4.Y ) * squared ) ) + ( ( ( ( -value1.Y + ( 3.0f * value2.Y ) ) - ( 3.0f * value3.Y ) ) + value4.Y ) * cubed ) ); + result.Z = 0.5f * ( ( ( ( 2.0f * value2.Z ) + ( ( -value1.Z + value3.Z ) * amount ) ) + ( ( ( ( ( 2.0f * value1.Z ) - ( 5.0f * value2.Z ) ) + ( 4.0f * value3.Z ) ) - value4.Z ) * squared ) ) + ( ( ( ( -value1.Z + ( 3.0f * value2.Z ) ) - ( 3.0f * value3.Z ) ) + value4.Z ) * cubed ) ); + result.W = 0.5f * ( ( ( ( 2.0f * value2.W ) + ( ( -value1.W + value3.W ) * amount ) ) + ( ( ( ( ( 2.0f * value1.W ) - ( 5.0f * value2.W ) ) + ( 4.0f * value3.W ) ) - value4.W ) * squared ) ) + ( ( ( ( -value1.W + ( 3.0f * value2.W ) ) - ( 3.0f * value3.W ) ) + value4.W ) * cubed ) ); } /// @@ -801,10 +814,10 @@ namespace math /// The fourth position in the interpolation. /// Weighting factor. /// A vector that is the result of the Catmull-Rom interpolation. - public static Vec4 CatmullRom(Vec4 value1, Vec4 value2, Vec4 value3, Vec4 value4, float amount) + public static Vec4 CatmullRom( Vec4 value1, Vec4 value2, Vec4 value3, Vec4 value4, float amount ) { Vec4 result; - CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result); + CatmullRom( ref value1, ref value2, ref value3, ref value4, amount, out result ); return result; } @@ -814,13 +827,13 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Max(ref Vec4 left, ref Vec4 right, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Max( ref Vec4 left, ref Vec4 right, out Vec4 result ) { - result.X = (left.X > right.X) ? left.X : right.X; - result.Y = (left.Y > right.Y) ? left.Y : right.Y; - result.Z = (left.Z > right.Z) ? left.Z : right.Z; - result.W = (left.W > right.W) ? left.W : right.W; + result.X = ( left.X > right.X ) ? left.X : right.X; + result.Y = ( left.Y > right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z > right.Z ) ? left.Z : right.Z; + result.W = ( left.W > right.W ) ? left.W : right.W; } /// @@ -829,11 +842,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the largest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Max(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Max( Vec4 left, Vec4 right ) { Vec4 result; - Max(ref left, ref right, out result); + Max( ref left, ref right, out result ); return result; } @@ -843,13 +856,13 @@ namespace math /// The first source vector. /// The second source vector. /// When the method completes, contains an new vector composed of the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Min(ref Vec4 left, ref Vec4 right, out Vec4 result) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static void Min( ref Vec4 left, ref Vec4 right, out Vec4 result ) { - result.X = (left.X < right.X) ? left.X : right.X; - result.Y = (left.Y < right.Y) ? left.Y : right.Y; - result.Z = (left.Z < right.Z) ? left.Z : right.Z; - result.W = (left.W < right.W) ? left.W : right.W; + result.X = ( left.X < right.X ) ? left.X : right.X; + result.Y = ( left.Y < right.Y ) ? left.Y : right.Y; + result.Z = ( left.Z < right.Z ) ? left.Z : right.Z; + result.W = ( left.W < right.W ) ? left.W : right.W; } /// @@ -858,11 +871,11 @@ namespace math /// The first source vector. /// The second source vector. /// A vector containing the smallest components of the source vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 Min(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 Min( Vec4 left, Vec4 right ) { Vec4 result; - Min(ref left, ref right, out result); + Min( ref left, ref right, out result ); return result; } @@ -882,7 +895,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthogonalize(Vec4[] destination, params Vec4[] source) + public static void Orthogonalize( Vec4[] destination, params Vec4[] source ) { //Uses the modified Gram-Schmidt process. //q1 = m1 @@ -891,20 +904,20 @@ namespace math //q4 = m4 - ((q1 ⋅ m4) / (q1 ⋅ q1)) * q1 - ((q2 ⋅ m4) / (q2 ⋅ q2)) * q2 - ((q3 ⋅ m4) / (q3 ⋅ q3)) * q3 //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Vec4 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= (Vec4.Dot(destination[r], newvector) / Vec4.Dot(destination[r], destination[r])) * destination[r]; + newvector -= ( Vec4.Dot( destination[r], newvector ) / Vec4.Dot( destination[r], destination[r] ) ) * destination[r]; } destination[i] = newvector; @@ -927,7 +940,7 @@ namespace math /// /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Orthonormalize(Vec4[] destination, params Vec4[] source) + public static void Orthonormalize( Vec4[] destination, params Vec4[] source ) { //Uses the modified Gram-Schmidt process. //Because we are making unit vectors, we can optimize the math for orthogonalization @@ -938,20 +951,20 @@ namespace math //q4 = (m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3) / |m4 - (q1 ⋅ m4) * q1 - (q2 ⋅ m4) * q2 - (q3 ⋅ m4) * q3| //q5 = ... - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { Vec4 newvector = source[i]; - for (int r = 0; r < i; ++r) + for( int r = 0; r < i; ++r ) { - newvector -= Vec4.Dot(destination[r], newvector) * destination[r]; + newvector -= Vec4.Dot( destination[r], newvector ) * destination[r]; } newvector.Normalize(); @@ -965,7 +978,7 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// When the method completes, contains the transformed . - public static void Transform(ref Vec4 vector, ref Quaternion rotation, out Vec4 result) + public static void Transform( ref Vec4 vector, ref Quaternion rotation, out Vec4 result ) { float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -981,10 +994,10 @@ namespace math float zz = rotation.Z * z; result = new Vec4( - ((vector.X * ((1.0f - yy) - zz)) + (vector.Y * (xy - wz))) + (vector.Z * (xz + wy)), - ((vector.X * (xy + wz)) + (vector.Y * ((1.0f - xx) - zz))) + (vector.Z * (yz - wx)), - ((vector.X * (xz - wy)) + (vector.Y * (yz + wx))) + (vector.Z * ((1.0f - xx) - yy)), - vector.W); + ( ( vector.X * ( ( 1.0f - yy ) - zz ) ) + ( vector.Y * ( xy - wz ) ) ) + ( vector.Z * ( xz + wy ) ), + ( ( vector.X * ( xy + wz ) ) + ( vector.Y * ( ( 1.0f - xx ) - zz ) ) ) + ( vector.Z * ( yz - wx ) ), + ( ( vector.X * ( xz - wy ) ) + ( vector.Y * ( yz + wx ) ) ) + ( vector.Z * ( ( 1.0f - xx ) - yy ) ), + vector.W ); } /// @@ -993,10 +1006,10 @@ namespace math /// The vector to rotate. /// The rotation to apply. /// The transformed . - public static Vec4 Transform(Vec4 vector, Quaternion rotation) + public static Vec4 Transform( Vec4 vector, Quaternion rotation ) { Vec4 result; - Transform(ref vector, ref rotation, out result); + Transform( ref vector, ref rotation, out result ); return result; } @@ -1009,14 +1022,14 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Vec4[] source, ref Quaternion rotation, Vec4[] destination) + public static void Transform( Vec4[] source, ref Quaternion rotation, Vec4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); float x = rotation.X + rotation.X; float y = rotation.Y + rotation.Y; @@ -1031,23 +1044,23 @@ namespace math float yz = rotation.Y * z; float zz = rotation.Z * z; - float num1 = ((1.0f - yy) - zz); - float num2 = (xy - wz); - float num3 = (xz + wy); - float num4 = (xy + wz); - float num5 = ((1.0f - xx) - zz); - float num6 = (yz - wx); - float num7 = (xz - wy); - float num8 = (yz + wx); - float num9 = ((1.0f - xx) - yy); + float num1 = ( ( 1.0f - yy ) - zz ); + float num2 = ( xy - wz ); + float num3 = ( xz + wy ); + float num4 = ( xy + wz ); + float num5 = ( ( 1.0f - xx ) - zz ); + float num6 = ( yz - wx ); + float num7 = ( xz - wy ); + float num8 = ( yz + wx ); + float num9 = ( ( 1.0f - xx ) - yy ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { destination[i] = new Vec4( - ((source[i].X * num1) + (source[i].Y * num2)) + (source[i].Z * num3), - ((source[i].X * num4) + (source[i].Y * num5)) + (source[i].Z * num6), - ((source[i].X * num7) + (source[i].Y * num8)) + (source[i].Z * num9), - source[i].W); + ( ( source[i].X * num1 ) + ( source[i].Y * num2 ) ) + ( source[i].Z * num3 ), + ( ( source[i].X * num4 ) + ( source[i].Y * num5 ) ) + ( source[i].Z * num6 ), + ( ( source[i].X * num7 ) + ( source[i].Y * num8 ) ) + ( source[i].Z * num9 ), + source[i].W ); } } @@ -1057,13 +1070,13 @@ namespace math /// The source vector. /// The transformation . /// When the method completes, contains the transformed . - public static void Transform(ref Vec4 vector, ref Matrix transform, out Vec4 result) + public static void Transform( ref Vec4 vector, ref Matrix transform, out Vec4 result ) { result = new Vec4( - (vector.X * transform.M11) + (vector.Y * transform.M21) + (vector.Z * transform.M31) + (vector.W * transform.M41), - (vector.X * transform.M12) + (vector.Y * transform.M22) + (vector.Z * transform.M32) + (vector.W * transform.M42), - (vector.X * transform.M13) + (vector.Y * transform.M23) + (vector.Z * transform.M33) + (vector.W * transform.M43), - (vector.X * transform.M14) + (vector.Y * transform.M24) + (vector.Z * transform.M34) + (vector.W * transform.M44)); + ( vector.X * transform.M11 ) + ( vector.Y * transform.M21 ) + ( vector.Z * transform.M31 ) + ( vector.W * transform.M41 ), + ( vector.X * transform.M12 ) + ( vector.Y * transform.M22 ) + ( vector.Z * transform.M32 ) + ( vector.W * transform.M42 ), + ( vector.X * transform.M13 ) + ( vector.Y * transform.M23 ) + ( vector.Z * transform.M33 ) + ( vector.W * transform.M43 ), + ( vector.X * transform.M14 ) + ( vector.Y * transform.M24 ) + ( vector.Z * transform.M34 ) + ( vector.W * transform.M44 ) ); } /// @@ -1072,10 +1085,10 @@ namespace math /// The source vector. /// The transformation . /// The transformed . - public static Vec4 Transform(Vec4 vector, Matrix transform) + public static Vec4 Transform( Vec4 vector, Matrix transform ) { Vec4 result; - Transform(ref vector, ref transform, out result); + Transform( ref vector, ref transform, out result ); return result; } @@ -1088,18 +1101,18 @@ namespace math /// This array may be the same array as . /// Thrown when or is null. /// Thrown when is shorter in length than . - public static void Transform(Vec4[] source, ref Matrix transform, Vec4[] destination) + public static void Transform( Vec4[] source, ref Matrix transform, Vec4[] destination ) { - if (source == null) - throw new ArgumentNullException("_source"); - if (destination == null) - throw new ArgumentNullException("destination"); - if (destination.Length < source.Length) - throw new ArgumentOutOfRangeException("destination", "The destination array must be of same length or larger length than the _source array."); + if( source == null ) + throw new ArgumentNullException( "_source" ); + if( destination == null ) + throw new ArgumentNullException( "destination" ); + if( destination.Length < source.Length ) + throw new ArgumentOutOfRangeException( "destination", "The destination array must be of same length or larger length than the _source array." ); - for (int i = 0; i < source.Length; ++i) + for( int i = 0; i < source.Length; ++i ) { - Transform(ref source[i], ref transform, out destination[i]); + Transform( ref source[i], ref transform, out destination[i] ); } } @@ -1109,10 +1122,10 @@ namespace math /// The first vector to add. /// The second vector to add. /// The sum of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator +(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator +( Vec4 left, Vec4 right ) { - return new Vec4(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + return new Vec4( left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W ); } /// @@ -1120,8 +1133,8 @@ namespace math /// /// The vector to assert (unchange). /// The asserted (unchanged) vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator +(Vec4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator +( Vec4 value ) { return value; } @@ -1132,10 +1145,10 @@ namespace math /// The first vector to subtract. /// The second vector to subtract. /// The difference of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator -(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator -( Vec4 left, Vec4 right ) { - return new Vec4(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + return new Vec4( left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W ); } /// @@ -1143,10 +1156,10 @@ namespace math /// /// The vector to negate. /// A vector facing in the opposite direction. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator -(Vec4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator -( Vec4 value ) { - return new Vec4(-value.X, -value.Y, -value.Z, -value.W); + return new Vec4( -value.X, -value.Y, -value.Z, -value.W ); } /// @@ -1155,10 +1168,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator *(float scale, Vec4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator *( float scale, Vec4 value ) { - return new Vec4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Vec4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -1167,10 +1180,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator *(Vec4 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator *( Vec4 value, float scale ) { - return new Vec4(value.X * scale, value.Y * scale, value.Z * scale, value.W * scale); + return new Vec4( value.X * scale, value.Y * scale, value.Z * scale, value.W * scale ); } /// @@ -1179,10 +1192,10 @@ namespace math /// The first vector to multiply. /// The second vector to multiply. /// The multiplication of the two vectors. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator *(Vec4 left, Vec4 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator *( Vec4 left, Vec4 right ) { - return new Vec4(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + return new Vec4( left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W ); } /// @@ -1191,10 +1204,10 @@ namespace math /// The vector to scale. /// The amount by which to scale the vector. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator /(Vec4 value, float scale) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator /( Vec4 value, float scale ) { - return new Vec4(value.X / scale, value.Y / scale, value.Z / scale, value.W / scale); + return new Vec4( value.X / scale, value.Y / scale, value.Z / scale, value.W / scale ); } /// @@ -1203,10 +1216,10 @@ namespace math /// The numerator. /// The value. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator /(float numerator, Vec4 value) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator /( float numerator, Vec4 value ) { - return new Vec4(numerator / value.X, numerator / value.Y, numerator / value.Z, numerator / value.W); + return new Vec4( numerator / value.X, numerator / value.Y, numerator / value.Z, numerator / value.W ); } /// @@ -1215,10 +1228,10 @@ namespace math /// The vector to scale. /// The by. /// The scaled vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vec4 operator /(Vec4 value, Vec4 by) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static Vec4 operator /( Vec4 value, Vec4 by ) { - return new Vec4(value.X / by.X, value.Y / by.Y, value.Z / by.Z, value.W / by.W); + return new Vec4( value.X / by.X, value.Y / by.Y, value.Z / by.Z, value.W / by.W ); } /// @@ -1227,9 +1240,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has the same value as ; otherwise, false. - public static bool operator ==(Vec4 left, Vec4 right) + public static bool operator ==( Vec4 left, Vec4 right ) { - return left.Equals(right); + return left.Equals( right ); } /// @@ -1238,9 +1251,9 @@ namespace math /// The first value to compare. /// The second value to compare. /// true if has a different value than ; otherwise, false. - public static bool operator !=(Vec4 left, Vec4 right) + public static bool operator !=( Vec4 left, Vec4 right ) { - return !left.Equals(right); + return !left.Equals( right ); } /// @@ -1248,9 +1261,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec2(Vec4 value) + public static explicit operator Vec2( Vec4 value ) { - return new Vec2(value.X, value.Y); + return new Vec2( value.X, value.Y ); } /// @@ -1258,9 +1271,9 @@ namespace math /// /// The value. /// The result of the conversion. - public static explicit operator Vec3(Vec4 value) + public static explicit operator Vec3( Vec4 value ) { - return new Vec3(value.X, value.Y, value.Z); + return new Vec3( value.X, value.Y, value.Z ); } /// @@ -1271,7 +1284,7 @@ namespace math /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -1281,13 +1294,13 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format) + public string ToString( string format ) { - if (format == null) + if( format == null ) return ToString(); - return string.Format(CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, CultureInfo.CurrentCulture), - Y.ToString(format, CultureInfo.CurrentCulture), Z.ToString(format, CultureInfo.CurrentCulture), W.ToString(format, CultureInfo.CurrentCulture)); + return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, CultureInfo.CurrentCulture ), + Y.ToString( format, CultureInfo.CurrentCulture ), Z.ToString( format, CultureInfo.CurrentCulture ), W.ToString( format, CultureInfo.CurrentCulture ) ); } /// @@ -1297,9 +1310,9 @@ namespace math /// /// A that represents this instance. /// - public string ToString(IFormatProvider formatProvider) + public string ToString( IFormatProvider formatProvider ) { - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X, Y, Z, W ); } /// @@ -1310,20 +1323,20 @@ namespace math /// /// A that represents this instance. /// - public string ToString(string format, IFormatProvider formatProvider) + public string ToString( string format, IFormatProvider formatProvider ) { - if (format == null) - ToString(formatProvider); + if( format == null ) + ToString( formatProvider ); - return string.Format(formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString(format, formatProvider), - Y.ToString(format, formatProvider), Z.ToString(format, formatProvider), W.ToString(format, formatProvider)); + return string.Format( formatProvider, "X:{0} Y:{1} Z:{2} W:{3}", X.ToString( format, formatProvider ), + Y.ToString( format, formatProvider ), Z.ToString( format, formatProvider ), W.ToString( format, formatProvider ) ); } /// /// Returns a hash code for this instance. /// /// - /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// public override int GetHashCode() { @@ -1337,12 +1350,12 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public bool Equals(Vec4 other) + public bool Equals( Vec4 other ) { - return ((float)Math.Abs(other.X - X) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Y - Y) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.Z - Z) < MathUtil.ZeroTolerance && - (float)Math.Abs(other.W - W) < MathUtil.ZeroTolerance); + return ( (float)Math.Abs( other.X - X ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Y - Y ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.Z - Z ) < MathUtil.ZeroTolerance && + (float)Math.Abs( other.W - W ) < MathUtil.ZeroTolerance ); } /// @@ -1352,15 +1365,15 @@ namespace math /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object value) + public override bool Equals( object value ) { - if (value == null) + if( value == null ) return false; - if (value.GetType() != GetType()) + if( value.GetType() != GetType() ) return false; - return Equals((Vec4)value); + return Equals( (Vec4)value ); } #if WPFInterop diff --git a/math/VectorExtensions.cs b/math/VectorExtensions.cs index 81606d4..eed52f2 100644 --- a/math/VectorExtensions.cs +++ b/math/VectorExtensions.cs @@ -11,54 +11,54 @@ namespace math /// Return the Y/X components of the vector in the inverse order. /// /// the input vector - public static Vec2 YX(this Vec2 vector) + public static Vec2 YX( this Vec2 vector ) { - return new Vec2(vector.Y, vector.X); + return new Vec2( vector.Y, vector.X ); } /// /// Return the X/Y components of the vector. /// /// the input vector - public static Vec2 XY(this Vec3 vector) + public static Vec2 XY( this Vec3 vector ) { - return new Vec2(vector.X, vector.Y); + return new Vec2( vector.X, vector.Y ); } /// /// Return the X/Z components of the vector. /// /// the input vector - public static Vec2 XZ(this Vec3 vector) + public static Vec2 XZ( this Vec3 vector ) { - return new Vec2(vector.X, vector.Z); + return new Vec2( vector.X, vector.Z ); } /// /// Return the Y/Z components of the vector. /// /// the input vector - public static Vec2 YZ(this Vec3 vector) + public static Vec2 YZ( this Vec3 vector ) { - return new Vec2(vector.Y, vector.Z); + return new Vec2( vector.Y, vector.Z ); } /// /// Return the X/Y components of the vector. /// /// the input vector - public static Vec2 XY(this Vec4 vector) + public static Vec2 XY( this Vec4 vector ) { - return new Vec2(vector.X, vector.Y); + return new Vec2( vector.X, vector.Y ); } /// /// Return the X/Y/Z components of the vector. /// /// the input vector - public static Vec3 XYZ(this Vec4 vector) + public static Vec3 XYZ( this Vec4 vector ) { - return new Vec3(vector.X, vector.Y, vector.Z); + return new Vec3( vector.X, vector.Y, vector.Z ); } } } diff --git a/math/fn.cs b/math/fn.cs index bc1c797..2499dbc 100644 --- a/math/fn.cs +++ b/math/fn.cs @@ -14,8 +14,8 @@ namespace math static public class fn { - static public float ToDeg( float rad ) => ( float )(180.0 / Math.PI) * rad; - static public float ToRad( float deg ) => ( float )(Math.PI / 180.0) * deg; + static public float ToDeg( float rad ) => (float)( 180.0 / Math.PI ) * rad; + static public float ToRad( float deg ) => (float)( Math.PI / 180.0 ) * deg; static public float Clamp( float v, float min, float max ) { @@ -29,7 +29,7 @@ namespace math static public float LogisticsFull( float v, float height, float spread, float f, float g, float h ) { - float res = height / (1.0f + (float)Math.Pow( g, (spread * (v+h))) ) + f; + float res = height / ( 1.0f + (float)Math.Pow( g, ( spread * ( v + h ) ) ) ) + f; return res; } @@ -47,28 +47,28 @@ namespace math } //Tracked these down in Desmos - static public float s_a = 0.0f; - static public float s_b = 0.155f; - static public float s_c = 1.03f; - static public float s_d = 6.13f; + static public float s_a = 0.0f; + static public float s_b = 0.155f; + static public float s_c = 1.03f; + static public float s_d = 6.13f; static public float s_f = -10.2f; - static public float s_g = 4.06f; + static public float s_g = 4.06f; static public float Quintic( float v ) { - var vv = v * v; - var vvv = vv * v; + var vv = v * v; + var vvv = vv * v; var vvvv = vvv * v; - var vvvvv= vvvv * v; + var vvvvv = vvvv * v; - var res = s_a + s_b*v + s_c*vv + s_d*vvv + s_f*vvvv + s_g * vvvvv; + var res = s_a + s_b * v + s_c * vv + s_d * vvv + s_f * vvvv + s_g * vvvvv; return res; } - static public float s_p = 0.37f; - static public float s_o = 0.15f; - static public float s_m = 2.11f; + static public float s_p = 0.37f; + static public float s_o = 0.15f; + static public float s_m = 2.11f; static public float s_n = -0.57f; static public float PerlinToContinent( float h ) @@ -93,7 +93,7 @@ namespace math { var dV = (double)v; - var newV = dV * dV * (3.0 - 2.0 * dV); + var newV = dV * dV * ( 3.0 - 2.0 * dV ); return (float)newV; diff --git a/mod/Modules.cs b/mod/Modules.cs index bf9a00d..af96caa 100644 --- a/mod/Modules.cs +++ b/mod/Modules.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,7 +10,7 @@ namespace mod { [Serializable] - public class Config: lib.Config + public class Config : lib.Config { public String name = "Generic"; } @@ -33,13 +33,13 @@ namespace mod [Serializable] - public class FluidConfig: Config + public class FluidConfig : Config { public String type = "none"; } - public class FluidBase: Base + public class FluidBase : Base { public new FluidConfig Cfg { get { return (FluidConfig)base.Cfg; } } @@ -65,7 +65,7 @@ namespace mod [Serializable] - public class SystemConfig: Config + public class SystemConfig : Config { public String type = "none"; } diff --git a/net/Conn.cs b/net/Conn.cs index 7a2d658..31d3637 100644 --- a/net/Conn.cs +++ b/net/Conn.cs @@ -52,9 +52,9 @@ namespace lib // // Returns: // The top object of the deserialized graph. - [RequiresDynamicCode("BinaryFormatter serialization uses dynamic code generation, the type of objects being processed cannot be statically discovered.")] - [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered.")] - object Deserialize(Stream serializationStream); + [RequiresDynamicCode( "BinaryFormatter serialization uses dynamic code generation, the type of objects being processed cannot be statically discovered." )] + [RequiresUnreferencedCode( "BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered." )] + object Deserialize( Stream serializationStream ); // // Summary: // Serializes an object, or graph of objects with the given root to the provided @@ -68,8 +68,8 @@ namespace lib // graph: // The object, or root of the object graph, to serialize. All child objects of this // root object are automatically serialized. - [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered.")] - void Serialize(Stream serializationStream, object graph); + [RequiresUnreferencedCode( "BinaryFormatter serialization is not trim compatible because the type of objects being processed cannot be statically discovered." )] + void Serialize( Stream serializationStream, object graph ); } @@ -89,7 +89,7 @@ namespace lib } - public class NewEveryCall: ISerDes where T : IFormatter, new() + public class NewEveryCall : ISerDes where T : IFormatter, new() { public T getInstance() { @@ -104,8 +104,8 @@ namespace lib public class Conn : Conn - where T : IFormatter, new() - where TInst : ISerDes, new() + where T : IFormatter, new() + where TInst : ISerDes, new() { public Socket Sock { get { return m_socket; } } public Stream Stream { get { return m_streamNet; } } diff --git a/net/NetMsg.cs b/net/NetMsg.cs index b69689f..5e77ecb 100644 --- a/net/NetMsg.cs +++ b/net/NetMsg.cs @@ -43,14 +43,14 @@ namespace lib.Net }; [Serializable] - public class CreateEntity: Admin + public class CreateEntity : Admin { } [Serializable] - public class MoveEntity: Admin + public class MoveEntity : Admin { } @@ -69,7 +69,7 @@ namespace lib.Net [Serializable] - public class EntityPos: EntityBase + public class EntityPos : EntityBase { public EntityPos( int id, float x, float y, float z ) : base( id ) @@ -85,7 +85,7 @@ namespace lib.Net } [Serializable] - public class EntityDesc: EntityBase + public class EntityDesc : EntityBase { public EntityDesc( int id ) : base( id ) diff --git a/prof/AddressStack.cs b/prof/AddressStack.cs index 3face11..bf57554 100644 --- a/prof/AddressStack.cs +++ b/prof/AddressStack.cs @@ -7,37 +7,41 @@ namespace Tracing // the first frame is the address of the last called method private readonly List _stack; - public AddressStack(int capacity) + public AddressStack( int capacity ) { - _stack = new List(capacity); + _stack = new List( capacity ); } // No need to override GetHashCode because we don't want to use it as a key in a dictionary - public override bool Equals(object obj) + public override bool Equals( object obj ) { - if (obj == null) return false; + if( obj == null ) + return false; var stack = obj as AddressStack; - if (stack == null) return false; + if( stack == null ) + return false; var frameCount = _stack.Count; - if (frameCount != stack._stack.Count) return false; + if( frameCount != stack._stack.Count ) + return false; - for (int i = 0; i < frameCount; i++) + for( int i = 0; i < frameCount; i++ ) { - if (_stack[i] != stack._stack[i]) return false; + if( _stack[i] != stack._stack[i] ) + return false; } return true; } - public override int GetHashCode() => _stack.GetHashCode(); + public override int GetHashCode() => _stack.GetHashCode(); - public IReadOnlyList Stack => _stack; + public IReadOnlyList Stack => _stack; - public void AddFrame(ulong address) + public void AddFrame( ulong address ) { - _stack.Add(address); + _stack.Add( address ); } } } diff --git a/prof/Memory.cs b/prof/Memory.cs index e534766..0cce0e0 100644 --- a/prof/Memory.cs +++ b/prof/Memory.cs @@ -68,9 +68,9 @@ namespace Tracing //* log.info( $"EnableKernelProvider" ); success = log.var( session.EnableKernelProvider( KernelTraceEventParser.Keywords.None | -// KernelTraceEventParser.Keywords.ImageLoad | -// KernelTraceEventParser.Keywords.Process - 0 , + // KernelTraceEventParser.Keywords.ImageLoad | + // KernelTraceEventParser.Keywords.Process + 0, KernelTraceEventParser.Keywords.None ) ); log.info( $"EnableKernelProvider {success}" ); @@ -159,7 +159,7 @@ namespace Tracing GetProcessMethods( data.ProcessID ).AddModule( data.FileName, data.ImageBase, data.ImageSize ); - log.info($"{data.ProcessID}.{data.ThreadID} --> {data.FileName}"); + log.info( $"{data.ProcessID}.{data.ThreadID} --> {data.FileName}" ); } private void OnMethodDetails( MethodLoadUnloadVerboseTraceData data ) diff --git a/prof/MemoryPipe.cs b/prof/MemoryPipe.cs index d296227..01314d7 100644 --- a/prof/MemoryPipe.cs +++ b/prof/MemoryPipe.cs @@ -77,20 +77,20 @@ namespace Tracing //await Task.Factory.StartNew( () => { - using EventPipeSession session = _client.StartEventPipeSession( providers, false ); + using EventPipeSession session = _client.StartEventPipeSession( providers, false ); - //log.info( $"SetupProviders" ); - //SetupProviders( session, allAllocations ); - var source = new EventPipeEventSource( session.EventStream ); + //log.info( $"SetupProviders" ); + //SetupProviders( session, allAllocations ); + var source = new EventPipeEventSource( session.EventStream ); - log.info( $"SetupListeners" ); - SetupListeners( source ); + log.info( $"SetupListeners" ); + SetupListeners( source ); - log.info( $"Run Process" ); - source.Process(); + log.info( $"Run Process" ); + source.Process(); - log.info( $"Done" ); + log.info( $"Done" ); //} ); } @@ -105,9 +105,9 @@ namespace Tracing //* log.info( $"EnableKernelProvider" ); success = log.var( session.EnableKernelProvider( KernelTraceEventParser.Keywords.None | -// KernelTraceEventParser.Keywords.ImageLoad | -// KernelTraceEventParser.Keywords.Process - 0 , + // KernelTraceEventParser.Keywords.ImageLoad | + // KernelTraceEventParser.Keywords.Process + 0, KernelTraceEventParser.Keywords.None ) ); log.info( $"EnableKernelProvider {success}" ); @@ -179,7 +179,7 @@ namespace Tracing private void OnAllocTick( GCAllocationTickTraceData data ) { - if( FilterOutEvent( data ) ) + if( FilterOutEvent( data ) ) return; //log.info( $"*** RAW: {data}" ); @@ -194,7 +194,7 @@ namespace Tracing var typeName = GetProcessTypeName( data.ProcessID, data.TypeID ); //if( data.TotalSizeForTypeSample >= 85000 ) { - var message = $"{data.ThreadID}/{thisThreadId} Alloc {data.ObjectSize, 8} at 0x{data.Address:0000000000000000} in {data.TypeName} (or {GetProcessTypeName( data.ProcessID, data.TypeID )}) "; + var message = $"{data.ThreadID}/{thisThreadId} Alloc {data.ObjectSize,8} at 0x{data.Address:0000000000000000} in {data.TypeName} (or {GetProcessTypeName( data.ProcessID, data.TypeID )}) "; log.info( message ); } GetProcessAllocations( data.ProcessID ) @@ -230,13 +230,13 @@ namespace Tracing //GetProcessMethods( data.ProcessID ).AddModule( data.FileName, data.ImageBase, data.ImageSize ); - log.info($"{data.ProcessID}.{data.ThreadID} --> {data.FileName}"); + log.info( $"{data.ProcessID}.{data.ThreadID} --> {data.FileName}" ); } private void OnMethodDetails( MethodLoadUnloadVerboseTraceData data ) { //if( FilterOutEvent( data ) ) - // return; + // return; //log.info( $"{data}" ); @@ -296,7 +296,7 @@ namespace Tracing private void OnClrStackWalk( ClrStackWalkTraceData data ) { var message = $"{data.ProcessID}.{data.ThreadID} - {data.TimeStampRelativeMSec,12} | {data.FrameCount} frames"; - log.info(message); + log.info( message ); var callstack = BuildCallStack( data ); GetProcessAllocations( data.ProcessID ).AddStack( data.ThreadID, callstack ); diff --git a/prof/MethodInfo.cs b/prof/MethodInfo.cs index 248f5c6..0facada 100644 --- a/prof/MethodInfo.cs +++ b/prof/MethodInfo.cs @@ -8,48 +8,48 @@ namespace ProfilerHelpers private readonly int _size; private readonly string _fullName; - internal MethodInfo(ulong startAddress, int size, string namespaceAndTypeName, string name, string signature) + internal MethodInfo( ulong startAddress, int size, string namespaceAndTypeName, string name, string signature ) { _startAddress = startAddress; _size = size; - _fullName = ComputeFullName(startAddress, namespaceAndTypeName, name, signature); + _fullName = ComputeFullName( startAddress, namespaceAndTypeName, name, signature ); } - private string ComputeFullName(ulong startAddress, string namespaceAndTypeName, string name, string signature) + private string ComputeFullName( ulong startAddress, string namespaceAndTypeName, string name, string signature ) { var fullName = signature; // constructor case: name = .ctor | namespaceAndTypeName = A.B.typeName | signature = ... (parameters) // --> A.B.typeName(parameters) - if (name == ".ctor") + if( name == ".ctor" ) { - return $"{namespaceAndTypeName}{ExtractParameters(signature)}"; + return $"{namespaceAndTypeName}{ExtractParameters( signature )}"; } // general case: name = Foo | namespaceAndTypeName = A.B.typeName | signature = ... (parameters) // --> A.B.Foo(parameters) - fullName = $"{namespaceAndTypeName}.{name}{ExtractParameters(signature)}"; + fullName = $"{namespaceAndTypeName}.{name}{ExtractParameters( signature )}"; return fullName; } - private string ExtractTypeName(string namespaceAndTypeName) + private string ExtractTypeName( string namespaceAndTypeName ) { - var pos = namespaceAndTypeName.LastIndexOf(".", StringComparison.Ordinal); - if (pos == -1) + var pos = namespaceAndTypeName.LastIndexOf( ".", StringComparison.Ordinal ); + if( pos == -1 ) { return namespaceAndTypeName; } - + // skip the . pos++; - return namespaceAndTypeName.Substring(pos); + return namespaceAndTypeName.Substring( pos ); } - private string ExtractParameters(string signature) + private string ExtractParameters( string signature ) { - var pos = signature.IndexOf(" ("); - if (pos == -1) + var pos = signature.IndexOf( " (" ); + if( pos == -1 ) { return "(???)"; } @@ -57,7 +57,7 @@ namespace ProfilerHelpers // skip double space pos += 2; - var parameters = signature.Substring(pos); + var parameters = signature.Substring( pos ); return parameters; } diff --git a/prof/MethodStore.cs b/prof/MethodStore.cs index 39e0dd8..9f09cc0 100644 --- a/prof/MethodStore.cs +++ b/prof/MethodStore.cs @@ -10,7 +10,7 @@ namespace ProfilerHelpers { // JITed methods information (start address + size + signature) private readonly List _methods; - + // addresses from callstacks already matching (address -> full name) private readonly Dictionary _cache; @@ -20,38 +20,38 @@ namespace ProfilerHelpers private Process _process; private readonly int _pid; - public MethodStore(int pid, bool loadModules = false) + public MethodStore( int pid, bool loadModules = false ) { // it may be possible to open the process // in that case, _hProcess = IntPtr.Zero _pid = pid; - _methods = new List(1024); + _methods = new List( 1024 ); _cache = new Dictionary(); - _hProcess = BindToProcess(pid, loadModules); + _hProcess = BindToProcess( pid, loadModules ); } - private IntPtr BindToProcess(int pid, bool loadModules) + private IntPtr BindToProcess( int pid, bool loadModules ) { try { - _process = Process.GetProcessById(pid); + _process = Process.GetProcessById( pid ); - if (!SymInitialize(_process.Handle, loadModules)) + if( !SymInitialize( _process.Handle, loadModules ) ) return IntPtr.Zero; return _process.Handle; } - catch (Exception x) + catch( Exception x ) { - Console.WriteLine($"Error while binding pid #{pid} to DbgHelp:"); - Console.WriteLine(x.Message); + Console.WriteLine( $"Error while binding pid #{pid} to DbgHelp:" ); + Console.WriteLine( x.Message ); return IntPtr.Zero; } } - private bool SymInitialize(IntPtr hProcess, bool loadModules = false) + private bool SymInitialize( IntPtr hProcess, bool loadModules = false ) { // read https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/nf-dbghelp-symsetoptions for more details // maybe SYMOPT_NO_PROMPTS and SYMOPT_FAIL_CRITICAL_ERRORS could be used @@ -66,29 +66,29 @@ namespace ProfilerHelpers // - The _NT_SYMBOL_PATH environment variable // - The _NT_ALTERNATE_SYMBOL_PATH environment variable // - // passing false as last parameter means that we will need to call SymLoadModule64 + // passing false as last parameter means that we will need to call SymLoadModule64 // each time a module is loaded in the process - return NativeDbgHelp.SymInitialize(hProcess, null, loadModules); + return NativeDbgHelp.SymInitialize( hProcess, null, loadModules ); } - public MethodInfo Add(ulong address, int size, string namespaceAndTypeName, string name, string signature) + public MethodInfo Add( ulong address, int size, string namespaceAndTypeName, string name, string signature ) { - var method = new MethodInfo(address, size, namespaceAndTypeName, name, signature); - _methods.Add(method); + var method = new MethodInfo( address, size, namespaceAndTypeName, name, signature ); + _methods.Add( method ); return method; } - public string GetFullName(ulong address) + public string GetFullName( ulong address ) { - if (_cache.TryGetValue(address, out var fullName)) + if( _cache.TryGetValue( address, out var fullName ) ) return fullName; - + // look for managed methods - for (int i = 0; i < _methods.Count; i++) + for( int i = 0; i < _methods.Count; i++ ) { var method = _methods[i]; - - if ((address >= method.StartAddress) && (address < method.StartAddress + (ulong)method.Size)) + + if( ( address >= method.StartAddress ) && ( address < method.StartAddress + (ulong)method.Size ) ) { fullName = method.FullName; _cache[address] = fullName; @@ -97,40 +97,40 @@ namespace ProfilerHelpers } // look for native methods - fullName = GetNativeMethodName(address); + fullName = GetNativeMethodName( address ); _cache[address] = fullName; return fullName; } - private string GetNativeMethodName(ulong address) + private string GetNativeMethodName( ulong address ) { var symbol = new NativeDbgHelp.SYMBOL_INFO(); symbol.MaxNameLen = 1024; - symbol.SizeOfStruct = (uint)Marshal.SizeOf(symbol) - 1024; // char buffer is not counted + symbol.SizeOfStruct = (uint)Marshal.SizeOf( symbol ) - 1024; // char buffer is not counted // the ANSI version of SymFromAddr is called so each character is 1 byte long - if (NativeDbgHelp.SymFromAddr(_hProcess, address, out var displacement, ref symbol)) + if( NativeDbgHelp.SymFromAddr( _hProcess, address, out var displacement, ref symbol ) ) { - var buffer = new StringBuilder(symbol.Name.Length); + var buffer = new StringBuilder( symbol.Name.Length ); // remove weird "$##" at the end of some symbols - var pos = symbol.Name.LastIndexOf("$##"); - if (pos == -1) - buffer.Append(symbol.Name); + var pos = symbol.Name.LastIndexOf( "$##" ); + if( pos == -1 ) + buffer.Append( symbol.Name ); else - buffer.Append(symbol.Name, 0, pos); + buffer.Append( symbol.Name, 0, pos ); // add offset if any - if (displacement != 0) - buffer.Append($"+0x{displacement}"); + if( displacement != 0 ) + buffer.Append( $"+0x{displacement}" ); return buffer.ToString(); } // default value is just the address in HEX #if DEBUG - return ($"0x{address:x} (SymFromAddr failed with 0x{Marshal.GetLastWin32Error():x})"); + return ( $"0x{address:x} (SymFromAddr failed with 0x{Marshal.GetLastWin32Error():x})" ); #else return $"0x{address:x}"; #endif @@ -138,21 +138,22 @@ namespace ProfilerHelpers } const int ERROR_SUCCESS = 0; - public void AddModule(string filename, ulong baseOfDll, int sizeOfDll) + public void AddModule( string filename, ulong baseOfDll, int sizeOfDll ) { - var baseAddress = NativeDbgHelp.SymLoadModule64(_hProcess, IntPtr.Zero, filename, null, baseOfDll, (uint)sizeOfDll); - if (baseAddress == 0) + var baseAddress = NativeDbgHelp.SymLoadModule64( _hProcess, IntPtr.Zero, filename, null, baseOfDll, (uint)sizeOfDll ); + if( baseAddress == 0 ) { // should work if the same module is added more than once - if (Marshal.GetLastWin32Error() == ERROR_SUCCESS) return; + if( Marshal.GetLastWin32Error() == ERROR_SUCCESS ) + return; - Console.WriteLine($"SymLoadModule64 failed for {filename}"); + Console.WriteLine( $"SymLoadModule64 failed for {filename}" ); } } public void Dispose() { - if (_hProcess == IntPtr.Zero) + if( _hProcess == IntPtr.Zero ) return; _hProcess = IntPtr.Zero; @@ -166,7 +167,7 @@ namespace ProfilerHelpers public const uint SYMOPT_UNDNAME = 0x00000002; public const uint SYMOPT_DEFERRED_LOADS = 0x00000004; - [StructLayout(LayoutKind.Sequential)] + [StructLayout( LayoutKind.Sequential )] public struct SYMBOL_INFO { public uint SizeOfStruct; @@ -184,25 +185,25 @@ namespace ProfilerHelpers public uint Tag; // pdb classification public uint NameLen; // Actual length of name public uint MaxNameLen; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)] + [MarshalAs( UnmanagedType.ByValTStr, SizeConst = 1024 )] public string Name; } - [DllImport("dbghelp.dll", SetLastError = true)] - public static extern bool SymInitialize(IntPtr hProcess, string userSearchPath, bool invadeProcess); + [DllImport( "dbghelp.dll", SetLastError = true )] + public static extern bool SymInitialize( IntPtr hProcess, string userSearchPath, bool invadeProcess ); - [DllImport("dbghelp.dll", SetLastError = true)] - public static extern uint SymSetOptions(uint symOptions); + [DllImport( "dbghelp.dll", SetLastError = true )] + public static extern uint SymSetOptions( uint symOptions ); - [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Ansi)] - public static extern ulong SymLoadModule64(IntPtr hProcess, IntPtr hFile, string imageName, string moduleName, ulong baseOfDll, uint sizeOfDll); + [DllImport( "dbghelp.dll", SetLastError = true, CharSet = CharSet.Ansi )] + public static extern ulong SymLoadModule64( IntPtr hProcess, IntPtr hFile, string imageName, string moduleName, ulong baseOfDll, uint sizeOfDll ); - // use ANSI version to ensure the right size of the structure + // use ANSI version to ensure the right size of the structure // read https://docs.microsoft.com/en-us/windows/win32/api/dbghelp/ns-dbghelp-symbol_info - [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Ansi)] - public static extern bool SymFromAddr(IntPtr hProcess, ulong address, out ulong displacement, ref SYMBOL_INFO symbol); + [DllImport( "dbghelp.dll", SetLastError = true, CharSet = CharSet.Ansi )] + public static extern bool SymFromAddr( IntPtr hProcess, ulong address, out ulong displacement, ref SYMBOL_INFO symbol ); - [DllImport("dbghelp.dll", SetLastError = true)] - public static extern bool SymCleanup(IntPtr hProcess); + [DllImport( "dbghelp.dll", SetLastError = true )] + public static extern bool SymCleanup( IntPtr hProcess ); } } diff --git a/prof/PerProcessProfilingState.cs b/prof/PerProcessProfilingState.cs index 0ffa72d..8a3c2d5 100644 --- a/prof/PerProcessProfilingState.cs +++ b/prof/PerProcessProfilingState.cs @@ -20,10 +20,11 @@ namespace Tracing public void Dispose() { - if (_disposed) return; + if( _disposed ) + return; _disposed = true; - foreach (var methodStore in _methods.Values) + foreach( var methodStore in _methods.Values ) { methodStore.Dispose(); } diff --git a/prof/ProcessAllocations.cs b/prof/ProcessAllocations.cs index 02ae0a9..acdc4dd 100644 --- a/prof/ProcessAllocations.cs +++ b/prof/ProcessAllocations.cs @@ -10,7 +10,7 @@ namespace Tracing private readonly Dictionary _allocations; private readonly Dictionary _perThreadLastAllocation; - public ProcessAllocations(int pid) + public ProcessAllocations( int pid ) { _pid = pid; _allocations = new Dictionary(); @@ -19,9 +19,9 @@ namespace Tracing public int Pid => _pid; - public AllocationInfo GetAllocations(string typeName) + public AllocationInfo GetAllocations( string typeName ) { - return (_allocations.TryGetValue(typeName, out var info)) ? info : null; + return ( _allocations.TryGetValue( typeName, out var info ) ) ? info : null; } public IEnumerable GetAllAllocations() @@ -29,20 +29,20 @@ namespace Tracing return _allocations.Values; } - public AllocationInfo AddAllocation(int threadID, ulong size, ulong count, string typeName) + public AllocationInfo AddAllocation( int threadID, ulong size, ulong count, string typeName ) { - if (!_allocations.TryGetValue(typeName, out var info)) + if( !_allocations.TryGetValue( typeName, out var info ) ) { - info = new AllocationInfo(typeName); + info = new AllocationInfo( typeName ); _allocations[typeName] = info; } - info.AddAllocation(size, count); + info.AddAllocation( size, count ); // the last allocation is still here without the corresponding stack - if (_perThreadLastAllocation.TryGetValue(threadID, out var lastAlloc)) + if( _perThreadLastAllocation.TryGetValue( threadID, out var lastAlloc ) ) { - Console.WriteLine("no stack for the last allocation"); + Console.WriteLine( "no stack for the last allocation" ); } // keep track of the allocation for the given thread @@ -52,12 +52,12 @@ namespace Tracing return info; } - public void AddStack(int threadID, AddressStack stack) + public void AddStack( int threadID, AddressStack stack ) { - if (_perThreadLastAllocation.TryGetValue(threadID, out var lastAlloc)) + if( _perThreadLastAllocation.TryGetValue( threadID, out var lastAlloc ) ) { - lastAlloc.AddStack(stack); - _perThreadLastAllocation.Remove(threadID); + lastAlloc.AddStack( stack ); + _perThreadLastAllocation.Remove( threadID ); return; } @@ -73,7 +73,7 @@ namespace Tracing private ulong _count; private List _stacks; - internal AllocationInfo(string typeName) + internal AllocationInfo( string typeName ) { _typeName = typeName; _stacks = new List(); @@ -84,30 +84,31 @@ namespace Tracing public ulong Size => _size; public IReadOnlyList Stacks => _stacks; - internal void AddAllocation(ulong size, ulong count) + internal void AddAllocation( ulong size, ulong count ) { _count += count; _size += size; } - internal void AddStack(AddressStack stack) + internal void AddStack( AddressStack stack ) { - var info = GetInfo(stack); - if (info == null) + var info = GetInfo( stack ); + if( info == null ) { - info = new StackInfo(stack); - _stacks.Add(info); + info = new StackInfo( stack ); + _stacks.Add( info ); } info.Count++; } - private StackInfo GetInfo(AddressStack stack) + private StackInfo GetInfo( AddressStack stack ) { - for (int i = 0; i < _stacks.Count; i++) + for( int i = 0; i < _stacks.Count; i++ ) { var info = _stacks[i]; - if (stack.Equals(info.Stack)) return info; + if( stack.Equals( info.Stack ) ) + return info; } return null; @@ -119,7 +120,7 @@ namespace Tracing private readonly AddressStack _stack; public ulong Count; - internal StackInfo(AddressStack stack) + internal StackInfo( AddressStack stack ) { Count = 0; _stack = stack; diff --git a/prof/ProcessTypeMapping.cs b/prof/ProcessTypeMapping.cs index 136cad6..81574cb 100644 --- a/prof/ProcessTypeMapping.cs +++ b/prof/ProcessTypeMapping.cs @@ -8,7 +8,7 @@ namespace Tracing { private readonly Dictionary _typesIdToName; - public ProcessTypeMapping(int processId) + public ProcessTypeMapping( int processId ) { ProcessId = processId; _typesIdToName = new Dictionary(); @@ -20,7 +20,7 @@ namespace Tracing { get { - if (!_typesIdToName.ContainsKey(id)) + if( !_typesIdToName.ContainsKey( id ) ) return null; return _typesIdToName[id]; diff --git a/res/Resource.cs b/res/Resource.cs index b9c3a6f..b35c292 100644 --- a/res/Resource.cs +++ b/res/Resource.cs @@ -182,7 +182,7 @@ public class Ref : Ref where T : class, new() // Let's assume you'll add saving logic here. // Mgr.Save(value, path); // Example: Needs implementation - var immMeta = (value as imm.Obj)?.Meta; + var immMeta = ( value as io.Obj )?.Meta; @@ -365,7 +365,7 @@ public static class Mgr { return cachedValue; } - + // 2. Get a lock specific to this filename and lock it. var fileLock = s_loadingLocks.GetOrAdd( filename, _ => new object() ); lock( fileLock ) @@ -433,10 +433,10 @@ public static class Mgr var loadedObject = loaderHolder.Load( filename, reason, dbgName, dbgPath, dbgLine ); if( loadedObject is T value ) { - var meta = (value as imm.Obj)?.Meta; + var meta = ( value as io.Obj )?.Meta; // If it's an immutable object, record its loading. - if( value is imm.Obj imm ) + if( value is io.Obj imm ) { return (T)imm.Record( $"Loading bcs {reason}", dbgName, dbgPath, dbgLine ); } diff --git a/scr/Script.cs b/scr/Script.cs index d8a7908..78df00c 100644 --- a/scr/Script.cs +++ b/scr/Script.cs @@ -35,7 +35,7 @@ public class MemorySourceText : SourceText public class MemoryRefResolver : SourceReferenceResolver { - public override bool Equals(object? other) + public override bool Equals( object? other ) { return false; } @@ -65,64 +65,68 @@ public class MemoryRefResolver : SourceReferenceResolver public static class scr { - public static FieldInfo? GetFieldInfo(Type? t, string name) + public static FieldInfo? GetFieldInfo( Type? t, string name ) { - if (t == null) return null; + if( t == null ) + return null; - var fi = t.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); + var fi = t.GetField( name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly ); - if (fi != null) + if( fi != null ) return fi; - if (t.BaseType != null) - return GetFieldInfo(t.BaseType, name); + if( t.BaseType != null ) + return GetFieldInfo( t.BaseType, name ); return null; } // From stack overflow static Lazy> typeSetLazy = - new Lazy>(() => { + new Lazy>( () => + { var types = AppDomain .CurrentDomain .GetAssemblies() - .SelectMany(a => a.GetTypes() - .Where(t => t.IsClass)); + .SelectMany( a => a.GetTypes() + .Where( t => t.IsClass ) ); var typesAndBaseTypes = types - .Select(t => new { Type = t, t.BaseType }) + .Select( t => new { Type = t, t.BaseType } ) .ToList(); var typesWithSubclasses = typesAndBaseTypes .Join( typesAndBaseTypes, t => t.Type, t => t.BaseType, - (t1, t2) => t2.BaseType); - var typesHs = new HashSet(types); - typesHs.ExceptWith(typesWithSubclasses); + ( t1, t2 ) => t2.BaseType ); + var typesHs = new HashSet( types ); + typesHs.ExceptWith( typesWithSubclasses ); return typesHs; - }); + } ); - static bool IsLeafType(this Type type) + static bool IsLeafType( this Type type ) { - return typeSetLazy.Value.Contains(type); + return typeSetLazy.Value.Contains( type ); } static HashSet s_badChars = new( new char[] { '<', '>', ' ', ',', '.', '+', '[', ']', '$', ':' } ); - static public string TypeToIdentifier(string typename) + static public string TypeToIdentifier( string typename ) { var safeStr = new StringBuilder( typename ); for( int i = 0; i < safeStr.Length; ++i ) { - if( s_badChars.Contains(safeStr[i]) ) safeStr[i] = '_'; + if( s_badChars.Contains( safeStr[i] ) ) + safeStr[i] = '_'; } return safeStr.ToString(); } static public FileSystemWatcher s_watcher = new(); - static public Action s_fnAss = (ass) => { + static public Action s_fnAss = ( ass ) => + { log.warn( $"Need to replace s_fnAss with custom function" ); }; @@ -170,7 +174,7 @@ public static class scr { log.debug( $"{fse.Name} got {fse.ChangeType}" ); - if( fse.Name?.EndsWith(".cs") ?? false ) + if( fse.Name?.EndsWith( ".cs" ) ?? false ) { while( true ) { @@ -223,21 +227,21 @@ public static class scr { string assemblyName = Path.GetRandomFileName(); - var options = new CSharpParseOptions(documentationMode: DocumentationMode.Diagnose, kind: SourceCodeKind.Regular); + var options = new CSharpParseOptions( documentationMode: DocumentationMode.Diagnose, kind: SourceCodeKind.Regular ); SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText( sourceText, options, uniquePath ); var memRef = new MemoryRefResolver(); - using MemoryStream ms = new (); - using MemoryStream pdb = new (); + using MemoryStream ms = new(); + using MemoryStream pdb = new(); - var result = CompileAndEmit(assemblyName, new[] { syntaxTree }, ms, pdb, platform); + var result = CompileAndEmit( assemblyName, new[] { syntaxTree }, ms, pdb, platform ); - if (!result.Success) + if( !result.Success ) { - if (onFailure == null) + if( onFailure == null ) { } else @@ -249,8 +253,8 @@ public static class scr } else { - ms.Seek(0, SeekOrigin.Begin); - var assembly = Assembly.Load(ms.ToArray(), pdb.ToArray()); + ms.Seek( 0, SeekOrigin.Begin ); + var assembly = Assembly.Load( ms.ToArray(), pdb.ToArray() ); onSuccess( assembly ); } @@ -265,7 +269,7 @@ public static class scr } } - private static EmitResult CompileAndEmit(string assemblyName, SyntaxTree[] syntaxTrees, MemoryStream ms, MemoryStream pdb, Platform platform) + private static EmitResult CompileAndEmit( string assemblyName, SyntaxTree[] syntaxTrees, MemoryStream ms, MemoryStream pdb, Platform platform ) { MemoryRefResolver memRef = new(); @@ -274,22 +278,22 @@ public static class scr assemblyName, syntaxTrees: syntaxTrees, references: RefCache.References, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, + options: new CSharpCompilationOptions( OutputKind.DynamicallyLinkedLibrary, sourceReferenceResolver: memRef, optimizationLevel: OptimizationLevel.Release, platform: platform, specificDiagnosticOptions: new Dictionary { { "CS1701", ReportDiagnostic.Suppress } - })); + } ) ); - return compilation.Emit(ms, pdb); + return compilation.Emit( ms, pdb ); } private static class RefCache { // create the list of references on first use, but if two threads both *start* making the list thats fine since we'll just use whichever wins. - private static readonly Lazy> lazyRef = new Lazy>(GetReferences, LazyThreadSafetyMode.PublicationOnly); + private static readonly Lazy> lazyRef = new Lazy>( GetReferences, LazyThreadSafetyMode.PublicationOnly ); public static IReadOnlyList References => lazyRef.Value; @@ -327,29 +331,29 @@ public static class scr var genArgs = t.GetGenericArguments(); var typeDef = t.FullName ?? ""; - var indexOfTick = typeDef.IndexOf("`"); + var indexOfTick = typeDef.IndexOf( "`" ); - var unmangledOuterName = typeDef.Substring(0, typeDef.IndexOf('`')).Replace('+', '.'); + var unmangledOuterName = typeDef.Substring( 0, typeDef.IndexOf( '`' ) ).Replace( '+', '.' ); var innerName = ""; //Check for inner class if( typeDef.ElementAt( indexOfTick + 2 ) != '[' ) { - var indexOfOpenBracket = typeDef.IndexOf('[', indexOfTick); + var indexOfOpenBracket = typeDef.IndexOf( '[', indexOfTick ); - innerName = typeDef.Substring( indexOfTick + 2, indexOfOpenBracket - (indexOfTick + 2) ).Replace( '+', '.' ); + innerName = typeDef.Substring( indexOfTick + 2, indexOfOpenBracket - ( indexOfTick + 2 ) ).Replace( '+', '.' ); } return unmangledOuterName + "<" + String.Join( ",", genArgs.Select( PrettyName ) ) + ">" + innerName; } - private static void AddIfFirst(IDictionary dict, TKey key, TValue value) + private static void AddIfFirst( IDictionary dict, TKey key, TValue value ) { - if (!dict.ContainsKey(key)) + if( !dict.ContainsKey( key ) ) { - dict.Add(key, value); + dict.Add( key, value ); } } } diff --git a/ser/XmlSer.cs b/ser/XmlSer.cs index 310d0b4..156422e 100644 --- a/ser/XmlSer.cs +++ b/ser/XmlSer.cs @@ -17,6 +17,52 @@ namespace ser; #region Attributes & Enums (Mostly unchanged, ensure these exist) +/* + +public CoolClass +{ + private string Rare = "Rare Change"; + private float TestF = 1.0f; +} + +public class Bag +{ + public string Owner { get; set; } + public CoolClass Cool { get; set; } = new(); +} +public class BasicTest +{ + public Bag MyBag { get; set; } = new(); +} + + + + + + + + + +public abstract class Item +{ + public int Id { get; set; } +} + +public class Key : Item +{ + public int Code { get; set; } +} + +public class Orb : Item +{ + private float Power = 1.0f; + public bool IsDark = true; +} + + + + +*/ public interface I_Serialize { @@ -90,7 +136,7 @@ public enum BackingFieldNaming { Short, Regular } public enum POD { Attributes, Elements } public record struct TypeProxy( Func fnSer, Func fnDes ); -public record XmlCfg : imm.Recorded +public record XmlCfg : io.Recorded { public bool Verbose { get; init; } = false; public Datastructure Structure { get; init; } = Datastructure.Tree; @@ -254,7 +300,7 @@ public class TypeMetaCache GetFilters( _cfg.TypesDefault, type, out doImpls, out doFields, out doProps ); - var isImm = typeof( imm.Obj ).IsAssignableFrom( type ); + var isImm = typeof( io.Obj ).IsAssignableFrom( type ); var typesAtt = type.GetCustomAttribute( true ); var serTypes = typesAtt?.Types ?? ser.Types.None; @@ -264,7 +310,7 @@ public class TypeMetaCache { foreach( var fi in refl.GetAllFields( type ) ) { - ProcessMember( fi, serTypes.HasFlag( ser.Types.Fields ), children, doImpls, isImm, members ); + ProcessMember( fi, serTypes.HasFlag( ser.Types.Fields ), children, doImpls, isImm, members ); } @@ -274,7 +320,7 @@ public class TypeMetaCache { foreach( var pi in refl.GetAllProperties( type ) ) { - ProcessMember( pi, serTypes.HasFlag( ser.Types.Props ), children, doImpls, isImm, members ); + ProcessMember( pi, serTypes.HasFlag( ser.Types.Props ), children, doImpls, isImm, members ); } } @@ -686,7 +732,7 @@ public class XmlSer // : IFormatter XmlDocument doc = new XmlDocument(); try { doc.Load( reader ); } - catch( Exception ex ) { log.exception( ex, $"XML Load failed: {ex.Message}" ); return null; } + catch( Exception ex ) { log.exception( ex, $"XML Load failed: {ex.Message}" ); return null; } if( doc.DocumentElement == null ) return null; @@ -708,7 +754,8 @@ public class XmlSer // : IFormatter } catch( Exception ex ) { - log.exception( ex, $"XML Load failed: {ex.Message}" ); return; + log.exception( ex, $"XML Load failed: {ex.Message}" ); + return; } if( doc.DocumentElement == null ) diff --git a/ser/XmlSer_Read.cs b/ser/XmlSer_Read.cs index cf9b99f..2742153 100644 --- a/ser/XmlSer_Read.cs +++ b/ser/XmlSer_Read.cs @@ -151,35 +151,35 @@ public partial class ObjectHandler : ITypeHandler { - var (valueSource, isAttribute) = FindValueSource( elem, memberMeta.XmlName ); + var (valueSource, isAttribute) = FindValueSource( elem, memberMeta.XmlName ); - if( valueSource != null ) - { - object? memberValue; - object? currentMemberValue = memberMeta.GetValue( obj ); + if( valueSource != null ) + { + object? memberValue; + object? currentMemberValue = memberMeta.GetValue( obj ); - if( isAttribute ) - { - memberValue = xml._resolver.ConvertSimple( valueSource.Value!, memberMeta.Type ); - } - else // Child Element - { - memberValue = xml.ReadNode( (XmlElement)valueSource, memberMeta.Type, currentMemberValue ); - } + if( isAttribute ) + { + memberValue = xml._resolver.ConvertSimple( valueSource.Value!, memberMeta.Type ); + } + else // Child Element + { + memberValue = xml.ReadNode( (XmlElement)valueSource, memberMeta.Type, currentMemberValue ); + } - // Set value, respecting ser.Do/ser.Dont and pre-hydration - if( ShouldSetValue( memberMeta, existing != null ) ) - { - memberMeta.SetValue( obj, memberValue ); + // Set value, respecting ser.Do/ser.Dont and pre-hydration + if( ShouldSetValue( memberMeta, existing != null ) ) + { + memberMeta.SetValue( obj, memberValue ); + } } } - } } // 3. Post-processing if( obj is ser.I_Serialize iSer ) obj = iSer.OnDeserialize( null ); - if( ti.IsImm && obj is imm.Obj immObj ) + if( ti.IsImm && obj is io.Obj immObj ) return immObj.Record( $"From XML {elem.Name}" ); return obj; diff --git a/ser/XmlSer_Tests.cs b/ser/XmlSer_Tests.cs index 6d39013..428f57b 100644 --- a/ser/XmlSer_Tests.cs +++ b/ser/XmlSer_Tests.cs @@ -9,7 +9,7 @@ using System.Text; namespace ser; -public record class SimpleImmutable( string Name, int Age ) : imm.Timed; +public record class SimpleImmutable( string Name, int Age ) : io.Timed; static public class Test { @@ -91,7 +91,7 @@ static public class Test """; -//*/ + //*/ Debug.Assert( strXml != badXml ); memStream.Position = 0; @@ -104,7 +104,7 @@ static public class Test { - var xml = new ser.XmlSer(cfg, metaCache); + var xml = new ser.XmlSer( cfg, metaCache ); classHasFields2 = xml.Deserialize( memStream ); } @@ -117,7 +117,7 @@ static public class Test var classHasFields3 = new TrunkClass(); { - var xml = new ser.XmlSer(cfg, metaCache); + var xml = new ser.XmlSer( cfg, metaCache ); xml.DeserializeInto( memStream, classHasFields3 ); } diff --git a/ser/XmlSer_Write.cs b/ser/XmlSer_Write.cs index 8f33925..77758cb 100644 --- a/ser/XmlSer_Write.cs +++ b/ser/XmlSer_Write.cs @@ -150,7 +150,8 @@ public partial class ObjectHandler : ITypeHandler { foreach( var memberMeta in ti.Members ) { - if( !memberMeta.IsPodAttribute ) continue; + if( !memberMeta.IsPodAttribute ) + continue; var value = memberMeta.GetValue( obj ); if( value != null ) @@ -169,7 +170,8 @@ public partial class ObjectHandler : ITypeHandler foreach( var memberMeta in ti.Members ) { - if( memberMeta.IsPodAttribute ) continue; + if( memberMeta.IsPodAttribute ) + continue; var value = memberMeta.GetValue( obj ); if( value != null ) diff --git a/sharplib_be.sln b/sharplib_be.sln index 3a45cad..1099e88 100644 --- a/sharplib_be.sln +++ b/sharplib_be.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.002.0 diff --git a/srl/srl.Core.cs b/srl/srl.Core.cs new file mode 100644 index 0000000..05016fa --- /dev/null +++ b/srl/srl.Core.cs @@ -0,0 +1,375 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace srl; + +// --- INTERFACES --- + +public interface Driver +{ + // Structural + void BeginScope( string name, Type type, int id ); + void EndScope(); + void BeginCollection( string name, int count ); + void EndCollection(); + + // Data + void WriteAttr( string name, string value ); // Primitives & Compact Strings + void WriteRef( string name, int id ); // DAG/Cycle Reference + + // Metadata Hook + void OnProp( MemberInfo member, string name ); +} + +public interface IInput +{ + string? Value { get; } + bool IsLeaf { get; } + IInput? GetAttr( string name ); + IInput? GetChild( string name ); +} + +// --- THE MODEL (Introspection) --- + +public class TypePlan +{ + public string Name; + public bool IsCollection; + public bool IsHybrid; // True if Type has a StringParser registered + public StringParser Parser; // The "Compact" converter + public List Props = new(); +} + +public class PropPlan +{ + public string Name; + public string MemberName; + public Type Type; + public bool IsSmart; // Primitive/Enum/String + public MemberInfo Info; + + // Fast Accessors + public Func Getter; + public Action Setter; +} + +public static class Model +{ + private static Dictionary _cache = new(); + + public static TypePlan Get( Type t ) + { + if( _cache.TryGetValue( t, out var plan ) ) + return plan; + + plan = new TypePlan { Name = t.Name }; + + // 1. Check for Custom Parsers (Hybrid Mode) + if( Parsers.TryGet( t, out var parser ) ) + { + plan.IsHybrid = true; + plan.Parser = parser; + } + + // 2. Check for Collections + if( t != typeof( string ) && typeof( IEnumerable ).IsAssignableFrom( t ) ) + { + plan.IsCollection = true; + _cache[t] = plan; + return plan; + } + + // 3. Scan Properties + foreach( var p in t.GetProperties( BindingFlags.Public | BindingFlags.Instance ) ) + { + if( Attribute.IsDefined( p, typeof( IgnoreAttribute ) ) ) + continue; + + var prop = new PropPlan + { + Name = p.Name, // Default to PascalCase, Drivers can lower if needed + MemberName = p.Name, + Type = p.PropertyType, + Info = p, + Getter = ( o ) => p.GetValue( o ), + Setter = ( o, v ) => p.SetValue( o, v ) + }; + + // Override name + var nameAttr = p.GetCustomAttribute(); + if( nameAttr != null ) + prop.Name = nameAttr.Name; + + // Is "Smart" (Atomic)? + prop.IsSmart = prop.Type.IsPrimitive || prop.Type.IsEnum || + prop.Type == typeof( string ) || prop.Type == typeof( Guid ); + + plan.Props.Add( prop ); + } + + _cache[t] = plan; + return plan; + } +} + +// --- ATTRIBUTES --- +public class IgnoreAttribute : Attribute { } +public class NameAttribute : Attribute { public string Name; public NameAttribute( string n ) => Name = n; } + +// --- UTILITIES --- + +public struct StringParser +{ + public Func To; + public Func From; +} + +public static class Parsers +{ + private static Dictionary _registry = new(); + + public static void Register( Func to, Func from ) + { + _registry[typeof( T )] = new StringParser { To = o => to( (T)o ), From = s => from( s ) }; + } + + public static bool TryGet( Type t, out StringParser p ) + { + if( _registry.TryGetValue( t, out p ) ) + return true; + // Auto-Discovery could go here (Static Parse methods) + return false; + } +} + +public static class Binder +{ + // Handles "Cool.Rare" dot notation + public static void Apply( object root, string path, string value ) + { + var current = root; + var parts = path.Split( '.' ); + + for( int i = 0; i < parts.Length; i++ ) + { + var part = parts[i]; + var isLast = i == parts.Length - 1; + var plan = Model.Get( current.GetType() ); + + // Case-Insensitive Match + var prop = plan.Props.Find( p => p.Name.Equals( part, StringComparison.OrdinalIgnoreCase ) ); + if( prop == null ) + return; + + if( isLast ) + { + var val = ParseUtils.Convert( value, prop.Type ); + prop.Setter( current, val ); + } + else + { + var next = prop.Getter( current ); + if( next == null ) + { + next = Activator.CreateInstance( prop.Type ); + prop.Setter( current, next ); + } + current = next; + } + } + } +} + +public static class ParseUtils +{ + public static object Convert( string raw, Type t ) + { + if( t == typeof( string ) ) + return raw; + if( t == typeof( int ) ) + return int.Parse( raw ); + if( t == typeof( float ) ) + return float.Parse( raw.Replace( "f", "" ) ); + if( t == typeof( bool ) ) + return bool.Parse( raw ); + if( t.IsEnum ) + return Enum.Parse( t, raw ); + // Fallback to TypeConverter + var cv = TypeDescriptor.GetConverter( t ); + if( cv != null && cv.CanConvertFrom( typeof( string ) ) ) + return cv.ConvertFrom( raw ); + return null; + } + + public static void CopyFields( object src, object dst ) + { + foreach( var p in src.GetType().GetProperties() ) + if( p.CanRead && p.CanWrite ) + p.SetValue( dst, p.GetValue( src ) ); + } +} + +// --- THE ENGINE (Walker & Loader) --- + +public static class Walker +{ + public class Context + { + private Dictionary _seen = new( ReferenceEqualityComparer.Instance ); + private int _nextId = 1; + public (int, bool) GetId( object o ) + { + if( _seen.TryGetValue( o, out var id ) ) + return (id, false); + _seen[o] = _nextId; + return (_nextId++, true); + } + } + + public static void Serialize( object root, Driver d ) + { + if( root == null ) + return; + SerializeRecursive( root, d, new Context(), "root", null ); + } + + private static void SerializeRecursive( object obj, Driver d, Context ctx, string name, MemberInfo? member ) + { + if( obj == null ) + return; + + Type type = obj.GetType(); + var plan = Model.Get( type ); + + // STRATEGY 1: COMPACT (Hybrid Parser) + if( plan.IsHybrid ) + { + if( member != null ) + d.OnProp( member, name ); + d.WriteAttr( name, plan.Parser.To( obj ) ); + return; + } + + // STRATEGY 2: DAG CHECK + bool isRef = !type.IsValueType && type != typeof( string ); + if( isRef ) + { + var (id, isNew) = ctx.GetId( obj ); + if( !isNew ) + { d.WriteRef( name, id ); return; } + if( member != null ) + d.OnProp( member, name ); + d.BeginScope( name, type, id ); + } + else + { + if( member != null ) + d.OnProp( member, name ); + d.BeginScope( name, type, 0 ); + } + + // STRATEGY 3: COLLECTIONS + if( plan.IsCollection ) + { + var list = (IEnumerable)obj; + int count = 0; // Simple count (could optimize for ICollection) + foreach( var _ in list ) + count++; + + d.BeginCollection( name, count ); + foreach( var item in list ) + SerializeRecursive( item, d, ctx, "item", null ); + d.EndCollection(); + } + else + { + // STRATEGY 4: STANDARD OBJECT + foreach( var prop in plan.Props ) + { + var val = prop.Getter( obj ); + if( prop.IsSmart ) + { + d.OnProp( prop.Info, prop.Name ); + d.WriteAttr( prop.Name, val?.ToString() ?? "" ); + } + else + { + if( val != null ) + SerializeRecursive( val, d, ctx, prop.Name, prop.Info ); + } + } + } + d.EndScope(); + } +} + +public static class Loader +{ + public static void Load( object target, IInput input ) + { + if( target == null || input == null ) + return; + var plan = Model.Get( target.GetType() ); + + // 1. HYBRID PARSE (Compact String) + // If we have a parser AND input is just a value "1,1" + if( plan.IsHybrid && input.IsLeaf && !string.IsNullOrWhiteSpace( input.Value ) ) + { + try + { + var newObj = plan.Parser.From( input.Value ); + ParseUtils.CopyFields( newObj, target ); + return; + } + catch { } + } + + // 2. STRUCTURAL MAP + foreach( var prop in plan.Props ) + { + // Look for Attribute OR Child Element + var sub = input.GetAttr( prop.Name ) ?? input.GetChild( prop.Name ); + + // Look for Dot Notation (e.g. "Pos.X") in attributes + // (Note: This simple loop doesn't scan ALL attrs for dots, + // it relies on the caller or specific recursive logic. + // For full dot support on root, we need to iterate input attributes if possible. + // But 'Binder' below handles it if we pass the specific attr key). + + if( sub != null ) + { + if( prop.IsSmart ) + { + if( sub.Value != null ) + prop.Setter( target, ParseUtils.Convert( sub.Value, prop.Type ) ); + } + else + { + var child = prop.Getter( target ); + if( child == null ) + { + child = Activator.CreateInstance( prop.Type ); + prop.Setter( target, child ); + } + Load( child, sub ); + } + } + } + } + + // Helper to scan all attributes on an element for "Cool.Rare" patterns + public static void LoadDotNotations( object target, IEnumerable<(string k, string v)> attrs ) + { + foreach( var (k, v) in attrs ) + { + if( k.Contains( '.' ) ) + Binder.Apply( target, k, v ); + } + } +} + diff --git a/srl/srl.Debug.cs b/srl/srl.Debug.cs new file mode 100644 index 0000000..0012b07 --- /dev/null +++ b/srl/srl.Debug.cs @@ -0,0 +1,47 @@ +using System; +using System.Reflection; +using System.Text; + +namespace srl.Debug; + +public class DebugDriver : Driver +{ + private StringBuilder _sb = new(); + private int _indent = 0; + + public override string ToString() => _sb.ToString(); + + private void Line( string s ) => _sb.AppendLine( new string( ' ', _indent * 2 ) + s ); + + public void BeginScope( string name, Type type, int id ) + { + var refStr = id > 0 ? $" #{id}" : ""; + Line( $"[{name}] <{type.Name}>{refStr}" ); + _indent++; + } + + public void EndScope() => _indent--; + + public void BeginCollection( string name, int count ) + { + Line( $"[{name}] (Count: {count})" ); + _indent++; + } + + public void EndCollection() => _indent--; + + public void WriteAttr( string name, string value ) + { + Line( $"{name} = {value}" ); + } + + public void WriteRef( string name, int id ) + { + Line( $"{name} -> See #{id}" ); + } + + public void OnProp( MemberInfo m, string name ) + { + // Could log attributes here, e.g. [Tooltip] + } +} diff --git a/srl/srl.Xml.cs b/srl/srl.Xml.cs new file mode 100644 index 0000000..4101906 --- /dev/null +++ b/srl/srl.Xml.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Xml.Linq; +using System.Reflection; + +namespace srl.Xml; + +// --- INPUT ADAPTER --- +public class XmlAdapter : IInput +{ + private XElement _e; + private XAttribute _a; + + public XmlAdapter( XElement e ) => _e = e; + public XmlAdapter( XAttribute a ) => _a = a; + + public string? Value => _e?.Value ?? _a?.Value; + public bool IsLeaf => _a != null || ( _e != null && !_e.HasElements ); + + public IInput? GetAttr( string name ) + { + if( _e == null ) + return null; + // Case-Insensitive search + var a = _e.Attribute( name ) ?? _e.Attribute( name.ToLower() ); + return a != null ? new XmlAdapter( a ) : null; + } + + public IInput? GetChild( string name ) + { + if( _e == null ) + return null; + + var c = _e.Element( name ) ?? _e.Element( name.ToLower() ); + + return c != null ? new XmlAdapter( c ) : null; + } + + // Extra helper for Dot Notation scanning + public IEnumerable<(string, string)> GetAllAttrs() + { + if( _e == null ) + yield break; + foreach( var a in _e.Attributes() ) + yield return (a.Name.LocalName, a.Value); + } +} + +// --- OUTPUT DRIVER --- +public class XmlDriver : Driver +{ + private Stack _stack = new(); + private XDocument _doc; + + public XDocument Document => _doc; + + public XmlDriver() + { + _doc = new XDocument(); + } + + public void BeginScope( string name, Type type, int id ) + { + var el = new XElement( name ); + + // Polymorphism Metadata (if needed, e.g. ) + // el.Add(new XAttribute("_type", type.Name)); + + if( id > 0 ) + el.Add( new XAttribute( "_id", id ) ); // DAG ID + + if( _stack.Count > 0 ) + _stack.Peek().Add( el ); + else + _doc.Add( el ); + + _stack.Push( el ); + } + + public void EndScope() => _stack.Pop(); + + public void BeginCollection( string name, int count ) + { + // XML doesn't strictly need array wrappers, but it helps structure + // We use the same BeginScope logic effectively + var el = new XElement( name, new XAttribute( "_count", count ) ); + if( _stack.Count > 0 ) + _stack.Peek().Add( el ); + _stack.Push( el ); + } + + public void EndCollection() => _stack.Pop(); + + public void WriteAttr( string name, string value ) + { + if( _stack.Count == 0 ) + return; + _stack.Peek().Add( new XAttribute( name, value ) ); + } + + public void WriteRef( string name, int id ) + { + var el = new XElement( name, new XAttribute( "_ref", id ) ); + _stack.Peek().Add( el ); + } + + public void OnProp( MemberInfo m, string name ) { /* Optional: Write tooltips/comments */ } +} + +// --- FACADE --- +public static class XmlSerializer +{ + public static string Serialize( object obj ) + { + var driver = new XmlDriver(); + srl.Walker.Serialize( obj, driver ); + return driver.Document.ToString(); + } + + public static void Deserialize( object root, string xml ) + { + var doc = XDocument.Parse( xml ); + var adapter = new XmlAdapter( doc.Root ); + + // 1. Standard Load + srl.Loader.Load( root, adapter ); + + // 2. Dot Notation Pass (MyBag Cool.Rare="Changed") + srl.Loader.LoadDotNotations( root, adapter.GetAllAttrs() ); + } +} diff --git a/task/Task.cs b/task/Task.cs index 57c936f..f5bfdb7 100644 --- a/task/Task.cs +++ b/task/Task.cs @@ -13,4 +13,4 @@ static public class Task -} \ No newline at end of file +} diff --git a/tests/Tests.cs b/tests/Tests.cs index 95c9455..ca21138 100644 --- a/tests/Tests.cs +++ b/tests/Tests.cs @@ -10,7 +10,7 @@ using System.IO; namespace test; -public record class SimpleImmutable( string Name, int Age ) : imm.Timed; +public record class SimpleImmutable( string Name, int Age ) : io.Timed; static public class XmlFormatter2 { @@ -69,7 +69,7 @@ static public class XmlFormatter2 var memStream = new MemoryStream(); { - var xml = new lib.XmlFormatter2 ( cfg ); + var xml = new lib.XmlFormatter2( cfg ); xml.Serialize( memStream, classHasFields ); } @@ -96,7 +96,7 @@ static public class XmlFormatter2 { - var xml = new lib.XmlFormatter2 ( cfg ); + var xml = new lib.XmlFormatter2( cfg ); classHasFields2 = xml.Deserialize( memStream ); } @@ -109,7 +109,7 @@ static public class XmlFormatter2 var classHasFields3 = new ClassHasFields(); { - var xml = new lib.XmlFormatter2 ( cfg ); + var xml = new lib.XmlFormatter2( cfg ); xml.DeserializeInto( memStream, classHasFields3 ); } diff --git a/time/Timer.cs b/time/Timer.cs index 5deb926..9869ee2 100644 --- a/time/Timer.cs +++ b/time/Timer.cs @@ -6,7 +6,7 @@ using System.Threading; namespace lib { - public class MicroStopwatch: System.Diagnostics.Stopwatch + public class MicroStopwatch : System.Diagnostics.Stopwatch { readonly double _microSecPerTick = 1000000D / System.Diagnostics.Stopwatch.Frequency; @@ -109,11 +109,11 @@ namespace lib _stopTimer = false; - System.Threading.ThreadStart threadStart = delegate() + System.Threading.ThreadStart threadStart = delegate () { - NotificationTimer(ref _timerIntervalInMicroSec, + NotificationTimer( ref _timerIntervalInMicroSec, ref _ignoreEventIfLateBy, - ref _stopTimer); + ref _stopTimer ); }; _threadTimer = new System.Threading.Thread( threadStart ); @@ -141,7 +141,7 @@ namespace lib ref long ignoreEventIfLateBy, ref bool stopTimer ) { - int timerCount = 0; + int timerCount = 0; long nextNotification = 0; MicroStopwatch microStopwatch = new MicroStopwatch(); @@ -153,9 +153,9 @@ namespace lib microStopwatch.ElapsedMicroseconds - nextNotification; long timerIntervalInMicroSecCurrent = - System.Threading.Interlocked.Read(ref timerIntervalInMicroSec); + System.Threading.Interlocked.Read( ref timerIntervalInMicroSec ); long ignoreEventIfLateByCurrent = - System.Threading.Interlocked.Read(ref ignoreEventIfLateBy); + System.Threading.Interlocked.Read( ref ignoreEventIfLateBy ); nextNotification += timerIntervalInMicroSecCurrent; timerCount++; @@ -175,10 +175,10 @@ namespace lib } MicroTimerEventArgs microTimerEventArgs = - new MicroTimerEventArgs(timerCount, + new MicroTimerEventArgs( timerCount, elapsedMicroseconds, timerLateBy, - callbackFunctionExecutionTime); + callbackFunctionExecutionTime ); MicroTimerElapsed( this, microTimerEventArgs ); } @@ -189,7 +189,7 @@ namespace lib /// /// MicroTimer Event Argument class /// - public class MicroTimerEventArgs: EventArgs + public class MicroTimerEventArgs : EventArgs { // Simple counter, number times timed event (callback function) executed public int TimerCount { get; private set; } diff --git a/util/Debug.cs b/util/Debug.cs index 416fa7b..8047888 100644 --- a/util/Debug.cs +++ b/util/Debug.cs @@ -12,7 +12,7 @@ static public class DebugEx { - extension(StackFrame sf) + extension( StackFrame sf ) { public string Method => sf.GetMethod().Name; public string File => sf.GetFileName(); @@ -25,4 +25,4 @@ static public class DebugEx -} \ No newline at end of file +} diff --git a/util/Guid.cs b/util/Guid.cs index b06d820..dbcf9a5 100644 --- a/util/Guid.cs +++ b/util/Guid.cs @@ -7,7 +7,7 @@ using System; public static class GuidExt { - extension(Guid g) + extension( Guid g ) { public string Log => $"{g.LastUShort():X8}"; } diff --git a/util/LinqExtensions.cs b/util/LinqExtensions.cs index ba279d7..c86737e 100644 --- a/util/LinqExtensions.cs +++ b/util/LinqExtensions.cs @@ -7,11 +7,11 @@ using System.Collections.Generic; public static class Enumerables { - public static void ForEach(this IEnumerable @this, Action action) + public static void ForEach( this IEnumerable @this, Action action ) { - foreach (T item in @this) + foreach( T item in @this ) { - action(item); + action( item ); } } -} \ No newline at end of file +} diff --git a/util/Pod.cs b/util/Pod.cs index 3032864..2ca0925 100644 --- a/util/Pod.cs +++ b/util/Pod.cs @@ -8,6 +8,6 @@ public static class PodExt { extension( Boolean b ) { - public int Int => b?1:0; + public int Int => b ? 1 : 0; } }; diff --git a/util/RandomEx.cs b/util/RandomEx.cs index ea01cd1..40de9e7 100644 --- a/util/RandomEx.cs +++ b/util/RandomEx.cs @@ -5,15 +5,15 @@ public static class RandomEx { -/* -// NextBytes work fine - public static void FillBytes( this Random rnd, ref byte[] buffer ) - { - rnd.NextBytes() - - for( int i = 0; i < buffer.Length; ++i ) + /* + // NextBytes work fine + public static void FillBytes( this Random rnd, ref byte[] buffer ) { - } + rnd.NextBytes() -*/ -} \ No newline at end of file + for( int i = 0; i < buffer.Length; ++i ) + { + } + + */ +} diff --git a/util/StringEx.cs b/util/StringEx.cs index a92a03d..06618d6 100644 --- a/util/StringEx.cs +++ b/util/StringEx.cs @@ -23,7 +23,7 @@ public static class StringEx return -1; } - -} \ No newline at end of file + +}