using System;
using System.Collections.Generic;
using CrossCutting;

namespace InterpreterLibrary.Models.Transform
{
    public class PerspectiveTransformer : IPointTransformer
    {
        private readonly PerspectiveTransform _perspectiveTransform;

        public PerspectiveTransformer(IReadOnlyList<Tuple<PointF, PointF>> pointPairs)
        {
            _perspectiveTransform = PerspectiveTransform.GetQuadToQuad(
                pointPairs[0].Item1.X, pointPairs[0].Item1.Y,
                pointPairs[1].Item1.X, pointPairs[1].Item1.Y,
                pointPairs[2].Item1.X, pointPairs[2].Item1.Y,
                pointPairs[3].Item1.X, pointPairs[3].Item1.Y,
                pointPairs[0].Item2.X, pointPairs[0].Item2.Y,
                pointPairs[1].Item2.X, pointPairs[1].Item2.Y,
                pointPairs[2].Item2.X, pointPairs[2].Item2.Y,
                pointPairs[3].Item2.X, pointPairs[3].Item2.Y
                );
        }
        public PointF TransformPoint(PointF point)
        {
            var inPoints = new[] { point };
            PointF[] outPoints = new PointF[1];

            _perspectiveTransform.Transform(inPoints, 0, outPoints, 0, 1);
            return outPoints[0];
        }
    }
}

