Merge pull request #56463 from Calinou/doc-lerp-3.x

Improve `lerp()`, `lerp_angle()` and `inverse_lerp()` documentation (3.x)
This commit is contained in:
Max Hilbrunner 2022-01-04 13:46:04 +01:00 committed by GitHub
commit 1e3bdb6c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -425,14 +425,16 @@
<argument index="1" name="to" type="float" /> <argument index="1" name="to" type="float" />
<argument index="2" name="weight" type="float" /> <argument index="2" name="weight" type="float" />
<description> <description>
Returns a normalized value considering the given range. This is the opposite of [method lerp]. Returns an interpolation or extrapolation factor considering the range specified in [code]from[/code] and [code]to[/code], and the interpolated value specified in [code]weight[/code]. The returned value will be between [code]0.0[/code] and [code]1.0[/code] if [code]weight[/code] is between [code]from[/code] and [code]to[/code] (inclusive). If [code]weight[/code] is located outside this range, then an extrapolation factor will be returned (return value lower than [code]0.0[/code] or greater than [code]1.0[/code]).
[codeblock] [codeblock]
# The interpolation ratio in the `lerp()` call below is 0.75.
var middle = lerp(20, 30, 0.75) var middle = lerp(20, 30, 0.75)
# `middle` is now 27.5. # `middle` is now 27.5.
# Now, we pretend to have forgotten the original ratio and want to get it back. # Now, we pretend to have forgotten the original ratio and want to get it back.
var ratio = inverse_lerp(20, 30, 27.5) var ratio = inverse_lerp(20, 30, 27.5)
# `ratio` is now 0.75. # `ratio` is now 0.75.
[/codeblock] [/codeblock]
See also [method lerp] which performs the reverse of this operation.
</description> </description>
</method> </method>
<method name="is_equal_approx"> <method name="is_equal_approx">
@ -492,13 +494,14 @@
<argument index="1" name="to" type="Variant" /> <argument index="1" name="to" type="Variant" />
<argument index="2" name="weight" type="float" /> <argument index="2" name="weight" type="float" />
<description> <description>
Linearly interpolates between two values by a normalized value. This is the opposite of [method inverse_lerp]. Linearly interpolates between two values by the factor defined in [code]weight[/code]. To perform interpolation, [code]weight[/code] should be between [code]0.0[/code] and [code]1.0[/code] (inclusive). However, values outside this range are allowed and can be used to perform [i]extrapolation[/i].
If the [code]from[/code] and [code]to[/code] arguments are of type [int] or [float], the return value is a [float]. If the [code]from[/code] and [code]to[/code] arguments are of type [int] or [float], the return value is a [float].
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). 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).
[codeblock] [codeblock]
lerp(0, 4, 0.75) # Returns 3.0 lerp(0, 4, 0.75) # Returns 3.0
lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5) lerp(Vector2(1, 5), Vector2(3, 2), 0.5) # Returns Vector2(2, 3.5)
[/codeblock] [/codeblock]
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> </description>
</method> </method>
<method name="lerp_angle"> <method name="lerp_angle">
@ -508,7 +511,7 @@
<argument index="2" name="weight" type="float" /> <argument index="2" name="weight" type="float" />
<description> <description>
Linearly interpolates between two angles (in radians) by a normalized value. Linearly interpolates between two angles (in radians) by a normalized value.
Similar to [method lerp], but interpolates correctly when the angles wrap around [constant @GDScript.TAU]. Similar to [method lerp], but interpolates correctly when the angles wrap around [constant @GDScript.TAU]. To perform eased interpolation with [method lerp_angle], combine it with [method ease] or [method smoothstep].
[codeblock] [codeblock]
extends Sprite extends Sprite
var elapsed = 0.0 var elapsed = 0.0