Rename AABB get_area to get_volume

This commit is contained in:
Brian Semrau 2021-11-04 21:01:59 -04:00
parent 70c82d9d3d
commit dc11e73bf0
7 changed files with 40 additions and 40 deletions

View file

@ -33,7 +33,7 @@
#include "core/string/print_string.h"
#include "core/variant/variant.h"
real_t AABB::get_area() const {
real_t AABB::get_volume() const {
return size.x * size.y * size.z;
}

View file

@ -46,8 +46,8 @@ public:
Vector3 position;
Vector3 size;
real_t get_area() const; /// get area
_FORCE_INLINE_ bool has_no_area() const {
real_t get_volume() const;
_FORCE_INLINE_ bool has_no_volume() const {
return (size.x <= 0 || size.y <= 0 || size.z <= 0);
}

View file

@ -1748,8 +1748,8 @@ static void _register_variant_builtin_methods() {
bind_method(AABB, abs, sarray(), varray());
bind_method(AABB, get_center, sarray(), varray());
bind_method(AABB, get_area, sarray(), varray());
bind_method(AABB, has_no_area, 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_point, sarray("point"), varray());
bind_method(AABB, is_equal_approx, sarray("aabb"), varray());

View file

@ -57,12 +57,6 @@
Returns this [AABB] expanded to include a given point.
</description>
</method>
<method name="get_area" qualifiers="const">
<return type="float" />
<description>
Returns the volume of the [AABB].
</description>
</method>
<method name="get_center" qualifiers="const">
<return type="Vector3" />
<description>
@ -119,6 +113,12 @@
Returns the support point in a given direction. This is useful for collision detection algorithms.
</description>
</method>
<method name="get_volume" qualifiers="const">
<return type="float" />
<description>
Returns the volume of the [AABB].
</description>
</method>
<method name="grow" qualifiers="const">
<return type="AABB" />
<argument index="0" name="by" type="float" />
@ -126,18 +126,18 @@
Returns a copy of the [AABB] grown a given amount of units towards all the sides.
</description>
</method>
<method name="has_no_area" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the [AABB] is flat or empty.
</description>
</method>
<method name="has_no_surface" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the [AABB] is empty.
</description>
</method>
<method name="has_no_volume" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the [AABB] is flat or empty.
</description>
</method>
<method name="has_point" qualifiers="const">
<return type="bool" />
<argument index="0" name="point" type="Vector3" />

View file

@ -171,7 +171,7 @@ void GodotCollisionObject3D::_update_shapes() {
s.aabb_cache = shape_aabb;
Vector3 scale = xform.get_basis().get_scale();
s.area_cache = s.shape->get_area() * scale.x * scale.y * scale.z;
s.area_cache = s.shape->get_volume() * scale.x * scale.y * scale.z;
if (s.bpid == 0) {
s.bpid = space->get_broadphase()->create(this, i, shape_aabb, _static);

View file

@ -64,7 +64,7 @@ public:
FEATURE_CIRCLE,
};
virtual real_t get_area() const { return aabb.get_area(); }
virtual real_t get_volume() const { return aabb.get_volume(); }
_FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; }
_FORCE_INLINE_ RID get_self() const { return self; }
@ -120,7 +120,7 @@ class GodotWorldBoundaryShape3D : public GodotShape3D {
public:
Plane get_plane() const;
virtual real_t get_area() const override { return INFINITY; }
virtual real_t get_volume() const override { return INFINITY; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_WORLD_BOUNDARY; }
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
@ -147,7 +147,7 @@ public:
real_t get_length() const;
bool get_slide_on_slope() const;
virtual real_t get_area() const override { return 0.0; }
virtual real_t get_volume() const override { return 0.0; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SEPARATION_RAY; }
virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
virtual Vector3 get_support(const Vector3 &p_normal) const override;
@ -173,7 +173,7 @@ class GodotSphereShape3D : public GodotShape3D {
public:
real_t get_radius() const;
virtual real_t get_area() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius; }
virtual real_t get_volume() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SPHERE; }
@ -198,7 +198,7 @@ class GodotBoxShape3D : public GodotShape3D {
public:
_FORCE_INLINE_ Vector3 get_half_extents() const { return half_extents; }
virtual real_t get_area() const override { return 8 * half_extents.x * half_extents.y * half_extents.z; }
virtual real_t get_volume() const override { return 8 * half_extents.x * half_extents.y * half_extents.z; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_BOX; }
@ -227,7 +227,7 @@ public:
_FORCE_INLINE_ real_t get_height() const { return height; }
_FORCE_INLINE_ real_t get_radius() const { return radius; }
virtual real_t get_area() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius + (height - radius * 2.0) * Math_PI * radius * radius; }
virtual real_t get_volume() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius + (height - radius * 2.0) * Math_PI * radius * radius; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CAPSULE; }
@ -256,7 +256,7 @@ public:
_FORCE_INLINE_ real_t get_height() const { return height; }
_FORCE_INLINE_ real_t get_radius() const { return radius; }
virtual real_t get_area() const override { return height * Math_PI * radius * radius; }
virtual real_t get_volume() const override { return height * Math_PI * radius * radius; }
virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CYLINDER; }

View file

@ -90,38 +90,38 @@ TEST_CASE("[AABB] Basic setters") {
"set_size() should result in the expected AABB.");
}
TEST_CASE("[AABB] Area getters") {
TEST_CASE("[AABB] Volume getters") {
AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6));
CHECK_MESSAGE(
Math::is_equal_approx(aabb.get_area(), 120),
"get_area() should return the expected value with positive size.");
Math::is_equal_approx(aabb.get_volume(), 120),
"get_volume() should return the expected value with positive size.");
CHECK_MESSAGE(
!aabb.has_no_area(),
"Non-empty volumetric AABB should have an area.");
!aabb.has_no_volume(),
"Non-empty volumetric AABB should have a volume.");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, 5, 6));
CHECK_MESSAGE(
Math::is_equal_approx(aabb.get_area(), -120),
"get_area() should return the expected value with negative size (1 component).");
Math::is_equal_approx(aabb.get_volume(), -120),
"get_volume() should return the expected value with negative size (1 component).");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, -5, 6));
CHECK_MESSAGE(
Math::is_equal_approx(aabb.get_area(), 120),
"get_area() should return the expected value with negative size (2 components).");
Math::is_equal_approx(aabb.get_volume(), 120),
"get_volume() should return the expected value with negative size (2 components).");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(-4, -5, -6));
CHECK_MESSAGE(
Math::is_equal_approx(aabb.get_area(), -120),
"get_area() should return the expected value with negative size (3 components).");
Math::is_equal_approx(aabb.get_volume(), -120),
"get_volume() should return the expected value with negative size (3 components).");
aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 0, 6));
CHECK_MESSAGE(
aabb.has_no_area(),
"Non-empty flat AABB should not have an area.");
aabb.has_no_volume(),
"Non-empty flat AABB should not have a volume.");
CHECK_MESSAGE(
AABB().has_no_area(),
"Empty AABB should not have an area.");
AABB().has_no_volume(),
"Empty AABB should not have a volume.");
}
TEST_CASE("[AABB] Surface getters") {