using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace OcadMapLibrary {

	/*public class OcadPathHelper {

		public OcadPathHelper(List<MapDrawingPoint> mapPoints) {
			this.mapPoints = mapPoints;
		}

		List<MapDrawingPoint> mapPoints;

		public bool HasLength {
			get {
				if (mapPoints.Count == 0) {
					return false;
				}
				Point currentPoint = mapPoints[0].Point;
				double distance = 0;
				for (int i = 1; i < mapPoints.Count; i++) {
					if (mapPoints[i].IsFirstCurvePoint) {
						if (i >= mapPoints.Count - 2) {
							return false;
						}
						distance = Point.Subtract(mapPoints[i + 2].Point, currentPoint).Length;
						if (distance > 0) {
							return true;
						}
						currentPoint = mapPoints[i + 2].Point;
						i += 2;
					} else {
						distance = Point.Subtract(mapPoints[i].Point, currentPoint).Length;
						if (distance > 0) {
							return true;
						}
						currentPoint = mapPoints[i].Point;
					}
				}
				return false;
			}
		}

		public PathFigure GetPathFigure() {
			if (mapPoints.Count == 0) {
				return null;
			}
			PathFigure pathFigure = new PathFigure();
			PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
			pathFigure.Segments = pathSegmentCollection;
			pathFigure.StartPoint = mapPoints[0].Point;
			for (int i = 1; i < mapPoints.Count; i++) {
				if (mapPoints[i].IsFirstCurvePoint) {
					if (i >= mapPoints.Count - 2) {
						break;
					}
					BezierSegment bezierSegment = new BezierSegment(mapPoints[i].Point, mapPoints[i + 1].Point, mapPoints[i + 2].Point, true);
					pathSegmentCollection.Add(bezierSegment);
					i += 2;
				} else {
					LineSegment lineSegment = new LineSegment();
					lineSegment.Point = mapPoints[i].Point;
					pathSegmentCollection.Add(lineSegment);
				}
			}
			return pathFigure;
		}

		public Geometry GetAreaGeometry() {
			if (mapPoints.Count == 0) {
				return null;
			}
			PathGeometry geometry = null;
			PathFigure pathFigure;
			PathGeometry pathGeometry;
			PathSegmentCollection pathSegmentCollection;
			Point firstPoint;
			pathFigure = new PathFigure();
			pathGeometry = new PathGeometry(new PathFigure[] { pathFigure });
			pathSegmentCollection = new PathSegmentCollection();
			pathFigure.Segments = pathSegmentCollection;
			firstPoint = mapPoints[0].Point;
			pathFigure.StartPoint = firstPoint;
			bool inHole = false;
			int i;
			for (i = 1; i < mapPoints.Count; i++) {
				if (mapPoints[i].IsFirstHolePoint) {
					if (inHole) {
						geometry = Geometry.Combine(geometry, pathGeometry, GeometryCombineMode.Xor, null);
					} else {
						geometry = pathGeometry;
					}
					pathFigure = new PathFigure();
					pathGeometry = new PathGeometry(new PathFigure[] { pathFigure });
					pathSegmentCollection = new PathSegmentCollection();
					pathFigure.Segments = pathSegmentCollection;
					pathFigure.StartPoint = mapPoints[i].Point;
					inHole = true;
				} else {
					if (mapPoints[i].IsFirstCurvePoint) {
						if (i >= mapPoints.Count - 2) {
							break;
						}
						BezierSegment bezierSegment = new BezierSegment(mapPoints[i].Point, mapPoints[i + 1].Point, mapPoints[i + 2].Point, false);
						pathSegmentCollection.Add(bezierSegment);
						i += 2;
					} else {
						LineSegment lineSegment = new LineSegment();
						lineSegment.Point = mapPoints[i].Point;
						pathSegmentCollection.Add(lineSegment);
					}
				}
			}
			if (inHole) {
				geometry = Geometry.Combine(geometry, pathGeometry, GeometryCombineMode.Xor, null);
			} else {
				geometry = pathGeometry;
			}
			return geometry;
		}

		public Rect Bounds {
			get {
				PathFigure pathFigure = GetPathFigure();
				PathGeometry geometry = new PathGeometry(new PathFigure[] { pathFigure });
				return geometry.Bounds;
			}
		}

		public static List<List<MapDrawingPoint>> SplitPointsByCorner(List<MapDrawingPoint> points) {
			List<List<MapDrawingPoint>> pointsList = new List<List<MapDrawingPoint>>();
			List<MapDrawingPoint> currentPoints = new List<MapDrawingPoint>();
			if (points.Count == 0) {
				return pointsList;
			}
			for (int i = 0; i < points.Count; i++) {
				currentPoints.Add(points[i]);
				if (points[i].IsCornerPoint && i > 0) {
					pointsList.Add(currentPoints);
					currentPoints = new List<MapDrawingPoint>();
					if (i < points.Count - 1) {
						currentPoints.Add(points[i]);
					}
				}
			}
			if (currentPoints.Count > 0) {
				pointsList.Add(currentPoints);
			}
			return pointsList;
		}

		public List<OcadPathHelper> SplitByCorner() {
			List<OcadPathHelper> paths = new List<OcadPathHelper>();
			List<List<MapDrawingPoint>> split = SplitPointsByCorner(mapPoints);
			for (int i = 0; i < split.Count; i++) {
				paths.Add(new OcadPathHelper(split[i]));
			}
			return paths;
		}

	}*/

}