Example #1
0
        // offset tree recursively
        public static void offsetTree(NFP t, double offset, NestingConfigurations config, bool?inside = null)
        {
            var simple = t;

            simple = simplifyFunction(t, (inside == null) ? false : inside.Value);

            var offsetpaths = new NFP[] { simple };

            if (offset > 0)
            {
                offsetpaths = polygonOffsetDeepNest(simple, offset);
            }

            if (offsetpaths.Count() > 0)
            {
                List <SvgPoint> rett = new List <SvgPoint>();
                rett.AddRange(offsetpaths[0].Points);
                rett.AddRange(t.Points.Skip(t.length));
                t.Points = rett.ToArray();

                // replace array items in place

                //Array.prototype.splice.apply(t, [0, t.length].concat(offsetpaths[0]));
            }

            if (simple.children != null && simple.children.Count > 0)
            {
                if (t.children == null)
                {
                    t.children = new List <NFP>();
                }

                for (var i = 0; i < simple.children.Count; i++)
                {
                    t.children.Add(simple.children[i]);
                }
            }

            if (t.children != null && t.children.Count > 0)
            {
                for (var i = 0; i < t.children.Count; i++)
                {
                    offsetTree(t.children[i], -offset, config, (inside == null) ? true : (!inside));
                }
            }
        }
Example #2
0
        public GeneticAlgorithm(NFP[] adam, NestingConfigurations config)
        {
            List <float> ang2 = new List <float>();

            for (int i = 0; i < adam.Length; i++)
            {
                ang2.Add((i * 90) % 360);
            }
            defaultAngles = ang2.ToArray();
            Config        = config;


            List <float> angles = new List <float>();

            for (int i = 0; i < adam.Length; i++)
            {
                if (StrictAngles)
                {
                    angles.Add(defaultAngles[i]);
                }
                else
                {
                    var angle = (float)Math.Floor(r.NextDouble() * Config.Rotations) * (360f / Config.Rotations);
                    angles.Add(angle);
                }

                //angles.Add(randomAngle(adam[i]));
            }
            population = new List <PopulationItem>();
            population.Add(new PopulationItem()
            {
                placements = adam.ToList(), Rotation = angles.ToArray()
            });
            while (population.Count() < config.PopulationSize)
            {
                var mutant = this.mutate(population[0]);
                population.Add(mutant);
            }
        }