Skip to content

Commit

Permalink
#5460: Add unit test covering the behaviour - the workzone needs to b…
Browse files Browse the repository at this point in the history
…e recalculated everytime the user has finished a selection through the SelectionSystem API.

The lower level Node_setSelected() itself is not enough.
  • Loading branch information
codereader committed Feb 5, 2021
1 parent 0cbee8e commit 53d3d9c
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 7 deletions.
71 changes: 65 additions & 6 deletions test/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ishaders.h"
#include "ieclass.h"
#include "algorithm/Scene.h"
#include "algorithm/Primitives.h"
#include "scenelib.h"
#include "selectionlib.h"
#include "string/convert.h"
Expand Down Expand Up @@ -77,6 +78,17 @@ void constructCenteredOrthoview(render::View& view, const Vector3& origin)
view.construct(projection, modelView, DeviceWidth, DeviceHeight);
}

SelectionVolume constructOrthoviewSelectionTest(const render::View& orthoView)
{
render::View scissored(orthoView);

auto epsilon = registry::getValue<float>(RKEY_SELECT_EPSILON);
Vector2 deviceEpsilon(epsilon / DeviceWidth, epsilon / DeviceHeight);
ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(Vector2(0, 0), deviceEpsilon));

return SelectionVolume(scissored);
}

TEST_F(SelectionTest, ApplyShadersToForcedVisibleObjects)
{
loadMap("primitives_with_clip_material.map");
Expand Down Expand Up @@ -184,12 +196,7 @@ TEST_F(SelectionTest, PivotIsResetAfterCancelingOperation)
render::View view(false);
constructCenteredOrthoview(view, originalBrushPosition);

render::View scissored(view);
auto epsilon = registry::getValue<float>(RKEY_SELECT_EPSILON);
Vector2 deviceEpsilon(epsilon / DeviceWidth, epsilon / DeviceHeight);
ConstructSelectionTest(scissored, selection::Rectangle::ConstructFromPoint(Vector2(0,0), deviceEpsilon));

SelectionVolume test(scissored);
SelectionVolume test = constructOrthoviewSelectionTest(view);
activeManipulator->testSelect(test, originalPivot);

EXPECT_TRUE(activeManipulator->isSelected());
Expand All @@ -215,6 +222,58 @@ TEST_F(SelectionTest, PivotIsResetAfterCancelingOperation)
EXPECT_EQ(GlobalSelectionSystem().getPivot2World().t().getVector3(), originalBrushPosition);
}

// #5460: Workzone not recalculated after selection change if XY view "Show Size Info" setting is off
TEST_F(SelectionTest, WorkzoneIsRecalculatedAfterSelectionChange)
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();

AABB tallBounds(Vector3(0, 0, 0), Vector3(64, 256, 128));
AABB smallBounds(Vector3(300, 300, 300), Vector3(64, 32, 64));

auto tallBrush = algorithm::createCuboidBrush(worldspawn, tallBounds);
auto smallBrush = algorithm::createCuboidBrush(worldspawn, smallBounds);

EXPECT_EQ(tallBrush->worldAABB().getOrigin(), tallBounds.getOrigin());
EXPECT_EQ(tallBrush->worldAABB().getExtents(), tallBounds.getExtents());
EXPECT_EQ(smallBrush->worldAABB().getOrigin(), smallBounds.getOrigin());
EXPECT_EQ(smallBrush->worldAABB().getExtents(), smallBounds.getExtents());

GlobalSelectionSystem().setSelectedAll(false);

render::View orthoView(false);

// Construct an orthoview to test-select the tall brush
constructCenteredOrthoview(orthoView, tallBrush->worldAABB().getOrigin());
auto tallBrushTest = constructOrthoviewSelectionTest(orthoView);

// Select and de-select first brush
GlobalSelectionSystem().selectPoint(tallBrushTest, SelectionSystem::eToggle, false);
EXPECT_TRUE(Node_isSelected(tallBrush));

// Workzone should match the size of the tall brush
EXPECT_EQ(GlobalSelectionSystem().getWorkZone().bounds, tallBounds);

// De-select the tall brush
GlobalSelectionSystem().selectPoint(tallBrushTest, SelectionSystem::eToggle, false);
EXPECT_FALSE(Node_isSelected(tallBrush));

// Workzone should still match the size of the tall brush
EXPECT_EQ(GlobalSelectionSystem().getWorkZone().bounds, tallBounds);

// Construct an orthoview to test-select the smaller brush
constructCenteredOrthoview(orthoView, smallBrush->worldAABB().getOrigin());
auto smallBrushTest = constructOrthoviewSelectionTest(orthoView);

// Select and de-select second brush (no getWorkZone() call in between)
GlobalSelectionSystem().selectPoint(smallBrushTest, SelectionSystem::eToggle, false);
EXPECT_TRUE(Node_isSelected(smallBrush));
GlobalSelectionSystem().selectPoint(smallBrushTest, SelectionSystem::eToggle, false);
EXPECT_FALSE(Node_isSelected(smallBrush));

// Workzone should match the size of the small brush now
EXPECT_EQ(GlobalSelectionSystem().getWorkZone().bounds, smallBounds);
}

class ViewSelectionTest :
public SelectionTest
{
Expand Down
27 changes: 26 additions & 1 deletion test/algorithm/Primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ibrush.h"
#include "math/Plane3.h"
#include "math/AABB.h"

namespace test
{
Expand All @@ -10,7 +11,7 @@ namespace algorithm
{

// Creates a cubic brush with dimensions 64x64x64 at the given origin
scene::INodePtr createCubicBrush(const scene::INodePtr& parent,
inline scene::INodePtr createCubicBrush(const scene::INodePtr& parent,
const Vector3& origin = Vector3(0,0,0),
const std::string& material = "_default")
{
Expand All @@ -34,6 +35,30 @@ scene::INodePtr createCubicBrush(const scene::INodePtr& parent,
return brushNode;
}

inline scene::INodePtr createCuboidBrush(const scene::INodePtr& parent,
const AABB& bounds = AABB(Vector3(0, 0, 0), Vector3(64,256,128)),
const std::string& material = "_default")
{
auto brushNode = GlobalBrushCreator().createBrush();
parent->addChildNode(brushNode);

auto& brush = *Node_getIBrush(brushNode);

auto translation = Matrix4::getTranslation(-bounds.getOrigin());
brush.addFace(Plane3(+1, 0, 0, bounds.getExtents().x()).transform(translation));
brush.addFace(Plane3(-1, 0, 0, bounds.getExtents().x()).transform(translation));
brush.addFace(Plane3(0, +1, 0, bounds.getExtents().y()).transform(translation));
brush.addFace(Plane3(0, -1, 0, bounds.getExtents().y()).transform(translation));
brush.addFace(Plane3(0, 0, +1, bounds.getExtents().z()).transform(translation));
brush.addFace(Plane3(0, 0, -1, bounds.getExtents().z()).transform(translation));

brush.setShader(material);

brush.evaluateBRep();

return brushNode;
}

}

}

0 comments on commit 53d3d9c

Please sign in to comment.