From 3861d6dc71dfb5c458b98795a8a0271190cdbad1 Mon Sep 17 00:00:00 2001 From: Ankith Date: Sun, 2 Jun 2024 21:24:24 +0530 Subject: [PATCH 1/2] Minor docs/stubs improvements in `invlerp`/`remap` --- buildconfig/stubs/pygame/math.pyi | 2 +- docs/reST/ref/math.rst | 10 +++++----- src_c/doc/math_doc.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/buildconfig/stubs/pygame/math.pyi b/buildconfig/stubs/pygame/math.pyi index 82ec91c7a0..f826a1e990 100644 --- a/buildconfig/stubs/pygame/math.pyi +++ b/buildconfig/stubs/pygame/math.pyi @@ -334,7 +334,7 @@ class Vector3(_GenericVector): def lerp(a: float, b: float, weight: float, do_clamp: bool = True, /) -> float: ... -def invlerp(a: float, b: float, weight: float, /) -> 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: ... diff --git a/docs/reST/ref/math.rst b/docs/reST/ref/math.rst index 93cb998bbc..4d93a46667 100644 --- a/docs/reST/ref/math.rst +++ b/docs/reST/ref/math.rst @@ -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: diff --git a/src_c/doc/math_doc.h b/src_c/doc/math_doc.h index f5607ce918..e002a0c672 100644 --- a/src_c/doc/math_doc.h +++ b/src_c/doc/math_doc.h @@ -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" From 136142643bd5b2fb33d96d1669f43808422a87da Mon Sep 17 00:00:00 2001 From: Ankith Date: Sun, 2 Jun 2024 21:58:15 +0530 Subject: [PATCH 2/2] Fix lerp stub to doc discrepancy Co-authored-by: Dan Lawrence --- buildconfig/stubs/pygame/math.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildconfig/stubs/pygame/math.pyi b/buildconfig/stubs/pygame/math.pyi index f826a1e990..963f2bd957 100644 --- a/buildconfig/stubs/pygame/math.pyi +++ b/buildconfig/stubs/pygame/math.pyi @@ -333,7 +333,7 @@ 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 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: ...