fCraft.Expression.EvaluateAsEquality C# (CSharp) Method

EvaluateAsEquality() public method

public EvaluateAsEquality ( ) : double>.Tuple
return double>.Tuple
        public Tuple<double, double> EvaluateAsEquality( params double[] param )
        {
            var stack = new Stack<double>();
            EvaluateInternal( param, stack );
            double compRes = stack.Pop();
            return new Tuple<double, double>( compRes, stack.Pop() );
        }

Usage Example

Example #1
0
        //this method exists to box coords nicely as ref params, note that the set of {arg1, arg2, arg3} must be the same with
        //{ xArg, yArg, zArg }
        private int InternalDraw(ref int arg1, ref int arg2, ref int arg3,
                                 int min1, int max1, int min2, int max2, int min3, int max3,
                                 ref int argX, ref int argY, ref int argZ,
                                 int minX, int maxX, int minY, int maxY, int minZ, int maxZ,
                                 int maxBlocksToDraw)
        {
            _count = 0;
            int exCount = 0;

            for (arg1 = min1; arg1 <= max1 && MathCommands.MaxCalculationExceptions >= exCount; ++arg1)
            {
                for (arg2 = min2; arg2 <= max2 && MathCommands.MaxCalculationExceptions >= exCount; ++arg2)
                {
                    double prevDiff = 0;
                    double prevComp = 0;
                    for (int arg3Iterator = min3; arg3Iterator <= max3; ++arg3Iterator)
                    {
                        try {
                            arg3 = arg3Iterator;
                            Tuple <double, double> res =
                                _expression.EvaluateAsEquality(_scaler.ToFuncParam(argX, minX, maxX),
                                                               _scaler.ToFuncParam(argY, minY, maxY),
                                                               _scaler.ToFuncParam(argZ, minZ, maxZ));
                            //decision: we cant only take points with 0 as comparison result as it will happen almost never.
                            //We are reacting on the changes of the comparison result sign
                            arg3 = int.MaxValue;
                            if (res.Item1 == 0)   //exactly equal, wow, such a surprise
                            {
                                arg3 = arg3Iterator;
                            }
                            else if (res.Item1 * prevComp < 0)                                 //i.e. different signs, but not the prev==0
                            {
                                arg3 = res.Item2 < prevDiff ? arg3Iterator : arg3Iterator - 1; //then choose the closest to 0 difference
                            }
                            if (DrawOneBlock())
                            {
                                ++_count;
                            }
                            //if (TimeToEndBatch)
                            //    return _count;

                            prevComp = res.Item1;
                            prevDiff = res.Item2;
                        } catch (Exception) {
                            //the exception here is kinda of normal, for functions (especially interesting ones)
                            //may have eg punctured points; we just have to keep an eye on the number, since producing 10000
                            //exceptions in the multiclient application is not the best idea
                            if (++exCount > MathCommands.MaxCalculationExceptions)
                            {
                                Player.Message("Surface drawing is interrupted: too many (>" + MathCommands.MaxCalculationExceptions +
                                               ") calculation exceptions.");
                                break;
                            }
                        }
                    }
                }
            }
            return(_count);
        }