You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-09 12:50:35 +00:00
Double precision of String.split_floats
This commit is contained in:
@@ -1256,8 +1256,8 @@ Vector<String> String::rsplit(const String &p_splitter, bool p_allow_empty, int
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<float> String::split_floats(const String &p_splitter, bool p_allow_empty) const {
|
Vector<double> String::split_floats(const String &p_splitter, bool p_allow_empty) const {
|
||||||
Vector<float> ret;
|
Vector<double> ret;
|
||||||
int from = 0;
|
int from = 0;
|
||||||
int len = length();
|
int len = length();
|
||||||
|
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ public:
|
|||||||
Vector<String> split(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
|
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> rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
|
||||||
Vector<String> split_spaces() 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<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(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;
|
Vector<int> split_ints_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const;
|
||||||
|
|||||||
@@ -738,7 +738,7 @@
|
|||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="split_floats" qualifiers="const">
|
<method name="split_floats" qualifiers="const">
|
||||||
<return type="PackedFloat32Array" />
|
<return type="PackedFloat64Array" />
|
||||||
<param index="0" name="delimiter" type="String" />
|
<param index="0" name="delimiter" type="String" />
|
||||||
<param index="1" name="allow_empty" type="bool" default="true" />
|
<param index="1" name="allow_empty" type="bool" default="true" />
|
||||||
<description>
|
<description>
|
||||||
|
|||||||
@@ -1363,7 +1363,7 @@ void EditorHelp::_update_doc() {
|
|||||||
|
|
||||||
if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) {
|
if (constants[i].value.begins_with("Color(") && constants[i].value.ends_with(")")) {
|
||||||
String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", "");
|
String stripped = constants[i].value.replace(" ", "").replace("Color(", "").replace(")", "");
|
||||||
Vector<float> color = stripped.split_floats(",");
|
PackedFloat64Array color = stripped.split_floats(",");
|
||||||
if (color.size() >= 3) {
|
if (color.size() >= 3) {
|
||||||
class_desc->push_color(Color(color[0], color[1], color[2]));
|
class_desc->push_color(Color(color[0], color[1], color[2]));
|
||||||
_add_bulletpoint();
|
_add_bulletpoint();
|
||||||
|
|||||||
@@ -1860,7 +1860,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
|
|||||||
if (valid) {
|
if (valid) {
|
||||||
color_args = line.substr(begin, end - begin);
|
color_args = line.substr(begin, end - begin);
|
||||||
String stripped = color_args.replace(" ", "").replace("(", "").replace(")", "");
|
String stripped = color_args.replace(" ", "").replace("(", "").replace(")", "");
|
||||||
Vector<float> color = stripped.split_floats(",");
|
PackedFloat64Array color = stripped.split_floats(",");
|
||||||
if (color.size() > 2) {
|
if (color.size() > 2) {
|
||||||
float alpha = color.size() > 3 ? color[3] : 1.0f;
|
float alpha = color.size() > 3 ? color[3] : 1.0f;
|
||||||
color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
|
color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha));
|
||||||
|
|||||||
@@ -516,21 +516,22 @@ TEST_CASE("[String] Splitting") {
|
|||||||
s = "1.2;2.3 4.5";
|
s = "1.2;2.3 4.5";
|
||||||
const double slices_d[3] = { 1.2, 2.3, 4.5 };
|
const double slices_d[3] = { 1.2, 2.3, 4.5 };
|
||||||
|
|
||||||
Vector<float> f;
|
Vector<double> d_arr;
|
||||||
f = s.split_floats(";");
|
d_arr = s.split_floats(";");
|
||||||
CHECK(f.size() == 2);
|
CHECK(d_arr.size() == 2);
|
||||||
for (int i = 0; i < f.size(); i++) {
|
for (int i = 0; i < d_arr.size(); i++) {
|
||||||
CHECK(ABS(f[i] - slices_d[i]) <= 0.00001);
|
CHECK(ABS(d_arr[i] - slices_d[i]) <= 0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<String> keys;
|
Vector<String> keys;
|
||||||
keys.push_back(";");
|
keys.push_back(";");
|
||||||
keys.push_back(" ");
|
keys.push_back(" ");
|
||||||
|
|
||||||
f = s.split_floats_mk(keys);
|
Vector<float> f_arr;
|
||||||
CHECK(f.size() == 3);
|
f_arr = s.split_floats_mk(keys);
|
||||||
for (int i = 0; i < f.size(); i++) {
|
CHECK(f_arr.size() == 3);
|
||||||
CHECK(ABS(f[i] - slices_d[i]) <= 0.00001);
|
for (int i = 0; i < f_arr.size(); i++) {
|
||||||
|
CHECK(ABS(f_arr[i] - slices_d[i]) <= 0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
s = "1;2 4";
|
s = "1;2 4";
|
||||||
|
|||||||
Reference in New Issue
Block a user