Skip to content

Commit

Permalink
ifs to switch
Browse files Browse the repository at this point in the history
  • Loading branch information
p-flis committed Jan 5, 2021
1 parent 47c3c84 commit c12bcf3
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions RayTracer/Source/BVH/BvhNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,25 @@ public BvhNode(List<IHittable> srcObjects, int start, int end, AbstractSampler<i
int Comparator(IHittable a, IHittable b) => BoxCompare(a, b, axis);

int objectSpan = end - start;
if (objectSpan == 1)
switch (objectSpan)
{
_left = _right = objects[start];
}
else if (objectSpan == 2)
{
if (Comparator(objects[start], objects[start + 1]) < 0)
{
case 1:
_left = _right = objects[start];
break;
case 2 when Comparator(objects[start], objects[start + 1]) < 0:
_left = objects[start];
_right = objects[start + 1];
}
else
{
break;
case 2:
_left = objects[start + 1];
_right = objects[start];
}
}
else
{
objects.Sort(start, objectSpan - 1, new FuncComparer<IHittable>(Comparator));
int mid = start + objectSpan / 2;
_left = new BvhNode(objects, start, mid, sampler);
_right = new BvhNode(objects, mid, end, sampler);
break;
default:
objects.Sort(start, objectSpan - 1, new FuncComparer<IHittable>(Comparator));
int mid = start + objectSpan / 2;
_left = new BvhNode(objects, start, mid, sampler);
_right = new BvhNode(objects, mid, end, sampler);
break;
}

var boxLeft = _left.BoundingBox();
Expand Down

0 comments on commit c12bcf3

Please sign in to comment.