Beispiel #1
0
            public static IScalar TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                switch (parsedParams.Identifier)
                {
                case SCALE:
                {
                    parsedParams.RequireCount(module, 2, 3);
                    IScalar input  = Scalars.Require(module, parsedParams[0]);
                    double  scale  = Statics.Parse(module, parsedParams[1]);
                    double  offset = (parsedParams.Count > 2) ? Statics.Parse(module, parsedParams[2]) : 0.0;
                    return(Of(input, scale, offset));
                }

                case OFFSET:
                {
                    parsedParams.RequireCount(module, 2);
                    IScalar input  = Scalars.Require(module, parsedParams[0]);
                    double  offset = Statics.Parse(module, parsedParams[1]);
                    return(Offset(input, offset));
                }

                default:
                    return(null);
                }
            }
Beispiel #2
0
            public static IToggle TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                if (parsedParams.Identifier != TYPE_NAME)
                {
                    return(null);
                }
                parsedParams.RequireCount(module, 2);
                IScalar input     = Scalars.Require(module, parsedParams[0]);
                double  threshold = Statics.Parse(module, parsedParams[1]);

                return(new LessThanOrEqual(input, threshold));
            }
Beispiel #3
0
 public static IScalar TryParse(PartModule module, ParsedParameters parsedParams)
 {
     if (parsedParams == null)
     {
         return(null);
     }
     if (parsedParams.Identifier != TYPE_NAME)
     {
         return(null);
     }
     parsedParams.RequireCount(module, 2, -1);
     IScalar[] inputs = new IScalar[parsedParams.Count];
     for (int i = 0; i < inputs.Length; ++i)
     {
         inputs[i] = Scalars.Require(module, parsedParams[i]);
     }
     return(Of(inputs));
 }
Beispiel #4
0
            public static IToggle TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                if (parsedParams.Identifier != TYPE_NAME)
                {
                    return(null);
                }
                parsedParams.RequireCount(module, 3);
                IScalar input   = Scalars.Require(module, parsedParams[0]);
                double  minimum = Statics.Parse(module, parsedParams[1]);
                double  maximum = Statics.Parse(module, parsedParams[2]);

                if (minimum > maximum)
                {
                    return(Constant.FALSE);
                }
                return(new Between(input, minimum, maximum));
            }
            /// <summary>
            /// Try to get a lerp color source from a ParsedParameters. The expected format is:
            ///
            /// lerp(input, source1, source2)
            /// lerp(input, source1, value1, source2, value2)
            /// </summary>
            public static IColorSource TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                if (parsedParams.Identifier != TYPE_NAME)
                {
                    return(null);
                }
                if ((parsedParams.Count != 3) && (parsedParams.Count != 5))
                {
                    throw new ColorSourceException(
                              module,
                              TYPE_NAME + "() source specified " + parsedParams.Count + " parameters (3 or 5 required)");
                }
                IScalar input = Scalars.Require(module, parsedParams[0]);

                if (parsedParams.Count == 3)
                {
                    return(new LerpColorSource(
                               input,
                               Find(module, parsedParams[1]),
                               0,
                               Find(module, parsedParams[2]),
                               1,
                               parsedParams.ToString()));
                }
                else
                {
                    return(new LerpColorSource(
                               input,
                               Find(module, parsedParams[1]),
                               Statics.Parse(module, parsedParams[2]),
                               Find(module, parsedParams[3]),
                               Statics.Parse(module, parsedParams[4]),
                               parsedParams.ToString()));
                }
            }
Beispiel #6
0
            public static IScalar TryParse(PartModule module, ParsedParameters parsedParams)
            {
                if (parsedParams == null)
                {
                    return(null);
                }
                switch (parsedParams.Identifier)
                {
                case RANGE:
                {
                    parsedParams.RequireCount(module, 3);
                    IScalar input   = Scalars.Require(module, parsedParams[0]);
                    double  minimum = Statics.Parse(module, parsedParams[1]);
                    double  maximum = Statics.Parse(module, parsedParams[2]);
                    return(Between(input, minimum, maximum));
                }

                case GREATER_THAN:
                {
                    parsedParams.RequireCount(module, 2);
                    IScalar input   = Scalars.Require(module, parsedParams[0]);
                    double  minimum = Statics.Parse(module, parsedParams[1]);
                    return(AtLeast(input, minimum));
                }

                case LESS_THAN:
                {
                    parsedParams.RequireCount(module, 2);
                    IScalar input   = Scalars.Require(module, parsedParams[0]);
                    double  maximum = Statics.Parse(module, parsedParams[1]);
                    return(AtMost(input, maximum));
                }

                default:
                    return(null);
                }
            }
 /// <summary>
 /// Find the specified scalar. Throws ArgumentException if there's a problem.
 /// </summary>
 /// <param name="scalarID"></param>
 /// <returns></returns>
 protected IScalar RequireScalar(string scalarID)
 {
     return(Scalars.Require(this, scalarID));
 }
 /// <summary>
 /// Try to find the specified scalar. Returns null if not found or there's a problem.
 /// </summary>
 /// <param name="scalarID"></param>
 /// <returns></returns>
 protected IScalar TryFindScalar(string scalarID)
 {
     return(Scalars.TryParse(this, scalarID));
 }