Skip to content

Commit

Permalink
Assert in computeBoundingBox()
Browse files Browse the repository at this point in the history
Use ptr in findSurfaceArea()
  • Loading branch information
vkoskiv committed Jan 27, 2020
1 parent 1b0cf6e commit ff5f285
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/acceleration/bbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "../datatypes/vertexbuffer.h"
#include "../datatypes/poly.h"
#include "../utils/assert.h"

/**
Get the longest axis of an axis-aligned bounding box
Expand All @@ -34,6 +35,8 @@ enum bboxAxis getLongestAxis(struct boundingBox *bbox) {
@return Axis-aligned bounding box
*/
struct boundingBox *computeBoundingBox(int *polys, int count) {
ASSERT(polys);
ASSERT(count > 0);
struct boundingBox *bbox = calloc(1, sizeof(struct boundingBox));
struct vector minPoint = vecWithPos(FLT_MAX, FLT_MAX, FLT_MAX);
struct vector maxPoint = vecWithPos(-FLT_MAX, -FLT_MAX, -FLT_MAX);
Expand Down Expand Up @@ -102,9 +105,9 @@ bool rayIntersectWithAABB(struct boundingBox *box, struct lightRay *ray, float *
return true;
}

float findSurfaceArea(struct boundingBox box) {
float width = box.end.x - box.start.x;
float height = box.end.y - box.start.y;
float length = box.end.z - box.start.z;
float findSurfaceArea(struct boundingBox *box) {
float width = box->end.x - box->start.x;
float height = box->end.y - box->start.y;
float length = box->end.z - box->start.z;
return 2 * (length * width) + 2 * (length * height) + 2 * (width * height);
}
2 changes: 1 addition & 1 deletion src/acceleration/bbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ bool rayIntersectWithAABB(struct boundingBox *box, struct lightRay *ray, float *

/// Compute the surface area of a given bounding box
/// @param box Bounding box to compute surface area for
float findSurfaceArea(struct boundingBox box);
float findSurfaceArea(struct boundingBox *box);
6 changes: 3 additions & 3 deletions src/acceleration/kdtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct kdTreeNode *buildTree(int *polygons, int polyCount) {
}

node->bbox = computeBoundingBox(node->polygons, node->polyCount);
float currentSAHCost = node->polyCount * findSurfaceArea(*node->bbox);
float currentSAHCost = node->polyCount * findSurfaceArea(node->bbox);

struct vector midPoint = node->bbox->midPoint;

Expand Down Expand Up @@ -122,8 +122,8 @@ struct kdTreeNode *buildTree(int *polygons, int polyCount) {
struct boundingBox *leftBBox = computeBoundingBox(leftPolys.array, (int)leftPolys.used);
struct boundingBox *rightBBox = computeBoundingBox(rightPolys.array, (int)rightPolys.used);

float leftSAHCost = leftPolys.used * findSurfaceArea(*leftBBox);
float rightSAHCost = rightPolys.used * findSurfaceArea(*rightBBox);
float leftSAHCost = leftPolys.used * findSurfaceArea(leftBBox);
float rightSAHCost = rightPolys.used * findSurfaceArea(rightBBox);

free(leftBBox);
free(rightBBox);
Expand Down

0 comments on commit ff5f285

Please sign in to comment.