Skip to content

Commit

Permalink
Removed RcVecUtils.Create(float[] values)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Jun 8, 2024
1 parent ed7173d commit fd03f0f
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/DotRecast.Core/Numerics/RcVec3f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public RcVec3f(float f)
Z = f;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RcVec3f(ReadOnlySpan<float> 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()
Expand Down
26 changes: 0 additions & 26 deletions src/DotRecast.Core/Numerics/RcVecUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ public static class RcVecUtils
{
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<float> values, int n)
{
Expand Down Expand Up @@ -112,26 +106,6 @@ public static RcVec3f SafeNormalize(RcVec3f v)
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)]
Expand Down
6 changes: 6 additions & 0 deletions src/DotRecast.Core/RcThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public static void ThrowExceptionIfIndexOutOfRange(int index, int size)
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowArgumentOutOfRangeException(string argument)
{
throw new ArgumentOutOfRangeException(argument);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void StackOverflow()
{
Expand Down
2 changes: 1 addition & 1 deletion src/DotRecast.Detour.Crowd/DtPathCorridor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public bool TrimInvalidPath(long safeRef, float[] safePos, DtNavMeshQuery navque
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;
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public DemoInputGeomProvider(float[] vertices, int[] faces)
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));
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public SimpleInputGeomProvider(float[] vertices, int[] faces)
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));
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Recast/RcAreas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ public static void MarkConvexPolyArea(RcContext context, float[] verts,
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));
Expand Down
8 changes: 4 additions & 4 deletions src/DotRecast.Recast/RcFilledVolumeRasterization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private static float[] IntersectBox(float[] rectangle, float[] vertices, float[]
{
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;
Expand Down Expand Up @@ -729,15 +729,15 @@ private static bool ZSlabSegmentIntersection(float[] rectangle, float x, float y
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;
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Recast/RcMeshDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,8 @@ public static int BuildPolyDetail(RcContext ctx, float[] @in, int nin,
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));
Expand Down

0 comments on commit fd03f0f

Please sign in to comment.