Skip to content

Commit 48664fa

Browse files
committed
refactor
1 parent 52e276b commit 48664fa

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/threepp/objects/BVH.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ std::unique_ptr<BVH::BVHNode> BVH::buildNode(std::vector<int>& indices, int dept
4444
if (size.z > size[axis]) axis = 2;
4545

4646
// Sort triangle indices along the longest axis
47-
std::sort(indices.begin(), indices.end(), [this, axis](int a, int b) {
47+
std::ranges::sort(indices, [this, axis](int a, int b) {
4848
Vector3 centerA, centerB;
4949
triangles[a].getMidpoint(centerA);
5050
triangles[b].getMidpoint(centerB);
5151
return centerA[axis] < centerB[axis];
5252
});
5353

5454
// Split triangles into two groups
55-
auto mid = indices.size() / 2;
55+
const auto mid = static_cast<int>(indices.size() / 2);
5656
std::vector<int> leftIndices(indices.begin(), indices.begin() + mid);
5757
std::vector<int> rightIndices(indices.begin() + mid, indices.end());
5858

@@ -74,17 +74,17 @@ void BVH::build(const BufferGeometry& geom) {
7474
if (geom.hasIndex()) {
7575
const auto index = geom.getIndex();
7676
for (int i = 0; i < index->count(); i += 3) {
77-
int a = index->getX(i);
78-
int b = index->getX(i + 1);
79-
int c = index->getX(i + 2);
77+
const auto a = index->getX(i);
78+
const auto b = index->getX(i + 1);
79+
const auto c = index->getX(i + 2);
8080

8181
Triangle tri(
8282
Vector3(posAttr->getX(a), posAttr->getY(a), posAttr->getZ(a)),
8383
Vector3(posAttr->getX(b), posAttr->getY(b), posAttr->getZ(b)),
8484
Vector3(posAttr->getX(c), posAttr->getY(c), posAttr->getZ(c)));
8585

8686
triangles.push_back(tri);
87-
indices.push_back(triangles.size() - 1);
87+
indices.push_back(static_cast<int>(triangles.size()) - 1);
8888
}
8989
} else {
9090
for (int i = 0; i < posAttr->count(); i += 3) {
@@ -94,7 +94,7 @@ void BVH::build(const BufferGeometry& geom) {
9494
Vector3(posAttr->getX(i + 2), posAttr->getY(i + 2), posAttr->getZ(i + 2)));
9595

9696
triangles.push_back(tri);
97-
indices.push_back(triangles.size() - 1);
97+
indices.push_back(static_cast<int>(triangles.size()) - 1);
9898
}
9999
}
100100

@@ -158,7 +158,7 @@ std::vector<int> BVH::intersect(const Sphere& sphere) const {
158158
for (int idx : node->triangleIndices) {
159159
Vector3 closestPoint;
160160
triangles[idx].closestPointToPoint(sphere.center, closestPoint);
161-
float distSq = closestPoint.distanceToSquared(sphere.center);
161+
const float distSq = closestPoint.distanceToSquared(sphere.center);
162162

163163
if (distSq <= (sphere.radius * sphere.radius)) {
164164
results.push_back(idx);
@@ -301,8 +301,8 @@ void BVH::intersectBVHNodes(const BVHNode* nodeA, const BVHNode* nodeB, std::vec
301301
Vector3 sizeA, sizeB;
302302
nodeA->boundingBox.getSize(sizeA);
303303
nodeB->boundingBox.getSize(sizeB);
304-
float volumeA = sizeA.x * sizeA.y * sizeA.z;
305-
float volumeB = sizeB.x * sizeB.y * sizeB.z;
304+
const float volumeA = sizeA.x * sizeA.y * sizeA.z;
305+
const float volumeB = sizeB.x * sizeB.y * sizeB.z;
306306

307307
if (volumeA < volumeB) {
308308
// A is smaller, descend A

0 commit comments

Comments
 (0)