| 1279 | } |
| 1280 | |
| 1281 | void performPatchVertexManipulationTest(bool cancelOperation) |
| 1282 | { |
| 1283 | auto patchNode = setupPatchNodeForTextureTool(); |
| 1284 | auto patch = Node_getIPatch(patchNode); |
| 1285 | |
| 1286 | // Remember the texcoords before manipulation |
| 1287 | std::vector<Vector2> oldTexcoords; |
| 1288 | algorithm::foreachPatchVertex(*patch, [&](const PatchControl& control) { oldTexcoords.push_back(control.texcoord); }); |
| 1289 | |
| 1290 | // Get the texture space bounds of this patch |
| 1291 | auto bounds = algorithm::getTextureSpaceBounds(*patch); |
| 1292 | bounds.extents *= 1.2f; |
| 1293 | |
| 1294 | render::TextureToolView view; |
| 1295 | view.constructFromTextureSpaceBounds(bounds, TEXTOOL_WIDTH, TEXTOOL_HEIGHT); |
| 1296 | |
| 1297 | GlobalTextureToolSelectionSystem().setSelectionMode(textool::SelectionMode::Vertex); |
| 1298 | |
| 1299 | // Select every odd vertex |
| 1300 | for (auto i = 1; i < oldTexcoords.size(); i += 2) |
| 1301 | { |
| 1302 | performPointSelection(oldTexcoords[i], view); |
| 1303 | } |
| 1304 | |
| 1305 | EXPECT_EQ(getAllSelectedComponentNodes().size(), 1) << "No component node selected"; |
| 1306 | |
| 1307 | // Drag-manipulate the first odd vertex |
| 1308 | dragManipulateSelectionTowardsLowerRight(oldTexcoords[1], view, cancelOperation); // optionally cancel the operation |
| 1309 | |
| 1310 | std::vector<Vector2> changedTexcoords; |
| 1311 | algorithm::foreachPatchVertex(*patch, [&](const PatchControl& control) { changedTexcoords.push_back(control.texcoord); }); |
| 1312 | |
| 1313 | if (!cancelOperation) |
| 1314 | { |
| 1315 | // All odd texcoords should have been moved to the lower right (U increased, V increased) |
| 1316 | for (auto i = 0; i < oldTexcoords.size(); ++i) |
| 1317 | { |
| 1318 | if (i % 2 == 1) |
| 1319 | { |
| 1320 | EXPECT_LT(oldTexcoords[i].x(), changedTexcoords[i].x()); |
| 1321 | EXPECT_LT(oldTexcoords[i].y(), changedTexcoords[i].y()); |
| 1322 | } |
| 1323 | else |
| 1324 | { |
| 1325 | // should be unchanged |
| 1326 | EXPECT_NEAR(oldTexcoords[i].x(), changedTexcoords[i].x(), 0.01); |
| 1327 | EXPECT_NEAR(oldTexcoords[i].y(), changedTexcoords[i].y(), 0.01); |
| 1328 | } |
| 1329 | } |
| 1330 | } |
| 1331 | else // operation cancelled |
| 1332 | { |
| 1333 | // All texcoords should remain unchanged |
| 1334 | for (auto i = 0; i < oldTexcoords.size(); ++i) |
| 1335 | { |
| 1336 | // should be unchanged |
| 1337 | EXPECT_NEAR(oldTexcoords[i].x(), changedTexcoords[i].x(), 0.01); |
| 1338 | EXPECT_NEAR(oldTexcoords[i].y(), changedTexcoords[i].y(), 0.01); |
no test coverage detected