public static HorizontalLayout ConstructHorizontal(
            List <Func <IFacadePanel> > constructors,
            float height,
            Func <int, float> getPanelWidth,
            int count)
        {
            var horizontal = new HorizontalLayout {
                height = height
            };

            for (int i = 0; i < count; i++)
            {
                IFacadePanel panel = constructors.GetRandom()();
                panel.width = getPanelWidth(i);
                horizontal.Add(panel);
            }
            return(horizontal);
        }
        public static HorizontalLayout ConstructHorizontal(
            Func <IFacadePanel> constructor,
            float height,
            float panelWidth,
            int count)
        {
            var horizontal = new HorizontalLayout {
                height = height
            };

            for (int i = 0; i < count; i++)
            {
                IFacadePanel panel = constructor();
                panel.width = panelWidth;
                horizontal.Add(panel);
            }
            return(horizontal);
        }
Beispiel #3
0
        private FacadeLayout GenerateFacadeChunk(
            float facadeWidth,
            List <PanelSize> panelSizes,
            int floors,
            bool hasBalconies,
            bool hasAttic,
            float?entranceInterval)
        {
            var   facadeLayout = new VerticalLayout();
            float facadeHeight = 0;

            if (entranceInterval.HasValue)
            {
                int entranceCount         = Mathf.Max(Mathf.FloorToInt(facadeWidth / entranceInterval.Value) - 1, 1);
                int entranceIndexInterval = (panelSizes.Count - entranceCount) / (entranceCount + 1);

                var horizontal        = new HorizontalLayout();
                int lastEntranceIndex = -1;
                for (int i = 0; i < entranceCount; i++)
                {
                    int entranceIndex = (i + 1) * entranceIndexInterval + i;

                    horizontal.Add(ConstructFacadeChunk(panelSizes, lastEntranceIndex + 1, entranceIndex, floors,
                                                        hasBalconies));

                    horizontal.Add(ConstructEntranceVertical(sizeValues[panelSizes[entranceIndex]], floors));

                    if (i == entranceCount - 1)
                    {
                        horizontal.Add(ConstructFacadeChunk(panelSizes, entranceIndex + 1, panelSizes.Count, floors,
                                                            hasBalconies));
                    }

                    lastEntranceIndex = entranceIndex;
                }

                facadeLayout.Add(horizontal);
                facadeHeight += socleHeight + floors * floorHeight;
            }
            else
            {
                var socle = ConstructHorizontal(
                    constructors: constructors[PanelType.Socle],
                    height: socleHeight,
                    getPanelWidth: index => sizeValues[panelSizes[index]],
                    count: panelSizes.Count);

                facadeLayout.Add(socle);
                facadeHeight += socleHeight;

                for (int floorIndex = 0; floorIndex < floors; floorIndex++)
                {
                    HorizontalLayout floor;
                    if (floorIndex == 0)
                    {
                        floor = ConstructHorizontal(
                            constructors: constructors[PanelType.Window],
                            height: floorHeight,
                            getPanelWidth: index => sizeValues[panelSizes[index]],
                            count: panelSizes.Count);
                    }
                    else
                    {
                        floor = ConstructHorizontal(
                            constructors: hasBalconies
                                ? constructors[PanelType.Balcony]
                                : constructors[PanelType.Window],
                            height: floorHeight,
                            getPanelWidth: index => sizeValues[panelSizes[index]],
                            count: panelSizes.Count);
                    }

                    facadeLayout.Add(floor);
                    facadeHeight += floorHeight;
                }
            }

            if (hasAttic)
            {
                var attic = ConstructHorizontal(
                    constructors: constructors[PanelType.Attic],
                    height: atticHeight,
                    getPanelWidth: index => sizeValues[panelSizes[index]],
                    count: panelSizes.Count);

                facadeLayout.Add(attic);
                facadeHeight += atticHeight;
            }

            facadeLayout.width  = facadeWidth;
            facadeLayout.height = facadeHeight;
            return(facadeLayout);
        }