From ebab0a11f38bc5f2af60d080c404f83a5a3b9288 Mon Sep 17 00:00:00 2001 From: ikpil Date: Fri, 7 Jun 2024 21:44:59 +0900 Subject: [PATCH] Removed RcVecUtils.Subtract(RcVec3f i, float[] verts, int j) --- CHANGELOG.md | 1 + src/DotRecast.Core/Numerics/RcVecUtils.cs | 12 ------------ src/DotRecast.Recast/RcMeshDetails.cs | 18 +++++++++--------- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e244f9..e1e5281 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Removed - Removed RcVecUtils.Dot() - Removed RcVecUtils.Scale() +- Removed RcVecUtils.Subtract(RcVec3f i, float[] verts, int j) ### Special Thanks - [@Doprez](https://github.com/Doprez) diff --git a/src/DotRecast.Core/Numerics/RcVecUtils.cs b/src/DotRecast.Core/Numerics/RcVecUtils.cs index a083b2c..65b24ff 100644 --- a/src/DotRecast.Core/Numerics/RcVecUtils.cs +++ b/src/DotRecast.Core/Numerics/RcVecUtils.cs @@ -84,18 +84,6 @@ namespace DotRecast.Core.Numerics ); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Subtract(RcVec3f i, float[] verts, int j) - { - return new RcVec3f( - i.X - verts[j], - i.Y - verts[j + 1], - i.Z - verts[j + 2] - ); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Cross(float[] dest, float[] v1, float[] v2) { diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index 7cead00..755dd4d 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -183,11 +183,11 @@ namespace DotRecast.Recast return false; } - private static float DistPtTri(RcVec3f p, float[] verts, int a, int b, int c) + private static float DistPtTri(RcVec3f p, RcVec3f a, RcVec3f b, RcVec3f c) { - var v0 = RcVecUtils.Subtract(verts, c, a); - var v1 = RcVecUtils.Subtract(verts, b, a); - var v2 = RcVecUtils.Subtract(p, verts, a); + var v0 = c - a; + var v1 = b - a; + var v2 = p - a; float dot00 = Vdot2(v0, v0); float dot01 = Vdot2(v0, v1); @@ -204,7 +204,7 @@ namespace DotRecast.Recast const float EPS = 1e-4f; if (u >= -EPS && v >= -EPS && (u + v) <= 1 + EPS) { - float y = verts[a + 1] + v0.Y * u + v1.Y * v; + float y = a.Y + v0.Y * u + v1.Y * v; return MathF.Abs(y - p.Y); } @@ -303,10 +303,10 @@ namespace DotRecast.Recast float dmin = float.MaxValue; for (int i = 0; i < ntris; ++i) { - int va = tris[i * 4 + 0] * 3; - int vb = tris[i * 4 + 1] * 3; - int vc = tris[i * 4 + 2] * 3; - float d = DistPtTri(p, verts, va, vb, vc); + RcVec3f va = RcVecUtils.Create(verts, tris[i * 4 + 0] * 3); + RcVec3f vb = RcVecUtils.Create(verts, tris[i * 4 + 1] * 3); + RcVec3f vc = RcVecUtils.Create(verts, tris[i * 4 + 2] * 3); + float d = DistPtTri(p, va, vb, vc); if (d < dmin) { dmin = d;