Skip to content

Commit

Permalink
#5382: Another test scenario of having multiple patches which are can…
Browse files Browse the repository at this point in the history
…didates of being merged together. The algorithm should be able to merge all 6 of them into 1, any path is valid. Expand unit tests.
  • Loading branch information
codereader committed Dec 13, 2020
1 parent 68e07fd commit 947b097
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 4 deletions.
63 changes: 63 additions & 0 deletions test/PatchWelding.cpp
Expand Up @@ -193,4 +193,67 @@ TEST_F(PatchWeldingTest, WeldedPatchInheritsSelectionGroups)
EXPECT_EQ(mergedNodeSelectionGroup->getGroupIds(), firstPatchGroups);
}

TEST_F(PatchWeldingTest, WeldMultipleSelectedPatches)
{
loadMap("weld_patches.mapx");

// Select all patches with the material 13
GlobalMapModule().findOrInsertWorldspawn()->foreachNode([&](const scene::INodePtr& node)
{
auto patchNode = std::dynamic_pointer_cast<IPatchNode>(node);

if (patchNode && patchNode->getPatch().getShader() == "textures/numbers/13")
{
Node_setSelected(node, true);
}

return true;
});

// Check the setup
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 6) << "Expected 6 patches with material 13, test map changed?";

// Execute the weld patches command three times, regardless of the order only one should remain
GlobalCommandSystem().executeCommand("WeldSelectedPatches");
GlobalCommandSystem().executeCommand("WeldSelectedPatches");
GlobalCommandSystem().executeCommand("WeldSelectedPatches");

EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "Expected 1 remaining patch with material 13";

// We might get a 7x9 or a 9x7 patch
auto& result = std::dynamic_pointer_cast<IPatchNode>(GlobalSelectionSystem().ultimateSelected())->getPatch();

EXPECT_EQ(std::max(result.getWidth(), result.getHeight()), 9);
EXPECT_EQ(std::min(result.getWidth(), result.getHeight()), 7);
}


