Skip to content

Commit

Permalink
[flatten] move tests from manifold_test to boolean_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Mar 16, 2023
1 parent 1adafe8 commit 6fcf61b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
36 changes: 36 additions & 0 deletions test/boolean_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,3 +589,39 @@ TEST(Boolean, UnionDifference) {
float blocksize = block.GetProperties().volume;
EXPECT_NEAR(resultsize, blocksize * 2, 0.0001);
}

TEST(Boolean, BooleanVolumes) {
glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));

// Define solids which volumes are easy to compute w/ bit arithmetics:
// m1, m2, m4 are unique, non intersecting "bits" (of volume 1, 2, 4)
// m3 = m1 + m2
// m7 = m1 + m2 + m3
auto m1 = Manifold::Cube({1, 1, 1});
auto m2 = Manifold::Cube({2, 1, 1}).Transform(
glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0, 0)));
auto m4 = Manifold::Cube({4, 1, 1}).Transform(
glm::translate(glm::mat4(1.0f), glm::vec3(3.0f, 0, 0)));
auto m3 = Manifold::Cube({3, 1, 1});
auto m7 = Manifold::Cube({7, 1, 1});

EXPECT_FLOAT_EQ((m1 ^ m2).GetProperties().volume, 0);
EXPECT_FLOAT_EQ((m1 + m2 + m4).GetProperties().volume, 7);
EXPECT_FLOAT_EQ((m1 + m2 - m4).GetProperties().volume, 3);
EXPECT_FLOAT_EQ((m1 + (m2 ^ m4)).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 ^ m4).GetProperties().volume, 4);
EXPECT_FLOAT_EQ((m7 ^ m3 ^ m1).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 ^ (m1 + m2)).GetProperties().volume, 3);
EXPECT_FLOAT_EQ((m7 - m4).GetProperties().volume, 3);
EXPECT_FLOAT_EQ((m7 - m4 - m2).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 - (m7 - m1)).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 - (m1 + m2)).GetProperties().volume, 4);
}

TEST(Boolean, TreeTransforms) {
auto a = (Manifold::Cube({1, 1, 1}) + Manifold::Cube({1, 1, 1}))
.Translate({1, 0, 0});
auto b = (Manifold::Cube({1, 1, 1}) + Manifold::Cube({1, 1, 1}));

EXPECT_FLOAT_EQ((a + b).GetProperties().volume, 2);
}
36 changes: 0 additions & 36 deletions test/manifold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,39 +505,3 @@ TEST(Manifold, MirrorUnion) {
EXPECT_FLOAT_EQ(vol_a * 2.75, result.GetProperties().volume);
EXPECT_TRUE(a.Mirror(glm::vec3(0)).IsEmpty());
}

TEST(Manifold, BooleanVolumes) {
glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));

// Define solids which volumes are easy to compute w/ bit arithmetics:
// m1, m2, m4 are unique, non intersecting "bits" (of volume 1, 2, 4)
// m3 = m1 + m2
// m7 = m1 + m2 + m3
auto m1 = Manifold::Cube({1, 1, 1});
auto m2 = Manifold::Cube({2, 1, 1}).Transform(
glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0, 0)));
auto m4 = Manifold::Cube({4, 1, 1}).Transform(
glm::translate(glm::mat4(1.0f), glm::vec3(3.0f, 0, 0)));
auto m3 = Manifold::Cube({3, 1, 1});
auto m7 = Manifold::Cube({7, 1, 1});

EXPECT_FLOAT_EQ((m1 ^ m2).GetProperties().volume, 0);
EXPECT_FLOAT_EQ((m1 + m2 + m4).GetProperties().volume, 7);
EXPECT_FLOAT_EQ((m1 + m2 - m4).GetProperties().volume, 3);
EXPECT_FLOAT_EQ((m1 + (m2 ^ m4)).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 ^ m4).GetProperties().volume, 4);
EXPECT_FLOAT_EQ((m7 ^ m3 ^ m1).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 ^ (m1 + m2)).GetProperties().volume, 3);
EXPECT_FLOAT_EQ((m7 - m4).GetProperties().volume, 3);
EXPECT_FLOAT_EQ((m7 - m4 - m2).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 - (m7 - m1)).GetProperties().volume, 1);
EXPECT_FLOAT_EQ((m7 - (m1 + m2)).GetProperties().volume, 4);
}

TEST(Manifold, TreeTransforms) {
auto a = (Manifold::Cube({1, 1, 1}) + Manifold::Cube({1, 1, 1}))
.Translate({1, 0, 0});
auto b = (Manifold::Cube({1, 1, 1}) + Manifold::Cube({1, 1, 1}));

EXPECT_FLOAT_EQ((a + b).GetProperties().volume, 2);
}

0 comments on commit 6fcf61b

Please sign in to comment.