Skip to content

Commit

Permalink
[Core] Rename linear_interpolate to lerp
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Apr 29, 2020
1 parent ad3c3e1 commit 540156b
Show file tree
Hide file tree
Showing 48 changed files with 144 additions and 155 deletions.
2 changes: 1 addition & 1 deletion core/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct Color {
Color inverted() const;
Color contrasted() const;

_FORCE_INLINE_ Color linear_interpolate(const Color &p_b, float p_t) const {
_FORCE_INLINE_ Color lerp(const Color &p_b, float p_t) const {

Color res = *this;

Expand Down
2 changes: 1 addition & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void Input::SpeedTrack::update(const Vector2 &p_delta_p) {
accum = accum - slice;
accum_t -= min_ref_frame;

speed = (slice / min_ref_frame).linear_interpolate(speed, min_ref_frame / max_ref_frame);
speed = (slice / min_ref_frame).lerp(speed, min_ref_frame / max_ref_frame);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/math/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct AudioFrame {
r = ::undenormalise(r);
}

_FORCE_INLINE_ AudioFrame linear_interpolate(const AudioFrame &p_b, float p_t) const {
_FORCE_INLINE_ AudioFrame lerp(const AudioFrame &p_b, float p_t) const {

AudioFrame res = *this;

Expand Down
4 changes: 2 additions & 2 deletions core/math/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ Vector<Plane> Geometry::build_sphere_planes(real_t p_radius, int p_lats, int p_l
for (int j = 1; j <= p_lats; j++) {

// FIXME: This is stupid.
Vector3 angle = normal.linear_interpolate(axis, j / (real_t)p_lats).normalized();
Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized();
Vector3 pos = angle * p_radius;
planes.push_back(Plane(pos, angle));
planes.push_back(Plane(pos * axis_neg, angle * axis_neg));
Expand Down Expand Up @@ -943,7 +943,7 @@ Vector<Plane> Geometry::build_capsule_planes(real_t p_radius, real_t p_height, i

for (int j = 1; j <= p_lats; j++) {

Vector3 angle = normal.linear_interpolate(axis, j / (real_t)p_lats).normalized();
Vector3 angle = normal.lerp(axis, j / (real_t)p_lats).normalized();
Vector3 pos = axis * p_height * 0.5 + angle * p_radius;
planes.push_back(Plane(pos, angle));
planes.push_back(Plane(pos * axis_neg, angle * axis_neg));
Expand Down
4 changes: 2 additions & 2 deletions core/math/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class Geometry {
if (mub < 0) mub = 0;
if (mua > 1) mua = 1;
if (mub > 1) mub = 1;
c1 = p1.linear_interpolate(p2, mua);
c2 = q1.linear_interpolate(q2, mub);
c1 = p1.lerp(p2, mua);
c2 = q1.lerp(q2, mub);
}

static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) {
Expand Down
4 changes: 2 additions & 2 deletions core/math/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ Transform Transform::interpolate_with(const Transform &p_transform, real_t p_c)
Vector3 dst_loc = p_transform.origin;

Transform interp;
interp.basis.set_quat_scale(src_rot.slerp(dst_rot, p_c).normalized(), src_scale.linear_interpolate(dst_scale, p_c));
interp.origin = src_loc.linear_interpolate(dst_loc, p_c);
interp.basis.set_quat_scale(src_rot.slerp(dst_rot, p_c).normalized(), src_scale.lerp(dst_scale, p_c));
interp.origin = src_loc.lerp(dst_loc, p_c);

return interp;
}
Expand Down
6 changes: 3 additions & 3 deletions core/math/transform_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,16 @@ Transform2D Transform2D::interpolate_with(const Transform2D &p_transform, real_t
Vector2 v;

if (dot > 0.9995) {
v = Vector2::linear_interpolate(v1, v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
v = v1.lerp(v2, p_c).normalized(); //linearly interpolate to avoid numerical precision issues
} else {
real_t angle = p_c * Math::acos(dot);
Vector2 v3 = (v2 - v1 * dot).normalized();
v = v1 * Math::cos(angle) + v3 * Math::sin(angle);
}

//construct matrix
Transform2D res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c));
res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c));
Transform2D res(Math::atan2(v.y, v.x), p1.lerp(p2, p_c));
res.scale_basis(s1.lerp(s2, p_c));
return res;
}

Expand Down
15 changes: 2 additions & 13 deletions core/math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ struct Vector2 {

Vector2 clamped(real_t p_len) const;

_FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t);
_FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector2 lerp(const Vector2 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector2 slerp(const Vector2 &p_b, real_t p_t) const;
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const;
Expand Down Expand Up @@ -224,7 +223,7 @@ _FORCE_INLINE_ bool Vector2::operator!=(const Vector2 &p_vec2) const {
return x != p_vec2.x || y != p_vec2.y;
}

Vector2 Vector2::linear_interpolate(const Vector2 &p_b, real_t p_t) const {
Vector2 Vector2::lerp(const Vector2 &p_b, real_t p_t) const {

Vector2 res = *this;

Expand All @@ -248,16 +247,6 @@ Vector2 Vector2::direction_to(const Vector2 &p_b) const {
return ret;
}

Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) {

Vector2 res = p_a;

res.x += (p_t * (p_b.x - p_a.x));
res.y += (p_t * (p_b.y - p_a.y));

return res;
}

typedef Vector2 Size2;
typedef Vector2 Point2;

Expand Down
4 changes: 2 additions & 2 deletions core/math/vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct Vector3 {

/* Static Methods between 2 vector3s */

_FORCE_INLINE_ Vector3 linear_interpolate(const Vector3 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector3 lerp(const Vector3 &p_b, real_t p_t) const;
_FORCE_INLINE_ Vector3 slerp(const Vector3 &p_b, real_t p_t) const;
Vector3 cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
Vector3 cubic_interpolaten(const Vector3 &p_b, const Vector3 &p_pre_a, const Vector3 &p_post_b, real_t p_t) const;
Expand Down Expand Up @@ -206,7 +206,7 @@ Vector3 Vector3::round() const {
return Vector3(Math::round(x), Math::round(y), Math::round(z));
}

Vector3 Vector3::linear_interpolate(const Vector3 &p_b, real_t p_t) const {
Vector3 Vector3::lerp(const Vector3 &p_b, real_t p_t) const {

return Vector3(
x + (p_t * (p_b.x - x)),
Expand Down
12 changes: 6 additions & 6 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector2, angle_to);
VCALL_LOCALMEM1R(Vector2, angle_to_point);
VCALL_LOCALMEM1R(Vector2, direction_to);
VCALL_LOCALMEM2R(Vector2, linear_interpolate);
VCALL_LOCALMEM2R(Vector2, lerp);
VCALL_LOCALMEM2R(Vector2, slerp);
VCALL_LOCALMEM4R(Vector2, cubic_interpolate);
VCALL_LOCALMEM2R(Vector2, move_toward);
Expand Down Expand Up @@ -426,7 +426,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Vector3, inverse);
VCALL_LOCALMEM1R(Vector3, snapped);
VCALL_LOCALMEM2R(Vector3, rotated);
VCALL_LOCALMEM2R(Vector3, linear_interpolate);
VCALL_LOCALMEM2R(Vector3, lerp);
VCALL_LOCALMEM2R(Vector3, slerp);
VCALL_LOCALMEM4R(Vector3, cubic_interpolate);
VCALL_LOCALMEM2R(Vector3, move_toward);
Expand Down Expand Up @@ -509,7 +509,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Color, to_rgba64);
VCALL_LOCALMEM0R(Color, inverted);
VCALL_LOCALMEM0R(Color, contrasted);
VCALL_LOCALMEM2R(Color, linear_interpolate);
VCALL_LOCALMEM2R(Color, lerp);
VCALL_LOCALMEM1R(Color, blend);
VCALL_LOCALMEM1R(Color, lightened);
VCALL_LOCALMEM1R(Color, darkened);
Expand Down Expand Up @@ -1801,7 +1801,7 @@ void register_variant_methods() {
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmod, FLOAT, "mod", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, posmodv, VECTOR2, "modv", varray());
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, project, VECTOR2, "b", varray());
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, linear_interpolate, VECTOR2, "b", FLOAT, "t", varray());
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, lerp, VECTOR2, "b", FLOAT, "t", varray());
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, slerp, VECTOR2, "b", FLOAT, "t", varray());
ADDFUNC4R(VECTOR2, VECTOR2, Vector2, cubic_interpolate, VECTOR2, "b", VECTOR2, "pre_a", VECTOR2, "post_b", FLOAT, "t", varray());
ADDFUNC2R(VECTOR2, VECTOR2, Vector2, move_toward, VECTOR2, "to", FLOAT, "delta", varray());
Expand Down Expand Up @@ -1866,7 +1866,7 @@ void register_variant_methods() {
ADDFUNC0R(VECTOR3, VECTOR3, Vector3, inverse, varray());
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, snapped, VECTOR3, "by", varray());
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, rotated, VECTOR3, "axis", FLOAT, "phi", varray());
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, linear_interpolate, VECTOR3, "b", FLOAT, "t", varray());
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, lerp, VECTOR3, "b", FLOAT, "t", varray());
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, slerp, VECTOR3, "b", FLOAT, "t", varray());
ADDFUNC4R(VECTOR3, VECTOR3, Vector3, cubic_interpolate, VECTOR3, "b", VECTOR3, "pre_a", VECTOR3, "post_b", FLOAT, "t", varray());
ADDFUNC2R(VECTOR3, VECTOR3, Vector3, move_toward, VECTOR3, "to", FLOAT, "delta", varray());
Expand Down Expand Up @@ -1925,7 +1925,7 @@ void register_variant_methods() {
ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray());
ADDFUNC0R(COLOR, COLOR, Color, inverted, varray());
ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray());
ADDFUNC2R(COLOR, COLOR, Color, linear_interpolate, COLOR, "b", FLOAT, "t", varray());
ADDFUNC2R(COLOR, COLOR, Color, lerp, COLOR, "b", FLOAT, "t", varray());
ADDFUNC1R(COLOR, COLOR, Color, blend, COLOR, "over", varray());
ADDFUNC1R(COLOR, COLOR, Color, lightened, FLOAT, "amount", varray());
ADDFUNC1R(COLOR, COLOR, Color, darkened, FLOAT, "amount", varray());
Expand Down
16 changes: 8 additions & 8 deletions core/variant_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4220,7 +4220,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
case VECTOR2: {
r_dst = reinterpret_cast<const Vector2 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector2 *>(b._data._mem), c);
r_dst = reinterpret_cast<const Vector2 *>(a._data._mem)->lerp(*reinterpret_cast<const Vector2 *>(b._data._mem), c);
}
return;
case VECTOR2I: {
Expand All @@ -4233,7 +4233,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
return;

case RECT2: {
r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->position.lerp(reinterpret_cast<const Rect2 *>(b._data._mem)->position, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.lerp(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
}
return;
case RECT2I: {
Expand All @@ -4254,7 +4254,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
return;

case VECTOR3: {
r_dst = reinterpret_cast<const Vector3 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector3 *>(b._data._mem), c);
r_dst = reinterpret_cast<const Vector3 *>(a._data._mem)->lerp(*reinterpret_cast<const Vector3 *>(b._data._mem), c);
}
return;
case VECTOR3I: {
Expand All @@ -4281,7 +4281,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
case AABB: {
r_dst = ::AABB(a._data._aabb->position.linear_interpolate(b._data._aabb->position, c), a._data._aabb->size.linear_interpolate(b._data._aabb->size, c));
r_dst = ::AABB(a._data._aabb->position.lerp(b._data._aabb->position, c), a._data._aabb->size.lerp(b._data._aabb->size, c));
}
return;
case BASIS: {
Expand All @@ -4293,7 +4293,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
}
return;
case COLOR: {
r_dst = reinterpret_cast<const Color *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Color *>(b._data._mem), c);
r_dst = reinterpret_cast<const Color *>(a._data._mem)->lerp(*reinterpret_cast<const Color *>(b._data._mem), c);
}
return;
case STRING_NAME: {
Expand Down Expand Up @@ -4448,7 +4448,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector2 *br = arr_b->ptr();

for (int i = 0; i < sz; i++) {
vw[i] = ar[i].linear_interpolate(br[i], c);
vw[i] = ar[i].lerp(br[i], c);
}
}
r_dst = v;
Expand All @@ -4473,7 +4473,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Vector3 *br = arr_b->ptr();

for (int i = 0; i < sz; i++) {
vw[i] = ar[i].linear_interpolate(br[i], c);
vw[i] = ar[i].lerp(br[i], c);
}
}
r_dst = v;
Expand All @@ -4497,7 +4497,7 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
const Color *br = arr_b->ptr();

for (int i = 0; i < sz; i++) {
vw[i] = ar[i].linear_interpolate(br[i], c);
vw[i] = ar[i].lerp(br[i], c);
}
}
r_dst = v;
Expand Down
26 changes: 13 additions & 13 deletions doc/classes/Color.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,32 @@
Returns [code]true[/code] if this color and [code]color[/code] are approximately equal, by running [method @GDScript.is_equal_approx] on each component.
</description>
</method>
<method name="lightened">
<method name="lerp">
<return type="Color">
</return>
<argument index="0" name="amount" type="float">
<argument index="0" name="b" type="Color">
</argument>
<argument index="1" name="t" type="float">
</argument>
<description>
Returns a new color resulting from making this color lighter by the specified percentage (ratio from 0 to 1).
Returns the linear interpolation with another color. The interpolation factor [code]t[/code] is between 0 and 1.
[codeblock]
var green = Color(0.0, 1.0, 0.0)
var lightgreen = green.lightened(0.2) # 20% lighter than regular green
var c1 = Color(1.0, 0.0, 0.0)
var c2 = Color(0.0, 1.0, 0.0)
var li_c = c1.lerp(c2, 0.5) # A color of an RGBA(128, 128, 0, 255)
[/codeblock]
</description>
</method>
<method name="linear_interpolate">
<method name="lightened">
<return type="Color">
</return>
<argument index="0" name="b" type="Color">
</argument>
<argument index="1" name="t" type="float">
<argument index="0" name="amount" type="float">
</argument>
<description>
Returns the linear interpolation with another color. The interpolation factor [code]t[/code] is between 0 and 1.
Returns a new color resulting from making this color lighter by the specified percentage (ratio from 0 to 1).
[codeblock]
var c1 = Color(1.0, 0.0, 0.0)
var c2 = Color(0.0, 1.0, 0.0)
var li_c = c1.linear_interpolate(c2, 0.5) # A color of an RGBA(128, 128, 0, 255)
var green = Color(0.0, 1.0, 0.0)
var lightgreen = green.lightened(0.2) # 20% lighter than regular green
[/codeblock]
</description>
</method>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
Returns the vector's length squared. Prefer this method over [method length] if you need to sort vectors or need the squared length for some formula.
</description>
</method>
<method name="linear_interpolate">
<method name="lerp">
<return type="Vector2">
</return>
<argument index="0" name="b" type="Vector2">
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Vector3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
Returns the vector's length squared. Prefer this function over [method length] if you need to sort vectors or need the squared length for some formula.
</description>
</method>
<method name="linear_interpolate">
<method name="lerp">
<return type="Vector3">
</return>
<argument index="0" name="b" type="Vector3">
Expand Down
4 changes: 2 additions & 2 deletions doc/translations/classes.pot
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ msgid ""
"[float], the return value is a [float].\n"
"If both are of the same vector type ([Vector2], [Vector3] or [Color]), the "
"return value will be of the same type ([code]lerp[/code] then calls the "
"vector type's [code]linear_interpolate[/code] method).\n"
"vector type's [code]lerp[/code] method).\n"
"[codeblock]\n"
"lerp(0, 4, 0.75) # Returns 3.0\n"
"lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)\n"
Expand Down Expand Up @@ -12703,7 +12703,7 @@ msgid ""
"[codeblock]\n"
"var c1 = Color(1.0, 0.0, 0.0)\n"
"var c2 = Color(0.0, 1.0, 0.0)\n"
"var li_c = c1.linear_interpolate(c2, 0.5) # A color of an RGBA(128, 128, 0, "
"var li_c = c1.lerp(c2, 0.5) # A color of an RGBA(128, 128, 0, "
"255)\n"
"[/codeblock]"
msgstr ""
Expand Down
4 changes: 2 additions & 2 deletions doc/translations/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ msgid ""
"[float], the return value is a [float].\n"
"If both are of the same vector type ([Vector2], [Vector3] or [Color]), the "
"return value will be of the same type ([code]lerp[/code] then calls the "
"vector type's [code]linear_interpolate[/code] method).\n"
"vector type's [code]lerp[/code] method).\n"
"[codeblock]\n"
"lerp(0, 4, 0.75) # Returns 3.0\n"
"lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)\n"
Expand Down Expand Up @@ -12713,7 +12713,7 @@ msgid ""
"[codeblock]\n"
"var c1 = Color(1.0, 0.0, 0.0)\n"
"var c2 = Color(0.0, 1.0, 0.0)\n"
"var li_c = c1.linear_interpolate(c2, 0.5) # A color of an RGBA(128, 128, 0, "
"var li_c = c1.lerp(c2, 0.5) # A color of an RGBA(128, 128, 0, "
"255)\n"
"[/codeblock]"
msgstr ""
Expand Down
6 changes: 3 additions & 3 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) {

float c = (t - low_pos.x) / (high_pos.x - low_pos.x);

h = low_pos.linear_interpolate(high_pos, c).y;
h = low_pos.lerp(high_pos, c).y;
}

h = _bezier_h_to_pixel(h);
Expand Down Expand Up @@ -201,12 +201,12 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V

if (to.x > p_clip_right) {
float c = (p_clip_right - from.x) / (to.x - from.x);
to = from.linear_interpolate(to, c);
to = from.lerp(to, c);
}

if (from.x < p_clip_left) {
float c = (p_clip_left - from.x) / (to.x - from.x);
from = from.linear_interpolate(to, c);
from = from.lerp(to, c);
}

draw_line(from, to, p_color);
Expand Down
Loading

0 comments on commit 540156b

Please sign in to comment.