Skip to content

Commit

Permalink
Applying linter fixes (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy authored Aug 25, 2020
1 parent f595118 commit 7fcb382
Show file tree
Hide file tree
Showing 22 changed files with 480 additions and 425 deletions.
41 changes: 38 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
"ranges": "cpp",
"compare": "cpp",
"concepts": "cpp",
"stop_token": "cpp"
"stop_token": "cpp",
"charconv": "cpp"
},
"json.schemas": [
{
Expand All @@ -116,7 +117,41 @@
"-build/include_subdir",
"-whitespace/braces",
"-readability/casting",
"-build/c++11"
"-build/c++11",
"-build/namespaces"
],
"clang-tidy.executable": "/usr/local/opt/llvm/bin/clang-tidy"
"clang-tidy.executable": "/usr/local/opt/llvm/bin/clang-tidy",
"clang-tidy.compilerArgs": [
"-xc++",
"-std=c++17",
"-I/usr/local/opt/llvm/include/c++/v1/"
],
"clang-tidy.lintOnSave": false,
"clang-tidy.buildPath": "${workspaceFolder}/build/vscode/x64-Release",
"clang-tidy.checks": [
"clang-diagnostic-*",
"clang-analyzer-*",
"performance-*",
"readability-*",
"-readability-braces-around-statements",
"-readability-uppercase-literal-suffix",
"-readability-magic-numbers",
"-readability-qualified-auto",
"-readability-else-after-return",
"-readability-isolate-declaration",
"portability-*",
"bugprone-*",
"-bugprone-narrowing-conversions",
"-bugprone-branch-clone",
"cppcoreguidelines-*",
"-cppcoreguidelines-avoid-magic-numbers",
"-cppcoreguidelines-pro-type-vararg",
"-cppcoreguidelines-pro-bounds-pointer-arithmetic",
"-cppcoreguidelines-narrowing-conversions",
"-cppcoreguidelines-special-member-functions",
"-cppcoreguidelines-pro-bounds-constant-array-index",
"modernize-*",
"-modernize-use-nodiscard",
"-modernize-use-trailing-return-type"
]
}
2 changes: 1 addition & 1 deletion libs/yocto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ endif(YOCTO_EMBREE)

# warning flags
if(APPLE)
target_compile_options(yocto PUBLIC -Wall -Wconversion -Wno-sign-conversion -Wno-implicit-float-conversion -ftime-trace)
target_compile_options(yocto PUBLIC -Wall -Wconversion -Wno-sign-conversion -Wno-implicit-float-conversion)
endif(APPLE)
if(MSVC)
target_compile_options(yocto PUBLIC /D_CRT_SECURE_NO_WARNINGS /wd4018 /wd4244 /wd4305 /wd4800 /wd4267)
Expand Down
135 changes: 69 additions & 66 deletions libs/yocto/yocto_bvh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include "yocto_bvh.h"

#include <algorithm>
#include <array>
#include <atomic>
#include <cstring>
#include <deque>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>

#include "yocto_geometry.h"

