using System;
using SphericalLib;

namespace SphericalVisualizer
{
    class Program
    {
        public static void Main(string[] args)
        {
            System.Drawing.Image img;
            double ra, dec, scale;
            Region r;

            //Arc a = new Arc(new Cartesian(180, 0), new Cartesian(181, 0), false);
            //r = new Region(a.WideConvex(20), false);

            ra = 13.72296;
            dec = -9.33997;
            scale = 15;
            
            SqlIO sql = new SqlIO ("Data Source=sdssdb001; Initial Catalog=bestdr4; User=test; Password=riuzg54; Timeout=60;");

            r = Region.Parse(@"REGION CONVEX
  -0.015226083812399 -0.499242363238016 -0.866328591886623 0
  -0.25095588837225 0.481277279574818 -0.839876968523579 0
  0.225986347339153 -0.967416067344797 -0.11417672030425 0
  -0.21089175599291 0.972191762035346 0.101822615782723 0
  0.266875950836591 -0.47723625030909 0.837271036317384 0
  0.0352044596935142 0.496266416917093 0.867456217602916 0
  0.95857531452087 0.234082467587171 -0.162292220267996 0.999953926969049", true);
            img = RegionDraw.Image(r, ra, dec, scale, 1024, 1024, false);
            img.Save(@"\temp\rMIS.png", System.Drawing.Imaging.ImageFormat.Png);

            r = sql.ReadRegion(44675);
            Console.Out.WriteLine(r);
            Console.Out.WriteLine(r.convexList[0].halfspaceList[0].RA);
            Console.Out.WriteLine(r.convexList[0].halfspaceList[0].Dec);
            SuperRegion s = new SuperRegion(r, false, false);
            Console.Out.WriteLine(s);
            Console.Out.WriteLine(s.convexList[0].patchList[0].mec.RA);
            Console.Out.WriteLine(s.convexList[0].patchList[0].mec.Dec);

            r.Intersect(new Convex(new Halfspace(new Cartesian(ra, dec), 1e-2), false));
            img = RegionDraw.Image(r, ra, dec, scale, 1024, 1024, false);
            img.Save(@"\temp\r44675.png", System.Drawing.Imaging.ImageFormat.Png);

            r = sql.ReadRegion(45672);
            img = RegionDraw.Image(r, ra, dec, scale, 1024, 1024, false);
            img.Save(@"\temp\r45672.png", System.Drawing.Imaging.ImageFormat.Png);

            r = sql.ReadRegion(45675);
            img = RegionDraw.Image(r, ra, dec, scale, 1024, 1024, false);
            img.Save(@"\temp\r45675.png", System.Drawing.Imaging.ImageFormat.Png);

            sql.Dispose();

            //System.Drawing.Image img = RegionDraw.Image(r, ra,dec, 10f, 1024,1024,false);
            //img.Save(@"\temp\spherical.png", System.Drawing.Imaging.ImageFormat.Png);
        }
    }
}
