Skip to content

Commit

Permalink
Merge FaceTest and FacePlaneTest into a single BrushTest suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mott committed Mar 14, 2021
1 parent 5237935 commit 3bc8e30
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 87 deletions.
79 changes: 68 additions & 11 deletions test/FacePlane.cpp → test/Brush.cpp
@@ -1,25 +1,21 @@
#include "RadiantTest.h"

#include "ibrush.h"
#include "icommandsystem.h"
#include "imap.h"
#include "iselection.h"
#include "itransformable.h"
#include "imap.h"
#include "scenelib.h"
#include "math/Matrix4.h"
#include "math/Quaternion.h"
#include "math/Vector3.h"

namespace test
{

class FacePlaneTest :
public RadiantTest
class BrushTest: public RadiantTest
{
protected:
scene::INodePtr _brushNode;

void performTest(const std::function<bool(const IBrushNodePtr&)>& functor)
void testFacePlane(const std::function<bool(const IBrushNodePtr&)>& functor)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();

Expand All @@ -44,9 +40,70 @@ class FacePlaneTest :
}
};

TEST_F(FacePlaneTest, FacePlaneRotateWithMatrix)
inline bool isSane(const Matrix4& matrix)
{
for (std::size_t i = 0; i < 15; ++i)
{
if (std::isnan(matrix[i]) || std::isinf(matrix[i]))
{
return false;
}
}

return true;
}

TEST_F(BrushTest, FitTextureWithZeroScale)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();

auto brushNode = GlobalBrushCreator().createBrush();
worldspawn->addChildNode(brushNode);

GlobalSelectionSystem().setSelectedAll(false);
Node_setSelected(brushNode, true);

const double size = 15;
Vector3 startPos(-size, -size, -size);
Vector3 endPos(size, size, size);
GlobalCommandSystem().executeCommand("ResizeSelectedBrushesToBounds",
startPos, endPos, std::string("shader"));

GlobalSelectionSystem().setSelectedAll(false);

auto brush = std::dynamic_pointer_cast<IBrushNode>(brushNode);
brush->getIBrush().evaluateBRep();

// Apply a texdef with a 0 scale component to the first face
ShiftScaleRotation scr;

scr.shift[0] = 0.0f;
scr.shift[1] = 0.0f;
scr.scale[0] = 1.0f;
scr.scale[1] = 0.0f; // zero scale
scr.rotate = 0.0f;

auto& face = brush->getIBrush().getFace(0);

face.setShiftScaleRotation(scr);

auto matrix = face.getProjectionMatrix();
EXPECT_FALSE(isSane(matrix)); // 5th matrix component is INF at the least

// Now fit the texture
face.fitTexture(1, 1);

matrix = face.getProjectionMatrix();

// The whole matrix should be sane now
EXPECT_TRUE(isSane(matrix)) << "Texture Projection Matrix is not sane after fitting";

scene::removeNodeFromParent(brushNode);
}

TEST_F(BrushTest, FacePlaneRotateWithMatrix)
{
performTest([this](const IBrushNodePtr& brush)
testFacePlane([this](const IBrushNodePtr& brush)
{
// Get the plane facing down the x axis and check it
for (std::size_t i = 0; i < brush->getIBrush().getNumFaces(); ++i)
Expand Down Expand Up @@ -75,9 +132,9 @@ TEST_F(FacePlaneTest, FacePlaneRotateWithMatrix)
});
}

TEST_F(FacePlaneTest, FacePlaneTranslate)
TEST_F(BrushTest, FacePlaneTranslate)
{
performTest([this](const IBrushNodePtr& brush)
testFacePlane([this](const IBrushNodePtr& brush)
{
// Get the plane facing down the x axis and check it
for (std::size_t i = 0; i < brush->getIBrush().getNumFaces(); ++i)
Expand Down
3 changes: 1 addition & 2 deletions test/CMakeLists.txt
@@ -1,11 +1,10 @@
add_executable(drtest
Basic.cpp
Brush.cpp
Camera.cpp
ColourSchemes.cpp
CSG.cpp
Entity.cpp
Face.cpp
FacePlane.cpp
Favourites.cpp
FileTypes.cpp
HeadlessOpenGLContext.cpp
Expand Down
74 changes: 0 additions & 74 deletions test/Face.cpp

This file was deleted.

0 comments on commit 3bc8e30

Please sign in to comment.