From af317be718e02fb4b2d9f7d5c45eb0f6755ccc6a Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 8 Apr 2024 18:04:53 +0200 Subject: [PATCH] Core: avoid conversion from float to double or vice-versa When synchronizing the Transparency property with the transparency value of the ShapeAppearance property then do not convert between float and double as otherwise some strange rounding issues can occur. Example: Set the Transparency property of an object to 35 in the Property Editor. After leaving the editor the value may switch to 34. --- src/App/PropertyStandard.cpp | 8 ++++---- src/App/PropertyStandard.h | 8 ++++---- src/Gui/ViewProviderGeometryObject.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index c46f62ee4b..07452a4de1 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -3033,22 +3033,22 @@ const Color& PropertyMaterialList::getEmissiveColor(int index) const return _lValueList[index].emissiveColor; } -double PropertyMaterialList::getShininess() const +float PropertyMaterialList::getShininess() const { return _lValueList[0].transparency; } -double PropertyMaterialList::getShininess(int index) const +float PropertyMaterialList::getShininess(int index) const { return _lValueList[index].transparency; } -double PropertyMaterialList::getTransparency() const +float PropertyMaterialList::getTransparency() const { return _lValueList[0].transparency; } -double PropertyMaterialList::getTransparency(int index) const +float PropertyMaterialList::getTransparency(int index) const { return _lValueList[index].transparency; } diff --git a/src/App/PropertyStandard.h b/src/App/PropertyStandard.h index a66e482f9c..ed617cc821 100644 --- a/src/App/PropertyStandard.h +++ b/src/App/PropertyStandard.h @@ -1166,11 +1166,11 @@ public: const Color& getEmissiveColor() const; const Color& getEmissiveColor(int index) const; - double getShininess() const; - double getShininess(int index) const; + float getShininess() const; + float getShininess(int index) const; - double getTransparency() const; - double getTransparency(int index) const; + float getTransparency() const; + float getTransparency(int index) const; PyObject* getPyObject() override; diff --git a/src/Gui/ViewProviderGeometryObject.cpp b/src/Gui/ViewProviderGeometryObject.cpp index 82d4295e47..34170b4f49 100644 --- a/src/Gui/ViewProviderGeometryObject.cpp +++ b/src/Gui/ViewProviderGeometryObject.cpp @@ -149,7 +149,7 @@ void ViewProviderGeometryObject::onChanged(const App::Property* prop) getObject()->touch(true); } const App::Material& Mat = ShapeAppearance[0]; - long value = (long)(100.0 * ShapeAppearance.getTransparency() + 0.5); + long value = (long)(100.0 * ShapeAppearance.getTransparency()); if (value != Transparency.getValue()) { Transparency.setValue(value); }