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

namespace PCUT.Extensions.Transforms
{
    public class RotateTransform : SvgTransform
    {
        private readonly double _sin;
        private readonly double _cos;

        public double Degree { get; private set; }
        public double OriginX { get; private set; }
        public double OriginY { get; private set; }

        public RotateTransform(double degree, double originX, double originY)
        {
            Degree = degree;
            OriginX = originX;
            OriginY = originY;

            var angle = degree * DToRFactor;
            _sin = Math.Sin(angle);
            _cos = Math.Cos(angle);
        }

        public RotateTransform(double degree) : this(degree, 0, 0)
        {
        }

        protected override (double X, double Y) InternalTransform(double x, double y)
        {
            var x1 = (x - OriginX) * _cos - (y - OriginY) * _sin + OriginX;
            var y1 = (x - OriginX) * _sin + (y - OriginY) * _cos + OriginY;
            return (x1, y1);
        }
    }
}
