// Methods

        public void AbsorbPlacementUnit(PlacementUnit unitToMerge)
        {
            foreach (Fitting newMember in unitToMerge.Members)
            {
                AddMember(newMember);
            }
        }
Exemple #2
0
        bool placecenter(List <PlacementUnit> placementUnits, int index, Room room)
        {
            for (int i = 0; i < placementUnits.Count; i++)
            {
                PlacementUnit placementUnit = placementUnits[i];
                foreach (Tuple <Vector2D, int> positionAndRotation in placementUnit.positionsAndRotationsDomain)
                {
                    // Place placement unit only if possible and then move on to test next unit
                    if (placementUnit.TryFitAt(positionAndRotation, ref room))
                    {
                        // Move on to the subsequent placement unit, and test if any placements in its domain fit
                        bool couldNextUnitBePlaced =
                            placecenter(placementUnits, i + 1, room);

                        if (couldNextUnitBePlaced)
                        {
                            return(true);
                        }
                        else
                        {
                            // Move back placementUnit to default placement and unregister placement
                            placementUnit.Unplace(positionAndRotation, ref room);
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>Tries to fit placement units in list -- from indexToTest to the end of the list -- in the room</summary>
        /// <param name="placementUnits">List of placement unit to place in room</param>
        /// <param name="indexToTest">List index of placement unit to try to fit in room</param>
        /// <param name="room">Room to place placement units in</param>
        /// <returns>
        /// Whether there were any possible arrangement of the placement units
        /// at indexToTest in list and subsequent placement units in list
        /// </returns>
        private bool TestPlacementRecursive(ref List <PlacementUnit> placementUnits, int indexToTest, ref Room room)
        {
            if (indexToTest >= placementUnits.Count)
            {
                // Print the room grid of obstruction values
                //Console.WriteLine(room);
                // All placement units in placementUnits have been tested
                return(true);
            }
            else
            {
                PlacementUnit placementUnit = placementUnits[indexToTest];

                // Test if placements in domains are possible
                foreach (Tuple <Vector2D, int> positionAndRotation in placementUnit.positionsAndRotationsDomain)
                {
                    // Place placement unit only if possible and then move on to test next unit
                    if (placementUnit.TryFitAt(positionAndRotation, ref room))
                    {
                        // Move on to the subsequent placement unit, and test if any placements in its domain fit
                        bool couldNextUnitBePlaced = TestPlacementRecursive(ref placementUnits, indexToTest + 1, ref room);

                        if (couldNextUnitBePlaced)
                        {
                            return(true);
                        }
                        else
                        {
                            // Move back placementUnit to default placement and unregister placement
                            placementUnit.Unplace(positionAndRotation, ref room);
                        }
                    }
                }

                // No placements fit for this and all subsequent placement units
                return(false);
            }
        }
        // Constructor

        public Fitting(FittingModel fittingModel)
        {
            Position     = Vector2D.Zero;
            Orientation  = 0;
            FittingModel = fittingModel;

            Faces = new List <ParticularFace>();
            foreach (Face fittingFace in fittingModel.FittingType.Faces)
            {
                float length;
                if (fittingFace.Facing == Facing.Left || fittingFace.Facing == Facing.Right)
                {
                    length = FittingModel.BoundingBox.Depth;
                }
                else
                {
                    length = FittingModel.BoundingBox.Width;
                }

                Faces.Add(new ParticularFace(this, fittingFace, length));
            }

            PlacementUnit = new PlacementUnit(this);
        }
 /// <summary>Rotates fitting's placement unit in plane around fitting</summary>
 /// <param name="rotationDelta">Number of 90 degree counterclockwise turns</param>
 public void RotatePlacementUnit(int rotationDelta)
 {
     PlacementUnit.RotateAround(Position, rotationDelta);
 }
 public void ChangePlacementUnit(PlacementUnit newPlacementUnit)
 {
     PlacementUnit = newPlacementUnit;
 }