Browse Source

Replace AABB has_no_volume with has_volume

Also replace has_no_surface with has_surface
Aaron Franke 3 years ago
parent
commit
817ae95667

+ 4 - 4
core/math/aabb.h

@@ -47,12 +47,12 @@ struct _NO_DISCARD_ AABB {
 	Vector3 size;
 
 	real_t get_volume() const;
-	_FORCE_INLINE_ bool has_no_volume() const {
-		return (size.x <= 0 || size.y <= 0 || size.z <= 0);
+	_FORCE_INLINE_ bool has_volume() const {
+		return size.x > 0.0f && size.y > 0.0f && size.z > 0.0f;
 	}
 
-	_FORCE_INLINE_ bool has_no_surface() const {
-		return (size.x <= 0 && size.y <= 0 && size.z <= 0);
+	_FORCE_INLINE_ bool has_surface() const {
+		return size.x > 0.0f || size.y > 0.0f || size.z > 0.0f;
 	}
 
 	const Vector3 &get_position() const { return position; }

+ 2 - 2
core/variant/variant_call.cpp

@@ -1938,8 +1938,8 @@ static void _register_variant_builtin_methods() {
 	bind_method(AABB, abs, sarray(), varray());
 	bind_method(AABB, get_center, sarray(), varray());
 	bind_method(AABB, get_volume, sarray(), varray());
-	bind_method(AABB, has_no_volume, sarray(), varray());
-	bind_method(AABB, has_no_surface, sarray(), varray());
+	bind_method(AABB, has_volume, sarray(), varray());
+	bind_method(AABB, has_surface, sarray(), varray());
 	bind_method(AABB, has_point, sarray("point"), varray());
 	bind_method(AABB, is_equal_approx, sarray("aabb"), varray());
 	bind_method(AABB, intersects, sarray("with"), varray());

+ 8 - 8
doc/classes/AABB.xml

@@ -142,24 +142,24 @@
 				Returns a copy of the [AABB] grown a given number of units towards all the sides.
 			</description>
 		</method>
-		<method name="has_no_surface" qualifiers="const">
+		<method name="has_point" qualifiers="const">
 			<return type="bool" />
+			<param index="0" name="point" type="Vector3" />
 			<description>
-				Returns [code]true[/code] if the [AABB] is empty.
+				Returns [code]true[/code] if the [AABB] contains a point. Points on the faces of the AABB are considered included, though float-point precision errors may impact the accuracy of such checks.
+				[b]Note:[/b] This method is not reliable for [AABB] with a [i]negative size[/i]. Use [method abs] to get a positive sized equivalent [AABB] to check for contained points.
 			</description>
 		</method>
-		<method name="has_no_volume" qualifiers="const">
+		<method name="has_surface" qualifiers="const">
 			<return type="bool" />
 			<description>
-				Returns [code]true[/code] if the [AABB] is flat or empty.
+				Returns [code]true[/code] if the [AABB] has a surface or a length, and [code]false[/code] if the [AABB] is empty (all components of [member size] are zero or negative).
 			</description>
 		</method>
-		<method name="has_point" qualifiers="const">
+		<method name="has_volume" qualifiers="const">
 			<return type="bool" />
-			<param index="0" name="point" type="Vector3" />
 			<description>
-				Returns [code]true[/code] if the [AABB] contains a point. Points on the faces of the AABB are considered included, though float-point precision errors may impact the accuracy of such checks.
-				[b]Note:[/b] This method is not reliable for [AABB] with a [i]negative size[/i]. Use [method abs] to get a positive sized equivalent [AABB] to check for contained points.
+				Returns [code]true[/code] if the [AABB] has a volume, and [code]false[/code] if the [AABB] is flat, empty, or has a negative [member size].
 			</description>
 		</method>
 		<method name="intersection" qualifiers="const">

+ 1 - 1
drivers/gles3/storage/mesh_storage.cpp

@@ -260,7 +260,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
 		}
 		for (int i = 0; i < p_surface.bone_aabbs.size(); i++) {
 			const AABB &bone = p_surface.bone_aabbs[i];
-			if (!bone.has_no_volume()) {
+			if (bone.has_volume()) {
 				mesh->bone_aabbs.write[i].merge_with(bone);
 			}
 		}

+ 1 - 5
modules/navigation/navigation_mesh_generator.cpp

@@ -572,12 +572,8 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh(
 	cfg.bmax[2] = bmax[2];
 
 	AABB baking_aabb = p_nav_mesh->get_filter_baking_aabb();
-
-	bool aabb_has_no_volume = baking_aabb.has_no_volume();
-
-	if (!aabb_has_no_volume) {
+	if (baking_aabb.has_volume()) {
 		Vector3 baking_aabb_offset = p_nav_mesh->get_filter_baking_aabb_offset();
-
 		cfg.bmin[0] = baking_aabb.position[0] + baking_aabb_offset.x;
 		cfg.bmin[1] = baking_aabb.position[1] + baking_aabb_offset.y;
 		cfg.bmin[2] = baking_aabb.position[2] + baking_aabb_offset.z;

+ 1 - 1
servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp

@@ -425,7 +425,7 @@ void MeshStorage::mesh_add_surface(RID p_mesh, const RS::SurfaceData &p_surface)
 		}
 		for (int i = 0; i < p_surface.bone_aabbs.size(); i++) {
 			const AABB &bone = p_surface.bone_aabbs[i];
-			if (!bone.has_no_volume()) {
+			if (bone.has_volume()) {
 				mesh->bone_aabbs.write[i].merge_with(bone);
 			}
 		}

+ 1 - 1
servers/rendering/renderer_scene_cull.cpp

@@ -1563,7 +1563,7 @@ void RendererSceneCull::_update_instance(Instance *p_instance) {
 		}
 	}
 
-	if (p_instance->aabb.has_no_surface()) {
+	if (!p_instance->aabb.has_surface()) {
 		return;
 	}
 

+ 11 - 6
tests/core/math/test_aabb.h

@@ -94,7 +94,7 @@ TEST_CASE("[AABB] Volume getters") {
 			Math::is_equal_approx(aabb.get_volume(), 120),
 			"get_volume() should return the expected value with positive size.");
 	CHECK_MESSAGE(
-			!aabb.has_no_volume(),
+			aabb.has_volume(),
 			"Non-empty volumetric AABB should have a volume.");
 
 	aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, 5, 6));
@@ -114,27 +114,32 @@ TEST_CASE("[AABB] Volume getters") {
 
 	aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 6));
 	CHECK_MESSAGE(
-			aabb.has_no_volume(),
+			!aabb.has_volume(),
 			"Non-empty flat AABB should not have a volume.");
 
 	CHECK_MESSAGE(
-			AABB().has_no_volume(),
+			!AABB().has_volume(),
 			"Empty AABB should not have a volume.");
 }
 
 TEST_CASE("[AABB] Surface getters") {
 	AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
 	CHECK_MESSAGE(
-			!aabb.has_no_surface(),
+			aabb.has_surface(),
 			"Non-empty volumetric AABB should have an surface.");
 
 	aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 6));
 	CHECK_MESSAGE(
-			!aabb.has_no_surface(),
+			aabb.has_surface(),
 			"Non-empty flat AABB should have a surface.");
 
+	aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 0));
 	CHECK_MESSAGE(
-			AABB().has_no_surface(),
+			aabb.has_surface(),
+			"Non-empty linear AABB should have a surface.");
+
+	CHECK_MESSAGE(
+			!AABB().has_surface(),
 			"Empty AABB should not have an surface.");
 }