Beispiel #1
0
        private void DrawPoint(SpriteBatch batch, VPoint point, Color color, int size = 1)
        {
            var rect = new Rectangle(
                Convert.ToInt32(point.X - (size / 2)),
                Convert.ToInt32(point.Y - (size / 2)),
                size,
                size);

            batch.Draw(GameEngine.DummyTexture,
                       destinationRectangle: rect,
                       color: color);
        }
Beispiel #2
0
        private List <VPoint> GetPoints(IEnumerable <VPoint> sites, int width, int height)
        {
            var list = new List <VPoint> ();

            for (var x = 0; x < width; x++)
            {
                for (var y = 0; y < height; y++)
                {
                    // max distance
                    float  closest_distance = width * height;
                    var    given_point      = new Vector2(x, y);
                    VPoint closest_point    = null;

                    foreach (var point in sites)
                    {
                        var distance = Vector2.Distance(point.ToVector2(), given_point);

                        if (distance < closest_distance)
                        {
                            closest_distance = distance;
                            closest_point    = point;
                        }
                    }

                    var original = false;

                    if (closest_point.X == x && closest_point.Y == y && closest_point.OriginalPoint)
                    {
                        original = true;
                    }

                    list.Add(new VPoint(x, y)
                    {
                        Type          = closest_point.Type,
                        ClosestPoint  = closest_point,
                        OriginalPoint = original
                    });
                }
            }

            return(list);
        }
Beispiel #3
0
        private VPoint GetClosestPoint(IEnumerable <VPoint> points, VPoint givenPoint)
        {
            float  closest_distance = float.MaxValue;
            var    given_point      = new Vector2(givenPoint.X, givenPoint.Y);
            VPoint closest_point    = null;

            points = points.Where(x => x != givenPoint);

            foreach (var point in points)
            {
                var distance = Vector2.Distance(point.ToVector2(), given_point);

                if (distance < closest_distance)
                {
                    closest_distance = distance;
                    closest_point    = point;
                }
            }

            return(closest_point);
        }