From 4de94e43449e0b7d1c28b9b72a1f84484703a7d7 Mon Sep 17 00:00:00 2001 From: codereader Date: Tue, 8 Dec 2020 19:17:32 +0100 Subject: [PATCH] #5382: Welding algorithm works for the 3x3 patches in the weld_patches2 testmap --- radiantcore/patch/algorithm/General.cpp | 39 +++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/radiantcore/patch/algorithm/General.cpp b/radiantcore/patch/algorithm/General.cpp index 5ab4742f9f..71dc40c7be 100644 --- a/radiantcore/patch/algorithm/General.cpp +++ b/radiantcore/patch/algorithm/General.cpp @@ -498,11 +498,11 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo }; // Construct edge iterators for the first patch - // Iterator, EdgeLocation, Edge Length - auto patch1FirstRow = std::make_tuple(SinglePatchRowIterator(patch1, 0), Begin, Row, patch1.getWidth()); - auto patch1FirstCol = std::make_tuple(SinglePatchColumnIterator(patch1, 0), Begin, Column, patch1.getHeight()); - auto patch1LastRow = std::make_tuple(SinglePatchRowIterator(patch1, patch1.getHeight() - 1), End, Row, patch1.getWidth()); - auto patch1LastCol = std::make_tuple(SinglePatchColumnIterator(patch1, patch1.getWidth() - 1), End, Column, patch1.getHeight()); + // Iterator, Starting Point for copying data to new patch, Edge Length + auto patch1FirstRow = std::make_tuple(SinglePatchRowIterator(patch1, 0), RowWisePatchIterator(patch1, patch1.getHeight() - 1, 1), Row, patch1.getWidth()); + auto patch1FirstCol = std::make_tuple(SinglePatchColumnIterator(patch1, 0), ColumnWisePatchIterator(patch1, patch1.getWidth() - 1, 1), Column, patch1.getHeight()); + auto patch1LastRow = std::make_tuple(SinglePatchRowIterator(patch1, patch1.getHeight() - 1), RowWisePatchIterator(patch1, 0, patch1.getHeight() - 2), Row, patch1.getWidth()); + auto patch1LastCol = std::make_tuple(SinglePatchColumnIterator(patch1, patch1.getWidth() - 1), ColumnWisePatchIterator(patch1, 0, patch1.getWidth() - 2), Column, patch1.getHeight()); // We'll be comparing each of the above edges to all other four edges of the second patch // and we're doing it in forward and backward iteration, so we're trying to orient patch 2 @@ -517,7 +517,7 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo auto patch2LastRowReverse = std::make_tuple(RowWisePatchReverseIterator(patch2, patch2.getHeight() - 1, 0), End, patch2.getWidth()); auto patch2LastColReverse = std::make_tuple(ColumnWisePatchReverseIterator(patch2, patch2.getWidth() - 1, 0), End, patch2.getHeight()); - std::vector> patch1Edges = + std::vector> patch1Edges = { patch1FirstRow, patch1FirstCol, patch1LastRow, patch1LastCol }; std::vector> patch2Edges = @@ -535,7 +535,7 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo continue; // length don't match } - if (!firstNItemsAreEqual(std::get<0>(patch1Edge), std::get<0>(patch2Edge), std::get<2>(patch1Edge), WELD_EPSILON)) + if (!firstNItemsAreEqual(std::get<0>(patch1Edge), std::get<0>(patch2Edge), std::get<3>(patch1Edge), WELD_EPSILON)) { continue; } @@ -555,21 +555,24 @@ scene::INodePtr createdMergedPatch(const PatchNodePtr& patchNode1, const PatchNo auto& newPatch = std::dynamic_pointer_cast(newPatchNode)->getPatch(); newPatch.setDims(numNewColumns, numNewRows); - if (std::get<1>(patch1Edge) == Begin) + if (std::get<2>(patch1Edge) == Row) { - if (std::get<2>(patch1Edge) == Row) - { - RowWisePatchIterator target(newPatch); - RowWisePatchIterator source(patch1, patch1.getHeight() - 1, 1); - - assignPatchControls(source, target); - assignPatchControls(std::get<0>(patch2Edge), target); + RowWisePatchIterator target(newPatch); - newPatch.controlPointsChanged(); + assignPatchControls(std::get<1>(patch1Edge), target); + assignPatchControls(std::get<0>(patch2Edge), target); + } + else + { + ColumnWisePatchIterator target(newPatch); - return newPatchNode; - } + assignPatchControls(std::get<1>(patch1Edge), target); + assignPatchControls(std::get<0>(patch2Edge), target); } + + newPatch.controlPointsChanged(); + + return newPatchNode; } }