This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/tests/geo/TestSphere3.cpp
FrankE 686151b511 worked on 2D/3D raytracing
adjusted BVH
improved 2D/3D BVH
new bounding volumes
new test cases
renamed some test-cases for grouping reasons
made GPC header-only using slight adjustments
2017-09-13 08:08:00 +02:00

64 lines
1.4 KiB
C++

#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../geo/Sphere3.h"
TEST(Geo_Sphere3, contains) {
Sphere3 a(Point3(0,0,0), 10);
Sphere3 b1(Point3(8,0,0), 1);
Sphere3 b2(Point3(0,8,0), 1);
Sphere3 b3(Point3(0,0,8), 1);
ASSERT_TRUE(a.contains(b1));
ASSERT_TRUE(a.contains(b2));
ASSERT_TRUE(a.contains(b3));
ASSERT_FALSE(b1.contains(a));
ASSERT_FALSE(b2.contains(a));
ASSERT_FALSE(b3.contains(a));
Sphere3 c1(Point3(8,0,0), 2.01);
Sphere3 c2(Point3(0,8,0), 2.01);
Sphere3 c3(Point3(0,0,8), 2.01);
ASSERT_FALSE(a.contains(c1));
ASSERT_FALSE(a.contains(c2));
ASSERT_FALSE(a.contains(c3));
ASSERT_FALSE(c1.contains(a));
ASSERT_FALSE(c2.contains(a));
ASSERT_FALSE(c3.contains(a));
}
TEST(Geo_Sphere3, join) {
// no overlap
Sphere3 a1(Point3(-1,0,0), 1);
Sphere3 a2(Point3(+1,0,0), 1);
Sphere3 a3 = Sphere3::join(a1, a2);
ASSERT_EQ(Point3(0,0,0), a3.center);
ASSERT_NEAR(2, a3.radius, 0.001);
// overlap
Sphere3 b1(Point3(-1,0,0), 1.5);
Sphere3 b2(Point3(+1,0,0), 1.5);
Sphere3 b3 = Sphere3::join(b1, b2);
ASSERT_EQ(Point3(0,0,0), b3.center);
ASSERT_NEAR(2.5, b3.radius, 0.001);
// fully within
Sphere3 c1(Point3(-1,0,0), 3.6);
Sphere3 c2(Point3(+1,0,0), 1.5);
Sphere3 c3 = Sphere3::join(c1, c2);
ASSERT_EQ(c1.center, c3.center);
ASSERT_NEAR(c1.radius, c3.radius, 0.001);
Sphere3 c4 = Sphere3::join(c2, c1);
ASSERT_EQ(c1.center, c4.center);
ASSERT_NEAR(c1.radius, c4.radius, 0.001);
}
#endif