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 Math::stepify to snapped #44586

Merged
merged 1 commit into from
Dec 28, 2020
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/math_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ double Math::ease(double p_x, double p_c) {
}
}

double Math::stepify(double p_value, double p_step) {
double Math::snapped(double p_value, double p_step) {
if (p_step != 0) {
p_value = Math::floor(p_value / p_step + 0.5) * p_step;
}
Expand Down
6 changes: 3 additions & 3 deletions core/math/math_funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class Math {
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);
static int range_step_decimals(double p_step);
static double stepify(double p_value, double p_step);
static double snapped(double p_value, double p_step);
static double dectime(double p_value, double p_amount, double p_step);

static uint32_t larger_prime(uint32_t p_val);
Expand Down Expand Up @@ -472,12 +472,12 @@ class Math {
}

static _ALWAYS_INLINE_ float snap_scalar(float p_offset, float p_step, float p_target) {
return p_step != 0 ? Math::stepify(p_target - p_offset, p_step) + p_offset : p_target;
return p_step != 0 ? Math::snapped(p_target - p_offset, p_step) + p_offset : p_target;
}

static _ALWAYS_INLINE_ float snap_scalar_separation(float p_offset, float p_step, float p_target, float p_separation) {
if (p_step != 0) {
float a = Math::stepify(p_target - p_offset, p_step + p_separation) + p_offset;
float a = Math::snapped(p_target - p_offset, p_step + p_separation) + p_offset;
float b = a;
if (p_target >= 0) {
b -= p_separation;
Expand Down
6 changes: 3 additions & 3 deletions core/math/vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ Vector2 Vector2::project(const Vector2 &p_to) const {
return p_to * (dot(p_to) / p_to.length_squared());
}

Vector2 Vector2::snapped(const Vector2 &p_by) const {
Vector2 Vector2::snapped(const Vector2 &p_step) const {
return Vector2(
Math::stepify(x, p_by.x),
Math::stepify(y, p_by.y));
Math::snapped(x, p_step.x),
Math::snapped(y, p_step.y));
}

Vector2 Vector2::clamped(real_t p_len) const {
Expand Down
12 changes: 6 additions & 6 deletions core/math/vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ int Vector3::max_axis() const {
return x < y ? (y < z ? 2 : 1) : (x < z ? 2 : 0);
}

void Vector3::snap(Vector3 p_val) {
x = Math::stepify(x, p_val.x);
y = Math::stepify(y, p_val.y);
z = Math::stepify(z, p_val.z);
void Vector3::snap(Vector3 p_step) {
x = Math::snapped(x, p_step.x);
y = Math::snapped(y, p_step.y);
z = Math::snapped(z, p_step.z);
}

Vector3 Vector3::snapped(Vector3 p_val) const {
Vector3 Vector3::snapped(Vector3 p_step) const {
Vector3 v = *this;
v.snap(p_val);
v.snap(p_step);
return v;
}

Expand Down
4 changes: 2 additions & 2 deletions core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ static void _register_variant_builtin_methods() {
bind_method(Vector2, cross, sarray("with"), varray());
bind_method(Vector2, abs, sarray(), varray());
bind_method(Vector2, sign, sarray(), varray());
bind_method(Vector2, snapped, sarray("by"), varray());
bind_method(Vector2, snapped, sarray("step"), varray());
bind_method(Vector2, clamped, sarray("length"), varray());

/* Vector2i */
Expand Down Expand Up @@ -1070,7 +1070,7 @@ static void _register_variant_builtin_methods() {
bind_method(Vector3, is_normalized, sarray(), varray());
bind_method(Vector3, is_equal_approx, sarray("to"), varray());
bind_method(Vector3, inverse, sarray(), varray());
bind_method(Vector3, snapped, sarray("by"), varray());
bind_method(Vector3, snapped, sarray("step"), varray());
bind_method(Vector3, rotated, sarray("by_axis", "phi"), varray());
bind_method(Vector3, lerp, sarray("to", "weight"), varray());
bind_method(Vector3, slerp, sarray("to", "weight"), varray());
Expand Down
6 changes: 3 additions & 3 deletions core/variant/variant_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ struct VariantUtilityFunctions {
return Math::range_step_decimals(step);
}

static inline double stepify(double value, double step) {
return Math::stepify(value, step);
static inline double snapped(double value, double step) {
return Math::snapped(value, step);
}

static inline double lerp(double from, double to, double weight) {
Expand Down Expand Up @@ -1181,7 +1181,7 @@ void Variant::_register_variant_utility_functions() {
FUNCBINDR(ease, sarray("x", "curve"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(range_step_decimals, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(stepify, sarray("x", "step"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(snapped, sarray("x", "step"), Variant::UTILITY_FUNC_TYPE_MATH);

FUNCBINDR(lerp, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH);
FUNCBINDR(lerp_angle, sarray("from", "to", "weight"), Variant::UTILITY_FUNC_TYPE_MATH);
Expand Down
12 changes: 6 additions & 6 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
i = ceil(1.45) # i is 2
i = ceil(1.001) # i is 2
[/codeblock]
See also [method floor], [method round], and [method stepify].
See also [method floor], [method round], and [method snapped].
</description>
</method>
<method name="clamp">
Expand Down Expand Up @@ -303,7 +303,7 @@
# a is -3.0
a = floor(-2.99)
[/codeblock]
See also [method ceil], [method round], and [method stepify].
See also [method ceil], [method round], and [method snapped].
[b]Note:[/b] This method returns a float. If you need an integer, you can use [code]int(x)[/code] directly.
</description>
</method>
Expand Down Expand Up @@ -848,7 +848,7 @@
[codeblock]
round(2.6) # Returns 3
[/codeblock]
See also [method floor], [method ceil], and [method stepify].
See also [method floor], [method ceil], and [method snapped].
</description>
</method>
<method name="seed">
Expand Down Expand Up @@ -974,7 +974,7 @@
[/codeblock]
</description>
</method>
<method name="stepify">
<method name="snapped">
<return type="float">
</return>
<argument index="0" name="x" type="float">
Expand All @@ -984,8 +984,8 @@
<description>
Snaps float value [code]x[/code] to a given [code]step[/code]. This can also be used to round a floating point number to an arbitrary number of decimals.
[codeblock]
stepify(100, 32) # Returns 96
stepify(3.14159, 0.01) # Returns 3.14
snapped(100, 32) # Returns 96
snapped(3.14159, 0.01) # Returns 3.14
[/codeblock]
See also [method ceil], [method floor], and [method round].
</description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@
<method name="snapped">
<return type="Vector2">
</return>
<argument index="0" name="by" type="Vector2">
<argument index="0" name="step" type="Vector2">
</argument>
<description>
Returns this vector with each component snapped to the nearest multiple of [code]step[/code]. This can also be used to round to an arbitrary number of decimals.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
<method name="snapped">
<return type="Vector3">
</return>
<argument index="0" name="by" type="Vector3">
<argument index="0" name="step" type="Vector3">
</argument>
<description>
Returns this vector with each component snapped to the nearest multiple of [code]step[/code]. This can also be used to round to an arbitrary number of decimals.
Expand Down
8 changes: 4 additions & 4 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {

float scale = (min_left_scale * 2) * v_zoom;
float step = Math::pow(10.0, Math::round(Math::log(scale / 5.0) / Math::log(10.0))) * 5.0;
scale = Math::stepify(scale, step);
scale = Math::snapped(scale, step);

while (scale / v_zoom < min_left_scale * 2) {
scale += step;
Expand All @@ -390,7 +390,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
draw_line(Point2(limit, i), Point2(right_limit, i), lc);
Color c = color;
c.a *= 0.5;
draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::stepify((iv + 1) * scale, step))), HALIGN_LEFT, -1, font_size, c);
draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::snapped((iv + 1) * scale, step))), HALIGN_LEFT, -1, font_size, c);
}

first = false;
Expand Down Expand Up @@ -461,8 +461,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
ep.point_rect.size = bezier_icon->get_size();
if (selection.has(i)) {
draw_texture(selected_icon, ep.point_rect.position);
draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 4), TTR("Time:") + " " + TS->format_number(rtos(Math::stepify(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent);
draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::stepify(value, 0.001))), HALIGN_LEFT, -1, font_size, accent);
draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 4), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent);
draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HALIGN_LEFT, -1, font_size, accent);
} else {
draw_texture(bezier_icon, ep.point_rect.position);
}
Expand Down
10 changes: 5 additions & 5 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3445,7 +3445,7 @@ void AnimationTrackEditor::_insert_delay(bool p_create_reset, bool p_create_bezi

float pos = timeline->get_play_position();

pos = Math::stepify(pos + step, step);
pos = Math::snapped(pos + step, step);
if (pos > animation->get_length()) {
pos = animation->get_length();
}
Expand Down Expand Up @@ -5433,7 +5433,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {

float pos = timeline->get_play_position();

pos = Math::stepify(pos + step, step);
pos = Math::snapped(pos + step, step);
if (pos > animation->get_length()) {
pos = animation->get_length();
}
Expand All @@ -5452,7 +5452,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
}

float pos = timeline->get_play_position();
pos = Math::stepify(pos - step, step);
pos = Math::snapped(pos - step, step);
if (pos < 0) {
pos = 0;
}
Expand Down Expand Up @@ -5581,9 +5581,9 @@ float AnimationTrackEditor::snap_time(float p_value, bool p_relative) {

if (p_relative) {
double rel = Math::fmod(timeline->get_value(), snap_increment);
p_value = Math::stepify(p_value + rel, snap_increment) - rel;
p_value = Math::snapped(p_value + rel, snap_increment) - rel;
} else {
p_value = Math::stepify(p_value, snap_increment);
p_value = Math::snapped(p_value, snap_increment);
}
}

Expand Down
Loading