Skip to content

Commit

Permalink
#5746: Add another test checking the area selection of a patch in the…
Browse files Browse the repository at this point in the history
… texture tool
  • Loading branch information
codereader committed Sep 18, 2021
1 parent 7c5da32 commit 4dd04b5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libs/Rectangle.h
Expand Up @@ -42,7 +42,7 @@ class Rectangle
return Rectangle(point - epsilon, point + epsilon);
}

// greebo: Constructs a Rectangle from (start - delta) to (start + delta) and ensures
// greebo: Constructs a Rectangle from (start) to (start + delta) and ensures
// that the resulting Rectangle's min is smaller than its max, in case delta has negative components
static Rectangle ConstructFromArea(const Vector2& start, const Vector2& delta)
{
Expand Down
44 changes: 41 additions & 3 deletions test/TextureTool.cpp
Expand Up @@ -219,19 +219,26 @@ inline AABB getTextureSpaceBounds(const IPatch& patch)
constexpr int TEXTOOL_WIDTH = 500;
constexpr int TEXTOOL_HEIGHT = 400;

TEST_F(TextureToolTest, TestSelectPatchVertex)
inline scene::INodePtr setupPatchNodeForTextureTool()
{
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto patchNode = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, 60), Vector3(64, 128, 256)), "textures/numbers/1");

auto patch = Node_getIPatch(patchNode);
patch->scaleTextureNaturally();
patch->controlPointsChanged();


// Select this node in the scene, to make it available in the texture tool
Node_setSelected(patchNode, true);

return patchNode;
}

TEST_F(TextureToolTest, TestSelectPatchByPoint)
{
auto patchNode = setupPatchNodeForTextureTool();
auto patch = Node_getIPatch(patchNode);

// Get the texture space bounds of this patch
auto bounds = getTextureSpaceBounds(*patch);

Expand Down Expand Up @@ -263,4 +270,35 @@ TEST_F(TextureToolTest, TestSelectPatchVertex)
EXPECT_EQ(selectedNodes.size(), 1) << "Only one patch should be selected";
}

TEST_F(TextureToolTest, TestSelectPatchByArea)
{
auto patchNode = setupPatchNodeForTextureTool();
auto patch = Node_getIPatch(patchNode);

// Get the texture space bounds of this patch
auto bounds = getTextureSpaceBounds(*patch);

// Construct a view that includes the patch UV bounds
bounds.extents *= 1.2f;

render::TextureToolView view;
view.constructFromTextureSpaceBounds(bounds, TEXTOOL_WIDTH, TEXTOOL_HEIGHT);

// Use the device point we calculated for this vertex and use it to construct a selection test
ConstructSelectionTest(view, selection::Rectangle::ConstructFromArea(Vector2(-0.95f, -0.95f), Vector2(0.95f*2, 0.95f*2)));

SelectionVolume test(view);
GlobalTextureToolSelectionSystem().selectArea(test, SelectionSystem::eToggle);

// Check if the node was selected
std::vector<textool::INode::Ptr> selectedNodes;
GlobalTextureToolSelectionSystem().foreachSelectedNode([&](const textool::INode::Ptr& node)
{
selectedNodes.push_back(node);
return true;
});

EXPECT_EQ(selectedNodes.size(), 1) << "Only one patch should be selected";
}

}

0 comments on commit 4dd04b5

Please sign in to comment.