Example #1
0
		public double GetInterpolatedValue(double compleatedRatio0To1, InterpolationType interpolationType)
		{
			switch (interpolationType)
			{
				case InterpolationType.LINEAR:
					return compleatedRatio0To1;

				case InterpolationType.EASE_IN:
					return Math.Pow(compleatedRatio0To1, 3);

				case InterpolationType.EASE_OUT:
					return (Math.Pow(compleatedRatio0To1 - 1, 3) + 1);

				case InterpolationType.EASE_IN_OUT:
					if (compleatedRatio0To1 < .5)
					{
						return Math.Pow(compleatedRatio0To1 * 2, 3) / 2;
					}
					else
					{
						return (Math.Pow(compleatedRatio0To1 * 2 - 2, 3) + 2) / 2;
					}

				default:
					throw new NotImplementedException();
			}
		}
 public static bool AllowedLimitedPrefix(InterpolationType x)
 {
     if ((x == InterpolationType.limitedCubic) ||
         (x == InterpolationType.limitedLinear))
         return false;
     return true;
 }
Example #3
0
 public FCurveKeyframe(InterpolationType interpolationType = asd.InterpolationType.Linear)
 {
     LeftHandle = new Vector2DF();
     RightHandle = new Vector2DF();
     KeyValue = new Vector2DF();
     Interpolation = interpolationType;
 }
Example #4
0
        public ViewMoverKenBurnsStyle(CameraParameters from, CameraParameters to, double time, Date fromDateTime, Date toDateTime, InterpolationType type)
        {
            InterpolationType = type;

            if (Math.Abs(from.Lng - to.Lng) > 180)
            {
                if (from.Lng > to.Lng)
                {
                    from.Lng -= 360;
                }
                else
                {
                    from.Lng += 360;
                }
            }

            this.fromDateTime = fromDateTime;
            this.toDateTime = toDateTime;

            dateTimeSpan = toDateTime - fromDateTime;

            this.from = from.Copy();
            this.to = to.Copy();
            fromTime = Date.Now;
            toTargetTime = time;
        }
 public static IInterpolation Instance(InterpolationType type)
 {
     if (type == InterpolationType.InterpolationTypeSmooth)
         return new SmoothInterpolation();
     else
         return new SmoothInterpolation();
 }
Example #6
0
 static string InterpolationTypeToString(InterpolationType eInterpolationType)
 {
     if (eInterpolationType == InterpolationType.LINEAR)
     {
         return "LINEAR";
     }
     throw new MyException ("Interpolation Type not recognized");
 }
 public ArcGISImageCapabilities(string url, long startTime = -1, long endTime = -1, string format = "jpgpng", InterpolationType interpolation = InterpolationType.RSP_NearestNeighbor)
 {
     ServiceUrl = url;
     Format = format;
     Interpolation = interpolation;
     StartTime = startTime;
     EndTime = endTime;           
 }
 public Keyframe(Bone bone, float time, Matrix output, InterpolationType interpolation)
 {
     Bone = bone;
     Time = time;
     Transform = output;
     Interpolation = interpolation;
     Transform.Decompose(out Scale, out Rotation, out Translation);
 }
Example #9
0
 public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType)
 {
     this.Octaves = 8;
     this.Frequency = 1.00;
     this.Lacunarity = 2.00;
     this.Type = fractalType;
     this.SetAllSourceTypes(basisType, interpolationType);
     this.ResetAllSources();
 }
 public static bool StrictlyBoundedField(InterpolationType x)
 {
     if ((x == InterpolationType.limitedLinear)
         || (x == InterpolationType.vanLeer)
         || (x == InterpolationType.Gamma)
         || (x == InterpolationType.limitedCubic)
         || (x == InterpolationType.MUSCL)
         ) return true;
     return false;
 }
 public override void Reset()
 {
     mode = InterpolationType.Linear;
     fromVector = new FsmVector3 { UseVariable = true };
     toVector = new FsmVector3 { UseVariable = true };
     time = 1.0f;
     storeResult = null;
     finishEvent = null;
     realTime = false;
 }
		public override void Reset()
		{
			mode = InterpolationType.Linear;
			fromFloat = null;
			toFloat = null;
			time = 1.0f;
			storeResult = null;
			finishEvent = null;
			realTime = false;
		}
 public ImplicitFractal(FractalType fractalType, BasisType basisType, InterpolationType interpolationType, Int32 octaves, double frequency, Int32 seed)
 {
     this.seed = seed;
     this.Octaves = octaves;
     this.Frequency = frequency;
     this.Lacunarity = 2.00;
     this.Type = fractalType;
     this.SetAllSourceTypes(basisType, interpolationType);
     this.ResetAllSources();
 }
Example #14
0
 public TimedInterpolator(double in_numSeconds, double in_startValue, double in_endValue, Repeate in_repeateType, InterpolationType in_interpolationType)
     : this()
 {
     numSeconds = in_numSeconds;
     startValue = in_startValue;
     endValue = in_endValue;
     distance = endValue - startValue;
     repeateType = in_repeateType;
     interpolationType = in_interpolationType;
 }
Example #15
0
        /// <summary>
        /// コンストラクター
        /// </summary>
        /// <param name="targetProperty">ターゲット プロパティ名</param>
        /// <param name="interp">補完方法</param>
        public AnimationTrack(string targetProperty,InterpolationType interp)
        {
            if (targetProperty == null || targetProperty == "") {
                throw new ArgumentNullException ("Target Property is null or empty");
            }

            this.targetProperty = targetProperty;
            this.frames = new List<Keyframe>();
            this.interpType = interp;
            this.compCount = 0;
            this.compType = null;
        }
Example #16
0
        public CPIBond(int settlementDays,
                double faceAmount,
                bool growthOnly,
                double baseCPI,
                Period observationLag,
                ZeroInflationIndex cpiIndex,
                InterpolationType observationInterpolation,
                Schedule schedule,
                List<double> fixedRate,
                DayCounter accrualDayCounter,
                BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing,
                Date issueDate = null,
                Calendar paymentCalendar = null,
                Period exCouponPeriod = null,
                Calendar exCouponCalendar = null,
					 BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                bool exCouponEndOfMonth = false)                
            :base(settlementDays, paymentCalendar == null ? schedule.calendar() : paymentCalendar, issueDate)
        {
            frequency_ = schedule.tenor().frequency();
            dayCounter_ = accrualDayCounter;
            growthOnly_ = growthOnly;
            baseCPI_=baseCPI;
            observationLag_ = observationLag;
            cpiIndex_= cpiIndex;
            observationInterpolation_ = observationInterpolation;

            maturityDate_ = schedule.endDate();

            // a CPIleg know about zero legs and inclusion of base inflation notional
            cashflows_ = new CPILeg(schedule, cpiIndex_,
                                    baseCPI_, observationLag_)
             .withSubtractInflationNominal(growthOnly_)
             .withObservationInterpolation(observationInterpolation_)
             .withPaymentDayCounter(accrualDayCounter)
             .withFixedRates(fixedRate)
             .withPaymentCalendar(calendar_)
             .withExCouponPeriod(exCouponPeriod,
                                exCouponCalendar,
                                exCouponConvention,
                                exCouponEndOfMonth)
             .withNotionals(faceAmount)
             .withPaymentAdjustment(paymentConvention);
            

            calculateNotionalsFromCashflows();

            cpiIndex_.registerWith(update);

            foreach ( CashFlow i in cashflows_) 
                i.registerWith(update);
        }
Example #17
0
 public TimedInterpolator(double in_numSeconds, double in_startValue, double in_endValue, Repeate in_repeateType, InterpolationType in_interpolationType)
 {
     if (!runningTimeStarted)
     {
         runningTime.Start();
     }
     numSeconds = in_numSeconds;
     startValue = in_startValue;
     endValue = in_endValue;
     distance = endValue - startValue;
     repeateType = in_repeateType;
     interpolationType = in_interpolationType;
 }
Example #18
0
 float interp(float e1, float e2, float t, float tension, InterpolationType type, InterpolationMode mode)
 {
     switch ((int)mode)
     {
         case 0:
             return interpIn(e1, e2, t, tension, type);
         case 1:
             return interpOut(e1, e2, t, tension, type);
         case 2:
             return interpInOut(e1, e2, t, tension, type);
         default:
             return interpOutIn(e1, e2, t, tension, type);
     }
 }
