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

Rename str2var to str_to_var and similar #64367

Merged
merged 1 commit into from
Aug 26, 2022
Merged
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
2 changes: 1 addition & 1 deletion core/math/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static inline float undenormalise(volatile float f) {
}

static const float AUDIO_PEAK_OFFSET = 0.0000000001f;
static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear2db(AUDIO_PEAK_OFFSET)
static const float AUDIO_MIN_PEAK_DB = -200.0f; // linear_to_db(AUDIO_PEAK_OFFSET)

struct AudioFrame {
//left and right samples
Expand Down
16 changes: 8 additions & 8 deletions core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,11 @@ class Math {
return value;
}

static _ALWAYS_INLINE_ double deg2rad(double p_y) { return p_y * (Math_PI / 180.0); }
static _ALWAYS_INLINE_ float deg2rad(float p_y) { return p_y * (float)(Math_PI / 180.0); }
static _ALWAYS_INLINE_ double deg_to_rad(double p_y) { return p_y * (Math_PI / 180.0); }
static _ALWAYS_INLINE_ float deg_to_rad(float p_y) { return p_y * (float)(Math_PI / 180.0); }

static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y * (180.0 / Math_PI); }
static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y * (float)(180.0 / Math_PI); }
static _ALWAYS_INLINE_ double rad_to_deg(double p_y) { return p_y * (180.0 / Math_PI); }
static _ALWAYS_INLINE_ float rad_to_deg(float p_y) { return p_y * (float)(180.0 / Math_PI); }

static _ALWAYS_INLINE_ double lerp(double p_from, double p_to, double p_weight) { return p_from + (p_to - p_from) * p_weight; }
static _ALWAYS_INLINE_ float lerp(float p_from, float p_to, float p_weight) { return p_from + (p_to - p_from) * p_weight; }
Expand Down Expand Up @@ -331,11 +331,11 @@ class Math {
static _ALWAYS_INLINE_ double move_toward(double p_from, double p_to, double p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; }
static _ALWAYS_INLINE_ float move_toward(float p_from, float p_to, float p_delta) { return abs(p_to - p_from) <= p_delta ? p_to : p_from + SIGN(p_to - p_from) * p_delta; }

static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log(p_linear) * (float)8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ double linear_to_db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ float linear_to_db(float p_linear) { return Math::log(p_linear) * (float)8.6858896380650365530225783783321; }

static _ALWAYS_INLINE_ double db2linear(double p_db) { return Math::exp(p_db * 0.11512925464970228420089957273422); }
static _ALWAYS_INLINE_ float db2linear(float p_db) { return Math::exp(p_db * (float)0.11512925464970228420089957273422); }
static _ALWAYS_INLINE_ double db_to_linear(double p_db) { return Math::exp(p_db * 0.11512925464970228420089957273422); }
static _ALWAYS_INLINE_ float db_to_linear(float p_db) { return Math::exp(p_db * (float)0.11512925464970228420089957273422); }

static _ALWAYS_INLINE_ double round(double p_val) { return ::round(p_val); }
static _ALWAYS_INLINE_ float round(float p_val) { return ::roundf(p_val); }
Expand Down
8 changes: 4 additions & 4 deletions core/math/projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t
}

real_t sine, cotangent, deltaZ;
real_t radians = Math::deg2rad(p_fovy_degrees / 2.0);
real_t radians = Math::deg_to_rad(p_fovy_degrees / 2.0);

deltaZ = p_z_far - p_z_near;
sine = Math::sin(radians);
Expand All @@ -282,7 +282,7 @@ void Projection::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t

real_t left, right, modeltranslation, ymax, xmax, frustumshift;

ymax = p_z_near * tan(Math::deg2rad(p_fovy_degrees / 2.0));
ymax = p_z_near * tan(Math::deg_to_rad(p_fovy_degrees / 2.0));
xmax = ymax * p_aspect;
frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist;

