refactor: TestVectorDot

This commit is contained in:
ikpil 2023-10-24 23:33:24 +09:00
parent 617eaa1287
commit ef8ef94826
4 changed files with 40 additions and 24 deletions

View File

@ -288,28 +288,13 @@ namespace DotRecast.Core.Numerics
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(RcVec3f v1, RcVec3f v2)
public static float Dot(RcVec3f vector1, RcVec3f vector2)
{
return (v1.X * v2.X)
+ (v1.Y * v2.Y)
+ (v1.Z * v2.Z);
return (vector1.X * vector2.X) +
(vector1.Y * vector2.Y) +
(vector1.Z * vector2.Z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(float[] v1, float[] v2)
{
return v1[0] * v2[0]
+ v1[1] * v2[1]
+ v1[2] * v2[2];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(float[] v1, RcVec3f v2)
{
return v1[0] * v2.X + v1[1] * v2.Y + v1[2] * v2.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float PerpXZ(RcVec3f a, RcVec3f b)
{

View File

@ -96,7 +96,7 @@ namespace DotRecast.Core.Numerics
dest[1] = v1[2] * v2[0] - v1[0] * v2[2];
dest[2] = v1[0] * v2[1] - v1[1] * v2[0];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy(float[] @out, int n, float[] @in, int m)
{
@ -104,5 +104,21 @@ namespace DotRecast.Core.Numerics
@out[n + 1] = @in[m + 1];
@out[n + 2] = @in[m + 2];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(float[] v1, float[] v2)
{
return v1[0] * v2[0] +
v1[1] * v2[1] +
v1[2] * v2[2];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Dot(float[] v1, RcVec3f vector2)
{
return v1[0] * vector2.X +
v1[1] * vector2.Y +
v1[2] * vector2.Z;
}
}
}

View File

@ -525,7 +525,7 @@ namespace DotRecast.Recast
{
if (Math.Abs(planes[j][1]) > EPSILON)
{
float dotNormalPoint = RcVec3f.Dot(planes[j], point);
float dotNormalPoint = RcVecUtils.Dot(planes[j], point);
float t = (planes[j][3] - dotNormalPoint) / planes[j][1];
float y = point.Y + t;
bool valid = true;
@ -729,15 +729,15 @@ namespace DotRecast.Recast
private static bool RayTriangleIntersection(RcVec3f point, int plane, float[][] planes, out float y)
{
y = 0.0f;
float t = (planes[plane][3] - RcVec3f.Dot(planes[plane], point)) / planes[plane][1];
float t = (planes[plane][3] - RcVecUtils.Dot(planes[plane], point)) / planes[plane][1];
float[] s = { point.X, point.Y + t, point.Z };
float u = RcVec3f.Dot(s, planes[plane + 1]) - planes[plane + 1][3];
float u = RcVecUtils.Dot(s, planes[plane + 1]) - planes[plane + 1][3];
if (u < 0.0f || u > 1.0f)
{
return false;
}
float v = RcVec3f.Dot(s, planes[plane + 2]) - planes[plane + 2][3];
float v = RcVecUtils.Dot(s, planes[plane + 2]) - planes[plane + 2][3];
if (v < 0.0f)
{
return false;

View File

@ -108,6 +108,21 @@ public class Vector3Tests
Assert.That(array1, Is.EqualTo(array11));
}
[Test]
[Repeat(100000)]
public void TestVectorDot()
{
var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
var v2 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
float d3 = Vector3.Dot(v1, v2);
var v11 = new RcVec3f(v1.X, v1.Y, v1.Z);
var v22 = new RcVec3f(v2.X, v2.Y, v2.Z);
var d33 = RcVec3f.Dot(v11, v22);
Assert.That(d3, Is.EqualTo(d33));
}
[Test]
[Repeat(100000)]
public void TestVectorDistance()