コード例 #1
0
        public Graph ExecuteStep(Graph graph)
        {
            var points       = _pointSupplier.Invoke();
            var fortuneSites = points.Select(point => new FortuneSite(point.X, point.Y)).ToList();

            FortunesAlgorithm.Run(fortuneSites, _generationMin.X, _generationMin.Y, _generationMax.X, _generationMax.Y);

            // add entities to graph
            Dictionary <FortuneSite, Entity> siteToEntityMapping = new ();

            foreach (var cell in fortuneSites)
            {
                var             areaEntity    = new Entity(_cellNameSupplier.Invoke(cell.X, cell.Y), graph);
                EntityComponent areaComponent = new ("AreaComponent");
                areaComponent.SetProperty("cell", cell);
                areaEntity.Components.Add(areaComponent);

                ComponentUtility.AddPosition2D(areaEntity, (float)cell.X, (float)cell.Y);

                if (_parent == null)
                {
                    graph.Entities.Add(areaEntity);
                }
                else
                {
                    _parent.AddChild(areaEntity);
                }

                siteToEntityMapping.Add(cell, areaEntity);
            }

            // add relations to graph
            Layer layer = graph.GetOrAddLayer(_layerName);

            foreach (var cell in fortuneSites)
            {
                foreach (var cellNeighbor in cell.Neighbors)
                {
                    layer.AddRelation(siteToEntityMapping[cell], siteToEntityMapping[cellNeighbor]);
                }
            }

            return(graph);
        }
        public Graph ExecuteStep(Graph graph)
        {
            List <Vector2> points = PoissonDiscSampler.GeneratePoints(_radius, _sampleRegionSize, _offset, _rejectionThreshold);

            foreach (var point in points)
            {
                Entity entity = new(_cellNameSupplier.Invoke(point.X, point.Y), graph);
                ComponentUtility.AddPosition2D(entity, point.X, point.Y);

                if (_parent != null)
                {
                    _parent.AddChild(entity);
                }
                else
                {
                    graph.Entities.Add(entity);
                }
            }

            return(graph);
        }