refactor: align variable names to match those of the recastnavigation project.

This commit is contained in:
ikpil 2024-01-04 23:59:00 +09:00
parent 10bf4ce164
commit cbdc670c6a
1 changed files with 66 additions and 65 deletions

View File

@ -27,35 +27,19 @@ namespace DotRecast.Recast
{ {
public static class RcRasterizations public static class RcRasterizations
{ {
/** /// Check whether two bounding boxes overlap
* Check whether two bounding boxes overlap ///
* /// @param[in] aMin Min axis extents of bounding box A
* @param amin /// @param[in] aMax Max axis extents of bounding box A
* Min axis extents of bounding box A /// @param[in] bMin Min axis extents of bounding box B
* @param amax /// @param[in] bMax Max axis extents of bounding box B
* Max axis extents of bounding box A /// @returns true if the two bounding boxes overlap. False otherwise.
* @param bmin private static bool OverlapBounds(RcVec3f aMin, RcVec3f aMax, RcVec3f bMin, RcVec3f bMax)
* Min axis extents of bounding box B
* @param bmax
* Max axis extents of bounding box B
* @returns true if the two bounding boxes overlap. False otherwise
*/
private static bool OverlapBounds(float[] amin, float[] amax, float[] bmin, float[] bmax)
{ {
bool overlap = true; return
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap; aMin.X <= bMax.X && aMax.X >= bMin.X &&
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap; aMin.Y <= bMax.Y && aMax.Y >= bMin.Y &&
overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap; aMin.Z <= bMax.Z && aMax.Z >= bMin.Z;
return overlap;
}
private static bool OverlapBounds(RcVec3f amin, RcVec3f amax, RcVec3f bmin, RcVec3f bmax)
{
bool overlap = true;
overlap = (amin.X > bmax.X || amax.X < bmin.X) ? false : overlap;
overlap = (amin.Y > bmax.Y || amax.Y < bmin.Y) ? false : overlap;
overlap = (amin.Z > bmax.Z || amax.Z < bmin.Z) ? false : overlap;
return overlap;
} }
@ -69,72 +53,89 @@ namespace DotRecast.Recast
/// @param[in] max The new span's maximum cell index /// @param[in] max The new span's maximum cell index
/// @param[in] areaID The new span's area type ID /// @param[in] areaID The new span's area type ID
/// @param[in] flagMergeThreshold How close two spans maximum extents need to be to merge area type IDs /// @param[in] flagMergeThreshold How close two spans maximum extents need to be to merge area type IDs
public static void AddSpan(RcHeightfield heightfield, int x, int y, int spanMin, int spanMax, int areaId, int flagMergeThreshold) public static void AddSpan(RcHeightfield heightfield, int x, int z, int min, int max, int areaID, int flagMergeThreshold)
{ {
int idx = x + y * heightfield.width; // Create the new span.
RcSpan newSpan = new RcSpan();
newSpan.smin = min;
newSpan.smax = max;
newSpan.area = areaID;
newSpan.next = null;
RcSpan s = new RcSpan(); int columnIndex = x + z * heightfield.width;
s.smin = spanMin;
s.smax = spanMax;
s.area = areaId;
s.next = null;
// Empty cell, add the first span. // Empty cell, add the first span.
if (heightfield.spans[idx] == null) if (heightfield.spans[columnIndex] == null)
{ {
heightfield.spans[idx] = s; heightfield.spans[columnIndex] = newSpan;
return; return;
} }
RcSpan prev = null; RcSpan previousSpan = null;
RcSpan cur = heightfield.spans[idx]; RcSpan currentSpan = heightfield.spans[columnIndex];
// Insert and merge spans. // Insert the new span, possibly merging it with existing spans.
while (cur != null) while (currentSpan != null)
{ {
if (cur.smin > s.smax) if (currentSpan.smin > newSpan.smax)
{ {
// Current span is further than the new span, break. // Current span is further than the new span, break.
break; break;
} }
else if (cur.smax < s.smin)
if (currentSpan.smax < newSpan.smin)
{ {
// Current span is before the new span advance. // Current span is completely before the new span. Keep going.
prev = cur; previousSpan = currentSpan;
cur = cur.next; currentSpan = currentSpan.next;
} }
else else
{ {
// Merge spans. // The new span overlaps with an existing span. Merge them.
if (cur.smin < s.smin) if (currentSpan.smin < newSpan.smin)
s.smin = cur.smin; {
if (cur.smax > s.smax) newSpan.smin = currentSpan.smin;
s.smax = cur.smax; }
if (currentSpan.smax > newSpan.smax)
{
newSpan.smax = currentSpan.smax;
}
// Merge flags. // Merge flags.
if (MathF.Abs(s.smax - cur.smax) <= flagMergeThreshold) if (MathF.Abs(newSpan.smax - currentSpan.smax) <= flagMergeThreshold)
s.area = Math.Max(s.area, cur.area); {
// Higher area ID numbers indicate higher resolution priority.
newSpan.area = Math.Max(newSpan.area, currentSpan.area);
}
// Remove current span. // Remove the current span since it's now merged with newSpan.
RcSpan next = cur.next; // Keep going because there might be other overlapping spans that also need to be merged.
if (prev != null) RcSpan next = currentSpan.next;
prev.next = next; if (previousSpan != null)
{
previousSpan.next = next;
}
else else
heightfield.spans[idx] = next; {
cur = next; heightfield.spans[columnIndex] = next;
}
currentSpan = next;
} }
} }
// Insert new span. // Insert new span after prev
if (prev != null) if (previousSpan != null)
{ {
s.next = prev.next; newSpan.next = previousSpan.next;
prev.next = s; previousSpan.next = newSpan;
} }
else else
{ {
s.next = heightfield.spans[idx]; // This span should go before the others in the list
heightfield.spans[idx] = s; newSpan.next = heightfield.spans[columnIndex];
heightfield.spans[columnIndex] = newSpan;
} }
} }