MCPcopy Create free account
hub / github.com/crownengine/crown / test_sphere

Function test_sphere

src/core/unit_tests.cpp:995–1065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

993}
994
995static void test_sphere()
996{
997 {
998 Sphere a;
999 sphere::reset(a);
1000 ENSURE(a.c == VECTOR3_ZERO);
1001 ENSURE(fequal(a.r, 0.0f, 0.00001f));
1002 }
1003 {
1004 Sphere a;
1005 a.c = VECTOR3_ZERO;
1006 a.r = 1.61f;
1007 const float b = sphere::volume(a);
1008 ENSURE(fequal(b, 17.48099f, 0.00001f));
1009 }
1010 {
1011 Sphere a;
1012 a.c = { -2.3f, 1.2f, -4.5f };
1013 a.r = 1.0f;
1014 ENSURE(sphere::contains_point(a, { -2.9f, 1.6f, -4.0f }));
1015 ENSURE(sphere::contains_point(a, { -1.3f, 1.2f, -4.5f }));
1016 ENSURE(!sphere::contains_point(a, { -3.9f, 1.6f, -4.0f }));
1017 ENSURE(!sphere::contains_point(a, { -2.9f, 2.6f, -4.0f }));
1018 ENSURE(!sphere::contains_point(a, { -2.9f, 1.6f, -6.0f }));
1019 }
1020 {
1021 const Vector3 points[] =
1022 {
1023 { -15.0f, -1.0f, -1.0f },
1024 { -15.0f, -1.0f, -1.0f },
1025 { -17.0f, -1.0f, -1.0f }
1026 };
1027
1028 Sphere a;
1029 sphere::reset(a);
1030 sphere::add_points(a, countof(points), points);
1031 ENSURE(fequal(a.c.x, -16.0f, 0.00001f));
1032 ENSURE(fequal(a.c.y, -1.0f, 0.00001f));
1033 ENSURE(fequal(a.c.z, -1.0f, 0.00001f));
1034 ENSURE(fequal(a.r, 1.0f + FLOAT_EPSILON * 10.0f, 0.00001f));
1035 }
1036 {
1037 const Vector3 points[] =
1038 {
1039 { -1.2f, 3.4f, 5.5f },
1040 { 8.2f, -2.4f, -1.5f },
1041 { -5.9f, 9.2f, 6.0f },
1042
1043 { 6.6f, 3.5f, -5.7f },
1044 { -5.3f, -9.1f, -7.9f },
1045 { -1.5f, 4.4f, -5.8f },
1046
1047 { 7.2f, -2.4f, -9.5f },
1048 { 4.0f, -8.1f, 6.6f },
1049 { -8.2f, 2.2f, 4.6f },
1050
1051 { 2.9f, -4.8f, -6.8f },
1052 { -7.6f, -7.0f, 0.8f },

Callers

nothing calls this directly

Calls 2

add_pointsFunction · 0.85
resetFunction · 0.50

Tested by

no test coverage detected