Skip to content

Commit

Permalink
Swizzle support for C# Vector implementations (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
jss2a98aj authored Dec 15, 2024
1 parent 8911377 commit 58015e7
Show file tree
Hide file tree
Showing 6 changed files with 2,596 additions and 0 deletions.
58 changes: 58 additions & 0 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,55 @@ public readonly Vector2 Orthogonal()
/// <value>Equivalent to <c>new Vector2(-1, 0)</c>.</value>
public static Vector2 Left { get { return _left; } }

#pragma warning disable CS1591 // Disable warning: "Missing XML comment for publicly visible type or member"
public readonly Vector2 XX => new(X, X);
public Vector2 XY
{
readonly get => new(X, Y);
set
{
X = value.X;
Y = value.Y;
}
}
public Vector2 YX
{
readonly get => new(Y, X);
set
{
Y = value.X;
X = value.Y;
}
}
public readonly Vector2 YY => new(Y, Y);

public readonly Vector3 XXX => new(X, X, X);
public readonly Vector3 XXY => new(X, X, Y);
public readonly Vector3 XYX => new(X, Y, X);
public readonly Vector3 XYY => new(X, Y, Y);
public readonly Vector3 YXX => new(Y, X, X);
public readonly Vector3 YXY => new(Y, X, Y);
public readonly Vector3 YYX => new(Y, Y, X);
public readonly Vector3 YYY => new(Y, Y, Y);

public readonly Vector4 XXXX => new(X, X, X, X);
public readonly Vector4 XXXY => new(X, X, X, Y);
public readonly Vector4 XXYX => new(X, X, Y, X);
public readonly Vector4 XXYY => new(X, X, Y, Y);
public readonly Vector4 XYXX => new(X, Y, X, X);
public readonly Vector4 XYXY => new(X, Y, X, Y);
public readonly Vector4 XYYX => new(X, Y, Y, X);
public readonly Vector4 XYYY => new(X, Y, Y, Y);
public readonly Vector4 YXXX => new(Y, X, X, X);
public readonly Vector4 YXXY => new(Y, X, X, Y);
public readonly Vector4 YXYX => new(Y, X, Y, X);
public readonly Vector4 YXYY => new(Y, X, Y, Y);
public readonly Vector4 YYXX => new(Y, Y, X, X);
public readonly Vector4 YYXY => new(Y, Y, X, Y);
public readonly Vector4 YYYX => new(Y, Y, Y, X);
public readonly Vector4 YYYY => new(Y, Y, Y, Y);
#pragma warning restore CS1591

/// <summary>
/// Constructs a new <see cref="Vector2"/> with the given components.
/// </summary>
Expand All @@ -770,6 +819,15 @@ public Vector2(real_t x, real_t y)
Y = y;
}

/// <summary>
/// Constructs a new <see cref="Vector2"/> with the given components.
/// </summary>
/// <param name="v">The vector's X and Y components.</param>
public Vector2(real_t v)
{
X = Y = v;
}

/// <summary>
/// Creates a unit Vector2 rotated to the given angle. This is equivalent to doing
/// <c>Vector2(Mathf.Cos(angle), Mathf.Sin(angle))</c> or <c>Vector2.Right.Rotated(angle)</c>.
Expand Down
58 changes: 58 additions & 0 deletions modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2I.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,55 @@ public readonly Vector2I Snapped(int step)
/// <value>Equivalent to <c>new Vector2I(-1, 0)</c>.</value>
public static Vector2I Left { get { return _left; } }

#pragma warning disable CS1591 // Disable warning: "Missing XML comment for publicly visible type or member"
public readonly Vector2I XX => new(X, X);
public Vector2I XY
{
readonly get => new(X, Y);
set
{
X = value.X;
Y = value.Y;
}
}
public Vector2I YX
{
readonly get => new(Y, X);
set
{
Y = value.X;
X = value.Y;
}
}
public readonly Vector2I YY => new(Y, Y);

public readonly Vector3I XXX => new(X, X, X);
public readonly Vector3I XXY => new(X, X, Y);
public readonly Vector3I XYX => new(X, Y, X);
public readonly Vector3I XYY => new(X, Y, Y);
public readonly Vector3I YXX => new(Y, X, X);
public readonly Vector3I YXY => new(Y, X, Y);
public readonly Vector3I YYX => new(Y, Y, X);
public readonly Vector3I YYY => new(Y, Y, Y);

public readonly Vector4I XXXX => new(X, X, X, X);
public readonly Vector4I XXXY => new(X, X, X, Y);
public readonly Vector4I XXYX => new(X, X, Y, X);
public readonly Vector4I XXYY => new(X, X, Y, Y);
public readonly Vector4I XYXX => new(X, Y, X, X);
public readonly Vector4I XYXY => new(X, Y, X, Y);
public readonly Vector4I XYYX => new(X, Y, Y, X);
public readonly Vector4I XYYY => new(X, Y, Y, Y);
public readonly Vector4I YXXX => new(Y, X, X, X);
public readonly Vector4I YXXY => new(Y, X, X, Y);
public readonly Vector4I YXYX => new(Y, X, Y, X);
public readonly Vector4I YXYY => new(Y, X, Y, Y);
public readonly Vector4I YYXX => new(Y, Y, X, X);
public readonly Vector4I YYXY => new(Y, Y, X, Y);
public readonly Vector4I YYYX => new(Y, Y, Y, X);
public readonly Vector4I YYYY => new(Y, Y, Y, Y);
#pragma warning restore CS1591

/// <summary>
/// Constructs a new <see cref="Vector2I"/> with the given components.
/// </summary>
Expand All @@ -383,6 +432,15 @@ public Vector2I(int x, int y)
Y = y;
}

/// <summary>
/// Constructs a new <see cref="Vector2I"/> with the given components.
/// </summary>
/// <param name="v">The vector's X and Y components.</param>
public Vector2I(int v)
{
X = Y = v;
}

/// <summary>
/// Adds each component of the <see cref="Vector2I"/>
/// with the components of the given <see cref="Vector2I"/>.
Expand Down
Loading

0 comments on commit 58015e7

Please sign in to comment.