From fd03f0f12fd3a3f79e732e9a7a5641c0d305a0f9 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 8 Jun 2024 14:24:47 +0900 Subject: [PATCH] Removed RcVecUtils.Create(float[] values) --- CHANGELOG.md | 1 + src/DotRecast.Core/Numerics/RcVec3f.cs | 13 ++++++++++ src/DotRecast.Core/Numerics/RcVecUtils.cs | 26 ------------------- src/DotRecast.Core/RcThrowHelper.cs | 6 +++++ src/DotRecast.Detour.Crowd/DtPathCorridor.cs | 2 +- .../Geom/DemoInputGeomProvider.cs | 4 +-- .../Geom/SimpleInputGeomProvider.cs | 4 +-- src/DotRecast.Recast/RcAreas.cs | 4 +-- .../RcFilledVolumeRasterization.cs | 8 +++--- src/DotRecast.Recast/RcMeshDetails.cs | 4 +-- 10 files changed, 33 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ef1b2..4e38c3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Removed RcVecUtils.Subtract(float[] verts, int i, int j) - Removed RcMeshDetails.VdistSq2(float[], float[]) - Removed RcVecUtils.Min(), RcVecUtils.Max() +- Removed RcVecUtils.Create(float[] values) ### Special Thanks - [@Doprez](https://github.com/Doprez) diff --git a/src/DotRecast.Core/Numerics/RcVec3f.cs b/src/DotRecast.Core/Numerics/RcVec3f.cs index 4c35eb5..d928945 100644 --- a/src/DotRecast.Core/Numerics/RcVec3f.cs +++ b/src/DotRecast.Core/Numerics/RcVec3f.cs @@ -50,6 +50,19 @@ namespace DotRecast.Core.Numerics Z = f; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public RcVec3f(ReadOnlySpan values) + { + if (values.Length < 3) + { + RcThrowHelper.ThrowArgumentOutOfRangeException(nameof(values)); + } + + X = values[0]; + Y = values[1]; + Z = values[2]; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly float Length() diff --git a/src/DotRecast.Core/Numerics/RcVecUtils.cs b/src/DotRecast.Core/Numerics/RcVecUtils.cs index 86a47b4..80138ad 100644 --- a/src/DotRecast.Core/Numerics/RcVecUtils.cs +++ b/src/DotRecast.Core/Numerics/RcVecUtils.cs @@ -7,12 +7,6 @@ namespace DotRecast.Core.Numerics { public const float EPSILON = 1e-6f; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Create(float[] values) - { - return Create(values, 0); - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RcVec3f Create(Span values, int n) { @@ -112,26 +106,6 @@ namespace DotRecast.Core.Numerics return v; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Min(RcVec3f v, float[] @in, int i) - { - return new RcVec3f( - (v.X < @in[i + 0]) ? v.X : @in[i + 0], - (v.Y < @in[i + 1]) ? v.Y : @in[i + 1], - (v.Z < @in[i + 2]) ? v.Z : @in[i + 2] - ); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Max(RcVec3f v, float[] @in, int i) - { - return new RcVec3f( - (v.X > @in[i + 0]) ? v.X : @in[i + 0], - (v.Y > @in[i + 1]) ? v.Y : @in[i + 1], - (v.Z > @in[i + 2]) ? v.Z : @in[i + 2] - ); - } - /// Derives the distance between the specified points on the xz-plane. /// @param[in] v1 A point. [(x, y, z)] /// @param[in] v2 A point. [(x, y, z)] diff --git a/src/DotRecast.Core/RcThrowHelper.cs b/src/DotRecast.Core/RcThrowHelper.cs index 4eb6526..b3f484b 100644 --- a/src/DotRecast.Core/RcThrowHelper.cs +++ b/src/DotRecast.Core/RcThrowHelper.cs @@ -15,6 +15,12 @@ namespace DotRecast.Core } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void ThrowArgumentOutOfRangeException(string argument) + { + throw new ArgumentOutOfRangeException(argument); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void StackOverflow() { diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 740b271..5a01d3c 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -436,7 +436,7 @@ namespace DotRecast.Detour.Crowd else if (n == 0) { // The first polyref is bad, use current safe values. - m_pos = RcVecUtils.Create(safePos); + m_pos = new RcVec3f(safePos); m_path.Clear(); m_path.Add(safeRef); m_npath = 1; diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 444a654..9d6ba80 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -57,8 +57,8 @@ namespace DotRecast.Recast.Toolset.Geom this.faces = faces; normals = new float[faces.Length]; CalculateNormals(); - bmin = RcVecUtils.Create(vertices); - bmax = RcVecUtils.Create(vertices); + bmin = new RcVec3f(vertices); + bmax = new RcVec3f(vertices); for (int i = 1; i < vertices.Length / 3; i++) { bmin = RcVec3f.Min(bmin, RcVecUtils.Create(vertices, i * 3)); diff --git a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs index 74b4ff4..56f281f 100644 --- a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs +++ b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs @@ -77,8 +77,8 @@ namespace DotRecast.Recast.Geom this.faces = faces; normals = new float[faces.Length]; CalculateNormals(); - bmin = RcVecUtils.Create(vertices); - bmax = RcVecUtils.Create(vertices); + bmin = new RcVec3f(vertices); + bmax = new RcVec3f(vertices); for (int i = 1; i < vertices.Length / 3; i++) { bmin = RcVec3f.Min(bmin, RcVecUtils.Create(vertices, i * 3)); diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index 2405883..011d45e 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -456,8 +456,8 @@ namespace DotRecast.Recast int zStride = xSize; // For readability // Compute the bounding box of the polygon - RcVec3f bmin = RcVecUtils.Create(verts); - RcVec3f bmax = RcVecUtils.Create(verts); + RcVec3f bmin = new RcVec3f(verts); + RcVec3f bmax = new RcVec3f(verts); for (int i = 3; i < verts.Length; i += 3) { bmin = RcVec3f.Min(bmin, RcVecUtils.Create(verts, i)); diff --git a/src/DotRecast.Recast/RcFilledVolumeRasterization.cs b/src/DotRecast.Recast/RcFilledVolumeRasterization.cs index fd558b2..e6a20e9 100644 --- a/src/DotRecast.Recast/RcFilledVolumeRasterization.cs +++ b/src/DotRecast.Recast/RcFilledVolumeRasterization.cs @@ -525,7 +525,7 @@ namespace DotRecast.Recast { if (MathF.Abs(planes[j][1]) > EPSILON) { - float dotNormalPoint = RcVec3f.Dot(RcVecUtils.Create(planes[j]), point); + float dotNormalPoint = RcVec3f.Dot(new RcVec3f(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(RcVecUtils.Create(planes[plane]), point)) / planes[plane][1]; + float t = (planes[plane][3] - RcVec3f.Dot(new RcVec3f(planes[plane]), point)) / planes[plane][1]; RcVec3f s = new RcVec3f(point.X, point.Y + t, point.Z); - float u = RcVec3f.Dot(s, RcVecUtils.Create(planes[plane + 1])) - planes[plane + 1][3]; + float u = RcVec3f.Dot(s, new RcVec3f(planes[plane + 1])) - planes[plane + 1][3]; if (u < 0.0f || u > 1.0f) { return false; } - float v = RcVec3f.Dot(s, RcVecUtils.Create(planes[plane + 2])) - planes[plane + 2][3]; + float v = RcVec3f.Dot(s, new RcVec3f(planes[plane + 2])) - planes[plane + 2][3]; if (v < 0.0f) { return false; diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index 891c632..b637b3b 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -931,8 +931,8 @@ namespace DotRecast.Recast if (sampleDist > 0) { // Create sample locations in a grid. - RcVec3f bmin = RcVecUtils.Create(@in); - RcVec3f bmax = RcVecUtils.Create(@in); + RcVec3f bmin = new RcVec3f(@in); + RcVec3f bmax = new RcVec3f(@in); for (int i = 1; i < nin; ++i) { bmin = RcVec3f.Min(bmin, RcVecUtils.Create(@in, i * 3));