diff --git a/libs/Rectangle.h b/libs/Rectangle.h index 9c4defaa1e..1c838e1c67 100644 --- a/libs/Rectangle.h +++ b/libs/Rectangle.h @@ -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) { diff --git a/test/TextureTool.cpp b/test/TextureTool.cpp index 6d4d06878c..ccff55cf17 100644 --- a/test/TextureTool.cpp +++ b/test/TextureTool.cpp @@ -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); @@ -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 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"; +} + }