コード例 #1
0
        public bool Contains(ref IntVector3 point)
        {
            int x = MathExtension.Abs(point.X);
            int y = MathExtension.Abs(point.Y);
            int z = MathExtension.Abs(point.Z);

            return((x + y + z) <= Level);
        }
コード例 #2
0
        public void ForEach(RefAction <IntVector3> action, int startLevel)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            if (startLevel < 0 || Level < startLevel)
            {
                throw new ArgumentOutOfRangeException("startLevel");
            }
            if (Level < 0)
            {
                throw new InvalidOperationException("Invalid value: Level");
            }

            var point = new IntVector3();

            int x = 0;
            int y = 0;
            int z = 0;

            int currentLevel = startLevel;

            x = -currentLevel;

            while (currentLevel <= Level)
            {
                point.X = Center.X + x;
                point.Y = Center.Y + y;
                point.Z = Center.Z + z;

                action(ref point);

                if (z < 0)
                {
                    z *= -1;
                }
                else if (y < 0)
                {
                    y *= -1;
                    z  = -(currentLevel - MathExtension.Abs(x) - MathExtension.Abs(y));
                }
                else
                {
                    y = -y + 1;
                    if (0 < y)
                    {
                        if (++x <= currentLevel)
                        {
                            y = MathExtension.Abs(x) - currentLevel;
                            z = 0;
                        }
                        else
                        {
                            currentLevel++;
                            x = -currentLevel;
                            y = 0;
                            z = 0;
                        }
                    }
                    else
                    {
                        z = -(currentLevel - MathExtension.Abs(x) - MathExtension.Abs(y));
                    }
                }
            }
        }