summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2022-08-14 21:48:13 -0500
committerAaron Franke <arnfranke@yahoo.com>2022-09-04 23:03:36 -0500
commit817ae9566723fd28be9dc5bb199001dc50ca6b54 (patch)
tree71b8b0c4a5b5c133415d66bb8c96e99ccf253b06
parente7a0a97c0bc5d86644e62d537503e3b05313a01c (diff)
Replace AABB has_no_volume with has_volume
Also replace has_no_surface with has_surface
-rw-r--r--core/math/aabb.h8
-rw-r--r--core/variant/variant_call.cpp4
-rw-r--r--doc/classes/AABB.xml16
-rw-r--r--drivers/gles3/storage/mesh_storage.cpp2
-rw-r--r--modules/navigation/navigation_mesh_generator.cpp6
-rw-r--r--servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp2
-rw-r--r--servers/rendering/renderer_scene_cull.cpp2
-rw-r--r--tests/core/math/test_aabb.h17
8 files changed, 29 insertions, 28 deletions
diff --git a/core/math/aabb.h b/core/math/aabb.h
index e88ba33531..acf903eeba 100644
--- a/core/math/aabb.h
+++ b/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; }
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 8f15a62f79..52e1a7b59c 100644
--- a/core/variant/variant_call.cpp
+++ b/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());
diff --git a/doc/classes/AABB.xml b/doc/classes/AABB.xml
index e2e4e7c61d..23dd41f275 100644
--- a/doc/classes/AABB.xml
+++ b/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">
diff --git a/drivers/gles3/storage/mesh_storage.cpp b/drivers/gles3/storage/mesh_storage.cpp
index ddf94af5b8..5fcb7706f4 100644
--- a/drivers/gles3/storage/mesh_storage.cpp
+++ b/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);
}
}
diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp
index 848e554fb0..cfb8e0cd42 100644
--- a/modules/navigation/navigation_mesh_generator.cpp
+++ b/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;
diff --git a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp b/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
index 49d7198ec2..49e3543ba5 100644
--- a/servers/rendering/renderer_rd/storage_rd/mesh_storage.cpp
+++ b/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);
}
}
diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp
index ffd1b421db..04dedc0646 100644
--- a/servers/rendering/renderer_scene_cull.cpp
+++ b/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;
}
diff --git a/tests/core/math/test_aabb.h b/tests/core/math/test_aabb.h
index 447420fc12..d5f54a139e 100644
--- a/tests/core/math/test_aabb.h
+++ b/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.");
}