diff options
Diffstat (limited to 'modules/mono/glue')
32 files changed, 1579 insertions, 389 deletions
diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs index 70a2cf5695..850ae7fc3b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs @@ -666,21 +666,40 @@ namespace Godot _size = new Vector3(width, height, depth); } + /// <summary> + /// Returns <see langword="true"/> if the AABBs are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left AABB.</param> + /// <param name="right">The right AABB.</param> + /// <returns>Whether or not the AABBs are exactly equal.</returns> public static bool operator ==(AABB left, AABB right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the AABBs are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left AABB.</param> + /// <param name="right">The right AABB.</param> + /// <returns>Whether or not the AABBs are not equal.</returns> public static bool operator !=(AABB left, AABB right) { return !left.Equals(right); } /// <summary> - /// Returns <see langword="true"/> if this AABB and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the AABB is exactly equal + /// to the given object (<see paramref="obj"/>). + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the AABB structure and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the AABB and the object are equal.</returns> public override bool Equals(object obj) { if (obj is AABB) @@ -692,10 +711,12 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this AABB and <paramref name="other"/> are equal + /// Returns <see langword="true"/> if the AABBs are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="other">The other AABB to compare.</param> - /// <returns>Whether or not the AABBs are equal.</returns> + /// <param name="other">The other AABB.</param> + /// <returns>Whether or not the AABBs are exactly equal.</returns> public bool Equals(AABB other) { return _position == other._position && _size == other._size; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index 0fb1df6c2f..37bdc42c2d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -209,27 +209,6 @@ namespace Godot } } - /// <summary> - /// Returns the <see cref="Basis"/>'s rotation in the form of a - /// <see cref="Quaternion"/>. See <see cref="GetEuler"/> if you - /// need Euler angles, but keep in mind quaternions should generally - /// be preferred to Euler angles. - /// </summary> - /// <returns>The basis rotation.</returns> - public Quaternion GetRotationQuaternion() - { - Basis orthonormalizedBasis = Orthonormalized(); - real_t det = orthonormalizedBasis.Determinant(); - if (det < 0) - { - // Ensure that the determinant is 1, such that result is a proper - // rotation matrix which can be represented by Euler angles. - orthonormalizedBasis = orthonormalizedBasis.Scaled(-Vector3.One); - } - - return orthonormalizedBasis.Quaternion(); - } - internal void SetQuaternionScale(Quaternion quaternion, Vector3 scale) { SetDiagonal(scale); @@ -272,8 +251,8 @@ namespace Godot /// The returned vector contains the rotation angles in /// the format (X angle, Y angle, Z angle). /// - /// Consider using the <see cref="Quaternion()"/> method instead, which - /// returns a <see cref="Godot.Quaternion"/> quaternion instead of Euler angles. + /// Consider using the <see cref="GetRotationQuaternion"/> method instead, which + /// returns a <see cref="Quaternion"/> quaternion instead of Euler angles. /// </summary> /// <returns>A <see cref="Vector3"/> representing the basis rotation in Euler angles.</returns> public Vector3 GetEuler() @@ -309,6 +288,85 @@ namespace Godot } /// <summary> + /// Returns the basis's rotation in the form of a quaternion. + /// See <see cref="GetEuler()"/> if you need Euler angles, but keep in + /// mind that quaternions should generally be preferred to Euler angles. + /// </summary> + /// <returns>A <see cref="Quaternion"/> representing the basis's rotation.</returns> + internal Quaternion GetQuaternion() + { + real_t trace = Row0[0] + Row1[1] + Row2[2]; + + if (trace > 0.0f) + { + real_t s = Mathf.Sqrt(trace + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + (Row2[1] - Row1[2]) * inv_s, + (Row0[2] - Row2[0]) * inv_s, + (Row1[0] - Row0[1]) * inv_s, + s * 0.25f + ); + } + + if (Row0[0] > Row1[1] && Row0[0] > Row2[2]) + { + real_t s = Mathf.Sqrt(Row0[0] - Row1[1] - Row2[2] + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + s * 0.25f, + (Row0[1] + Row1[0]) * inv_s, + (Row0[2] + Row2[0]) * inv_s, + (Row2[1] - Row1[2]) * inv_s + ); + } + + if (Row1[1] > Row2[2]) + { + real_t s = Mathf.Sqrt(-Row0[0] + Row1[1] - Row2[2] + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + (Row0[1] + Row1[0]) * inv_s, + s * 0.25f, + (Row1[2] + Row2[1]) * inv_s, + (Row0[2] - Row2[0]) * inv_s + ); + } + else + { + real_t s = Mathf.Sqrt(-Row0[0] - Row1[1] + Row2[2] + 1.0f) * 2f; + real_t inv_s = 1f / s; + return new Quaternion( + (Row0[2] + Row2[0]) * inv_s, + (Row1[2] + Row2[1]) * inv_s, + s * 0.25f, + (Row1[0] - Row0[1]) * inv_s + ); + } + } + + /// <summary> + /// Returns the <see cref="Basis"/>'s rotation in the form of a + /// <see cref="Quaternion"/>. See <see cref="GetEuler"/> if you + /// need Euler angles, but keep in mind quaternions should generally + /// be preferred to Euler angles. + /// </summary> + /// <returns>The basis rotation.</returns> + public Quaternion GetRotationQuaternion() + { + Basis orthonormalizedBasis = Orthonormalized(); + real_t det = orthonormalizedBasis.Determinant(); + if (det < 0) + { + // Ensure that the determinant is 1, such that result is a proper + // rotation matrix which can be represented by Euler angles. + orthonormalizedBasis = orthonormalizedBasis.Scaled(-Vector3.One); + } + + return orthonormalizedBasis.GetQuaternion(); + } + + /// <summary> /// Get rows by index. Rows are not very useful for user code, /// but are more efficient for some internal calculations. /// </summary> @@ -468,10 +526,10 @@ namespace Godot /// <summary> /// Introduce an additional rotation around the given <paramref name="axis"/> - /// by <paramref name="phi"/> (in radians). The axis must be a normalized vector. + /// by <paramref name="angle"/> (in radians). The axis must be a normalized vector. /// </summary> /// <param name="axis">The axis to rotate around. Must be normalized.</param> - /// <param name="phi">The angle to rotate, in radians.</param> + /// <param name="angle">The angle to rotate, in radians.</param> /// <returns>The rotated basis matrix.</returns> public Basis Rotated(Vector3 axis, real_t phi) { @@ -600,64 +658,6 @@ namespace Godot ); } - /// <summary> - /// Returns the basis's rotation in the form of a quaternion. - /// See <see cref="GetEuler()"/> if you need Euler angles, but keep in - /// mind that quaternions should generally be preferred to Euler angles. - /// </summary> - /// <returns>A <see cref="Godot.Quaternion"/> representing the basis's rotation.</returns> - public Quaternion Quaternion() - { - real_t trace = Row0[0] + Row1[1] + Row2[2]; - - if (trace > 0.0f) - { - real_t s = Mathf.Sqrt(trace + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - (Row2[1] - Row1[2]) * inv_s, - (Row0[2] - Row2[0]) * inv_s, - (Row1[0] - Row0[1]) * inv_s, - s * 0.25f - ); - } - - if (Row0[0] > Row1[1] && Row0[0] > Row2[2]) - { - real_t s = Mathf.Sqrt(Row0[0] - Row1[1] - Row2[2] + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - s * 0.25f, - (Row0[1] + Row1[0]) * inv_s, - (Row0[2] + Row2[0]) * inv_s, - (Row2[1] - Row1[2]) * inv_s - ); - } - - if (Row1[1] > Row2[2]) - { - real_t s = Mathf.Sqrt(-Row0[0] + Row1[1] - Row2[2] + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - (Row0[1] + Row1[0]) * inv_s, - s * 0.25f, - (Row1[2] + Row2[1]) * inv_s, - (Row0[2] - Row2[0]) * inv_s - ); - } - else - { - real_t s = Mathf.Sqrt(-Row0[0] - Row1[1] + Row2[2] + 1.0f) * 2f; - real_t inv_s = 1f / s; - return new Quaternion( - (Row0[2] + Row2[0]) * inv_s, - (Row1[2] + Row2[1]) * inv_s, - s * 0.25f, - (Row1[0] - Row0[1]) * inv_s - ); - } - } - private static readonly Basis[] _orthoBases = { new Basis(1f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 1f), new Basis(0f, -1f, 0f, 1f, 0f, 0f, 0f, 0f, 1f), @@ -745,7 +745,7 @@ namespace Godot /// given in the vector format as (X angle, Y angle, Z angle). /// /// Consider using the <see cref="Basis(Quaternion)"/> constructor instead, which - /// uses a <see cref="Godot.Quaternion"/> quaternion instead of Euler angles. + /// uses a <see cref="Quaternion"/> quaternion instead of Euler angles. /// </summary> /// <param name="eulerYXZ">The Euler angles to create the basis from.</param> public Basis(Vector3 eulerYXZ) @@ -770,10 +770,10 @@ namespace Godot /// <summary> /// Constructs a pure rotation basis matrix, rotated around the given <paramref name="axis"/> - /// by <paramref name="phi"/> (in radians). The axis must be a normalized vector. + /// by <paramref name="angle"/> (in radians). The axis must be a normalized vector. /// </summary> /// <param name="axis">The axis to rotate around. Must be normalized.</param> - /// <param name="phi">The angle to rotate, in radians.</param> + /// <param name="angle">The angle to rotate, in radians.</param> public Basis(Vector3 axis, real_t phi) { Vector3 axisSq = new Vector3(axis.x * axis.x, axis.y * axis.y, axis.z * axis.z); @@ -827,6 +827,14 @@ namespace Godot Row2 = new Vector3(xz, yz, zz); } + /// <summary> + /// Composes these two basis matrices by multiplying them + /// together. This has the effect of transforming the second basis + /// (the child) by the first basis (the parent). + /// </summary> + /// <param name="left">The parent basis.</param> + /// <param name="right">The child basis.</param> + /// <returns>The composed basis.</returns> public static Basis operator *(Basis left, Basis right) { return new Basis @@ -837,21 +845,40 @@ namespace Godot ); } + /// <summary> + /// Returns <see langword="true"/> if the basis matrices are exactly + /// equal. Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left basis.</param> + /// <param name="right">The right basis.</param> + /// <returns>Whether or not the basis matrices are exactly equal.</returns> public static bool operator ==(Basis left, Basis right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the basis matrices are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left basis.</param> + /// <param name="right">The right basis.</param> + /// <returns>Whether or not the basis matrices are not equal.</returns> public static bool operator !=(Basis left, Basis right) { return !left.Equals(right); } /// <summary> - /// Returns <see langword="true"/> if this basis and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the <see cref="Basis"/> is + /// exactly equal to the given object (<see paramref="obj"/>). + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the basis and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the basis matrix and the object are exactly equal.</returns> public override bool Equals(object obj) { if (obj is Basis) @@ -863,10 +890,12 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this basis and <paramref name="other"/> are equal + /// Returns <see langword="true"/> if the basis matrices are exactly + /// equal. Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="other">The other basis to compare.</param> - /// <returns>Whether or not the bases are equal.</returns> + /// <param name="other">The other basis.</param> + /// <returns>Whether or not the basis matrices are exactly equal.</returns> public bool Equals(Basis other) { return Row0.Equals(other.Row0) && Row1.Equals(other.Row1) && Row2.Equals(other.Row2); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 2a869bc335..fc9d40ca48 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -878,6 +878,13 @@ namespace Godot return true; } + /// <summary> + /// Adds each component of the <see cref="Color"/> + /// with the components of the given <see cref="Color"/>. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>The added color.</returns> public static Color operator +(Color left, Color right) { left.r += right.r; @@ -887,6 +894,13 @@ namespace Godot return left; } + /// <summary> + /// Subtracts each component of the <see cref="Color"/> + /// by the components of the given <see cref="Color"/>. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>The subtracted color.</returns> public static Color operator -(Color left, Color right) { left.r -= right.r; @@ -896,11 +910,25 @@ namespace Godot return left; } + /// <summary> + /// Inverts the given color. This is equivalent to + /// <c>Colors.White - c</c> or + /// <c>new Color(1 - c.r, 1 - c.g, 1 - c.b, 1 - c.a)</c>. + /// </summary> + /// <param name="color">The color to invert.</param> + /// <returns>The inverted color</returns> public static Color operator -(Color color) { return Colors.White - color; } + /// <summary> + /// Multiplies each component of the <see cref="Color"/> + /// by the given <see langword="float"/>. + /// </summary> + /// <param name="color">The color to multiply.</param> + /// <param name="scale">The value to multiply by.</param> + /// <returns>The multiplied color.</returns> public static Color operator *(Color color, float scale) { color.r *= scale; @@ -910,6 +938,13 @@ namespace Godot return color; } + /// <summary> + /// Multiplies each component of the <see cref="Color"/> + /// by the given <see langword="float"/>. + /// </summary> + /// <param name="scale">The value to multiply by.</param> + /// <param name="color">The color to multiply.</param> + /// <returns>The multiplied color.</returns> public static Color operator *(float scale, Color color) { color.r *= scale; @@ -919,6 +954,13 @@ namespace Godot return color; } + /// <summary> + /// Multiplies each component of the <see cref="Color"/> + /// by the components of the given <see cref="Color"/>. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>The multiplied color.</returns> public static Color operator *(Color left, Color right) { left.r *= right.r; @@ -928,6 +970,13 @@ namespace Godot return left; } + /// <summary> + /// Divides each component of the <see cref="Color"/> + /// by the given <see langword="float"/>. + /// </summary> + /// <param name="color">The dividend vector.</param> + /// <param name="scale">The divisor value.</param> + /// <returns>The divided color.</returns> public static Color operator /(Color color, float scale) { color.r /= scale; @@ -937,6 +986,13 @@ namespace Godot return color; } + /// <summary> + /// Divides each component of the <see cref="Color"/> + /// by the components of the given <see cref="Color"/>. + /// </summary> + /// <param name="left">The dividend color.</param> + /// <param name="right">The divisor color.</param> + /// <returns>The divided color.</returns> public static Color operator /(Color left, Color right) { left.r /= right.r; @@ -946,23 +1002,51 @@ namespace Godot return left; } + /// <summary> + /// Returns <see langword="true"/> if the colors are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>Whether or not the colors are equal.</returns> public static bool operator ==(Color left, Color right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the colors are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>Whether or not the colors are equal.</returns> public static bool operator !=(Color left, Color right) { return !left.Equals(right); } + /// <summary> + /// Compares two <see cref="Color"/>s by first checking if + /// the red value of the <paramref name="left"/> color is less than + /// the red value of the <paramref name="right"/> color. + /// If the red values are exactly equal, then it repeats this check + /// with the green values of the two colors, then with the blue values, + /// and then with the alpha value. + /// This operator is useful for sorting colors. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>Whether or not the left is less than the right.</returns> public static bool operator <(Color left, Color right) { - if (Mathf.IsEqualApprox(left.r, right.r)) + if (left.r == right.r) { - if (Mathf.IsEqualApprox(left.g, right.g)) + if (left.g == right.g) { - if (Mathf.IsEqualApprox(left.b, right.b)) + if (left.b == right.b) { return left.a < right.a; } @@ -973,13 +1057,25 @@ namespace Godot return left.r < right.r; } + /// <summary> + /// Compares two <see cref="Color"/>s by first checking if + /// the red value of the <paramref name="left"/> color is greater than + /// the red value of the <paramref name="right"/> color. + /// If the red values are exactly equal, then it repeats this check + /// with the green values of the two colors, then with the blue values, + /// and then with the alpha value. + /// This operator is useful for sorting colors. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>Whether or not the left is greater than the right.</returns> public static bool operator >(Color left, Color right) { - if (Mathf.IsEqualApprox(left.r, right.r)) + if (left.r == right.r) { - if (Mathf.IsEqualApprox(left.g, right.g)) + if (left.g == right.g) { - if (Mathf.IsEqualApprox(left.b, right.b)) + if (left.b == right.b) { return left.a > right.a; } @@ -991,6 +1087,64 @@ namespace Godot } /// <summary> + /// Compares two <see cref="Color"/>s by first checking if + /// the red value of the <paramref name="left"/> color is less than + /// or equal to the red value of the <paramref name="right"/> color. + /// If the red values are exactly equal, then it repeats this check + /// with the green values of the two colors, then with the blue values, + /// and then with the alpha value. + /// This operator is useful for sorting colors. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>Whether or not the left is less than or equal to the right.</returns> + public static bool operator <=(Color left, Color right) + { + if (left.r == right.r) + { + if (left.g == right.g) + { + if (left.b == right.b) + { + return left.a <= right.a; + } + return left.b < right.b; + } + return left.g < right.g; + } + return left.r < right.r; + } + + /// <summary> + /// Compares two <see cref="Color"/>s by first checking if + /// the red value of the <paramref name="left"/> color is greater than + /// or equal to the red value of the <paramref name="right"/> color. + /// If the red values are exactly equal, then it repeats this check + /// with the green values of the two colors, then with the blue values, + /// and then with the alpha value. + /// This operator is useful for sorting colors. + /// </summary> + /// <param name="left">The left color.</param> + /// <param name="right">The right color.</param> + /// <returns>Whether or not the left is greater than or equal to the right.</returns> + public static bool operator >=(Color left, Color right) + { + if (left.r == right.r) + { + if (left.g == right.g) + { + if (left.b == right.b) + { + return left.a >= right.a; + } + return left.b > right.b; + } + return left.g > right.g; + } + return left.r > right.r; + } + + /// <summary> /// Returns <see langword="true"/> if this color and <paramref name="obj"/> are equal. /// </summary> /// <param name="obj">The other object to compare.</param> @@ -1006,9 +1160,11 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this color and <paramref name="other"/> are equal + /// Returns <see langword="true"/> if the colors are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="other">The other color to compare.</param> + /// <param name="other">The other color.</param> /// <returns>Whether or not the colors are equal.</returns> public bool Equals(Color other) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs index d64c8b563e..68c821b447 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs @@ -158,6 +158,7 @@ namespace Godot {"YELLOWGREEN", new Color(0.60f, 0.80f, 0.20f)}, }; +#pragma warning disable CS1591 // Disable warning: "Missing XML comment for publicly visible type or member" public static Color AliceBlue { get { return namedColors["ALICEBLUE"]; } } public static Color AntiqueWhite { get { return namedColors["ANTIQUEWHITE"]; } } public static Color Aqua { get { return namedColors["AQUA"]; } } @@ -304,5 +305,6 @@ namespace Godot public static Color WhiteSmoke { get { return namedColors["WHITESMOKE"]; } } public static Color Yellow { get { return namedColors["YELLOW"]; } } public static Color YellowGreen { get { return namedColors["YELLOWGREEN"]; } } +#pragma warning restore CS1591 } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs index 2dfe304aaa..e80b6af68f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Dictionary.cs @@ -314,13 +314,16 @@ namespace Godot.Collections internal static extern int godot_icall_Dictionary_Count(IntPtr ptr); [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static int godot_icall_Dictionary_KeyValuePairs(IntPtr ptr, out IntPtr keys, out IntPtr values); + internal static extern int godot_icall_Dictionary_KeyValuePairs(IntPtr ptr, out IntPtr keys, out IntPtr values); [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static void godot_icall_Dictionary_KeyValuePairAt(IntPtr ptr, int index, out object key, out object value); + internal static extern void godot_icall_Dictionary_KeyValuePairAt(IntPtr ptr, int index, out object key, out object value); [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static void godot_icall_Dictionary_Add(IntPtr ptr, object key, object value); + internal static extern void godot_icall_Dictionary_KeyValuePairAt_Generic(IntPtr ptr, int index, out object key, out object value, int valueTypeEncoding, IntPtr valueTypeClass); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void godot_icall_Dictionary_Add(IntPtr ptr, object key, object value); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void godot_icall_Dictionary_Clear(IntPtr ptr); @@ -485,7 +488,7 @@ namespace Godot.Collections private KeyValuePair<TKey, TValue> GetKeyValuePair(int index) { - Dictionary.godot_icall_Dictionary_KeyValuePairAt(GetPtr(), index, out object key, out object value); + Dictionary.godot_icall_Dictionary_KeyValuePairAt_Generic(GetPtr(), index, out object key, out object value, valTypeEncoding, valTypeClass); return new KeyValuePair<TKey, TValue>((TKey)key, (TValue)value); } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs index ef42374041..74aa38386f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs @@ -127,7 +127,7 @@ namespace Godot /// </code> /// </example> /// <param name="linear">The linear energy to convert.</param> - /// <returns>Audio as decibels</returns> + /// <returns>Audio as decibels.</returns> public static real_t Linear2Db(real_t linear) { return (real_t)(Math.Log(linear) * 8.6858896380650365530225783783321); @@ -323,6 +323,16 @@ namespace Godot } /// <summary> + /// Returns a normally-distributed pseudo-random number, using Box-Muller transform with the specified <c>mean</c> and a standard <c>deviation</c>. + /// This is also called Gaussian distribution. + /// </summary> + /// <returns>A random normally-distributed <see langword="float"/> number.</returns> + public static double Randfn(double mean, double deviation) + { + return godot_icall_GD_randfn(mean, deviation); + } + + /// <summary> /// Returns a random unsigned 32-bit integer. /// Use remainder to obtain a random value in the interval <c>[0, N - 1]</c> (where N is smaller than 2^32). /// </summary> @@ -390,7 +400,7 @@ namespace Godot /// </summary> /// <param name="seed"> /// Seed to use to generate the random number. - /// If a different seed is used, its value will be modfied. + /// If a different seed is used, its value will be modified. /// </param> /// <returns>A random <see langword="uint"/> number.</returns> public static uint RandFromSeed(ref ulong seed) @@ -564,19 +574,22 @@ namespace Godot internal static extern void godot_icall_GD_printt(object[] what); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern float godot_icall_GD_randf(); + internal static extern void godot_icall_GD_randomize(); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern uint godot_icall_GD_randi(); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern void godot_icall_GD_randomize(); + internal static extern float godot_icall_GD_randf(); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern int godot_icall_GD_randi_range(int from, int to); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern double godot_icall_GD_randf_range(double from, double to); [MethodImpl(MethodImplOptions.InternalCall)] - internal static extern int godot_icall_GD_randi_range(int from, int to); + internal static extern double godot_icall_GD_randfn(double mean, double deviation); [MethodImpl(MethodImplOptions.InternalCall)] internal static extern uint godot_icall_GD_rand_seed(ulong seed, out ulong newSeed); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/MarshalUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/MarshalUtils.cs index 3051bcedc7..ee4d0eed08 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/MarshalUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/MarshalUtils.cs @@ -80,6 +80,18 @@ namespace Godot private static bool TypeIsGenericIDictionary(Type type) => type.GetGenericTypeDefinition() == typeof(IDictionary<,>); /// <summary> + /// Returns the generic type definition of <paramref name="type"/>. + /// </summary> + /// <exception cref="InvalidOperationException"> + /// Thrown when the given <paramref name="type"/> is not a generic type. + /// That is, <see cref="Type.IsGenericType"/> returns <see langword="false"/>. + /// </exception> + private static void GetGenericTypeDefinition(Type type, out Type genericTypeDefinition) + { + genericTypeDefinition = type.GetGenericTypeDefinition(); + } + + /// <summary> /// Gets the element type for the given <paramref name="arrayType"/>. /// </summary> /// <param name="arrayType">Type for the generic array.</param> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs index 6f7fac7429..ce213da6a7 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs @@ -180,6 +180,24 @@ namespace Godot } /// <summary> + /// Cubic interpolates between two values by a normalized value with pre and post values. + /// </summary> + /// <param name="from">The start value for interpolation.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="pre">The value which before "from" value for interpolation.</param> + /// <param name="post">The value which after "to" value for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting value of the interpolation.</returns> + public static real_t CubicInterpolate(real_t from, real_t to, real_t pre, real_t post, real_t weight) + { + return 0.5f * + ((from * 2.0f) + + (-pre + to) * weight + + (2.0f * pre - 5.0f * from + 4.0f * to - post) * (weight * weight) + + (-pre + 3.0f * from - 3.0f * to + post) * (weight * weight * weight)); + } + + /// <summary> /// Converts an angle expressed in degrees to radians. /// </summary> /// <param name="deg">An angle expressed in degrees.</param> @@ -624,7 +642,7 @@ namespace Godot /// </summary> /// <param name="s">The value to snap.</param> /// <param name="step">The step size to snap to.</param> - /// <returns></returns> + /// <returns>The snapped value.</returns> public static real_t Snapped(real_t s, real_t step) { if (step != 0f) @@ -693,5 +711,23 @@ namespace Godot } return min + ((((value - min) % range) + range) % range); } + + private static real_t Fract(real_t value) + { + return value - (real_t)Math.Floor(value); + } + + /// <summary> + /// Returns the [code]value[/code] wrapped between [code]0[/code] and the [code]length[/code]. + /// If the limit is reached, the next value the function returned is decreased to the [code]0[/code] side or increased to the [code]length[/code] side (like a triangle wave). + /// If [code]length[/code] is less than zero, it becomes positive. + /// </summary> + /// <param name="value">The value to pingpong.</param> + /// <param name="length">The maximum value of the function.</param> + /// <returns>The ping-ponged value.</returns> + public static real_t PingPong(real_t value, real_t length) + { + return (length != (real_t)0.0) ? Abs(Fract((value - length) / (length * (real_t)2.0)) * length * (real_t)2.0 - length) : (real_t)0.0; + } } } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs index 9bb73ce7dd..f15d01b34b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs @@ -44,7 +44,7 @@ namespace Godot /// <summary> /// Returns the amount of digits after the decimal place. /// </summary> - /// <param name="s">The input <see cref="decimal"/> value.</param> + /// <param name="s">The input <see langword="decimal"/> value.</param> /// <returns>The amount of digits.</returns> public static int DecimalCount(decimal s) { @@ -54,7 +54,7 @@ namespace Godot /// <summary> /// Rounds <paramref name="s"/> upward (towards positive infinity). /// - /// This is the same as <see cref="Ceil(real_t)"/>, but returns an <c>int</c>. + /// This is the same as <see cref="Ceil(real_t)"/>, but returns an <see langword="int"/>. /// </summary> /// <param name="s">The number to ceil.</param> /// <returns>The smallest whole number that is not less than <paramref name="s"/>.</returns> @@ -66,7 +66,7 @@ namespace Godot /// <summary> /// Rounds <paramref name="s"/> downward (towards negative infinity). /// - /// This is the same as <see cref="Floor(real_t)"/>, but returns an <c>int</c>. + /// This is the same as <see cref="Floor(real_t)"/>, but returns an <see langword="int"/>. /// </summary> /// <param name="s">The number to floor.</param> /// <returns>The largest whole number that is not more than <paramref name="s"/>.</returns> @@ -78,7 +78,7 @@ namespace Godot /// <summary> /// Rounds <paramref name="s"/> to the nearest whole number. /// - /// This is the same as <see cref="Round(real_t)"/>, but returns an <c>int</c>. + /// This is the same as <see cref="Round(real_t)"/>, but returns an <see langword="int"/>. /// </summary> /// <param name="s">The number to round.</param> /// <returns>The rounded number.</returns> diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs index f53b5dc904..40fb5f8788 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NodePath.cs @@ -122,7 +122,7 @@ namespace Godot /// "/root/Level/Path2D" /// </code> /// </example> - /// <param name="path"></param> + /// <param name="path">A string that represents a path in a scene tree.</param> public NodePath(string path) { ptr = godot_icall_NodePath_Ctor(path); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs index 66f7b745f7..63af1c5892 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs @@ -309,16 +309,43 @@ namespace Godot D = _normal.Dot(v1); } + /// <summary> + /// Returns the negative value of the <see cref="Plane"/>. + /// This is the same as writing <c>new Plane(-p.Normal, -p.D)</c>. + /// This operation flips the direction of the normal vector and + /// also flips the distance value, resulting in a Plane that is + /// in the same place, but facing the opposite direction. + /// </summary> + /// <param name="plane">The plane to negate/flip.</param> + /// <returns>The negated/flipped plane.</returns> public static Plane operator -(Plane plane) { return new Plane(-plane._normal, -plane.D); } + /// <summary> + /// Returns <see langword="true"/> if the + /// <see cref="Plane"/>s are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left rect.</param> + /// <param name="right">The right rect.</param> + /// <returns>Whether or not the planes are exactly equal.</returns> public static bool operator ==(Plane left, Plane right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the + /// <see cref="Plane"/>s are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left rect.</param> + /// <param name="right">The right rect.</param> + /// <returns>Whether or not the planes are not equal.</returns> public static bool operator !=(Plane left, Plane right) { return !left.Equals(right); @@ -328,7 +355,7 @@ namespace Godot /// Returns <see langword="true"/> if this plane and <paramref name="obj"/> are equal. /// </summary> /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the plane and the other object are equal.</returns> + /// <returns>Whether or not the plane and the other object are exactly equal.</returns> public override bool Equals(object obj) { if (obj is Plane) @@ -343,7 +370,7 @@ namespace Godot /// Returns <see langword="true"/> if this plane and <paramref name="other"/> are equal. /// </summary> /// <param name="other">The other plane to compare.</param> - /// <returns>Whether or not the planes are equal.</returns> + /// <returns>Whether or not the planes are exactly equal.</returns> public bool Equals(Plane other) { return _normal == other._normal && D == other.D; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs index c18f818ed2..e38dca414f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quaternion.cs @@ -377,7 +377,7 @@ namespace Godot /// <param name="basis">The <see cref="Basis"/> to construct from.</param> public Quaternion(Basis basis) { - this = basis.Quaternion(); + this = basis.GetQuaternion(); } /// <summary> @@ -446,6 +446,14 @@ namespace Godot } } + /// <summary> + /// Composes these two quaternions by multiplying them together. + /// This has the effect of rotating the second quaternion + /// (the child) by the first quaternion (the parent). + /// </summary> + /// <param name="left">The parent quaternion.</param> + /// <param name="right">The child quaternion.</param> + /// <returns>The composed quaternion.</returns> public static Quaternion operator *(Quaternion left, Quaternion right) { return new Quaternion @@ -457,21 +465,55 @@ namespace Godot ); } + /// <summary> + /// Adds each component of the left <see cref="Quaternion"/> + /// to the right <see cref="Quaternion"/>. This operation is not + /// meaningful on its own, but it can be used as a part of a + /// larger expression, such as approximating an intermediate + /// rotation between two nearby rotations. + /// </summary> + /// <param name="left">The left quaternion to add.</param> + /// <param name="right">The right quaternion to add.</param> + /// <returns>The added quaternion.</returns> public static Quaternion operator +(Quaternion left, Quaternion right) { return new Quaternion(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); } + /// <summary> + /// Subtracts each component of the left <see cref="Quaternion"/> + /// by the right <see cref="Quaternion"/>. This operation is not + /// meaningful on its own, but it can be used as a part of a + /// larger expression. + /// </summary> + /// <param name="left">The left quaternion to subtract.</param> + /// <param name="right">The right quaternion to subtract.</param> + /// <returns>The subtracted quaternion.</returns> public static Quaternion operator -(Quaternion left, Quaternion right) { return new Quaternion(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); } - public static Quaternion operator -(Quaternion left) + /// <summary> + /// Returns the negative value of the <see cref="Quaternion"/>. + /// This is the same as writing + /// <c>new Quaternion(-q.x, -q.y, -q.z, -q.w)</c>. This operation + /// results in a quaternion that represents the same rotation. + /// </summary> + /// <param name="quat">The quaternion to negate.</param> + /// <returns>The negated quaternion.</returns> + public static Quaternion operator -(Quaternion quat) { - return new Quaternion(-left.x, -left.y, -left.z, -left.w); + return new Quaternion(-quat.x, -quat.y, -quat.z, -quat.w); } + /// <summary> + /// Rotates (multiplies) the <see cref="Vector3"/> + /// by the given <see cref="Quaternion"/>. + /// </summary> + /// <param name="quat">The quaternion to rotate by.</param> + /// <param name="vec">The vector to rotate.</param> + /// <returns>The rotated vector.</returns> public static Vector3 operator *(Quaternion quat, Vector3 vec) { #if DEBUG @@ -485,31 +527,81 @@ namespace Godot return vec + (((uv * quat.w) + u.Cross(uv)) * 2); } + /// <summary> + /// Inversely rotates (multiplies) the <see cref="Vector3"/> + /// by the given <see cref="Quaternion"/>. + /// </summary> + /// <param name="vec">The vector to rotate.</param> + /// <param name="quat">The quaternion to rotate by.</param> + /// <returns>The inversely rotated vector.</returns> public static Vector3 operator *(Vector3 vec, Quaternion quat) { return quat.Inverse() * vec; } + /// <summary> + /// Multiplies each component of the <see cref="Quaternion"/> + /// by the given <see cref="real_t"/>. This operation is not + /// meaningful on its own, but it can be used as a part of a + /// larger expression. + /// </summary> + /// <param name="left">The quaternion to multiply.</param> + /// <param name="right">The value to multiply by.</param> + /// <returns>The multiplied quaternion.</returns> public static Quaternion operator *(Quaternion left, real_t right) { return new Quaternion(left.x * right, left.y * right, left.z * right, left.w * right); } + /// <summary> + /// Multiplies each component of the <see cref="Quaternion"/> + /// by the given <see cref="real_t"/>. This operation is not + /// meaningful on its own, but it can be used as a part of a + /// larger expression. + /// </summary> + /// <param name="left">The value to multiply by.</param> + /// <param name="right">The quaternion to multiply.</param> + /// <returns>The multiplied quaternion.</returns> public static Quaternion operator *(real_t left, Quaternion right) { return new Quaternion(right.x * left, right.y * left, right.z * left, right.w * left); } + /// <summary> + /// Divides each component of the <see cref="Quaternion"/> + /// by the given <see cref="real_t"/>. This operation is not + /// meaningful on its own, but it can be used as a part of a + /// larger expression. + /// </summary> + /// <param name="left">The quaternion to divide.</param> + /// <param name="right">The value to divide by.</param> + /// <returns>The divided quaternion.</returns> public static Quaternion operator /(Quaternion left, real_t right) { return left * (1.0f / right); } + /// <summary> + /// Returns <see langword="true"/> if the quaternions are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left quaternion.</param> + /// <param name="right">The right quaternion.</param> + /// <returns>Whether or not the quaternions are exactly equal.</returns> public static bool operator ==(Quaternion left, Quaternion right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the quaternions are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left quaternion.</param> + /// <param name="right">The right quaternion.</param> + /// <returns>Whether or not the quaternions are not equal.</returns> public static bool operator !=(Quaternion left, Quaternion right) { return !left.Equals(right); @@ -519,7 +611,7 @@ namespace Godot /// Returns <see langword="true"/> if this quaternion and <paramref name="obj"/> are equal. /// </summary> /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the quaternion and the other object are equal.</returns> + /// <returns>Whether or not the quaternion and the other object are exactly equal.</returns> public override bool Equals(object obj) { if (obj is Quaternion) @@ -534,7 +626,7 @@ namespace Godot /// Returns <see langword="true"/> if this quaternion and <paramref name="other"/> are equal. /// </summary> /// <param name="other">The other quaternion to compare.</param> - /// <returns>Whether or not the quaternions are equal.</returns> + /// <returns>Whether or not the quaternions are exactly equal.</returns> public bool Equals(Quaternion other) { return x == other.x && y == other.y && z == other.z && w == other.w; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs index af94484577..ec16920fed 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs @@ -396,11 +396,29 @@ namespace Godot _size = new Vector2(width, height); } + /// <summary> + /// Returns <see langword="true"/> if the + /// <see cref="Rect2"/>s are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left rect.</param> + /// <param name="right">The right rect.</param> + /// <returns>Whether or not the rects are exactly equal.</returns> public static bool operator ==(Rect2 left, Rect2 right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the + /// <see cref="Rect2"/>s are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left rect.</param> + /// <param name="right">The right rect.</param> + /// <returns>Whether or not the rects are not equal.</returns> public static bool operator !=(Rect2 left, Rect2 right) { return !left.Equals(right); @@ -410,7 +428,7 @@ namespace Godot /// Returns <see langword="true"/> if this rect and <paramref name="obj"/> are equal. /// </summary> /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the rect and the other object are equal.</returns> + /// <returns>Whether or not the rect and the other object are exactly equal.</returns> public override bool Equals(object obj) { if (obj is Rect2) @@ -425,7 +443,7 @@ namespace Godot /// Returns <see langword="true"/> if this rect and <paramref name="other"/> are equal. /// </summary> /// <param name="other">The other rect to compare.</param> - /// <returns>Whether or not the rects are equal.</returns> + /// <returns>Whether or not the rects are exactly equal.</returns> public bool Equals(Rect2 other) { return _position.Equals(other._position) && _size.Equals(other._size); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs index 03f406a910..5d53b8330e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs @@ -377,11 +377,25 @@ namespace Godot _size = new Vector2i(width, height); } + /// <summary> + /// Returns <see langword="true"/> if the + /// <see cref="Rect2i"/>s are exactly equal. + /// </summary> + /// <param name="left">The left rect.</param> + /// <param name="right">The right rect.</param> + /// <returns>Whether or not the rects are equal.</returns> public static bool operator ==(Rect2i left, Rect2i right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the + /// <see cref="Rect2i"/>s are not equal. + /// </summary> + /// <param name="left">The left rect.</param> + /// <param name="right">The right rect.</param> + /// <returns>Whether or not the rects are not equal.</returns> public static bool operator !=(Rect2i left, Rect2i right) { return !left.Equals(right); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs index 6b3eb09581..a1f058ffe5 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/StringExtensions.cs @@ -266,7 +266,7 @@ namespace Godot /// <returns>The capitalized string.</returns> public static string Capitalize(this string instance) { - string aux = instance.Replace("_", " ").ToLower(); + string aux = instance.CamelcaseToUnderscore(true).Replace("_", " ").Trim(); string cap = string.Empty; for (int i = 0; i < aux.GetSliceCount(" "); i++) @@ -284,6 +284,51 @@ namespace Godot return cap; } + private static string CamelcaseToUnderscore(this string instance, bool lowerCase) + { + string newString = string.Empty; + int startIndex = 0; + + for (int i = 1; i < instance.Length; i++) + { + bool isUpper = char.IsUpper(instance[i]); + bool isNumber = char.IsDigit(instance[i]); + + bool areNext2Lower = false; + bool isNextLower = false; + bool isNextNumber = false; + bool wasPrecedentUpper = char.IsUpper(instance[i - 1]); + bool wasPrecedentNumber = char.IsDigit(instance[i - 1]); + + if (i + 2 < instance.Length) + { + areNext2Lower = char.IsLower(instance[i + 1]) && char.IsLower(instance[i + 2]); + } + + if (i + 1 < instance.Length) + { + isNextLower = char.IsLower(instance[i + 1]); + isNextNumber = char.IsDigit(instance[i + 1]); + } + + bool condA = isUpper && !wasPrecedentUpper && !wasPrecedentNumber; + bool condB = wasPrecedentUpper && isUpper && areNext2Lower; + bool condC = isNumber && !wasPrecedentNumber; + bool canBreakNumberLetter = isNumber && !wasPrecedentNumber && isNextLower; + bool canBreakLetterNumber = !isNumber && wasPrecedentNumber && (isNextLower || isNextNumber); + + bool shouldSplit = condA || condB || condC || canBreakNumberLetter || canBreakLetterNumber; + if (shouldSplit) + { + newString += instance.Substring(startIndex, i - startIndex) + "_"; + startIndex = i; + } + } + + newString += instance.Substring(startIndex, instance.Length - startIndex); + return lowerCase ? newString.ToLower() : newString; + } + /// <summary> /// Performs a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. /// </summary> @@ -415,6 +460,10 @@ namespace Godot /// <summary> /// Find the first occurrence of a substring. Optionally, the search starting position can be passed. /// </summary> + /// <seealso cref="Find(string, char, int, bool)"/> + /// <seealso cref="FindLast(string, string, bool)"/> + /// <seealso cref="FindLast(string, string, int, bool)"/> + /// <seealso cref="FindN(string, string, int)"/> /// <param name="instance">The string that will be searched.</param> /// <param name="what">The substring to find.</param> /// <param name="from">The search starting position.</param> @@ -690,7 +739,7 @@ namespace Godot /// <summary> /// Returns <see langword="true"/> if the string is a path to a file or - /// directory and its startign point is explicitly defined. This includes + /// directory and its starting point is explicitly defined. This includes /// <c>res://</c>, <c>user://</c>, <c>C:\</c>, <c>/</c>, etc. /// </summary> /// <seealso cref="IsRelativePath(string)"/> @@ -723,7 +772,7 @@ namespace Godot /// <summary> /// Check whether this string is a subsequence of the given string. /// </summary> - /// <seealso cref="IsSubsequenceOfI(string, string)"/> + /// <seealso cref="IsSubsequenceOfN(string, string)"/> /// <param name="instance">The subsequence to search.</param> /// <param name="text">The string that contains the subsequence.</param> /// <param name="caseSensitive">If <see langword="true"/>, the check is case sensitive.</param> @@ -775,7 +824,7 @@ namespace Godot /// <param name="instance">The subsequence to search.</param> /// <param name="text">The string that contains the subsequence.</param> /// <returns>If the string is a subsequence of the given string.</returns> - public static bool IsSubsequenceOfI(this string instance, string text) + public static bool IsSubsequenceOfN(this string instance, string text) { return instance.IsSubsequenceOf(text, caseSensitive: false); } @@ -1345,7 +1394,7 @@ namespace Godot } [MethodImpl(MethodImplOptions.InternalCall)] - internal extern static string godot_icall_String_simplify_path(string str); + internal static extern string godot_icall_String_simplify_path(string str); /// <summary> /// Split the string by a divisor string, return an array of the substrings. diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index c82c5f4588..89947899cb 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -23,7 +23,6 @@ namespace Godot /// <summary> /// The basis matrix's X vector (column 0). Equivalent to array index <c>[0]</c>. /// </summary> - /// <value></value> public Vector2 x; /// <summary> @@ -298,9 +297,9 @@ namespace Godot } /// <summary> - /// Rotates the transform by <paramref name="phi"/> (in radians), using matrix multiplication. + /// Rotates the transform by <paramref name="angle"/> (in radians), using matrix multiplication. /// </summary> - /// <param name="phi">The angle to rotate, in radians.</param> + /// <param name="angle">The angle to rotate, in radians.</param> /// <returns>The rotated transformation matrix.</returns> public Transform2D Rotated(real_t phi) { @@ -420,12 +419,12 @@ namespace Godot /// Constructs a transformation matrix from the given components. /// Arguments are named such that xy is equal to calling x.y /// </summary> - /// <param name="xx">The X component of the X column vector, accessed via <c>t.x.x</c> or <c>[0][0]</c></param> - /// <param name="xy">The Y component of the X column vector, accessed via <c>t.x.y</c> or <c>[0][1]</c></param> - /// <param name="yx">The X component of the Y column vector, accessed via <c>t.y.x</c> or <c>[1][0]</c></param> - /// <param name="yy">The Y component of the Y column vector, accessed via <c>t.y.y</c> or <c>[1][1]</c></param> - /// <param name="ox">The X component of the origin vector, accessed via <c>t.origin.x</c> or <c>[2][0]</c></param> - /// <param name="oy">The Y component of the origin vector, accessed via <c>t.origin.y</c> or <c>[2][1]</c></param> + /// <param name="xx">The X component of the X column vector, accessed via <c>t.x.x</c> or <c>[0][0]</c>.</param> + /// <param name="xy">The Y component of the X column vector, accessed via <c>t.x.y</c> or <c>[0][1]</c>.</param> + /// <param name="yx">The X component of the Y column vector, accessed via <c>t.y.x</c> or <c>[1][0]</c>.</param> + /// <param name="yy">The Y component of the Y column vector, accessed via <c>t.y.y</c> or <c>[1][1]</c>.</param> + /// <param name="ox">The X component of the origin vector, accessed via <c>t.origin.x</c> or <c>[2][0]</c>.</param> + /// <param name="oy">The Y component of the origin vector, accessed via <c>t.origin.y</c> or <c>[2][1]</c>.</param> public Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { x = new Vector2(xx, xy); @@ -447,6 +446,14 @@ namespace Godot this.origin = origin; } + /// <summary> + /// Composes these two transformation matrices by multiplying them + /// together. This has the effect of transforming the second transform + /// (the child) by the first transform (the parent). + /// </summary> + /// <param name="left">The parent transform.</param> + /// <param name="right">The child transform.</param> + /// <returns>The composed transform.</returns> public static Transform2D operator *(Transform2D left, Transform2D right) { left.origin = left * right.origin; @@ -554,31 +561,52 @@ namespace Godot return newArray; } + /// <summary> + /// Returns <see langword="true"/> if the transforms are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left transform.</param> + /// <param name="right">The right transform.</param> + /// <returns>Whether or not the transforms are exactly equal.</returns> public static bool operator ==(Transform2D left, Transform2D right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the transforms are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left transform.</param> + /// <param name="right">The right transform.</param> + /// <returns>Whether or not the transforms are not equal.</returns> public static bool operator !=(Transform2D left, Transform2D right) { return !left.Equals(right); } /// <summary> - /// Returns <see langword="true"/> if this transform and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the transform is exactly equal + /// to the given object (<see paramref="obj"/>). + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the transform and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the transform and the object are exactly equal.</returns> public override bool Equals(object obj) { return obj is Transform2D transform2D && Equals(transform2D); } /// <summary> - /// Returns <see langword="true"/> if this transform and <paramref name="other"/> are equal. + /// Returns <see langword="true"/> if the transforms are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> /// <param name="other">The other transform to compare.</param> - /// <returns>Whether or not the matrices are equal.</returns> + /// <returns>Whether or not the matrices are exactly equal.</returns> public bool Equals(Transform2D other) { return x.Equals(other.x) && y.Equals(other.y) && origin.Equals(other.origin); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs index 7176cd60dc..7b211b6577 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs @@ -166,7 +166,7 @@ namespace Godot /// Operations take place in global space. /// </summary> /// <param name="target">The object to look at.</param> - /// <param name="up">The relative up direction</param> + /// <param name="up">The relative up direction.</param> /// <returns>The resulting transform.</returns> public Transform3D LookingAt(Vector3 target, Vector3 up) { @@ -186,11 +186,11 @@ namespace Godot } /// <summary> - /// Rotates the transform around the given <paramref name="axis"/> by <paramref name="phi"/> (in radians), + /// Rotates the transform around the given <paramref name="axis"/> by <paramref name="angle"/> (in radians), /// using matrix multiplication. The axis must be a normalized vector. /// </summary> /// <param name="axis">The axis to rotate around. Must be normalized.</param> - /// <param name="phi">The angle to rotate, in radians.</param> + /// <param name="angle">The angle to rotate, in radians.</param> /// <returns>The rotated transformation matrix.</returns> public Transform3D Rotated(Vector3 axis, real_t phi) { @@ -352,6 +352,14 @@ namespace Godot this.origin = origin; } + /// <summary> + /// Composes these two transformation matrices by multiplying them + /// together. This has the effect of transforming the second transform + /// (the child) by the first transform (the parent). + /// </summary> + /// <param name="left">The parent transform.</param> + /// <param name="right">The child transform.</param> + /// <returns>The composed transform.</returns> public static Transform3D operator *(Transform3D left, Transform3D right) { left.origin = left.Xform(right.origin); @@ -359,21 +367,40 @@ namespace Godot return left; } + /// <summary> + /// Returns <see langword="true"/> if the transforms are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left transform.</param> + /// <param name="right">The right transform.</param> + /// <returns>Whether or not the transforms are exactly equal.</returns> public static bool operator ==(Transform3D left, Transform3D right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the transforms are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left transform.</param> + /// <param name="right">The right transform.</param> + /// <returns>Whether or not the transforms are not equal.</returns> public static bool operator !=(Transform3D left, Transform3D right) { return !left.Equals(right); } /// <summary> - /// Returns <see langword="true"/> if this transform and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the transform is exactly equal + /// to the given object (<see paramref="obj"/>). + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the transform and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the transform and the object are exactly equal.</returns> public override bool Equals(object obj) { if (obj is Transform3D) @@ -385,10 +412,12 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this transform and <paramref name="other"/> are equal. + /// Returns <see langword="true"/> if the transforms are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> /// <param name="other">The other transform to compare.</param> - /// <returns>Whether or not the matrices are equal.</returns> + /// <returns>Whether or not the matrices are exactly equal.</returns> public bool Equals(Transform3D other) { return basis.Equals(other.basis) && origin.Equals(other.origin); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index fe70d71cce..9e990ce83e 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -17,7 +17,7 @@ namespace Godot { /// <summary> /// Enumerated index values for the axes. - /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// Returned by <see cref="MaxAxisIndex"/> and <see cref="MinAxisIndex"/>. /// </summary> public enum Axis { @@ -81,6 +81,15 @@ namespace Godot } } + /// <summary> + /// Helper method for deconstruction into a tuple. + /// </summary> + public void Deconstruct(out real_t x, out real_t y) + { + x = this.x; + y = this.y; + } + internal void Normalize() { real_t lengthsq = LengthSquared(); @@ -184,13 +193,13 @@ namespace Godot } /// <summary> - /// Returns the cross product of this vector and <paramref name="b"/>. + /// Returns the cross product of this vector and <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector.</param> + /// <param name="with">The other vector.</param> /// <returns>The cross product value.</returns> - public real_t Cross(Vector2 b) + public real_t Cross(Vector2 with) { - return (x * b.y) - (y * b.x); + return (x * with.y) - (y * with.x); } /// <summary> @@ -204,31 +213,21 @@ namespace Godot /// <returns>The interpolated vector.</returns> public Vector2 CubicInterpolate(Vector2 b, Vector2 preA, Vector2 postB, real_t weight) { - Vector2 p0 = preA; - Vector2 p1 = this; - Vector2 p2 = b; - Vector2 p3 = postB; - - real_t t = weight; - real_t t2 = t * t; - real_t t3 = t2 * t; - - return 0.5f * ( - (p1 * 2.0f) + - ((-p0 + p2) * t) + - (((2.0f * p0) - (5.0f * p1) + (4 * p2) - p3) * t2) + - ((-p0 + (3.0f * p1) - (3.0f * p2) + p3) * t3) + return new Vector2 + ( + Mathf.CubicInterpolate(x, b.x, preA.x, postB.x, weight), + Mathf.CubicInterpolate(y, b.y, preA.y, postB.y, weight) ); } /// <summary> - /// Returns the normalized vector pointing from this vector to <paramref name="b"/>. + /// Returns the normalized vector pointing from this vector to <paramref name="to"/>. /// </summary> - /// <param name="b">The other vector to point towards.</param> - /// <returns>The direction from this vector to <paramref name="b"/>.</returns> - public Vector2 DirectionTo(Vector2 b) + /// <param name="to">The other vector to point towards.</param> + /// <returns>The direction from this vector to <paramref name="to"/>.</returns> + public Vector2 DirectionTo(Vector2 to) { - return new Vector2(b.x - x, b.y - y).Normalized(); + return new Vector2(to.x - x, to.y - y).Normalized(); } /// <summary> @@ -365,21 +364,21 @@ namespace Godot } /// <summary> - /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's highest value. See <see cref="Axis"/>. /// If both components are equal, this method returns <see cref="Axis.X"/>. /// </summary> - /// <returns>The index of the largest axis.</returns> - public Axis MaxAxis() + /// <returns>The index of the highest axis.</returns> + public Axis MaxAxisIndex() { return x < y ? Axis.Y : Axis.X; } /// <summary> - /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's lowest value. See <see cref="Axis"/>. /// If both components are equal, this method returns <see cref="Axis.Y"/>. /// </summary> - /// <returns>The index of the smallest axis.</returns> - public Axis MinAxis() + /// <returns>The index of the lowest axis.</returns> + public Axis MinAxisIndex() { return x < y ? Axis.X : Axis.Y; } @@ -471,9 +470,9 @@ namespace Godot } /// <summary> - /// Rotates this vector by <paramref name="phi"/> radians. + /// Rotates this vector by <paramref name="angle"/> radians. /// </summary> - /// <param name="phi">The angle to rotate by, in radians.</param> + /// <param name="angle">The angle to rotate by, in radians.</param> /// <returns>The rotated vector.</returns> public Vector2 Rotated(real_t phi) { @@ -512,24 +511,25 @@ namespace Godot /// Returns the result of the spherical linear interpolation between /// this vector and <paramref name="to"/> by amount <paramref name="weight"/>. /// - /// Note: 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 <see cref="Lerp"/>. /// </summary> - /// <param name="to">The destination vector for interpolation. Must be normalized.</param> + /// <param name="to">The destination vector for interpolation.</param> /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> /// <returns>The resulting vector of the interpolation.</returns> public Vector2 Slerp(Vector2 to, real_t weight) { -#if DEBUG - if (!IsNormalized()) - { - throw new InvalidOperationException("Vector2.Slerp: From vector is not normalized."); + real_t startLengthSquared = LengthSquared(); + real_t endLengthSquared = to.LengthSquared(); + if (startLengthSquared == 0.0 || endLengthSquared == 0.0) { + // Zero length vectors have no angle, so the best we can do is either lerp or throw an error. + return Lerp(to, weight); } - if (!to.IsNormalized()) - { - throw new InvalidOperationException($"Vector2.Slerp: `{nameof(to)}` is not normalized."); - } -#endif - return Rotated(AngleTo(to) * weight); + real_t startLength = Mathf.Sqrt(startLengthSquared); + real_t resultLength = Mathf.Lerp(startLength, Mathf.Sqrt(endLengthSquared), weight); + real_t angle = AngleTo(to); + return Rotated(angle * weight) * (resultLength / startLength); } /// <summary> @@ -642,6 +642,13 @@ namespace Godot return new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)); } + /// <summary> + /// Adds each component of the <see cref="Vector2"/> + /// with the components of the given <see cref="Vector2"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The added vector.</returns> public static Vector2 operator +(Vector2 left, Vector2 right) { left.x += right.x; @@ -649,6 +656,13 @@ namespace Godot return left; } + /// <summary> + /// Subtracts each component of the <see cref="Vector2"/> + /// by the components of the given <see cref="Vector2"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The subtracted vector.</returns> public static Vector2 operator -(Vector2 left, Vector2 right) { left.x -= right.x; @@ -656,6 +670,15 @@ namespace Godot return left; } + /// <summary> + /// Returns the negative value of the <see cref="Vector2"/>. + /// This is the same as writing <c>new Vector2(-v.x, -v.y)</c>. + /// This operation flips the direction of the vector while + /// keeping the same magnitude. + /// With floats, the number zero can be either positive or negative. + /// </summary> + /// <param name="vec">The vector to negate/flip.</param> + /// <returns>The negated/flipped vector.</returns> public static Vector2 operator -(Vector2 vec) { vec.x = -vec.x; @@ -663,6 +686,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2"/> + /// by the given <see cref="real_t"/>. + /// </summary> + /// <param name="vec">The vector to multiply.</param> + /// <param name="scale">The scale to multiply by.</param> + /// <returns>The multiplied vector.</returns> public static Vector2 operator *(Vector2 vec, real_t scale) { vec.x *= scale; @@ -670,6 +700,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2"/> + /// by the given <see cref="real_t"/>. + /// </summary> + /// <param name="scale">The scale to multiply by.</param> + /// <param name="vec">The vector to multiply.</param> + /// <returns>The multiplied vector.</returns> public static Vector2 operator *(real_t scale, Vector2 vec) { vec.x *= scale; @@ -677,6 +714,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2"/> + /// by the components of the given <see cref="Vector2"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The multiplied vector.</returns> public static Vector2 operator *(Vector2 left, Vector2 right) { left.x *= right.x; @@ -684,6 +728,13 @@ namespace Godot return left; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2"/> + /// by the given <see cref="real_t"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The divided vector.</returns> public static Vector2 operator /(Vector2 vec, real_t divisor) { vec.x /= divisor; @@ -691,6 +742,13 @@ namespace Godot return vec; } + /// <summary> + /// Divides each component of the <see cref="Vector2"/> + /// by the components of the given <see cref="Vector2"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The divided vector.</returns> public static Vector2 operator /(Vector2 vec, Vector2 divisorv) { vec.x /= divisorv.x; @@ -698,6 +756,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector2"/> + /// with the components of the given <see cref="real_t"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(real_t)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector2(10, -20) % 7); // Prints "(3, -6)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The remainder vector.</returns> public static Vector2 operator %(Vector2 vec, real_t divisor) { vec.x %= divisor; @@ -705,6 +779,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector2"/> + /// with the components of the given <see cref="Vector2"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(Vector2)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector2(10, -20) % new Vector2(7, 8)); // Prints "(3, -4)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The remainder vector.</returns> public static Vector2 operator %(Vector2 vec, Vector2 divisorv) { vec.x %= divisorv.x; @@ -712,16 +802,43 @@ namespace Godot return vec; } + /// <summary> + /// Returns <see langword="true"/> if the vectors are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are exactly equal.</returns> public static bool operator ==(Vector2 left, Vector2 right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the vectors are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are not equal.</returns> public static bool operator !=(Vector2 left, Vector2 right) { return !left.Equals(right); } + /// <summary> + /// Compares two <see cref="Vector2"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than the right.</returns> public static bool operator <(Vector2 left, Vector2 right) { if (left.x == right.x) @@ -731,6 +848,17 @@ namespace Godot return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector2"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than the right.</returns> public static bool operator >(Vector2 left, Vector2 right) { if (left.x == right.x) @@ -740,29 +868,54 @@ namespace Godot return left.x > right.x; } + /// <summary> + /// Compares two <see cref="Vector2"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// or equal to the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than or equal to the right.</returns> public static bool operator <=(Vector2 left, Vector2 right) { if (left.x == right.x) { return left.y <= right.y; } - return left.x <= right.x; + return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector2"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// or equal to the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than or equal to the right.</returns> public static bool operator >=(Vector2 left, Vector2 right) { if (left.x == right.x) { return left.y >= right.y; } - return left.x >= right.x; + return left.x > right.x; } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the vector is exactly equal + /// to the given object (<see paramref="obj"/>). + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the vector and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the vector and the object are equal.</returns> public override bool Equals(object obj) { if (obj is Vector2) @@ -773,10 +926,12 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="other"/> are equal. + /// Returns <see langword="true"/> if the vectors are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="other">The other vector to compare.</param> - /// <returns>Whether or not the vectors are equal.</returns> + /// <param name="other">The other vector.</param> + /// <returns>Whether or not the vectors are exactly equal.</returns> public bool Equals(Vector2 other) { return x == other.x && y == other.y; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs index ca4531d885..412a885daa 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs @@ -17,7 +17,7 @@ namespace Godot { /// <summary> /// Enumerated index values for the axes. - /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// Returned by <see cref="MaxAxisIndex"/> and <see cref="MinAxisIndex"/>. /// </summary> public enum Axis { @@ -82,6 +82,15 @@ namespace Godot } /// <summary> + /// Helper method for deconstruction into a tuple. + /// </summary> + public void Deconstruct(out int x, out int y) + { + x = this.x; + y = this.y; + } + + /// <summary> /// Returns a new vector with all components in absolute values (i.e. positive). /// </summary> /// <returns>A vector with <see cref="Mathf.Abs(int)"/> called on each component.</returns> @@ -149,45 +158,45 @@ namespace Godot } /// <summary> - /// Returns the cross product of this vector and <paramref name="b"/>. + /// Returns the cross product of this vector and <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector.</param> + /// <param name="with">The other vector.</param> /// <returns>The cross product vector.</returns> - public int Cross(Vector2i b) + public int Cross(Vector2i with) { - return x * b.y - y * b.x; + return x * with.y - y * with.x; } /// <summary> - /// Returns the squared distance between this vector and <paramref name="b"/>. + /// Returns the squared distance between this vector and <paramref name="to"/>. /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if /// you need to compare vectors or need the squared distance for some formula. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="to">The other vector to use.</param> /// <returns>The squared distance between the two vectors.</returns> - public int DistanceSquaredTo(Vector2i b) + public int DistanceSquaredTo(Vector2i to) { - return (b - this).LengthSquared(); + return (to - this).LengthSquared(); } /// <summary> - /// Returns the distance between this vector and <paramref name="b"/>. + /// Returns the distance between this vector and <paramref name="to"/>. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="to">The other vector to use.</param> /// <returns>The distance between the two vectors.</returns> - public real_t DistanceTo(Vector2i b) + public real_t DistanceTo(Vector2i to) { - return (b - this).Length(); + return (to - this).Length(); } /// <summary> - /// Returns the dot product of this vector and <paramref name="b"/>. + /// Returns the dot product of this vector and <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="with">The other vector to use.</param> /// <returns>The dot product of the two vectors.</returns> - public int Dot(Vector2i b) + public int Dot(Vector2i with) { - return x * b.x + y * b.y; + return x * with.x + y * with.y; } /// <summary> @@ -218,21 +227,21 @@ namespace Godot } /// <summary> - /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's highest value. See <see cref="Axis"/>. /// If both components are equal, this method returns <see cref="Axis.X"/>. /// </summary> - /// <returns>The index of the largest axis.</returns> - public Axis MaxAxis() + /// <returns>The index of the highest axis.</returns> + public Axis MaxAxisIndex() { return x < y ? Axis.Y : Axis.X; } /// <summary> - /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's lowest value. See <see cref="Axis"/>. /// If both components are equal, this method returns <see cref="Axis.Y"/>. /// </summary> - /// <returns>The index of the smallest axis.</returns> - public Axis MinAxis() + /// <returns>The index of the lowest axis.</returns> + public Axis MinAxisIndex() { return x < y ? Axis.X : Axis.Y; } @@ -366,6 +375,13 @@ namespace Godot this.y = Mathf.RoundToInt(v.y); } + /// <summary> + /// Adds each component of the <see cref="Vector2i"/> + /// with the components of the given <see cref="Vector2i"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The added vector.</returns> public static Vector2i operator +(Vector2i left, Vector2i right) { left.x += right.x; @@ -373,6 +389,13 @@ namespace Godot return left; } + /// <summary> + /// Subtracts each component of the <see cref="Vector2i"/> + /// by the components of the given <see cref="Vector2i"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The subtracted vector.</returns> public static Vector2i operator -(Vector2i left, Vector2i right) { left.x -= right.x; @@ -380,6 +403,14 @@ namespace Godot return left; } + /// <summary> + /// Returns the negative value of the <see cref="Vector2i"/>. + /// This is the same as writing <c>new Vector2i(-v.x, -v.y)</c>. + /// This operation flips the direction of the vector while + /// keeping the same magnitude. + /// </summary> + /// <param name="vec">The vector to negate/flip.</param> + /// <returns>The negated/flipped vector.</returns> public static Vector2i operator -(Vector2i vec) { vec.x = -vec.x; @@ -387,6 +418,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2i"/> + /// by the given <see langword="int"/>. + /// </summary> + /// <param name="vec">The vector to multiply.</param> + /// <param name="scale">The scale to multiply by.</param> + /// <returns>The multiplied vector.</returns> public static Vector2i operator *(Vector2i vec, int scale) { vec.x *= scale; @@ -394,6 +432,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2i"/> + /// by the given <see langword="int"/>. + /// </summary> + /// <param name="scale">The scale to multiply by.</param> + /// <param name="vec">The vector to multiply.</param> + /// <returns>The multiplied vector.</returns> public static Vector2i operator *(int scale, Vector2i vec) { vec.x *= scale; @@ -401,6 +446,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2i"/> + /// by the components of the given <see cref="Vector2i"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The multiplied vector.</returns> public static Vector2i operator *(Vector2i left, Vector2i right) { left.x *= right.x; @@ -408,6 +460,13 @@ namespace Godot return left; } + /// <summary> + /// Multiplies each component of the <see cref="Vector2i"/> + /// by the given <see langword="int"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The divided vector.</returns> public static Vector2i operator /(Vector2i vec, int divisor) { vec.x /= divisor; @@ -415,6 +474,13 @@ namespace Godot return vec; } + /// <summary> + /// Divides each component of the <see cref="Vector2i"/> + /// by the components of the given <see cref="Vector2i"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The divided vector.</returns> public static Vector2i operator /(Vector2i vec, Vector2i divisorv) { vec.x /= divisorv.x; @@ -422,6 +488,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector2i"/> + /// with the components of the given <see langword="int"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(int)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector2i(10, -20) % 7); // Prints "(3, -6)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The remainder vector.</returns> public static Vector2i operator %(Vector2i vec, int divisor) { vec.x %= divisor; @@ -429,6 +511,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector2i"/> + /// with the components of the given <see cref="Vector2i"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(Vector2i)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector2i(10, -20) % new Vector2i(7, 8)); // Prints "(3, -4)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The remainder vector.</returns> public static Vector2i operator %(Vector2i vec, Vector2i divisorv) { vec.x %= divisorv.x; @@ -436,6 +534,13 @@ namespace Godot return vec; } + /// <summary> + /// Performs a bitwise AND operation with this <see cref="Vector2i"/> + /// and the given <see langword="int"/>. + /// </summary> + /// <param name="vec">The vector to AND with.</param> + /// <param name="and">The integer to AND with.</param> + /// <returns>The result of the bitwise AND.</returns> public static Vector2i operator &(Vector2i vec, int and) { vec.x &= and; @@ -443,6 +548,13 @@ namespace Godot return vec; } + /// <summary> + /// Performs a bitwise AND operation with this <see cref="Vector2i"/> + /// and the given <see cref="Vector2i"/>. + /// </summary> + /// <param name="vec">The left vector to AND with.</param> + /// <param name="andv">The right vector to AND with.</param> + /// <returns>The result of the bitwise AND.</returns> public static Vector2i operator &(Vector2i vec, Vector2i andv) { vec.x &= andv.x; @@ -450,50 +562,106 @@ namespace Godot return vec; } + /// <summary> + /// Returns <see langword="true"/> if the vectors are equal. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are equal.</returns> public static bool operator ==(Vector2i left, Vector2i right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the vectors are not equal. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are not equal.</returns> public static bool operator !=(Vector2i left, Vector2i right) { return !left.Equals(right); } + /// <summary> + /// Compares two <see cref="Vector2i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than the right.</returns> public static bool operator <(Vector2i left, Vector2i right) { - if (left.x.Equals(right.x)) + if (left.x == right.x) { return left.y < right.y; } return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector2i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than the right.</returns> public static bool operator >(Vector2i left, Vector2i right) { - if (left.x.Equals(right.x)) + if (left.x == right.x) { return left.y > right.y; } return left.x > right.x; } + /// <summary> + /// Compares two <see cref="Vector2i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// or equal to the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than or equal to the right.</returns> public static bool operator <=(Vector2i left, Vector2i right) { - if (left.x.Equals(right.x)) + if (left.x == right.x) { return left.y <= right.y; } - return left.x <= right.x; + return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector2i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// or equal to the X value of the <paramref name="right"/> 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. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than or equal to the right.</returns> public static bool operator >=(Vector2i left, Vector2i right) { - if (left.x.Equals(right.x)) + if (left.x == right.x) { return left.y >= right.y; } - return left.x >= right.x; + return left.x > right.x; } /// <summary> @@ -515,10 +683,11 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the vector is equal + /// to the given object (<see paramref="obj"/>). /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the vector and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the vector and the object are equal.</returns> public override bool Equals(object obj) { if (obj is Vector2i) @@ -530,9 +699,9 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="other"/> are equal. + /// Returns <see langword="true"/> if the vectors are equal. /// </summary> - /// <param name="other">The other vector to compare.</param> + /// <param name="other">The other vector.</param> /// <returns>Whether or not the vectors are equal.</returns> public bool Equals(Vector2i other) { diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index 01e3a71bcb..56859da7f2 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -17,7 +17,7 @@ namespace Godot { /// <summary> /// Enumerated index values for the axes. - /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// Returned by <see cref="MaxAxisIndex"/> and <see cref="MinAxisIndex"/>. /// </summary> public enum Axis { @@ -96,6 +96,16 @@ namespace Godot } } + /// <summary> + /// Helper method for deconstruction into a tuple. + /// </summary> + public void Deconstruct(out real_t x, out real_t y, out real_t z) + { + x = this.x; + y = this.y; + z = this.z; + } + internal void Normalize() { real_t lengthsq = LengthSquared(); @@ -170,17 +180,17 @@ namespace Godot } /// <summary> - /// Returns the cross product of this vector and <paramref name="b"/>. + /// Returns the cross product of this vector and <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector.</param> + /// <param name="with">The other vector.</param> /// <returns>The cross product vector.</returns> - public Vector3 Cross(Vector3 b) + public Vector3 Cross(Vector3 with) { return new Vector3 ( - (y * b.z) - (z * b.y), - (z * b.x) - (x * b.z), - (x * b.y) - (y * b.x) + (y * with.z) - (z * with.y), + (z * with.x) - (x * with.z), + (x * with.y) - (y * with.x) ); } @@ -195,63 +205,55 @@ namespace Godot /// <returns>The interpolated vector.</returns> public Vector3 CubicInterpolate(Vector3 b, Vector3 preA, Vector3 postB, real_t weight) { - Vector3 p0 = preA; - Vector3 p1 = this; - Vector3 p2 = b; - Vector3 p3 = postB; - - real_t t = weight; - real_t t2 = t * t; - real_t t3 = t2 * t; - - return 0.5f * ( - (p1 * 2.0f) + ((-p0 + p2) * t) + - (((2.0f * p0) - (5.0f * p1) + (4f * p2) - p3) * t2) + - ((-p0 + (3.0f * p1) - (3.0f * p2) + p3) * t3) + return new Vector3 + ( + Mathf.CubicInterpolate(x, b.x, preA.x, postB.x, weight), + Mathf.CubicInterpolate(y, b.y, preA.y, postB.y, weight), + Mathf.CubicInterpolate(z, b.z, preA.z, postB.z, weight) ); } /// <summary> - /// Returns the normalized vector pointing from this vector to <paramref name="b"/>. + /// Returns the normalized vector pointing from this vector to <paramref name="to"/>. /// </summary> - /// <param name="b">The other vector to point towards.</param> - /// <returns>The direction from this vector to <paramref name="b"/>.</returns> - public Vector3 DirectionTo(Vector3 b) + /// <param name="to">The other vector to point towards.</param> + /// <returns>The direction from this vector to <paramref name="to"/>.</returns> + public Vector3 DirectionTo(Vector3 to) { - return new Vector3(b.x - x, b.y - y, b.z - z).Normalized(); + return new Vector3(to.x - x, to.y - y, to.z - z).Normalized(); } /// <summary> - /// Returns the squared distance between this vector and <paramref name="b"/>. + /// Returns the squared distance between this vector and <paramref name="to"/>. /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if /// you need to compare vectors or need the squared distance for some formula. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="to">The other vector to use.</param> /// <returns>The squared distance between the two vectors.</returns> - public real_t DistanceSquaredTo(Vector3 b) + public real_t DistanceSquaredTo(Vector3 to) { - return (b - this).LengthSquared(); + return (to - this).LengthSquared(); } /// <summary> - /// Returns the distance between this vector and <paramref name="b"/>. + /// Returns the distance between this vector and <paramref name="to"/>. /// </summary> /// <seealso cref="DistanceSquaredTo(Vector3)"/> - /// <param name="b">The other vector to use.</param> + /// <param name="to">The other vector to use.</param> /// <returns>The distance between the two vectors.</returns> - public real_t DistanceTo(Vector3 b) + public real_t DistanceTo(Vector3 to) { - return (b - this).Length(); + return (to - this).Length(); } /// <summary> - /// Returns the dot product of this vector and <paramref name="b"/>. + /// Returns the dot product of this vector and <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="with">The other vector to use.</param> /// <returns>The dot product of the two vectors.</returns> - public real_t Dot(Vector3 b) + public real_t Dot(Vector3 with) { - return (x * b.x) + (y * b.y) + (z * b.z); + return (x * with.x) + (y * with.y) + (z * with.z); } /// <summary> @@ -364,21 +366,21 @@ namespace Godot } /// <summary> - /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's highest value. See <see cref="Axis"/>. /// If all components are equal, this method returns <see cref="Axis.X"/>. /// </summary> - /// <returns>The index of the largest axis.</returns> - public Axis MaxAxis() + /// <returns>The index of the highest axis.</returns> + public Axis MaxAxisIndex() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } /// <summary> - /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's lowest value. See <see cref="Axis"/>. /// If all components are equal, this method returns <see cref="Axis.Z"/>. /// </summary> - /// <returns>The index of the smallest axis.</returns> - public Axis MinAxis() + /// <returns>The index of the lowest axis.</returns> + public Axis MinAxisIndex() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } @@ -412,16 +414,16 @@ namespace Godot } /// <summary> - /// Returns the outer product with <paramref name="b"/>. + /// Returns the outer product with <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector.</param> + /// <param name="with">The other vector.</param> /// <returns>A <see cref="Basis"/> representing the outer product matrix.</returns> - public Basis Outer(Vector3 b) + public Basis Outer(Vector3 with) { return new Basis( - x * b.x, x * b.y, x * b.z, - y * b.x, y * b.y, y * b.z, - z * b.x, z * b.y, z * b.z + x * with.x, x * with.y, x * with.z, + y * with.x, y * with.y, y * with.z, + z * with.x, z * with.y, z * with.z ); } @@ -486,11 +488,11 @@ namespace Godot } /// <summary> - /// Rotates this vector around a given <paramref name="axis"/> vector by <paramref name="phi"/> radians. + /// Rotates this vector around a given <paramref name="axis"/> vector by <paramref name="angle"/> (in radians). /// The <paramref name="axis"/> vector must be a normalized vector. /// </summary> /// <param name="axis">The vector to rotate around. Must be normalized.</param> - /// <param name="phi">The angle to rotate by, in radians.</param> + /// <param name="angle">The angle to rotate by, in radians.</param> /// <returns>The rotated vector.</returns> public Vector3 Rotated(Vector3 axis, real_t phi) { @@ -549,25 +551,25 @@ namespace Godot /// Returns the result of the spherical linear interpolation between /// this vector and <paramref name="to"/> by amount <paramref name="weight"/>. /// - /// Note: 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 <see cref="Lerp"/>. /// </summary> - /// <param name="to">The destination vector for interpolation. Must be normalized.</param> + /// <param name="to">The destination vector for interpolation.</param> /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> /// <returns>The resulting vector of the interpolation.</returns> public Vector3 Slerp(Vector3 to, real_t weight) { -#if DEBUG - if (!IsNormalized()) - { - throw new InvalidOperationException("Vector3.Slerp: From vector is not normalized."); + real_t startLengthSquared = LengthSquared(); + real_t endLengthSquared = to.LengthSquared(); + if (startLengthSquared == 0.0 || endLengthSquared == 0.0) { + // Zero length vectors have no angle, so the best we can do is either lerp or throw an error. + return Lerp(to, weight); } - if (!to.IsNormalized()) - { - throw new InvalidOperationException($"Vector3.Slerp: `{nameof(to)}` is not normalized."); - } -#endif - real_t theta = AngleTo(to); - return Rotated(Cross(to), theta * weight); + real_t startLength = Mathf.Sqrt(startLengthSquared); + real_t resultLength = Mathf.Lerp(startLength, Mathf.Sqrt(endLengthSquared), weight); + real_t angle = AngleTo(to); + return Rotated(Cross(to).Normalized(), angle * weight) * (resultLength / startLength); } /// <summary> @@ -699,6 +701,13 @@ namespace Godot z = v.z; } + /// <summary> + /// Adds each component of the <see cref="Vector3"/> + /// with the components of the given <see cref="Vector3"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The added vector.</returns> public static Vector3 operator +(Vector3 left, Vector3 right) { left.x += right.x; @@ -707,6 +716,13 @@ namespace Godot return left; } + /// <summary> + /// Subtracts each component of the <see cref="Vector3"/> + /// by the components of the given <see cref="Vector3"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The subtracted vector.</returns> public static Vector3 operator -(Vector3 left, Vector3 right) { left.x -= right.x; @@ -715,6 +731,15 @@ namespace Godot return left; } + /// <summary> + /// Returns the negative value of the <see cref="Vector3"/>. + /// This is the same as writing <c>new Vector3(-v.x, -v.y, -v.z)</c>. + /// This operation flips the direction of the vector while + /// keeping the same magnitude. + /// With floats, the number zero can be either positive or negative. + /// </summary> + /// <param name="vec">The vector to negate/flip.</param> + /// <returns>The negated/flipped vector.</returns> public static Vector3 operator -(Vector3 vec) { vec.x = -vec.x; @@ -723,6 +748,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3"/> + /// by the given <see cref="real_t"/>. + /// </summary> + /// <param name="vec">The vector to multiply.</param> + /// <param name="scale">The scale to multiply by.</param> + /// <returns>The multiplied vector.</returns> public static Vector3 operator *(Vector3 vec, real_t scale) { vec.x *= scale; @@ -731,6 +763,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3"/> + /// by the given <see cref="real_t"/>. + /// </summary> + /// <param name="scale">The scale to multiply by.</param> + /// <param name="vec">The vector to multiply.</param> + /// <returns>The multiplied vector.</returns> public static Vector3 operator *(real_t scale, Vector3 vec) { vec.x *= scale; @@ -739,6 +778,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3"/> + /// by the components of the given <see cref="Vector3"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The multiplied vector.</returns> public static Vector3 operator *(Vector3 left, Vector3 right) { left.x *= right.x; @@ -747,6 +793,13 @@ namespace Godot return left; } + /// <summary> + /// Divides each component of the <see cref="Vector3"/> + /// by the given <see cref="real_t"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The divided vector.</returns> public static Vector3 operator /(Vector3 vec, real_t divisor) { vec.x /= divisor; @@ -755,6 +808,13 @@ namespace Godot return vec; } + /// <summary> + /// Divides each component of the <see cref="Vector3"/> + /// by the components of the given <see cref="Vector3"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The divided vector.</returns> public static Vector3 operator /(Vector3 vec, Vector3 divisorv) { vec.x /= divisorv.x; @@ -763,6 +823,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector3"/> + /// with the components of the given <see cref="real_t"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(real_t)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector3(10, -20, 30) % 7); // Prints "(3, -6, 2)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The remainder vector.</returns> public static Vector3 operator %(Vector3 vec, real_t divisor) { vec.x %= divisor; @@ -771,6 +847,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector3"/> + /// with the components of the given <see cref="Vector3"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(Vector3)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector3(10, -20, 30) % new Vector3(7, 8, 9)); // Prints "(3, -4, 3)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The remainder vector.</returns> public static Vector3 operator %(Vector3 vec, Vector3 divisorv) { vec.x %= divisorv.x; @@ -779,16 +871,43 @@ namespace Godot return vec; } + /// <summary> + /// Returns <see langword="true"/> if the vectors are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are exactly equal.</returns> public static bool operator ==(Vector3 left, Vector3 right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the vectors are not equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are not equal.</returns> public static bool operator !=(Vector3 left, Vector3 right) { return !left.Equals(right); } + /// <summary> + /// Compares two <see cref="Vector3"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than the right.</returns> public static bool operator <(Vector3 left, Vector3 right) { if (left.x == right.x) @@ -802,6 +921,17 @@ namespace Godot return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector3"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than the right.</returns> public static bool operator >(Vector3 left, Vector3 right) { if (left.x == right.x) @@ -815,6 +945,17 @@ namespace Godot return left.x > right.x; } + /// <summary> + /// Compares two <see cref="Vector3"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// or equal to the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than or equal to the right.</returns> public static bool operator <=(Vector3 left, Vector3 right) { if (left.x == right.x) @@ -828,6 +969,17 @@ namespace Godot return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector3"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// or equal to the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than or equal to the right.</returns> public static bool operator >=(Vector3 left, Vector3 right) { if (left.x == right.x) @@ -842,10 +994,13 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the vector is exactly equal + /// to the given object (<see paramref="obj"/>). + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the vector and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the vector and the object are equal.</returns> public override bool Equals(object obj) { if (obj is Vector3) @@ -857,10 +1012,12 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="other"/> are equal + /// Returns <see langword="true"/> if the vectors are exactly equal. + /// Note: Due to floating-point precision errors, consider using + /// <see cref="IsEqualApprox"/> instead, which is more reliable. /// </summary> - /// <param name="other">The other vector to compare.</param> - /// <returns>Whether or not the vectors are equal.</returns> + /// <param name="other">The other vector.</param> + /// <returns>Whether or not the vectors are exactly equal.</returns> public bool Equals(Vector3 other) { return x == other.x && y == other.y && z == other.z; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs index 2a7771cdfc..abfd2ae720 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs @@ -17,7 +17,7 @@ namespace Godot { /// <summary> /// Enumerated index values for the axes. - /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// Returned by <see cref="MaxAxisIndex"/> and <see cref="MinAxisIndex"/>. /// </summary> public enum Axis { @@ -97,6 +97,16 @@ namespace Godot } /// <summary> + /// Helper method for deconstruction into a tuple. + /// </summary> + public void Deconstruct(out int x, out int y, out int z) + { + x = this.x; + y = this.y; + z = this.z; + } + + /// <summary> /// Returns a new vector with all components in absolute values (i.e. positive). /// </summary> /// <returns>A vector with <see cref="Mathf.Abs(int)"/> called on each component.</returns> @@ -124,36 +134,36 @@ namespace Godot } /// <summary> - /// Returns the squared distance between this vector and <paramref name="b"/>. + /// Returns the squared distance between this vector and <paramref name="to"/>. /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if /// you need to compare vectors or need the squared distance for some formula. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="to">The other vector to use.</param> /// <returns>The squared distance between the two vectors.</returns> - public int DistanceSquaredTo(Vector3i b) + public int DistanceSquaredTo(Vector3i to) { - return (b - this).LengthSquared(); + return (to - this).LengthSquared(); } /// <summary> - /// Returns the distance between this vector and <paramref name="b"/>. + /// Returns the distance between this vector and <paramref name="to"/>. /// </summary> /// <seealso cref="DistanceSquaredTo(Vector3i)"/> - /// <param name="b">The other vector to use.</param> + /// <param name="to">The other vector to use.</param> /// <returns>The distance between the two vectors.</returns> - public real_t DistanceTo(Vector3i b) + public real_t DistanceTo(Vector3i to) { - return (b - this).Length(); + return (to - this).Length(); } /// <summary> - /// Returns the dot product of this vector and <paramref name="b"/>. + /// Returns the dot product of this vector and <paramref name="with"/>. /// </summary> - /// <param name="b">The other vector to use.</param> + /// <param name="with">The other vector to use.</param> /// <returns>The dot product of the two vectors.</returns> - public int Dot(Vector3i b) + public int Dot(Vector3i with) { - return x * b.x + y * b.y + z * b.z; + return x * with.x + y * with.y + z * with.z; } /// <summary> @@ -186,21 +196,21 @@ namespace Godot } /// <summary> - /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's highest value. See <see cref="Axis"/>. /// If all components are equal, this method returns <see cref="Axis.X"/>. /// </summary> - /// <returns>The index of the largest axis.</returns> - public Axis MaxAxis() + /// <returns>The index of the highest axis.</returns> + public Axis MaxAxisIndex() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } /// <summary> - /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// Returns the axis of the vector's lowest value. See <see cref="Axis"/>. /// If all components are equal, this method returns <see cref="Axis.Z"/>. /// </summary> - /// <returns>The index of the smallest axis.</returns> - public Axis MinAxis() + /// <returns>The index of the lowest axis.</returns> + public Axis MinAxisIndex() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } @@ -347,6 +357,13 @@ namespace Godot this.z = Mathf.RoundToInt(v.z); } + /// <summary> + /// Adds each component of the <see cref="Vector3i"/> + /// with the components of the given <see cref="Vector3i"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The added vector.</returns> public static Vector3i operator +(Vector3i left, Vector3i right) { left.x += right.x; @@ -355,6 +372,13 @@ namespace Godot return left; } + /// <summary> + /// Subtracts each component of the <see cref="Vector3i"/> + /// by the components of the given <see cref="Vector3i"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The subtracted vector.</returns> public static Vector3i operator -(Vector3i left, Vector3i right) { left.x -= right.x; @@ -363,6 +387,14 @@ namespace Godot return left; } + /// <summary> + /// Returns the negative value of the <see cref="Vector3i"/>. + /// This is the same as writing <c>new Vector3i(-v.x, -v.y, -v.z)</c>. + /// This operation flips the direction of the vector while + /// keeping the same magnitude. + /// </summary> + /// <param name="vec">The vector to negate/flip.</param> + /// <returns>The negated/flipped vector.</returns> public static Vector3i operator -(Vector3i vec) { vec.x = -vec.x; @@ -371,6 +403,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3i"/> + /// by the given <see langword="int"/>. + /// </summary> + /// <param name="vec">The vector to multiply.</param> + /// <param name="scale">The scale to multiply by.</param> + /// <returns>The multiplied vector.</returns> public static Vector3i operator *(Vector3i vec, int scale) { vec.x *= scale; @@ -379,6 +418,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3i"/> + /// by the given <see langword="int"/>. + /// </summary> + /// <param name="scale">The scale to multiply by.</param> + /// <param name="vec">The vector to multiply.</param> + /// <returns>The multiplied vector.</returns> public static Vector3i operator *(int scale, Vector3i vec) { vec.x *= scale; @@ -387,6 +433,13 @@ namespace Godot return vec; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3i"/> + /// by the components of the given <see cref="Vector3i"/>. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>The multiplied vector.</returns> public static Vector3i operator *(Vector3i left, Vector3i right) { left.x *= right.x; @@ -395,6 +448,13 @@ namespace Godot return left; } + /// <summary> + /// Multiplies each component of the <see cref="Vector3i"/> + /// by the given <see langword="int"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The divided vector.</returns> public static Vector3i operator /(Vector3i vec, int divisor) { vec.x /= divisor; @@ -403,6 +463,13 @@ namespace Godot return vec; } + /// <summary> + /// Divides each component of the <see cref="Vector3i"/> + /// by the components of the given <see cref="Vector3i"/>. + /// </summary> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The divided vector.</returns> public static Vector3i operator /(Vector3i vec, Vector3i divisorv) { vec.x /= divisorv.x; @@ -411,6 +478,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector3i"/> + /// with the components of the given <see langword="int"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(int)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector3i(10, -20, 30) % 7); // Prints "(3, -6, 2)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisor">The divisor value.</param> + /// <returns>The remainder vector.</returns> public static Vector3i operator %(Vector3i vec, int divisor) { vec.x %= divisor; @@ -419,6 +502,22 @@ namespace Godot return vec; } + /// <summary> + /// Gets the remainder of each component of the <see cref="Vector3i"/> + /// with the components of the given <see cref="Vector3i"/>. + /// This operation uses truncated division, which is often not desired + /// as it does not work well with negative numbers. + /// Consider using <see cref="PosMod(Vector3i)"/> instead + /// if you want to handle negative numbers. + /// </summary> + /// <example> + /// <code> + /// GD.Print(new Vector3i(10, -20, 30) % new Vector3i(7, 8, 9)); // Prints "(3, -4, 3)" + /// </code> + /// </example> + /// <param name="vec">The dividend vector.</param> + /// <param name="divisorv">The divisor vector.</param> + /// <returns>The remainder vector.</returns> public static Vector3i operator %(Vector3i vec, Vector3i divisorv) { vec.x %= divisorv.x; @@ -427,6 +526,13 @@ namespace Godot return vec; } + /// <summary> + /// Performs a bitwise AND operation with this <see cref="Vector3i"/> + /// and the given <see langword="int"/>. + /// </summary> + /// <param name="vec">The vector to AND with.</param> + /// <param name="and">The integer to AND with.</param> + /// <returns>The result of the bitwise AND.</returns> public static Vector3i operator &(Vector3i vec, int and) { vec.x &= and; @@ -435,6 +541,13 @@ namespace Godot return vec; } + /// <summary> + /// Performs a bitwise AND operation with this <see cref="Vector3i"/> + /// and the given <see cref="Vector3i"/>. + /// </summary> + /// <param name="vec">The left vector to AND with.</param> + /// <param name="andv">The right vector to AND with.</param> + /// <returns>The result of the bitwise AND.</returns> public static Vector3i operator &(Vector3i vec, Vector3i andv) { vec.x &= andv.x; @@ -443,65 +556,121 @@ namespace Godot return vec; } + /// <summary> + /// Returns <see langword="true"/> if the vectors are equal. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are equal.</returns> public static bool operator ==(Vector3i left, Vector3i right) { return left.Equals(right); } + /// <summary> + /// Returns <see langword="true"/> if the vectors are not equal. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the vectors are not equal.</returns> public static bool operator !=(Vector3i left, Vector3i right) { return !left.Equals(right); } + /// <summary> + /// Compares two <see cref="Vector3i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than the right.</returns> public static bool operator <(Vector3i left, Vector3i right) { if (left.x == right.x) { if (left.y == right.y) + { return left.z < right.z; - else - return left.y < right.y; + } + return left.y < right.y; } - return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector3i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than the right.</returns> public static bool operator >(Vector3i left, Vector3i right) { if (left.x == right.x) { if (left.y == right.y) + { return left.z > right.z; - else - return left.y > right.y; + } + return left.y > right.y; } - return left.x > right.x; } + /// <summary> + /// Compares two <see cref="Vector3i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is less than + /// or equal to the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is less than or equal to the right.</returns> public static bool operator <=(Vector3i left, Vector3i right) { if (left.x == right.x) { if (left.y == right.y) + { return left.z <= right.z; - else - return left.y < right.y; + } + return left.y < right.y; } - return left.x < right.x; } + /// <summary> + /// Compares two <see cref="Vector3i"/> vectors by first checking if + /// the X value of the <paramref name="left"/> vector is greater than + /// or equal to the X value of the <paramref name="right"/> vector. + /// If the X values are exactly equal, then it repeats this check + /// with the Y values of the two vectors, and then with the Z values. + /// This operator is useful for sorting vectors. + /// </summary> + /// <param name="left">The left vector.</param> + /// <param name="right">The right vector.</param> + /// <returns>Whether or not the left is greater than or equal to the right.</returns> public static bool operator >=(Vector3i left, Vector3i right) { if (left.x == right.x) { if (left.y == right.y) + { return left.z >= right.z; - else - return left.y > right.y; + } + return left.y > right.y; } - return left.x > right.x; } @@ -524,10 +693,11 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="obj"/> are equal. + /// Returns <see langword="true"/> if the vector is equal + /// to the given object (<see paramref="obj"/>). /// </summary> - /// <param name="obj">The other object to compare.</param> - /// <returns>Whether or not the vector and the other object are equal.</returns> + /// <param name="obj">The object to compare with.</param> + /// <returns>Whether or not the vector and the object are equal.</returns> public override bool Equals(object obj) { if (obj is Vector3i) @@ -539,9 +709,9 @@ namespace Godot } /// <summary> - /// Returns <see langword="true"/> if this vector and <paramref name="other"/> are equal + /// Returns <see langword="true"/> if the vectors are equal. /// </summary> - /// <param name="other">The other vector to compare.</param> + /// <param name="other">The other vector.</param> /// <returns>Whether or not the vectors are equal.</returns> public bool Equals(Vector3i other) { diff --git a/modules/mono/glue/arguments_vector.h b/modules/mono/glue/arguments_vector.h index 9ba6a05ac6..4405809887 100644 --- a/modules/mono/glue/arguments_vector.h +++ b/modules/mono/glue/arguments_vector.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -37,7 +37,7 @@ template <typename T, int POOL_SIZE = 5> struct ArgumentsVector { private: T pool[POOL_SIZE]; - T *_ptr; + T *_ptr = nullptr; int size; ArgumentsVector() = delete; diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index 6c5503a3bd..b10d78c593 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -148,7 +148,7 @@ MonoObject *godot_icall_Object_weakref(Object *p_ptr) { RefCounted *rc = Object::cast_to<RefCounted>(p_ptr); if (rc) { - REF r = rc; + Ref<RefCounted> r = rc; if (!r.is_valid()) { return nullptr; } @@ -199,7 +199,7 @@ MonoBoolean godot_icall_DynamicGodotObject_InvokeMember(Object *p_ptr, MonoStrin } Callable::CallError error; - Variant result = p_ptr->call(StringName(name), args.ptr(), argc, error); + Variant result = p_ptr->callp(StringName(name), args.ptr(), argc, error); *r_result = GDMonoMarshal::variant_to_mono_object(result); diff --git a/modules/mono/glue/callable_glue.cpp b/modules/mono/glue/callable_glue.cpp index 54b65fdb94..e59b34313c 100644 --- a/modules/mono/glue/callable_glue.cpp +++ b/modules/mono/glue/callable_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/glue/collections_glue.cpp b/modules/mono/glue/collections_glue.cpp index 86976de244..8a9f30459c 100644 --- a/modules/mono/glue/collections_glue.cpp +++ b/modules/mono/glue/collections_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -144,7 +144,7 @@ void godot_icall_Array_Insert(Array *ptr, int32_t index, MonoObject *item) { MonoBoolean godot_icall_Array_Remove(Array *ptr, MonoObject *item) { int idx = ptr->find(GDMonoMarshal::mono_object_to_variant(item)); if (idx >= 0) { - ptr->remove(idx); + ptr->remove_at(idx); return true; } return false; @@ -155,7 +155,7 @@ void godot_icall_Array_RemoveAt(Array *ptr, int32_t index) { GDMonoUtils::set_pending_exception(mono_get_exception_index_out_of_range()); return; } - ptr->remove(index); + ptr->remove_at(index); } int32_t godot_icall_Array_Resize(Array *ptr, int32_t new_size) { @@ -237,10 +237,14 @@ int32_t godot_icall_Dictionary_KeyValuePairs(Dictionary *ptr, Array **keys, Arra } void godot_icall_Dictionary_KeyValuePairAt(Dictionary *ptr, int index, MonoObject **key, MonoObject **value) { - Array *keys = godot_icall_Dictionary_Keys(ptr); - Array *values = godot_icall_Dictionary_Values(ptr); - *key = GDMonoMarshal::variant_to_mono_object(keys->get(index)); - *value = GDMonoMarshal::variant_to_mono_object(values->get(index)); + *key = GDMonoMarshal::variant_to_mono_object(ptr->get_key_at_index(index)); + *value = GDMonoMarshal::variant_to_mono_object(ptr->get_value_at_index(index)); +} + +void godot_icall_Dictionary_KeyValuePairAt_Generic(Dictionary *ptr, int index, MonoObject **key, MonoObject **value, uint32_t value_type_encoding, GDMonoClass *value_type_class) { + ManagedType type(value_type_encoding, value_type_class); + *key = GDMonoMarshal::variant_to_mono_object(ptr->get_key_at_index(index)); + *value = GDMonoMarshal::variant_to_mono_object(ptr->get_value_at_index(index), type); } void godot_icall_Dictionary_Add(Dictionary *ptr, MonoObject *key, MonoObject *value) { @@ -353,6 +357,7 @@ void godot_register_collections_icalls() { GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Count", godot_icall_Dictionary_Count); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_KeyValuePairs", godot_icall_Dictionary_KeyValuePairs); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_KeyValuePairAt", godot_icall_Dictionary_KeyValuePairAt); + GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_KeyValuePairAt_Generic", godot_icall_Dictionary_KeyValuePairAt_Generic); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Add", godot_icall_Dictionary_Add); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Clear", godot_icall_Dictionary_Clear); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Contains", godot_icall_Dictionary_Contains); diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index a2ff868f65..8aead217cf 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -182,26 +182,30 @@ void godot_icall_GD_printt(MonoArray *p_what) { print_line(str); } -float godot_icall_GD_randf() { - return Math::randf(); +void godot_icall_GD_randomize() { + Math::randomize(); } uint32_t godot_icall_GD_randi() { return Math::rand(); } -void godot_icall_GD_randomize() { - Math::randomize(); +float godot_icall_GD_randf() { + return Math::randf(); } -double godot_icall_GD_randf_range(double from, double to) { +int32_t godot_icall_GD_randi_range(int32_t from, int32_t to) { return Math::random(from, to); } -int32_t godot_icall_GD_randi_range(int32_t from, int32_t to) { +double godot_icall_GD_randf_range(double from, double to) { return Math::random(from, to); } +double godot_icall_GD_randfn(double mean, double deviation) { + return Math::randfn(mean, deviation); +} + uint32_t godot_icall_GD_rand_seed(uint64_t seed, uint64_t *newSeed) { uint32_t ret = Math::rand_from_seed(&seed); *newSeed = seed; @@ -300,11 +304,12 @@ void godot_register_gd_icalls() { GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_printraw", godot_icall_GD_printraw); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_prints", godot_icall_GD_prints); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_printt", godot_icall_GD_printt); - GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf", godot_icall_GD_randf); - GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randi", godot_icall_GD_randi); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randomize", godot_icall_GD_randomize); - GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf_range", godot_icall_GD_randf_range); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randi", godot_icall_GD_randi); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf", godot_icall_GD_randf); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randi_range", godot_icall_GD_randi_range); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randf_range", godot_icall_GD_randf_range); + GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_randfn", godot_icall_GD_randfn); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_rand_seed", godot_icall_GD_rand_seed); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_seed", godot_icall_GD_seed); GDMonoUtils::add_internal_call("Godot.GD::godot_icall_GD_str", godot_icall_GD_str); diff --git a/modules/mono/glue/glue_header.h b/modules/mono/glue/glue_header.h index 074220bb9b..9638b23410 100644 --- a/modules/mono/glue/glue_header.h +++ b/modules/mono/glue/glue_header.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/glue/nodepath_glue.cpp b/modules/mono/glue/nodepath_glue.cpp index 4ddb94e1a8..0ea9814b1a 100644 --- a/modules/mono/glue/nodepath_glue.cpp +++ b/modules/mono/glue/nodepath_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/glue/rid_glue.cpp b/modules/mono/glue/rid_glue.cpp index f464e63a81..3e09564539 100644 --- a/modules/mono/glue/rid_glue.cpp +++ b/modules/mono/glue/rid_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/glue/scene_tree_glue.cpp b/modules/mono/glue/scene_tree_glue.cpp index 5a6fd69db8..c60e7c4869 100644 --- a/modules/mono/glue/scene_tree_glue.cpp +++ b/modules/mono/glue/scene_tree_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/glue/string_glue.cpp b/modules/mono/glue/string_glue.cpp index bb80a836ad..fc6b13ceb3 100644 --- a/modules/mono/glue/string_glue.cpp +++ b/modules/mono/glue/string_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ diff --git a/modules/mono/glue/string_name_glue.cpp b/modules/mono/glue/string_name_glue.cpp index f537896559..46d15316ba 100644 --- a/modules/mono/glue/string_name_glue.cpp +++ b/modules/mono/glue/string_name_glue.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ |