using DeepNestLib;
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.Foundation;
using Windows.UI.Xaml.Media;

namespace PCUT.Extensions
{
    public static class PointExtensions
    {
        public static double DistTo(this SvgPoint p, SvgPoint p2)
        {
            return Math.Sqrt(Math.Pow(p.x - p2.x, 2) + Math.Pow(p.y - p2.y, 2));
        }

        public static double DistTo(this Point p, Point p2)
        {
            return Math.Sqrt(Math.Pow(p.X - p2.X, 2) + Math.Pow(p.Y - p2.Y, 2));
        }

        public static Point Mult(this Point p, double m)
        {
            return new Point((p.X * m), (p.Y * m));
        }

        public static PathGeometry BuildPath(this IEnumerable<Point> points)
        {
            if (points.Count() < 2)
                return null;

            var figure = new PathFigure { StartPoint = points.First() };
            foreach (var point in points)
                figure.Segments.Add(new LineSegment { Point = point });

            var path = new PathGeometry();
            path.Figures.Add(figure);
            return path;
        }

        public static IEnumerable<Point> PathPoints(this Rect rect)
        {
            yield return new Point(rect.Top, rect.Left);
            yield return new Point(rect.Top, rect.Right);
            yield return new Point(rect.Bottom, rect.Right);
            yield return new Point(rect.Bottom, rect.Left);
            yield break;
        }
    }
}
