From 1bf2ff48f2eda36c25d58c3aa413ec245276e9d8 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 13 Oct 2024 16:41:25 +0900 Subject: [PATCH] Changed bmin/bmax from float[] to RcVec2f for improved memory efficiency and readability --- src/DotRecast.Recast/Geom/RcChunkyTriMeshs.cs | 8 ++++---- src/DotRecast.Recast/Geom/RcTriMesh.cs | 3 ++- src/DotRecast.Recast/RcVoxelizations.cs | 13 +++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/DotRecast.Recast/Geom/RcChunkyTriMeshs.cs b/src/DotRecast.Recast/Geom/RcChunkyTriMeshs.cs index 795f57f..25a3ff9 100644 --- a/src/DotRecast.Recast/Geom/RcChunkyTriMeshs.cs +++ b/src/DotRecast.Recast/Geom/RcChunkyTriMeshs.cs @@ -99,7 +99,7 @@ namespace DotRecast.Recast.Geom } /// Returns the chunk indices which overlap the input rectable. - public static List GetChunksOverlappingRect(RcChunkyTriMesh cm, float[] bmin, float[] bmax) + public static List GetChunksOverlappingRect(RcChunkyTriMesh cm, RcVec2f bmin, RcVec2f bmax) { // Traverse tree List ids = new List(); @@ -252,11 +252,11 @@ namespace DotRecast.Recast.Geom } } - private static bool CheckOverlapRect(float[] amin, float[] amax, RcVec2f bmin, RcVec2f bmax) + private static bool CheckOverlapRect(RcVec2f amin, RcVec2f amax, RcVec2f bmin, RcVec2f bmax) { bool overlap = true; - overlap = (amin[0] > bmax.X || amax[0] < bmin.X) ? false : overlap; - overlap = (amin[1] > bmax.Y || amax[1] < bmin.Y) ? false : overlap; + overlap = (amin.X > bmax.X || amax.X < bmin.X) ? false : overlap; + overlap = (amin.Y > bmax.Y || amax.Y < bmin.Y) ? false : overlap; return overlap; } diff --git a/src/DotRecast.Recast/Geom/RcTriMesh.cs b/src/DotRecast.Recast/Geom/RcTriMesh.cs index 5cd22d1..1e45b6f 100644 --- a/src/DotRecast.Recast/Geom/RcTriMesh.cs +++ b/src/DotRecast.Recast/Geom/RcTriMesh.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using System.Collections.Generic; +using DotRecast.Core.Numerics; namespace DotRecast.Recast.Geom { @@ -46,7 +47,7 @@ namespace DotRecast.Recast.Geom return vertices; } - public List GetChunksOverlappingRect(float[] bmin, float[] bmax) + public List GetChunksOverlappingRect(RcVec2f bmin, RcVec2f bmax) { return RcChunkyTriMeshs.GetChunksOverlappingRect(chunkyTriMesh, bmin, bmax); } diff --git a/src/DotRecast.Recast/RcVoxelizations.cs b/src/DotRecast.Recast/RcVoxelizations.cs index a6d8d4b..0687824 100644 --- a/src/DotRecast.Recast/RcVoxelizations.cs +++ b/src/DotRecast.Recast/RcVoxelizations.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core; +using DotRecast.Core.Numerics; using DotRecast.Recast.Geom; namespace DotRecast.Recast @@ -44,12 +45,12 @@ namespace DotRecast.Recast float[] verts = geom.GetVerts(); if (cfg.UseTiles) { - float[] tbmin = new float[2]; - float[] tbmax = new float[2]; - tbmin[0] = builderCfg.bmin.X; - tbmin[1] = builderCfg.bmin.Z; - tbmax[0] = builderCfg.bmax.X; - tbmax[1] = builderCfg.bmax.Z; + RcVec2f tbmin; + RcVec2f tbmax; + tbmin.X = builderCfg.bmin.X; + tbmin.Y = builderCfg.bmin.Z; + tbmax.X = builderCfg.bmax.X; + tbmax.Y = builderCfg.bmax.Z; List nodes = geom.GetChunksOverlappingRect(tbmin, tbmax); foreach (RcChunkyTriMeshNode node in nodes) {