Example #19
0
 public static void GlobalInterpolation(InterpolationType typeInterpolation)
 {
     switch (typeInterpolation)
     {
         case InterpolationType.Slerp:
             System.Console.WriteLine("Bezier");
             break;
         case InterpolationType.Linear:
             System.Console.WriteLine("Linear");
             break;
         case InterpolationType.Constant:
             System.Console.WriteLine("Constant");
             break;
     }
 }
Example #20
0
        public static Vector2 Interpolate( InterpolationType type, Vector2 from, Vector2 to, float amount )
        {
            switch( type )
            {
                case InterpolationType.Linear:
                    return Lerp( from, to, amount );

                case InterpolationType.SinusCurve:
                    return Sinus( from, to, amount );

                case InterpolationType.SmoothStep:
                    return SmoothStep( from, to, amount );

                default:
                    return Vector2.Zero;
            }
        }
Example #21
0
        public static Vector2 PixelInterpolate( InterpolationType type, Vector2 from, Vector2 to, float pixelPerSec, float elapsed )
        {
            switch( type )
            {
                case InterpolationType.Linear:
                    return PixelLerp( from, to, pixelPerSec, elapsed );

                case InterpolationType.SinusCurve:
                    return PixelSinus( from, to, pixelPerSec, elapsed );

                case InterpolationType.SmoothStep:
                    return PixelSmoothStep( from, to, pixelPerSec, elapsed );

                default:
                    return Vector2.Zero;
            }
        }
        public ArcGISImageServiceProvider(string url, bool continueOnError = false, string format = "jpgpng", InterpolationType interpolation = InterpolationType.RSP_NearestNeighbor, long startTime = -1, long endTime = -1)
        {
            Url = url;
            CRS = "";
            TimeOut = 10000;
            ContinueOnError = continueOnError;

            ArcGisImageCapabilities = new ArcGISImageCapabilities(Url, startTime, endTime, format, interpolation)
            {
                fullExtent = new Extent { xmin = 0, xmax = 0, ymin = 0, ymax = 0 },
                initialExtent = new Extent { xmin = 0, xmax = 0, ymin = 0, ymax = 0 }
            };

            var capabilitiesHelper = new CapabilitiesHelper();
            capabilitiesHelper.CapabilitiesReceived += CapabilitiesHelperCapabilitiesReceived;
            capabilitiesHelper.CapabilitiesFailed += CapabilitiesHelperCapabilitiesFailed;
            capabilitiesHelper.GetCapabilities(url, CapabilitiesType.DynamicServiceCapabilities);
        }
Example #23
0
    float interpInOut(float e1, float e2, float t, float tension, InterpolationType type)
    {
        float e01, e02, t0;

        if (t < 0.5f)
        {
            e01 = e1;
            e02 = (e1 + e2) / 2.0f;
            t0 = t*2.0f;
        }
        else
        {
            e01 = e2;
            e02 = (e1 + e2) / 2.0f;
            t0 = 2.0f - t*2.0f;
        }

        return interpType(e01, e02, t0, tension, type);
    }
