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

Fixed inspector precision issues when editing floats #25470

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions core/math/math_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,12 @@ uint32_t Math::rand() {

int Math::step_decimals(double p_step) {
static const int maxn = 10;
static const double sd[maxn] = {
0.9999, // somehow compensate for floating point error
0.09999,
0.009999,
0.0009999,
0.00009999,
0.000009999,
0.0000009999,
0.00000009999,
0.000000009999,
0.0000000009999
};

double abs = Math::abs(p_step);
double decs = abs - (int)abs; // Strip away integer part
for (int i = 0; i < maxn; i++) {
if (decs >= sd[i]) {
return i;
}
if (p_step > 0) {
return MAX(MIN(-Math::floor(::log10(p_step)), maxn), 0);
} else {
return maxn;
}

return 0;
}

double Math::dectime(double p_value, double p_amount, double p_step) {
Expand Down
20 changes: 10 additions & 10 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2885,7 +2885,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ

} else {
EditorPropertyFloat *editor = memnew(EditorPropertyFloat);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;
bool exp_range = false;
bool greater = true, lesser = true;
Expand Down Expand Up @@ -2977,7 +2977,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ

case Variant::VECTOR2: {
EditorPropertyVector2 *editor = memnew(EditorPropertyVector2);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -2995,7 +2995,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break; // 5
case Variant::RECT2: {
EditorPropertyRect2 *editor = memnew(EditorPropertyRect2);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3012,7 +3012,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::VECTOR3: {
EditorPropertyVector3 *editor = memnew(EditorPropertyVector3);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3030,7 +3030,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::TRANSFORM2D: {
EditorPropertyTransform2D *editor = memnew(EditorPropertyTransform2D);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3048,7 +3048,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::PLANE: {
EditorPropertyPlane *editor = memnew(EditorPropertyPlane);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3065,7 +3065,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::QUAT: {
EditorPropertyQuat *editor = memnew(EditorPropertyQuat);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3082,7 +3082,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break; // 10
case Variant::AABB: {
EditorPropertyAABB *editor = memnew(EditorPropertyAABB);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3099,7 +3099,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::BASIS: {
EditorPropertyBasis *editor = memnew(EditorPropertyBasis);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand All @@ -3116,7 +3116,7 @@ bool EditorInspectorDefaultPlugin::parse_property(Object *p_object, Variant::Typ
} break;
case Variant::TRANSFORM: {
EditorPropertyTransform *editor = memnew(EditorPropertyTransform);
double min = -65535, max = 65535, step = 0.001;
double min = -65535, max = 65535, step = 0;
bool hide_slider = true;

if (p_hint == PROPERTY_HINT_RANGE && p_hint_text.get_slice_count(",") >= 2) {
Expand Down
2 changes: 1 addition & 1 deletion servers/visual/shader_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class ShaderLanguage {
hint = HINT_NONE;
hint_range[0] = 0;
hint_range[1] = 1;
hint_range[2] = 0.001;
hint_range[2] = 0;
}
};

Expand Down