Merge pull request #51812 from aaronfranke/test-variant-geom
Fixes to tests for Variant and Geometry3D
This commit is contained in:
commit
2da6641e3d
4 changed files with 45 additions and 25 deletions
|
@ -1423,7 +1423,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
p_store_string_func(p_store_string_ud, itos(p_variant.operator int64_t()));
|
||||
} break;
|
||||
case Variant::FLOAT: {
|
||||
String s = rtosfix(p_variant.operator real_t());
|
||||
String s = rtosfix(p_variant.operator double());
|
||||
if (s != "inf" && s != "nan") {
|
||||
if (s.find(".") == -1 && s.find("e") == -1) {
|
||||
s += ".0";
|
||||
|
|
|
@ -2104,7 +2104,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|||
grests.resize(skel->get_bone_count());
|
||||
|
||||
LocalVector<int> bones;
|
||||
LocalVector<real_t> weights;
|
||||
LocalVector<float> weights;
|
||||
bones.resize(4);
|
||||
weights.resize(4);
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef TEST_3D_GEOMETRY_H
|
||||
#define TEST_3D_GEOMETRY_H
|
||||
#ifndef TEST_GEOMETRY_3D_H
|
||||
#define TEST_GEOMETRY_3D_H
|
||||
|
||||
#include "core/math/geometry_3d.h"
|
||||
#include "core/math/plane.h"
|
||||
|
@ -38,7 +38,7 @@
|
|||
#include "tests/test_macros.h"
|
||||
#include "vector"
|
||||
|
||||
namespace Test3DGeometry {
|
||||
namespace TestGeometry3D {
|
||||
TEST_CASE("[Geometry3D] Closest Points Between Segments") {
|
||||
struct Case {
|
||||
Vector3 p_1, p_2, p_3, p_4;
|
||||
|
@ -57,6 +57,7 @@ TEST_CASE("[Geometry3D] Closest Points Between Segments") {
|
|||
CHECK(current_case.got_2.is_equal_approx(current_case.want_2));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Closest Distance Between Segments") {
|
||||
struct Case {
|
||||
Vector3 p_1, p_2, p_3, p_4;
|
||||
|
@ -73,6 +74,7 @@ TEST_CASE("[Geometry3D] Closest Distance Between Segments") {
|
|||
CHECK(out == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Build Box Planes") {
|
||||
const Vector3 extents = Vector3(5, 5, 20);
|
||||
Vector<Plane> box = Geometry3D::build_box_planes(extents);
|
||||
|
@ -90,6 +92,7 @@ TEST_CASE("[Geometry3D] Build Box Planes") {
|
|||
CHECK(extents.z == box[5].d);
|
||||
CHECK(box[5].normal == Vector3(0, 0, -1));
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Build Capsule Planes") {
|
||||
struct Case {
|
||||
real_t radius, height;
|
||||
|
@ -109,6 +112,7 @@ TEST_CASE("[Geometry3D] Build Capsule Planes") {
|
|||
CHECK(capsule.size() == current_case.want_size);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Build Cylinder Planes") {
|
||||
struct Case {
|
||||
real_t radius, height;
|
||||
|
@ -127,6 +131,7 @@ TEST_CASE("[Geometry3D] Build Cylinder Planes") {
|
|||
CHECK(planes.size() == current_case.want_size);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Build Sphere Planes") {
|
||||
struct Case {
|
||||
real_t radius;
|
||||
|
@ -145,6 +150,7 @@ TEST_CASE("[Geometry3D] Build Sphere Planes") {
|
|||
CHECK(planes.size() == 63);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Build Convex Mesh") {
|
||||
struct Case {
|
||||
Vector<Plane> object;
|
||||
|
@ -166,6 +172,7 @@ TEST_CASE("[Geometry3D] Build Convex Mesh") {
|
|||
CHECK(mesh.vertices.size() == current_case.want_vertices);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Clip Polygon") {
|
||||
struct Case {
|
||||
Plane clipping_plane;
|
||||
|
@ -190,6 +197,7 @@ TEST_CASE("[Geometry3D] Clip Polygon") {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Compute Convex Mesh Points") {
|
||||
struct Case {
|
||||
Vector<Plane> mesh;
|
||||
|
@ -215,6 +223,7 @@ TEST_CASE("[Geometry3D] Compute Convex Mesh Points") {
|
|||
CHECK(vectors == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Get Closest Point To Segment") {
|
||||
struct Case {
|
||||
Vector3 point;
|
||||
|
@ -235,6 +244,7 @@ TEST_CASE("[Geometry3D] Get Closest Point To Segment") {
|
|||
CHECK(output.is_equal_approx(current_case.want));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Plane and Box Overlap") {
|
||||
struct Case {
|
||||
Vector3 normal, max_box;
|
||||
|
@ -254,6 +264,7 @@ TEST_CASE("[Geometry3D] Plane and Box Overlap") {
|
|||
CHECK(overlap == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Is Point in Projected Triangle") {
|
||||
struct Case {
|
||||
Vector3 point, v_1, v_2, v_3;
|
||||
|
@ -272,6 +283,7 @@ TEST_CASE("[Geometry3D] Is Point in Projected Triangle") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Does Ray Intersect Triangle") {
|
||||
struct Case {
|
||||
Vector3 from, direction, v_1, v_2, v_3;
|
||||
|
@ -291,6 +303,7 @@ TEST_CASE("[Geometry3D] Does Ray Intersect Triangle") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Does Segment Intersect Convex") {
|
||||
struct Case {
|
||||
Vector3 from, to;
|
||||
|
@ -311,6 +324,7 @@ TEST_CASE("[Geometry3D] Does Segment Intersect Convex") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Segment Intersects Cylinder") {
|
||||
struct Case {
|
||||
Vector3 from, to;
|
||||
|
@ -330,6 +344,7 @@ TEST_CASE("[Geometry3D] Segment Intersects Cylinder") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Segment Intersects Cylinder") {
|
||||
struct Case {
|
||||
Vector3 from, to, sphere_pos;
|
||||
|
@ -350,6 +365,7 @@ TEST_CASE("[Geometry3D] Segment Intersects Cylinder") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Segment Intersects Triangle") {
|
||||
struct Case {
|
||||
Vector3 from, to, v_1, v_2, v_3, *result;
|
||||
|
@ -368,6 +384,7 @@ TEST_CASE("[Geometry3D] Segment Intersects Triangle") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Triangle and Box Overlap") {
|
||||
struct Case {
|
||||
Vector3 box_centre;
|
||||
|
@ -389,6 +406,7 @@ TEST_CASE("[Geometry3D] Triangle and Box Overlap") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Geometry3D] Triangle and Sphere Intersect") {
|
||||
struct Case {
|
||||
Vector<Vector3> triangle;
|
||||
|
@ -413,5 +431,6 @@ TEST_CASE("[Geometry3D] Triangle and Sphere Intersect") {
|
|||
CHECK(output == current_case.want);
|
||||
}
|
||||
}
|
||||
} // namespace Test3DGeometry
|
||||
#endif
|
||||
} // namespace TestGeometry3D
|
||||
|
||||
#endif // TEST_GEOMETRY_3D_H
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
namespace TestVariant {
|
||||
|
||||
TEST_CASE("[Variant] Writer and parser integer") {
|
||||
int64_t a32 = 2147483648; // 2^31, so out of bounds for 32-bit signed int [-2^31,-2^31-1].
|
||||
int64_t a32 = 2147483648; // 2^31, so out of bounds for 32-bit signed int [-2^31, +2^31-1].
|
||||
String a32_str;
|
||||
VariantWriter::write_to_string(a32, a32_str);
|
||||
|
||||
|
@ -76,34 +76,35 @@ TEST_CASE("[Variant] Writer and parser integer") {
|
|||
CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
|
||||
}
|
||||
|
||||
TEST_CASE("[Variant] Writer and parser float") {
|
||||
// Assuming real_t is double.
|
||||
real_t a64 = 340282346638528859811704183484516925440.0; // std::numeric_limits<real_t>::max()
|
||||
TEST_CASE("[Variant] Writer and parser Variant::FLOAT") {
|
||||
// Variant::FLOAT is always 64-bit (C++ double).
|
||||
// This is the maximum non-infinity double-precision float.
|
||||
double a64 = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
|
||||
String a64_str;
|
||||
VariantWriter::write_to_string(a64, a64_str);
|
||||
|
||||
CHECK_MESSAGE(a64_str == "3.40282e+38", "Writes in scientific notation.");
|
||||
CHECK_MESSAGE(a64_str == "1.79769e+308", "Writes in scientific notation.");
|
||||
CHECK_MESSAGE(a64_str != "inf", "Should not overflow.");
|
||||
CHECK_MESSAGE(a64_str != "nan", "The result should be defined.");
|
||||
|
||||
VariantParser::StreamString ss;
|
||||
String errs;
|
||||
int line;
|
||||
Variant b64_parsed;
|
||||
real_t b64_float_parsed;
|
||||
Variant variant_parsed;
|
||||
double float_parsed;
|
||||
|
||||
ss.s = a64_str;
|
||||
VariantParser::parse(&ss, b64_parsed, errs, line);
|
||||
b64_float_parsed = b64_parsed;
|
||||
|
||||
CHECK_MESSAGE(b64_float_parsed == 340282001837565597733306976381245063168.0, "Should parse back.");
|
||||
VariantParser::StreamString bss;
|
||||
bss.s = a64_str;
|
||||
VariantParser::parse(&bss, variant_parsed, errs, line);
|
||||
float_parsed = variant_parsed;
|
||||
// Loses precision, but that's alright.
|
||||
CHECK_MESSAGE(float_parsed == 1.79769e+308, "Should parse back.");
|
||||
|
||||
ss.s = "1.0e+100"; // Float version of Googol!
|
||||
VariantParser::parse(&ss, b64_parsed, errs, line);
|
||||
b64_float_parsed = b64_parsed;
|
||||
|
||||
CHECK_MESSAGE(b64_float_parsed == 340282001837565597733306976381245063168.0, "Should not overflow.");
|
||||
// Approximation of Googol with a double-precision float.
|
||||
VariantParser::StreamString css;
|
||||
css.s = "1.0e+100";
|
||||
VariantParser::parse(&css, variant_parsed, errs, line);
|
||||
float_parsed = variant_parsed;
|
||||
CHECK_MESSAGE(float_parsed == 1.0e+100, "Should match the double literal.");
|
||||
}
|
||||
|
||||
TEST_CASE("[Variant] Assignment To Bool from Int,Float,String,Vec2,Vec2i,Vec3,Vec3i and Color") {
|
||||
|
|
Loading…
Reference in a new issue