Skip to content

Commit

Permalink
refactor: move Dot2D function
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Oct 20, 2023
1 parent bc7b02d commit 33fa18c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
22 changes: 0 additions & 22 deletions src/DotRecast.Core/Numerics/RcVec3f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,6 @@ public static RcVec3f Add(RcVec3f left, RcVec3f right)
}




/// Derives the dot product of two vectors on the xz-plane. (@p u . @p v)
/// @param[in] u A vector [(x, y, z)]
/// @param[in] v A vector [(x, y, z)]
/// @return The dot product on the xz-plane.
///
/// The vectors are projected onto the xz-plane, so the y-values are
/// ignored.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Dot2D(RcVec3f v)
{
return X * v.X + Z * v.Z;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly float Dot2D(float[] v, int vi)
{
return X * v[vi] + Z * v[vi + 2];
}


public override bool Equals(object obj)
{
if (!(obj is RcVec3f))
Expand Down
23 changes: 22 additions & 1 deletion src/DotRecast.Core/Numerics/RcVecExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,32 @@ public static float Get(this RcVec3f v, int i)
default: throw new IndexOutOfRangeException("vector3f index out of range");
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RcVec3f Scale(this RcVec3f v, float scale)
{
return v * scale;
}

/// Derives the dot product of two vectors on the xz-plane. (@p u . @p v)
/// @param[in] u A vector [(x, y, z)]
/// @param[in] v A vector [(x, y, z)]
/// @return The dot product on the xz-plane.
///
/// The vectors are projected onto the xz-plane, so the y-values are
/// ignored.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot2D(this RcVec3f @this, RcVec3f v)
{
return @this.X * v.X +
@this.Z * v.Z;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot2D(this RcVec3f @this, float[] v, int vi)
{
return @this.X * v[vi] +
@this.Z * v[vi + 2];
}
}
}

0 comments on commit 33fa18c

Please sign in to comment.