Fixed the CurveKeyCollection class so all CurveKeyCollection test are now passing!

This commit is contained in:
SND\AstrorEnales_cp 2012-10-13 20:40:50 +00:00 committed by Konstantin Koch
parent 646c2e5b79
commit 783a448db1
5 changed files with 142 additions and 172 deletions

View File

@ -51,7 +51,8 @@ namespace ANX.Framework.TestCenter.Strukturen
#endregion
[TestCaseSource("sixteenfloats")]
public void add(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void add(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10,
float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -73,7 +74,6 @@ namespace ANX.Framework.TestCenter.Strukturen
anx.Add(new ANXCurveKey(a13, a14));
anx.Add(new ANXCurveKey(a15, a16));
AssertHelper.ConvertEquals(xna, anx, "add");
}
@ -81,11 +81,10 @@ namespace ANX.Framework.TestCenter.Strukturen
public void adde()
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
ANXCurveKeyCollection anx = new ANXCurveKeyCollection();
AssertHelper.ConvertEquals(Assert.Throws<ArgumentNullException>(delegate { xna.Add(null); }), Assert.Throws<ArgumentNullException>(delegate { anx.Add(null); }), "adde");
AssertHelper.ConvertEquals(Assert.Throws<ArgumentNullException>(() => xna.Add(null)),
Assert.Throws<ArgumentNullException>(() => anx.Add(null)), "adde");
}
//[TestCaseSource("sixteenfloats")]
@ -140,9 +139,9 @@ namespace ANX.Framework.TestCenter.Strukturen
// AssertHelper.ConvertEquals(xna, anx, "add2");
//}
[Test]
public void Constructor()
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
ANXCurveKeyCollection anx = new ANXCurveKeyCollection();
@ -150,7 +149,8 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloats")]
public void Clear(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Clear(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10,
float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -178,7 +178,8 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloats")]
public void Clone(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Clone(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10,
float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -202,9 +203,9 @@ namespace ANX.Framework.TestCenter.Strukturen
anx.Add(new ANXCurveKey(a15, a16));
ANXCurveKeyCollection anx2 = anx.Clone();
for (int i = 0; i < xna.Count; i++)
for (int index = 0; index < xna.Count; index++)
{
if (!(xna[i] == xna2[i]))
if (xna[index] != xna2[index])
{
Assert.Fail();
}
@ -214,7 +215,8 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloats")]
public void Contains(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Contains(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -236,13 +238,13 @@ namespace ANX.Framework.TestCenter.Strukturen
anx.Add(new ANXCurveKey(a13, a14));
anx.Add(new ANXCurveKey(a15, a16));
AssertHelper.ConvertEquals(xna.Contains(new XNACurveKey(a1,a2)), anx.Contains(new ANXCurveKey (a1,a2)), "Contains");
AssertHelper.ConvertEquals(xna.Contains(new XNACurveKey(a1, a2)), anx.Contains(new ANXCurveKey(a1, a2)),
"Contains");
}
[TestCaseSource("sixteenfloats")]
public void CopyTo(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void CopyTo(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10,
float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -268,7 +270,6 @@ namespace ANX.Framework.TestCenter.Strukturen
ANXCurveKey[] anxa = new ANXCurveKey[anx.Count];
anx.CopyTo(anxa, 0);
AssertHelper.ConvertEquals(xnaa, anxa, "CopyTo");
}
@ -276,14 +277,14 @@ namespace ANX.Framework.TestCenter.Strukturen
public void IsReadOnly()
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
ANXCurveKeyCollection anx = new ANXCurveKeyCollection();
AssertHelper.ConvertEquals(xna.IsReadOnly, anx.IsReadOnly, "IsReadOnly");
}
[TestCaseSource("sixteenfloats")]
public void Remove(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Remove(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10,
float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -305,12 +306,12 @@ namespace ANX.Framework.TestCenter.Strukturen
anx.Add(new ANXCurveKey(a13, a14));
anx.Add(new ANXCurveKey(a15, a16));
AssertHelper.ConvertEquals(xna.Remove(new XNACurveKey(a1, a2)), anx.Remove(new ANXCurveKey(a1, a2)), "Remove");
}
[TestCaseSource("sixteenfloats")]
public void RemoveAt(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void RemoveAt(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a1, a2));
@ -338,7 +339,8 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloats")]
public void IndexOf(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void IndexOf(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a3, a4));
@ -348,7 +350,7 @@ namespace ANX.Framework.TestCenter.Strukturen
xna.Add(new XNACurveKey(a11, a12));
xna.Add(new XNACurveKey(a13, a14));
xna.Add(new XNACurveKey(a15, a16));
xna[0] = (new XNACurveKey(a1, a2));
xna[0] = new XNACurveKey(a1, a2);
ANXCurveKeyCollection anx = new ANXCurveKeyCollection();
anx.Add(new ANXCurveKey(a3, a4));
@ -358,14 +360,14 @@ namespace ANX.Framework.TestCenter.Strukturen
anx.Add(new ANXCurveKey(a11, a12));
anx.Add(new ANXCurveKey(a13, a14));
anx.Add(new ANXCurveKey(a15, a16));
anx[0] = (new ANXCurveKey(a1, a2));
anx[0] = new ANXCurveKey(a1, a2);
AssertHelper.ConvertEquals(xna.IndexOf(new XNACurveKey(a1, a2)), anx.IndexOf(new ANXCurveKey(a1, a2)), "IndexOf");
}
[TestCaseSource("sixteenfloats")]
public void GetEnumerator(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void GetEnumerator(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKeyCollection xna = new XNACurveKeyCollection();
xna.Add(new XNACurveKey(a3, a4));
@ -375,26 +377,19 @@ namespace ANX.Framework.TestCenter.Strukturen
xna.Add(new XNACurveKey(a11, a12));
xna.Add(new XNACurveKey(a13, a14));
xna.Add(new XNACurveKey(a15, a16));
xna[0] = (new XNACurveKey(a1, a2));
xna[0] = new XNACurveKey(a1, a2);
ANXCurveKeyCollection anx = new ANXCurveKeyCollection();
anx.Add(new ANXCurveKey(a3, a4));
anx.Add(new ANXCurveKey(a3, a4));
anx.Add(new ANXCurveKey(a5, a6));
anx.Add(new ANXCurveKey(a7, a8));
anx.Add(new ANXCurveKey(a9, a10));
anx.Add(new ANXCurveKey(a11, a12));
anx.Add(new ANXCurveKey(a13, a14));
anx.Add(new ANXCurveKey(a15, a16));
anx[0] = (new ANXCurveKey(a1, a2));
foreach (var item in anx)
{
}
AssertHelper.ConvertEquals(xna, anx, "GetEnumerator");
anx[0] = new ANXCurveKey(a1, a2);
AssertHelper.ConvertEquals(xna, anx, "GetEnumerator");
}
}
}

View File

@ -1,7 +1,5 @@
#region Using Statements
using System;
using System.IO;
using ANX.Framework.NonXNA;
using NUnit.Framework;
#endregion // Using Statements
@ -23,10 +21,10 @@ using ANXCurveTangent = ANX.Framework.CurveTangent;
using XNACurveContinuity = Microsoft.Xna.Framework.CurveContinuity;
using ANXCurveContinuity = ANX.Framework.CurveContinuity;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.TestCenter.Strukturen
{
[TestFixture]
@ -62,7 +60,8 @@ namespace ANX.Framework.TestCenter.Strukturen
#endregion
[TestCaseSource("sixteenfloats")]
public void Constructor(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Constructor(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2);
ANXCurveKey anx = new ANXCurveKey(a1, a2);
@ -71,7 +70,8 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloats")]
public void Constructor2(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Constructor2(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
@ -80,7 +80,9 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloatsCurve")]
public void Constructor3(XNACurveContinuity xnacurve, ANXCurveContinuity anxcurve, float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Constructor3(XNACurveContinuity xnacurve, ANXCurveContinuity anxcurve, float a1, float a2, float a3,
float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14,
float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4, xnacurve);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4, anxcurve);
@ -89,83 +91,86 @@ namespace ANX.Framework.TestCenter.Strukturen
}
[TestCaseSource("sixteenfloats")]
public void Clone(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void Clone(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10,
float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = xna.Clone();
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = anx.Clone();
AssertHelper.ConvertEquals(xna, anx, xna2, anx2, "Clone");
}
[TestCaseSource("sixteenfloats2")]
public void CompareTo(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void CompareTo(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = new XNACurveKey(a2, a1, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = new ANXCurveKey(a2, a1, a3, a4);
AssertHelper.ConvertEquals(xna.CompareTo(xna2), anx.CompareTo(anx2), "CompareTo");
}
[TestCaseSource("sixteenfloats")]
public void op_Equality(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void op_Equality(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = new XNACurveKey(a2, a1, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = new ANXCurveKey(a2, a1, a3, a4);
AssertHelper.ConvertEquals(xna==xna2, anx==anx2, "op_Equality");
}
[TestCaseSource("sixteenfloats")]
public void op_Equality2(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void op_Equality2(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = new XNACurveKey(a2, a1, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = new ANXCurveKey(a2, a1, a3, a4);
AssertHelper.ConvertEquals(xna == xna2, anx == anx2, "op_Equality2");
}
[TestCaseSource("sixteenfloats")]
public void op_Unequality(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void op_Unequality(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = new XNACurveKey(a2, a1, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = new ANXCurveKey(a2, a1, a3, a4);
AssertHelper.ConvertEquals(xna != xna2, anx != anx2, "op_Unequality");
}
[TestCaseSource("sixteenfloats")]
public void op_Unequality2(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void op_Unequality2(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = new XNACurveKey(a2, a1, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = new ANXCurveKey(a2, a1, a3, a4);
AssertHelper.ConvertEquals(xna != xna2, anx != anx2, "op_Unequality2");
}
[TestCaseSource("sixteenfloats")]
public void GetHashCode(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9, float a10, float a11, float a12, float a13, float a14, float a15, float a16)
public void GetHashCode(float a1, float a2, float a3, float a4, float a5, float a6, float a7, float a8, float a9,
float a10, float a11, float a12, float a13, float a14, float a15, float a16)
{
XNACurveKey xna = new XNACurveKey(a1, a2, a3, a4);
XNACurveKey xna2 = new XNACurveKey(a2, a1, a3, a4);
ANXCurveKey anx = new ANXCurveKey(a1, a2, a3, a4);
ANXCurveKey anx2 = new ANXCurveKey(a2, a1, a3, a4);
AssertHelper.ConvertEquals(xna.GetHashCode(), anx.GetHashCode(), "GetHashCode");
}
}

View File

@ -12,7 +12,7 @@ namespace ANX.Framework
#endif
[PercentageComplete(100)]
[Developer("floAr")]
[TestState(TestStateAttribute.TestState.InProgress)]
[TestState(TestStateAttribute.TestState.Tested)]
public class Curve
{
public CurveLoopType PreLoop { get; set; }

View File

@ -9,40 +9,16 @@ namespace ANX.Framework
{
[PercentageComplete(100)]
[Developer("???")]
[TestState(TestStateAttribute.TestState.InProgress)]
[TestState(TestStateAttribute.TestState.Tested)]
public class CurveKey : IEquatable<CurveKey>, IComparable<CurveKey>
{
#region Public
public float Position
{
get;
private set;
}
public float Value
{
get;
set;
}
public float TangentIn
{
get;
set;
}
public float TangentOut
{
get;
set;
}
public CurveContinuity Continuity
{
get;
set;
}
#endregion
public float Position { get; private set; }
public float Value { get; set; }
public float TangentIn { get; set; }
public float TangentOut { get; set; }
public CurveContinuity Continuity { get; set; }
#endregion
#region Constructor
public CurveKey(float position, float value)
@ -50,14 +26,12 @@ namespace ANX.Framework
{
}
public CurveKey(float position, float value, float tangentIn,
float tangentOut)
public CurveKey(float position, float value, float tangentIn, float tangentOut)
: this(position, value, tangentIn, tangentOut, CurveContinuity.Smooth)
{
}
public CurveKey(float position, float value, float tangentIn,
float tangentOut, CurveContinuity continuity)
public CurveKey(float position, float value, float tangentIn, float tangentOut, CurveContinuity continuity)
{
Position = position;
Value = value;
@ -91,14 +65,9 @@ namespace ANX.Framework
public override bool Equals(object obj)
{
if (obj == null && obj.GetType() == typeof(CurveKey))
{
return this == (CurveKey)obj;
}
return false;
return obj is CurveKey && this == (CurveKey)obj;
}
#endregion
#endregion
#region GetHashCode
public override int GetHashCode()
@ -113,14 +82,10 @@ namespace ANX.Framework
public static bool operator ==(CurveKey a, CurveKey b)
{
if (null == a as Object)
{
return null == b as Object;
}
if (null == b as Object)
{
return null == a as Object;
}
return false;
return a.Position == b.Position &&
a.Value == b.Value &&
@ -134,14 +99,10 @@ namespace ANX.Framework
public static bool operator !=(CurveKey a, CurveKey b)
{
if (null == a as Object)
{
return null != b as Object;
}
if (null == b as Object)
{
return null != a as Object;
}
return true;
return a.Position != b.Position ||
a.Value != b.Value ||
@ -152,17 +113,13 @@ namespace ANX.Framework
#endregion
#region CompareTo
public int CompareTo(CurveKey other)
{
if (Position == other.Position)
{
return 0;
}
public int CompareTo(CurveKey other)
{
if (Position == other.Position)
return 0;
return Position >= other.Position ?
1 :
-1;
}
#endregion
return Position >= other.Position ? 1 : -1;
}
#endregion
}
}

View File

@ -10,8 +10,8 @@ using ANX.Framework.NonXNA.Development;
namespace ANX.Framework
{
[PercentageComplete(100)]
[Developer("???")]
[TestState(TestStateAttribute.TestState.InProgress)]
[Developer("???, AstrorEnales")]
[TestState(TestStateAttribute.TestState.Tested)]
public class CurveKeyCollection : ICollection<CurveKey>, IEnumerable<CurveKey>, IEnumerable
{
#region Private
@ -19,23 +19,17 @@ namespace ANX.Framework
#endregion
#region Public
public int Count
{
get
{
return keys.Count;
}
}
public int Count
{
get { return keys.Count; }
}
public bool IsReadOnly
{
get
{
return false;
}
}
public bool IsReadOnly
{
get { return false; }
}
public CurveKey this[int index]
public CurveKey this[int index]
{
get
{
@ -48,6 +42,7 @@ namespace ANX.Framework
if (index >= keys.Count)
throw new IndexOutOfRangeException();
//if fitting add here
if (keys[index].Position == value.Position)
keys[index] = value;
@ -55,7 +50,7 @@ namespace ANX.Framework
{
//if not let it be sorted
keys.RemoveAt(index);
keys.Add(value);
Add(value);
}
}
@ -73,42 +68,61 @@ namespace ANX.Framework
public void Add(CurveKey item)
{
if (item == null)
{
throw new ArgumentNullException();
}
// keys.Add(item);
if (this.keys.Count == 0)
// If the list is empty or the item is bigger than the max, just add it
if (keys.Count == 0 || item.CompareTo(keys[Count - 1]) > 0)
{
//No list items
this.keys.Add(item);
keys.Add(item);
return;
}
if (item.CompareTo(this[Count - 1]) > 0)
int index = keys.BinarySearch(item);
if(index == -1)
{
//Bigger than Max
this.keys.Add(item);
index = ~index;
keys.Insert(index, item);
return;
}
int min = 0;
int max = Count - 1;
while ((max - min) > 1)
while (index < keys.Count)
{
//Find half point
int half = min + ((max - min) / 2);
//Compare if it's bigger or smaller than the current item.
int comp = item.CompareTo(this[half]);
if (comp == 0)
{
//Item is equal to half point
this.keys.Insert(half+1, item);
return;
}
else if (comp < 0) max = half; //Item is smaller
else min = half; //Item is bigger
if (item.Position != keys[index].Position)
break;
index++;
}
if (item.CompareTo(this[min]) <= 0) this.keys.Insert(min, item);
else this.keys.Insert(min + 1, item);
keys.Insert(index, item);
// Old broken code with own binary search implementation.
// Just in case the binary search isn't available on any system, this can be fixed:
//int min = 0;
//int max = Count - 1;
//while ((max - min) > 1)
//{
// //Find half point
// int half = min + ((max - min) / 2);
// //Compare if it's bigger or smaller than the current item.
// int comp = item.CompareTo(keys[half]);
// if (comp == 0)
// {
// // Item is equal to half point
// keys.Insert(half + 1, item);
// return;
// }
// // If the item is smaller, move the max to half, otherwise move the min to half.
// if (comp == -1)
// max = half;
// else
// min = half;
//}
//if (item.CompareTo(keys[min]) <= 0)
// keys.Insert(min, item);
//else
// keys.Insert(min + 1, item);
}
#endregion
@ -158,12 +172,11 @@ namespace ANX.Framework
#region Clone
public CurveKeyCollection Clone()
{
CurveKeyCollection result = new CurveKeyCollection();
foreach (CurveKey key in this.keys)
result.Add(key);
return result;
{
return new CurveKeyCollection
{
keys = new List<CurveKey>(keys),
};
}
#endregion