Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image scale change improvements #1260

Merged
merged 9 commits into from
Dec 1, 2024
14 changes: 14 additions & 0 deletions src/advanced_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,20 @@ double AdvancedDialog::DetermineGuideSpeed()
}
return sidRate;
}

// Floating point equality comparisons can be a problem due to rounding and trivial inequalities.
// PercentChange can be used to see if a change is worth reacting to
double AdvancedDialog::PercentChange(double oldVal, double newVal)
{
double chg;
if (fabs(oldVal) < 0.0001)
{
return 100. * newVal; // not meaningful, but avoids divide by zero
}
else
return 100. * fabs(1. - newVal / oldVal);
}

// Reacts to param changes in the AD that change the image scale. Calibration step-size is recalculated, calibration is
// cleared, MinMoves are set to defaults based on new image scale
void AdvancedDialog::MakeImageScaleAdjustments()
Expand Down
1 change: 1 addition & 0 deletions src/advanced_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class AdvancedDialog : public wxDialog

bool Validate() override;
void ShowInvalid(wxWindow *ctrl, const wxString& message);
double PercentChange(double oldVal, double newVal);
void FlagImageScaleChange()
{
m_imageScaleChanged = true;
Expand Down
5 changes: 4 additions & 1 deletion src/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,10 @@ void CameraConfigDialogCtrlSet::UnloadValues()

double oldPxSz = m_pCamera->GetCameraPixelSize();
double newPxSz = m_pPixelSize->GetValue();
if (oldPxSz != newPxSz)
if (oldPxSz != newPxSz &&
pFrame->pAdvancedDialog->PercentChange(oldPxSz, newPxSz) >
5.0) // Avoid rounding problems with floating point equality test; don't clear
// calibration for inconsequential changes
pFrame->pAdvancedDialog->FlagImageScaleChange();
m_pCamera->SetCameraPixelSize(m_pPixelSize->GetValue());

Expand Down
5 changes: 3 additions & 2 deletions src/myframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3327,8 +3327,9 @@ void MyFrameConfigDialogCtrlSet::UnloadValues()
m_varExpDelayLong->GetValue() * 1000);
int oldFL = m_pFrame->GetFocalLength();
int newFL = GetFocalLength(); // From UI control
if (oldFL != newFL) // Validator insures fl is generally reasonable and non-zero
m_pFrame->pAdvancedDialog->FlagImageScaleChange();
if (oldFL != newFL) // Validator insures fl is generally reasonable and non-zero; don't react to trivial changes
if (m_pFrame->pAdvancedDialog->PercentChange(oldFL, newFL) > 5.0)
m_pFrame->pAdvancedDialog->FlagImageScaleChange();
m_pFrame->SetFocalLength(GetFocalLength());

int idx = m_pLanguage->GetSelection();
Expand Down