Exemplo n.º 1
0
        private static bool AddNextPoint(VecteurV point)
        {
            var found = false;
            var q     = GenerateRandomAround(point);

            if (q.X > 0 && q.X < Settings.Dimensions.Width && q.Y > 0 && q.Y < Settings.Dimensions.Height)
            {
                var qIndex   = Denormalize(q);
                var tooClose = false;

                for (var i = (int)Math.Max(0, qIndex.X - 2); i < Math.Min(Settings.GridWidth, qIndex.X + 3) && !tooClose; i++)
                {
                    for (var j = (int)Math.Max(0, qIndex.Y - 2); j < Math.Min(Settings.GridHeight, qIndex.Y + 3) && !tooClose; j++)
                    {
                        if (State.Grid[i, j].HasValue && VecteurV.Distance(State.Grid[i, j].Value, q) < State.Grid[i, j].Value.MinimumDistance)
                        {
                            tooClose = true;
                        }
                    }
                }

                if (!tooClose)
                {
                    found = true;
                    q.InitFacteurGris();
                    State.ActivePoints.Add(q);
                    State.Points.Add(q);
                    State.Grid[(int)qIndex.X, (int)qIndex.Y] = q;
                }
            }
            return(found);
        }
Exemplo n.º 2
0
        private static VecteurV GenerateRandomAround(VecteurV center)
        {
            var d = RandomHelper.Random.NextDouble();

            var radius = center.MinimumDistance + (center.MinimumDistance * Settings.FactDistanceRejection * d);

            d = RandomHelper.Random.NextDouble();
            var angle = MathHelper.TwoPi * d;

            var newX = radius * Math.Sin(angle);
            var newY = radius * Math.Cos(angle);

            return(new VecteurV((float)(center.X + newX), (float)(center.Y + newY)));
        }
Exemplo n.º 3
0
        private static void AddFirstPoint()
        {
            var d  = RandomHelper.Random.NextDouble();
            var xr = Settings.Dimensions.Width * d;

            d = RandomHelper.Random.NextDouble();
            var yr = Settings.Dimensions.Height * d;

            var p = new VecteurV((float)xr, (float)yr);

            p.InitFacteurGris();

            var index = Denormalize(p);

            State.Grid[(int)index.X, (int)index.Y] = p;

            State.ActivePoints.Add(p);
            State.Points.Add(p);
        }
Exemplo n.º 4
0
 public static float DistanceSquared(VecteurV v1, VecteurV v2)
 {
     return(((v2.X - v1.X) * (v2.X - v1.X)) + ((v2.Y - v1.Y) * (v2.Y - v1.Y)));
 }
Exemplo n.º 5
0
 public static float Distance(VecteurV v1, VecteurV v2)
 {
     return((float)Math.Sqrt(DistanceSquared(v1, v2)));
 }
Exemplo n.º 6
0
 private static VecteurV Denormalize(VecteurV point)
 {
     return(new VecteurV((int)(point.X / Settings.CellSize), (int)(point.Y / Settings.CellSize)));
 }