using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WaferAdjust
{
    internal class TranslateCirclePoint
    {
        private double rotateX;
        private double rotateY;
        List<PointInfo> totalPoints;
        List<PointInfo> totalCenters;
        private int circleIndex;
        private double perAngle;
        PointInfo nashPoint;
        PointInfo firstPoint;
        public void SetRotateXY(double x, double y, double angle)
        {
            rotateX = x; rotateY = y;
            totalPoints = new List<PointInfo>();
            totalCenters = new List<PointInfo>();
            circleIndex = 0;
            perAngle = angle;
            nashPoint = null;
            firstPoint = null;
        }
        public double GetRotateX()
        {
            return rotateX;
        }
        public double GetRotateY()
        {
            return rotateY;
        }
        public void AddCirclePoint(List<PointInfo> pointInfos)
        {
            if (pointInfos == null || pointInfos.Count == 0) return;
            foreach (var item in pointInfos)
            {
                totalPoints.Add(new PointInfo(item.X, item.Y, circleIndex * perAngle));
            }
            firstPoint = pointInfos[0];
        }
        public PointInfo GetFirstPoint()
        {
            return firstPoint; 
        }
        public void AddCircleIndex()
        {
            circleIndex++;
        }
        public double GetCurrentDegree()
        {
            return circleIndex * perAngle;
        }
        public void AddNashPoint(double x, double y)
        {
            nashPoint = new PointInfo(x, y, circleIndex * perAngle);
        }
        public void AddCircleCenter(double x, double y, double r)
        {
            totalCenters.Add(new PointInfo(x, y, r));
        }        
        public List<PointInfo> DoTranslatePoint()
        {
            List<PointInfo> trans = new List<PointInfo>();
            foreach (var item in totalPoints)
            {
                var res = Rotation2D.GetOriginalPointDegrees(item.X, item.Y,
                    rotateX, rotateY, item.Radius, true, false);
                trans.Add(new PointInfo(res.x, res.y, item.Radius));
            }
            return trans;
        }
        public void DoTranslateNashPoint()
        {
            if (nashPoint == null)
                return;

            var res = Rotation2D.GetOriginalPointDegrees(nashPoint.X, nashPoint.Y,
                    rotateX, rotateY, nashPoint.Radius, true, false);

            nashPoint = new PointInfo(res.x, res.y, nashPoint.Radius);
        }
        public PointInfo GetNashPoint()
        {
            return nashPoint;
        }
    }
}
