Ejemplo n.º 1
0
        public void CalculateResult_FindMatchingOffcut_Returns_Null_When_No_Suitable_Offcuts()
        {
            var result = new CalculatorResult(new Tile(12, 12));
            result.Offcuts.Add(new Tile(2, 10));
            result.Offcuts.Add(new Tile(6, 1));

            var offcut = result.FindMatchingOffcut(new Area(3, 5));
            Assert.IsNull(offcut);
        }
Ejemplo n.º 2
0
        public void CalculateResult_FindMatchingOffcut_Can_Return_Suitable_Rotated_Offcut()
        {
            var result = new CalculatorResult(new Tile(12, 12));
            result.Offcuts.Add(new Tile(2, 10));
            result.Offcuts.Add(new Tile(6, 3));

            var offcut = result.FindMatchingOffcut(new Area(3, 5));
            Assert.IsNotNull(offcut);
            Assert.AreEqual(3, offcut.Width);
            Assert.AreEqual(6, offcut.Length);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates the number of whole tiles used, along with the number of cuts
        /// and the total waste percentage.
        /// </summary>
        /// <returns>An instance of CalculatorResult.</returns>
        public CalculatorResult Calculate(Room room, Tile tile, double groutThickness)
        {
            Room = room;
            Tile = tile;
            GroutThickness = groutThickness;

            CalculatorResult result = new CalculatorResult(Tile);

            bool roomComplete = false;
            Point origin = new Point(0, 0);

            while (roomComplete == false)
            {
                // can a whole tile be placed?
                Point destination = new Point(origin.X + Tile.Width, origin.Y + Tile.Length);
                if (destination.X <= Room.Width & destination.Y <= Room.Length)
                {
                    result.WholeTilesUsed++;

                    origin.X += Tile.Width + GroutThickness;
                }

                // there is not enough room in width, a tile has to be cut
                else if (destination.X > Room.Width & destination.Y <= Room.Length)
                {
                    Area availableArea = new Area(Room.Width - origin.X, Tile.Length);

                    // look for an offcut
                    var foundTile = result.FindMatchingOffcut(availableArea);
                    if (foundTile == null)
                    {
                        foundTile = Tile;
                        result.WholeTilesUsed++;
                    }

                    foundTile.CutPartialTile(availableArea).ForEach(o => result.Offcuts.Add(o));

                    origin.X = 0;
                    origin.Y += Tile.Length + GroutThickness;
                }

                // there is not enough room in length, a tile has to be cut
                else if (destination.X <= Room.Width & destination.Y > Room.Length)
                {
                    Area availableArea = new Area(Tile.Width, Room.Length - origin.Y);

                    // look for an offcut
                    var foundTile = result.FindMatchingOffcut(availableArea);
                    if (foundTile == null)
                    {
                        foundTile = Tile;
                        result.WholeTilesUsed++;
                    }

                    foundTile.CutPartialTile(availableArea).ForEach(o => result.Offcuts.Add(o));

                    origin.X += Tile.Width + GroutThickness;
                }

                // there is not enough room in length or width, a tile has to be cut twice
                else if (destination.X > Room.Width & destination.Y > Room.Length)
                {
                    Area availableArea = new Area(Room.Width - origin.X, Room.Length - origin.Y);

                    // look for an offcut
                    var foundTile = result.FindMatchingOffcut(availableArea);
                    if (foundTile == null)
                    {
                        foundTile = Tile;
                        result.WholeTilesUsed++;
                    }

                    foundTile.CutPartialTile(availableArea).ForEach(o => result.Offcuts.Add(o));

                    origin.X += Tile.Width + GroutThickness;
                    origin.Y += Tile.Length + GroutThickness;
                }

                if (destination.X >= Room.Width & destination.Y >= Room.Length)
                {
                    roomComplete = true;
                }
            }

            return result;
        }