Ejemplo n.º 1
0
 public static bool CheckIfTop(ObservableCollection <Cuboid> cuboids, Cuboid cuboid)
 {
     foreach (Cuboid c in cuboids)
     {
         if (c != cuboid && c.SitsOn(cuboid))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
        public static bool CheckIfCanBeAdded(ObservableCollection <Cuboid> cuboids, Cuboid cuboid)
        {
            if (cuboid.X < 0 || cuboid.Y < 0 || cuboid.Z < 0)
            {
                return(false);
            }

            if ((cuboid.X + cuboid.Width > Settings.MaxSize) ||
                (cuboid.Y + cuboid.Depth > Settings.MaxSize) ||
                (cuboid.Z + cuboid.Height > Settings.MaxSize))
            {
                return(false);
            }

            foreach (Cuboid c in cuboids)
            {
                if (c != cuboid && c.OverlapsWith(cuboid))
                {
                    return(false);
                }
            }

            if (cuboid.Z == 0)
            {
                return(true);
            }

            bool[,] checks = new bool[cuboid.Width, cuboid.Depth];
            for (int i = 0; i < cuboid.Width; i++)
            {
                for (int j = 0; j < cuboid.Depth; j++)
                {
                    checks[i, j] = false;
                }
            }

            foreach (Cuboid c in cuboids)
            {
                if (cuboid.SitsOn(c))
                {
                    int xStart = cuboid.X > c.X ? cuboid.X : c.X;
                    xStart -= cuboid.X;
                    int yStart = cuboid.Y > c.Y ? cuboid.Y : c.Y;
                    yStart -= cuboid.Y;

                    int xEnd = (cuboid.X + cuboid.Width) < (c.X + c.Width) ? (cuboid.X + cuboid.Width) : (c.X + c.Width);
                    xEnd -= cuboid.X;
                    int yEnd = (cuboid.Y + cuboid.Depth) < (c.Y + c.Depth) ? (cuboid.Y + cuboid.Depth) : (c.Y + c.Depth);
                    yEnd -= cuboid.Y;

                    for (int i = xStart; i < xEnd; i++)
                    {
                        for (int j = yStart; j < yEnd; j++)
                        {
                            checks[i, j] = true;
                        }
                    }
                }
            }

            for (int i = 0; i < cuboid.Width; i++)
            {
                for (int j = 0; j < cuboid.Depth; j++)
                {
                    if (!checks[i, j])
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static int FindLastCoordinateForTopView(ObservableCollection <Cuboid> cuboids, Cuboid cuboid)
        {
            int max = 0;

            foreach (Cuboid c in cuboids)
            {
                if ((c.X <= cuboid.X) && (cuboid.X < c.X + c.Width) &&
                    (c.Y <= cuboid.Y) && (cuboid.Y < c.Y + c.Depth) &&
                    (c.Z + c.Height > max) && cuboid != c)
                {
                    max = c.Z + c.Height;
                }
            }
            return(max);
        }