mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-19 11:23:42 +00:00
Fix: Fixed the values comparison for Float-based config options (#12478)
This commit is contained in:
@@ -37,9 +37,9 @@ namespace Slic3r {
|
|||||||
template<class Archive> void serialize(Archive& ar) { ar(this->value); ar(this->percent); }
|
template<class Archive> void serialize(Archive& ar) { ar(this->value); ar(this->percent); }
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return l.value == r.value && l.percent == r.percent; }
|
inline bool operator==(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return is_approx(l.value, r.value) && l.percent == r.percent; }
|
||||||
inline bool operator!=(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return !(l == r); }
|
inline bool operator!=(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return !(l == r); }
|
||||||
inline bool operator< (const FloatOrPercent& l, const FloatOrPercent& r) throw() { return l.value < r.value || (l.value == r.value && int(l.percent) < int(r.percent)); }
|
inline bool operator< (const FloatOrPercent& l, const FloatOrPercent& r) throw() { return l.value < r.value || (is_approx(l.value, r.value) && int(l.percent) < int(r.percent)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
@@ -762,8 +762,8 @@ public:
|
|||||||
ConfigOptionType type() const override { return static_type(); }
|
ConfigOptionType type() const override { return static_type(); }
|
||||||
double getFloat() const override { return this->value; }
|
double getFloat() const override { return this->value; }
|
||||||
ConfigOption* clone() const override { return new ConfigOptionFloat(*this); }
|
ConfigOption* clone() const override { return new ConfigOptionFloat(*this); }
|
||||||
bool operator==(const ConfigOptionFloat &rhs) const throw() { return this->value == rhs.value; }
|
bool operator==(const ConfigOptionFloat &rhs) const throw() { return is_approx(this->value, rhs.value); }
|
||||||
bool operator< (const ConfigOptionFloat &rhs) const throw() { return this->value < rhs.value; }
|
bool operator< (const ConfigOptionFloat &rhs) const throw() { return this->value < rhs.value; }
|
||||||
|
|
||||||
std::string serialize() const override
|
std::string serialize() const override
|
||||||
{
|
{
|
||||||
@@ -780,6 +780,14 @@ public:
|
|||||||
return !iss.fail();
|
return !iss.fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const ConfigOption &rhs) const override
|
||||||
|
{
|
||||||
|
if (rhs.type() != this->type())
|
||||||
|
throw ConfigurationError("ConfigOptionFloat: Comparing incompatible types");
|
||||||
|
assert(dynamic_cast<const ConfigOptionFloat*>(&rhs));
|
||||||
|
return *this == *static_cast<const ConfigOptionFloat*>(&rhs);
|
||||||
|
}
|
||||||
|
|
||||||
ConfigOptionFloat& operator=(const ConfigOption *opt)
|
ConfigOptionFloat& operator=(const ConfigOption *opt)
|
||||||
{
|
{
|
||||||
this->set(opt);
|
this->set(opt);
|
||||||
@@ -906,7 +914,7 @@ protected:
|
|||||||
if (v1.size() != v2.size())
|
if (v1.size() != v2.size())
|
||||||
return false;
|
return false;
|
||||||
for (auto it1 = v1.begin(), it2 = v2.begin(); it1 != v1.end(); ++ it1, ++ it2)
|
for (auto it1 = v1.begin(), it2 = v2.begin(); it1 != v1.end(); ++ it1, ++ it2)
|
||||||
if (! ((std::isnan(*it1) && std::isnan(*it2)) || *it1 == *it2))
|
if (! ((std::isnan(*it1) && std::isnan(*it2)) || is_approx(*it1, *it2)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
@@ -1258,11 +1266,11 @@ public:
|
|||||||
return *this == *static_cast<const ConfigOptionFloatOrPercent*>(&rhs);
|
return *this == *static_cast<const ConfigOptionFloatOrPercent*>(&rhs);
|
||||||
}
|
}
|
||||||
bool operator==(const ConfigOptionFloatOrPercent &rhs) const throw()
|
bool operator==(const ConfigOptionFloatOrPercent &rhs) const throw()
|
||||||
{ return this->value == rhs.value && this->percent == rhs.percent; }
|
{ return is_approx(this->value, rhs.value) && this->percent == rhs.percent; }
|
||||||
size_t hash() const throw() override
|
size_t hash() const throw() override
|
||||||
{ size_t seed = std::hash<double>{}(this->value); return this->percent ? seed ^ 0x9e3779b9 : seed; }
|
{ size_t seed = std::hash<double>{}(this->value); return this->percent ? seed ^ 0x9e3779b9 : seed; }
|
||||||
bool operator< (const ConfigOptionFloatOrPercent &rhs) const throw()
|
bool operator< (const ConfigOptionFloatOrPercent &rhs) const throw()
|
||||||
{ return this->value < rhs.value || (this->value == rhs.value && int(this->percent) < int(rhs.percent)); }
|
{ return this->value < rhs.value || (is_approx(this->value, rhs.value) && int(this->percent) < int(rhs.percent)); }
|
||||||
|
|
||||||
double get_abs_value(double ratio_over) const
|
double get_abs_value(double ratio_over) const
|
||||||
{ return this->percent ? (ratio_over * this->value / 100) : this->value; }
|
{ return this->percent ? (ratio_over * this->value / 100) : this->value; }
|
||||||
|
|||||||
@@ -883,13 +883,18 @@ bool TextCtrl::value_was_changed()
|
|||||||
case coInt:
|
case coInt:
|
||||||
return boost::any_cast<int>(m_value) != boost::any_cast<int>(val);
|
return boost::any_cast<int>(m_value) != boost::any_cast<int>(val);
|
||||||
case coPercent:
|
case coPercent:
|
||||||
case coPercents:
|
case coPercents: {
|
||||||
|
if (m_opt.nullable && std::isnan(boost::any_cast<double>(m_value)) &&
|
||||||
|
std::isnan(boost::any_cast<double>(val)))
|
||||||
|
return false;
|
||||||
|
return boost::any_cast<double>(m_value) != boost::any_cast<double>(val);
|
||||||
|
}
|
||||||
case coFloats:
|
case coFloats:
|
||||||
case coFloat: {
|
case coFloat: {
|
||||||
if (m_opt.nullable && std::isnan(boost::any_cast<double>(m_value)) &&
|
if (m_opt.nullable && std::isnan(boost::any_cast<double>(m_value)) &&
|
||||||
std::isnan(boost::any_cast<double>(val)))
|
std::isnan(boost::any_cast<double>(val)))
|
||||||
return false;
|
return false;
|
||||||
return boost::any_cast<double>(m_value) != boost::any_cast<double>(val);
|
return !is_approx(boost::any_cast<double>(m_value), boost::any_cast<double>(val));
|
||||||
}
|
}
|
||||||
case coString:
|
case coString:
|
||||||
case coStrings:
|
case coStrings:
|
||||||
|
|||||||
Reference in New Issue
Block a user