I have this simple wxSpinCtrlDouble:
Code: Select all
wxSpinCtrlDouble* rotSpin = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(80, -1), wxSP_WRAP, 0.0, 359.9, 0, 0.1);
rotSpin->SetDigits(1);
Can I get rid of it?
Code: Select all
wxSpinCtrlDouble* rotSpin = new wxSpinCtrlDouble(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(80, -1), wxSP_WRAP, 0.0, 359.9, 0, 0.1);
rotSpin->SetDigits(1);
Code: Select all
// This function tries to work around issues caused by floating point numbers
// representations when comparing them.
// Returns -1 when d1 < d2, 1 when d1 > 2, and 0 when d1 == d2.
int wxCompareDoublesForUI(const double d1, const double d2, wxUint8 decimalPlaces)
{
wxCHECK_MSG(decimalPlaces <= 9, 0, "decimalPlaces must be between 0 and 9");
// First compare only the integer parts of the values
const wxInt64 d1IntPart = trunc(d1);
const wxInt64 d2IntPart = trunc(d2);
if ( d1IntPart < d2IntPart )
return -1;
if ( d1IntPart > d2IntPart )
return 1;
if ( decimalPlaces == 0 )
return 0;
// If the integer parts were the same, compare only the fractional parts
// as if they were integers * 10^decimalPlaces
const double factor = pow(10, decimalPlaces);
const int d1FractPartAsInt = round((d1 - d1IntPart) * factor);
const int d2FractPartAsInt = round((d2 - d2IntPart) * factor);
return d1FractPartAsInt - d2FractPartAsInt;
}