TEST_F(PatchWeldingTest, WeldingIsUndoable)
{
loadMap("weld_patches.mapx");

{
auto firstPatch = findPatchWithNumber("1");
auto secondPatch = findPatchWithNumber("2");

EXPECT_TRUE(firstPatch && firstPatch->getParent());
EXPECT_TRUE(secondPatch && secondPatch->getParent());

Node_setSelected(firstPatch, true);
Node_setSelected(secondPatch, true);
}

GlobalCommandSystem().executeCommand("WeldSelectedPatches");

// Patches should be gone now
EXPECT_FALSE(findPatchWithNumber("1"));
EXPECT_FALSE(findPatchWithNumber("2"));

GlobalCommandSystem().executeCommand("Undo");

// Patches should be back again
EXPECT_TRUE(findPatchWithNumber("1"));
EXPECT_TRUE(findPatchWithNumber("2"));
}

}
158 changes: 154 additions & 4 deletions test/resources/tdm/maps/weld_patches.mapx
Expand Up @@ -7,10 +7,10 @@
<selectionGroups/>
<selectionSets/>
<properties>
<property key="EditTimeInSeconds" value="5444"/>
<property key="LastCameraAngle" value="-60 110.1 0"/>
<property key="LastCameraPosition" value="402.122 -354.216 590.801"/>
<property key="LastShaderClipboardMaterial" value="textures/numbers/11"/>
<property key="EditTimeInSeconds" value="5919"/>
<property key="LastCameraAngle" value="-60.6 85.2 0"/>
<property key="LastCameraPosition" value="439.949 -666.827 1100.6"/>
<property key="LastShaderClipboardMaterial" value="textures/numbers/13"/>
</properties>
<entity number="0">
<primitives>
Expand Down Expand Up @@ -185,6 +185,156 @@
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="7" width="5" height="3" fixedSubdivisions="false">
<material name="textures/numbers/13"/>
<controlVertices>
<controlVertex row="0" column="0" x="1106.000000" y="160.000000" z="0" u="0" v="0"/>
<controlVertex row="1" column="0" x="1106.000000" y="80.000000" z="0" u="0" v="0.500000"/>
<controlVertex row="2" column="0" x="1106.000000" y="16.000000" z="0" u="0" v="1.000000"/>
<controlVertex row="0" column="1" x="1070.000000" y="160.000000" z="0" u="-0.250000" v="0"/>
<controlVertex row="1" column="1" x="1070.000000" y="80.000000" z="0" u="-0.250000" v="0.500000"/>
<controlVertex row="2" column="1" x="1070.000000" y="4.000000" z="0" u="-0.250000" v="1.000000"/>
<controlVertex row="0" column="2" x="1034.000000" y="160.000000" z="0" u="-0.500000" v="0"/>
<controlVertex row="1" column="2" x="1034.000000" y="80.000000" z="0" u="-0.500000" v="0.500000"/>
<controlVertex row="2" column="2" x="1034.000000" y="-8.000000" z="0" u="-0.500000" v="1.000000"/>
<controlVertex row="0" column="3" x="998.000000" y="160.000000" z="0" u="-0.750000" v="0"/>
<controlVertex row="1" column="3" x="998.000000" y="80.000000" z="0" u="-0.750000" v="0.500000"/>
<controlVertex row="2" column="3" x="998.000000" y="4.000000" z="0" u="-0.750000" v="1.000000"/>
<controlVertex row="0" column="4" x="962.000000" y="160.000000" z="0" u="-1.000000" v="0"/>
<controlVertex row="1" column="4" x="962.000000" y="80.000000" z="0" u="-1.000000" v="0.500000"/>
<controlVertex row="2" column="4" x="962.000000" y="16.000000" z="0" u="-1.000000" v="1.000000"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="8" width="5" height="3" fixedSubdivisions="false">
<material name="textures/numbers/13"/>
<controlVertices>
<controlVertex row="0" column="0" x="962.000000" y="-112.000000" z="0" u="0" v="0"/>
<controlVertex row="1" column="0" x="962.000000" y="-48.000000" z="0" u="0" v="-0.500000"/>
<controlVertex row="2" column="0" x="962.000000" y="16.000000" z="0" u="0" v="-1.000000"/>
<controlVertex row="0" column="1" x="998.000000" y="-112.000000" z="0" u="0.250000" v="0"/>
<controlVertex row="1" column="1" x="998.000000" y="-48.000000" z="0" u="0.250000" v="-0.500000"/>
<controlVertex row="2" column="1" x="998.000000" y="4.000000" z="0" u="0.250000" v="-1.000000"/>
<controlVertex row="0" column="2" x="1034.000000" y="-112.000000" z="0" u="0.500000" v="0"/>
<controlVertex row="1" column="2" x="1034.000000" y="-48.000000" z="0" u="0.500000" v="-0.500000"/>
<controlVertex row="2" column="2" x="1034.000000" y="-8.000000" z="0" u="0.500000" v="-1.000000"/>
<controlVertex row="0" column="3" x="1070.000000" y="-112.000000" z="0" u="0.750000" v="0"/>
<controlVertex row="1" column="3" x="1070.000000" y="-48.000000" z="0" u="0.750000" v="-0.500000"/>
<controlVertex row="2" column="3" x="1070.000000" y="4.000000" z="0" u="0.750000" v="-1.000000"/>
<controlVertex row="0" column="4" x="1106.000000" y="-112.000000" z="0" u="1.000000" v="0"/>
<controlVertex row="1" column="4" x="1106.000000" y="-48.000000" z="0" u="1.000000" v="-0.500000"/>
<controlVertex row="2" column="4" x="1106.000000" y="16.000000" z="0" u="1.000000" v="-1.000000"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="9" width="3" height="5" fixedSubdivisions="false">
<material name="textures/numbers/13"/>
<controlVertices>
<controlVertex row="0" column="0" x="1106.000000" y="-240.000000" z="0" u="0" v="1.000000"/>
<controlVertex row="1" column="0" x="1070.000000" y="-240.000000" z="0" u="0" v="0.750000"/>
<controlVertex row="2" column="0" x="1034.000000" y="-240.000000" z="0" u="0" v="0.500000"/>
<controlVertex row="3" column="0" x="998.000000" y="-240.000000" z="0" u="0" v="0.250000"/>
<controlVertex row="4" column="0" x="962.000000" y="-240.000000" z="0" u="0" v="0"/>
<controlVertex row="0" column="1" x="1106.000000" y="-176.000000" z="0" u="0.500000" v="1.000000"/>
<controlVertex row="1" column="1" x="1070.000000" y="-176.000000" z="0" u="0.500000" v="0.750000"/>
<controlVertex row="2" column="1" x="1034.000000" y="-176.000000" z="0" u="0.500000" v="0.500000"/>
<controlVertex row="3" column="1" x="998.000000" y="-176.000000" z="0" u="0.500000" v="0.250000"/>
<controlVertex row="4" column="1" x="962.000000" y="-176.000000" z="0" u="0.500000" v="0"/>
<controlVertex row="0" column="2" x="1106.000000" y="-112.000000" z="0" u="1.000000" v="1.000000"/>
<controlVertex row="1" column="2" x="1070.000000" y="-112.000000" z="0" u="1.000000" v="0.750000"/>
<controlVertex row="2" column="2" x="1034.000000" y="-112.000000" z="0" u="1.000000" v="0.500000"/>
<controlVertex row="3" column="2" x="998.000000" y="-112.000000" z="0" u="1.000000" v="0.250000"/>
<controlVertex row="4" column="2" x="962.000000" y="-112.000000" z="0" u="1.000000" v="0"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="10" width="5" height="3" fixedSubdivisions="false">
<material name="textures/numbers/13"/>
<controlVertices>
<controlVertex row="0" column="0" x="1250.000000" y="160.000000" z="0" u="0" v="0"/>
<controlVertex row="1" column="0" x="1250.000000" y="80.000000" z="0" u="0" v="0.500000"/>
<controlVertex row="2" column="0" x="1250.000000" y="16.000000" z="0" u="0" v="1.000000"/>
<controlVertex row="0" column="1" x="1214.000000" y="160.000000" z="0" u="-0.250000" v="0"/>
<controlVertex row="1" column="1" x="1214.000000" y="80.000000" z="0" u="-0.250000" v="0.500000"/>
<controlVertex row="2" column="1" x="1214.000000" y="4.000000" z="0" u="-0.250000" v="1.000000"/>
<controlVertex row="0" column="2" x="1178.000000" y="160.000000" z="0" u="-0.500000" v="0"/>
<controlVertex row="1" column="2" x="1178.000000" y="80.000000" z="0" u="-0.500000" v="0.500000"/>
<controlVertex row="2" column="2" x="1178.000000" y="-8.000000" z="0" u="-0.500000" v="1.000000"/>
<controlVertex row="0" column="3" x="1142.000000" y="160.000000" z="0" u="-0.750000" v="0"/>
<controlVertex row="1" column="3" x="1142.000000" y="80.000000" z="0" u="-0.750000" v="0.500000"/>
<controlVertex row="2" column="3" x="1142.000000" y="4.000000" z="0" u="-0.750000" v="1.000000"/>
<controlVertex row="0" column="4" x="1106.000000" y="160.000000" z="0" u="-1.000000" v="0"/>
<controlVertex row="1" column="4" x="1106.000000" y="80.000000" z="0" u="-1.000000" v="0.500000"/>
<controlVertex row="2" column="4" x="1106.000000" y="16.000000" z="0" u="-1.000000" v="1.000000"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="11" width="5" height="3" fixedSubdivisions="false">
<material name="textures/numbers/13"/>
<controlVertices>
<controlVertex row="0" column="0" x="1106.000000" y="-112.000000" z="0" u="0" v="0"/>
<controlVertex row="1" column="0" x="1106.000000" y="-48.000000" z="0" u="0" v="-0.500000"/>
<controlVertex row="2" column="0" x="1106.000000" y="16.000000" z="0" u="0" v="-1.000000"/>
<controlVertex row="0" column="1" x="1142.000000" y="-112.000000" z="0" u="0.250000" v="0"/>
<controlVertex row="1" column="1" x="1142.000000" y="-48.000000" z="0" u="0.250000" v="-0.500000"/>
<controlVertex row="2" column="1" x="1142.000000" y="4.000000" z="0" u="0.250000" v="-1.000000"/>
<controlVertex row="0" column="2" x="1178.000000" y="-112.000000" z="0" u="0.500000" v="0"/>
<controlVertex row="1" column="2" x="1178.000000" y="-48.000000" z="0" u="0.500000" v="-0.500000"/>
<controlVertex row="2" column="2" x="1178.000000" y="-8.000000" z="0" u="0.500000" v="-1.000000"/>
<controlVertex row="0" column="3" x="1214.000000" y="-112.000000" z="0" u="0.750000" v="0"/>
<controlVertex row="1" column="3" x="1214.000000" y="-48.000000" z="0" u="0.750000" v="-0.500000"/>
<controlVertex row="2" column="3" x="1214.000000" y="4.000000" z="0" u="0.750000" v="-1.000000"/>
<controlVertex row="0" column="4" x="1250.000000" y="-112.000000" z="0" u="1.000000" v="0"/>
<controlVertex row="1" column="4" x="1250.000000" y="-48.000000" z="0" u="1.000000" v="-0.500000"/>
<controlVertex row="2" column="4" x="1250.000000" y="16.000000" z="0" u="1.000000" v="-1.000000"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
<patch number="12" width="3" height="5" fixedSubdivisions="false">
<material name="textures/numbers/13"/>
<controlVertices>
<controlVertex row="0" column="0" x="1250.000000" y="-240.000000" z="0" u="0" v="1.000000"/>
<controlVertex row="1" column="0" x="1214.000000" y="-240.000000" z="0" u="0" v="0.750000"/>
<controlVertex row="2" column="0" x="1178.000000" y="-240.000000" z="0" u="0" v="0.500000"/>
<controlVertex row="3" column="0" x="1142.000000" y="-240.000000" z="0" u="0" v="0.250000"/>
<controlVertex row="4" column="0" x="1106.000000" y="-240.000000" z="0" u="0" v="0"/>
<controlVertex row="0" column="1" x="1250.000000" y="-176.000000" z="0" u="0.500000" v="1.000000"/>
<controlVertex row="1" column="1" x="1214.000000" y="-176.000000" z="0" u="0.500000" v="0.750000"/>
<controlVertex row="2" column="1" x="1178.000000" y="-176.000000" z="0" u="0.500000" v="0.500000"/>
<controlVertex row="3" column="1" x="1142.000000" y="-176.000000" z="0" u="0.500000" v="0.250000"/>
<controlVertex row="4" column="1" x="1106.000000" y="-176.000000" z="0" u="0.500000" v="0"/>
<controlVertex row="0" column="2" x="1250.000000" y="-112.000000" z="0" u="1.000000" v="1.000000"/>
<controlVertex row="1" column="2" x="1214.000000" y="-112.000000" z="0" u="1.000000" v="0.750000"/>
<controlVertex row="2" column="2" x="1178.000000" y="-112.000000" z="0" u="1.000000" v="0.500000"/>
<controlVertex row="3" column="2" x="1142.000000" y="-112.000000" z="0" u="1.000000" v="0.250000"/>
<controlVertex row="4" column="2" x="1106.000000" y="-112.000000" z="0" u="1.000000" v="0"/>
</controlVertices>
<layers>
<layer id="0"/>
</layers>
<selectionGroups/>
<selectionSets/>
</patch>
</primitives>
<keyValues>
<keyValue key="classname" value="worldspawn"/>
Expand Down

0 comments on commit 947b097

Please sign in to comment.