ToFuncParam() public method

public ToFuncParam ( double coord, double min, double max ) : double
coord double
min double
max double
return double
Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public override int DrawBatch(int maxBlocksToDraw)
        {
            //ignoring maxBlocksToDraw
            _count = 0;
            int exCount = 0;

            for (Coords.X = Bounds.XMin;
                 Coords.X <= Bounds.XMax && MathCommands.MaxCalculationExceptions >= exCount;
                 ++Coords.X)
            {
                for (Coords.Y = Bounds.YMin;
                     Coords.Y <= Bounds.YMax && MathCommands.MaxCalculationExceptions >= exCount;
                     ++Coords.Y)
                {
                    for (Coords.Z = Bounds.ZMin; Coords.Z <= Bounds.ZMax; ++Coords.Z)
                    {
                        try
                        {
                            if (_expression.Evaluate(_scaler.ToFuncParam(Coords.X, Bounds.XMin, Bounds.XMax),
                                                     _scaler.ToFuncParam(Coords.Y, Bounds.YMin, Bounds.YMax),
                                                     _scaler.ToFuncParam(Coords.Z, Bounds.ZMin, Bounds.ZMax)) > 0) //1.0 means true
                            {
                                if (DrawOneBlock())
                                {
                                    ++_count;
                                }
                            }
                            //if (TimeToEndBatch)
                            //    return _count;
                        }
                        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("Drawing is interrupted: too many (>" +
                                               MathCommands.MaxCalculationExceptions +
                                               ") calculation exceptions.");
                                break;
                            }
                        }
                    }
                }
            }

            IsDone = true;
            return(_count);
        }
Ejemplo n.º 3
0
        //this method exists to box coords nicely as ref params
        private int InternalDraw(ref int arg1, ref int arg2, ref int val, int min1, int max1, int min2, int max2,
                                 int minV, int maxV, int maxBlocksToDraw)
        {
            _count = 0;
            int exCount = 0;

            DrawFasePrepare(min1, max1, min2, max2);

            for (arg1 = min1; arg1 <= max1 && MathCommands.MaxCalculationExceptions >= exCount; ++arg1)
            {
                for (arg2 = min2; arg2 <= max2; ++arg2)
                {
                    try
                    {
                        int fval =
                            _scaler.FromFuncResult(
                                _expression.Evaluate(_scaler.ToFuncParam(arg1, min1, max1),
                                                     _scaler.ToFuncParam(arg2, min2, max2)),
                                minV, maxV);
                        DrawFase1(fval, ref arg1, ref arg2, ref val, min1, max1, min2, max2, minV, maxV, maxBlocksToDraw);
                        //if (TimeToEndBatch)
                        //    return _count;
                    }
                    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("Function drawing is interrupted: too many (>" +
                                           MathCommands.MaxCalculationExceptions + ") calculation exceptions.");
                            break;
                        }
                    }
                }
            }
            //the real drawing for the surface variant
            DrawFase2(ref arg1, ref arg2, ref val, min1, max1, min2, max2, minV, maxV, maxBlocksToDraw);
            return(_count);
        }