コード例 #1
0
        public EvaluatedGradientNode(GradientNode gradient, VariableBag variables)
        {
            _gradient = gradient;
            Min       = gradient.Min.Evaluate(variables);
            Max       = gradient.Max.Evaluate(variables);

            variables.GradientMinimum = Min;
            variables.GradientMaximum = Max;

            var evaluatedStops = new List <EvaluatedStopNode>();

            // ReSharper disable once ForCanBeConvertedToForeach
            // ReSharper disable once LoopCanBeConvertedToQuery
            for (var i = 0; i < gradient.Stops.Length; i++)
            {
                evaluatedStops.Add(gradient.Stops[i].Evaluate(variables));
            }

            Stops = FilterStopsForConflicts(evaluatedStops);

            var colorKeys = new List <GradientColorKey>();
            var alphaKeys = new List <GradientAlphaKey>();

            // ReSharper disable once ForCanBeConvertedToForeach
            for (var i = 0; i < Stops.Count; i++)
            {
                var stop = Stops[i];

                var colorKey = stop.TryConvertToColorKey(Min, Max);
                var alphaKey = stop.TryConvertToAlphaKey(Min, Max);

                if (colorKey != null)
                {
                    colorKeys.Add(colorKey.Value);
                }

                if (alphaKey != null)
                {
                    alphaKeys.Add(alphaKey.Value);
                }
            }

            _unityGradient = new Gradient();
            _unityGradient.SetKeys(colorKeys.ToArray(), alphaKeys.ToArray());
        }
コード例 #2
0
ファイル: Expression.cs プロジェクト: HebaruSan/HotSpot
        public double Evaluate(VariableBag variables)
        {
            if (_constant != null)
            {
                return(_constant.Value);
            }

            if (_variable != null)
            {
                var value = variables.GetValue(_variable.Value);

                if (!double.IsNaN(value))
                {
                    return(value);
                }
            }

            throw new InvalidOperationException($"Expression '{this}' could not be evaluated.");
        }
コード例 #3
0
 public EvaluatedStopNode(StopNode stop, VariableBag variables)
 {
     _stop = stop;
     Value = stop.Value.Evaluate(variables) * stop.Factor;
 }
コード例 #4
0
 public void PopulatePartVariables(Part part, VariableBag variables)
 => _populatePartVariables(part, variables);
コード例 #5
0
 public void PopulateVesselVariables(Vessel vessel, VariableBag variables)
 => _populateVesselVariables(vessel, variables);