remove cmake warning about untestable CPP file

also: fix some broken unit tests
This commit is contained in:
Andrew Meadows 2016-10-05 13:06:36 -07:00
parent 4974c88880
commit 7642e9fd1e
5 changed files with 57 additions and 72 deletions

View file

@ -20,7 +20,7 @@
#include <CollisionRenderMeshCache.h>
#include <ShapeInfo.h> // for MAX_HULL_POINTS
#include "MeshUtil.cpp"
#include "MeshUtil.h"
QTEST_MAIN(CollisionRenderMeshCacheTests)

View file

@ -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;
}

View file

@ -42,8 +42,6 @@ private:
uint32_t _indexB { (uint32_t)(-1) };
};
bool isClosedManifold(const uint32_t* meshIndices, uint32_t numIndices);
} // MeshUtil namespace
namespace std {
@ -55,7 +53,39 @@ namespace std {
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

View file

@ -42,7 +42,7 @@ void ShapeInfoTests::testHashFunctions() {
int testCount = 0;
int numCollisions = 0;
btClock timer;
for (int x = 1; x < numSteps && testCount < maxTests; ++x) {
float radiusX = (float)x * deltaLength;
@ -52,7 +52,7 @@ void ShapeInfoTests::testHashFunctions() {
DoubleHashKey key = info.getHash();
uint32_t* hashPtr = hashes.find(key.getHash());
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()
<< " h2 = 0x" << std::hex << key.getHash2()
<< std::endl;
@ -88,7 +88,7 @@ void ShapeInfoTests::testHashFunctions() {
key = info.getHash();
hashPtr = hashes.find(key.getHash());
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()
<< " h2 = 0x" << std::hex << key.getHash2()
<< std::endl;
@ -113,8 +113,8 @@ void ShapeInfoTests::testHashFunctions() {
DoubleHashKey key = info.getHash();
hashPtr = hashes.find(key.getHash());
if (hashPtr && *hashPtr == key.getHash2()) {
std::cout << testCount << " hash collision radiusX = " << radiusX
<< " radiusY = " << radiusY << " radiusZ = " << radiusZ
std::cout << testCount << " hash collision radiusX = " << radiusX
<< " radiusY = " << radiusY << " radiusZ = " << radiusZ
<< " h1 = 0x" << std::hex << key.getHash()
<< " h2 = 0x" << std::hex << key.getHash2()
<< std::endl;
@ -148,9 +148,9 @@ void ShapeInfoTests::testBoxShape() {
info.setBox(halfExtents);
DoubleHashKey key = info.getHash();
btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
const btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
QCOMPARE(shape != nullptr, true);
ShapeInfo otherInfo = info;
DoubleHashKey otherKey = otherInfo.getHash();
QCOMPARE(key.getHash(), otherKey.getHash());
@ -165,7 +165,7 @@ void ShapeInfoTests::testSphereShape() {
info.setSphere(radius);
DoubleHashKey key = info.getHash();
btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
const btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info);
QCOMPARE(shape != nullptr, true);
ShapeInfo otherInfo = info;

View file

@ -27,14 +27,14 @@ void ShapeManagerTests::testShapeAccounting() {
QCOMPARE(numReferences, 0);
// 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);
// verify number of shapes
QCOMPARE(shapeManager.getNumShapes(), 1);
// 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);
// verify number of references
@ -84,7 +84,7 @@ void ShapeManagerTests::testShapeAccounting() {
void ShapeManagerTests::addManyShapes() {
ShapeManager shapeManager;
QVector<btCollisionShape*> shapes;
QVector<const btCollisionShape*> shapes;
int numSizes = 100;
float startSize = 1.0f;
@ -96,7 +96,7 @@ void ShapeManagerTests::addManyShapes() {
float s = startSize + (float)i * deltaSize;
glm::vec3 scale(s, 1.23f + s, s - 0.573f);
info.setBox(0.5f * scale);
btCollisionShape* shape = shapeManager.getShape(info);
const btCollisionShape* shape = shapeManager.getShape(info);
shapes.push_back(shape);
QCOMPARE(shape != nullptr, true);
@ -114,14 +114,14 @@ void ShapeManagerTests::addManyShapes() {
// release each shape by pointer
for (int i = 0; i < numShapes; ++i) {
btCollisionShape* shape = shapes[i];
const btCollisionShape* shape = shapes[i];
bool success = shapeManager.releaseShape(shape);
QCOMPARE(success, true);
}
// verify zero references
for (int i = 0; i < numShapes; ++i) {
btCollisionShape* shape = shapes[i];
const btCollisionShape* shape = shapes[i];
int numReferences = shapeManager.getNumReferences(shape);
QCOMPARE(numReferences, 0);
}
@ -133,10 +133,10 @@ void ShapeManagerTests::addBoxShape() {
info.setBox(halfExtents);
ShapeManager shapeManager;
btCollisionShape* shape = shapeManager.getShape(info);
const btCollisionShape* shape = shapeManager.getShape(info);
ShapeInfo otherInfo = info;
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
QCOMPARE(shape, otherShape);
}
@ -146,10 +146,10 @@ void ShapeManagerTests::addSphereShape() {
info.setSphere(radius);
ShapeManager shapeManager;
btCollisionShape* shape = shapeManager.getShape(info);
const btCollisionShape* shape = shapeManager.getShape(info);
ShapeInfo otherInfo = info;
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
QCOMPARE(shape, otherShape);
}
@ -161,10 +161,10 @@ void ShapeManagerTests::addCylinderShape() {
info.setCylinder(radius, height);
ShapeManager shapeManager;
btCollisionShape* shape = shapeManager.getShape(info);
const btCollisionShape* shape = shapeManager.getShape(info);
ShapeInfo otherInfo = info;
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
QCOMPARE(shape, otherShape);
*/
}
@ -177,10 +177,10 @@ void ShapeManagerTests::addCapsuleShape() {
info.setCapsule(radius, height);
ShapeManager shapeManager;
btCollisionShape* shape = shapeManager.getShape(info);
const btCollisionShape* shape = shapeManager.getShape(info);
ShapeInfo otherInfo = info;
btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
const btCollisionShape* otherShape = shapeManager.getShape(otherInfo);
QCOMPARE(shape, otherShape);
*/
}
@ -219,14 +219,14 @@ void ShapeManagerTests::addCompoundShape() {
// create the shape
ShapeManager shapeManager;
btCollisionShape* shape = shapeManager.getShape(info);
const btCollisionShape* shape = shapeManager.getShape(info);
QVERIFY(shape != nullptr);
// verify the shape is correct type
QCOMPARE(shape->getShapeType(), (int)COMPOUND_SHAPE_PROXYTYPE);
// 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);
// verify manager has only one shape