using AstroFrame.Engine; using System.Security.Cryptography; static class StellarDetailRegression { public static void Run(Action check) { double[] Gaussian(double major,double minor,double angle)=>Enumerable.Range(0,169).Select(i=> { double x=i%13-6,y=i/13-6,u=x*Math.Cos(angle)+y*Math.Sin(angle),v=-x*Math.Sin(angle)+y*Math.Cos(angle); return 1000+3000*Math.Exp(-.5*(u*u/(major*major)+v*v/(minor*minor))); }).ToArray(); var round=StellarDetail.Describe(Gaussian(1,1,0))!; var stretched=StellarDetail.Describe(Gaussian(1.4,.7,.6))!; check(round.Ellipticity<.001&&stretched.Ellipticity>.45&&Math.Abs(stretched.Angle-.6)<.03,"source-moment guides distinguish round stars from rotated elongation"); check(Math.Abs(stretched.X-6.5)<.01&&Math.Abs(stretched.Y-6.5)<.01,"shape guides remain centered on source pixel centers"); check(StellarDetail.Describe(Enumerable.Repeat(1000.0,169).ToArray())==null&&StellarDetail.Describe([double.NaN])==null,"empty or invalid stellar profiles do not invent shape guides"); string directory=Path.Combine(Path.GetTempPath(),"AstroFrame-stars-"+Guid.NewGuid());Directory.CreateDirectory(directory); try { const int size=64;var positions=new[]{(X:14,Y:16),(X:40,Y:38),(X:18,Y:43)};List frames=[]; for(int n=0;n<2;n++) { float[] pixels=Enumerable.Repeat(1000f,size*size).ToArray(); foreach(var p in positions)for(int y=0;ynew Star((double)p.X/size,(double)p.Y/size,100,3,n==0?.5:0)).ToList();frames.Add(f); } var project=new Project{Frames=frames};ProjectStore.Save(project,directory); byte[] hash=SHA256.HashData(File.ReadAllBytes(frames[0].Path)); check(StellarDetail.Comparison(project,frames[0])==frames[1],"elongation inspector selects an aligned same-session KEEP comparison"); var detail=StellarDetail.Read(directory,frames[0],frames[1]); check(detail.Stars.Count==3&&detail.Stars.All(s=>s.Selected.Shape!.Ellipticity>.45&&s.Comparison!.Shape!.Ellipticity<.01),"aligned shifted source crops compare the same elongated and round stars"); check(hash.SequenceEqual(SHA256.HashData(File.ReadAllBytes(frames[0].Path)))&&frames[0].Automatic==Verdict.Keep,"source inspection preserves FITS bytes and frame decisions"); frames[1].Override=Verdict.Reject; check(StellarDetail.Comparison(project,frames[0])==null&&StellarDetail.Read(directory,frames[0],null).Stars.All(s=>s.Comparison==null),"source elongation remains inspectable without a suitable KEEP exposure"); frames[1].Override=null;frames[1].ReferenceId="different"; check(StellarDetail.Comparison(project,frames[0])==null,"unrelated reference alignments are excluded from star comparison"); using var cancel=new CancellationTokenSource();cancel.Cancel();bool cancelled=false;try{StellarDetail.Read(directory,frames[0],null,cancel.Token);}catch(OperationCanceledException){cancelled=true;} check(cancelled,"source star inspection cancels during read"); frames[0].Modified--;bool refused=false;try{StellarDetail.Read(directory,frames[0],null);}catch(IOException){refused=true;} check(refused,"changed sources are refused by the elongation inspector"); } finally{Directory.Delete(directory,true);} } }