From 108cc7fc031e716a4ec48183988e82f9fd9f6f74 Mon Sep 17 00:00:00 2001 From: "SND\\floAr_cp" Date: Sun, 20 Nov 2011 22:48:32 +0000 Subject: [PATCH] CurveKey removed useless code, CurveKey collection is now sorted and pass add tests --- ANX.Framework/CurveKey.cs | 4 +- ANX.Framework/CurveKeyCollection.cs | 57 +++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/ANX.Framework/CurveKey.cs b/ANX.Framework/CurveKey.cs index 95ac3de5..0adc785a 100644 --- a/ANX.Framework/CurveKey.cs +++ b/ANX.Framework/CurveKey.cs @@ -161,11 +161,11 @@ namespace ANX.Framework { return !a.Equals(b); - return a.Position != b.Position || + /*return a.Position != b.Position || a.Value != b.Value || a.TangentIn != b.TangentIn || a.TangentOut != b.TangentOut || - a.Continuity != b.Continuity; + a.Continuity != b.Continuity;*/ } #endregion diff --git a/ANX.Framework/CurveKeyCollection.cs b/ANX.Framework/CurveKeyCollection.cs index c7e0af1f..0859a0c8 100644 --- a/ANX.Framework/CurveKeyCollection.cs +++ b/ANX.Framework/CurveKeyCollection.cs @@ -96,18 +96,51 @@ namespace ANX.Framework #endregion #region Add - public void Add(CurveKey item) - { - if (item == null) - { - throw new ArgumentNullException(); - } - keys.Add(item); - } - #endregion - - #region Clear - public void Clear() + public void Add(CurveKey item) + { + if (item == null) + { + throw new ArgumentNullException(); + } + // keys.Add(item); + + if (this.keys.Count == 0) + { + //No list items + this.keys.Add(item); + return; + } + if (item.CompareTo(this[Count - 1]) > 0) + { + //Bigger than Max + this.keys.Add(item); + return; + } + 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(this[half]); + if (comp == 0) + { + //Item is equal to half point + this.keys.Insert(half, item); + return; + } + else if (comp < 0) max = half; //Item is smaller + else min = half; //Item is bigger + } + if (item.CompareTo(this[min]) <= 0) this.keys.Insert(min, item); + else this.keys.Insert(min + 1, item); + } + + #endregion + + #region Clear + public void Clear() { keys.Clear(); }