mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 06:18:52 +02:00
remove cmake warning about untestable CPP file
also: fix some broken unit tests
This commit is contained in:
parent
4974c88880
commit
7642e9fd1e
5 changed files with 57 additions and 72 deletions
|
@ -20,7 +20,7 @@
|
||||||
#include <CollisionRenderMeshCache.h>
|
#include <CollisionRenderMeshCache.h>
|
||||||
#include <ShapeInfo.h> // for MAX_HULL_POINTS
|
#include <ShapeInfo.h> // for MAX_HULL_POINTS
|
||||||
|
|
||||||
#include "MeshUtil.cpp"
|
#include "MeshUtil.h"
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(CollisionRenderMeshCacheTests)
|
QTEST_MAIN(CollisionRenderMeshCacheTests)
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
//
|
|
||||||
// MeshUtil.cpp
|
|
||||||
// tests/physics/src
|
|
||||||
//
|
|
||||||
// Created by Andrew Meadows 2016.07.14
|
|
||||||
// Copyright 2016 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "MeshUtil.h"
|
|
||||||
|
|
||||||
#include<unordered_map>
|
|
||||||
|
|
||||||
// returns false if any edge has only one adjacent triangle
|
|
||||||
bool MeshUtil::isClosedManifold(const uint32_t* meshIndices, uint32_t numIndices) {
|
|
||||||
using EdgeList = std::unordered_map<MeshUtil::TriangleEdge, uint32_t>;
|
|
||||||
EdgeList edges;
|
|
||||||
|
|
||||||
// count the triangles for each edge
|
|
||||||
const uint32_t TRIANGLE_STRIDE = 3;
|
|
||||||
for (uint32_t i = 0; i < numIndices; i += TRIANGLE_STRIDE) {
|
|
||||||
MeshUtil::TriangleEdge edge;
|
|
||||||
// the triangles indices are stored in sequential order
|
|
||||||
for (uint32_t j = 0; j < 3; ++j) {
|
|
||||||
edge.setIndices(meshIndices[i + j], meshIndices[i + ((j + 1) % 3)]);
|
|
||||||
|
|
||||||
EdgeList::iterator edgeEntry = edges.find(edge);
|
|
||||||
if (edgeEntry == edges.end()) {
|
|
||||||
edges.insert(std::pair<MeshUtil::TriangleEdge, uint32_t>(edge, 1));
|
|
||||||
} else {
|
|
||||||
edgeEntry->second += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// scan for outside edge
|
|
||||||
for (auto& edgeEntry : edges) {
|
|
||||||
if (edgeEntry.second == 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
|
@ -42,8 +42,6 @@ private:
|
||||||
uint32_t _indexB { (uint32_t)(-1) };
|
uint32_t _indexB { (uint32_t)(-1) };
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isClosedManifold(const uint32_t* meshIndices, uint32_t numIndices);
|
|
||||||
|
|
||||||
} // MeshUtil namespace
|
} // MeshUtil namespace
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
@ -55,7 +53,39 @@ namespace std {
|
||||||
return hash<uint32_t>()((ab * (ab + 1)) / 2 + edge.getIndexB());
|
return hash<uint32_t>()((ab * (ab + 1)) / 2 + edge.getIndexB());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
} // std namesspace
|
||||||
|
|
||||||
|
namespace MeshUtil {
|
||||||
|
bool isClosedManifold(const uint32_t* meshIndices, uint32_t numIndices) {
|
||||||
|
using EdgeList = std::unordered_map<TriangleEdge, uint32_t>;
|
||||||
|
EdgeList edges;
|
||||||
|
|
||||||
|
// count the triangles for each edge
|
||||||
|
const uint32_t TRIANGLE_STRIDE = 3;
|
||||||
|
for (uint32_t i = 0; i < numIndices; i += TRIANGLE_STRIDE) {
|
||||||
|
TriangleEdge edge;
|
||||||
|
// the triangles indices are stored in sequential order
|
||||||
|
for (uint32_t j = 0; j < 3; ++j) {
|
||||||
|
edge.setIndices(meshIndices[i + j], meshIndices[i + ((j + 1) % 3)]);
|
||||||
|
|
||||||
|
EdgeList::iterator edgeEntry = edges.find(edge);
|
||||||
|
if (edgeEntry == edges.end()) {
|
||||||
|
edges.insert(std::pair<TriangleEdge, uint32_t>(edge, 1));
|
||||||
|
} else {
|
||||||
|
edgeEntry->second += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// scan for outside edge
|
||||||
|
for (auto& edgeEntry : edges) {
|
||||||
|
if (edgeEntry.second == 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // MeshUtil namespace
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_MeshUtil_h
|
#endif // hifi_MeshUtil_h
|
||||||
|
|
|
@ -42,7 +42,7 @@ void ShapeInfoTests::testHashFunctions() {
|
||||||
|
|
||||||
int testCount = 0;
|
int testCount = 0;
|
||||||
int numCollisions = 0;
|
int numCollisions = 0;
|
||||||
|
|
||||||
btClock timer;
|
btClock timer;
|
||||||
for (int x = 1; x < numSteps && testCount < maxTests; ++x) {
|
for (int x = 1; x < numSteps && testCount < maxTests; ++x) {
|
||||||
float radiusX = (float)x * deltaLength;
|
float radiusX = (float)x * deltaLength;
|
||||||
|
@ -52,7 +52,7 @@ void ShapeInfoTests::testHashFunctions() {
|
||||||
DoubleHashKey key = info.getHash();
|
DoubleHashKey key = info.getHash();
|
||||||
uint32_t* hashPtr = hashes.find(key.getHash());
|
uint32_t* hashPtr = hashes.find(key.getHash());
|
||||||
if (hashPtr && *hashPtr == key.getHash2()) {
|
if (hashPtr && *hashPtr == key.getHash2()) {
|
||||||
std::cout << testCount << " hash collision radiusX = " << radiusX
|
std::cout << testCount << " hash collision radiusX = " << radiusX
|
||||||
<< " h1 = 0x" << std::hex << key.getHash()
|
<< " h1 = 0x" << std::hex << key.getHash()
|
||||||
<< " h2 = 0x" << std::hex << key.getHash2()
|
<< " h2 = 0x" << std::hex << key.getHash2()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -88,7 +88,7 @@ void ShapeInfoTests::testHashFunctions() {
|
||||||
key = info.getHash();
|
key = info.getHash();
|
||||||
hashPtr = hashes.find(key.getHash());
|
hashPtr = hashes.find(key.getHash());
|
||||||
if (hashPtr && *hashPtr == key.getHash2()) {
|
if (hashPtr && *hashPtr == key.getHash2()) {
|
||||||
std::cout << testCount << " hash collision radiusX = " << radiusX << " radiusY = " << radiusY
|
std::cout << testCount << " hash collision radiusX = " << radiusX << " radiusY = " << radiusY
|
||||||
<< " h1 = 0x" << std::hex << key.getHash()
|
<< " h1 = 0x" << std::hex << key.getHash()
|
||||||
<< " h2 = 0x" << std::hex << key.getHash2()
|
<< " h2 = 0x" << std::hex << key.getHash2()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -113,8 +113,8 @@ void ShapeInfoTests::testHashFunctions() {
|
||||||
DoubleHashKey key = info.getHash();
|
DoubleHashKey key = info.getHash();
|
||||||
hashPtr = hashes.find(key.getHash());
|
hashPtr = hashes.find(key.getHash());
|
||||||
if (hashPtr && *hashPtr == key.getHash2()) {
|
if (hashPtr && *hashPtr == key.getHash2()) {
|
||||||
std::cout << testCount << " hash collision radiusX = " << radiusX
|
std::cout << testCount << " hash collision radiusX = " << radiusX
|
||||||
<< " radiusY = " << radiusY << " radiusZ = " << radiusZ
|
<< " radiusY = " << radiusY << " radiusZ = " << radiusZ
|
||||||
<< " h1 = 0x" << std::hex << key.getHash()
|
<< " h1 = 0x" << std::hex << key.getHash()
|
||||||
<< " h2 = 0x" << std::hex << key.getHash2()
|
<< " h2 = 0x" << std::hex << key.getHash2()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
@ -148,9 +148,9 @@ void ShapeInfoTests::testBoxShape() {
|
||||||
info.setBox(halfExtents);
|
info.setBox(halfExtents);
|
||||||
DoubleHashKey key = info.getHash();
|
DoubleHashKey key = info.getHash();
|
||||||
|
|
||||||
btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
|
const btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
|
||||||
QCOMPARE(shape != nullptr, true);
|
QCOMPARE(shape != nullptr, true);
|
||||||
|
|
||||||
ShapeInfo otherInfo = info;
|
ShapeInfo otherInfo = info;
|
||||||
DoubleHashKey otherKey = otherInfo.getHash();
|
DoubleHashKey otherKey = otherInfo.getHash();
|
||||||
QCOMPARE(key.getHash(), otherKey.getHash());
|
QCOMPARE(key.getHash(), otherKey.getHash());
|
||||||
|
@ -165,7 +165,7 @@ void ShapeInfoTests::testSphereShape() {
|
||||||
info.setSphere(radius);
|
info.setSphere(radius);
|
||||||
DoubleHashKey key = info.getHash();
|
DoubleHashKey key = info.getHash();
|
||||||
|
|
||||||
btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
|
const btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
|
||||||
QCOMPARE(shape != nullptr, true);
|
QCOMPARE(shape != nullptr, true);
|
||||||
|
|
||||||
ShapeInfo otherInfo = info;
|
ShapeInfo otherInfo = info;
|
||||||
|
|
|
@ -27,14 +27,14 @@ void ShapeManagerTests::testShapeAccounting() {
|
||||||
QCOMPARE(numReferences, 0);
|
QCOMPARE(numReferences, 0);
|
||||||
|
|
||||||
// create one shape and verify we get a valid pointer
|
// create one shape and verify we get a valid pointer
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
QCOMPARE(shape != nullptr, true);
|
QCOMPARE(shape != nullptr, true);
|
||||||
|
|
||||||
// verify number of shapes
|
// verify number of shapes
|
||||||
QCOMPARE(shapeManager.getNumShapes(), 1);
|
QCOMPARE(shapeManager.getNumShapes(), 1);
|
||||||
|
|
||||||
// reference the shape again and verify that we get the same pointer
|
// reference the shape again and verify that we get the same pointer
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(info);
|
const btCollisionShape* otherShape = shapeManager.getShape(info);
|
||||||
QCOMPARE(otherShape, shape);
|
QCOMPARE(otherShape, shape);
|
||||||
|
|
||||||
// verify number of references
|
// verify number of references
|
||||||
|
@ -84,7 +84,7 @@ void ShapeManagerTests::testShapeAccounting() {
|
||||||
void ShapeManagerTests::addManyShapes() {
|
void ShapeManagerTests::addManyShapes() {
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
|
|
||||||
QVector<btCollisionShape*> shapes;
|
QVector<const btCollisionShape*> shapes;
|
||||||
|
|
||||||
int numSizes = 100;
|
int numSizes = 100;
|
||||||
float startSize = 1.0f;
|
float startSize = 1.0f;
|
||||||
|
@ -96,7 +96,7 @@ void ShapeManagerTests::addManyShapes() {
|
||||||
float s = startSize + (float)i * deltaSize;
|
float s = startSize + (float)i * deltaSize;
|
||||||
glm::vec3 scale(s, 1.23f + s, s - 0.573f);
|
glm::vec3 scale(s, 1.23f + s, s - 0.573f);
|
||||||
info.setBox(0.5f * scale);
|
info.setBox(0.5f * scale);
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
shapes.push_back(shape);
|
shapes.push_back(shape);
|
||||||
QCOMPARE(shape != nullptr, true);
|
QCOMPARE(shape != nullptr, true);
|
||||||
|
|
||||||
|
@ -114,14 +114,14 @@ void ShapeManagerTests::addManyShapes() {
|
||||||
|
|
||||||
// release each shape by pointer
|
// release each shape by pointer
|
||||||
for (int i = 0; i < numShapes; ++i) {
|
for (int i = 0; i < numShapes; ++i) {
|
||||||
btCollisionShape* shape = shapes[i];
|
const btCollisionShape* shape = shapes[i];
|
||||||
bool success = shapeManager.releaseShape(shape);
|
bool success = shapeManager.releaseShape(shape);
|
||||||
QCOMPARE(success, true);
|
QCOMPARE(success, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify zero references
|
// verify zero references
|
||||||
for (int i = 0; i < numShapes; ++i) {
|
for (int i = 0; i < numShapes; ++i) {
|
||||||
btCollisionShape* shape = shapes[i];
|
const btCollisionShape* shape = shapes[i];
|
||||||
int numReferences = shapeManager.getNumReferences(shape);
|
int numReferences = shapeManager.getNumReferences(shape);
|
||||||
QCOMPARE(numReferences, 0);
|
QCOMPARE(numReferences, 0);
|
||||||
}
|
}
|
||||||
|
@ -133,10 +133,10 @@ void ShapeManagerTests::addBoxShape() {
|
||||||
info.setBox(halfExtents);
|
info.setBox(halfExtents);
|
||||||
|
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo = info;
|
ShapeInfo otherInfo = info;
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
QCOMPARE(shape, otherShape);
|
QCOMPARE(shape, otherShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,10 +146,10 @@ void ShapeManagerTests::addSphereShape() {
|
||||||
info.setSphere(radius);
|
info.setSphere(radius);
|
||||||
|
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo = info;
|
ShapeInfo otherInfo = info;
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
QCOMPARE(shape, otherShape);
|
QCOMPARE(shape, otherShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,10 +161,10 @@ void ShapeManagerTests::addCylinderShape() {
|
||||||
info.setCylinder(radius, height);
|
info.setCylinder(radius, height);
|
||||||
|
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo = info;
|
ShapeInfo otherInfo = info;
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
QCOMPARE(shape, otherShape);
|
QCOMPARE(shape, otherShape);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -177,10 +177,10 @@ void ShapeManagerTests::addCapsuleShape() {
|
||||||
info.setCapsule(radius, height);
|
info.setCapsule(radius, height);
|
||||||
|
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
|
|
||||||
ShapeInfo otherInfo = info;
|
ShapeInfo otherInfo = info;
|
||||||
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
|
||||||
QCOMPARE(shape, otherShape);
|
QCOMPARE(shape, otherShape);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -219,14 +219,14 @@ void ShapeManagerTests::addCompoundShape() {
|
||||||
|
|
||||||
// create the shape
|
// create the shape
|
||||||
ShapeManager shapeManager;
|
ShapeManager shapeManager;
|
||||||
btCollisionShape* shape = shapeManager.getShape(info);
|
const btCollisionShape* shape = shapeManager.getShape(info);
|
||||||
QVERIFY(shape != nullptr);
|
QVERIFY(shape != nullptr);
|
||||||
|
|
||||||
// verify the shape is correct type
|
// verify the shape is correct type
|
||||||
QCOMPARE(shape->getShapeType(), (int)COMPOUND_SHAPE_PROXYTYPE);
|
QCOMPARE(shape->getShapeType(), (int)COMPOUND_SHAPE_PROXYTYPE);
|
||||||
|
|
||||||
// verify the shape has correct number of children
|
// verify the shape has correct number of children
|
||||||
btCompoundShape* compoundShape = static_cast<btCompoundShape*>(shape);
|
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
|
||||||
QCOMPARE(compoundShape->getNumChildShapes(), numHulls);
|
QCOMPARE(compoundShape->getNumChildShapes(), numHulls);
|
||||||
|
|
||||||
// verify manager has only one shape
|
// verify manager has only one shape
|
||||||
|
|
Loading…
Reference in a new issue