MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / performPatchRotateTest

Function performPatchRotateTest

test/TextureManipulation.cpp:98–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96{
97
98void performPatchRotateTest(bool clockwise)
99{
100 auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
101 auto patchNode = algorithm::createPatchFromBounds(worldspawn, AABB(Vector3(4, 50, 60), Vector3(64, 128, 256)), "textures/numbers/1");
102
103 auto patch = Node_getIPatch(patchNode);
104 patch->scaleTextureNaturally();
105 patch->controlPointsChanged();
106
107 Node_setSelected(patchNode, true);
108
109 auto bounds = algorithm::getTextureSpaceBounds(*patch);
110
111 std::vector<Vector2> oldTexCoords;
112 algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl) { oldTexCoords.push_back(ctrl.texcoord); });
113
114 // Set the rotation in the registry, TexRotate will pick it up
115 constexpr auto angle = 15.0f;
116 registry::setValue("user/ui/textures/surfaceInspector/rotStep", angle);
117 GlobalCommandSystem().executeCommand("TexRotate", { cmd::Argument(clockwise ? "1" : "-1") });
118
119 // Rotate each texture coordinate around the patch center with a manual transform
120 auto transform = Matrix3::getTranslation({ -bounds.origin.x(), -bounds.origin.y() });
121 transform.premultiplyBy(Matrix3::getRotation(degrees_to_radians(clockwise ? angle : -angle)));
122 transform.premultiplyBy(Matrix3::getTranslation({ bounds.origin.x(), bounds.origin.y() }));
123
124 auto old = oldTexCoords.begin();
125 algorithm::foreachPatchVertex(*patch, [&](const PatchControl& ctrl)
126 {
127 auto transformed = transform * (*old++);
128 EXPECT_TRUE(math::isNear(transformed, ctrl.texcoord, 0.02))
129 << "Transformed UV coords should be " << transformed << " but was " << ctrl.texcoord;
130 });
131}
132
133}
134

Callers 1

TEST_FFunction · 0.85

Calls 15

createPatchFromBoundsFunction · 0.85
Node_getIPatchFunction · 0.85
Node_setSelectedFunction · 0.85
getTextureSpaceBoundsFunction · 0.85
foreachPatchVertexFunction · 0.85
setValueFunction · 0.85
degrees_to_radiansFunction · 0.85
scaleTextureNaturallyMethod · 0.80
xMethod · 0.80
yMethod · 0.80
AABBClass · 0.50
ArgumentClass · 0.50

Tested by

no test coverage detected