diff options
author | Micky <micheledevita2@gmail.com> | 2022-11-20 12:29:50 +0100 |
---|---|---|
committer | Micky <micheledevita2@gmail.com> | 2022-11-20 12:29:50 +0100 |
commit | e791f4fce275247a66eb657ff7cc7be4ffd4d5bc (patch) | |
tree | 00b1015cdb150ca4277c47f665a630cbb73c0ca9 | |
parent | 8aafcf9d2ae43e83636d60dbfd5f10e50fcdb324 (diff) |
Double precision of `String.split_floats`
-rw-r--r-- | core/string/ustring.cpp | 4 | ||||
-rw-r--r-- | core/string/ustring.h | 2 | ||||
-rw-r--r-- | doc/classes/String.xml | 2 | ||||
-rw-r--r-- | editor/editor_help.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 2 | ||||
-rw-r--r-- | tests/core/string/test_string.h | 19 |
6 files changed, 16 insertions, 15 deletions
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 8993f9667d..175c42542b 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -1256,8 +1256,8 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int return ret; } -Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty) const { - Vector<float> ret; +Vector<double> String::split_floats(const String &p_splitter, bool p_allow_empty) const { + Vector<double> ret; int from = 0; int len = length(); diff --git a/core/string/ustring.h b/core/string/ustring.h index 8af74584f3..0c171024f7 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -348,7 +348,7 @@ public: Vector<String> split(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const; Vector<String> rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const; Vector<String> split_spaces() const; - Vector<float> split_floats(const String &p_splitter, bool p_allow_empty = true) const; + Vector<double> split_floats(const String &p_splitter, bool p_allow_empty = true) const; Vector<float> split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const; Vector<int> split_ints(const String &p_splitter, bool p_allow_empty = true) const; Vector<int> split_ints_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const; diff --git a/doc/classes/String.xml b/doc/classes/String.xml index 999913b1ac..53040b2753 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -738,7 +738,7 @@ </description> </method> <method name="split_floats" qualifiers="const"> - <return type="PackedFloat32Array" /> + <return type="PackedFloat64Array" /> <param index="0" name="delimiter" type="String" /> <param index="1" name="allow_empty" type="bool" default="true" /> <description> diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 0a443ee645..636e076b1e 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -1363,7 +1363,7 @@ void EditorHelp::_update_doc() { if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) { String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", ""); - Vector<float> color = stripped.split_floats(","); + PackedFloat64Array color = stripped.split_floats(","); if (color.size() >= 3) { class_desc->push_color(Color(color[0], color[1], color[2])); _add_bulletpoint(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 0d12d07aa7..4e66dc3d7e 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1860,7 +1860,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (valid) { color_args = line.substr(begin, end - begin); String stripped = color_args.replace(" ", "").replace("(", "").replace(")", ""); - Vector<float> color = stripped.split_floats(","); + PackedFloat64Array color = stripped.split_floats(","); if (color.size() > 2) { float alpha = color.size() > 3 ? color[3] : 1.0f; color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); diff --git a/tests/core/string/test_string.h b/tests/core/string/test_string.h index 7e4e3aa9f0..ebb526b37c 100644 --- a/tests/core/string/test_string.h +++ b/tests/core/string/test_string.h @@ -516,21 +516,22 @@ TEST_CASE("[String] Splitting") { s = "1.2;2.3 4.5"; const double slices_d[3] = { 1.2, 2.3, 4.5 }; - Vector<float> f; - f = s.split_floats(";"); - CHECK(f.size() == 2); - for (int i = 0; i < f.size(); i++) { - CHECK(ABS(f[i] - slices_d[i]) <= 0.00001); + Vector<double> d_arr; + d_arr = s.split_floats(";"); + CHECK(d_arr.size() == 2); + for (int i = 0; i < d_arr.size(); i++) { + CHECK(ABS(d_arr[i] - slices_d[i]) <= 0.00001); } Vector<String> keys; keys.push_back(";"); keys.push_back(" "); - f = s.split_floats_mk(keys); - CHECK(f.size() == 3); - for (int i = 0; i < f.size(); i++) { - CHECK(ABS(f[i] - slices_d[i]) <= 0.00001); + Vector<float> f_arr; + f_arr = s.split_floats_mk(keys); + CHECK(f_arr.size() == 3); + for (int i = 0; i < f_arr.size(); i++) { + CHECK(ABS(f_arr[i] - slices_d[i]) <= 0.00001); } s = "1;2 4"; |