示例#1
0
        private static ComponentInstance InstantiateLayout(SpaceConfiguration configs, double width, double length, Polygon rectangle, Transform xform)
        {
            ContentConfiguration selectedConfig = null;
            var orderedKeys = configs.OrderByDescending(kvp => kvp.Value.CellBoundary.Depth * kvp.Value.CellBoundary.Width).Select(kvp => kvp.Key);

            foreach (var key in orderedKeys)
            {
                var config = configs[key];
                if (config.CellBoundary.Width < width && config.CellBoundary.Depth < length)
                {
                    selectedConfig = config;
                    break;
                }
            }
            if (selectedConfig == null)
            {
                return(null);
            }
            var baseRectangle = Polygon.Rectangle(selectedConfig.CellBoundary.Min, selectedConfig.CellBoundary.Max);
            var rules         = selectedConfig.Rules();

            var componentDefinition = new ComponentDefinition(rules, selectedConfig.Anchors());
            var instance            = componentDefinition.Instantiate(ContentConfiguration.AnchorsFromRect(rectangle.TransformedPolygon(xform)));
            var allPlacedInstances  = instance.Instances;

            foreach (var item in allPlacedInstances)
            {
                if (item is ElementInstance ei && !rectangle.Contains(ei.Transform.Origin))
                {
                }
            }
            return(instance);
        }
示例#2
0
        private static ComponentInstance InstantiateLayout(SpaceConfiguration configs, double width, double length, Polygon rectangle, Transform xform)
        {
            ContentConfiguration selectedConfig = null;
            var orderedKeys = configs.OrderBy(k => rand.NextDouble()).Select(k => k.Key);

            foreach (var key in orderedKeys)
            {
                var config = configs[key];
                if (config.CellBoundary.Width < width && config.CellBoundary.Depth < length)
                {
                    selectedConfig = config;
                    break;
                }
            }
            if (selectedConfig == null)
            {
                return(null);
            }
            var baseRectangle = Polygon.Rectangle(selectedConfig.CellBoundary.Min, selectedConfig.CellBoundary.Max);
            var rules         = selectedConfig.Rules();

            var componentDefinition = new ComponentDefinition(rules, selectedConfig.Anchors());
            var instance            = componentDefinition.Instantiate(ContentConfiguration.AnchorsFromRect(rectangle.TransformedPolygon(xform)));

            return(instance);
        }
示例#3
0
        public void ArrayResults(ComponentDefinition def, List <List <Vector3> > targetAnchors)
        {
            var currentX = 0.0;

            foreach (var anchorSet in targetAnchors)
            {
                var bbox           = new BBox3(anchorSet);
                var xForm          = new Transform(currentX - bbox.Min.X, 0, 0);
                var transformedSet = anchorSet.Select(v => xForm.OfPoint(v)).ToList();
                foreach (var anchor in transformedSet)
                {
                    Model.AddElement(new ModelCurve(Polygon.Ngon(10, 0.1), transform: new Transform(anchor)));
                }
                Model.AddElement(def.Instantiate(transformedSet));
                currentX += (bbox.Max.X - bbox.Min.X + 1);
            }
        }
示例#4
0
        private static ComponentInstance InstantiateLayout(SpaceConfiguration configs, double width, double length, Polygon rectangle, Transform xform)
        {
            var orderedKeys        = configs.OrderByDescending(kvp => kvp.Value.CellBoundary.Depth * kvp.Value.CellBoundary.Width).Select(kvp => kvp.Key);
            var configsThatFitWell = new List <ContentConfiguration>();

            foreach (var key in orderedKeys)
            {
                var config = configs[key];
                // if it fits
                if (config.CellBoundary.Width < width && config.CellBoundary.Depth < length)
                {
                    if (configsThatFitWell.Count == 0)
                    {
                        configsThatFitWell.Add(config);
                    }
                    else
                    {
                        var firstFittingConfig = configsThatFitWell.First();
                        // check if there's another config that's roughly the same size
                        if (config.CellBoundary.Width.ApproximatelyEquals(firstFittingConfig.CellBoundary.Width, 1.0) && config.CellBoundary.Depth.ApproximatelyEquals(firstFittingConfig.CellBoundary.Depth, 1.0))
                        {
                            configsThatFitWell.Add(config);
                        }
                    }
                }
            }
            if (configsThatFitWell.Count == 0)
            {
                return(null);
            }
            var selectedConfig = configsThatFitWell[varietyCounter % configsThatFitWell.Count];
            var baseRectangle  = Polygon.Rectangle(selectedConfig.CellBoundary.Min, selectedConfig.CellBoundary.Max);

            var rules = selectedConfig.Rules();

            varietyCounter++;
            var componentDefinition = new ComponentDefinition(rules, selectedConfig.Anchors());
            var instance            = componentDefinition.Instantiate(ContentConfiguration.AnchorsFromRect(rectangle.TransformedPolygon(xform)));
            var allPlacedInstances  = instance.Instances;

            return(instance);
        }