Exemplo n.º 1
0
        public IEnumerable KeyframeBinarySearch(TestContext context)
        {
            var curve = new BezierAnimationCurve();

            curve.SetKeyframe(0, 10, CurveTypeValues.Linear);
            curve.SetKeyframe(1, 20, CurveTypeValues.Linear);
            curve.SetKeyframe(2, 30, CurveTypeValues.Linear);

            if (!context.Assert(curve.KeyframeBinarySearch(0.0f), 0, "0.0f"))
            {
                yield break;
            }
            if (!context.Assert(curve.KeyframeBinarySearch(0.5f, true), 1, "0.5f"))
            {
                yield break;
            }
            if (!context.Assert(curve.KeyframeBinarySearch(1.0f), 1, "1.0f"))
            {
                yield break;
            }
            if (!context.Assert(curve.KeyframeBinarySearch(1.5f, true), 2, "1.5f"))
            {
                yield break;
            }
            if (!context.Assert(curve.KeyframeBinarySearch(2.0f), 2, "2.0f"))
            {
                yield break;
            }
        }
Exemplo n.º 2
0
        public IEnumerable AddAndRemoveFrames(TestContext context)
        {
            var curve = new BezierAnimationCurve();

            {
                var key = curve.SetKeyframe(0, 123, CurveTypeValues.Linear);
                if (!context.Assert(key, 0, "First key is zero"))
                {
                    yield break;
                }
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f }, "Expected one frame"))
                {
                    yield break;
                }
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0)).value, 123, "Set and get at time 0");
            }

            {
                var key = curve.SetKeyframe(0.499999f, 456, CurveTypeValues.Linear);
                if (!context.Assert(key, 1, "Second key is one"))
                {
                    yield break;
                }
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f, 0.5f }, "Expected two frames"))
                {
                    yield break;
                }
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.000001f)).value, 123, "Set and get at time 0.000001");
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.499999f)).value, 456, "Set and get at time 0.499999");
            }

            {
                var key = curve.SetKeyframe(0.250f, 789, CurveTypeValues.Linear);
                if (!context.Assert(key, 1, "Third key is one"))
                {
                    yield break;
                }
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f, 0.250f, 0.5f }, "Expected three frames"))
                {
                    yield break;
                }
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.000001f)).value, 123, "Set and get at time 0.000001");
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.250f)).value, 789, "Set and get at time 0.250f");
                context.Assert(curve.GetKeyframeByKey(curve.KeyframeBinarySearch(0.499999f)).value, 456, "Set and get at time 0.499999");
            }

            {
                curve.RemoveKey(1);
                if (!context.Assert(curve.keys.Select(k => k.time), new[] { 0f, 0.5f }, "Expected two frames after remove"))
                {
                    yield break;
                }
            }

            yield break;
        }
Exemplo n.º 3
0
 public float GetTimeClosestTo(float time)
 {
     return(x.GetKeyframeByKey(x.KeyframeBinarySearch(time, true)).time);
 }