Beispiel #1
0
        /// <summary>
        /// Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="xParam">The X axis of this surface</param>
        /// <param name="yParam">The Y axis of this surface</param>
        /// <returns>The surface which corresponds to this expression</returns>
        public override Functions.Surface createSurface(Interpreter.InterpretationContext context, Parameter xParam, Parameter yParam)
        {
            Functions.Surface retVal = base.createSurface(context, xParam, yParam);

            if (Term != null)
            {
                retVal = Functions.Surface.createSurface(xParam, yParam, GetValue(context));
            }
            else if (Expression != null)
            {
                if (UnaryOp == null)
                {
                    retVal = Expression.createSurface(context, xParam, yParam);
                }
                else
                {
                    if (UnaryOp == MINUS)
                    {
                        retVal = Expression.createSurface(context, xParam, yParam);
                        retVal.Negate();
                    }
                    else
                    {
                        AddError("Cannot create surface with unary op " + UnaryOp);
                    }
                }
            }
            retVal.XParameter = xParam;
            retVal.YParameter = yParam;

            return(retVal);
        }
        /// <summary>
        /// Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="xParam">The X axis of this surface</param>
        /// <param name="yParam">The Y axis of this surface</param>
        /// <returns>The surface which corresponds to this expression</returns>
        public override Functions.Surface createSurface(Interpreter.InterpretationContext context, Parameter xParam, Parameter yParam)
        {
            Functions.Surface retVal = base.createSurface(context, xParam, yParam);

            Functions.Function function             = getFunction(context);
            Functions.PredefinedFunctions.Cast cast = Called.Ref as Functions.PredefinedFunctions.Cast;
            if (cast != null)
            {
                // In case of cast, just take the surface of the enclosed expression
                Expression actual = (Expression)ActualParameters[0];
                retVal = actual.createSurface(context, xParam, yParam);
            }
            else
            {
                Parameter Xaxis = null;
                Parameter Yaxis = null;

                if (function == null)
                {
                    function = Called.getCalled(context) as Function;
                }

                SelectXandYAxis(context, xParam, yParam, function, out Xaxis, out Yaxis);
                if (Xaxis != null || Yaxis != null)
                {
                    int token = context.LocalScope.PushContext();
                    function.AssignParameters(context, AssignParameterValues(context, function, true));
                    retVal = function.createSurfaceForParameters(context, Xaxis, Yaxis);
                    context.LocalScope.PopContext(token);
                }
                else
                {
                    Values.IValue value = GetValue(context);
                    if (value != null)
                    {
                        retVal = Functions.Surface.createSurface(value, xParam, yParam);
                    }
                    else
                    {
                        throw new Exception("Cannot create surface for expression");
                    }
                }
            }
            retVal.XParameter = xParam;
            retVal.YParameter = yParam;

            return(retVal);
        }
        /// <summary>
        /// Creates the graph for the unbount parameters provided
        /// </summary>
        /// <param name="context"></param>
        /// <param name="expression"></param>
        /// <param name="function"></param>
        /// <param name="unbound"></param>
        /// <returns></returns>
        private Surface createSurfaceForUnbound(InterpretationContext context, Expression expression, Function function, List <Parameter> unbound)
        {
            Surface retVal = null;

            if (unbound.Count == 0)
            {
                if (function != null)
                {
                    Parameter xAxis = null;

                    if (function.FormalParameters.Count > 0)
                    {
                        xAxis = (Parameter)function.FormalParameters[0];
                    }
                    Parameter yAxis = null;
                    if (function.FormalParameters.Count > 1)
                    {
                        yAxis = (Parameter)function.FormalParameters[1];
                    }
                    retVal = function.createSurfaceForParameters(context, xAxis, yAxis);
                }
                else
                {
                    retVal = Surface.createSurface(expression.GetValue(context), null, null);
                }
            }
            else if (unbound.Count == 1)
            {
                Graph graph = createGraphForUnbound(context, expression, function, unbound);
                retVal = Surface.createSurface(graph.Function, unbound[0], null);
            }
            else
            {
                if (function == null)
                {
                    retVal = expression.createSurface(context, unbound[0], unbound[1]);
                }
                else
                {
                    retVal = function.createSurfaceForParameters(context, unbound[0], unbound[1]);
                }
            }
            return(retVal);
        }
Beispiel #4
0
        /// <summary>
        /// Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="xParam">The X axis of this surface</param>
        /// <param name="yParam">The Y axis of this surface</param>
        /// <returns>The surface which corresponds to this expression</returns>
        public override Functions.Surface createSurface(Interpreter.InterpretationContext context, Parameter xParam, Parameter yParam)
        {
            Functions.Surface retVal = base.createSurface(context, xParam, yParam);

            if (xParam == null || yParam == null)
            {
                AddError("Cannot have null parameters for Function expression " + ToString());
            }
            else
            {
                int       token = context.LocalScope.PushContext();
                Parameter xAxis = Parameters[0];
                Parameter yAxis = Parameters[1];
                context.LocalScope.setSurfaceParameters(xAxis, yAxis);
                retVal = Expression.createSurface(context, xAxis, yAxis);
                context.LocalScope.PopContext(token);
            }
            retVal.XParameter = xParam;
            retVal.YParameter = yParam;

            return(retVal);
        }
        /// <summary>
        /// Creates the graph for the unbount parameters provided
        /// </summary>
        /// <param name="context"></param>
        /// <param name="expression"></param>
        /// <param name="function"></param>
        /// <param name="unbound"></param>
        /// <returns></returns>
        private Surface createSurfaceForUnbound(InterpretationContext context, Expression expression, Function function, List<Parameter> unbound)
        {
            Surface retVal = null;

            if (unbound.Count == 0)
            {
                if (function != null)
                {
                    Parameter xAxis = null;

                    if (function.FormalParameters.Count > 0)
                    {
                        xAxis = (Parameter)function.FormalParameters[0];
                    }
                    Parameter yAxis = null;
                    if (function.FormalParameters.Count > 1)
                    {
                        yAxis = (Parameter)function.FormalParameters[1];
                    }
                    retVal = function.createSurfaceForParameters(context, xAxis, yAxis);
                }
                else
                {
                    retVal = Surface.createSurface(expression.GetValue(context), null, null);
                }
            }
            else if (unbound.Count == 1)
            {
                Graph graph = createGraphForUnbound(context, expression, function, unbound);
                retVal = Surface.createSurface(graph.Function, unbound[0], null);
            }
            else
            {
                if (function == null)
                {
                    retVal = expression.createSurface(context, unbound[0], unbound[1]);
                }
                else
                {
                    retVal = function.createSurfaceForParameters(context, unbound[0], unbound[1]);
                }
            }
            return retVal;
        }