forked from mirror/DotRecast
refactor: TestVectorDot
This commit is contained in:
parent
617eaa1287
commit
ef8ef94826
|
@ -288,28 +288,13 @@ namespace DotRecast.Core.Numerics
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float Dot(RcVec3f v1, RcVec3f v2)
|
public static float Dot(RcVec3f vector1, RcVec3f vector2)
|
||||||
{
|
{
|
||||||
return (v1.X * v2.X)
|
return (vector1.X * vector2.X) +
|
||||||
+ (v1.Y * v2.Y)
|
(vector1.Y * vector2.Y) +
|
||||||
+ (v1.Z * v2.Z);
|
(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)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static float PerpXZ(RcVec3f a, RcVec3f b)
|
public static float PerpXZ(RcVec3f a, RcVec3f b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,5 +104,21 @@ namespace DotRecast.Core.Numerics
|
||||||
@out[n + 1] = @in[m + 1];
|
@out[n + 1] = @in[m + 1];
|
||||||
@out[n + 2] = @in[m + 2];
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -525,7 +525,7 @@ namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
if (Math.Abs(planes[j][1]) > EPSILON)
|
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 t = (planes[j][3] - dotNormalPoint) / planes[j][1];
|
||||||
float y = point.Y + t;
|
float y = point.Y + t;
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
|
@ -729,15 +729,15 @@ namespace DotRecast.Recast
|
||||||
private static bool RayTriangleIntersection(RcVec3f point, int plane, float[][] planes, out float y)
|
private static bool RayTriangleIntersection(RcVec3f point, int plane, float[][] planes, out float y)
|
||||||
{
|
{
|
||||||
y = 0.0f;
|
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[] 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)
|
if (u < 0.0f || u > 1.0f)
|
||||||
{
|
{
|
||||||
return false;
|
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)
|
if (v < 0.0f)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -108,6 +108,21 @@ public class Vector3Tests
|
||||||
Assert.That(array1, Is.EqualTo(array11));
|
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]
|
[Test]
|
||||||
[Repeat(100000)]
|
[Repeat(100000)]
|
||||||
public void TestVectorDistance()
|
public void TestVectorDistance()
|
||||||
|
|
Loading…
Reference in New Issue