Skip to content

Commit

Permalink
#5547: Add preliminary unit test for IPatch::normaliseTexture()
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 5, 2021
1 parent 7c61c84 commit ce0a9df
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
32 changes: 32 additions & 0 deletions test/TextureManipulation.cpp
Expand Up @@ -505,4 +505,36 @@ TEST_F(TextureManipulationTest, NormaliseFace)
EXPECT_TRUE(algorithm::faceHasVertex(face, Vector3(-992.0,-280.0,208.0), Vector2(-2.5, 0.75)));
}

TEST_F(TextureManipulationTest, NormalisePatch)
{
std::string mapPath = "maps/simple_brushes.map";
GlobalCommandSystem().executeCommand("OpenMap", mapPath);

auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
auto patchNode = algorithm::findFirstPatchWithMaterial(worldspawn, "textures/numbers/4");
auto patch = Node_getIPatch(patchNode);

EXPECT_TRUE(math::isNear(patch->ctrlAt(0, 0).texcoord, { 45.2263, 28.4018}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(1, 0).texcoord, { 43.855, 25.9462}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(2, 0).texcoord, { 42.4838, 23.4907}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(0, 1).texcoord, { 46.8088, 27.5181}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(1, 1).texcoord, { 45.4375, 25.0625}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(2, 1).texcoord, { 44.0662, 22.6069}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(0, 2).texcoord, { 48.3912, 26.6343}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(1, 2).texcoord, { 47.02, 24.1788}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(2, 2).texcoord, { 45.6487, 21.7232}, 0.01));

patch->normaliseTexture();

EXPECT_TRUE(math::isNear(patch->ctrlAt(0, 0).texcoord,{ 3.2263, 6.4018}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(1, 0).texcoord,{ 1.855, 3.9462}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(2, 0).texcoord,{ 0.4838, 1.4907}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(0, 1).texcoord,{ 4.8088, 5.5181}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(1, 1).texcoord,{ 3.4375, 3.0625}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(2, 1).texcoord,{ 2.0662, 0.6069}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(0, 2).texcoord,{ 6.3912, 4.6343}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(1, 2).texcoord,{ 5.02, 2.1788}, 0.01));
EXPECT_TRUE(math::isNear(patch->ctrlAt(2, 2).texcoord,{ 3.6487, 0.2768}, 0.01));
}

}
17 changes: 15 additions & 2 deletions test/resources/tdm/maps/simple_brushes.map
Expand Up @@ -34,20 +34,33 @@ brushDef3
( 0 1 0 24 ) ( ( 0.004186429083347321 0 2.054934978485107 ) ( 0 0.00506557896733284 0.3746414184570313 ) ) "textures/numbers/3" 0 0 0
( 1 0 0 -1176 ) ( ( 0.004044952336698771 -0.001084655988961458 0.5863834023475647 ) ( 0.001312433741986752 0.004894392099231482 56.02444076538086 ) ) "textures/numbers/3" 0 0 0
( 0 0 -1 192 ) ( ( 0.004186429083347321 0 1.236819624900818 ) ( 0 0.00506557896733284 3.002462148666382 ) ) "textures/numbers/3" 0 0 0
( 0 -0.8502650260925293 0.5263550281524658 -427.5620231628418 ) ( ( 0.004044952336698771 -0.001084655988961459 58.91525650024414 ) ( 0.001312433741986752 0.004894392099231482 58.65273284912109 ) ) "textures/numbers/3" 0 0 0
( 0 -0.8502650260925293 0.5263550281524658 -427.56201171875 ) ( ( 0.004044952336698771 -0.001084655988961458 58.91525650024414 ) ( 0.001312433741986752 0.004894392099231482 58.65273284912109 ) ) "textures/numbers/3" 0 0 0
( -1 0 0 944 ) ( ( 0.004186429083347321 0 62.76317977905273 ) ( 0 0.00506557896733284 0.3746414184570313 ) ) "textures/numbers/3" 0 0 0
}
}
// primitive 3
{
brushDef3
{
( 0 0 1 -376 ) ( ( 0.003266689270040298 0 -0.5408562421798706 ) ( 0 0.00343125305239949 0.3779624998569489 ) ) "textures/numbers/4" 0 0 0
( 0 0 1 -376 ) ( ( 0.003266689367592335 0 -0.5408562421798706 ) ( 0 0.003431253135204315 0.3779624998569489 ) ) "textures/numbers/4" 0 0 0
( 0 1 0 24 ) ( ( 0.004186429083347321 0 57.95000839233398 ) ( 0 0.00506557896733284 0.4556884765625 ) ) "textures/numbers/4" 0 0 0
( 1 0 0 760 ) ( ( 0.004044952336698771 -0.001084655988961458 0.56902676820755 ) ( 0.001312433741986752 0.004894392099231482 56.10275268554688 ) ) "textures/numbers/4" 0 0 0
( 0 0 -1 208 ) ( ( 0.004186429083347321 0 1.236819624900818 ) ( 0 0.00506557896733284 57.19549942016602 ) ) "textures/numbers/4" 0 0 0
( -1 0 0 -992 ) ( ( 0.004186429083347321 0 62.76318359375 ) ( 0 0.00506557896733284 0.4556884765625 ) ) "textures/numbers/4" 0 0 0
( 0 -1 0 -280 ) ( ( 0.015625 0 0 ) ( 0 0.015625 0 ) ) "textures/numbers/4" 0 0 0
}
}
// primitive 4
{
patchDef2
{
"textures/numbers/4"
( 3 3 0 0 0 )
(
( ( -336 -576.0000897296054 276 45.22630435546817 28.40176760625495 ) ( -336 -396.0000448648027 276 43.85502959701321 25.94620945989833 ) ( -336 -216 276 42.48375483855826 23.49065131354172 ) )
( ( -220 -576.0000897296054 276 46.80877475845495 27.51805743110088 ) ( -220 -396.0000448648027 276 45.4375 25.06249928474426 ) ( -220 -216 276 44.06622524154504 22.60694113838765 ) )
( ( -104 -576.0000897296054 276 48.39124516144173 26.6343472559468 ) ( -104 -396.0000448648027 276 47.01997040298677 24.17878910959019 ) ( -104 -216 276 45.64869564453182 21.72323096323357 ) )
)
}
}
}

0 comments on commit ce0a9df

Please sign in to comment.