public virtual IObjectiveFunction Fork()
        {
            // we need to deep-clone values since they may be updated inplace on evaluation
            ObjectiveFunctionBase objective = (ObjectiveFunctionBase)CreateNew();

            objective.Point    = Point == null ? null : Point.Clone();
            objective.Value    = Value;
            objective.Gradient = Gradient == null ? null : Gradient.Clone();
            objective.Hessian  = Hessian == null ? null : Hessian.Clone();
            return(objective);
        }
Beispiel #2
0
        /// <summary>
        /// Reverses the gradient color and alpha keys.
        /// </summary>
        /// <param name="_Gradient">The original gradient you want to reverse.</param>
        /// <returns>Returns a new Gradient instance with the reversed keys of the input Gradient.</returns>
        public static Gradient Reverse(this Gradient _Gradient)
        {
            Gradient gradient = _Gradient.Clone();

            gradient.colorKeys = new GradientColorKey[_Gradient.colorKeys.Length];
            for (int i = 0; i < _Gradient.colorKeys.Length; i++)
            {
                gradient.colorKeys[i] = new GradientColorKey(_Gradient.colorKeys[i].color, 1f - _Gradient.colorKeys[i].time);
            }

            gradient.alphaKeys = new GradientAlphaKey[_Gradient.alphaKeys.Length];
            for (int i = 0; i < _Gradient.alphaKeys.Length; i++)
            {
                gradient.alphaKeys[i] = new GradientAlphaKey(_Gradient.alphaKeys[i].alpha, 1f - _Gradient.alphaKeys[i].time);
            }

            return(gradient);
        }