浏览代码

split internal extensions

vpenades 1 年之前
父节点
当前提交
1c02f80eb8

+ 52 - 0
src/SharpGLTF.Core/Schema2/_Extensions.MorphWeights.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Text;
+
+namespace SharpGLTF.Schema2
+{
+    /// <summary>
+    /// Extensions used internally.
+    /// </summary>
+    static partial class _Schema2Extensions
+    {
+        #region morph weights
+
+        public static void SetMorphWeights(this IList<Double> list, int maxCount, Transforms.SparseWeight8 weights)
+        {
+            while (list.Count > maxCount) list.RemoveAt(list.Count - 1);
+            while (list.Count < maxCount) list.Add(0);
+
+            if (list.Count > 0)
+            {
+                for (int i = 0; i < list.Count; ++i)
+                {
+                    list[i] = 0;
+                }
+
+                foreach (var (index, weight) in weights.GetIndexedWeights())
+                {
+                    list[index] = weight;
+                }
+            }
+        }
+
+        public static void SetMorphWeights(this IList<Double> list, IReadOnlyList<float> weights)
+        {
+            if (weights == null) { list.Clear(); return; }
+
+            while (list.Count > weights.Count) list.RemoveAt(list.Count - 1);
+            while (list.Count < weights.Count) list.Add(0);
+
+            if (list.Count > 0)
+            {
+                for (int i = 0; i < list.Count; ++i)
+                {
+                    list[i] = weights[i];
+                }
+            }
+        }
+
+        #endregion
+    }
+}

+ 85 - 124
src/SharpGLTF.Core/Schema2/_Extensions.cs → src/SharpGLTF.Core/Schema2/_Extensions.Nullables.cs

