Skip to content

Commit

Permalink
#5361: Port some FacePlane tests to the gtest project.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 25, 2020
1 parent a28f468 commit 54974a8
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 109 deletions.
3 changes: 3 additions & 0 deletions include/ibrush.h
Expand Up @@ -177,6 +177,9 @@ class IFace
*/
virtual ShiftScaleRotation getShiftScaleRotation() = 0;
virtual void setShiftScaleRotation(const ShiftScaleRotation& scr) = 0;

// Transforms this face plane with the given transformation matrix
virtual void transform(const Matrix4& transformation) = 0;
};

// Plane classification info used by splitting and CSG algorithms
Expand Down
5 changes: 5 additions & 0 deletions libs/math/Plane3.h
Expand Up @@ -85,6 +85,11 @@ class Plane3
float_equal_epsilon(_dist, other._dist, EPSILON_DIST);
}

bool operator!= (const Plane3& other) const
{
return !operator==(other);
}

// Subtracts plane equations: the returned plane is (a1-a2)*x + (b1-b2)*y + (c1-c2)*z + (d1-d2) = 0
Plane3 operator-(const Plane3& other) const
{
Expand Down
107 changes: 0 additions & 107 deletions radiant/test/facePlaneTest.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion radiantcore/brush/Face.h
Expand Up @@ -111,7 +111,7 @@ class Face :

void setRenderSystem(const RenderSystemPtr& renderSystem);

void transform(const Matrix4& matrix);
void transform(const Matrix4& matrix) override;

void assign_planepts(const PlanePoints planepts);

Expand Down
110 changes: 110 additions & 0 deletions test/FacePlane.cpp
@@ -0,0 +1,110 @@
#include "RadiantTest.h"

#include "ibrush.h"
#include "icommandsystem.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
{
protected:
scene::INodePtr _brushNode;

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

_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"));

auto result = functor(std::dynamic_pointer_cast<IBrushNode>(_brushNode));

scene::removeNodeFromParent(_brushNode);
_brushNode.reset();

EXPECT_TRUE(result) << "Test failed to perform anything.";
}
};

TEST_F(FacePlaneTest, FacePlaneRotateWithMatrix)
{
performTest([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)
{
auto& face = brush->getIBrush().getFace(i);

if (face.getPlane3().normal().isParallel(Vector3(1, 0, 0)))
{
Plane3 orig = face.getPlane3();

// Transform the plane with a rotation matrix
Matrix4 rot = Matrix4::getRotation(Vector3(0, 1, 0), 2);

Node_getTransformable(_brushNode)->setRotation(Quaternion::createForMatrix(rot));
Node_getTransformable(_brushNode)->freezeTransform();

EXPECT_NE(face.getPlane3(), orig);
EXPECT_EQ(face.getPlane3(), orig.transformed(rot));
EXPECT_NEAR(face.getPlane3().normal().getLength(), 1, 0.001);

return true;
}
}

return false;
});
}

TEST_F(FacePlaneTest, FacePlaneTranslate)
{
performTest([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)
{
auto& face = brush->getIBrush().getFace(i);

if (face.getPlane3().normal().isParallel(Vector3(0, 1, 0)))
{
Plane3 orig = face.getPlane3();

// Translate in the Y direction
const Vector3 translation(0, 3, 0);

Node_getTransformable(_brushNode)->setTranslation(translation);
Node_getTransformable(_brushNode)->freezeTransform();

EXPECT_NE(face.getPlane3(), orig);
EXPECT_EQ(face.getPlane3().normal(), orig.normal());
EXPECT_EQ(face.getPlane3().dist(), orig.dist() + translation.y());
EXPECT_NEAR(face.getPlane3().normal().getLength(), 1, 0.001);

return true;
}
}

return false;
});
}

}
1 change: 1 addition & 0 deletions test/Makefile.am
Expand Up @@ -28,5 +28,6 @@ drtest_SOURCES = Camera.cpp \
CSG.cpp \
HeadlessOpenGLContext.cpp \
Math.cpp \
FacePlane.cpp \
ModelScale.cpp \
SelectionAlgorithm.cpp
2 changes: 1 addition & 1 deletion test/Math.cpp
@@ -1,4 +1,4 @@
#include "RadiantTest.h"
#include "gtest/gtest.h"

#include "math/Matrix4.h"
#include "math/Quaternion.h"
Expand Down
2 changes: 2 additions & 0 deletions test/RadiantTest.h
Expand Up @@ -92,6 +92,8 @@ class RadiantTest :
}

_glContextModule->createContext();

GlobalMapModule().createNewMap();
}

void TearDown() override
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -63,6 +63,7 @@
<ItemGroup>
<ClCompile Include="..\..\..\test\Camera.cpp" />
<ClCompile Include="..\..\..\test\CSG.cpp" />
<ClCompile Include="..\..\..\test\FacePlane.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
<ClCompile Include="..\..\..\test\Math.cpp" />
<ClCompile Include="..\..\..\test\ModelScale.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -7,6 +7,7 @@
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
<ClCompile Include="..\..\..\test\ModelScale.cpp" />
<ClCompile Include="..\..\..\test\Math.cpp" />
<ClCompile Include="..\..\..\test\FacePlane.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit 54974a8

Please sign in to comment.