diff options
Diffstat (limited to 'doc/classes/Vector2.xml')
-rw-r--r-- | doc/classes/Vector2.xml | 97 |
1 files changed, 67 insertions, 30 deletions
diff --git a/doc/classes/Vector2.xml b/doc/classes/Vector2.xml index eaaf41561a..f9ef126658 100644 --- a/doc/classes/Vector2.xml +++ b/doc/classes/Vector2.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="Vector2" version="4.0"> +<class name="Vector2" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <brief_description> Vector used for 2D math using floating point coordinates. </brief_description> @@ -9,9 +9,9 @@ [b]Note:[/b] In a boolean context, a Vector2 will evaluate to [code]false[/code] if it's equal to [code]Vector2(0, 0)[/code]. Otherwise, a Vector2 will always evaluate to [code]true[/code]. </description> <tutorials> - <link title="Math documentation index">https://docs.godotengine.org/en/latest/tutorials/math/index.html</link> - <link title="Vector math">https://docs.godotengine.org/en/latest/tutorials/math/vector_math.html</link> - <link title="Advanced vector math">https://docs.godotengine.org/en/latest/tutorials/math/vectors_advanced.html</link> + <link title="Math documentation index">$DOCS_URL/tutorials/math/index.html</link> + <link title="Vector math">$DOCS_URL/tutorials/math/vector_math.html</link> + <link title="Advanced vector math">$DOCS_URL/tutorials/math/vectors_advanced.html</link> <link title="3Blue1Brown Essence of Linear Algebra">https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab</link> <link title="Matrix Transform Demo">https://godotengine.org/asset-library/asset/584</link> <link title="All 2D Demos">https://github.com/godotengine/godot-demo-projects/tree/master/2d</link> @@ -75,6 +75,7 @@ <argument index="0" name="to" type="Vector2" /> <description> Returns the angle between the line connecting the two points and the X axis, in radians. + [code]a.angle_to_point(b)[/code] is equivalent of doing [code](b - a).angle()[/code]. [url=https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to_point.png]Illustration of the returned angle.[/url] </description> </method> @@ -94,7 +95,7 @@ <method name="ceil" qualifiers="const"> <return type="Vector2" /> <description> - Returns the vector with all components rounded up (towards positive infinity). + Returns a new vector with all components rounded up (towards positive infinity). </description> </method> <method name="clamp" qualifiers="const"> @@ -109,7 +110,9 @@ <return type="float" /> <argument index="0" name="with" type="Vector2" /> <description> - Returns the cross product of this vector and [code]with[/code]. + Returns the 2D analog of the cross product for this vector and [code]with[/code]. + This is the signed area of the parallelogram formed by the two vectors. If the second vector is clockwise from the first vector, then the cross product is the positive area. If counter-clockwise, the cross product is the negative area. + [b]Note:[/b] Cross product is not defined in 2D mathematically. This method embeds the 2D vectors in the XY plane of 3D space and uses their cross product's Z component as the analog. </description> </method> <method name="cubic_interpolate" qualifiers="const"> @@ -124,16 +127,16 @@ </method> <method name="direction_to" qualifiers="const"> <return type="Vector2" /> - <argument index="0" name="b" type="Vector2" /> + <argument index="0" name="to" type="Vector2" /> <description> - Returns the normalized vector pointing from this vector to [code]b[/code]. This is equivalent to using [code](b - a).normalized()[/code]. + Returns the normalized vector pointing from this vector to [code]to[/code]. This is equivalent to using [code](b - a).normalized()[/code]. </description> </method> <method name="distance_squared_to" qualifiers="const"> <return type="float" /> <argument index="0" name="to" type="Vector2" /> <description> - Returns the squared distance between this vector and [code]b[/code]. + Returns the squared distance between this vector and [code]to[/code]. This method runs faster than [method distance_to], so prefer it if you need to compare vectors or need the squared distance for some formula. </description> </method> @@ -157,7 +160,7 @@ <method name="floor" qualifiers="const"> <return type="Vector2" /> <description> - Returns the vector with all components rounded down (towards negative infinity). + Returns a new vector with all components rounded down (towards negative infinity). </description> </method> <method name="from_angle" qualifiers="static"> @@ -213,12 +216,24 @@ Returns the vector with a maximum length by limiting its length to [code]length[/code]. </description> </method> + <method name="max_axis_index" qualifiers="const"> + <return type="int" /> + <description> + Returns the axis of the vector's highest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_X]. + </description> + </method> + <method name="min_axis_index" qualifiers="const"> + <return type="int" /> + <description> + Returns the axis of the vector's lowest value. See [code]AXIS_*[/code] constants. If all components are equal, this method returns [constant AXIS_Y]. + </description> + </method> <method name="move_toward" qualifiers="const"> <return type="Vector2" /> <argument index="0" name="to" type="Vector2" /> <argument index="1" name="delta" type="float" /> <description> - Moves the vector toward [code]to[/code] by the fixed [code]delta[/code] amount. + Returns a new vector moved toward [code]to[/code] by the fixed [code]delta[/code] amount. Will not go past the final value. </description> </method> <method name="normalized" qualifiers="const"> @@ -251,14 +266,14 @@ <return type="Vector2" /> <argument index="0" name="b" type="Vector2" /> <description> - Returns the vector projected onto the vector [code]b[/code]. + Returns this vector projected onto the vector [code]b[/code]. </description> </method> <method name="reflect" qualifiers="const"> <return type="Vector2" /> <argument index="0" name="n" type="Vector2" /> <description> - Returns the vector reflected from a plane defined by the given normal. + Returns the vector reflected (i.e. mirrored, or symmetric) over a line defined by the given direction vector [code]n[/code]. </description> </method> <method name="rotated" qualifiers="const"> @@ -271,13 +286,13 @@ <method name="round" qualifiers="const"> <return type="Vector2" /> <description> - Returns the vector with all components rounded to the nearest integer, with halfway cases rounded away from zero. + Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded away from zero. </description> </method> <method name="sign" qualifiers="const"> <return type="Vector2" /> <description> - Returns the vector with each component set to one or negative one, depending on the signs of the components, or zero if the component is zero, by calling [method @GlobalScope.sign] on each component. + Returns a new vector with each component set to one or negative one, depending on the signs of the components, or zero if the component is zero, by calling [method @GlobalScope.sign] on each component. </description> </method> <method name="slerp" qualifiers="const"> @@ -286,7 +301,7 @@ <argument index="1" name="weight" type="float" /> <description> Returns the result of spherical linear interpolation between this vector and [code]to[/code], by amount [code]weight[/code]. [code]weight[/code] is on the range of 0.0 to 1.0, representing the amount of interpolation. - [b]Note:[/b] Both vectors must be normalized. + This method also handles interpolating the lengths if the input vectors have different lengths. For the special case of one or both input vectors having zero length, this method behaves like [method lerp]. </description> </method> <method name="slide" qualifiers="const"> @@ -314,10 +329,10 @@ </members> <constants> <constant name="AXIS_X" value="0"> - Enumerated value for the X axis. + Enumerated value for the X axis. Returned by [method max_axis_index] and [method min_axis_index]. </constant> <constant name="AXIS_Y" value="1"> - Enumerated value for the Y axis. + Enumerated value for the Y axis. Returned by [method max_axis_index] and [method min_axis_index]. </constant> <constant name="ZERO" value="Vector2(0, 0)"> Zero vector, a vector with all components set to [code]0[/code]. @@ -344,118 +359,140 @@ <operators> <operator name="operator !="> <return type="bool" /> - <description> - </description> - </operator> - <operator name="operator !="> - <return type="bool" /> <argument index="0" name="right" type="Vector2" /> <description> + Returns [code]true[/code] if the vectors are not equal. + [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. </description> </operator> <operator name="operator *"> <return type="Vector2" /> - <argument index="0" name="right" type="Vector2" /> + <argument index="0" name="right" type="Transform2D" /> <description> + Inversely transforms (multiplies) the [Vector2] by the given [Transform2D] transformation matrix. </description> </operator> <operator name="operator *"> <return type="Vector2" /> - <argument index="0" name="right" type="Transform2D" /> + <argument index="0" name="right" type="Vector2" /> <description> + Multiplies each component of the [Vector2] by the components of the given [Vector2]. + [codeblock] + print(Vector2(10, 20) * Vector2(3, 4)) # Prints "(30, 80)" + [/codeblock] </description> </operator> <operator name="operator *"> <return type="Vector2" /> <argument index="0" name="right" type="float" /> <description> + Multiplies each component of the [Vector2] by the given [float]. </description> </operator> <operator name="operator *"> <return type="Vector2" /> <argument index="0" name="right" type="int" /> <description> + Multiplies each component of the [Vector2] by the given [int]. </description> </operator> <operator name="operator +"> <return type="Vector2" /> <argument index="0" name="right" type="Vector2" /> <description> + Adds each component of the [Vector2] by the components of the given [Vector2]. + [codeblock] + print(Vector2(10, 20) + Vector2(3, 4)) # Prints "(13, 24)" + [/codeblock] </description> </operator> <operator name="operator -"> <return type="Vector2" /> <argument index="0" name="right" type="Vector2" /> <description> + Subtracts each component of the [Vector2] by the components of the given [Vector2]. + [codeblock] + print(Vector2(10, 20) - Vector2(3, 4)) # Prints "(7, 16)" + [/codeblock] </description> </operator> <operator name="operator /"> <return type="Vector2" /> <argument index="0" name="right" type="Vector2" /> <description> + Divides each component of the [Vector2] by the components of the given [Vector2]. + [codeblock] + print(Vector2(10, 20) / Vector2(2, 5)) # Prints "(5, 4)" + [/codeblock] </description> </operator> <operator name="operator /"> <return type="Vector2" /> <argument index="0" name="right" type="float" /> <description> + Divides each component of the [Vector2] by the given [float]. </description> </operator> <operator name="operator /"> <return type="Vector2" /> <argument index="0" name="right" type="int" /> <description> + Divides each component of the [Vector2] by the given [int]. </description> </operator> <operator name="operator <"> <return type="bool" /> <argument index="0" name="right" type="Vector2" /> <description> + Compares two [Vector2] vectors by first checking if the X value of the left vector is less than the X value of the [code]right[/code] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors. </description> </operator> <operator name="operator <="> <return type="bool" /> <argument index="0" name="right" type="Vector2" /> <description> - </description> - </operator> - <operator name="operator =="> - <return type="bool" /> - <description> + Compares two [Vector2] vectors by first checking if the X value of the left vector is less than or equal to the X value of the [code]right[/code] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors. </description> </operator> <operator name="operator =="> <return type="bool" /> <argument index="0" name="right" type="Vector2" /> <description> + Returns [code]true[/code] if the vectors are exactly equal. + [b]Note:[/b] Due to floating-point precision errors, consider using [method is_equal_approx] instead, which is more reliable. </description> </operator> <operator name="operator >"> <return type="bool" /> <argument index="0" name="right" type="Vector2" /> <description> + Compares two [Vector2] vectors by first checking if the X value of the left vector is greater than the X value of the [code]right[/code] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors. </description> </operator> <operator name="operator >="> <return type="bool" /> <argument index="0" name="right" type="Vector2" /> <description> + Compares two [Vector2] vectors by first checking if the X value of the left vector is greater than or equal to the X value of the [code]right[/code] vector. If the X values are exactly equal, then it repeats this check with the Y values of the two vectors. This operator is useful for sorting vectors. </description> </operator> <operator name="operator []"> <return type="float" /> <argument index="0" name="index" type="int" /> <description> + Access vector components using their index. [code]v[0][/code] is equivalent to [code]v.x[/code], and [code]v[1][/code] is equivalent to [code]v.y[/code]. </description> </operator> <operator name="operator unary+"> <return type="Vector2" /> <description> + Returns the same value as if the [code]+[/code] was not there. Unary [code]+[/code] does nothing, but sometimes it can make your code more readable. </description> </operator> <operator name="operator unary-"> <return type="Vector2" /> <description> + Returns the negative value of the [Vector2]. This is the same as writing [code]Vector2(-v.x, -v.y)[/code]. This operation flips the direction of the vector while keeping the same magnitude. With floats, the number zero can be either positive or negative. </description> </operator> </operators> |