public void GetClosestReturnsFirstKeyframe()
        {
            int keyPos   = 10;
            int getAtPos = keyPos - 5;
            KeyframeTimelineDeprecated testCollection = new KeyframeTimelineDeprecated();
            KeyframePropertyInfo       testProperty   = new KeyframePropertyInfo(null, PropertyType.Executable);
            Entity testNode = new Entity();

            //Add some keys
            testCollection.AddKeyframe(new ValueKeyframe(testProperty, null, null), keyPos, testNode);
            testCollection.AddKeyframe(new ValueKeyframe(testProperty, null, null), keyPos + 2, testNode);
            testCollection.AddKeyframe(new ValueKeyframe(testProperty, null, null), keyPos + 4, testNode);
            Tuple <int, int> closest = testCollection.GetClosestKeys(testProperty, getAtPos);

            Assert.AreEqual(keyPos, closest.Item1);
            Assert.AreEqual(keyPos, closest.Item2);
        }
Example #2
0
        public KeySet GetClosestKeys(KeyframePropertyInfo info, int time)
        {
            int firstKey, lastKey;
            //Find the times at which a keyframe exist
            List <int> times = propertiesCache?[info];

            if (times == null)
            {
                throw new ArgumentException($"{nameof(KeyframePropertyInfo)} not valid for timeline, is it not a property of the entity with keyframe attribute?", nameof(info));
            }
            int[] keysArray = times.ToArray();
            //Find the lower bound index
            int lowerBoundIndex = BinarySearch(keysArray, time);

            //Get the keys for our retrieved indices
            if (lowerBoundIndex != 0)
            {
                //We have at least one item before us
                firstKey = keysArray[lowerBoundIndex - 1];
                //Check if our first key is also the last, in this case lastkey
                //will be the same as first key.. If we are not at the end we
                //assign lastkey to one the content of one index higher
                if (lowerBoundIndex < keysArray.Length)
                {
                    lastKey = keysArray[lowerBoundIndex];
                }
                else
                {
                    lastKey = firstKey;
                }
            }
            else
            {
                //if index is 0 this means there are no keyframes before our
                //given time. We know there is at least one entry therefore we can
                //assume that the first entry in our list of keyframes is the closest one
                firstKey = keysArray[0];
                lastKey  = firstKey;
            }

            return(new KeySet(keysArray[firstKey], keysArray[lastKey]));
        }
Example #3
0
 public ValueKeyframe GetPropertyKey(KeyframePropertyInfo keys, int time)
 {
     throw new NotImplementedException();
 }