using SemiconductorVisionAlgorithm.SemiParams;
using System;
using System.Collections.Generic;
using System.IO;

namespace MainShell.AlgorithmCalib.Service
{
    /// <summary>
    /// 旋转表标定文件服务
    /// </summary>
    public static class RotateMatixFormCalibFileService
    {
        /// <summary>
        /// 保存验证点数据
        /// </summary>
        public static void SaveVerifyPointsFile(string path, List<Point> cal, List<Point> real)
        {
            using (var sw = new StreamWriter(path))
            {
                int count = cal.Count;
                sw.WriteLine("Cal_X,Cal_Y,Real_X,Real_Y");
                for (int i = 0; i < count; i++)
                {
                    sw.WriteLine($"{cal[i].X},{cal[i].Y},{real[i].X},{real[i].Y}");
                }
            }
        }

        /// <summary>
        /// 保存标定网格数据（用于调试）
        /// </summary>
        public static void SaveCalibrationGridData(string path, List<Point[,]> calibData,List<double> rotatePosList)
        {
            using (var sw = new StreamWriter(path))
            {
                sw.WriteLine("RotatePos,GridY,GridX,PointX,PointY");
                for (int step = 0; step < calibData.Count; step++)
                {
                    var grid = calibData[step];
                    int n = grid.GetLength(0);
                    for (int y = 0; y < n; y++)
                    {
                        for (int x = 0; x < n; x++)
                        {
                            sw.WriteLine($"{rotatePosList[step]:F4},{y},{x},{grid[y,x].X:F6},{grid[y, x].Y:F6}");
                        }
                    }
                }
            }
        }
    }
}