Expand All @@ -28,6 +30,7 @@
namespace yocto {

// using directives
using std::array;
using std::atomic;
using std::deque;
using std::pair;
Expand Down Expand Up @@ -323,7 +326,7 @@ static pair<int, int> split_sah(vector<int>& primitives,
if (mid == start || mid == end) {
split_axis = 0;
mid = (start + end) / 2;
throw std::runtime_error{"bad bvh split"};
// throw std::runtime_error{"bad bvh split"};
}

return {mid, split_axis};
Expand Down Expand Up @@ -362,7 +365,7 @@ static pair<int, int> split_balanced(vector<int>& primitives,
if (mid == start || mid == end) {
axis = 0;
mid = (start + end) / 2;
throw std::runtime_error("bad bvh split");
// throw std::runtime_error("bad bvh split");
}

return {mid, axis};
Expand Down Expand Up @@ -401,7 +404,7 @@ static pair<int, int> split_middle(vector<int>& primitives,
if (mid == start || mid == end) {
axis = 0;
mid = (start + end) / 2;
throw std::runtime_error("bad bvh split");
// throw std::runtime_error("bad bvh split");
}

return {mid, axis};
Expand Down Expand Up @@ -544,8 +547,8 @@ void init_shape_bvh(bvh_shape* shape, bool embree) {

void init_scene_bvh(bvh_scene* scene, bool embree) {
// Make shape bvh
for (auto idx = 0; idx < scene->shapes.size(); idx++) {
init_shape_bvh(scene->shapes[idx], embree);
for (auto shape : scene->shapes) {
init_shape_bvh(shape, embree);
}

// embree
Expand Down Expand Up @@ -649,7 +652,7 @@ static bool intersect_shape_bvh(const bvh_shape* shape, const ray3f& ray_,
if (shape->bvh.nodes.empty()) return false;

// node stack
int node_stack[128];
auto node_stack = array<int, 128>{};
auto node_cur = 0;
node_stack[node_cur++] = 0;

Expand All @@ -665,7 +668,7 @@ static bool intersect_shape_bvh(const bvh_shape* shape, const ray3f& ray_,
(ray_dinv.z < 0) ? 1 : 0};

// walking stack
while (node_cur) {
while (node_cur != 0) {
// grab node
auto& node = shape->bvh.nodes[node_stack[--node_cur]];

Expand All @@ -678,7 +681,7 @@ static bool intersect_shape_bvh(const bvh_shape* shape, const ray3f& ray_,
if (node.internal) {
// for internal nodes, attempts to proceed along the
// split axis from smallest to largest nodes
if (ray_dsign[node.axis]) {
if (ray_dsign[node.axis] != 0) {
node_stack[node_cur++] = node.start + 0;
node_stack[node_cur++] = node.start + 1;
} else {
Expand Down Expand Up @@ -750,7 +753,7 @@ static bool intersect_scene_bvh(const bvh_scene* scene, const ray3f& ray_,
if (scene->bvh.nodes.empty()) return false;

// node stack
int node_stack[128];
auto node_stack = array<int, 128>{};
auto node_cur = 0;
node_stack[node_cur++] = 0;

Expand All @@ -766,7 +769,7 @@ static bool intersect_scene_bvh(const bvh_scene* scene, const ray3f& ray_,
(ray_dinv.z < 0) ? 1 : 0};

// walking stack
while (node_cur) {
while (node_cur != 0) {
// grab node
auto& node = scene->bvh.nodes[node_stack[--node_cur]];

Expand All @@ -779,7 +782,7 @@ static bool intersect_scene_bvh(const bvh_scene* scene, const ray3f& ray_,
if (node.internal) {
// for internal nodes, attempts to proceed along the
// split axis from smallest to largest nodes
if (ray_dsign[node.axis]) {
if (ray_dsign[node.axis] != 0) {
node_stack[node_cur++] = node.start + 0;
node_stack[node_cur++] = node.start + 1;
} else {
Expand Down Expand Up @@ -826,15 +829,15 @@ static bool overlap_shape_bvh(const bvh_shape* shape, const vec3f& pos,
if (shape->bvh.nodes.empty()) return false;

// node stack
int node_stack[64];
auto node_stack = array<int, 64>{};
auto node_cur = 0;
node_stack[node_cur++] = 0;

// hit
auto hit = false;

// walking stack
while (node_cur) {
while (node_cur != 0) {
// grab node
auto& node = shape->bvh.nodes[node_stack[--node_cur]];

Expand Down Expand Up @@ -913,15 +916,15 @@ static bool overlap_scene_bvh(const bvh_scene* scene, const vec3f& pos,
if (scene->bvh.nodes.empty()) return false;

// node stack
int node_stack[64];
auto node_stack = array<int, 64>{};
auto node_cur = 0;
node_stack[node_cur++] = 0;

// hit
auto hit = false;

// walking stack
while (node_cur) {
while (node_cur != 0) {
// grab node
auto& node = scene->bvh.nodes[node_stack[--node_cur]];

Expand Down Expand Up @@ -957,64 +960,64 @@ static bool overlap_scene_bvh(const bvh_scene* scene, const vec3f& pos,
}

#if 0
// Finds the overlap between BVH leaf nodes.
template <typename OverlapElem>
void overlap_bvh_elems(const bvh_scene_data& bvh1, const bvh_scene_data& bvh2,
bool skip_duplicates, bool skip_self, vector<vec2i>& overlaps,
const OverlapElem& overlap_elems) {
// node stack
vec2i node_stack[128];
auto node_cur = 0;
node_stack[node_cur++] = {0, 0};

// walking stack
while (node_cur) {
// grab node
auto node_idx = node_stack[--node_cur];
const auto node1 = bvh1->nodes[node_idx.x];
const auto node2 = bvh2->nodes[node_idx.y];

// intersect bbox
if (!overlap_bbox(node1.bbox, node2.bbox)) continue;

// check for leaves
if (node1.isleaf && node2.isleaf) {
// collide primitives
for (auto i1 = node1.start; i1 < node1.start + node1.count; i1++) {
for (auto i2 = node2.start; i2 < node2.start + node2.count;
i2++) {
auto idx1 = bvh1->sorted_prim[i1];
auto idx2 = bvh2->sorted_prim[i2];
if (skip_duplicates && idx1 > idx2) continue;
if (skip_self && idx1 == idx2) continue;
if (overlap_elems(idx1, idx2))
overlaps.push_back({idx1, idx2});
}
// Finds the overlap between BVH leaf nodes.
template <typename OverlapElem>
void overlap_bvh_elems(const bvh_scene_data& bvh1, const bvh_scene_data& bvh2,
bool skip_duplicates, bool skip_self, vector<vec2i>& overlaps,
const OverlapElem& overlap_elems) {
// node stack
vec2i node_stack[128];
auto node_cur = 0;
node_stack[node_cur++] = {0, 0};

// walking stack
while (node_cur) {
// grab node
auto node_idx = node_stack[--node_cur];
const auto node1 = bvh1->nodes[node_idx.x];
const auto node2 = bvh2->nodes[node_idx.y];

// intersect bbox
if (!overlap_bbox(node1.bbox, node2.bbox)) continue;

// check for leaves
if (node1.isleaf && node2.isleaf) {
// collide primitives
for (auto i1 = node1.start; i1 < node1.start + node1.count; i1++) {
for (auto i2 = node2.start; i2 < node2.start + node2.count;
i2++) {
auto idx1 = bvh1->sorted_prim[i1];
auto idx2 = bvh2->sorted_prim[i2];
if (skip_duplicates && idx1 > idx2) continue;
if (skip_self && idx1 == idx2) continue;
if (overlap_elems(idx1, idx2))
overlaps.push_back({idx1, idx2});
}
}
} else {
// descend
if (node1.isleaf) {
for (auto idx2 = node2.start; idx2 < node2.start + node2.count;
idx2++) {
node_stack[node_cur++] = {node_idx.x, (int)idx2};
}
} else if (node2.isleaf) {
for (auto idx1 = node1.start; idx1 < node1.start + node1.count;
idx1++) {
node_stack[node_cur++] = {(int)idx1, node_idx.y};
}
} else {
// descend
if (node1.isleaf) {
for (auto idx2 = node2.start; idx2 < node2.start + node2.count;
idx2++) {
node_stack[node_cur++] = {node_idx.x, (int)idx2};
}
} else if (node2.isleaf) {
for (auto idx1 = node1.start; idx1 < node1.start + node1.count;
idx1++) {
node_stack[node_cur++] = {(int)idx1, node_idx.y};
}
} else {
for (auto idx2 = node2.start; idx2 < node2.start + node2.count;
idx2++) {
for (auto idx1 = node1.start;
idx1 < node1.start + node1.count; idx1++) {
node_stack[node_cur++] = {(int)idx1, (int)idx2};
}
for (auto idx2 = node2.start; idx2 < node2.start + node2.count;
idx2++) {
for (auto idx1 = node1.start;
idx1 < node1.start + node1.count; idx1++) {
node_stack[node_cur++] = {(int)idx1, (int)idx2};
}
}
}
}
}
}
#endif

bvh_shape_intersection intersect_shape_bvh(
Expand Down
10 changes: 5 additions & 5 deletions libs/yocto/yocto_bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ const int bvh_max_prims = 4;
// and the split axis. Leaf and internal nodes are identical, except that
// indices refer to primitives for leaf nodes or other nodes for internal nodes.
struct bvh_node_ {
bbox3f bbox;
int32_t start;
int16_t num;
int8_t axis;
bool internal;
bbox3f bbox = invalidb3f;
int32_t start = 0;
int16_t num = 0;
int8_t axis = 0;
bool internal = false;
};

// BVH tree stored as a node array with the tree structure is encoded using
Expand Down
2 changes: 1 addition & 1 deletion libs/yocto/yocto_commonio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bool save_binary(
error = filename + ": file not found";
return false;
}
if (!write_values(fs, data.data(), data.size()) != data.size()) {
if (!write_values(fs, data.data(), data.size())) {
error = filename + ": write error";
return false;
}
Expand Down
Loading

0 comments on commit 7fcb382

Please sign in to comment.