Пример #1
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 virtual CalculatorResult Calculate(Room room, Tile tile, double groutThickness)
        {
            Room = room;
            Tile = tile;
            GroutThickness = groutThickness;

            CalculatorResult result = new CalculatorResult(Tile);

            // determine how many whole tiles will be used to tile the floor.
            int wholeTilesUsedAlongWidth = (int)Math.Floor(Room.Width / (Tile.Width + GroutThickness));
            int wholeTilesUsedAlongLength = (int)Math.Floor(Room.Length / (Tile.Length + GroutThickness));
            // add them to the sum of tiles
            result.WholeTilesUsed = wholeTilesUsedAlongWidth * wholeTilesUsedAlongLength;

            // determine if the 'width' require partial tiles
            // if yes, add as many partial tiles to the sum of tiles as there are whole tiles in the 'length'
            // add the offcuts to the collection for later use and waste calculation
            bool requiresIncompleteTileForWidth = false;
            double remainingWidth = Room.Width % (Tile.Width + GroutThickness);
            if (remainingWidth > 0)
            {
                requiresIncompleteTileForWidth = true;
                result.WholeTilesUsed += wholeTilesUsedAlongLength;

                for (int i = 1; i <= wholeTilesUsedAlongLength; i++)
                {
                    result.Offcuts.Add(new Tile(Tile.Width - remainingWidth, Tile.Length));
                }
            }

            // determine if the 'length' require partial tiles
            // if yes, add as many partial tiles to the sum of tiles as there are whole tiles in the 'width'
            // add the offcuts to the collection for later use and waste calculation
            bool requiresIncompleteTileForLength = false;
            double remainingLength = Room.Length % (Tile.Length + GroutThickness);
            if (remainingLength > 0)
            {
                requiresIncompleteTileForLength = true;
                result.WholeTilesUsed += wholeTilesUsedAlongWidth;

                for (int i = 1; i <= wholeTilesUsedAlongWidth; i++)
                {
                    result.Offcuts.Add(new Tile(Tile.Length - remainingLength, Tile.Width));
                }
            }

            // if partials were required for both width and length, then one tile must be cut twice to fill the last corner.
            // add the offcuts to the collection for later use and waste calculation
            if (requiresIncompleteTileForWidth && requiresIncompleteTileForLength)
            {
                result.WholeTilesUsed++;

                // TODO this is not ideal: it does not take into account that the second cut has a different length/width
                result.Offcuts.Add(new Tile(Tile.Length, Tile.Width - remainingWidth));
                result.Offcuts.Add(new Tile(Tile.Length - remainingLength, Tile.Width));
            }

            return result;
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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;
        }