@@ -1,124 +1,85 @@
-using System;
-using System.Collections.Generic;
-using System.Numerics;
-using System.Text;
-
-namespace SharpGLTF.Schema2
-{
-    /// <summary>
-    /// Extensions used internally.
-    /// </summary>
-    static class _Schema2Extensions
-    {
-        #region morph weights
-
-        public static void SetMorphWeights(this IList<Double> list, int maxCount, Transforms.SparseWeight8 weights)
-        {
-            while (list.Count > maxCount) list.RemoveAt(list.Count - 1);
-            while (list.Count < maxCount) list.Add(0);
-
-            if (list.Count > 0)
-            {
-                for (int i = 0; i < list.Count; ++i)
-                {
-                    list[i] = 0;
-                }
-
-                foreach (var (index, weight) in weights.GetIndexedWeights())
-                {
-                    list[index] = weight;
-                }
-            }
-        }
-
-        public static void SetMorphWeights(this IList<Double> list, IReadOnlyList<float> weights)
-        {
-            if (weights == null) { list.Clear(); return; }
-
-            while (list.Count > weights.Count) list.RemoveAt(list.Count - 1);
-            while (list.Count < weights.Count) list.Add(0);
-
-            if (list.Count > 0)
-            {
-                for (int i = 0; i < list.Count; ++i)
-                {
-                    list[i] = weights[i];
-                }
-            }
-        }
-
-        #endregion
-
-        #region nullables
-
-        internal static String AsName(this string name)
-        {
-            return string.IsNullOrWhiteSpace(name) ? null : name;
-        }
-
-        internal static T AsValue<T>(this T? value, T defval)
-            where T : struct
-        {
-            return value ?? defval;
-        }
-
-        internal static T? AsNullable<T>(this T value, T defval)
-            where T : struct
-        {
-            return value.Equals(defval) ? (T?)null : value;
-        }
-
-        internal static T? AsNullable<T>(this T value, T defval, T minval, T maxval)
-            where T : struct, IEquatable<T>, IComparable<T>
-        {
-            if (value.Equals(defval)) return null;
-
-            if (value.CompareTo(minval) < 0) value = minval;
-            if (value.CompareTo(maxval) > 0) value = maxval;
-
-            return value.Equals(defval) ? (T?)null : value;
-        }
-
-        internal static Vector2? AsNullable(this Vector2 value, Vector2 defval, Vector2 minval, Vector2 maxval)
-        {
-            if (value.Equals(defval)) return null;
-
-            value = Vector2.Min(value, maxval);
-            value = Vector2.Max(value, minval);
-
-            return value.Equals(defval) ? (Vector2?)null : value;
-        }
-
-        internal static Vector3? AsNullable(this Vector3 value, Vector3 defval, Vector3 minval, Vector3 maxval)
-        {
-            if (value.Equals(defval)) return null;
-
-            value = Vector3.Min(value, maxval);
-            value = Vector3.Max(value, minval);
-
-            return value.Equals(defval) ? (Vector3?)null : value;
-        }
-
-        internal static Vector4? AsNullable(this Vector4 value, Vector4 defval, Vector4 minval, Vector4 maxval)
-        {
-            if (value.Equals(defval)) return (Vector4?)null;
-
-            value = Vector4.Min(value, maxval);
-            value = Vector4.Max(value, minval);
-
-            return value.Equals(defval) ? (Vector4?)null : value;
-        }
-
-        internal static String AsNullable(this string value)
-        {
-            return string.IsNullOrEmpty(value) ? null : value;
-        }
-
-        internal static String AsEmptyNullable(this string value)
-        {
-            return string.IsNullOrWhiteSpace(value) ? null : value;
-        }
-
-        #endregion
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+using System.Text;
+
+namespace SharpGLTF.Schema2
+{
+    /// <summary>
+    /// Extensions used internally.
+    /// </summary>
+    static partial class _Schema2Extensions
+    {
+        #region nullables
+
+        internal static String AsName(this string name)
+        {
+            return string.IsNullOrWhiteSpace(name) ? null : name;
+        }
+
+        internal static T AsValue<T>(this T? value, T defval)
+            where T : struct
+        {
+            return value ?? defval;
+        }
+
+        internal static T? AsNullable<T>(this T value, T defval)
+            where T : struct
+        {
+            return value.Equals(defval) ? (T?)null : value;
+        }
+
+        internal static T? AsNullable<T>(this T value, T defval, T minval, T maxval)
+            where T : struct, IEquatable<T>, IComparable<T>
+        {
+            if (value.Equals(defval)) return null;
+
+            if (value.CompareTo(minval) < 0) value = minval;
+            if (value.CompareTo(maxval) > 0) value = maxval;
+
+            return value.Equals(defval) ? (T?)null : value;
+        }
+
+        internal static Vector2? AsNullable(this Vector2 value, Vector2 defval, Vector2 minval, Vector2 maxval)
+        {
+            if (value.Equals(defval)) return null;
+
+            value = Vector2.Min(value, maxval);
+            value = Vector2.Max(value, minval);
+
+            return value.Equals(defval) ? (Vector2?)null : value;
+        }
+
+        internal static Vector3? AsNullable(this Vector3 value, Vector3 defval, Vector3 minval, Vector3 maxval)
+        {
+            if (value.Equals(defval)) return null;
+
+            value = Vector3.Min(value, maxval);
+            value = Vector3.Max(value, minval);
+
+            return value.Equals(defval) ? (Vector3?)null : value;
+        }
+
+        internal static Vector4? AsNullable(this Vector4 value, Vector4 defval, Vector4 minval, Vector4 maxval)
+        {
+            if (value.Equals(defval)) return (Vector4?)null;
+
+            value = Vector4.Min(value, maxval);
+            value = Vector4.Max(value, minval);
+
+            return value.Equals(defval) ? (Vector4?)null : value;
+        }
+
+        internal static String AsNullable(this string value)
+        {
+            return string.IsNullOrEmpty(value) ? null : value;
+        }
+
+        internal static String AsEmptyNullable(this string value)
+        {
+            return string.IsNullOrWhiteSpace(value) ? null : value;
+        }
+
+        #endregion
+    }
+}

+ 4 - 1
src/SharpGLTF.Ext.3DTiles/SharpGLTF.Ext.3DTiles.csproj

@@ -8,7 +8,8 @@
 
   <ItemGroup>
     <Compile Include="..\Shared\Guard.cs" Link="Diagnostics\Guard.cs" />
-    <Compile Include="..\Shared\_Extensions.cs" Link="_Extensions.cs" />    
+    <Compile Include="..\Shared\_Extensions.cs" Link="_Extensions.cs" />
+    <Compile Include="..\SharpGLTF.Core\Schema2\_Extensions.Nullables.cs" Link="Schema2\_Extensions.Nullables.cs" />    
   </ItemGroup>
 
   <ItemGroup>
@@ -19,8 +20,10 @@
     <Folder Include="Schema2\Generated\" />
   </ItemGroup>
 
+  <!--
   <ItemGroup>
     <PackageReference Include="OneOf" Version="3.0.263" />
   </ItemGroup>
+  -->
 
 </Project>

+ 1 - 1
src/SharpGLTF.Ext.Agi/SharpGLTF.Ext.Agi.csproj

@@ -17,7 +17,7 @@
   <ItemGroup>
     <Compile Include="..\Shared\Guard.cs" Link="Diagnostics\Guard.cs" />
     <Compile Include="..\Shared\_Extensions.cs" Link="_Extensions.cs" />
-    <Compile Include="..\SharpGLTF.Core\Schema2\_Extensions.cs" Link="Schema2\_Extensions.cs" />
+    <Compile Include="..\SharpGLTF.Core\Schema2\_Extensions.Nullables.cs" Link="Schema2\_Extensions.Nullables.cs" />
   </ItemGroup>
 
   <ItemGroup>