Expand Down Expand Up @@ -816,7 +816,7 @@ real_t Projection::get_fov() const {
right_plane.normalize();

if ((matrix[8] == 0) && (matrix[9] == 0)) {
return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
return Math::rad_to_deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
} else {
// our frustum is asymmetrical need to calculate the left planes angle separately..
Plane left_plane = Plane(matrix[3] + matrix[0],
Expand All @@ -825,7 +825,7 @@ real_t Projection::get_fov() const {
matrix[15] + matrix[12]);
left_plane.normalize();

return Math::rad2deg(Math::acos(Math::abs(left_plane.normal.x))) + Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x)));
return Math::rad_to_deg(Math::acos(Math::abs(left_plane.normal.x))) + Math::rad_to_deg(Math::acos(Math::abs(right_plane.normal.x)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/math/projection.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct Projection {
Projection jitter_offseted(const Vector2 &p_offset) const;

static real_t get_fovy(real_t p_fovx, real_t p_aspect) {
return Math::rad2deg(Math::atan(p_aspect * Math::tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0);
return Math::rad_to_deg(Math::atan(p_aspect * Math::tan(Math::deg_to_rad(p_fovx) * 0.5)) * 2.0);
}

real_t get_z_far() const;
Expand Down
48 changes: 24 additions & 24 deletions core/variant/variant_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,20 +396,20 @@ struct VariantUtilityFunctions {
return Math::move_toward(from, to, delta);
}

static inline double deg2rad(double angle_deg) {
return Math::deg2rad(angle_deg);
static inline double deg_to_rad(double angle_deg) {
return Math::deg_to_rad(angle_deg);
}

static inline double rad2deg(double angle_rad) {
return Math::rad2deg(angle_rad);
static inline double rad_to_deg(double angle_rad) {
return Math::rad_to_deg(angle_rad);
}

static inline double linear2db(double linear) {
return Math::linear2db(linear);
static inline double linear_to_db(double linear) {
return Math::linear_to_db(linear);
}

static inline double db2linear(double db) {
return Math::db2linear(db);
static inline double db_to_linear(double db) {
return Math::db_to_linear(db);
}

static inline Variant wrap(const Variant &p_x, const Variant &p_min, const Variant &p_max, Callable::CallError &r_error) {
Expand Down Expand Up @@ -837,13 +837,13 @@ struct VariantUtilityFunctions {
r_error.error = Callable::CallError::CALL_OK;
}

static inline String var2str(const Variant &p_var) {
static inline String var_to_str(const Variant &p_var) {
String vars;
VariantWriter::write_to_string(p_var, vars);
return vars;
}

static inline Variant str2var(const String &p_var) {
static inline Variant str_to_var(const String &p_var) {
VariantParser::StreamString ss;
ss.s = p_var;

Expand All @@ -855,7 +855,7 @@ struct VariantUtilityFunctions {
return ret;
}

static inline PackedByteArray var2bytes(const Variant &p_var) {
static inline PackedByteArray var_to_bytes(const Variant &p_var) {
int len;
Error err = encode_variant(p_var, nullptr, len, false);
if (err != OK) {
Expand All @@ -875,7 +875,7 @@ struct VariantUtilityFunctions {
return barr;
}

static inline PackedByteArray var2bytes_with_objects(const Variant &p_var) {
static inline PackedByteArray var_to_bytes_with_objects(const Variant &p_var) {
int len;
Error err = encode_variant(p_var, nullptr, len, true);
if (err != OK) {
Expand All @@ -895,7 +895,7 @@ struct VariantUtilityFunctions {
return barr;
}

static inline Variant bytes2var(const PackedByteArray &p_arr) {
static inline Variant bytes_to_var(const PackedByteArray &p_arr) {
Variant ret;
{
const uint8_t *r = p_arr.ptr();
Expand All @@ -907,7 +907,7 @@ struct VariantUtilityFunctions {
return ret;
}

static inline Variant bytes2var_with_objects(const PackedByteArray &p_arr) {
static inline Variant bytes_to_var_with_objects(const PackedByteArray &p_arr) {
Variant ret;
{
const uint8_t *r = p_arr.ptr();
Expand Down Expand Up @@ -1428,10 +1428,10 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(smoothstep, sarray("from", "to", "x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(move_toward, sarray("from", "to", "delta"), Variant::UTILITY_FUNC_TYPE_MATH);

FUNCBINDR(deg2rad, sarray("deg"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(rad2deg, sarray("rad"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(linear2db, sarray("lin"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(db2linear, sarray("db"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(deg_to_rad, sarray("deg"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(rad_to_deg, sarray("rad"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(linear_to_db, sarray("lin"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(db_to_linear, sarray("db"), Variant::UTILITY_FUNC_TYPE_MATH);

FUNCBINDVR3(wrap, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(wrapi, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH);
Expand Down Expand Up @@ -1479,14 +1479,14 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDVARARGV(push_error, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDVARARGV(push_warning, sarray(), Variant::UTILITY_FUNC_TYPE_GENERAL);

FUNCBINDR(var2str, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(str2var, sarray("string"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(var_to_str, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(str_to_var, sarray("string"), Variant::UTILITY_FUNC_TYPE_GENERAL);

FUNCBINDR(var2bytes, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(bytes2var, sarray("bytes"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(var_to_bytes, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(bytes_to_var, sarray("bytes"), Variant::UTILITY_FUNC_TYPE_GENERAL);

FUNCBINDR(var2bytes_with_objects, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(bytes2var_with_objects, sarray("bytes"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(var_to_bytes_with_objects, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);
FUNCBINDR(bytes_to_var_with_objects, sarray("bytes"), Variant::UTILITY_FUNC_TYPE_GENERAL);

FUNCBINDR(hash, sarray("variable"), Variant::UTILITY_FUNC_TYPE_GENERAL);

Expand Down
62 changes: 31 additions & 31 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<description>
Returns the arc cosine of [param x] in radians. Use to get the angle of cosine [param x]. [param x] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method acos] will return [constant @GDScript.NAN].
[codeblock]
# c is 0.523599 or 30 degrees if converted with rad2deg(c)
# c is 0.523599 or 30 degrees if converted with rad_to_deg(c)
var c = acos(0.866025)
[/codeblock]
</description>
Expand All @@ -77,7 +77,7 @@
<description>
Returns the arc sine of [param x] in radians. Use to get the angle of sine [param x]. [param x] must be between [code]-1.0[/code] and [code]1.0[/code] (inclusive), otherwise, [method asin] will return [constant @GDScript.NAN].
[codeblock]
# s is 0.523599 or 30 degrees if converted with rad2deg(s)
# s is 0.523599 or 30 degrees if converted with rad_to_deg(s)
var s = asin(0.5)
[/codeblock]
</description>
Expand Down Expand Up @@ -117,15 +117,15 @@
Returns the point at the given [param t] on a one-dimnesional [url=https://en.wikipedia.org/wiki/B%C3%A9zier_curve]Bezier curve[/url] defined by the given [param control_1], [param control_2], and [param end] points.
</description>
</method>
<method name="bytes2var">
<method name="bytes_to_var">
<return type="Variant" />
<param index="0" name="bytes" type="PackedByteArray" />
<description>
Decodes a byte array back to a [Variant] value, without decoding objects.
[b]Note:[/b] If you need object deserialization, see [method bytes2var_with_objects].
[b]Note:[/b] If you need object deserialization, see [method bytes_to_var_with_objects].
</description>
</method>
<method name="bytes2var_with_objects">
<method name="bytes_to_var_with_objects">
<return type="Variant" />
<param index="0" name="bytes" type="PackedByteArray" />
<description>
Expand Down Expand Up @@ -232,9 +232,9 @@
<description>
Returns the cosine of angle [param angle_rad] in radians.
[codeblock]
cos(PI * 2) # Returns 1.0
cos(PI) # Returns -1.0
cos(deg2rad(90)) # Returns 0.0
cos(PI * 2) # Returns 1.0
cos(PI) # Returns -1.0
cos(deg_to_rad(90)) # Returns 0.0
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -275,21 +275,21 @@
It can perform smoother interpolation than [code]cubic_interpolate()[/code] by the time values.
</description>
</method>
<method name="db2linear">
<method name="db_to_linear">
<return type="float" />
<param index="0" name="db" type="float" />
<description>
Converts from decibels to linear energy (audio).
</description>
</method>
<method name="deg2rad">
<method name="deg_to_rad">
<return type="float" />
<param index="0" name="deg" type="float" />
<description>
Converts an angle expressed in degrees to radians.
[codeblock]
# r is 3.141593
var r = deg2rad(180)
var r = deg_to_rad(180)
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -513,8 +513,8 @@
extends Sprite
var elapsed = 0.0
func _process(delta):
var min_angle = deg2rad(0.0)
var max_angle = deg2rad(90.0)
var min_angle = deg_to_rad(0.0)
var max_angle = deg_to_rad(90.0)
rotation = lerp_angle(min_angle, max_angle, elapsed)
elapsed += delta
[/codeblock]
Expand All @@ -534,7 +534,7 @@
See also [method inverse_lerp] which performs the reverse of this operation. To perform eased interpolation with [method lerp], combine it with [method ease] or [method smoothstep].
</description>
</method>
<method name="linear2db">
<method name="linear_to_db">
<return type="float" />
<param index="0" name="lin" type="float" />
<description>
Expand All @@ -543,7 +543,7 @@
# "Slider" refers to a node that inherits Range such as HSlider or VSlider.
# Its range must be configured to go from 0 to 1.
# Change the bus name if you'd like to change the volume of a specific bus only.
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear2db($Slider.value))
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear_to_db($Slider.value))
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -787,13 +787,13 @@
[/codeblock]
</description>
</method>
<method name="rad2deg">
<method name="rad_to_deg">
<return type="float" />
<param index="0" name="rad" type="float" />
<description>
Converts an angle expressed in radians to degrees.
[codeblock]
rad2deg(0.523599) # Returns 30
rad_to_deg(0.523599) # Returns 30
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -974,8 +974,8 @@
<description>
Returns the sine of angle [param angle_rad] in radians.
[codeblock]
sin(0.523599) # Returns 0.5
sin(deg2rad(90)) # Returns 1.0
sin(0.523599) # Returns 0.5
sin(deg_to_rad(90)) # Returns 1.0
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -1054,14 +1054,14 @@
Converts one or more arguments of any type to string in the best way possible.
</description>
</method>
<method name="str2var">
<method name="str_to_var">
<return type="Variant" />
<param index="0" name="string" type="String" />
<description>
Converts a formatted string that was returned by [method var2str] to the original value.
Converts a formatted [param string] that was returned by [method var_to_str] to the original value.
[codeblock]
var a = '{ "a": 1, "b": 2 }'
var b = str2var(a)
var b = str_to_var(a)
print(b["a"]) # Prints 1
[/codeblock]
</description>
Expand All @@ -1072,7 +1072,7 @@
<description>
Returns the tangent of angle [param angle_rad] in radians.
[codeblock]
tan(deg2rad(45)) # Returns 1
tan(deg_to_rad(45)) # Returns 1
[/codeblock]
</description>
</method>
Expand Down Expand Up @@ -1103,29 +1103,29 @@
[/codeblock]
</description>
</method>
<method name="var2bytes">
<method name="var_to_bytes">
<return type="PackedByteArray" />
<param index="0" name="variable" type="Variant" />
<description>
Encodes a [Variant] value to a byte array, without encoding objects. Deserialization can be done with [method bytes2var].
[b]Note:[/b] If you need object serialization, see [method var2bytes_with_objects].
Encodes a [Variant] value to a byte array, without encoding objects. Deserialization can be done with [method bytes_to_var].
[b]Note:[/b] If you need object serialization, see [method var_to_bytes_with_objects].
</description>
</method>
<method name="var2bytes_with_objects">
<method name="var_to_bytes_with_objects">
<return type="PackedByteArray" />
<param index="0" name="variable" type="Variant" />
<description>
Encodes a [Variant] value to a byte array. Encoding objects is allowed (and can potentially include code). Deserialization can be done with [method bytes2var_with_objects].
Encodes a [Variant] value to a byte array. Encoding objects is allowed (and can potentially include code). Deserialization can be done with [method bytes_to_var_with_objects].
</description>
</method>
<method name="var2str">
<method name="var_to_str">
<return type="String" />
<param index="0" name="variable" type="Variant" />
<description>
Converts a Variant [param variable] to a formatted string that can later be parsed using [method str2var].
Converts a Variant [param variable] to a formatted string that can later be parsed using [method str_to_var].
[codeblock]
a = { "a": 1, "b": 2 }
print(var2str(a))
print(var_to_str(a))
[/codeblock]
prints
[codeblock]
Expand Down
Loading