Example #1
0
        public static Coord3D OnUnitShape3D(this Radius r, double distance, IRNG rng)
        {
            if (rng is null)
            {
                throw new ArgumentNullException($"rng");
            }
            int x = 0, y = 0, z = 0;

            switch (r)
            {
            case SquidGrid.Radius.Square:
            case SquidGrid.Radius.Diamond:
            case SquidGrid.Radius.Circle:
            case SquidGrid.Radius.RoughCircle:
                Coord p = OnUnitShape(r, distance, rng);
                return(new Coord3D(p.X, p.Y, 0));   //2D strategies

            case SquidGrid.Radius.Cube:
                x = rng.NextInt((int)-distance, (int)distance + 1);
                y = rng.NextInt((int)-distance, (int)distance + 1);
                z = rng.NextInt((int)-distance, (int)distance + 1);
                break;

            case SquidGrid.Radius.Octahedron:
            case SquidGrid.Radius.Sphere:
                do
                {
                    x = rng.NextInt((int)-distance, (int)distance + 1);
                    y = rng.NextInt((int)-distance, (int)distance + 1);
                    z = rng.NextInt((int)-distance, (int)distance + 1);
                } while (Radius(r, x, y, z) > distance);
                break;
            }

            return(new Coord3D(x, y, z));
        }
Example #2
0
        public static Coord OnUnitShape(this Radius r, double distance, IRNG rng)
        {
            if (rng is null)
            {
                throw new ArgumentNullException($"rng");
            }
            int x = 0, y = 0;

            switch (r)
            {
            case SquidGrid.Radius.Square:
            case SquidGrid.Radius.Cube:
                x = rng.NextInt((int)-distance, (int)distance + 1);
                y = rng.NextInt((int)-distance, (int)distance + 1);
                break;

            case SquidGrid.Radius.Diamond:
            case SquidGrid.Radius.Octahedron:
                x = rng.NextInt((int)-distance, (int)distance + 1);
                y = rng.NextInt((int)-distance, (int)distance + 1);
                if (Radius(r, x, y) > distance)
                {
                    if (x > 0)
                    {
                        if (y > 0)
                        {
                            x = (int)(distance - x);
                            y = (int)(distance - y);
                        }
                        else
                        {
                            x = (int)(distance - x);
                            y = (int)(-distance - y);
                        }
                    }
                    else
                    {
                        if (y > 0)
                        {
                            x = (int)(-distance - x);
                            y = (int)(distance - y);
                        }
                        else
                        {
                            x = (int)(-distance - x);
                            y = (int)(-distance - y);
                        }
                    }
                }
                break;

            default:     // includes CIRCLE, SPHERE, and ROUGH_CIRCLE
                double result = distance * Math.Sqrt(rng.NextDouble());
                double theta  = rng.NextDouble(0, pi2);
                x = Convert.ToInt32(Math.Cos(theta) * result);
                y = Convert.ToInt32(Math.Sin(theta) * result);
                break;
            }

            return(Coord.Get(x, y));
        }