#include "StraightEdge.h"#include <math.h>// ---------------------------------------------------------------------------------//		¥ CreateStraightEdgeFit [static]// ---------------------------------------------------------------------------------FitFunction *StraightEdgeFit::CreateStraightEdgeFit( ){	return NEW StraightEdgeFit();}FitFunction *StraightEdgeFit::CreateStraightEdgeMoveDetectorFit( ){	StraightEdgeFit *p = NEW StraightEdgeFit();	p->moveBlade = false;	return p;}StraightEdgeFit::StraightEdgeFit() : FitFunction(false, true), moveBlade( true ){	// Add the parameters		FitParameter *fp;		// The functional form is		AddParameter( NEW FitParameter("Baseline", 0.01) );						// Param(1)	AddParameter( NEW FitParameter("Intensity", 1) );						// Param(2)	AddParameter( NEW FitParameter("Edge Position (mm)", 10) );				// Param(3)	AddParameter( NEW FitParameter("Source Distance (mm)", 300) );			// Param(4)	AddParameter( fp = NEW FitParameter("Image Distance (mm)", 2000) );		// Param(5)	fp->Lock();		AddParameter( fp = NEW FitParameter("Wavelength", 0.0006328) );			// Param(6)	fp->Lock();}StraightEdgeFit::~StraightEdgeFit(){}// Remember that fit parameters are 1-basedREAL StraightEdgeFit::CalcFitFunction(REAL x){	REAL result = 0;	// arg = (x - x0) sqrt(2/image * (1/source + 1/lambda))	x -= Param(3)();							// the edge position parameter	REAL argument = x * sqrt(2 / Param(6)() 			* (1.0 / Param(4)() + 1.0 / Param(5)()));		if ( !moveBlade )		argument *= Param(4)() / ( Param(4)() + Param(5)() );		FLOAT C, S;	fresnelIntegral.Evaluate(argument, C, S);	C += 0.5;	S += 0.5;		result = Param(1)() 						// baseline		+ 0.5 * Param(2)()						// amplitude		* (C*C + S*S);							// squared amplitude of the Fresnel integral		return result;}