Repository: godotengine/godot (language: cpp)

Issue:
Vector2.clamped doesn't handle INFs
**Godot version:**
3.1.1.stable.official

`Vector2.clamped` returns `nan`s (Not a Number) when operating on vectors with `INF` components while `clamp` global function seems to work just fine, I'd expect `Vector2.clamped` to be able to handle `INF`s as well.


Discussion / hints:
I think this is a more general problem with `INF` `Vector` math as `Vector2(INF, 0) * Vector2.ZERO` also gives `Vector2(-nan, 0)` say. I haven't tried `Vector3` yet
Still valid in 173ebe487

Although if it's impossible to fix it without math hacks (affecting performance), it should just be documented.

Fix patch:
diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml
index c03262bb33b1..57c351ce4a89 100644
--- a/doc/classes/Vector2.xml
+++ b/doc/classes/Vector2.xml
@@ -270,7 +270,7 @@
 			<return type="Vector2" />
 			<param index="0" name="length" type="float" default="1.0" />
 			<description>
-				Returns the vector with a maximum length by limiting its length to [param length].
+				Returns the vector with a maximum length by limiting its length to [param length]. If the vector is non-finite, the result is undefined.
 			</description>
 		</method>
 		<method name="max" qualifiers="const">
diff --git a/doc/classes/Vector3.xml b/doc/classes/Vector3.xml
index 4ab3140eb633..6483d969378c 100644
--- a/doc/classes/Vector3.xml
+++ b/doc/classes/Vector3.xml
@@ -239,7 +239,7 @@
 			<return type="Vector3" />
 			<param index="0" name="length" type="float" default="1.0" />
 			<description>
-				Returns the vector with a maximum length by limiting its length to [param length].
+				Returns the vector with a maximum length by limiting its length to [param length]. If the vector is non-finite, the result is undefined.
 			</description>
 		</method>
 		<method name="max" qualifiers="const">


Test patch: