Skip to content

Commit

Permalink
Merge pull request #2902 from pygame-community/ankith26-math-fixes
Browse files Browse the repository at this point in the history
Minor docs/stubs improvements in `invlerp`/`remap`
  • Loading branch information
Starbuck5 authored Jun 2, 2024
2 parents 011f7ff + 1361426 commit 8d122e3
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions buildconfig/stubs/pygame/math.pyi
Original file line number Diff line number Diff line change
@@ -333,8 +333,8 @@ class Vector3(_GenericVector):
def update(self, x: int, y: int, z: int) -> None: ...


def lerp(a: float, b: float, weight: float, do_clamp: bool = True, /) -> float: ...
def invlerp(a: float, b: float, weight: float, /) -> float: ...
def lerp(a: float, b: float, value: float, do_clamp: bool = True, /) -> float: ...
def invlerp(a: float, b: float, value: float, /) -> float: ...
def remap(i_min: float, i_max: float, o_min: float, o_max: float, value: float, /) -> float: ...
def smoothstep(a: float, b: float, weight: float, /) -> float: ...

10 changes: 5 additions & 5 deletions docs/reST/ref/math.rst
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ Multiple coordinates can be set using slices or swizzling
and ``b``. The third parameter ``value`` is the result of the linear interpolation
between a and b with a certain coefficient. In other words, this coefficient
will be the result of this function.
If ``b - a`` is equal to 0, it raises a ``ZeroDivisionError``.
If ``b`` and ``a`` are equal, it raises a ``ValueError``.

The formula is:

@@ -135,12 +135,12 @@ Multiple coordinates can be set using slices or swizzling
.. function:: remap

| :sl:`remaps value from i_range to o_range`
| :sl:`remaps value from given input range to given output range`
| :sg:`remap(i_min, i_max, o_min, o_max, value, /) -> float`
Returns a number which is the value remapped from ``i_range`` to
``o_range``.
If ``i_max - i_min`` is equal to 0, it raises a ``ZeroDivisionError``.
Returns a number which is the value remapped from ``[i_min, i_max]`` range to
``[o_min, o_max]`` range.
If ``i_min`` and ``i_max`` are equal, it raises a ``ValueError``.

Example:

2 changes: 1 addition & 1 deletion src_c/doc/math_doc.h
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
#define DOC_MATH_LERP "lerp(a, b, value, do_clamp=True, /) -> float\nreturns value linearly interpolated between a and b"
#define DOC_MATH_INVLERP "invlerp(a, b, value, /) -> float\nreturns value inverse interpolated between a and b"
#define DOC_MATH_SMOOTHSTEP "smoothstep(a, b, value, /) -> float\nreturns value smoothly interpolated between a and b."
#define DOC_MATH_REMAP "remap(i_min, i_max, o_min, o_max, value, /) -> float\nremaps value from i_range to o_range"
#define DOC_MATH_REMAP "remap(i_min, i_max, o_min, o_max, value, /) -> float\nremaps value from given input range to given output range"
#define DOC_MATH_VECTOR2 "Vector2() -> Vector2(0, 0)\nVector2(int) -> Vector2\nVector2(float) -> Vector2\nVector2(Vector2) -> Vector2\nVector2(x, y) -> Vector2\nVector2((x, y)) -> Vector2\na 2-Dimensional Vector"
#define DOC_MATH_VECTOR2_DOT "dot(Vector2, /) -> float\ncalculates the dot- or scalar-product with the other vector"
#define DOC_MATH_VECTOR2_CROSS "cross(Vector2, /) -> float\ncalculates the cross- or vector-product"

0 comments on commit 8d122e3

Please sign in to comment.