Example #24
0
        /// <summary>
        /// Animate position, rotation and size. (GameObject must implement Resizable)
        /// </summary>
        /// <param name="world"></param>
        /// <param name="targetObject"></param>
        /// <param name="originalPosition"></param>
        /// <param name="destinationPosition"></param>
        /// <param name="originalRotation"></param>
        /// <param name="destinationRotation"></param>
        /// <param name="originalSize"></param>
        /// <param name="destinationSize"></param>
        /// <param name="duration"></param>
        /// <param name="interpolationType"></param>
        /// <param name="start"></param>
        public LoopingAnimation(
            World world, 
            GameObject targetObject, 
            Vector2 originalPosition, 
            Vector2 destinationPosition,
            float originalRotation,
            float destinationRotation,
            Vector2 originalSize,
            Vector2 destinationSize,
            float loopTime, 
            InterpolationType 
            interpolationType, 
            bool start,
            float initialPhase
            )
            : base(world)
        {
            target = targetObject;

            if (!(target is Resizable))
                throw new Exception("Attempt at resizing a unresizable object. (Implement Resizable interface)");

            started = start;
            running = start;
            ended = false;

            this.looptime = loopTime;
            this.initialPhase = initialPhase;

            interpolPosition = true;
            interpolRotation = true;
            interpolSize = true;

            this.interpolationType = interpolationType;

            this.originalPosition = originalPosition;
            this.destinationPosition = destinationPosition;
            this.originalRotation = originalRotation;
            this.destinationRotation = destinationRotation;
            this.originalSize = originalSize;
            this.destinationSize = destinationSize;
        }
        public Tweener Using(InterpolationType interpolation, Easing easing)
        {
            object currentValueAsObject =
                LateBinder.GetValueStatic(Caller, MemberToSet);

            if (currentValueAsObject is float)
            {
                float currentValue = (float)currentValueAsObject;
                Tweener tweener = new Tweener(currentValue, ValueToSet, (float)TimeToTake,
                    interpolation, easing);

                tweener.PositionChanged = HandlePositionSet;

                TweenerManager.Self.Add(tweener);
                tweener.Start();
                return tweener;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #26
0
        private static double[] Interpolate(double[] xs, double[] ys, double[] newxs, InterpolationType interpolationType)
        {
            var results = newxs
                .Select(x =>
                {
                    var i = 0;
                    Func<int, double> interpolate = j => (ys[j + 1] - ys[j]) / (xs[j + 1] - xs[j]) * (x - xs[j]) + ys[j];

                    if (x < xs[0])
                    {
                        if (interpolationType == InterpolationType.Linear)
                            return interpolate(0);
                        else if (interpolationType == InterpolationType.Flat)
                            return ys[0];
                        else
                            return double.NaN;
                    }
                    if (x > xs[xs.Count() - 1])
                    {
                        if (interpolationType == InterpolationType.Linear)
                            return interpolate(xs.Count() - 2);
                        else if (interpolationType == InterpolationType.Flat)
                            return ys[xs.Count() - 1];
                        else
                            return double.NaN;
                    }

                    for (i = 0; i < xs.Count(); i++)
                    {
                        if (xs[i] <= x && xs[i + 1] >= x) break;
                    }

                    return interpolate(i);
                })
                .ToList();

            return results.ToArray();
        }
Example #27
0
        public CPICashFlow(double notional,
                         ZeroInflationIndex index,
                         Date baseDate,
                         double baseFixing,
                         Date fixingDate,
                         Date paymentDate,
                         bool growthOnly = false,
                         InterpolationType interpolation = InterpolationType.AsIndex,
                         Frequency frequency = Frequency.NoFrequency)
            : base(notional, index, baseDate, fixingDate,paymentDate, growthOnly)
        {
            baseFixing_= baseFixing;
             interpolation_= interpolation;
             frequency_=frequency;

             if(Math.Abs(baseFixing_) <= 1e-16)
               throw new ApplicationException("|baseFixing|<1e-16, future divide-by-zero error");

             if (interpolation_ != InterpolationType.AsIndex)
             {
               if ( frequency_ == Frequency.NoFrequency)
                  throw new ApplicationException ("non-index interpolation w/o frequency");
             }
        }
 public ArcGISImageCapabilities(string url, long startTime = -1, long endTime = -1, string format = "jpgpng", InterpolationType interpolation = InterpolationType.RSP_NearestNeighbor)
 {
     ServiceUrl    = url;
     Format        = format;
     Interpolation = interpolation;
     StartTime     = startTime;
     EndTime       = endTime;
 }
Example #29
0
        public static void AddScaleCurves(AnimationClip clip, string animationPath, NativeArray <float> times, NativeArray <Vector3> translations, InterpolationType interpolationType)
        {
            // TODO: Refactor interface to use Unity.Mathematics types and remove this Reinterpret
            var values = translations.Reinterpret <float3>();

            AddVec3Curves(clip, animationPath, "localScale.", times, values, interpolationType);
        }
Example #30
0
        public static HSD_FOBJ EncodeFrames(List <FOBJKey> Keys, byte TrackType)
        {
            HSD_FOBJ fobj = new HSD_FOBJ();

            fobj.AnimationType = TrackType;

            // perform quantization
            FOBJQuantanizer valueQ   = new FOBJQuantanizer();
            FOBJQuantanizer tangentQ = new FOBJQuantanizer();

            foreach (FOBJKey key in Keys)
            {
                valueQ.AddValue(key.Value);
                tangentQ.AddValue(key.Tan);
            }

            fobj.ValueScale  = valueQ.GetValueScale();
            fobj.ValueFormat = valueQ.GetDataFormat();

            fobj.TanScale  = tangentQ.GetValueScale();
            fobj.TanFormat = tangentQ.GetDataFormat();

            MemoryStream o = new MemoryStream();

            using (HSDWriter Writer = new HSDWriter(o))
            {
                Writer.BigEndian = false;

                int time = 0;
                for (int i = 0; i < Keys.Count;)
                {
                    InterpolationType ip = Keys[i].InterpolationType;
                    int j;
                    for (j = 0; j < Keys.Count - i; j++)
                    {
                        if (Keys[i + j].InterpolationType != ip)
                        {
                            break;
                        }
                    }

                    int flag = ((j - 1) << 4) | (int)ip;
                    Writer.ExtendedByte(flag);

                    for (int k = i; k < i + j; k++)
                    {
                        int DeltaTime = 0;

                        if (k + 1 < Keys.Count)
                        {
                            DeltaTime = (int)(Keys[k + 1].Frame - Keys[k].Frame);
                        }

                        if (k == Keys.Count)
                        {
                            DeltaTime = 1;
                        }

                        switch (ip)
                        {
                        case InterpolationType.Step:
                            valueQ.WriteValue(Writer, Keys[k].Value);
                            Writer.ExtendedByte(DeltaTime);
                            break;

                        case InterpolationType.Linear:
                            valueQ.WriteValue(Writer, Keys[k].Value);
                            Writer.ExtendedByte(DeltaTime);
                            break;

                        case InterpolationType.HermiteValue:
                            valueQ.WriteValue(Writer, Keys[k].Value);
                            Writer.ExtendedByte(DeltaTime);
                            break;

                        case InterpolationType.Hermite:
                            valueQ.WriteValue(Writer, Keys[k].Value);
                            tangentQ.WriteValue(Writer, Keys[k].Tan);
                            Writer.ExtendedByte(DeltaTime);
                            break;

                        case InterpolationType.HermiteCurve:
                            tangentQ.WriteValue(Writer, Keys[k].Tan);
                            break;

                        case InterpolationType.Constant:
                            valueQ.WriteValue(Writer, Keys[k].Value);
                            break;

                        default:
                            throw new Exception("end");
                        }

                        if (ip != InterpolationType.HermiteCurve)
                        {
                            time = (int)Keys[k].Frame;
                        }
                    }

                    i += j;
                }
            }
            fobj.Data = o.ToArray();
            o.Close();
            o.Dispose();
            return(fobj);
        }
                public void SetTarget(Vector2 target, float moveTime, Vector2 current, float tolerance, InterpolationType interpolationType)
                {
                    if (!IsLerping() || _interpolationType != interpolationType || Mathf.Abs(target.x - _target.x) > tolerance || Mathf.Abs(target.y - _target.y) > tolerance)
                    {
                        _lerp = 1f;
                        _from = current;
                        _interpolationType = interpolationType;
                    }

                    _lerpSpeed = 1f / moveTime;
                    _target    = target;
                }
Example #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Timeline{T}"/> class. This constructor overrides the duration
 /// of the timeline with the given value.
 /// </summary>
 /// <param name="interpolation">The interpolation type of the timeline.</param>
 /// <param name="timestamps">The timestamps in the timeline.</param>
 /// <param name="values">The values at the timestamps in the timeline.</param>
 /// <param name="duration">The duration of the timeline.</param>
 public Timeline(InterpolationType interpolation, IReadOnlyCollection <uint> timestamps, IReadOnlyCollection <T> values, float duration)
     : this(interpolation, timestamps, values)
 {
     this.Duration = duration;
 }
Example #33
0
        private void GetControlPoint(List <DrawablePoint> p, int count, bool closePath, float factor, InterpolationType type = InterpolationType.Catmullrom)
        {
            DrawablePoint p0 = new DrawablePoint();   // prev point
            DrawablePoint p1 = new DrawablePoint();   // current point
            DrawablePoint p2 = new DrawablePoint();   // next point

            for (int i = 0; i < count; i++)
            {
                p1.Set(p[i]);

                if (i == 0)
                {
                    if (closePath)
                    {
                        p0.Set(p[count - 1]);
                    }
                    else
                    {
                        p0.Set(p1);
                    }
                }
                else
                {
                    p0.Set(p[i - 1]);
                }

                if (i == count - 1)
                {
                    if (closePath)
                    {
                        p2.Set(p[0]);
                    }
                    else
                    {
                        p2.Set(p1);
                    }
                }
                else
                {
                    p2.Set(p[i + 1]);
                }

                float d1 = p0.GetDistance(p1);
                float d2 = p1.GetDistance(p2);

                if (type == InterpolationType.Catmullrom)
                {
                    float d1_a  = (float)Math.Pow(d1, factor); // factor 기본 값 : 0.5
                    float d1_2a = d1_a * d1_a;
                    float d2_a  = (float)Math.Pow(d2, factor);
                    float d2_2a = d2_a * d2_a;

                    if (i != 0 || closePath)
                    {
                        float A = 2 * d2_2a + 3 * d2_a * d1_a + d1_2a;
                        float N = 3 * d2_a * (d2_a + d1_a);

                        if (N != 0)
                        {
                            p[i].SetIn((d2_2a * p0.X + A * p1.X - d1_2a * p2.X) / N, (d2_2a * p0.Y + A * p1.Y - d1_2a * p2.Y) / N);
                        }
                        else
                        {
                            p[i].SetIn(p1.X, p1.Y);
                        }
                    }
                    else
                    {
                        p[i].SetIn(p1.X, p1.Y);
                    }

                    if (i != count - 1 || closePath)
                    {
                        float A = 2 * d1_2a + 3 * d1_a * d2_a + d2_2a;
                        float N = 3 * d1_a * (d1_a + d2_a);

                        if (N != 0)
                        {
                            p[i].SetOut((d1_2a * p2.X + A * p1.X - d2_2a * p0.X) / N, (d1_2a * p2.Y + A * p1.Y - d2_2a * p0.Y) / N);
                        }
                        else
                        {
                            p[i].SetOut(p1.X, p1.Y);
                        }
                    }
                    else
                    {
                        p[i].SetOut(p1.X, p1.Y);
                    }
                }
                else
                {
                    float vx = p0.X - p2.X;
                    float vy = p0.Y - p2.Y;
                    float t  = factor; // factor 기본값 : 0.4
                    float k  = t * d1 / (d1 + d2);

                    if (i != 0 || closePath)
                    {
                        p[i].SetIn(p1.X + vx * k, p1.Y + vy * k);
                    }
                    else
                    {
                        p[i].SetIn(p1.X, p1.Y);
                    }

                    if (i != count - 1 || closePath)
                    {
                        p[i].SetOut(p1.X + vx * (k - t), p1.Y + vy * (k - t));
                    }
                    else
                    {
                        p[i].SetOut(p1.X, p1.Y);
                    }
                }
            }
        }
Example #34
0
        public void cpibondconsistency()
        {
            CommonVars common = new CommonVars();

            // ZeroInflationSwap aka CPISwap

            CPISwap.Type type    = CPISwap.Type.Payer;
            double       nominal = 1000000.0;
            bool         subtractInflationNominal = true;
            // float+spread leg
            double                spread                 = 0.0;
            DayCounter            floatDayCount          = new Actual365Fixed();
            BusinessDayConvention floatPaymentConvention = BusinessDayConvention.ModifiedFollowing;
            int       fixingDays = 0;
            IborIndex floatIndex = new GBPLibor(new Period(6, TimeUnit.Months), common.nominalUK);

            // fixed x inflation leg
            double                fixedRate                = 0.1;   //1% would be 0.01
            double                baseCPI                  = 206.1; // would be 206.13871 if we were interpolating
            DayCounter            fixedDayCount            = new Actual365Fixed();
            BusinessDayConvention fixedPaymentConvention   = BusinessDayConvention.ModifiedFollowing;
            Calendar              fixedPaymentCalendar     = new UnitedKingdom();
            ZeroInflationIndex    fixedIndex               = common.ii;
            Period                contractObservationLag   = common.contractObservationLag;
            InterpolationType     observationInterpolation = common.contractObservationInterpolation;

            // set the schedules
            Date     startDate     = new Date(2, Month.October, 2007);
            Date     endDate       = new Date(2, Month.October, 2052);
            Schedule floatSchedule = new MakeSchedule().from(startDate).to(endDate)
                                     .withTenor(new Period(6, TimeUnit.Months))
                                     .withCalendar(new UnitedKingdom())
                                     .withConvention(floatPaymentConvention)
                                     .backwards().value();
            Schedule fixedSchedule = new MakeSchedule().from(startDate).to(endDate)
                                     .withTenor(new Period(6, TimeUnit.Months))
                                     .withCalendar(new UnitedKingdom())
                                     .withConvention(BusinessDayConvention.Unadjusted)
                                     .backwards().value();

            CPISwap zisV = new CPISwap(type, nominal, subtractInflationNominal,
                                       spread, floatDayCount, floatSchedule,
                                       floatPaymentConvention, fixingDays, floatIndex,
                                       fixedRate, baseCPI, fixedDayCount, fixedSchedule,
                                       fixedPaymentConvention, contractObservationLag,
                                       fixedIndex, observationInterpolation);

            double[] floatFix = { 0.06255, 0.05975, 0.0637, 0.018425, 0.0073438, -1, -1 };
            double[] cpiFix   = { 211.4, 217.2, 211.4, 213.4, -2, -2 };
            for (int i = 0; i < floatSchedule.Count; i++)
            {
                if (floatSchedule[i] < common.evaluationDate)
                {
                    floatIndex.addFixing(floatSchedule[i], floatFix[i], true); //true=overwrite
                }

                CPICoupon zic = zisV.cpiLeg()[i] as CPICoupon;
                if (zic != null)
                {
                    if (zic.fixingDate() < (common.evaluationDate - new Period(1, TimeUnit.Months)))
                    {
                        fixedIndex.addFixing(zic.fixingDate(), cpiFix[i], true);
                    }
                }
            }

            // simple structure so simple pricing engine - most work done by index
            DiscountingSwapEngine dse = new DiscountingSwapEngine(common.nominalUK);

            zisV.setPricingEngine(dse);

            // now do the bond equivalent
            List <double> fixedRates     = new InitializedList <double>(1, fixedRate);
            int           settlementDays = 1;// cannot be zero!
            bool          growthOnly     = true;
            CPIBond       cpiB           = new CPIBond(settlementDays, nominal, growthOnly,
                                                       baseCPI, contractObservationLag, fixedIndex,
                                                       observationInterpolation, fixedSchedule,
                                                       fixedRates, fixedDayCount, fixedPaymentConvention);

            DiscountingBondEngine dbe = new DiscountingBondEngine(common.nominalUK);

            cpiB.setPricingEngine(dbe);

            QAssert.IsTrue(Math.Abs(cpiB.NPV() - zisV.legNPV(0).GetValueOrDefault()) < 1e-5,
                           "cpi bond does not equal equivalent cpi swap leg");
            // remove circular refernce
            common.hcpi.linkTo(null);
        }
Example #35
0
    public static void Animate(Color from, Color to, float over, Action <Color> onChange, bool fullValue = false, float delay = 0f, InterpolationType type = InterpolationType.Linear, MonoBehaviour obj = null)
    {
        obj = obj == null ? BaseScript.Instance : obj;
        var fromVec = new Vector3(from.r, from.g, from.b);
        var toVec   = new Vector3(to.r, to.g, to.b);

        obj.StartCoroutine(Animation(fromVec, toVec, over, v => onChange(new Color(v.x, v.y, v.z)), fullValue, delay, type));
    }
Example #36
0
 public static void Animate(Vector3 from, Vector3 to, float over, Action <Vector3> onChange, bool fullValue = false, float delay = 0f, InterpolationType type = InterpolationType.Linear, MonoBehaviour obj = null)
 {
     obj = obj == null ? BaseScript.Instance : obj;
     obj.StartCoroutine(Animation(from, to, over, onChange, fullValue, delay, type));
 }
Example #37
0
    private static IEnumerator Animation(Vector3 from, Vector3 to, float over, Action <Vector3> action, bool fullValue, float delay, InterpolationType type)
    {
        yield return(new WaitForSeconds(delay));

        var t      = 0f;
        var result = from;

        while (t < over)
        {
            var x    = Interpolate(from.x, to.x, over, t, type);
            var y    = Interpolate(from.y, to.y, over, t, type);
            var z    = Interpolate(from.z, to.z, over, t, type);
            var temp = new Vector3(x, y, z);
            result += temp;
            action(fullValue ? result : temp);
            t += Time.deltaTime;
            yield return(null);
        }
        action(fullValue ? to : to - result);
    }
Example #38
0
 public static void Animate(float from, float to, float over, Action <float> onChange, bool fullValue = false, float delay = 0f, InterpolationType type = InterpolationType.Linear, MonoBehaviour obj = null)
 {
     obj = obj == null ? BaseScript.Instance : obj;
     obj.StartCoroutine(Animation(new Vector3(from, 0), new Vector3(to, 0), over, v => onChange(v.x), fullValue, delay, type));
 }
Example #39
0
 public Config(InterpolationType type, float speed)
 {
     _interpolationType  = type;
     _interpolationSpeed = speed;
 }
Example #40
0
        public static TweeningFunction GetInterpolationFunction(InterpolationType type, Easing easing)
        {
            switch (type)
            {
                case InterpolationType.Back:
                    switch (easing)
                    {
                        case Easing.In:
                            return Back.EaseIn;
                        case Easing.Out:
                            return Back.EaseOut;
                        case Easing.InOut:
                            return Back.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Bounce:
                    switch (easing)
                    {
                        case Easing.In:
                            return Bounce.EaseIn;
                        case Easing.Out:
                            return Bounce.EaseOut;
                        case Easing.InOut:
                            return Bounce.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Circular:
                    switch (easing)
                    {
                        case Easing.In:
                            return Circular.EaseIn;
                        case Easing.Out:
                            return Circular.EaseOut;
                        case Easing.InOut:
                            return Circular.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Cubic:
                    switch (easing)
                    {
                        case Easing.In:
                            return Cubic.EaseIn;
                        case Easing.Out:
                            return Cubic.EaseOut;
                        case Easing.InOut:
                            return Cubic.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Elastic:
                    switch (easing)
                    {
                        case Easing.In:
                            return Elastic.EaseIn;
                        case Easing.Out:
                            return Elastic.EaseOut;
                        case Easing.InOut:
                            return Elastic.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Exponential:
                    switch (easing)
                    {
                        case Easing.In:
                            return Exponential.EaseIn;
                        case Easing.Out:
                            return Exponential.EaseOut;
                        case Easing.InOut:
                            return Exponential.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Linear:
                    switch (easing)
                    {
                        case Easing.In:
                            return Linear.EaseIn;
                        case Easing.Out:
                            return Linear.EaseOut;
                        case Easing.InOut:
                            return Linear.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Quadratic:
                    switch (easing)
                    {
                        case Easing.In:
                            return Quadratic.EaseIn;
                        case Easing.Out:
                            return Quadratic.EaseOut;
                        case Easing.InOut:
                            return Quadratic.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Quartic:
                    switch (easing)
                    {
                        case Easing.In:
                            return Quartic.EaseIn;
                        case Easing.Out:
                            return Quartic.EaseOut;
                        case Easing.InOut:
                            return Quartic.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Quintic:
                    switch (easing)
                    {
                        case Easing.In:
                            return Quintic.EaseIn;
                        case Easing.Out:
                            return Quintic.EaseOut;
                        case Easing.InOut:
                            return Quintic.EaseInOut;
                        default:
                            throw new Exception();
                    }
                case InterpolationType.Sinusoidal:
                    switch (easing)
                    {
                        case Easing.In:
                            return Sinusoidal.EaseIn;
                        case Easing.Out:
                            return Sinusoidal.EaseOut;
                        case Easing.InOut:
                            return Sinusoidal.EaseInOut;
                        default:
                            throw new Exception();
                    }
                default:
                    throw new Exception();

            }

        }
Example #41
0
        static void AddVec3Curves(AnimationClip clip, string animationPath, string propertyPrefix, NativeArray <float> times, NativeArray <float3> values, InterpolationType interpolationType)
        {
            Profiler.BeginSample("AnimationUtils.AddVec3Curves");
            var curveX = new AnimationCurve();
            var curveY = new AnimationCurve();
            var curveZ = new AnimationCurve();

#if DEBUG
            uint duplicates = 0;
#endif

            switch (interpolationType)
            {
            case InterpolationType.STEP: {
                for (var i = 0; i < times.Length; i++)
                {
                    var time  = times[i];
                    var value = values[i];
                    curveX.AddKey(new Keyframe(time, value.x, float.PositiveInfinity, 0));
                    curveY.AddKey(new Keyframe(time, value.y, float.PositiveInfinity, 0));
                    curveZ.AddKey(new Keyframe(time, value.z, float.PositiveInfinity, 0));
                }
                break;
            }

            case InterpolationType.CUBICSPLINE: {
                for (var i = 0; i < times.Length; i++)
                {
                    var time       = times[i];
                    var inTangent  = values[i * 3];
                    var value      = values[i * 3 + 1];
                    var outTangent = values[i * 3 + 2];
                    curveX.AddKey(new Keyframe(time, value.x, inTangent.x, outTangent.x, .5f, .5f));
                    curveY.AddKey(new Keyframe(time, value.y, inTangent.y, outTangent.y, .5f, .5f));
                    curveZ.AddKey(new Keyframe(time, value.z, inTangent.z, outTangent.z, .5f, .5f));
                }
                break;
            }

            default: {     // LINEAR
                var prevTime  = times[0];
                var prevValue = values[0];
                var inTangent = new float3(0f);

                for (var i = 1; i < times.Length; i++)
                {
                    var time  = times[i];
                    var value = values[i];

                    if (prevTime >= time)
                    {
                        // Time value is not increasing, so we ignore this keyframe
                        // This happened on some Sketchfab files (see #298)
#if DEBUG
                        duplicates++;
#endif
                        continue;
                    }

                    var    dT = time - prevTime;
                    var    dV = value - prevValue;
                    float3 outTangent;
                    if (dT < k_TimeEpsilon)
                    {
                        outTangent.x = (dV.x < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                        outTangent.y = (dV.y < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                        outTangent.z = (dV.z < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                    }
                    else
                    {
                        outTangent = dV / dT;
                    }

                    curveX.AddKey(new Keyframe(prevTime, prevValue.x, inTangent.x, outTangent.x));
                    curveY.AddKey(new Keyframe(prevTime, prevValue.y, inTangent.y, outTangent.y));
                    curveZ.AddKey(new Keyframe(prevTime, prevValue.z, inTangent.z, outTangent.z));

                    inTangent = outTangent;
                    prevTime  = time;
                    prevValue = value;
                }

                curveX.AddKey(new Keyframe(prevTime, prevValue.x, inTangent.x, 0));
                curveY.AddKey(new Keyframe(prevTime, prevValue.y, inTangent.y, 0));
                curveZ.AddKey(new Keyframe(prevTime, prevValue.z, inTangent.z, 0));

                break;
            }
            }

            clip.SetCurve(animationPath, typeof(Transform), $"{propertyPrefix}x", curveX);
            clip.SetCurve(animationPath, typeof(Transform), $"{propertyPrefix}y", curveY);
            clip.SetCurve(animationPath, typeof(Transform), $"{propertyPrefix}z", curveZ);
            Profiler.EndSample();
#if DEBUG
            if (duplicates > 0)
            {
                ReportDuplicateKeyframes();
            }
#endif
        }
Example #42
0
        public List <FOBJKey> GetKeys(float FrameCount = -1)
        {
            List <FOBJKey> Keys  = new List <FOBJKey>();
            int            clock = 0;

            Reader.Seek(0);
            while (Reader.Position() < FOBJ.Data.Length)
            {
                int type = Reader.ExtendedByte();
                InterpolationType interpolation = (InterpolationType)((type) & 0x0F);
                int numOfKey = ((type >> 4)) + 1;
                if (interpolation == 0)
                {
                    break;
                }

                for (int i = 0; i < numOfKey; i++)
                {
                    double value = 0;
                    double tan   = 0;
                    int    time  = 0;
                    switch (interpolation)
                    {
                    case InterpolationType.Step:
                        value = ReadVal(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ExtendedByte();
                        break;

                    case InterpolationType.Linear:
                        value = ReadVal(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ExtendedByte();
                        break;

                    case InterpolationType.HermiteValue:
                        value = ReadVal(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ExtendedByte();
                        break;

                    case InterpolationType.Hermite:
                        value = ReadVal(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        tan   = ReadVal(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        time  = Reader.ExtendedByte();
                        break;

                    case InterpolationType.HermiteCurve:
                        tan = ReadVal(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        break;

                    case InterpolationType.Constant:
                        value = ReadVal(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        break;

                    default:
                        throw new Exception("Unknown Interpolation Type " + interpolation.ToString("X"));
                    }
                    //Console.WriteLine(clock + " " + value + " " + FOBJ.ValueFormat );

                    FOBJKey kf = new FOBJKey();
                    kf.InterpolationType = interpolation;
                    kf.Value             = (float)value;
                    kf.Frame             = clock;
                    kf.Tan = (float)tan;
                    Keys.Add(kf);
                    clock += time;
                }
            }
            return(Keys);
        }
Example #43
0
            // setup
            public CommonVars()
            {
                backup    = new SavedSettings();
                cleaner   = new IndexHistoryCleaner();
                nominalUK = new RelinkableHandle <YieldTermStructure>();
                cpiUK     = new RelinkableHandle <ZeroInflationTermStructure>();
                hcpi      = new RelinkableHandle <ZeroInflationTermStructure>();
                zciisD    = new List <Date>();
                zciisR    = new List <double>();
                hii       = new RelinkableHandle <ZeroInflationIndex>();

                nominals = new InitializedList <double>(1, 1000000);
                // option variables
                frequency = Frequency.Annual;
                // usual setup
                volatility = 0.01;
                length     = 7;
                calendar   = new UnitedKingdom();
                convention = BusinessDayConvention.ModifiedFollowing;
                Date today = new Date(25, Month.November, 2009);

                evaluationDate = calendar.adjust(today);
                Settings.setEvaluationDate(evaluationDate);
                settlementDays = 0;
                fixingDays     = 0;
                settlement     = calendar.advance(today, settlementDays, TimeUnit.Days);
                startDate      = settlement;
                dcZCIIS        = new ActualActual();
                dcNominal      = new ActualActual();

                // uk rpi index
                //      fixing data
                Date     from        = new Date(20, Month.July, 2007);
                Date     to          = new Date(20, Month.November, 2009);
                Schedule rpiSchedule = new MakeSchedule().from(from).to(to)
                                       .withTenor(new Period(1, TimeUnit.Months))
                                       .withCalendar(new UnitedKingdom())
                                       .withConvention(BusinessDayConvention.ModifiedFollowing).value();

                double[] fixData =
                {
                    206.1,  207.3, 208.0, 208.9, 209.7, 210.9,
                    209.8,  211.4, 212.1, 214.0, 215.1, 216.8,
                    216.5,  217.2, 218.4, 217.7,   216,
                    212.9,  210.1, 211.4, 211.3, 211.5,
                    212.8,  213.4, 213.4, 213.4, 214.4,
                    -999.0, -999.0
                };

                // link from cpi index to cpi TS
                bool interp = false;// this MUST be false because the observation lag is only 2 months

                // for ZCIIS; but not for contract if the contract uses a bigger lag.
                ii = new UKRPI(interp, hcpi);
                for (int i = 0; i < rpiSchedule.Count; i++)
                {
                    ii.addFixing(rpiSchedule[i], fixData[i], true); // force overwrite in case multiple use
                }

                Datum[] nominalData =
                {
                    new Datum(new Date(26, Month.November,  2009),   0.475),
                    new Datum(new Date(2,  Month.December,  2009), 0.47498),
                    new Datum(new Date(29, Month.December,  2009), 0.49988),
                    new Datum(new Date(25, Month.February,  2010), 0.59955),
                    new Datum(new Date(18, Month.March,     2010), 0.65361),
                    new Datum(new Date(25, Month.May,       2010), 0.82830),
                    new Datum(new Date(17, Month.June,      2010),     0.7),
                    new Datum(new Date(16, Month.September, 2010), 0.78960),
                    new Datum(new Date(16, Month.December,  2010), 0.93762),
                    new Datum(new Date(17, Month.March,     2011), 1.12037),
                    new Datum(new Date(22, Month.September, 2011), 1.52011),
                    new Datum(new Date(25, Month.November,  2011), 1.78399),
                    new Datum(new Date(26, Month.November,  2012), 2.41170),
                    new Datum(new Date(25, Month.November,  2013), 2.83935),
                    new Datum(new Date(25, Month.November,  2014), 3.12888),
                    new Datum(new Date(25, Month.November,  2015), 3.34298),
                    new Datum(new Date(25, Month.November,  2016), 3.50632),
                    new Datum(new Date(27, Month.November,  2017), 3.63666),
                    new Datum(new Date(26, Month.November,  2018), 3.74723),
                    new Datum(new Date(25, Month.November,  2019), 3.83988),
                    new Datum(new Date(25, Month.November,  2021), 4.00508),
                    new Datum(new Date(25, Month.November,  2024), 4.16042),
                    new Datum(new Date(26, Month.November,  2029), 4.15577),
                    new Datum(new Date(27, Month.November,  2034), 4.04933),
                    new Datum(new Date(25, Month.November,  2039), 3.95217),
                    new Datum(new Date(25, Month.November,  2049), 3.80932),
                    new Datum(new Date(25, Month.November,  2059), 3.80849),
                    new Datum(new Date(25, Month.November,  2069), 3.72677),
                    new Datum(new Date(27, Month.November,  2079), 3.63082)
                };
                int nominalDataLength = 30 - 1;

                List <Date>   nomD = new List <Date>();
                List <double> nomR = new List <double>();

                for (int i = 0; i < nominalDataLength; i++)
                {
                    nomD.Add(nominalData[i].date);
                    nomR.Add(nominalData[i].rate / 100.0);
                }
                YieldTermStructure nominal = new InterpolatedZeroCurve <Linear>(nomD, nomR, dcNominal);

                nominalUK.linkTo(nominal);

                // now build the zero inflation curve
                observationLag                   = new Period(2, TimeUnit.Months);
                contractObservationLag           = new Period(3, TimeUnit.Months);
                contractObservationInterpolation = InterpolationType.Flat;

                Datum[] zciisData =
                {
                    new Datum(new Date(25, Month.November, 2010),  3.0495),
                    new Datum(new Date(25, Month.November, 2011),    2.93),
                    new Datum(new Date(26, Month.November, 2012),  2.9795),
                    new Datum(new Date(25, Month.November, 2013),   3.029),
                    new Datum(new Date(25, Month.November, 2014),  3.1425),
                    new Datum(new Date(25, Month.November, 2015),   3.211),
                    new Datum(new Date(25, Month.November, 2016),  3.2675),
                    new Datum(new Date(25, Month.November, 2017),  3.3625),
                    new Datum(new Date(25, Month.November, 2018),   3.405),
                    new Datum(new Date(25, Month.November, 2019),    3.48),
                    new Datum(new Date(25, Month.November, 2021),   3.576),
                    new Datum(new Date(25, Month.November, 2024),   3.649),
                    new Datum(new Date(26, Month.November, 2029),   3.751),
                    new Datum(new Date(27, Month.November, 2034), 3.77225),
                    new Datum(new Date(25, Month.November, 2039),    3.77),
                    new Datum(new Date(25, Month.November, 2049),   3.734),
                    new Datum(new Date(25, Month.November, 2059), 3.714)
                };
                zciisDataLength = 17;
                for (int i = 0; i < zciisDataLength; i++)
                {
                    zciisD.Add(zciisData[i].date);
                    zciisR.Add(zciisData[i].rate);
                }

                // now build the helpers ...
                List <BootstrapHelper <ZeroInflationTermStructure> > helpers = makeHelpers(zciisData, zciisDataLength, ii,
                                                                                           observationLag, calendar, convention, dcZCIIS);

                // we can use historical or first ZCIIS for this
                // we know historical is WAY off market-implied, so use market implied flat.
                double baseZeroRate = zciisData[0].rate / 100.0;
                PiecewiseZeroInflationCurve <Linear> pCPIts = new PiecewiseZeroInflationCurve <Linear>(
                    evaluationDate, calendar, dcZCIIS, observationLag, ii.frequency(), ii.interpolated(), baseZeroRate,
                    new Handle <YieldTermStructure>(nominalUK), helpers);

                pCPIts.recalculate();
                cpiUK.linkTo(pCPIts);

                // make sure that the index has the latest zero inflation term structure
                hcpi.linkTo(pCPIts);
            }
        public void ApplyInterpolateToState(object firstStateUncasted, object secondStateUncasted, float time, InterpolationType interpolationType, Easing easing)
        {
            // We gotta find the type that this is:
            string categoryName = "Uncategorized";

            StateSave firstState  = (StateSave)firstStateUncasted;
            StateSave secondState = (StateSave)secondStateUncasted;


            Type type = firstState.GetType();

            categoryName = type.Name;

            foreach (var uncastedControl in this.StatePanel.Controls)
            {
                if (uncastedControl is StateCategoryControl)
                {
                    StateCategoryControl control = uncastedControl as StateCategoryControl;

                    if (control.ContainsState(firstState) && control.ContainsState(secondState))
                    {
                        control.ApplyInterpolateToState(firstState, secondState, time, interpolationType, easing);
                        break;
                    }
                }
            }
        }
Example #45
0
        public void consistency()
        {
            // check inflation leg vs calculation directly from inflation TS
            CommonVars common = new CommonVars();

            // ZeroInflationSwap aka CPISwap
            CPISwap.Type type    = CPISwap.Type.Payer;
            double       nominal = 1000000.0;
            bool         subtractInflationNominal = true;
            // float+spread leg
            double                spread                 = 0.0;
            DayCounter            floatDayCount          = new Actual365Fixed();
            BusinessDayConvention floatPaymentConvention = BusinessDayConvention.ModifiedFollowing;
            int       fixingDays = 0;
            IborIndex floatIndex = new GBPLibor(new Period(6, TimeUnit.Months), common.nominalUK);

            // fixed x inflation leg
            double                fixedRate                = 0.1;   //1% would be 0.01
            double                baseCPI                  = 206.1; // would be 206.13871 if we were interpolating
            DayCounter            fixedDayCount            = new Actual365Fixed();
            BusinessDayConvention fixedPaymentConvention   = BusinessDayConvention.ModifiedFollowing;
            Calendar              fixedPaymentCalendar     = new UnitedKingdom();
            ZeroInflationIndex    fixedIndex               = common.ii;
            Period                contractObservationLag   = common.contractObservationLag;
            InterpolationType     observationInterpolation = common.contractObservationInterpolation;

            // set the schedules
            Date     startDate     = new Date(2, Month.October, 2007);
            Date     endDate       = new Date(2, Month.October, 2052);
            Schedule floatSchedule = new MakeSchedule().from(startDate).to(endDate)
                                     .withTenor(new Period(6, TimeUnit.Months))
                                     .withCalendar(new UnitedKingdom())
                                     .withConvention(floatPaymentConvention)
                                     .backwards().value();
            Schedule fixedSchedule = new MakeSchedule().from(startDate).to(endDate)
                                     .withTenor(new Period(6, TimeUnit.Months))
                                     .withCalendar(new UnitedKingdom())
                                     .withConvention(BusinessDayConvention.Unadjusted)
                                     .backwards().value();


            CPISwap zisV = new CPISwap(type, nominal, subtractInflationNominal,
                                       spread, floatDayCount, floatSchedule,
                                       floatPaymentConvention, fixingDays, floatIndex,
                                       fixedRate, baseCPI, fixedDayCount, fixedSchedule,
                                       fixedPaymentConvention, contractObservationLag,
                                       fixedIndex, observationInterpolation);
            Date asofDate = Settings.evaluationDate();

            double[] floatFix = { 0.06255, 0.05975, 0.0637, 0.018425, 0.0073438, -1, -1 };
            double[] cpiFix   = { 211.4, 217.2, 211.4, 213.4, -2, -2 };
            for (int i = 0; i < floatSchedule.Count; i++)
            {
                if (floatSchedule[i] < common.evaluationDate)
                {
                    floatIndex.addFixing(floatSchedule[i], floatFix[i], true); //true=overwrite
                }

                CPICoupon zic = zisV.cpiLeg()[i] as CPICoupon;
                if (zic != null)
                {
                    if (zic.fixingDate() < (common.evaluationDate - new Period(1, TimeUnit.Months)))
                    {
                        fixedIndex.addFixing(zic.fixingDate(), cpiFix[i], true);
                    }
                }
            }

            // simple structure so simple pricing engine - most work done by index
            DiscountingSwapEngine dse = new DiscountingSwapEngine(common.nominalUK);

            zisV.setPricingEngine(dse);

            // get float+spread & fixed*inflation leg prices separately
            double testInfLegNPV = 0.0;
            double diff;

            for (int i = 0; i < zisV.leg(0).Count; i++)
            {
                Date zicPayDate = (zisV.leg(0))[i].date();
                if (zicPayDate > asofDate)
                {
                    testInfLegNPV += (zisV.leg(0))[i].amount() * common.nominalUK.link.discount(zicPayDate);
                }

                CPICoupon zicV = zisV.cpiLeg()[i] as CPICoupon;
                if (zicV != null)
                {
                    diff = Math.Abs(zicV.rate() - (fixedRate * (zicV.indexFixing() / baseCPI)));
                    QAssert.IsTrue(diff < 1e-8, "failed " + i + "th coupon reconstruction as "
                                   + (fixedRate * (zicV.indexFixing() / baseCPI)) + " vs rate = "
                                   + zicV.rate() + ", with difference: " + diff);
                }
            }

            double error = Math.Abs(testInfLegNPV - zisV.legNPV(0).Value);

            QAssert.IsTrue(error < 1e-5, "failed manual inf leg NPV calc vs pricing engine: " + testInfLegNPV + " vs " +
                           zisV.legNPV(0));

            diff = Math.Abs(1 - zisV.NPV() / 4191660.0);
#if QL_USE_INDEXED_COUPON
            double max_diff = 1e-5;
#else
            double max_diff = 3e-5;
#endif
            QAssert.IsTrue(diff < max_diff, "failed stored consistency value test, ratio = " + diff);

            // remove circular refernce
            common.hcpi.linkTo(null);
        }
        public static CameraParameters InterpolateGreatCircle(CameraParameters from, CameraParameters to, double alphaIn, InterpolationType type, bool fastDirectionMove)
        {
            CameraParameters result   = new CameraParameters();
            double           alpha    = EaseCurve(alphaIn, type);
            double           alphaBIn = Math.Min(1.0, alphaIn * 2);
            double           alphaB   = EaseCurve(alphaBIn, type);

            result.Angle    = to.Angle * alpha + from.Angle * (1.0 - alpha);
            result.Rotation = to.Rotation * alpha + from.Rotation * (1.0 - alpha);

            Vector3d left  = Coordinates.GeoTo3dDouble(from.Lat, from.Lng);
            Vector3d right = Coordinates.GeoTo3dDouble(to.Lat, to.Lng);

            Vector3d mid = Vector3d.Slerp(left, right, alpha);

            Vector2d midV2 = Coordinates.CartesianToLatLng(mid);

            result.Lat = midV2.Y;
            result.Lng = midV2.X;


            result.Zoom       = Math.Pow(2, LogN(to.Zoom, 2) * alpha + LogN(from.Zoom, 2) * (1.0 - alpha));
            result.Opacity    = (double)(to.Opacity * alpha + from.Opacity * (1.0 - alpha));
            result.ViewTarget = Vector3d.Lerp(from.ViewTarget, to.ViewTarget, alpha);

            result.TargetReferenceFrame = to.TargetReferenceFrame;
            if (to.Target == from.Target)
            {
                result.Target = to.Target;
            }
            else
            {
                result.Target = SolarSystemObjects.Custom;
            }
            return(result);
        }
Example #47
0
 public TimedInterpolator(double in_numSeconds, double in_startValue, double in_endValue, Repeate in_repeateType, InterpolationType in_interpolationType)
     : this()
 {
     numSeconds        = in_numSeconds;
     startValue        = in_startValue;
     endValue          = in_endValue;
     distance          = endValue - startValue;
     repeateType       = in_repeateType;
     interpolationType = in_interpolationType;
 }
        public static CameraParameters Interpolate(CameraParameters from, CameraParameters to, double alphaIn, InterpolationType type, bool fastDirectionMove)
        {
            CameraParameters result   = new CameraParameters();
            double           alpha    = EaseCurve(alphaIn, type);
            double           alphaBIn = Math.Min(1.0, alphaIn * 2);
            double           alphaB   = EaseCurve(alphaBIn, type);

            result.Angle    = to.Angle * alpha + from.Angle * (1.0 - alpha);
            result.Rotation = to.Rotation * alpha + from.Rotation * (1.0 - alpha);
            if (fastDirectionMove)
            {
                result.Lat = to.Lat * alphaB + from.Lat * (1.0 - alphaB);
                result.Lng = to.Lng * alphaB + from.Lng * (1.0 - alphaB);
            }
            else
            {
                result.Lat = to.Lat * alpha + from.Lat * (1.0 - alpha);
                result.Lng = to.Lng * alpha + from.Lng * (1.0 - alpha);
            }
            result.Zoom                 = Math.Pow(2, LogN(to.Zoom, 2) * alpha + LogN(from.Zoom, 2) * (1.0 - alpha));
            result.Opacity              = (double)(to.Opacity * alpha + from.Opacity * (1.0 - alpha));
            result.ViewTarget           = Vector3d.Lerp(from.ViewTarget, to.ViewTarget, alpha);
            result.TargetReferenceFrame = to.TargetReferenceFrame;
            if (to.Target == from.Target)
            {
                result.Target = to.Target;
            }
            else
            {
                result.Target = SolarSystemObjects.Custom;
            }
            return(result);
        }
            public void SetAnchoredPosition(Vector2 anchoredPosition, float time = -1f, InterpolationType interpolationType = InterpolationType.InOutCubic)
            {
                Vector2 currentAnchoredPosition = GetRectTransform().anchoredPosition;

                if (time > 0f)
                {
                    _anchorTarget.SetTarget(anchoredPosition, time, currentAnchoredPosition, _targetTolerance, interpolationType);
                }
                else
                {
                    _anchorTarget.Clear();
                    GetRectTransform().anchoredPosition = anchoredPosition;
                }
            }
 public void SetBottom(float target, float time = -1f, InterpolationType interpolationType = InterpolationType.InOutCubic)
 {
     SetOffsetMin(new Vector2(GetRectTransform().offsetMin.x, target), time, interpolationType);
 }
 public void SetRight(float target, float time = -1f, InterpolationType interpolationType = InterpolationType.InOutCubic)
 {
     SetOffsetMax(new Vector2(-target, GetRectTransform().offsetMax.y), time, interpolationType);
 }
Example #52
0
        public static void AddRotationCurves(AnimationClip clip, string animationPath, NativeArray <float> times, NativeArray <Quaternion> quaternions, InterpolationType interpolationType)
        {
            Profiler.BeginSample("AnimationUtils.AddRotationCurves");
            var rotX = new AnimationCurve();
            var rotY = new AnimationCurve();
            var rotZ = new AnimationCurve();
            var rotW = new AnimationCurve();

            // TODO: Refactor interface to use Unity.Mathematics types and remove this Reinterpret
            var values = quaternions.Reinterpret <quaternion>();

#if DEBUG
            uint duplicates = 0;
#endif

            switch (interpolationType)
            {
            case InterpolationType.STEP: {
                for (var i = 0; i < times.Length; i++)
                {
                    var time  = times[i];
                    var value = values[i];
                    rotX.AddKey(new Keyframe(time, value.value.x, float.PositiveInfinity, 0));
                    rotY.AddKey(new Keyframe(time, value.value.y, float.PositiveInfinity, 0));
                    rotZ.AddKey(new Keyframe(time, value.value.z, float.PositiveInfinity, 0));
                    rotW.AddKey(new Keyframe(time, value.value.w, float.PositiveInfinity, 0));
                }
                break;
            }

            case InterpolationType.CUBICSPLINE: {
                for (var i = 0; i < times.Length; i++)
                {
                    var time       = times[i];
                    var inTangent  = values[i * 3];
                    var value      = values[i * 3 + 1];
                    var outTangent = values[i * 3 + 2];
                    rotX.AddKey(new Keyframe(time, value.value.x, inTangent.value.x, outTangent.value.x, .5f, .5f));
                    rotY.AddKey(new Keyframe(time, value.value.y, inTangent.value.y, outTangent.value.y, .5f, .5f));
                    rotZ.AddKey(new Keyframe(time, value.value.z, inTangent.value.z, outTangent.value.z, .5f, .5f));
                    rotW.AddKey(new Keyframe(time, value.value.w, inTangent.value.w, outTangent.value.w, .5f, .5f));
                }
                break;
            }

            default: {     // LINEAR
                var prevTime  = times[0];
                var prevValue = values[0];
                var inTangent = new quaternion(new float4(0f));

                for (var i = 1; i < times.Length; i++)
                {
                    var time  = times[i];
                    var value = values[i];

                    if (prevTime >= time)
                    {
                        // Time value is not increasing, so we ignore this keyframe
                        // This happened on some Sketchfab files (see #298)
#if DEBUG
                        duplicates++;
#endif
                        continue;
                    }

                    // Ensure shortest path rotation ( see https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#interpolation-slerp )
                    if (math.dot(prevValue, value) < 0)
                    {
                        value.value = -value.value;
                    }

                    var        dT = time - prevTime;
                    var        dV = value.value - prevValue.value;
                    quaternion outTangent;
                    if (dT < k_TimeEpsilon)
                    {
                        outTangent.value.x = (dV.x < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                        outTangent.value.y = (dV.y < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                        outTangent.value.z = (dV.z < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                        outTangent.value.w = (dV.w < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                    }
                    else
                    {
                        outTangent = dV / dT;
                    }

                    rotX.AddKey(new Keyframe(prevTime, prevValue.value.x, inTangent.value.x, outTangent.value.x));
                    rotY.AddKey(new Keyframe(prevTime, prevValue.value.y, inTangent.value.y, outTangent.value.y));
                    rotZ.AddKey(new Keyframe(prevTime, prevValue.value.z, inTangent.value.z, outTangent.value.z));
                    rotW.AddKey(new Keyframe(prevTime, prevValue.value.w, inTangent.value.w, outTangent.value.w));

                    inTangent = outTangent;
                    prevTime  = time;
                    prevValue = value;
                }

                rotX.AddKey(new Keyframe(prevTime, prevValue.value.x, inTangent.value.x, 0));
                rotY.AddKey(new Keyframe(prevTime, prevValue.value.y, inTangent.value.y, 0));
                rotZ.AddKey(new Keyframe(prevTime, prevValue.value.z, inTangent.value.z, 0));
                rotW.AddKey(new Keyframe(prevTime, prevValue.value.w, inTangent.value.w, 0));

                break;
            }
            }

            clip.SetCurve(animationPath, typeof(Transform), "localRotation.x", rotX);
            clip.SetCurve(animationPath, typeof(Transform), "localRotation.y", rotY);
            clip.SetCurve(animationPath, typeof(Transform), "localRotation.z", rotZ);
            clip.SetCurve(animationPath, typeof(Transform), "localRotation.w", rotW);
            Profiler.EndSample();

#if DEBUG
            if (duplicates > 0)
            {
                ReportDuplicateKeyframes();
            }
#endif
        }
 public void SetY(float target, float time = -1f, InterpolationType interpolationType = InterpolationType.InOutCubic)
 {
     SetAnchoredPosition(new Vector2(GetRectTransform().anchoredPosition.x, target), time, interpolationType);
 }
Example #54
0
 public ImplicitBasisFunction(BasisType basisType = BasisType.Gradient, InterpolationType interpolationType = InterpolationType.Quintic)
 {
     BasisType         = basisType;
     InterpolationType = interpolationType;
     Seed = (int)DateTime.Now.Ticks;
 }
Example #55
0
 public DynamicAttributeCurved(InterpolationType interpolationType)
 {
     nativePointer = DynamicAttributeCurved_New(interpolationType);
 }
Example #56
0
        static void AddScalarCurve(AnimationClip clip, string animationPath, string propertyPrefix, int curveIndex, int valueStride, NativeArray <float> times, NativeArray <float> values, InterpolationType interpolationType)
        {
            Profiler.BeginSample("AnimationUtils.AddScalarCurve");
            var curve = new AnimationCurve();

#if DEBUG
            uint duplicates = 0;
#endif

            switch (interpolationType)
            {
            case InterpolationType.STEP: {
                for (var i = 0; i < times.Length; i++)
                {
                    var time       = times[i];
                    var valueIndex = i * valueStride + curveIndex;
                    var value      = values[valueIndex];
                    curve.AddKey(new Keyframe(time, value, float.PositiveInfinity, 0));
                }
                break;
            }

            case InterpolationType.CUBICSPLINE: {
                for (var i = 0; i < times.Length; i++)
                {
                    var time       = times[i];
                    var valueIndex = i * valueStride + curveIndex;
                    var inTangent  = values[valueIndex * 3];
                    var value      = values[valueIndex * 3 + 1];
                    var outTangent = values[valueIndex * 3 + 2];
                    curve.AddKey(new Keyframe(time, value, inTangent, outTangent, .5f, .5f));
                }
                break;
            }

            default: {     // LINEAR
                var prevTime  = times[0];
                var prevValue = values[curveIndex];
                var inTangent = 0f;

                for (var i = 1; i < times.Length; i++)
                {
                    var time       = times[i];
                    var valueIndex = i * valueStride + curveIndex;
                    var value      = values[valueIndex];

                    if (prevTime >= time)
                    {
                        // Time value is not increasing, so we ignore this keyframe
                        // This happened on some Sketchfab files (see #298)
#if DEBUG
                        duplicates++;
#endif
                        continue;
                    }

                    var   dT = time - prevTime;
                    var   dV = value - prevValue;
                    float outTangent;
                    if (dT < k_TimeEpsilon)
                    {
                        outTangent = (dV < 0f) ^ (dT < 0f) ? float.NegativeInfinity : float.PositiveInfinity;
                    }
                    else
                    {
                        outTangent = dV / dT;
                    }

                    curve.AddKey(new Keyframe(prevTime, prevValue, inTangent, outTangent));

                    inTangent = outTangent;
                    prevTime  = time;
                    prevValue = value;
                }

                curve.AddKey(new Keyframe(prevTime, prevValue, inTangent, 0));

                break;
            }
            }

            clip.SetCurve(animationPath, typeof(SkinnedMeshRenderer), $"blendShape.{propertyPrefix}", curve);
            Profiler.EndSample();
#if DEBUG
            if (duplicates > 0)
            {
                ReportDuplicateKeyframes();
            }
#endif
        }
Example #57
0
        public void SetSourceType(Int32 which, BasisType newBasisType, InterpolationType newInterpolationType)
        {
            if (which >= Noise.MAX_SOURCES || which < 0) return;

            this.basisFunctions[which].BasisType = newBasisType;
            this.basisFunctions[which].InterpolationType = newInterpolationType;
        }
Example #58
0
 internal static extern IntPtr DynamicAttributeCurved_New(InterpolationType interpolationType);
Example #59
0
        public Tweener(float from, float to, float duration, InterpolationType type, Easing easing)
        {
            Start(from, to, duration, GetInterpolationFunction(type, easing));
            // Start sets Running to true, so let's set it to false
            Running = false;

        }
Example #60
0
 internal static extern void DynamicAttributeCurved_SetInterpolationType(IntPtr ptr, InterpolationType interpolationType);