Skip to content

Commit

Permalink
Changed bmin/bmax from float[] to RcVec2f for improved memory efficie…
Browse files Browse the repository at this point in the history
…ncy and readability
  • Loading branch information
ikpil committed Oct 13, 2024
1 parent ea437ef commit 1bf2ff4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/DotRecast.Recast/Geom/RcChunkyTriMeshs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static bool CreateChunkyTriMesh(float[] verts, int[] tris, int ntris, int
}

/// Returns the chunk indices which overlap the input rectable.
public static List<RcChunkyTriMeshNode> GetChunksOverlappingRect(RcChunkyTriMesh cm, float[] bmin, float[] bmax)
public static List<RcChunkyTriMeshNode> GetChunksOverlappingRect(RcChunkyTriMesh cm, RcVec2f bmin, RcVec2f bmax)
{
// Traverse tree
List<RcChunkyTriMeshNode> ids = new List<RcChunkyTriMeshNode>();
Expand Down Expand Up @@ -252,11 +252,11 @@ private static void Subdivide(BoundsItem[] items, int imin, int imax, int trisPe
}
}

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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/DotRecast.Recast/Geom/RcTriMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 3. This notice may not be removed or altered from any source distribution.
*/

using System.Collections.Generic;
using DotRecast.Core.Numerics;

namespace DotRecast.Recast.Geom
{
Expand Down Expand Up @@ -46,7 +47,7 @@ public float[] GetVerts()
return vertices;
}

public List<RcChunkyTriMeshNode> GetChunksOverlappingRect(float[] bmin, float[] bmax)
public List<RcChunkyTriMeshNode> GetChunksOverlappingRect(RcVec2f bmin, RcVec2f bmax)
{
return RcChunkyTriMeshs.GetChunksOverlappingRect(chunkyTriMesh, bmin, bmax);
}
Expand Down
13 changes: 7 additions & 6 deletions src/DotRecast.Recast/RcVoxelizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 3. This notice may not be removed or altered from any source distribution.

using System.Collections.Generic;
using DotRecast.Core;
using DotRecast.Core.Numerics;
using DotRecast.Recast.Geom;

namespace DotRecast.Recast
Expand All @@ -44,12 +45,12 @@ public static RcHeightfield BuildSolidHeightfield(RcContext ctx, IInputGeomProvi
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<RcChunkyTriMeshNode> nodes = geom.GetChunksOverlappingRect(tbmin, tbmax);
foreach (RcChunkyTriMeshNode node in nodes)
{
Expand Down

0 comments on commit 1bf2ff4

Please sign in to comment.