diff --git a/SharpLib.csproj b/SharpLib.csproj
index 9926905..99cb4fe 100644
--- a/SharpLib.csproj
+++ b/SharpLib.csproj
@@ -1,41 +1,41 @@
-
- net9.0;net10.0
- lib
- 0.0.1.0
- 0.0.1.0
- 2003..2025 Marc Hernandez
- A core set of libraries
- AnyCPU;x64
- true
- true
- 14.0
- Copyright 2003..2025 Marc Hernandez
- A base set of
+
+ net9.0;net10.0
+ lib
+ 0.0.1.0
+ 0.0.1.0
+ 2003..2025 Marc Hernandez
+ A core set of libraries
+ AnyCPU;x64
+ true
+ true
+ 14.0
+ Copyright 2003..2025 Marc Hernandez
+ A base set of
- $(NoWarn);SYSLIB0050;CS8981; CS8632
-
+ $(NoWarn);SYSLIB0050;CS8981; CS8632
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
-
+
-
+
diff --git a/imm/FSM.cs b/imm/FSM.cs
index 3f066bf..7c4e86f 100644
--- a/imm/FSM.cs
+++ b/imm/FSM.cs
@@ -12,7 +12,7 @@ public abstract record class FsmContextBase : io.Recorded
where TSelf : FsmContextBase
{
// Required for 'with' expressions.
- protected FsmContextBase(io.Recorded original) : base(original) { }
+ protected FsmContextBase( io.Recorded original ) : base( original ) { }
protected FsmContextBase() { }
}
@@ -29,7 +29,7 @@ public abstract record class FsmStateBase : io.Recorded
///
/// 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,13 +37,13 @@ public abstract record class FsmStateBase : io.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(io.Recorded original) : base(original) { }
+ protected FsmStateBase( io.Recorded original ) : base( original ) { }
protected FsmStateBase() { }
}
@@ -62,14 +62,14 @@ public abstract record class FsmBase : io.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(io.Recorded original) : base(original)
+ protected FsmBase( io.Recorded original ) : base( original )
{
var o = original as FsmBase;
Context = o!.Context;
@@ -86,12 +86,12 @@ public abstract record class FsmBase : io.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 'io.Recorded', we can call the
// detailed 'Process'. If 'this' is actually 'Timed', C#'s
diff --git a/imm/Imm.cs b/imm/Imm.cs
index 5fc8745..d602eb1 100644
--- a/imm/Imm.cs
+++ b/imm/Imm.cs
@@ -9,43 +9,43 @@ using System.Runtime.CompilerServices;
///
public static class imm
{
- ///
- /// Processes a 'Versioned' object (Level 1).
- ///
- public static T LightProcess(
- ref T obj,
- Func fn,
- string reason = "Processed" )
- where T : io.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 : 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 = "" )
+ ///
+ /// Processes a 'Versioned' object (Level 1).
+ ///
+ public static T LightProcess(
+ ref T obj,
+ Func fn,
+ string reason = "Processed" )
+ where T : io.Versioned
{
- return $"{dbgExpCur} changed from {old} to {cur}";
+ obj = obj.Process( fn, reason );
+ return obj;
}
- // No specific Process needed for Timed, as it's caught by Recorded
- // and its Process override handles the timing.
+ ///
+ /// 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 : 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.
}
diff --git a/imm/List.cs b/imm/List.cs
index 70dae60..8aefe53 100644
--- a/imm/List.cs
+++ b/imm/List.cs
@@ -13,56 +13,56 @@ namespace io;
///
public record class List : Timed>, IImmutableList
{
- static public List Empty { get; } = new();
+ static public List Empty { get; } = new();
- public ImmutableList Values { get; init; } = ImmutableList.Empty;
+ public ImmutableList Values { get; init; } = ImmutableList.Empty;
- public List() { }
- // Required for 'with' expressions to work with the base class hierarchy
- protected List(Timed> original) : base(original) { }
+ public List() { }
+ // Required for 'with' expressions to work with the base class hierarchy
+ protected List( Timed> original ) : base( original ) { }
- // Helper to apply changes using the Process method
- private List Change(
- Func, ImmutableList> listChange,
- [CallerMemberName] string dbgMethod = "",
- [CallerFilePath] string dbgPath = "",
- [CallerLineNumber] int dbgLine = -1,
- [CallerArgumentExpression( "listChange" )] string reason = "" )
- {
- var newValues = listChange(Values);
- return ReferenceEquals(Values, newValues)
- ? this
- : Process(l => l with { Values = newValues }, reason, dbgMethod, dbgPath, dbgLine, reason);
- }
+ // Helper to apply changes using the Process method
+ private List Change(
+ Func, ImmutableList> listChange,
+ [CallerMemberName] string dbgMethod = "",
+ [CallerFilePath] string dbgPath = "",
+ [CallerLineNumber] int dbgLine = -1,
+ [CallerArgumentExpression( "listChange" )] string reason = "" )
+ {
+ var newValues = listChange( Values );
+ return ReferenceEquals( Values, newValues )
+ ? this
+ : 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;
+ // --- 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);
- #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 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 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 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 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.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 );
@@ -74,9 +74,9 @@ public record class List : Timed>, IImmutableList
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
+ #endregion
- // --- Standard Interfaces ---
- public IEnumerator GetEnumerator() => Values.GetEnumerator();
- IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)Values).GetEnumerator();
+ // --- Standard Interfaces ---
+ public IEnumerator GetEnumerator() => Values.GetEnumerator();
+ IEnumerator IEnumerable.GetEnumerator() => ( (IEnumerable)Values ).GetEnumerator();
}
diff --git a/imm/io.cs b/imm/io.cs
index 840d319..9cc2300 100644
--- a/imm/io.cs
+++ b/imm/io.cs
@@ -261,7 +261,8 @@ public record class Recorded : Versioned where T : Recorded
if( ReferenceEquals( current, next ) )
return current;
- var newMeta = current.Meta with {
+ var newMeta = current.Meta with
+ {
Version = current.Meta.Version + 1,
Reason = reason,
MemberName = dbgName,
diff --git a/lib/CodeGen.cs b/lib/CodeGen.cs
index e1bd6e7..1488112 100644
--- a/lib/CodeGen.cs
+++ b/lib/CodeGen.cs
@@ -19,164 +19,164 @@ namespace ser;
public record CodeGenConfig : io.Recorded
{
- // Whitelists (if needed, otherwise rely on attributes/defaults)
- public ImmutableDictionary> WLProps { get; init; } = ImmutableDictionary>.Empty;
- public ImmutableDictionary> WLFields { get; init; } = ImmutableDictionary>.Empty;
+ // Whitelists (if needed, otherwise rely on attributes/defaults)
+ public ImmutableDictionary> WLProps { get; init; } = ImmutableDictionary>.Empty;
+ public ImmutableDictionary> WLFields { get; init; } = ImmutableDictionary>.Empty;
- // Default member types to process
- public ser.Types TypesDefault { get; init; } = ser.Types.Fields | ser.Types.Props;
+ // Default member types to process
+ public ser.Types TypesDefault { get; init; } = ser.Types.Fields | ser.Types.Props;
- // How to handle backing fields (might be less relevant for code gen)
- public BackingFieldNaming Naming { get; init; } = BackingFieldNaming.Regular;
+ // How to handle backing fields (might be less relevant for code gen)
+ public BackingFieldNaming Naming { get; init; } = BackingFieldNaming.Regular;
- public static CodeGenConfig Default { get; } = new CodeGenConfig();
+ public static CodeGenConfig Default { get; } = new CodeGenConfig();
}
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(
- Type Type,
- List Members,
- bool IsValueType,
- bool IsCollection
+ Type Type,
+ List Members,
+ bool IsValueType,
+ bool IsCollection
);
public class TypeStructureAnalyzer
{
- private readonly ConcurrentDictionary _cache = new();
- private readonly CodeGenConfig _cfg;
+ 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 )
- {
- 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 );
+ 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 );
- // Track processed names to avoid duplicates (e.g., field + prop)
- var processedNames = new HashSet();
+ // Track processed names to avoid duplicates (e.g., field + prop)
+ var processedNames = new HashSet();
- // Process Properties First (often preferred interface)
- if( doProps )
- {
- foreach( var pi in refl.GetAllProperties( type ) )
- {
- if( ProcessMember( pi, false, false, new HashSet(), false, members ) )
- {
- processedNames.Add( pi.Name );
- }
- }
- }
+ // Process Properties First (often preferred interface)
+ if( doProps )
+ {
+ foreach( var pi in refl.GetAllProperties( type ) )
+ {
+ if( ProcessMember( pi, false, false, new HashSet(), false, members ) )
+ {
+ processedNames.Add( pi.Name );
+ }
+ }
+ }
- // Process Fields, avoiding those already covered by properties
- if( doFields )
- {
- foreach( var fi in refl.GetAllFields( type ) )
- {
- var (isBacking, propName) = IsBackingField( fi );
- string nameToTest = isBacking ? propName : fi.Name;
+ // Process Fields, avoiding those already covered by properties
+ if( doFields )
+ {
+ foreach( var fi in refl.GetAllFields( type ) )
+ {
+ var (isBacking, propName) = IsBackingField( fi );
+ string nameToTest = isBacking ? propName : fi.Name;
- if( !processedNames.Contains( nameToTest ) )
- {
- if( ProcessMember( fi, false, false, new HashSet(), false, members ) )
- {
- processedNames.Add( nameToTest );
- }
- }
- }
- }
+ if( !processedNames.Contains( nameToTest ) )
+ {
+ if( ProcessMember( fi, false, false, new HashSet(), false, members ) )
+ {
+ processedNames.Add( nameToTest );
+ }
+ }
+ }
+ }
- return new TypeStructureInfo(
- type,
- members,
- type.IsValueType,
- typeof( IEnumerable ).IsAssignableFrom( type ) && type != typeof( string )
- );
- }
+ return new TypeStructureInfo(
+ type,
+ members,
+ type.IsValueType,
+ typeof( IEnumerable ).IsAssignableFrom( type ) && type != typeof( string )
+ );
+ }
- private bool ProcessMember( MemberInfo mi, bool filter, bool doImpls, HashSet whitelist, bool isImm, List members )
- {
- var (hasDo, hasDont, propName) = GetMemberAttributes( mi, out var actualMiForAtts );
+ private bool ProcessMember( MemberInfo mi, bool filter, bool doImpls, HashSet whitelist, bool isImm, List members )
+ {
+ 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.)
+ // 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(
- mi, type, name, isPrimitive, isCollection, elementType, hasDo, hasDont
- ) );
- return true;
- }
+ members.Add( new GenMemberMeta(
+ mi, type, name, isPrimitive, isCollection, elementType, hasDo, hasDont
+ ) );
+ return true;
+ }
- 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 ));
- }
- }
- return (false, "");
- }
+ 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 ));
+ }
+ }
+ return (false, "");
+ }
- 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 )
- {
- 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;
- }
+ 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 )
+ {
+ 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 (
- actualMi.GetCustomAttribute() != null,
- actualMi.GetCustomAttribute() != null,
- propName
- );
- }
+ return (
+ actualMi.GetCustomAttribute() != null,
+ actualMi.GetCustomAttribute() != null,
+ propName
+ );
+ }
- 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
- }
+ 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
+ }
- // Add GetFilters and FilterField if needed, or simplify as above
+ // Add GetFilters and FilterField if needed, or simplify as above
}
diff --git a/lib/XmlFormatter2.cs b/lib/XmlFormatter2.cs
index 715f1be..41cd61d 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(io.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,7 +648,7 @@ namespace lib
}
}
- if(!isImm)
+ if( !isImm )
{
return obj;
}
@@ -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(io.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/Log.cs b/logging/Log.cs
index 4dc67e9..439718a 100644
--- a/logging/Log.cs
+++ b/logging/Log.cs
@@ -174,14 +174,14 @@ static public class log
{
None = 0,
- File = 1 << 0,
+ File = 1 << 0,
Console = 1 << 1,
All = File | Console,
}
-#region LogEvent
+ #region LogEvent
public struct LogEvent
{
@@ -256,7 +256,7 @@ static public class log
ImmutableInterlocked.AddOrUpdate( ref s_logEPforCat, cat, ep, ( k, v ) => ep );
}
-#endregion // LogEvent
+ #endregion // LogEvent
static public void shutdown()
{
@@ -299,7 +299,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; } );
@@ -396,32 +396,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 );
}
@@ -456,12 +456,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
@@ -523,7 +523,7 @@ static public class log
foreach( var fr in stackTrace.GetFrames() )
{
- logBase( $"{fr.Log}", LogType.Raw );
+ logBase( $"{fr.Log}", LogType.Raw );
}
}
@@ -546,14 +546,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/math/Half.cs b/math/Half.cs
index 5791e0b..583a819 100644
--- a/math/Half.cs
+++ b/math/Half.cs
@@ -29,239 +29,239 @@ using System.Runtime.Serialization;
namespace math
{
- ///
- /// A half precision (16 bit) floating point value.
- ///
- [DataContract]
- [StructLayout( LayoutKind.Sequential, Pack = 2 )]
- public struct Half
- {
- private ushort value;
+ ///
+ /// A half precision (16 bit) floating point value.
+ ///
+ [DataContract]
+ [StructLayout( LayoutKind.Sequential, Pack = 2 )]
+ public struct Half
+ {
+ private ushort value;
- ///
- /// Number of decimal digits of precision.
- ///
- public const int PrecisionDigits = 3;
+ ///
+ /// Number of decimal digits of precision.
+ ///
+ public const int PrecisionDigits = 3;
- ///
- /// Number of bits in the mantissa.
- ///
- public const int MantissaBits = 11;
+ ///
+ /// Number of bits in the mantissa.
+ ///
+ public const int MantissaBits = 11;
- ///
- /// Maximum decimal exponent.
- ///
- public const int MaximumDecimalExponent = 4;
+ ///
+ /// Maximum decimal exponent.
+ ///
+ public const int MaximumDecimalExponent = 4;
- ///
- /// Maximum binary exponent.
- ///
- public const int MaximumBinaryExponent = 15;
+ ///
+ /// Maximum binary exponent.
+ ///
+ public const int MaximumBinaryExponent = 15;
- ///
- /// Minimum decimal exponent.
- ///
- public const int MinimumDecimalExponent = -4;
+ ///
+ /// Minimum decimal exponent.
+ ///
+ public const int MinimumDecimalExponent = -4;
- ///
- /// Minimum binary exponent.
- ///
- public const int MinimumBinaryExponent = -14;
+ ///
+ /// Minimum binary exponent.
+ ///
+ public const int MinimumBinaryExponent = -14;
- ///
- /// Exponent radix.
- ///
- public const int ExponentRadix = 2;
+ ///
+ /// Exponent radix.
+ ///
+ public const int ExponentRadix = 2;
- ///
- /// Additional rounding.
- ///
- public const int AdditionRounding = 1;
+ ///
+ /// Additional rounding.
+ ///
+ public const int AdditionRounding = 1;
- ///
- /// Smallest such that 1.0 + epsilon != 1.0
- ///
- public static readonly float Epsilon;
+ ///
+ /// Smallest such that 1.0 + epsilon != 1.0
+ ///
+ public static readonly float Epsilon;
- ///
- /// Maximum value of the number.
- ///
- public static readonly float MaxValue;
+ ///
+ /// Maximum value of the number.
+ ///
+ public static readonly float MaxValue;
- ///
- /// Minimum value of the number.
- ///
- public static readonly float MinValue;
+ ///
+ /// Minimum value of the number.
+ ///
+ public static readonly float MinValue;
- ///
- /// A whose value is 0.0f.
- ///
- public static readonly Half Zero;
+ ///
+ /// A whose value is 0.0f.
+ ///
+ public static readonly Half Zero;
- ///
- /// A whose value is 1.0f.
- ///
- public static readonly Half One;
+ ///
+ /// A whose value is 1.0f.
+ ///
+ public static readonly Half One;
- ///
- /// Initializes a new instance of the structure.
- ///
- /// The floating point value that should be stored in 16 bit format.
- public Half( float value )
- {
- this.value = HalfUtils.Pack( value );
- }
+ ///
+ /// Initializes a new instance of the structure.
+ ///
+ /// The floating point value that should be stored in 16 bit format.
+ public Half( float value )
+ {
+ this.value = HalfUtils.Pack( value );
+ }
- ///
- /// Gets or sets the raw 16 bit value used to back this half-float.
- ///
- public ushort RawValue
- {
- get { return value; }
- set { this.value = value; }
- }
+ ///
+ /// Gets or sets the raw 16 bit value used to back this half-float.
+ ///
+ public ushort RawValue
+ {
+ get { return value; }
+ set { this.value = value; }
+ }
- ///
- /// Converts an array of half precision values into full precision values.
- ///
- /// The values to be converted.
- /// An array of converted 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 );
- return results;
- }
+ ///
+ /// Converts an array of half precision values into full precision values.
+ ///
+ /// The values to be converted.
+ /// An array of converted 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 );
+ return results;
+ }
- ///
- /// Converts an array of full precision values into half precision values.
- ///
- /// The values to be converted.
- /// An array of converted 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] );
- return results;
- }
+ ///
+ /// Converts an array of full precision values into half precision values.
+ ///
+ /// The values to be converted.
+ /// An array of converted 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] );
+ return results;
+ }
- ///
- /// Performs an explicit conversion from to .
- ///
- /// The value to be converted.
- /// The converted value.
- public static explicit operator Half( float value )
- {
- return new Half( value );
- }
+ ///
+ /// Performs an explicit conversion from to .
+ ///
+ /// The value to be converted.
+ /// The converted value.
+ public static explicit operator Half( float value )
+ {
+ return new Half( value );
+ }
- ///
- /// Performs an implicit conversion from to .
- ///
- /// The value to be converted.
- /// The converted value.
- public static implicit operator float( Half value )
- {
- return HalfUtils.Unpack( value.value );
- }
+ ///
+ /// Performs an implicit conversion from to .
+ ///
+ /// The value to be converted.
+ /// The converted value.
+ public static implicit operator float( Half value )
+ {
+ return HalfUtils.Unpack( value.value );
+ }
- ///
- /// Tests for equality between two objects.
- ///
- /// The first value to compare.
- /// The second value to compare.
- ///
- /// true if has the same value as ; otherwise, false.
- public static bool operator ==( Half left, Half right )
- {
- return left.value == right.value;
- }
+ ///
+ /// Tests for equality between two objects.
+ ///
+ /// The first value to compare.
+ /// The second value to compare.
+ ///
+ /// true if has the same value as ; otherwise, false.
+ public static bool operator ==( Half left, Half right )
+ {
+ return left.value == right.value;
+ }
- ///
- /// Tests for inequality between two objects.
- ///
- /// The first value to compare.
- /// The second value to compare.
- ///
- /// true if has a different value than ; otherwise, false.
- public static bool operator !=( Half left, Half right )
- {
- return left.value != right.value;
- }
+ ///
+ /// Tests for inequality between two objects.
+ ///
+ /// The first value to compare.
+ /// The second value to compare.
+ ///
+ /// true if has a different value than ; otherwise, false.
+ public static bool operator !=( Half left, Half right )
+ {
+ return left.value != right.value;
+ }
- ///
- /// Converts the value of the object to its equivalent string representation.
- ///
- /// The string representation of the value of this instance.
- public override string ToString()
- {
- float num = this;
- return num.ToString( CultureInfo.CurrentCulture );
- }
+ ///
+ /// Converts the value of the object to its equivalent string representation.
+ ///
+ /// The string representation of the value of this instance.
+ public override string ToString()
+ {
+ float num = this;
+ return num.ToString( CultureInfo.CurrentCulture );
+ }
- ///
- /// Returns the hash code for this instance.
- ///
- /// A 32-bit signed integer hash code.
- public override int GetHashCode()
- {
- ushort num = value;
- return ( ( num * 3 ) / 2 ) ^ num;
- }
+ ///
+ /// Returns the hash code for this instance.
+ ///
+ /// A 32-bit signed integer hash code.
+ public override int GetHashCode()
+ {
+ ushort num = value;
+ return ( ( num * 3 ) / 2 ) ^ num;
+ }
- ///
- /// Determines whether the specified object instances are considered equal.
- ///
- /// The first value.
- /// The second value.
- ///
- /// 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 )
- {
- return value1.value == value2.value;
- }
+ ///
+ /// Determines whether the specified object instances are considered equal.
+ ///
+ /// The first value.
+ /// The second value.
+ ///
+ /// 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 )
+ {
+ return value1.value == value2.value;
+ }
- ///
- /// 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( Half other )
- {
- return other.value == value;
- }
+ ///
+ /// 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( Half other )
+ {
+ return other.value == value;
+ }
- ///
- /// 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 )
- {
- if( obj == null )
- {
- return false;
- }
- if( obj.GetType() != GetType() )
- {
- return false;
- }
- Half half = (Half)obj;
- return half.value == value;
- }
+ ///
+ /// 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 )
+ {
+ if( obj == null )
+ {
+ return false;
+ }
+ if( obj.GetType() != GetType() )
+ {
+ return false;
+ }
+ Half half = (Half)obj;
+ return half.value == value;
+ }
- static Half()
- {
- Epsilon = 0.0004887581f;
- MaxValue = 65504f;
- MinValue = 6.103516E-05f;
- Zero = (Half)0.0f;
- One = (Half)1.0f;
- }
- }
+ static Half()
+ {
+ Epsilon = 0.0004887581f;
+ MaxValue = 65504f;
+ MinValue = 6.103516E-05f;
+ Zero = (Half)0.0f;
+ One = (Half)1.0f;
+ }
+ }
}
diff --git a/math/Int3.cs b/math/Int3.cs
index 8ce2ac4..585fb6b 100644
--- a/math/Int3.cs
+++ b/math/Int3.cs
@@ -33,741 +33,741 @@ using System.Runtime.Serialization;
namespace math
{
- ///
- /// Represents a three dimensional mathematical vector.
- ///
- [DataContract( Name = "Int3" )]
- [DataStyle( DataStyle.Compact )]
- [StructLayout( LayoutKind.Sequential, Pack = 4 )]
- public struct Int3 : IEquatable, IFormattable
- {
- ///
- /// The size of the type, in bytes.
- ///
- public static readonly int SizeInBytes = lib.Util.SizeOf();
-
- ///
- /// A with all of its components set to zero.
- ///
- public static readonly Int3 Zero = new Int3();
-
- ///
- /// The X unit (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 );
-
- ///
- /// The Z unit (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 );
-
- ///
- /// The X component of the vector.
- ///
- [DataMember( Order = 0 )]
- public int X;
-
- ///
- /// The Y component of the vector.
- ///
- [DataMember( Order = 1 )]
- public int Y;
-
- ///
- /// The Z component of the vector.
- ///
- [DataMember( Order = 2 )]
- public int Z;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The value that will be assigned to all components.
- public Int3( int value )
- {
- X = value;
- Y = value;
- Z = value;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// 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 )
- {
- X = x;
- Y = y;
- Z = z;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// 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 )
- {
- X = (int)value.X;
- Y = (int)value.Y;
- Z = z;
- }
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// 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 )
- {
- 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];
- Z = values[2];
- }
-
- ///
- /// Gets or sets the component at the specified index.
- ///
- /// The value of the X, Y, or Z component, depending on the index.
- /// The index of the component to access. Use 0 for the X component, 1 for the Y component, and 2 for the Z component.
- /// The value of the component at the specified index.
- /// Thrown when the is out of the range [0, 2].
- public int this[int index]
- {
- get
- {
- switch( index )
- {
- 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." );
- }
-
- set
- {
- 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." );
- }
- }
- }
-
- ///
- /// Calculates the length of the vector.
- ///
- /// The length of the vector.
- ///
- /// may be preferred when only the relative length is needed
- /// and speed is of the essence.
- ///
- public int Length()
- {
- return (int)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) );
- }
-
- ///
- /// Calculates the squared length of the vector.
- ///
- /// The squared length of the vector.
- ///
- /// This method may be preferred to when only a relative length is needed
- /// and speed is of the essence.
- ///
- public int LengthSquared()
- {
- return ( X * X ) + ( Y * Y ) + ( Z * Z );
- }
-
- ///
- /// Raises the exponent for each components.
- ///
- /// The exponent.
- public void Pow( int exponent )
- {
- X = (int)Math.Pow( X, exponent );
- Y = (int)Math.Pow( Y, exponent );
- Z = (int)Math.Pow( Z, exponent );
- }
-
- ///
- /// Creates an array containing the elements of the vector.
- ///
- /// A three-element array containing the components of the vector.
- public int[] ToArray()
- {
- return new int[] { X, Y, Z };
- }
-
- ///
- /// Adds two vectors.
- ///
- /// 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 )
- {
- result = new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z );
- }
-
- ///
- /// Adds two vectors.
- ///
- /// The first vector to add.
- /// The second vector to add.
- /// The sum of the two vectors.
- public static Int3 Add( Int3 left, Int3 right )
- {
- return new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z );
- }
-
- ///
- /// Subtracts two vectors.
- ///
- /// 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 )
- {
- result = new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z );
- }
-
- ///
- /// Subtracts two vectors.
- ///
- /// The first vector to subtract.
- /// The second vector to subtract.
- /// The difference of the two vectors.
- public static Int3 Subtract( Int3 left, Int3 right )
- {
- return new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// 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 )
- {
- result = new Int3( value.X * scale, value.Y * scale, value.Z * scale );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// The vector to scale.
- /// The amount by which to scale the vector.
- /// The scaled vector.
- public static Int3 Multiply( Int3 value, int scale )
- {
- return new Int3( 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.
- 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 );
- }
-
- ///
- /// Modulates a vector with another by performing component-wise multiplication.
- ///
- /// The first vector to modulate.
- /// The second vector to modulate.
- /// The modulated vector.
- public static Int3 Modulate( Int3 left, Int3 right )
- {
- return new Int3( left.X * right.X, left.Y * right.Y, left.Z * right.Z );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// 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 )
- {
- result = new Int3( value.X / scale, value.Y / scale, value.Z / scale );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// The vector to scale.
- /// The amount by which to scale the vector.
- /// The scaled vector.
- public static Int3 Divide( Int3 value, int scale )
- {
- return new Int3( value.X / scale, value.Y / scale, value.Z / scale );
- }
-
- ///
- /// Reverses the direction of a given vector.
- ///
- /// 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 )
- {
- result = new Int3( -value.X, -value.Y, -value.Z );
- }
-
- ///
- /// Reverses the direction of a given vector.
- ///
- /// The vector to negate.
- /// A vector facing in the opposite direction.
- public static Int3 Negate( Int3 value )
- {
- return new Int3( -value.X, -value.Y, -value.Z );
- }
-
- ///
- /// Restricts a value to be within a specified range.
- ///
- /// The value to clamp.
- /// 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 )
- {
- int x = value.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;
-
- int z = value.Z;
- z = ( z > max.Z ) ? max.Z : z;
- z = ( z < min.Z ) ? min.Z : z;
-
- result = new Int3( x, y, z );
- }
-
- ///
- /// Restricts a value to be within a specified range.
- ///
- /// The value to clamp.
- /// The minimum value.
- /// The maximum value.
- /// The clamped value.
- public static Int3 Clamp( Int3 value, Int3 min, Int3 max )
- {
- Int3 result;
- Clamp( ref value, ref min, ref max, out result );
- return result;
- }
-
- ///
- /// Calculates the dot product of two vectors.
- ///
- /// 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 )
- {
- result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z );
- }
-
- ///
- /// Calculates the dot product of two vectors.
- ///
- /// First source vector.
- /// Second source vector.
- /// The dot product of the two vectors.
- public static int Dot( Int3 left, Int3 right )
- {
- return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z );
- }
-
- ///
- /// Performs a linear interpolation between two vectors.
- ///
- /// Start vector.
- /// End vector.
- /// Value between 0 and 1 indicating the weight of .
- /// When the method completes, contains the linear interpolation of the two vectors.
- ///
- /// 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.
- ///
- 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 ) );
- }
-
- ///
- /// Performs a linear interpolation between two vectors.
- ///
- /// Start vector.
- /// End vector.
- /// Value between 0 and 1 indicating the weight of .
- /// The linear interpolation of the two vectors.
- ///
- /// 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.
- ///
- public static Int3 Lerp( Int3 start, Int3 end, float amount )
- {
- Int3 result;
- Lerp( ref start, ref end, amount, out result );
- return result;
- }
-
- ///
- /// Performs a cubic interpolation between two vectors.
- ///
- /// Start vector.
- /// 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 )
- {
- 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 ) );
- }
-
- ///
- /// Performs a cubic interpolation between two vectors.
- ///
- /// Start vector.
- /// 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 )
- {
- Int3 result;
- SmoothStep( ref start, ref end, amount, out result );
- return result;
- }
-
- ///
- /// Returns a vector containing the smallest components of the specified vectors.
- ///
- /// 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 )
- {
- 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;
- }
-
- ///
- /// Returns a vector containing the largest components of the specified vectors.
- ///
- /// 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 )
- {
- Int3 result;
- Max( ref left, ref right, out result );
- return result;
- }
-
- ///
- /// Returns a vector containing the smallest components of the specified vectors.
- ///
- /// 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 )
- {
- 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;
- }
-
- ///
- /// Returns a vector containing the smallest components of the specified vectors.
- ///
- /// 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 )
- {
- Int3 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 )
- {
- return new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z );
- }
-
- ///
- /// Assert a vector (return it unchanged).
- ///
- /// The vector to assert (unchange).
- /// The asserted (unchanged) vector.
- public static Int3 operator +( Int3 value )
- {
- return value;
- }
-
- ///
- /// Subtracts two vectors.
- ///
- /// The first vector to subtract.
- /// The second vector to subtract.
- /// The difference of the two vectors.
- public static Int3 operator -( Int3 left, Int3 right )
- {
- return new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z );
- }
-
- ///
- /// Reverses the direction of a given vector.
- ///
- /// The vector to negate.
- /// A vector facing in the opposite direction.
- public static Int3 operator -( Int3 value )
- {
- return new Int3( -value.X, -value.Y, -value.Z );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// The vector to scale.
- /// The amount by which to scale the vector.
- /// The scaled vector.
- public static Int3 operator *( float scale, Int3 value )
- {
- return new Int3( (int)( value.X * scale ), (int)( value.Y * scale ), (int)( value.Z * scale ) );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// The vector to scale.
- /// The amount by which to scale the vector.
- /// The scaled vector.
- public static Int3 operator *( Int3 value, float scale )
- {
- return new Int3( (int)( value.X * scale ), (int)( value.Y * scale ), (int)( value.Z * scale ) );
- }
-
- ///
- /// Scales a vector by the given value.
- ///
- /// The vector to scale.
- /// The amount by which to scale the vector.
- /// The scaled vector.
- public static Int3 operator /( Int3 value, float scale )
- {
- return new Int3( (int)( value.X / scale ), (int)( value.Y / scale ), (int)( value.Z / scale ) );
- }
-
- ///
- /// Tests for equality between two objects.
- ///
- /// 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 )
- {
- return left.Equals( right );
- }
-
- ///
- /// Tests for inequality between two objects.
- ///
- /// 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 )
- {
- return !left.Equals( right );
- }
-
- ///
- /// Performs an explicit conversion from to .
- ///
- /// The value.
- /// The result of the conversion.
- public static explicit operator Vec2( Int3 value )
- {
- return new Vec2( value.X, value.Y );
- }
-
- ///
- /// Performs an explicit conversion from to .
- ///
- /// The value.
- /// The result of the conversion.
- public static explicit operator Vec3( Int3 value )
- {
- return new Vec3( value.X, value.Y, value.Z );
- }
-
- ///
- /// Performs an explicit conversion from to .
- ///
- /// The value.
- /// The result of the conversion.
- public static explicit operator Vec4( Int3 value )
- {
- return new Vec4( value.X, value.Y, value.Z, 0 );
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- ///
- /// A that represents this instance.
- ///
- public override string ToString()
- {
- return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z );
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- /// The format.
- ///
- /// A that represents this instance.
- ///
- public string ToString( string format )
- {
- 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 ) );
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- /// The format provider.
- ///
- /// A that represents this instance.
- ///
- public string ToString( IFormatProvider formatProvider )
- {
- return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z );
- }
-
- ///
- /// Returns a that represents this instance.
- ///
- /// The format.
- /// The format provider.
- ///
- /// A that represents this instance.
- ///
- public string ToString( string format, IFormatProvider 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 ) );
- }
-
- ///
- /// 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.
- ///
- public override int GetHashCode()
- {
- return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode();
- }
-
- ///
- /// Determines whether the specified is equal to this instance.
- ///
- /// The to compare with this instance.
- ///
- /// true if the specified is equal to this instance; otherwise, false.
- ///
- 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 );
- }
-
- ///
- /// Determines whether the specified is equal to this instance.
- ///
- /// The to compare with this instance.
- ///
- /// true if the specified is equal to this instance; otherwise, false.
- ///
- public override bool Equals( object value )
- {
- if( value == null )
- return false;
-
- if( value.GetType() != GetType() )
- return false;
-
- return Equals( (Int3)value );
- }
+ ///
+ /// Represents a three dimensional mathematical vector.
+ ///
+ [DataContract( Name = "Int3" )]
+ [DataStyle( DataStyle.Compact )]
+ [StructLayout( LayoutKind.Sequential, Pack = 4 )]
+ public struct Int3 : IEquatable, IFormattable
+ {
+ ///
+ /// The size of the type, in bytes.
+ ///
+ public static readonly int SizeInBytes = lib.Util.SizeOf();
+
+ ///
+ /// A with all of its components set to zero.
+ ///
+ public static readonly Int3 Zero = new Int3();
+
+ ///
+ /// The X unit (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 );
+
+ ///
+ /// The Z unit (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 );
+
+ ///
+ /// The X component of the vector.
+ ///
+ [DataMember( Order = 0 )]
+ public int X;
+
+ ///
+ /// The Y component of the vector.
+ ///
+ [DataMember( Order = 1 )]
+ public int Y;
+
+ ///
+ /// The Z component of the vector.
+ ///
+ [DataMember( Order = 2 )]
+ public int Z;
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The value that will be assigned to all components.
+ public Int3( int value )
+ {
+ X = value;
+ Y = value;
+ Z = value;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// 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 )
+ {
+ X = x;
+ Y = y;
+ Z = z;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// 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 )
+ {
+ X = (int)value.X;
+ Y = (int)value.Y;
+ Z = z;
+ }
+
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// 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 )
+ {
+ 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];
+ Z = values[2];
+ }
+
+ ///
+ /// Gets or sets the component at the specified index.
+ ///
+ /// The value of the X, Y, or Z component, depending on the index.
+ /// The index of the component to access. Use 0 for the X component, 1 for the Y component, and 2 for the Z component.
+ /// The value of the component at the specified index.
+ /// Thrown when the is out of the range [0, 2].
+ public int this[int index]
+ {
+ get
+ {
+ switch( index )
+ {
+ 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." );
+ }
+
+ set
+ {
+ 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." );
+ }
+ }
+ }
+
+ ///
+ /// Calculates the length of the vector.
+ ///
+ /// The length of the vector.
+ ///
+ /// may be preferred when only the relative length is needed
+ /// and speed is of the essence.
+ ///
+ public int Length()
+ {
+ return (int)Math.Sqrt( ( X * X ) + ( Y * Y ) + ( Z * Z ) );
+ }
+
+ ///
+ /// Calculates the squared length of the vector.
+ ///
+ /// The squared length of the vector.
+ ///
+ /// This method may be preferred to when only a relative length is needed
+ /// and speed is of the essence.
+ ///
+ public int LengthSquared()
+ {
+ return ( X * X ) + ( Y * Y ) + ( Z * Z );
+ }
+
+ ///
+ /// Raises the exponent for each components.
+ ///
+ /// The exponent.
+ public void Pow( int exponent )
+ {
+ X = (int)Math.Pow( X, exponent );
+ Y = (int)Math.Pow( Y, exponent );
+ Z = (int)Math.Pow( Z, exponent );
+ }
+
+ ///
+ /// Creates an array containing the elements of the vector.
+ ///
+ /// A three-element array containing the components of the vector.
+ public int[] ToArray()
+ {
+ return new int[] { X, Y, Z };
+ }
+
+ ///
+ /// Adds two vectors.
+ ///
+ /// 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 )
+ {
+ result = new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z );
+ }
+
+ ///
+ /// Adds two vectors.
+ ///
+ /// The first vector to add.
+ /// The second vector to add.
+ /// The sum of the two vectors.
+ public static Int3 Add( Int3 left, Int3 right )
+ {
+ return new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z );
+ }
+
+ ///
+ /// Subtracts two vectors.
+ ///
+ /// 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 )
+ {
+ result = new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z );
+ }
+
+ ///
+ /// Subtracts two vectors.
+ ///
+ /// The first vector to subtract.
+ /// The second vector to subtract.
+ /// The difference of the two vectors.
+ public static Int3 Subtract( Int3 left, Int3 right )
+ {
+ return new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// 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 )
+ {
+ result = new Int3( value.X * scale, value.Y * scale, value.Z * scale );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// The vector to scale.
+ /// The amount by which to scale the vector.
+ /// The scaled vector.
+ public static Int3 Multiply( Int3 value, int scale )
+ {
+ return new Int3( 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.
+ 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 );
+ }
+
+ ///
+ /// Modulates a vector with another by performing component-wise multiplication.
+ ///
+ /// The first vector to modulate.
+ /// The second vector to modulate.
+ /// The modulated vector.
+ public static Int3 Modulate( Int3 left, Int3 right )
+ {
+ return new Int3( left.X * right.X, left.Y * right.Y, left.Z * right.Z );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// 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 )
+ {
+ result = new Int3( value.X / scale, value.Y / scale, value.Z / scale );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// The vector to scale.
+ /// The amount by which to scale the vector.
+ /// The scaled vector.
+ public static Int3 Divide( Int3 value, int scale )
+ {
+ return new Int3( value.X / scale, value.Y / scale, value.Z / scale );
+ }
+
+ ///
+ /// Reverses the direction of a given vector.
+ ///
+ /// 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 )
+ {
+ result = new Int3( -value.X, -value.Y, -value.Z );
+ }
+
+ ///
+ /// Reverses the direction of a given vector.
+ ///
+ /// The vector to negate.
+ /// A vector facing in the opposite direction.
+ public static Int3 Negate( Int3 value )
+ {
+ return new Int3( -value.X, -value.Y, -value.Z );
+ }
+
+ ///
+ /// Restricts a value to be within a specified range.
+ ///
+ /// The value to clamp.
+ /// 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 )
+ {
+ int x = value.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;
+
+ int z = value.Z;
+ z = ( z > max.Z ) ? max.Z : z;
+ z = ( z < min.Z ) ? min.Z : z;
+
+ result = new Int3( x, y, z );
+ }
+
+ ///
+ /// Restricts a value to be within a specified range.
+ ///
+ /// The value to clamp.
+ /// The minimum value.
+ /// The maximum value.
+ /// The clamped value.
+ public static Int3 Clamp( Int3 value, Int3 min, Int3 max )
+ {
+ Int3 result;
+ Clamp( ref value, ref min, ref max, out result );
+ return result;
+ }
+
+ ///
+ /// Calculates the dot product of two vectors.
+ ///
+ /// 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 )
+ {
+ result = ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z );
+ }
+
+ ///
+ /// Calculates the dot product of two vectors.
+ ///
+ /// First source vector.
+ /// Second source vector.
+ /// The dot product of the two vectors.
+ public static int Dot( Int3 left, Int3 right )
+ {
+ return ( left.X * right.X ) + ( left.Y * right.Y ) + ( left.Z * right.Z );
+ }
+
+ ///
+ /// Performs a linear interpolation between two vectors.
+ ///
+ /// Start vector.
+ /// End vector.
+ /// Value between 0 and 1 indicating the weight of .
+ /// When the method completes, contains the linear interpolation of the two vectors.
+ ///
+ /// 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.
+ ///
+ 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 ) );
+ }
+
+ ///
+ /// Performs a linear interpolation between two vectors.
+ ///
+ /// Start vector.
+ /// End vector.
+ /// Value between 0 and 1 indicating the weight of .
+ /// The linear interpolation of the two vectors.
+ ///
+ /// 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.
+ ///
+ public static Int3 Lerp( Int3 start, Int3 end, float amount )
+ {
+ Int3 result;
+ Lerp( ref start, ref end, amount, out result );
+ return result;
+ }
+
+ ///
+ /// Performs a cubic interpolation between two vectors.
+ ///
+ /// Start vector.
+ /// 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 )
+ {
+ 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 ) );
+ }
+
+ ///
+ /// Performs a cubic interpolation between two vectors.
+ ///
+ /// Start vector.
+ /// 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 )
+ {
+ Int3 result;
+ SmoothStep( ref start, ref end, amount, out result );
+ return result;
+ }
+
+ ///
+ /// Returns a vector containing the smallest components of the specified vectors.
+ ///
+ /// 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 )
+ {
+ 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;
+ }
+
+ ///
+ /// Returns a vector containing the largest components of the specified vectors.
+ ///
+ /// 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 )
+ {
+ Int3 result;
+ Max( ref left, ref right, out result );
+ return result;
+ }
+
+ ///
+ /// Returns a vector containing the smallest components of the specified vectors.
+ ///
+ /// 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 )
+ {
+ 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;
+ }
+
+ ///
+ /// Returns a vector containing the smallest components of the specified vectors.
+ ///
+ /// 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 )
+ {
+ Int3 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 )
+ {
+ return new Int3( left.X + right.X, left.Y + right.Y, left.Z + right.Z );
+ }
+
+ ///
+ /// Assert a vector (return it unchanged).
+ ///
+ /// The vector to assert (unchange).
+ /// The asserted (unchanged) vector.
+ public static Int3 operator +( Int3 value )
+ {
+ return value;
+ }
+
+ ///
+ /// Subtracts two vectors.
+ ///
+ /// The first vector to subtract.
+ /// The second vector to subtract.
+ /// The difference of the two vectors.
+ public static Int3 operator -( Int3 left, Int3 right )
+ {
+ return new Int3( left.X - right.X, left.Y - right.Y, left.Z - right.Z );
+ }
+
+ ///
+ /// Reverses the direction of a given vector.
+ ///
+ /// The vector to negate.
+ /// A vector facing in the opposite direction.
+ public static Int3 operator -( Int3 value )
+ {
+ return new Int3( -value.X, -value.Y, -value.Z );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// The vector to scale.
+ /// The amount by which to scale the vector.
+ /// The scaled vector.
+ public static Int3 operator *( float scale, Int3 value )
+ {
+ return new Int3( (int)( value.X * scale ), (int)( value.Y * scale ), (int)( value.Z * scale ) );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// The vector to scale.
+ /// The amount by which to scale the vector.
+ /// The scaled vector.
+ public static Int3 operator *( Int3 value, float scale )
+ {
+ return new Int3( (int)( value.X * scale ), (int)( value.Y * scale ), (int)( value.Z * scale ) );
+ }
+
+ ///
+ /// Scales a vector by the given value.
+ ///
+ /// The vector to scale.
+ /// The amount by which to scale the vector.
+ /// The scaled vector.
+ public static Int3 operator /( Int3 value, float scale )
+ {
+ return new Int3( (int)( value.X / scale ), (int)( value.Y / scale ), (int)( value.Z / scale ) );
+ }
+
+ ///
+ /// Tests for equality between two objects.
+ ///
+ /// 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 )
+ {
+ return left.Equals( right );
+ }
+
+ ///
+ /// Tests for inequality between two objects.
+ ///
+ /// 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 )
+ {
+ return !left.Equals( right );
+ }
+
+ ///
+ /// Performs an explicit conversion from to .
+ ///
+ /// The value.
+ /// The result of the conversion.
+ public static explicit operator Vec2( Int3 value )
+ {
+ return new Vec2( value.X, value.Y );
+ }
+
+ ///
+ /// Performs an explicit conversion from to .
+ ///
+ /// The value.
+ /// The result of the conversion.
+ public static explicit operator Vec3( Int3 value )
+ {
+ return new Vec3( value.X, value.Y, value.Z );
+ }
+
+ ///
+ /// Performs an explicit conversion from to .
+ ///
+ /// The value.
+ /// The result of the conversion.
+ public static explicit operator Vec4( Int3 value )
+ {
+ return new Vec4( value.X, value.Y, value.Z, 0 );
+ }
+
+ ///
+ /// Returns a that represents this instance.
+ ///
+ ///
+ /// A that represents this instance.
+ ///
+ public override string ToString()
+ {
+ return string.Format( CultureInfo.CurrentCulture, "X:{0} Y:{1} Z:{2}", X, Y, Z );
+ }
+
+ ///
+ /// Returns a that represents this instance.
+ ///
+ /// The format.
+ ///
+ /// A that represents this instance.
+ ///
+ public string ToString( string format )
+ {
+ 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 ) );
+ }
+
+ ///
+ /// Returns a that represents this instance.
+ ///
+ /// The format provider.
+ ///
+ /// A that represents this instance.
+ ///
+ public string ToString( IFormatProvider formatProvider )
+ {
+ return string.Format( formatProvider, "X:{0} Y:{1} Z:{2}", X, Y, Z );
+ }
+
+ ///
+ /// Returns a that represents this instance.
+ ///
+ /// The format.
+ /// The format provider.
+ ///
+ /// A that represents this instance.
+ ///
+ public string ToString( string format, IFormatProvider 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 ) );
+ }
+
+ ///
+ /// 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.
+ ///
+ public override int GetHashCode()
+ {
+ return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode();
+ }
+
+ ///
+ /// Determines whether the specified is equal to this instance.
+ ///
+ /// The to compare with this instance.
+ ///
+ /// true if the specified is equal to this instance; otherwise, false.
+ ///
+ 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 );
+ }
+
+ ///
+ /// Determines whether the specified is equal to this instance.
+ ///
+ /// The to compare with this instance.
+ ///
+ /// true if the specified is equal to this instance; otherwise, false.
+ ///
+ public override bool Equals( object value )
+ {
+ if( value == null )
+ return false;
+
+ if( value.GetType() != GetType() )
+ return false;
+
+ return Equals( (Int3)value );
+ }
#if WPFInterop
///
/// Performs an implicit conversion from to .
@@ -811,5 +811,5 @@ namespace math
return new Int3(value.X, value.Y, value.Z);
}
#endif
- }
+ }
}
diff --git a/math/Size2F.cs b/math/Size2F.cs
index d551c49..d40d710 100644
--- a/math/Size2F.cs
+++ b/math/Size2F.cs
@@ -27,108 +27,108 @@ using System.Runtime.Serialization;
namespace math
{
- ///
- /// Defines a 2D rectangular size (width,height).
- ///
- [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 );
+ ///
+ /// Defines a 2D rectangular size (width,height).
+ ///
+ [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 );
- ///
- /// A zero size with (width, height) = (0,0)
- ///
- public static readonly Size2F Empty = Zero;
+ ///
+ /// A zero size with (width, height) = (0,0)
+ ///
+ public static readonly Size2F Empty = Zero;
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The x.
- /// The y.
- public Size2F( float width, float height )
- {
- Width = width;
- Height = height;
- }
+ ///
+ /// Initializes a new instance of the struct.
+ ///
+ /// The x.
+ /// The y.
+ public Size2F( float width, float height )
+ {
+ Width = width;
+ Height = height;
+ }
- ///
- /// Width.
- ///
- [DataMember( Order = 0 )]
- public float Width;
+ ///
+ /// Width.
+ ///
+ [DataMember( Order = 0 )]
+ public float Width;
- ///
- /// Height.
- ///
- [DataMember( Order = 1 )]
- public float Height;
+ ///
+ /// Height.
+ ///
+ [DataMember( Order = 1 )]
+ public float Height;
- ///
- /// Determines whether the specified is equal to this instance.
- ///
- /// The to compare with this instance.
- ///
- /// true if the specified is equal to this instance; otherwise, false.
- ///
- public bool Equals( Size2F other )
- {
- return other.Width == Width && other.Height == Height;
- }
+ ///
+ /// Determines whether the specified is equal to this instance.
+ ///
+ /// The to compare with this instance.
+ ///
+ /// true if the specified is equal to this instance; otherwise, false.
+ ///
+ public bool Equals( Size2F other )
+ {
+ return other.Width == Width && other.Height == Height;
+ }
- ///
- public override bool Equals( object obj )
- {
- if( ReferenceEquals( null, obj ) )
- return false;
- if( obj.GetType() != typeof( Size2F ) )
- return false;
- return Equals( (Size2F)obj );
- }
+ ///
+ public override bool Equals( object obj )
+ {
+ if( ReferenceEquals( null, obj ) )
+ return false;
+ if( obj.GetType() != typeof( Size2F ) )
+ return false;
+ return Equals( (Size2F)obj );
+ }
- ///
- public override int GetHashCode()
- {
- unchecked
- {
- return ( Width.GetHashCode() * 397 ) ^ Height.GetHashCode();
- }
- }
+ ///
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return ( Width.GetHashCode() * 397 ) ^ Height.GetHashCode();
+ }
+ }
- ///
- /// Implements the operator ==.
- ///
- /// The left.
- /// The right.
- ///
- /// The result of the operator.
- ///
- public static bool operator ==( Size2F left, Size2F right )
- {
- return left.Equals( right );
- }
+ ///
+ /// Implements the operator ==.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static bool operator ==( Size2F left, Size2F right )
+ {
+ return left.Equals( right );
+ }
- ///
- /// Implements the operator !=.
- ///
- /// The left.
- /// The right.
- ///
- /// The result of the operator.
- ///
- public static bool operator !=( Size2F left, Size2F right )
- {
- return !left.Equals( right );
- }
+ ///
+ /// Implements the operator !=.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static bool operator !=( Size2F left, Size2F right )
+ {
+ return !left.Equals( right );
+ }
- ///
- public override string ToString()
- {
- return string.Format( "({0},{1})", Width, Height );
- }
- }
+ ///
+ public override string ToString()
+ {
+ return string.Format( "({0},{1})", Width, Height );
+ }
+ }
}
diff --git a/math/VectorExtensions.cs b/math/VectorExtensions.cs
index eed52f2..7f64ee5 100644
--- a/math/VectorExtensions.cs
+++ b/math/VectorExtensions.cs
@@ -2,63 +2,63 @@
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
namespace math
{
- ///
- /// Extensions methods of the vector classes.
- ///
- public static class VectorExtensions
- {
- ///
- /// Return the Y/X components of the vector in the inverse order.
- ///
- /// the input vector
- public static Vec2 YX( this Vec2 vector )
- {
- return new Vec2( vector.Y, vector.X );
- }
+ ///
+ /// Extensions methods of the vector classes.
+ ///
+ public static class VectorExtensions
+ {
+ ///
+ /// Return the Y/X components of the vector in the inverse order.
+ ///
+ /// the input vector
+ public static Vec2 YX( this Vec2 vector )
+ {
+ 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 )
- {
- return new Vec2( vector.X, vector.Y );
- }
+ ///
+ /// Return the X/Y components of the vector.
+ ///
+ /// the input vector
+ public static Vec2 XY( this Vec3 vector )
+ {
+ 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 )
- {
- return new Vec2( vector.X, vector.Z );
- }
+ ///
+ /// Return the X/Z components of the vector.
+ ///
+ /// the input vector
+ public static Vec2 XZ( this Vec3 vector )
+ {
+ 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 )
- {
- return new Vec2( vector.Y, vector.Z );
- }
+ ///
+ /// Return the Y/Z components of the vector.
+ ///
+ /// the input vector
+ public static Vec2 YZ( this Vec3 vector )
+ {
+ 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 )
- {
- return new Vec2( vector.X, vector.Y );
- }
+ ///
+ /// Return the X/Y components of the vector.
+ ///
+ /// the input vector
+ public static Vec2 XY( this Vec4 vector )
+ {
+ 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 )
- {
- return new Vec3( vector.X, vector.Y, vector.Z );
- }
- }
+ ///
+ /// Return the X/Y/Z components of the vector.
+ ///
+ /// the input vector
+ public static Vec3 XYZ( this Vec4 vector )
+ {
+ return new Vec3( vector.X, vector.Y, vector.Z );
+ }
+ }
}
diff --git a/res/Resource.cs b/res/Resource.cs
index 2ceb0c5..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 io.Obj)?.Meta;
+ var immMeta = ( value as io.Obj )?.Meta;
@@ -433,7 +433,7 @@ public static class Mgr
var loadedObject = loaderHolder.Load( filename, reason, dbgName, dbgPath, dbgLine );
if( loadedObject is T value )
{
- var meta = (value as io.Obj)?.Meta;
+ var meta = ( value as io.Obj )?.Meta;
// If it's an immutable object, record its loading.
if( value is io.Obj imm )
diff --git a/sharplib.sln b/sharplib.sln
index b6ca767..4af1880 100644
--- a/sharplib.sln
+++ b/sharplib.sln
@@ -1,4 +1,4 @@
-
+
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0