diff options
-rw-r--r-- | core/variant/variant_call.cpp | 27 | ||||
-rw-r--r-- | core/variant/variant_internal.h | 22 | ||||
-rw-r--r-- | core/variant/variant_setget.cpp | 106 | ||||
-rw-r--r-- | doc/classes/RenderingServer.xml | 3 | ||||
-rw-r--r-- | editor/editor_node.cpp | 2 | ||||
-rw-r--r-- | editor/editor_settings.cpp | 3 | ||||
-rw-r--r-- | modules/webm/doc_classes/VideoStreamWebm.xml | 1 | ||||
-rw-r--r-- | servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp | 5 | ||||
-rw-r--r-- | servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp | 28 | ||||
-rw-r--r-- | servers/rendering/rasterizer_rd/rasterizer_storage_rd.h | 1 | ||||
-rw-r--r-- | tests/test_aabb.h | 375 | ||||
-rw-r--r-- | tests/test_main.cpp | 1 |
12 files changed, 452 insertions, 122 deletions
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index f6fe642493..13514b7b9f 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -42,27 +42,6 @@ typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); -template <class T> -struct TypeAdjust { - _FORCE_INLINE_ static void adjust(Variant *r_ret) { - VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret); - } -}; - -template <> //do nothing for variant -struct TypeAdjust<Variant> { - _FORCE_INLINE_ static void adjust(Variant *r_ret) { - } -}; - -template <> //do nothing for variant -struct TypeAdjust<Object *> { - _FORCE_INLINE_ static void adjust(Variant *r_ret) { - VariantInternal::clear(r_ret); - *r_ret = (Object *)nullptr; - } -}; - template <class R, class T, class... P> static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); @@ -124,12 +103,12 @@ static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_bas template <class R, class T, class... P> static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...), Variant *v) { - TypeAdjust<R>::adjust(v); + VariantTypeAdjust<R>::adjust(v); } template <class R, class T, class... P> static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...) const, Variant *v) { - TypeAdjust<R>::adjust(v); + VariantTypeAdjust<R>::adjust(v); } template <class T, class... P> @@ -144,7 +123,7 @@ static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...) const, template <class R, class... P> static _FORCE_INLINE_ void vc_change_return_type(R (*method)(P...), Variant *v) { - TypeAdjust<R>::adjust(v); + VariantTypeAdjust<R>::adjust(v); } template <class R, class T, class... P> diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 9bb3e5b060..bf7e46eed7 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -1359,4 +1359,26 @@ struct VariantTypeChanger { } }; +template <class T> +struct VariantTypeAdjust { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + VariantTypeChanger<typename GetSimpleTypeT<T>::type_t>::change(r_ret); + } +}; + +template <> +struct VariantTypeAdjust<Variant> { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + // Do nothing for variant. + } +}; + +template <> +struct VariantTypeAdjust<Object *> { + _FORCE_INLINE_ static void adjust(Variant *r_ret) { + VariantInternal::clear(r_ret); + *r_ret = (Object *)nullptr; + } +}; + #endif // VARIANT_INTERNAL_H diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 05fe2b80d9..f6a2c11830 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -41,9 +41,7 @@ #define SETGET_STRUCT(m_base_type, m_member_type, m_member) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -71,9 +69,7 @@ #define SETGET_NUMBER_STRUCT(m_base_type, m_member_type, m_member) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_member; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -104,9 +100,7 @@ #define SETGET_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -134,9 +128,7 @@ #define SETGET_NUMBER_STRUCT_CUSTOM(m_base_type, m_member_type, m_member, m_custom) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_custom; \ } \ static void ptr_get(const void *base, void *member) { \ @@ -167,9 +159,7 @@ #define SETGET_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ } \ static void ptr_get(const void *base, void *member) { \ @@ -197,9 +187,7 @@ #define SETGET_NUMBER_STRUCT_FUNC(m_base_type, m_member_type, m_member, m_setter, m_getter) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(); \ } \ static void ptr_get(const void *base, void *member) { \ @@ -230,9 +218,7 @@ #define SETGET_STRUCT_FUNC_INDEX(m_base_type, m_member_type, m_member, m_setter, m_getter, m_index) \ struct VariantSetGet_##m_base_type##_##m_member { \ static void get(const Variant *base, Variant *member) { \ - *member = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ - } \ - static void validated_get(const Variant *base, Variant *member) { \ + VariantTypeAdjust<m_member_type>::adjust(member); \ *VariantGetInternalPtr<m_member_type>::get_ptr(member) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_getter(m_index); \ } \ static void ptr_get(const void *base, void *member) { \ @@ -340,7 +326,7 @@ static void register_member(Variant::Type p_type, const StringName &p_member) { sgi.ptr_setter = T::ptr_set; sgi.getter = T::get; - sgi.validated_getter = T::validated_get; + sgi.validated_getter = T::get; sgi.ptr_getter = T::ptr_get; sgi.member_type = T::get_type(); @@ -605,18 +591,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ - *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ - oob = false; \ - } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \ - if (index < 0) { \ - index += size; \ - } \ - if (index < 0 || index >= size) { \ - oob = true; \ - return; \ - } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ @@ -682,18 +657,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ - *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ - oob = false; \ - } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \ - if (index < 0) { \ - index += size; \ - } \ - if (index < 0 || index >= size) { \ - oob = true; \ - return; \ - } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ @@ -760,14 +724,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ - *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ - oob = false; \ - } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - if (index < 0 || index >= m_max) { \ - oob = true; \ - return; \ - } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ @@ -822,14 +779,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ - *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \ - oob = false; \ - } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - if (index < 0 || index >= m_max) { \ - oob = true; \ - return; \ - } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))m_accessor[index]; \ oob = false; \ } \ @@ -878,14 +828,7 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { oob = true; \ return; \ } \ - *value = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \ - oob = false; \ - } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - if (index < 0 || index >= m_max) { \ - oob = true; \ - return; \ - } \ + VariantTypeAdjust<m_elem_type>::adjust(value); \ *VariantGetInternalPtr<m_elem_type>::get_ptr(value) = VariantGetInternalPtr<m_base_type>::get_ptr(base)->m_get(index); \ oob = false; \ } \ @@ -941,18 +884,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ oob = false; \ } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - int64_t size = VariantGetInternalPtr<m_base_type>::get_ptr(base)->size(); \ - if (index < 0) { \ - index += size; \ - } \ - if (index < 0 || index >= size) { \ - oob = true; \ - return; \ - } \ - *value = (*VariantGetInternalPtr<m_base_type>::get_ptr(base))[index]; \ - oob = false; \ - } \ static void ptr_get(const void *base, int64_t index, void *member) { \ /* avoid ptrconvert for performance*/ \ const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \ @@ -1010,15 +941,6 @@ Variant Variant::get_named(const StringName &p_member, bool &r_valid) const { *value = *ptr; \ oob = false; \ } \ - static void validated_get(const Variant *base, int64_t index, Variant *value, bool &oob) { \ - const Variant *ptr = VariantGetInternalPtr<m_base_type>::get_ptr(base)->getptr(index); \ - if (!ptr) { \ - oob = true; \ - return; \ - } \ - *value = *ptr; \ - oob = false; \ - } \ static void ptr_get(const void *base, int64_t index, void *member) { \ /* avoid ptrconvert for performance*/ \ const m_base_type &v = *reinterpret_cast<const m_base_type *>(base); \ @@ -1094,7 +1016,7 @@ static void register_indexed_member(Variant::Type p_type) { sgi.ptr_setter = T::ptr_set; sgi.getter = T::get; - sgi.validated_getter = T::validated_get; + sgi.validated_getter = T::get; sgi.ptr_getter = T::ptr_get; sgi.index_type = T::get_index_type(); diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 5830a8452c..22a9925d4b 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -3365,7 +3365,8 @@ Objects are displayed with only light information. </constant> <constant name="VIEWPORT_DEBUG_DRAW_OVERDRAW" value="3" enum="ViewportDebugDraw"> - Objects are displayed semi-transparent with additive blending so you can see where they are drawing over top of one another. A higher overdraw means you are wasting performance on drawing pixels that are being hidden behind others. + Objects are displayed semi-transparent with additive blending so you can see where they are drawing over top of one another. A higher overdraw (represented by brighter colors) means you are wasting performance on drawing pixels that are being hidden behind others. + [b]Note:[/b] When using this debug draw mode, custom shaders will be ignored. This means vertex displacement won't be visible anymore. </constant> <constant name="VIEWPORT_DEBUG_DRAW_WIREFRAME" value="4" enum="ViewportDebugDraw"> Debug draw draws objects in wireframe. diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 976afd8e8e..9fcb5fff35 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6821,7 +6821,7 @@ EditorNode::EditorNode() { ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_CTRL | KEY_F2); ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_CTRL | KEY_F3); ED_SHORTCUT("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_CTRL | KEY_F4); - ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_MASK_SHIFT | KEY_F1); + ED_SHORTCUT("editor/editor_help", TTR("Search Help"), KEY_F1); #endif ED_SHORTCUT("editor/editor_next", TTR("Open the next Editor")); ED_SHORTCUT("editor/editor_prev", TTR("Open the previous Editor")); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index f5c1de9def..2cf0bed7d0 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -510,7 +510,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["editors/3d/secondary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/secondary_grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT); // If a line is a multiple of this, it uses the primary grid color. - _initial_set("editors/3d/primary_grid_steps", 10); + // Use a power of 2 value by default as it's more common to use powers of 2 in level design. + _initial_set("editors/3d/primary_grid_steps", 8); hints["editors/3d/primary_grid_steps"] = PropertyInfo(Variant::INT, "editors/3d/primary_grid_steps", PROPERTY_HINT_RANGE, "1,100,1", PROPERTY_USAGE_DEFAULT); // At 1000, the grid mostly looks like it has no edge. diff --git a/modules/webm/doc_classes/VideoStreamWebm.xml b/modules/webm/doc_classes/VideoStreamWebm.xml index 2edbc08cc8..f3e13ba31a 100644 --- a/modules/webm/doc_classes/VideoStreamWebm.xml +++ b/modules/webm/doc_classes/VideoStreamWebm.xml @@ -5,6 +5,7 @@ </brief_description> <description> [VideoStream] resource handling the [url=https://www.webmproject.org/]WebM[/url] video format with [code].webm[/code] extension. Both the VP8 and VP9 codecs are supported. The VP8 and VP9 codecs are more efficient than [VideoStreamTheora], but they require more CPU resources to decode (especially VP9). Both the VP8 and VP9 codecs are decoded on the CPU. + [b]Note:[/b] Alpha channel (also known as transparency) is not supported. The video will always appear to have a black background, even if it originally contains an alpha channel. [b]Note:[/b] There are known bugs and performance issues with WebM video playback in Godot. If you run into problems, try using the Ogg Theora format instead: [VideoStreamTheora] </description> <tutorials> diff --git a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp index da2b00b7a7..12fcc6fbb9 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_scene_rd.cpp @@ -351,8 +351,7 @@ void RasterizerSceneRD::sdfgi_update(RID p_render_buffers, RID p_environment, co RD::TextureFormat tf_probe_average = tf_probes; tf_probe_average.format = RD::DATA_FORMAT_R32G32B32A32_SINT; //signed integer because SH are signed - tf_probe_average.type = RD::TEXTURE_TYPE_2D_ARRAY; - tf_probe_average.array_layers = 1; + tf_probe_average.type = RD::TEXTURE_TYPE_2D; sdfgi->lightprobe_history_scroll = RD::get_singleton()->texture_create(tf_probe_history, RD::TextureView()); sdfgi->lightprobe_average_scroll = RD::get_singleton()->texture_create(tf_probe_average, RD::TextureView()); @@ -8218,7 +8217,7 @@ RasterizerSceneRD::RasterizerSceneRD(RasterizerStorageRD *p_storage) { RD::Uniform u; u.type = RD::UNIFORM_TYPE_TEXTURE; u.binding = 0; - u.ids.push_back(storage->texture_rd_get_default(RasterizerStorageRD::DEFAULT_RD_TEXTURE_3D_WHITE)); + u.ids.push_back(storage->texture_rd_get_default(RasterizerStorageRD::DEFAULT_RD_TEXTURE_CUBEMAP_WHITE)); uniforms.push_back(u); } { diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp index 847d73fe51..5fd8003f8f 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp +++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.cpp @@ -7755,6 +7755,34 @@ RasterizerStorageRD::RasterizerStorageRD() { } } + { //create default cubemap white array + + RD::TextureFormat tformat; + tformat.format = RD::DATA_FORMAT_R8G8B8A8_UNORM; + tformat.width = 4; + tformat.height = 4; + tformat.array_layers = 6; + tformat.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT; + tformat.type = RD::TEXTURE_TYPE_CUBE; + + Vector<uint8_t> pv; + pv.resize(16 * 4); + for (int i = 0; i < 16; i++) { + pv.set(i * 4 + 0, 255); + pv.set(i * 4 + 1, 255); + pv.set(i * 4 + 2, 255); + pv.set(i * 4 + 3, 255); + } + + { + Vector<Vector<uint8_t>> vpv; + for (int i = 0; i < 6; i++) { + vpv.push_back(pv); + } + default_rd_textures[DEFAULT_RD_TEXTURE_CUBEMAP_WHITE] = RD::get_singleton()->texture_create(tformat, RD::TextureView(), vpv); + } + } + { //create default 3D RD::TextureFormat tformat; diff --git a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h index 05cb1b4a73..b7ad931149 100644 --- a/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h +++ b/servers/rendering/rasterizer_rd/rasterizer_storage_rd.h @@ -155,6 +155,7 @@ public: DEFAULT_RD_TEXTURE_MULTIMESH_BUFFER, DEFAULT_RD_TEXTURE_CUBEMAP_BLACK, DEFAULT_RD_TEXTURE_CUBEMAP_ARRAY_BLACK, + DEFAULT_RD_TEXTURE_CUBEMAP_WHITE, DEFAULT_RD_TEXTURE_3D_WHITE, DEFAULT_RD_TEXTURE_2D_ARRAY_WHITE, DEFAULT_RD_TEXTURE_2D_UINT, diff --git a/tests/test_aabb.h b/tests/test_aabb.h new file mode 100644 index 0000000000..8acd2a9963 --- /dev/null +++ b/tests/test_aabb.h @@ -0,0 +1,375 @@ +/*************************************************************************/ +/* test_aabb.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef TEST_AABB_H +#define TEST_AABB_H + +#include "core/math/aabb.h" +#include "core/string/print_string.h" +#include "tests/test_macros.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestAABB { + +TEST_CASE("[AABB] Constructor methods") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + const AABB aabb_copy = AABB(aabb); + + CHECK_MESSAGE( + aabb == aabb_copy, + "AABBs created with the same dimensions but by different methods should be equal."); +} + +TEST_CASE("[AABB] String conversion") { + CHECK_MESSAGE( + String(AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6))) == "-1.5, 2, -2.5 - 4, 5, 6", + "The string representation shouild match the expected value."); +} + +TEST_CASE("[AABB] Basic getters") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.get_position().is_equal_approx(Vector3(-1.5, 2, -2.5)), + "get_position() should return the expected value."); + CHECK_MESSAGE( + aabb.get_size().is_equal_approx(Vector3(4, 5, 6)), + "get_size() should return the expected value."); + CHECK_MESSAGE( + aabb.get_end().is_equal_approx(Vector3(2.5, 7, 3.5)), + "get_end() should return the expected value."); +} + +TEST_CASE("[AABB] Basic setters") { + AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + aabb.set_end(Vector3(100, 0, 100)); + CHECK_MESSAGE( + aabb.is_equal_approx(AABB(Vector3(-1.5, 2, -2.5), Vector3(101.5, -2, 102.5))), + "set_end() should result in the expected AABB."); + + aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + aabb.set_position(Vector3(-1000, -2000, -3000)); + CHECK_MESSAGE( + aabb.is_equal_approx(AABB(Vector3(-1000, -2000, -3000), Vector3(4, 5, 6))), + "set_position() should result in the expected AABB."); + + aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + aabb.set_size(Vector3(0, 0, -50)); + CHECK_MESSAGE( + aabb.is_equal_approx(AABB(Vector3(-1.5, 2, -2.5), Vector3(0, 0, -50))), + "set_size() should result in the expected AABB."); +} + +TEST_CASE("[AABB] Area 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."); + CHECK_MESSAGE( + !aabb.has_no_area(), + "Non-empty volumetric AABB should have an area."); + + 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)."); + + 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)."); + + 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)."); + + 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."); + + CHECK_MESSAGE( + AABB().has_no_area(), + "Empty AABB should not have an area."); +} + +TEST_CASE("[AABB] Surface getters") { + AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + !aabb.has_no_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(), + "Non-empty flat AABB should have a surface."); + + CHECK_MESSAGE( + AABB().has_no_surface(), + "Empty AABB should not have an surface."); +} + +TEST_CASE("[AABB] Intersection") { + const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + + AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.intersects(aabb_small), + "intersects() with fully contained AABB (touching the edge) should return the expected result."); + + aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.intersects(aabb_small), + "intersects() with partially contained AABB (overflowing on Y axis) should return the expected result."); + + aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1)); + CHECK_MESSAGE( + !aabb_big.intersects(aabb_small), + "intersects() with non-contained AABB should return the expected result."); + + aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.intersection(aabb_small).is_equal_approx(aabb_small), + "intersection() with fully contained AABB (touching the edge) should return the expected result."); + + aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.intersection(aabb_small).is_equal_approx(AABB(Vector3(0.5, 2, -2), Vector3(1, 0.5, 1))), + "intersection() with partially contained AABB (overflowing on Y axis) should return the expected result."); + + aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.intersection(aabb_small).is_equal_approx(AABB()), + "intersection() with non-contained AABB should return the expected result."); + + CHECK_MESSAGE( + aabb_big.intersects_plane(Plane(Vector3(0, 1, 0), 4)), + "intersects_plane() should return the expected result."); + CHECK_MESSAGE( + aabb_big.intersects_plane(Plane(Vector3(0, -1, 0), -4)), + "intersects_plane() should return the expected result."); + CHECK_MESSAGE( + !aabb_big.intersects_plane(Plane(Vector3(0, 1, 0), 200)), + "intersects_plane() should return the expected result."); + + CHECK_MESSAGE( + aabb_big.intersects_segment(Vector3(1, 3, 0), Vector3(0, 3, 0)), + "intersects_segment() should return the expected result."); + CHECK_MESSAGE( + aabb_big.intersects_segment(Vector3(0, 3, 0), Vector3(0, -300, 0)), + "intersects_segment() should return the expected result."); + CHECK_MESSAGE( + aabb_big.intersects_segment(Vector3(-50, 3, -50), Vector3(50, 3, 50)), + "intersects_segment() should return the expected result."); + CHECK_MESSAGE( + !aabb_big.intersects_segment(Vector3(-50, 25, -50), Vector3(50, 25, 50)), + "intersects_segment() should return the expected result."); + CHECK_MESSAGE( + aabb_big.intersects_segment(Vector3(0, 3, 0), Vector3(0, 3, 0)), + "intersects_segment() should return the expected result with segment of length 0."); + CHECK_MESSAGE( + !aabb_big.intersects_segment(Vector3(0, 300, 0), Vector3(0, 300, 0)), + "intersects_segment() should return the expected result with segment of length 0."); +} + +TEST_CASE("[AABB] Merging") { + const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + + AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.merge(aabb_small).is_equal_approx(aabb_big), + "merge() with fully contained AABB (touching the edge) should return the expected result."); + + aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.merge(aabb_small).is_equal_approx(AABB(Vector3(-1.5, 1.5, -2.5), Vector3(4, 5.5, 6))), + "merge() with partially contained AABB (overflowing on Y axis) should return the expected result."); + + aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.merge(aabb_small).is_equal_approx(AABB(Vector3(-1.5, -10, -10), Vector3(12.5, 17, 13.5))), + "merge() with non-contained AABB should return the expected result."); +} + +TEST_CASE("[AABB] Encloses") { + const AABB aabb_big = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + + AABB aabb_small = AABB(Vector3(-1.5, 2, -2.5), Vector3(1, 1, 1)); + CHECK_MESSAGE( + aabb_big.encloses(aabb_small), + "encloses() with fully contained AABB (touching the edge) should return the expected result."); + + aabb_small = AABB(Vector3(0.5, 1.5, -2), Vector3(1, 1, 1)); + CHECK_MESSAGE( + !aabb_big.encloses(aabb_small), + "encloses() with partially contained AABB (overflowing on Y axis) should return the expected result."); + + aabb_small = AABB(Vector3(10, -10, -10), Vector3(1, 1, 1)); + CHECK_MESSAGE( + !aabb_big.encloses(aabb_small), + "encloses() with non-contained AABB should return the expected result."); +} + +TEST_CASE("[AABB] Get endpoints") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.get_endpoint(0).is_equal_approx(Vector3(-1.5, 2, -2.5)), + "The endpoint at index 0 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(1).is_equal_approx(Vector3(-1.5, 2, 3.5)), + "The endpoint at index 1 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(2).is_equal_approx(Vector3(-1.5, 7, -2.5)), + "The endpoint at index 2 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(3).is_equal_approx(Vector3(-1.5, 7, 3.5)), + "The endpoint at index 3 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(4).is_equal_approx(Vector3(2.5, 2, -2.5)), + "The endpoint at index 4 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(5).is_equal_approx(Vector3(2.5, 2, 3.5)), + "The endpoint at index 5 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(6).is_equal_approx(Vector3(2.5, 7, -2.5)), + "The endpoint at index 6 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(7).is_equal_approx(Vector3(2.5, 7, 3.5)), + "The endpoint at index 7 should match the expected value."); + + ERR_PRINT_OFF; + CHECK_MESSAGE( + aabb.get_endpoint(8).is_equal_approx(Vector3()), + "The endpoint at invalid index 8 should match the expected value."); + CHECK_MESSAGE( + aabb.get_endpoint(-1).is_equal_approx(Vector3()), + "The endpoint at invalid index -1 should match the expected value."); + ERR_PRINT_ON; +} + +TEST_CASE("[AABB] Get longest/shortest axis") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.get_longest_axis().is_equal_approx(Vector3(0, 0, 1)), + "get_longest_axis() should return the expected value."); + CHECK_MESSAGE( + aabb.get_longest_axis_index() == Vector3::AXIS_Z, + "get_longest_axis() should return the expected value."); + CHECK_MESSAGE( + Math::is_equal_approx(aabb.get_longest_axis_size(), 6), + "get_longest_axis() should return the expected value."); + + CHECK_MESSAGE( + aabb.get_shortest_axis().is_equal_approx(Vector3(1, 0, 0)), + "get_shortest_axis() should return the expected value."); + CHECK_MESSAGE( + aabb.get_shortest_axis_index() == Vector3::AXIS_X, + "get_shortest_axis() should return the expected value."); + CHECK_MESSAGE( + Math::is_equal_approx(aabb.get_shortest_axis_size(), 4), + "get_shortest_axis() should return the expected value."); +} + +TEST_CASE("[AABB] Get support") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.get_support(Vector3(1, 0, 0)).is_equal_approx(Vector3(-1.5, 7, 3.5)), + "get_support() should return the expected value."); + CHECK_MESSAGE( + aabb.get_support(Vector3(0.5, 1, 0)).is_equal_approx(Vector3(-1.5, 2, 3.5)), + "get_support() should return the expected value."); + CHECK_MESSAGE( + aabb.get_support(Vector3(0.5, 1, -400)).is_equal_approx(Vector3(-1.5, 2, 3.5)), + "get_support() should return the expected value."); + CHECK_MESSAGE( + aabb.get_support(Vector3(0, -1, 0)).is_equal_approx(Vector3(2.5, 7, 3.5)), + "get_support() should return the expected value."); + CHECK_MESSAGE( + aabb.get_support(Vector3(0, -0.1, 0)).is_equal_approx(Vector3(2.5, 7, 3.5)), + "get_support() should return the expected value."); + CHECK_MESSAGE( + aabb.get_support(Vector3()).is_equal_approx(Vector3(2.5, 7, 3.5)), + "get_support() should return the expected value with a null vector."); +} + +TEST_CASE("[AABB] Grow") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.grow(0.25).is_equal_approx(AABB(Vector3(-1.75, 1.75, -2.75), Vector3(4.5, 5.5, 6.5))), + "grow() with positive value should return the expected AABB."); + CHECK_MESSAGE( + aabb.grow(-0.25).is_equal_approx(AABB(Vector3(-1.25, 2.25, -2.25), Vector3(3.5, 4.5, 5.5))), + "grow() with negative value should return the expected AABB."); + CHECK_MESSAGE( + aabb.grow(-10).is_equal_approx(AABB(Vector3(8.5, 12, 7.5), Vector3(-16, -15, -14))), + "grow() with large negative value should return the expected AABB."); +} + +TEST_CASE("[AABB] Has point") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.has_point(Vector3(-1, 3, 0)), + "has_point() with contained point should return the expected value."); + CHECK_MESSAGE( + aabb.has_point(Vector3(2, 3, 0)), + "has_point() with contained point should return the expected value."); + CHECK_MESSAGE( + aabb.has_point(Vector3(-1.5, 3, 0)), + "has_point() with contained point on negative edge should return the expected value."); + CHECK_MESSAGE( + aabb.has_point(Vector3(2.5, 3, 0)), + "has_point() with contained point on positive edge should return the expected value."); + CHECK_MESSAGE( + !aabb.has_point(Vector3(-20, 0, 0)), + "has_point() with non-contained point should return the expected value."); +} + +TEST_CASE("[AABB] Expanding") { + const AABB aabb = AABB(Vector3(-1.5, 2, -2.5), Vector3(4, 5, 6)); + CHECK_MESSAGE( + aabb.expand(Vector3(-1, 3, 0)).is_equal_approx(aabb), + "expand() with contained point should return the expected AABB."); + CHECK_MESSAGE( + aabb.expand(Vector3(2, 3, 0)).is_equal_approx(aabb), + "expand() with contained point should return the expected AABB."); + CHECK_MESSAGE( + aabb.expand(Vector3(-1.5, 3, 0)).is_equal_approx(aabb), + "expand() with contained point on negative edge should return the expected AABB."); + CHECK_MESSAGE( + aabb.expand(Vector3(2.5, 3, 0)).is_equal_approx(aabb), + "expand() with contained point on positive edge should return the expected AABB."); + CHECK_MESSAGE( + aabb.expand(Vector3(-20, 0, 0)).is_equal_approx(AABB(Vector3(-20, 0, -2.5), Vector3(22.5, 7, 6))), + "expand() with non-contained point should return the expected AABB."); +} +} // namespace TestAABB + +#endif // TEST_AABB_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 4388654d08..c9bf9ab5d5 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -32,6 +32,7 @@ #include "core/templates/list.h" +#include "test_aabb.h" #include "test_astar.h" #include "test_basis.h" #include "test_class_db.h" |