diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8d6dc7502..d632d398f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -22,8 +22,8 @@ jobs: - name: Prerequisites run: | - sudo apt update - sudo apt install doxygen graphviz + sudo apt-get -y update + sudo apt-get -y install doxygen graphviz - name: Configure run: > diff --git a/Library/include/playrho/BodyID.hpp b/Library/include/playrho/BodyID.hpp index 04ea72b08..7ad3606a2 100644 --- a/Library/include/playrho/BodyID.hpp +++ b/Library/include/playrho/BodyID.hpp @@ -27,23 +27,27 @@ // IWYU pragma: begin_exports #include -#include +#include // for BodyCounter // IWYU pragma: end_exports namespace playrho { -/// @brief Strongly typed identifier for bodies within @c World instances. +/// @brief Body identifier. +/// @details A strongly typed identifier for uniquely identifying bodes within @c d2::World +/// instances. This is based on the @c BodyCounter type as its underlying type. +/// @see BodyCounter, ContactID, JointID, ShapeID, d2::Body, d2::World. using BodyID = detail::IndexingNamedType; /// @brief Invalid body ID value. -/// @see BodyID. -constexpr auto InvalidBodyID = static_cast(static_cast(-1)); - -/// @brief Determines if the given value is valid. -/// @see BodyID. -template <> -constexpr bool IsValid(const BodyID& value) noexcept +/// @details A special, reserved value of a @c BodyID that represents/identifies an _invalid_ body. +/// @see BodyID, IsValid. +constexpr auto InvalidBodyID = BodyID{static_cast(-1)}; + +/// @brief Determines validity of given value by comparing against InvalidBodyID. +/// @return true if not equal to @c InvalidBodyID , else false. +/// @see BodyID, InvalidBodyID. +constexpr auto IsValid(const BodyID& value) noexcept -> bool { return value != InvalidBodyID; } diff --git a/Library/include/playrho/ContactID.hpp b/Library/include/playrho/ContactID.hpp index 293c33c78..e767632cd 100644 --- a/Library/include/playrho/ContactID.hpp +++ b/Library/include/playrho/ContactID.hpp @@ -34,16 +34,21 @@ namespace playrho { -/// @brief Strongly typed identifier of contacts within @c World instances. +/// @brief Contact identifier. +/// @details A strongly typed identifier for uniquely identifying contacts within @c d2::World +/// instances. This is based on the @c ContactCounter type as its underlying type. +/// @see Contact, ContactCounter, BodyID, JointID, ShapeID, d2::World. using ContactID = detail::IndexingNamedType; /// @brief Invalid contact ID value. -constexpr auto InvalidContactID = - static_cast(static_cast(-1)); - -/// @brief Determines if the given value is valid. -template <> -constexpr bool IsValid(const ContactID& value) noexcept +/// @details A special, reserved value of a @c ContactID that represents/identifies an _invalid_ contact. +/// @see ContactID, IsValid. +constexpr auto InvalidContactID = ContactID{static_cast(-1)}; + +/// @brief Determines validity of given value by comparing against InvalidContactID. +/// @return true if not equal to @c InvalidContactID , else false. +/// @see ContactID, InvalidContactID. +constexpr auto IsValid(const ContactID& value) noexcept -> bool { return value != InvalidContactID; } diff --git a/Library/include/playrho/JointID.hpp b/Library/include/playrho/JointID.hpp index 9ec4c815a..59935be6d 100644 --- a/Library/include/playrho/JointID.hpp +++ b/Library/include/playrho/JointID.hpp @@ -34,14 +34,20 @@ namespace playrho { /// @brief Joint identifier. +/// @details A strongly typed identifier for uniquely identifying joints within @c d2::World +/// instances. This is based on the @c JointCounter type as its underlying type. +/// @see JointCounter, BodyID, ContactID, ShapeID, d2::Joint, d2::World. using JointID = detail::IndexingNamedType; /// @brief Invalid joint ID value. -constexpr auto InvalidJointID = static_cast(static_cast(-1)); - -/// @brief Determines if the given value is valid. -template <> -constexpr bool IsValid(const JointID& value) noexcept +/// @details A special, reserved value of a @c JointID that represents/identifies an _invalid_ joint. +/// @see JointID, IsValid. +constexpr auto InvalidJointID = JointID{static_cast(-1)}; + +/// @brief Determines validity of given value by comparing against InvalidJointID. +/// @return true if not equal to @c InvalidJointID , else false. +/// @see JointID, InvalidJointID. +constexpr auto IsValid(const JointID& value) noexcept -> bool { return value != InvalidJointID; } diff --git a/Library/include/playrho/Matrix.hpp b/Library/include/playrho/Matrix.hpp index 9cad32f21..9a0ca5e8d 100644 --- a/Library/include/playrho/Matrix.hpp +++ b/Library/include/playrho/Matrix.hpp @@ -215,8 +215,7 @@ using InvMass22 = Matrix22; using Mat33 = Matrix33; /// @brief Determines if the given value is valid. -template <> -constexpr bool IsValid(const Mat22& value) noexcept +constexpr auto IsValid(const Mat22& value) noexcept -> bool { return IsValid(get<0>(value)) && IsValid(get<1>(value)); } diff --git a/Library/include/playrho/Settings.hpp b/Library/include/playrho/Settings.hpp index e95fbdedf..1e154920a 100644 --- a/Library/include/playrho/Settings.hpp +++ b/Library/include/playrho/Settings.hpp @@ -56,7 +56,7 @@ constexpr auto MaxChildCount = std::numeric_limits::max() >> 6; /// @note This type must always be able to contain the MaxChildCount value. using ChildCounter = std::remove_const_t; -/// Time step iterations type. +/// @brief Time step iterations type. /// @details A type for counting iterations per time-step. using TimestepIters = std::uint8_t; @@ -65,23 +65,27 @@ constexpr auto MaxFloat = std::numeric_limits::max(); // FLT_MAX // Collision -/// Maximum manifold points. -/// This is the maximum number of contact points between two convex shapes. +/// @brief Maximum manifold points. +/// @details This is the maximum number of contact points between two convex shapes. /// Do not change this value. -/// @note For memory efficiency, uses the smallest integral type that can hold the value. +/// @note For memory efficiency, this uses the smallest integral type that can hold the value. constexpr auto MaxManifoldPoints = std::uint8_t{2}; /// @brief Maximum number of vertices for any shape type. /// @note For memory efficiency, uses the smallest integral type that can hold the value minus -/// one that's left out as a sentinel value. +/// one that's left out as a special, reserved value. +/// @see VertexCounter, InvalidVertex. constexpr auto MaxShapeVertices = std::uint8_t{254}; /// @brief Vertex count type. /// @note This type must not support more than 255 vertices as that would conflict /// with the ContactFeature::Index type. +/// @see MaxShapeVertices, InvalidVertex. using VertexCounter = std::remove_const_t; /// @brief Invalid vertex index. +/// @details This is a special, reserved value for indicating/identifying an invalid vertex. +/// @see VertexCounter. constexpr auto InvalidVertex = static_cast(-1); /// @brief Default linear slop. @@ -91,15 +95,18 @@ constexpr auto InvalidVertex = static_cast(-1); /// between bodies at rest. /// @note Smaller values relative to sizes of bodies increases the time it takes /// for bodies to come to rest. -/// @note The value used by Box2D 2.3.2 b2_linearSlop define is 0.005_m. +/// @note The value used by Box2D 2.3.2's @c b2_linearSlop define is 0.005 (meters). +/// @see DefaultAngularSlop. constexpr auto DefaultLinearSlop = 0.005_m; /// @brief Default minimum vertex radius. /// @note Recommend using 0.01_m or DefaultLinearSlop * Real(2). +/// @see DefaultMaxVertexRadius, DefaultLinearSlop. constexpr auto DefaultMinVertexRadius = 0.01_m; /// @brief Default maximum vertex radius. /// @note Recommend using 255_m or DefaultLinearSlop * 2 * 25500. +/// @see DefaultMinVertexRadius, DefaultLinearSlop. constexpr auto DefaultMaxVertexRadius = 255_m; /// @brief Default AABB extension amount. @@ -112,37 +119,41 @@ constexpr auto DefaultDistanceMultiplier = Real(2); /// @details /// A small angle used as a collision and constraint tolerance. Usually it is /// chosen to be numerically significant, but visually insignificant. +/// @see DefaultLinearSlop. constexpr auto DefaultAngularSlop = (Pi * 2_rad) / Real(180); /// @brief Default maximum linear correction. /// @details The maximum linear position correction used when solving constraints. /// This helps to prevent overshoot. /// @note This value should be greater than the linear slop value. +/// @see DefaultMaxAngularCorrection. constexpr auto DefaultMaxLinearCorrection = 0.2_m; /// @brief Default maximum angular correction. /// @note This value should be greater than the angular slop value. +/// @see DefaultMaxLinearCorrection. constexpr auto DefaultMaxAngularCorrection = Real(8.0f / 180.0f) * Pi * 1_rad; /// @brief Default maximum translation amount. +/// @see DefaultMaxRotation. constexpr auto DefaultMaxTranslation = 2_m; /// @brief Default maximum rotation per world step. /// @warning This value should always be less than 180 degrees - i.e. less than .5 * Pi * Radian. /// @note This limit is meant to prevent numerical problems. Adjusting this value isn't advised. -/// @see StepConf::maxRotation. +/// @see DefaultMaxTranslation, StepConf::maxRotation. constexpr auto DefaultMaxRotation = Angle{179_deg}; /// @brief Default maximum time of impact iterations. constexpr auto DefaultMaxToiIters = std::uint8_t{20}; -/// Default maximum time of impact root iterator count. +/// @brief Default maximum time of impact root iterator count. constexpr auto DefaultMaxToiRootIters = std::uint8_t{30}; -/// Default max number of distance iterations. +/// @brief Default max number of distance iterations. constexpr auto DefaultMaxDistanceIters = std::uint8_t{20}; -/// Default maximum number of sub steps. +/// @brief Default maximum number of sub steps. /// @details /// This is the default maximum number of sub-steps per contact in continuous physics simulation. /// In other words, this is the default maximum number of times in a world step that a contact will @@ -156,75 +167,92 @@ constexpr auto DefaultMaxSubSteps = std::uint8_t{8}; constexpr auto DefaultVelocityThreshold = 1_mps; /// @brief Default regular-phase minimum momentum. +/// @see DefaultToiMinMomentum. constexpr auto DefaultRegMinMomentum = Momentum{0_Ns / 100}; /// @brief Default TOI-phase minimum momentum. +/// @see DefaultRegMinMomentum. constexpr auto DefaultToiMinMomentum = Momentum{0_Ns / 100}; /// @brief Maximum number of bodies in a world. -/// @note This is 65534 based off std::uint16_t and eliminating one value for invalid. +/// @note This is 2^16 - 2, i.e. 65534, based off std::uint16_t and eliminating one value for +/// the _invalid_ body identifier (@c InvalidBodyID). +/// @see BodyCounter, BodyID, InvalidBodyID, MaxContacts, MaxJoints, MaxShapes. constexpr auto MaxBodies = static_cast(std::numeric_limits::max() - std::uint16_t{1}); /// @brief Count type for bodies. -/// @note This type must always be able to contain the MaxBodies value. +/// @note This type must always be able to contain the @c MaxBodies value. +/// @see MaxBodies, ContactCounter, JointCounter, ShapeCounter. using BodyCounter = std::remove_const_t; /// @brief Count type for contacts. -/// @note This type must be able to contain the squared value of BodyCounter. +/// @note This type is meant to contain up to the square of the maximum value of a BodyCounter without possibility of overflow. +/// @see MaxContacts, BodyCounter, JointCounter, ShapeCounter. using ContactCounter = WiderType; /// @brief Invalid contact index. +/// @see ContactCounter. constexpr auto InvalidContactIndex = static_cast(-1); /// @brief Maximum number of contacts in a world (2147319811). /// @details Uses the formula for the maximum number of edges in an unidirectional graph of /// MaxBodies nodes. /// This occurs when every possible body is connected to every other body. +/// @see ContactCounter. ContactID, InvalidContactID, MaxBodies, MaxJoints, MaxShapes. constexpr auto MaxContacts = ContactCounter{MaxBodies} * ContactCounter{MaxBodies - 1} / ContactCounter{2}; /// @brief Dynamic tree size type. using DynamicTreeSize = ContactCounter; /// @brief Maximum number of joints in a world. -/// @note This is 65534 based off std::uint16_t and eliminating one value for invalid. +/// @note This is 2^16 - 2, i.e. 65534, based off std::uint16_t and eliminating one value for +/// the invalid joint identifier (@c InvalidJointID). +/// @see JointCounter, JointID. InvalidJointID, MaxBodies, MaxContacts. MaxShapes. constexpr auto MaxJoints = static_cast(std::numeric_limits::max() - std::uint16_t{1}); /// @brief Counter type for joints. -/// @note This type must be able to contain the MaxJoints value. +/// @note This type must be able to contain the @c MaxJoints value. +/// @see MaxJoints, BodyCounter, ContactCounter, ShapeCounter. using JointCounter = std::remove_const_t; /// @brief Maximum number of shapes in a world. /// @note This is 65534 based off std::uint16_t and eliminating one value for invalid. +/// @see ShapeCounter, ShapeID, InvalidShapeID, MaxBodies, MaxContacts, MaxJoints. constexpr auto MaxShapes = static_cast(std::numeric_limits::max() - std::uint16_t{1}); /// @brief Count type for shapes. /// @note This type must always be able to contain the MaxShapes value. +/// @see MaxShapes, BodyCounter, ContactCounter, JointCounter. using ShapeCounter = std::remove_const_t; /// @brief Default step time. +/// @see DefaultStepFrequency. constexpr auto DefaultStepTime = Time{1_s / 60}; /// @brief Default step frequency. +/// @see DefaultStepTime. constexpr auto DefaultStepFrequency = 60_Hz; // Sleep -/// Default minimum still time to sleep. +/// @brief Default minimum still time to sleep. /// @details The default minimum time bodies must be still for bodies to be put to sleep. constexpr auto DefaultMinStillTimeToSleep = Time{1_s / 2}; // aka 0.5 secs -/// Default linear sleep tolerance. +/// @brief Default linear sleep tolerance. /// @details A body cannot sleep if the magnitude of its linear velocity is above this amount. +/// @see DefaultAngularSleepTolerance. constexpr auto DefaultLinearSleepTolerance = 0.01_mps; // aka 0.01 -/// Default angular sleep tolerance. +/// @brief Default angular sleep tolerance. /// @details A body cannot sleep if its angular velocity is above this amount. +/// @see DefaultLinearSleepTolerance. constexpr auto DefaultAngularSleepTolerance = Real((Pi * 2) / 180) * RadianPerSecond; -/// Default circles ratio. +/// @brief Default circles ratio. /// @details Ratio used for switching between rounded-corner collisions and closest-face /// biased normal collisions. constexpr auto DefaultCirclesRatio = Real(10); diff --git a/Library/include/playrho/ShapeID.hpp b/Library/include/playrho/ShapeID.hpp index 860125089..e55d4679e 100644 --- a/Library/include/playrho/ShapeID.hpp +++ b/Library/include/playrho/ShapeID.hpp @@ -34,14 +34,20 @@ namespace playrho { /// @brief Shape identifier. +/// @details A strongly typed identifier for uniquely identifying shapes within @c d2::World +/// instances. This is based on the @c ShapeCounter type as its underlying type. +/// @see ShapeCounter, BodyID, ContactID, JointID, d2::Shape, d2::World. using ShapeID = detail::IndexingNamedType; -/// @brief Invalid fixture ID value. -constexpr auto InvalidShapeID = static_cast(static_cast(-1)); +/// @brief Invalid shape ID value. +/// @details A special, reserved value of a @c ShapeID that represents/identifies an _invalid_ shape. +/// @see ShapeID, IsValid. +constexpr auto InvalidShapeID = ShapeID{static_cast(-1)}; -/// @brief Determines if the given value is valid. -template <> -constexpr bool IsValid(const ShapeID& value) noexcept +/// @brief Determines validity of given value by comparing against InvalidShapeID. +/// @return true if not equal to @c InvalidShapeID , else false. +/// @see ShapeID, InvalidShapeID. +constexpr auto IsValid(const ShapeID& value) noexcept -> bool { return value != InvalidShapeID; } diff --git a/Library/include/playrho/Templates.hpp b/Library/include/playrho/Templates.hpp index 8df1658d4..b21477ab9 100644 --- a/Library/include/playrho/Templates.hpp +++ b/Library/include/playrho/Templates.hpp @@ -35,9 +35,14 @@ namespace playrho { -/// @brief Determines if the given value is valid. +/// @brief Determines if the given value is valid, using the equality operator. +/// @details Any value for which the comparison of that value with itself is @c true +/// is considered valid by this function, and any value for which this comparison is +/// @c false is said to be not valid. If this seems like an odd algorithm, be aware +/// that this is essentially how floating point @c NaN (not-a-number) works. +/// @see https://en.wikipedia.org/wiki/NaN template -constexpr bool IsValid(const T& value) noexcept +constexpr auto IsValid(const T& value) noexcept -> bool { // Note: This is not necessarily a no-op!! But it is a "constexpr". // @@ -52,11 +57,8 @@ constexpr bool IsValid(const T& value) noexcept return value == value; // NOLINT(misc-redundant-expression) } -// IsValid template specializations. - /// @brief Determines if the given value is valid. -template <> -constexpr bool IsValid(const std::size_t& value) noexcept +constexpr auto IsValid(std::size_t value) noexcept -> bool { return value != static_cast(-1); } diff --git a/Library/include/playrho/Vector2.hpp b/Library/include/playrho/Vector2.hpp index 5ad5e3aaf..233203c70 100644 --- a/Library/include/playrho/Vector2.hpp +++ b/Library/include/playrho/Vector2.hpp @@ -115,7 +115,7 @@ constexpr auto GetFwdPerpendicular(const Vector2& vector) noexcept -> Vector2 /// @brief Determines whether the given vector contains finite coordinates. template -constexpr bool IsValid(const Vector2& value) noexcept +constexpr auto IsValid(const Vector2& value) noexcept -> bool { return IsValid(get<0>(value)) && IsValid(get<1>(value)); } diff --git a/Library/include/playrho/Vector3.hpp b/Library/include/playrho/Vector3.hpp index b4bb6a5b7..32804ca8b 100644 --- a/Library/include/playrho/Vector3.hpp +++ b/Library/include/playrho/Vector3.hpp @@ -51,8 +51,7 @@ using Mass3 = Vector3; using InvMass3 = Vector3; /// @brief Determines whether the given vector contains finite coordinates. -template <> -constexpr bool IsValid(const Vec3& value) noexcept +constexpr auto IsValid(const Vec3& value) noexcept -> bool { return IsValid(get<0>(value)) && IsValid(get<1>(value)) && IsValid(get<2>(value)); } diff --git a/Library/include/playrho/d2/Acceleration.hpp b/Library/include/playrho/d2/Acceleration.hpp index 15ab62261..94a888701 100644 --- a/Library/include/playrho/d2/Acceleration.hpp +++ b/Library/include/playrho/d2/Acceleration.hpp @@ -146,8 +146,7 @@ namespace playrho { /// @brief Determines if the given value is valid. /// @relatedalso playrho::d2::Acceleration -template <> -constexpr bool IsValid(const d2::Acceleration& value) noexcept +constexpr auto IsValid(const d2::Acceleration& value) noexcept -> bool { return IsValid(value.linear) && IsValid(value.angular); } diff --git a/Library/include/playrho/d2/DynamicTree.hpp b/Library/include/playrho/d2/DynamicTree.hpp index 61fa5a355..cdc0902fe 100644 --- a/Library/include/playrho/d2/DynamicTree.hpp +++ b/Library/include/playrho/d2/DynamicTree.hpp @@ -79,11 +79,8 @@ class DynamicTree class TreeNode; - /// @brief Gets the invalid size value. - static constexpr Size GetInvalidSize() noexcept - { - return static_cast(-1); - } + /// @brief Invalid size constant value. + static constexpr auto InvalidSize = static_cast(-1); /// @brief Type for heights. /// @note The maximum height of a tree can never exceed half of the max value of the @@ -93,16 +90,10 @@ class DynamicTree /// @brief Invalid height constant value. static constexpr auto InvalidHeight = static_cast(-1); - /// @brief Gets the invalid height value. - static constexpr Height GetInvalidHeight() noexcept - { - return InvalidHeight; - } - /// @brief Gets whether the given height is the height for an "unused" node. static constexpr bool IsUnused(Height value) noexcept { - return value == GetInvalidHeight(); + return value == InvalidHeight; } /// @brief Gets whether the given height is the height for a "leaf" node. @@ -121,7 +112,7 @@ class DynamicTree /// @post GetNodeCapacity() returns 0. /// @post GetNodeCount() returns 0. /// @post GetFreeIndex() and GetRootIndex() return - /// GetInvalidSize(). + /// InvalidSize. DynamicTree() noexcept; /// @brief Size initializing constructor. @@ -132,7 +123,7 @@ class DynamicTree /// results in GetNodeCapacity() returning zero. /// @post GetNodeCount() returns 0. /// @post GetFreeIndex() and GetRootIndex() return - /// GetInvalidSize(). + /// InvalidSize. /// @throws std::bad_alloc If unable to allocate non-zero sized memory. explicit DynamicTree(Size nodeCapacity); @@ -160,9 +151,9 @@ class DynamicTree /// capacity. /// @post GetLeafCount() will return 0. /// @post GetNodeCount() will return 0. - /// @post GetRootIndex() will return GetInvalidSize(). + /// @post GetRootIndex() will return InvalidSize. /// @post GetFreeIndex() will return 0 if this tree had any node capacity, - /// else the value of GetInvalidSize(). + /// else the value of InvalidSize. void Clear() noexcept; /// @brief Creates a new leaf node. @@ -172,14 +163,14 @@ class DynamicTree /// is less than std::numeric_limits::max(). /// @pre The number of nodes already allocated (as reported by GetNodeCount()) /// is at least one or two less than std::numeric_limits::max() depending - /// on whether root index is GetInvalidSize() or not. - /// @post If the root index had been the GetInvalidSize(), then it will + /// on whether root index is InvalidSize or not. + /// @post If the root index had been the InvalidSize, then it will /// be set to the index returned from this function. /// @post The leaf count per GetLeafCount() is incremented by one. /// @post The node count (as reported by GetNodeCount()) will be incremented by one - /// or two (if the root index had not been GetInvalidSize()). + /// or two (if the root index had not been InvalidSize). /// @return The index of the created leaf node. This will be a value not equal to - /// GetInvalidSize(). + /// InvalidSize. /// @throws std::bad_alloc If unable to allocate necessary memory. If this exception is /// thrown, this function has no effect. /// @see GetLeafCount(), GetNodeCount() @@ -239,7 +230,7 @@ class DynamicTree /// @brief Gets the index of the "root" node if this tree has one. /// @note If the tree has a root node, then the "other" property of this node will be /// the invalid size. - /// @return GetInvalidSize() if this tree is "empty", else index to "root" node. + /// @return InvalidSize if this tree is "empty", else index to "root" node. Size GetRootIndex() const noexcept; /// @brief Gets the free index. @@ -282,7 +273,7 @@ class DynamicTree /// @brief Finds first node which references the given index. /// @note Primarily intended for unit testing and/or debugging. /// @return Index of node referencing the given index, or the value of - /// GetInvalidSize(). + /// InvalidSize. Size FindReference(Size index) const noexcept; /// @brief Customized swap function for DynamicTree objects. @@ -300,7 +291,7 @@ class DynamicTree /// GetNodeCount()) is less than GetNodeCapacity(). /// @note Call Reserve(GetNodeCount() + 1u) before this if uncertain of whether /// any entries are available on the free list. - /// @return Value not equal to GetInvalidSize(). + /// @return Value not equal to InvalidSize. /// @see GetNodeCount() Size AllocateNode() noexcept; @@ -316,8 +307,8 @@ class DynamicTree Size m_nodeCount{0u}; ///< Node count. @details Count of currently allocated nodes. Size m_leafCount{0u}; ///< Leaf count. @details Count of currently allocated leaf nodes. Size m_rootIndex{ - GetInvalidSize()}; ///< Index of root element in m_nodes or GetInvalidSize(). - Size m_freeIndex{GetInvalidSize()}; ///< Free list. @details Index to free nodes. + InvalidSize}; ///< Index of root element in m_nodes or InvalidSize. + Size m_freeIndex{InvalidSize}; ///< Free list. @details Index to free nodes. Size m_nodeCapacity{0u}; ///< Node capacity. @details Size of buffer allocated for nodes. TreeNode* m_nodes{nullptr}; ///< Nodes. @details Initialized on construction. }; @@ -356,7 +347,7 @@ class DynamicTree::TreeNode constexpr TreeNode(TreeNode&& other) = default; /// @brief Initializing constructor. - constexpr explicit TreeNode(Size other = DynamicTree::GetInvalidSize()) noexcept + constexpr explicit TreeNode(Size other = DynamicTree::InvalidSize) noexcept : m_other{other} { assert(IsUnused(GetHeight())); @@ -364,7 +355,7 @@ class DynamicTree::TreeNode /// @brief Initializing constructor. constexpr TreeNode(const Contactable& value, const AABB& aabb, - Size other = DynamicTree::GetInvalidSize()) noexcept + Size other = DynamicTree::InvalidSize) noexcept : m_aabb{aabb}, m_variant{value}, m_height{0}, m_other{other} { // Intentionally empty. @@ -372,14 +363,14 @@ class DynamicTree::TreeNode /// @brief Initializing constructor. /// @pre @c height is a value such that IsBranch(height) is true. - /// @pre Neither @c value.child1 nor @c value.child2 is equal to GetInvalidSize(). + /// @pre Neither @c value.child1 nor @c value.child2 is equal to InvalidSize. constexpr TreeNode(const DynamicTreeBranchData& value, const AABB& aabb, Height height, - Size other = DynamicTree::GetInvalidSize()) noexcept + Size other = DynamicTree::InvalidSize) noexcept : m_aabb{aabb}, m_variant{value}, m_height{height}, m_other{other} { assert(IsBranch(height)); - assert(value.child1 != GetInvalidSize()); - assert(value.child2 != GetInvalidSize()); + assert(value.child1 != InvalidSize); + assert(value.child2 != InvalidSize); } /// @brief Copy assignment operator. @@ -463,12 +454,12 @@ class DynamicTree::TreeNode /// @brief Assigns the node as a "branch" value. /// @pre This node is a branch, i.e.: IsBranch(GetHeight()) is true. - /// @pre Neither @c v.child1 nor @c v.child2 is equal to GetInvalidSize(). + /// @pre Neither @c v.child1 nor @c v.child2 is equal to InvalidSize. constexpr void Assign(const DynamicTreeBranchData& v, const AABB& bb, Height h) noexcept { assert(IsBranch(GetHeight())); - assert(v.child1 != GetInvalidSize()); - assert(v.child2 != GetInvalidSize()); + assert(v.child1 != InvalidSize); + assert(v.child2 != InvalidSize); assert(IsBranch(h)); m_variant.branch = v; m_aabb = bb; @@ -486,21 +477,21 @@ class DynamicTree::TreeNode /// @brief Height. /// @details "Height" for tree balancing. - /// @note 0 if leaf node, DynamicTree::GetInvalidHeight() if free (unallocated) + /// @note 0 if leaf node, DynamicTree::InvalidHeight if free (unallocated) /// node, else branch node. - Height m_height = GetInvalidHeight(); + Height m_height = InvalidHeight; /// @brief Index to "other" node. /// @note This is an index to the next node for a free node, else this is the index to the /// parent node. - Size m_other = DynamicTree::GetInvalidSize(); ///< Index of another node. + Size m_other = DynamicTree::InvalidSize; ///< Index of another node. }; inline DynamicTree::Size DynamicTree::GetRootIndex() const noexcept { - assert((m_rootIndex == GetInvalidSize() && (m_leafCount == 0)) || + assert((m_rootIndex == InvalidSize && (m_leafCount == 0)) || ((m_rootIndex < m_nodeCapacity) && (m_leafCount > 0) && - (GetOther(m_rootIndex) == GetInvalidSize()))); + (GetOther(m_rootIndex) == InvalidSize))); return m_rootIndex; } @@ -521,15 +512,15 @@ inline DynamicTree::Size DynamicTree::GetNodeCount() const noexcept inline DynamicTree::Size DynamicTree::GetLeafCount() const noexcept { - assert(((m_leafCount == 0) && (m_rootIndex == GetInvalidSize())) || - ((m_leafCount > 0) && (m_rootIndex != GetInvalidSize()) && - (GetOther(m_rootIndex) == GetInvalidSize()))); + assert(((m_leafCount == 0) && (m_rootIndex == InvalidSize)) || + ((m_leafCount > 0) && (m_rootIndex != InvalidSize) && + (GetOther(m_rootIndex) == InvalidSize))); return m_leafCount; } inline const DynamicTree::TreeNode& DynamicTree::GetNode(Size index) const noexcept { - assert(index != GetInvalidSize()); + assert(index != InvalidSize); assert(index < GetNodeCapacity()); return *(m_nodes + index); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } @@ -568,8 +559,8 @@ inline Contactable DynamicTree::GetLeafData(Size index) const noexcept // Free functions... /// @brief Finds index of node matching given contactble using a linear search. -/// @return Node index or DynamicTree::GetInvalidSize(). -/// @see DynamicTree::GetInvalidSize(). +/// @return Node index or DynamicTree::InvalidSize. +/// @see DynamicTree::InvalidSize. /// @relatedalso DynamicTree auto FindIndex(const DynamicTree &tree, const Contactable &c) noexcept -> DynamicTree::Size; @@ -631,7 +622,7 @@ constexpr DynamicTree::Size GetNext(const DynamicTree::TreeNode& node) noexcept inline DynamicTree::Height GetHeight(const DynamicTree& tree) noexcept { const auto index = tree.GetRootIndex(); - return (index != DynamicTree::GetInvalidSize()) ? tree.GetHeight(index) + return (index != DynamicTree::InvalidSize) ? tree.GetHeight(index) : DynamicTree::Height{0}; } @@ -643,7 +634,7 @@ inline DynamicTree::Height GetHeight(const DynamicTree& tree) noexcept inline AABB GetAABB(const DynamicTree& tree) noexcept { const auto index = tree.GetRootIndex(); - return (index != DynamicTree::GetInvalidSize()) ? tree.GetAABB(index) : AABB{}; + return (index != DynamicTree::InvalidSize) ? tree.GetAABB(index) : AABB{}; } /// @brief Tests for overlap of the elements identified in the given dynamic tree. diff --git a/Library/include/playrho/d2/Manifold.hpp b/Library/include/playrho/d2/Manifold.hpp index b40f63f5a..0f7ae9a89 100644 --- a/Library/include/playrho/d2/Manifold.hpp +++ b/Library/include/playrho/d2/Manifold.hpp @@ -562,8 +562,7 @@ namespace playrho { /// @brief Gets whether the given manifold is valid. /// @relatedalso d2::Manifold -template <> -constexpr bool IsValid(const d2::Manifold& value) noexcept +constexpr auto IsValid(const d2::Manifold& value) noexcept -> bool { return value.GetType() != d2::Manifold::e_unset; } diff --git a/Library/include/playrho/d2/Position.hpp b/Library/include/playrho/d2/Position.hpp index d6bc0bcc1..1284547f2 100644 --- a/Library/include/playrho/d2/Position.hpp +++ b/Library/include/playrho/d2/Position.hpp @@ -141,8 +141,7 @@ namespace playrho { /// @brief Determines if the given value is valid. /// @relatedalso d2::Position -template <> -constexpr bool IsValid(const d2::Position& value) noexcept +constexpr auto IsValid(const d2::Position& value) noexcept -> bool { return IsValid(value.linear) && IsValid(value.angular); } diff --git a/Library/include/playrho/d2/Sweep.hpp b/Library/include/playrho/d2/Sweep.hpp index e4ba6bdc9..7dc54be99 100644 --- a/Library/include/playrho/d2/Sweep.hpp +++ b/Library/include/playrho/d2/Sweep.hpp @@ -116,8 +116,7 @@ namespace playrho { /// @brief Determines if the given value is valid. /// @relatedalso d2::Sweep -template <> -constexpr bool IsValid(const d2::Sweep& value) noexcept +constexpr auto IsValid(const d2::Sweep& value) noexcept -> bool { return IsValid(value.pos0) && IsValid(value.pos1) && IsValid(value.localCenter) && IsValid(value.alpha0); diff --git a/Library/include/playrho/d2/Transformation.hpp b/Library/include/playrho/d2/Transformation.hpp index af7787df1..2c7283ef3 100644 --- a/Library/include/playrho/d2/Transformation.hpp +++ b/Library/include/playrho/d2/Transformation.hpp @@ -85,8 +85,7 @@ namespace playrho { /// @brief Determines if the given value is valid. /// @relatedalso d2::Transformation -template <> -constexpr bool IsValid(const d2::Transformation& value) noexcept +constexpr auto IsValid(const d2::Transformation& value) noexcept -> bool { return IsValid(value.p) && IsValid(value.q); } diff --git a/Library/include/playrho/d2/UnitVec.hpp b/Library/include/playrho/d2/UnitVec.hpp index 708d57d60..579e0f951 100644 --- a/Library/include/playrho/d2/UnitVec.hpp +++ b/Library/include/playrho/d2/UnitVec.hpp @@ -426,7 +426,7 @@ inline ::std::ostream& operator<<(::std::ostream& os, const UnitVec& value) } // namespace d2 /// @brief Determines if the given value is valid. -template <> constexpr bool IsValid(const d2::UnitVec& value) noexcept +constexpr auto IsValid(const d2::UnitVec& value) noexcept -> bool { return IsValid(value.GetX()) && IsValid(value.GetY()) && (value != d2::UnitVec::GetZero()); } diff --git a/Library/include/playrho/d2/Velocity.hpp b/Library/include/playrho/d2/Velocity.hpp index b9dd4da83..22089b56f 100644 --- a/Library/include/playrho/d2/Velocity.hpp +++ b/Library/include/playrho/d2/Velocity.hpp @@ -162,8 +162,7 @@ Velocity Cap(Velocity velocity, Time h, const MovementConf& conf) noexcept; /// @brief Determines if the given value is valid. /// @relatedalso d2::Velocity -template <> -constexpr bool IsValid(const d2::Velocity& value) noexcept +constexpr auto IsValid(const d2::Velocity& value) noexcept -> bool { return IsValid(value.linear) && IsValid(value.angular); } diff --git a/Library/source/playrho/d2/DynamicTree.cpp b/Library/source/playrho/d2/DynamicTree.cpp index 353c43ef6..8afb8e652 100644 --- a/Library/source/playrho/d2/DynamicTree.cpp +++ b/Library/source/playrho/d2/DynamicTree.cpp @@ -136,7 +136,7 @@ DynamicTree::Size RebalanceAt(DynamicTree::TreeNode nodes[], DynamicTree::Size i nodes[ms.first].SetOther(i); nodes[i] = newNodeI; nodes[c2] = c2Node; - if (o != DynamicTree::GetInvalidSize()) { + if (o != DynamicTree::InvalidSize) { const auto oNode = nodes[o]; const auto oNodeBD = oNode.AsBranch(); assert(oNodeBD.child1 == i || oNodeBD.child2 == i); @@ -186,7 +186,7 @@ DynamicTree::Size RebalanceAt(DynamicTree::TreeNode nodes[], DynamicTree::Size i nodes[ms.first].SetOther(i); nodes[i] = newNodeI; nodes[c1] = c1Node; - if (o != DynamicTree::GetInvalidSize()) { + if (o != DynamicTree::InvalidSize) { const auto oNode = nodes[o]; const auto oNodeBD = oNode.AsBranch(); assert(oNodeBD.child1 == i || oNodeBD.child2 == i); @@ -212,8 +212,8 @@ DynamicTree::Size RebalanceAt(DynamicTree::TreeNode nodes[], DynamicTree::Size i DynamicTree::Size UpdateUpwardFrom(DynamicTree::TreeNode nodes[], DynamicTree::Size start) noexcept { assert(DynamicTree::IsBranch(nodes[start].GetHeight())); - auto rootIndex = DynamicTree::GetInvalidSize(); - for (auto index = start; index != DynamicTree::GetInvalidSize(); + auto rootIndex = DynamicTree::InvalidSize; + for (auto index = start; index != DynamicTree::InvalidSize; index = nodes[index].GetOther()) { assert(DynamicTree::IsBranch(nodes[index].GetHeight())); assert(nodes[nodes[index].AsBranch().child1].GetOther() == index); @@ -230,13 +230,13 @@ DynamicTree::Size UpdateUpwardFrom(DynamicTree::TreeNode nodes[], DynamicTree::S /// starting from the given index. /// @details Finds the index of the "lowest cost" node using a surface area heuristic /// (S.A.H.) for two dimensions. -/// @pre IsValid(leafAABB), index != DynamicTree::GetInvalidSize(), +/// @pre IsValid(leafAABB), index != DynamicTree::InvalidSize, /// and !playrho::d2::IsUnused(nodes[index]) are all true. DynamicTree::Size FindLowestCostNode(const DynamicTree::TreeNode nodes[], const AABB& leafAABB, DynamicTree::Size index) noexcept { assert(IsValid(leafAABB)); - assert(index != DynamicTree::GetInvalidSize()); + assert(index != DynamicTree::InvalidSize); assert(!playrho::d2::IsUnused(nodes[index])); // Cost function to calculate cost of descending into specified child @@ -259,8 +259,8 @@ DynamicTree::Size FindLowestCostNode(const DynamicTree::TreeNode nodes[], const const auto combinedPerimeter = GetPerimeter(GetEnclosingAABB(aabb, leafAABB)); assert(combinedPerimeter >= perimeter); - assert(child1 != DynamicTree::GetInvalidSize()); - assert(child2 != DynamicTree::GetInvalidSize()); + assert(child1 != DynamicTree::InvalidSize); + assert(child2 != DynamicTree::InvalidSize); // Cost of creating a new parent for this node and the new leaf const auto cost = combinedPerimeter * 2; @@ -290,16 +290,16 @@ std::pair RemoveParent(DynamicTree::TreeNo const auto parentBD = nodes[parent].AsBranch(); const auto sibling = (parentBD.child1 == index) ? parentBD.child2 : parentBD.child1; - nodes[index].SetOther(DynamicTree::GetInvalidSize()); + nodes[index].SetOther(DynamicTree::InvalidSize); nodes[sibling].SetOther(grandParent); - if (grandParent != DynamicTree::GetInvalidSize()) { + if (grandParent != DynamicTree::InvalidSize) { const auto newBD = ReplaceChild(nodes[grandParent].AsBranch(), parent, sibling); const auto newAabb = GetEnclosingAABB(nodes[newBD.child1].GetAABB(), nodes[newBD.child2].GetAABB()); const auto newHeight = 1 + std::max(nodes[newBD.child1].GetHeight(), nodes[newBD.child2].GetHeight()); nodes[grandParent].Assign(newBD, newAabb, newHeight); - nodes[parent].SetOther(DynamicTree::GetInvalidSize()); + nodes[parent].SetOther(DynamicTree::InvalidSize); return std::make_pair(UpdateUpwardFrom(nodes, grandParent), parent); } return std::make_pair(sibling, parent); @@ -318,7 +318,7 @@ DynamicTree::Size InsertParent(DynamicTree::TreeNode nodes[], DynamicTree::Size 1 + nodes[sibling].GetHeight(), oldParent}; nodes[sibling].SetOther(newParent); nodes[index].SetOther(newParent); - if (oldParent != DynamicTree::GetInvalidSize()) { + if (oldParent != DynamicTree::InvalidSize) { const auto newBD = ReplaceChild(nodes[oldParent].AsBranch(), sibling, newParent); const auto newAabb = GetEnclosingAABB(nodes[newBD.child1].GetAABB(), nodes[newBD.child2].GetAABB()); @@ -335,7 +335,7 @@ DynamicTree::Size InsertParent(DynamicTree::TreeNode nodes[], DynamicTree::Size DynamicTree::Size UpdateNonRoot(DynamicTree::TreeNode nodes[], DynamicTree::Size index, const AABB& aabb) noexcept { - assert(nodes[index].GetOther() != DynamicTree::GetInvalidSize()); + assert(nodes[index].GetOther() != DynamicTree::InvalidSize); const auto parent = nodes[index].GetOther(); const auto grandParent = nodes[parent].GetOther(); @@ -345,8 +345,8 @@ DynamicTree::Size UpdateNonRoot(DynamicTree::TreeNode nodes[], DynamicTree::Size nodes[sibling].SetOther(grandParent); nodes[index].SetAABB(aabb); - auto rootIndex = DynamicTree::GetInvalidSize(); - if (grandParent != DynamicTree::GetInvalidSize()) { + auto rootIndex = DynamicTree::InvalidSize; + if (grandParent != DynamicTree::InvalidSize) { assert(nodes[grandParent].AsBranch().child1 == parent || nodes[grandParent].AsBranch().child2 == parent); const auto newBD = ReplaceChild(nodes[grandParent].AsBranch(), parent, sibling); @@ -355,12 +355,12 @@ DynamicTree::Size UpdateNonRoot(DynamicTree::TreeNode nodes[], DynamicTree::Size const auto newHeight = 1 + std::max(nodes[newBD.child1].GetHeight(), nodes[newBD.child2].GetHeight()); nodes[grandParent].Assign(newBD, newAabb, newHeight); - nodes[parent].SetOther(DynamicTree::GetInvalidSize()); + nodes[parent].SetOther(DynamicTree::InvalidSize); assert(nodes[nodes[grandParent].AsBranch().child1].GetOther() == grandParent); assert(nodes[nodes[grandParent].AsBranch().child2].GetOther() == grandParent); rootIndex = UpdateUpwardFrom(nodes, grandParent); } - else // grandParent == GetInvalidSize() + else // grandParent == InvalidSize { rootIndex = sibling; } @@ -372,7 +372,7 @@ DynamicTree::Size UpdateNonRoot(DynamicTree::TreeNode nodes[], DynamicTree::Size nodes[parent] = DynamicTree::TreeNode{DynamicTreeBranchData{cheapest, index}, GetEnclosingAABB(aabb, nodes[cheapest].GetAABB()), 1 + nodes[cheapest].GetHeight(), cheapestParent}; - if (cheapestParent != DynamicTree::GetInvalidSize()) { + if (cheapestParent != DynamicTree::InvalidSize) { const auto newBD = ReplaceChild(nodes[cheapestParent].AsBranch(), cheapest, parent); const auto newAabb = GetEnclosingAABB(nodes[newBD.child1].GetAABB(), nodes[newBD.child2].GetAABB()); @@ -389,7 +389,7 @@ DynamicTree::Size UpdateNonRoot(DynamicTree::TreeNode nodes[], DynamicTree::Size DynamicTree::DynamicTree() noexcept = default; DynamicTree::DynamicTree(Size nodeCapacity) - : m_freeIndex{nodeCapacity ? 0 : GetInvalidSize()}, + : m_freeIndex{nodeCapacity ? 0 : InvalidSize}, m_nodeCapacity{NextPowerOfTwo(nodeCapacity - 1u /*rollover okay!*/)}, m_nodes{m_nodeCapacity ? AllocArray(m_nodeCapacity) : nullptr} { @@ -465,12 +465,12 @@ DynamicTree::Size DynamicTree::AllocateNode() noexcept void DynamicTree::FreeNode(Size index) noexcept { - assert(index != GetInvalidSize()); + assert(index != InvalidSize); assert(index < GetNodeCapacity()); assert(index != GetFreeIndex()); assert(m_nodeCount > 0); // index is not necessarily less than m_nodeCount. assert(!IsUnused(m_nodes[index].GetHeight())); - assert(m_nodes[index].GetOther() == GetInvalidSize()); + assert(m_nodes[index].GetOther() == InvalidSize); m_nodes[index] = TreeNode{m_freeIndex}; m_freeIndex = index; --m_nodeCount; @@ -480,7 +480,7 @@ void DynamicTree::Clear() noexcept { m_nodeCount = Size{0u}; m_leafCount = Size{0u}; - m_rootIndex = GetInvalidSize(); + m_rootIndex = InvalidSize; if (m_nodeCapacity && m_nodes) { m_freeIndex = Size{0u}; const auto endCapacity = m_nodeCapacity - 1; @@ -493,7 +493,7 @@ void DynamicTree::Clear() noexcept Free(m_nodes); m_nodes = nullptr; m_nodeCapacity = Size{0u}; - m_freeIndex = GetInvalidSize(); + m_freeIndex = InvalidSize; } } @@ -511,14 +511,14 @@ DynamicTree::Size DynamicTree::FindReference(Size index) const noexcept } return false; }); - return (it != m_nodes + m_nodeCapacity) ? static_cast(it - m_nodes) : GetInvalidSize(); + return (it != m_nodes + m_nodeCapacity) ? static_cast(it - m_nodes) : InvalidSize; } DynamicTree::Size DynamicTree::CreateLeaf(const AABB& aabb, const Contactable& data) { assert(m_leafCount < std::numeric_limits::max()); assert(IsValid(aabb)); - if (m_rootIndex == GetInvalidSize()) { + if (m_rootIndex == InvalidSize) { assert(GetNodeCount() < std::numeric_limits::max()); Reserve(GetNodeCount() + 1u); // Note: may change m_nodes! const auto index = AllocateNode(); @@ -538,7 +538,7 @@ DynamicTree::Size DynamicTree::CreateLeaf(const AABB& aabb, const Contactable& d void DynamicTree::DestroyLeaf(Size index) noexcept { - assert(index != GetInvalidSize()); + assert(index != InvalidSize); assert(index < m_nodeCapacity); assert(!IsUnused(m_nodes[index].GetHeight())); assert(IsLeaf(m_nodes[index].GetHeight())); @@ -552,25 +552,25 @@ void DynamicTree::DestroyLeaf(Size index) noexcept const auto parent = std::get<1>(result); #ifndef NDEBUG const auto found = FindReference(parent); - assert(found == GetInvalidSize()); + assert(found == InvalidSize); #endif FreeNode(parent); } else { - assert(m_nodes[index].GetOther() == GetInvalidSize()); - m_rootIndex = GetInvalidSize(); + assert(m_nodes[index].GetOther() == InvalidSize); + m_rootIndex = InvalidSize; } #ifndef NDEBUG const auto found = FindReference(index); - assert(found == GetInvalidSize()); + assert(found == InvalidSize); #endif FreeNode(index); } void DynamicTree::UpdateLeaf(Size index, const AABB& aabb) { - assert(index != GetInvalidSize()); + assert(index != InvalidSize); assert(index < m_nodeCapacity); assert(IsLeaf(m_nodes[index].GetHeight())); @@ -578,7 +578,7 @@ void DynamicTree::UpdateLeaf(Size index, const AABB& aabb) m_rootIndex = UpdateNonRoot(m_nodes, index, aabb); } else { - assert(m_nodes[index].GetOther() == GetInvalidSize()); + assert(m_nodes[index].GetOther() == InvalidSize); m_nodes[index].SetAABB(aabb); } } @@ -592,20 +592,20 @@ void DynamicTree::RebuildBottomUp() for (auto i = decltype(m_nodeCapacity){0}; i < m_nodeCapacity; ++i) { const auto height = m_nodes[i].GetHeight(); if (IsLeaf(height)) { - m_nodes[i].SetOther(GetInvalidSize()); + m_nodes[i].SetOther(InvalidSize); nodes[count] = i; ++count; } else if (IsBranch(height)) { - m_nodes[i].SetOther(GetInvalidSize()); + m_nodes[i].SetOther(InvalidSize); FreeNode(i); } } while (count > 1) { auto minCost = std::numeric_limits::infinity(); - auto iMin = GetInvalidSize(); - auto jMin = GetInvalidSize(); + auto iMin = InvalidSize; + auto jMin = InvalidSize; for (auto i = decltype(count){0}; i < count; ++i) { const auto& aabbi = m_nodes[nodes[i]].GetAABB(); @@ -679,7 +679,7 @@ void Query(const DynamicTree& tree, const AABB& aabb, const DynamicTreeSizeCB& c while (!empty(stack)) { const auto index = stack.top(); stack.pop(); - if (index != DynamicTree::GetInvalidSize()) { + if (index != DynamicTree::InvalidSize) { if (TestOverlap(tree.GetAABB(index), aabb)) { const auto height = tree.GetHeight(index); if (DynamicTree::IsBranch(height)) { @@ -718,7 +718,7 @@ auto FindIndex(const DynamicTree &tree, const Contactable &c) noexcept -> Dynami return i; } } - return DynamicTree::GetInvalidSize(); + return DynamicTree::InvalidSize; } Length ComputeTotalPerimeter(const DynamicTree& tree) noexcept @@ -736,7 +736,7 @@ Length ComputeTotalPerimeter(const DynamicTree& tree) noexcept Real ComputePerimeterRatio(const DynamicTree& tree) noexcept { const auto root = tree.GetRootIndex(); - if (root != DynamicTree::GetInvalidSize()) { + if (root != DynamicTree::InvalidSize) { const auto rootPerimeter = GetPerimeter(tree.GetAABB(root)); const auto total = ComputeTotalPerimeter(tree); return total / rootPerimeter; @@ -774,13 +774,13 @@ DynamicTree::Height GetMaxImbalance(const DynamicTree& tree) noexcept bool ValidateStructure(const DynamicTree& tree, DynamicTree::Size index) noexcept { - if (index == DynamicTree::GetInvalidSize()) { + if (index == DynamicTree::InvalidSize) { return true; } // DynamicTree enforces this invariant, so can't setup instance in this state to runtime test. assert((index != tree.GetRootIndex()) || - (tree.GetOther(index) == DynamicTree::GetInvalidSize())); + (tree.GetOther(index) == DynamicTree::InvalidSize)); const auto nodeCapacity = tree.GetNodeCapacity(); if (index >= nodeCapacity) { @@ -808,7 +808,7 @@ bool ValidateStructure(const DynamicTree& tree, DynamicTree::Size index) noexcep bool ValidateMetrics(const DynamicTree& tree, DynamicTree::Size index) noexcept { - if (index == DynamicTree::GetInvalidSize()) { + if (index == DynamicTree::InvalidSize) { return true; } diff --git a/Library/source/playrho/d2/RayCastOutput.cpp b/Library/source/playrho/d2/RayCastOutput.cpp index c4fae4f99..ca88a0945 100644 --- a/Library/source/playrho/d2/RayCastOutput.cpp +++ b/Library/source/playrho/d2/RayCastOutput.cpp @@ -250,7 +250,7 @@ bool RayCast(const DynamicTree& tree, RayCastInput input, const DynamicTreeRayCa { const auto index = stack.top(); stack.pop(); - if (index == DynamicTree::GetInvalidSize()) + if (index == DynamicTree::InvalidSize) { continue; } diff --git a/Library/source/playrho/d2/Simplex.cpp b/Library/source/playrho/d2/Simplex.cpp index f51341ef1..8524b836f 100644 --- a/Library/source/playrho/d2/Simplex.cpp +++ b/Library/source/playrho/d2/Simplex.cpp @@ -23,8 +23,7 @@ #include -namespace playrho { -namespace d2 { +namespace playrho::d2 { IndexPair3 GetIndexPairs(const SimplexEdges& collection) noexcept { @@ -239,5 +238,4 @@ Real Simplex::CalcMetric(const SimplexEdges& simplexEdges) return Real{0}; } -} // namespace d2 -} // namespace playrho +} // namespace playrho::d2 diff --git a/Testbed/Framework/Test.cpp b/Testbed/Framework/Test.cpp index 044092ce0..6bd647487 100644 --- a/Testbed/Framework/Test.cpp +++ b/Testbed/Framework/Test.cpp @@ -762,7 +762,7 @@ bool DrawWorld(Drawer& drawer, const World& world, const Test::FixtureSet& selec if (stepSettings.drawAABBs) { const auto color = Color{0.9f, 0.3f, 0.9f}; const auto root = GetTree(world).GetRootIndex(); - if (root != DynamicTree::GetInvalidSize()) { + if (root != DynamicTree::InvalidSize) { const auto worldAabb = GetTree(world).GetAABB(root); Draw(drawer, worldAabb, color); Query(GetTree(world), worldAabb, [&](DynamicTree::Size id) { diff --git a/UnitTests/DynamicTree.cpp b/UnitTests/DynamicTree.cpp index e0b0472c1..f5e044da0 100644 --- a/UnitTests/DynamicTree.cpp +++ b/UnitTests/DynamicTree.cpp @@ -312,15 +312,15 @@ TEST(DynamicTree, DefaultConstruction) DynamicTree foo; EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size{0}); EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); - EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::GetInvalidSize()); - EXPECT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::InvalidSize); + EXPECT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); EXPECT_EQ(GetHeight(foo), DynamicTree::Height(0)); EXPECT_EQ(GetMaxImbalance(foo), DynamicTree::Height(0)); EXPECT_EQ(ComputePerimeterRatio(foo), Real(0)); EXPECT_TRUE(ValidateStructure(foo, foo.GetRootIndex())); EXPECT_TRUE(ValidateMetrics(foo, foo.GetRootIndex())); - EXPECT_EQ(foo.FindReference(DynamicTree::GetInvalidSize()), DynamicTree::GetInvalidSize()); - EXPECT_EQ(foo.FindReference(DynamicTree::Size(0)), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.FindReference(DynamicTree::InvalidSize), DynamicTree::InvalidSize); + EXPECT_EQ(foo.FindReference(DynamicTree::Size(0)), DynamicTree::InvalidSize); } TEST(Contactable, DefaultConstructor) @@ -369,7 +369,7 @@ TEST(DynamicTree, InitializingConstruction) EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); EXPECT_TRUE(ValidateStructure(foo, foo.GetRootIndex())); EXPECT_TRUE(ValidateMetrics(foo, foo.GetRootIndex())); - EXPECT_EQ(foo.FindReference(DynamicTree::GetInvalidSize()), + EXPECT_EQ(foo.FindReference(DynamicTree::InvalidSize), foo.GetNodeCapacity() - 1u); } @@ -422,7 +422,7 @@ TEST(DynamicTree, CopyAssignment) Length2{1_m, 1_m} }; const auto pid = orig.CreateLeaf(aabb, Contactable{BodyID(1u), ShapeID(0u), 0u}); - EXPECT_EQ(orig.FindReference(pid), DynamicTree::GetInvalidSize()); + EXPECT_EQ(orig.FindReference(pid), DynamicTree::InvalidSize); { DynamicTree copy; copy = orig; @@ -433,7 +433,7 @@ TEST(DynamicTree, CopyAssignment) EXPECT_EQ(copy.GetNodeCount(), orig.GetNodeCount()); EXPECT_EQ(GetMaxImbalance(copy), GetMaxImbalance(orig)); EXPECT_EQ(copy.GetLeafData(pid), orig.GetLeafData(pid)); - EXPECT_EQ(copy.FindReference(pid), DynamicTree::GetInvalidSize()); + EXPECT_EQ(copy.FindReference(pid), DynamicTree::InvalidSize); } } @@ -477,12 +477,12 @@ TEST(DynamicTree, FourIdenticalProxies) ASSERT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(0)); ASSERT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); - ASSERT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); - ASSERT_TRUE(ValidateStructure(foo, DynamicTree::GetInvalidSize())); + ASSERT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); + ASSERT_TRUE(ValidateStructure(foo, DynamicTree::InvalidSize)); ASSERT_TRUE(ValidateStructure(foo, foo.GetFreeIndex())); ASSERT_FALSE(ValidateStructure(foo, foo.GetNodeCapacity() + 1)); ASSERT_FALSE(ValidateMetrics(foo, foo.GetNodeCapacity() + 1)); - ASSERT_TRUE(ValidateMetrics(foo, DynamicTree::GetInvalidSize())); + ASSERT_TRUE(ValidateMetrics(foo, DynamicTree::InvalidSize)); ASSERT_TRUE(ValidateStructure(foo, foo.GetRootIndex())); ASSERT_TRUE(ValidateMetrics(foo, foo.GetRootIndex())); ASSERT_EQ(size(foo), 0u); @@ -619,7 +619,7 @@ TEST(DynamicTree, MoveConstruction) DynamicTree roo{std::move(foo)}; - EXPECT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetLeafCount(), DynamicTree::Size(0)); @@ -660,8 +660,8 @@ TEST(DynamicTree, MoveAssignment) roo = std::move(foo); - EXPECT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); - EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); + EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::InvalidSize); EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetLeafCount(), DynamicTree::Size(0)); @@ -695,7 +695,7 @@ TEST(DynamicTree, CreateLeaf) EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(1)); EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(1)); const auto p1 = foo.GetOther(l1); - EXPECT_TRUE(p1 == DynamicTree::GetInvalidSize()); + EXPECT_TRUE(p1 == DynamicTree::InvalidSize); const auto l2 = foo.CreateLeaf(aabb, leafData); ASSERT_EQ(foo.GetLeafCount(), DynamicTree::Size(2)); @@ -703,7 +703,7 @@ TEST(DynamicTree, CreateLeaf) EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(4)); const auto p2 = foo.GetOther(l2); EXPECT_TRUE(foo.GetBranchData(p2).child1 == l2 || foo.GetBranchData(p2).child2 == l2); - ASSERT_NE(foo.GetOther(l1), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l1), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l1)).child1 == l1 || foo.GetBranchData(foo.GetOther(l1)).child2 == l1); const auto l3 = foo.CreateLeaf(aabb, leafData); @@ -712,9 +712,9 @@ TEST(DynamicTree, CreateLeaf) EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(8)); const auto p3 = foo.GetOther(l3); EXPECT_TRUE(foo.GetBranchData(p3).child1 == l3 || foo.GetBranchData(p3).child2 == l3); - ASSERT_NE(foo.GetOther(l2), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l2), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l2)).child1 == l2 || foo.GetBranchData(foo.GetOther(l2)).child2 == l2); - ASSERT_NE(foo.GetOther(l1), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l1), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l1)).child1 == l1 || foo.GetBranchData(foo.GetOther(l1)).child2 == l1); const auto l4 = foo.CreateLeaf(aabb, leafData); @@ -723,11 +723,11 @@ TEST(DynamicTree, CreateLeaf) EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(8)); const auto p4 = foo.GetOther(l4); EXPECT_TRUE(foo.GetBranchData(p4).child1 == l4 || foo.GetBranchData(p4).child2 == l4); - ASSERT_NE(foo.GetOther(l3), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l3), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l3)).child1 == l3 || foo.GetBranchData(foo.GetOther(l3)).child2 == l3); - ASSERT_NE(foo.GetOther(l2), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l2), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l2)).child1 == l2 || foo.GetBranchData(foo.GetOther(l2)).child2 == l2); - ASSERT_NE(foo.GetOther(l1), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l1), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l1)).child1 == l1 || foo.GetBranchData(foo.GetOther(l1)).child2 == l1); const auto l5 = foo.CreateLeaf(AABB{Length2{2_m, 4_m}, Length2{-1_m, 2_m}}, leafData); @@ -736,13 +736,13 @@ TEST(DynamicTree, CreateLeaf) EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(16)); const auto p5 = foo.GetOther(l5); EXPECT_TRUE(foo.GetBranchData(p5).child1 == l5 || foo.GetBranchData(p5).child2 == l5); - ASSERT_NE(foo.GetOther(l4), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l4), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l4)).child1 == l4 || foo.GetBranchData(foo.GetOther(l4)).child2 == l4); - ASSERT_NE(foo.GetOther(l3), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l3), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l3)).child1 == l3 || foo.GetBranchData(foo.GetOther(l3)).child2 == l3); - ASSERT_NE(foo.GetOther(l2), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l2), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l2)).child1 == l2 || foo.GetBranchData(foo.GetOther(l2)).child2 == l2); - ASSERT_NE(foo.GetOther(l1), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(l1), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(l1)).child1 == l1 || foo.GetBranchData(foo.GetOther(l1)).child2 == l1); } @@ -768,63 +768,63 @@ TEST(DynamicTree, UpdateLeaf) ASSERT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(16)); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[0], AABB{Length2{1.5_m, -2_m}, Length2{-1_m, -3_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[1], AABB{Length2{10_m, 12_m}, Length2{1_m, 3_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[2], AABB{Length2{4_m, 5_m}, Length2{2_m, -2_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[3], AABB{Length2{2_m, 3_m}, Length2{5_m, 6_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[4], AABB{Length2{1.5_m, -2_m}, Length2{-1_m, -2.5_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[1], AABB{Length2{1_m, 2_m}, Length2{-2_m, -3_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); leafs.push_back(foo.CreateLeaf(AABB{Length2{-2_m, -4_m}, Length2{1_m, -2_m}}, leafData)); // 6 ASSERT_EQ(foo.GetLeafCount(), DynamicTree::Size(6)); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[2], AABB{Length2{-4_m, -5_m}, Length2{2_m, -2_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); leafs.push_back(foo.CreateLeaf(AABB{Length2{-0.2_m, -0.3_m}, Length2{4.1_m, 4.2_m}}, leafData)); // 7 ASSERT_EQ(foo.GetLeafCount(), DynamicTree::Size(7)); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); @@ -833,19 +833,19 @@ TEST(DynamicTree, UpdateLeaf) ASSERT_EQ(foo.GetNodeCount(), DynamicTree::Size(15)); EXPECT_EQ(foo.GetHeight(foo.GetRootIndex()), DynamicTree::Height{4}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[0], AABB{Length2{10.5_m, 8_m}, Length2{-1_m, -3_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[7], AABB{Length2{-1.2_m, -1.3_m}, Length2{4.1_m, 4.2_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); @@ -854,13 +854,13 @@ TEST(DynamicTree, UpdateLeaf) ASSERT_EQ(foo.GetNodeCount(), DynamicTree::Size(17)); EXPECT_EQ(foo.GetHeight(foo.GetRootIndex()), DynamicTree::Height{4}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); foo.UpdateLeaf(leafs[8], AABB{Length2{-20_m, -11_m}, Length2{1.1_m, 11_m}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); @@ -877,7 +877,7 @@ TEST(DynamicTree, UpdateLeaf) const auto aabb{foo.GetAABB(leaf)}; foo.UpdateLeaf(leaf, AABB{aabb.ranges[1], aabb.ranges[0]}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); }); @@ -888,7 +888,7 @@ TEST(DynamicTree, UpdateLeaf) const auto aabb{foo.GetAABB(leaf)}; foo.UpdateLeaf(leaf, GetMovedAABB(aabb, Length2{6_m, 0_m})); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); }); @@ -899,7 +899,7 @@ TEST(DynamicTree, UpdateLeaf) const auto aabb{foo.GetAABB(leaf)}; foo.UpdateLeaf(leaf, GetFattenedAABB(aabb, 0.5_m)); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); }); @@ -909,7 +909,7 @@ TEST(DynamicTree, UpdateLeaf) std::for_each(begin(leafs), end(leafs), [&foo,&leafs](const auto leaf) { foo.UpdateLeaf(leaf, AABB{Length2{}, Length2{}}); std::for_each(begin(leafs), end(leafs), [&foo](const auto leaf) { - ASSERT_NE(foo.GetOther(leaf), DynamicTree::GetInvalidSize()); + ASSERT_NE(foo.GetOther(leaf), DynamicTree::InvalidSize); EXPECT_TRUE(foo.GetBranchData(foo.GetOther(leaf)).child1 == leaf || foo.GetBranchData(foo.GetOther(leaf)).child2 == leaf); }); }); @@ -924,21 +924,21 @@ TEST(DynamicTree, Clear) ASSERT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(0)); ASSERT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); ASSERT_EQ(foo.GetLeafCount(), DynamicTree::Size(0)); - ASSERT_EQ(foo.GetFreeIndex(), DynamicTree::GetInvalidSize()); - ASSERT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); + ASSERT_EQ(foo.GetFreeIndex(), DynamicTree::InvalidSize); + ASSERT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); EXPECT_NO_THROW(foo.Clear()); EXPECT_EQ(foo.GetNodeCapacity(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetLeafCount(), DynamicTree::Size(0)); - EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::GetInvalidSize()); - EXPECT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::InvalidSize); + EXPECT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); ASSERT_NO_THROW(foo.CreateLeaf(AABB{}, Contactable())); ASSERT_EQ(foo.GetNodeCount(), DynamicTree::Size(1)); ASSERT_GE(foo.GetNodeCapacity(), DynamicTree::Size(1)); ASSERT_EQ(foo.GetLeafCount(), DynamicTree::Size(1)); - ASSERT_EQ(foo.GetFreeIndex(), DynamicTree::GetInvalidSize()); + ASSERT_EQ(foo.GetFreeIndex(), DynamicTree::InvalidSize); ASSERT_EQ(foo.GetRootIndex(), DynamicTree::Size(0)); EXPECT_NO_THROW(foo.Clear()); @@ -946,7 +946,7 @@ TEST(DynamicTree, Clear) EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetLeafCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::Size(0)); - EXPECT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); const auto capacity = foo.GetNodeCapacity(); auto numLeafs = foo.GetLeafCount(); @@ -964,7 +964,7 @@ TEST(DynamicTree, Clear) EXPECT_EQ(foo.GetNodeCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetLeafCount(), DynamicTree::Size(0)); EXPECT_EQ(foo.GetFreeIndex(), DynamicTree::Size(0)); - EXPECT_EQ(foo.GetRootIndex(), DynamicTree::GetInvalidSize()); + EXPECT_EQ(foo.GetRootIndex(), DynamicTree::InvalidSize); } TEST(DynamicTree, QueryFF) @@ -1021,21 +1021,21 @@ TEST(DynamicTree, FindIndex) { EXPECT_EQ(playrho::d2::FindIndex(DynamicTree{}, Contactable{}), DynamicTree::Size(-1)); { - auto idx0 = DynamicTree::GetInvalidSize(); - auto idx1 = DynamicTree::GetInvalidSize(); + auto idx0 = DynamicTree::InvalidSize; + auto idx1 = DynamicTree::InvalidSize; auto tree = DynamicTree{}; const auto aabb0 = AABB{Length2{-1_m, -1_m}, Length2{+1_m, +1_m}}; const auto contactable0 = Contactable{BodyID(0), ShapeID(1), ChildCounter(2)}; ASSERT_NO_THROW(idx0 = tree.CreateLeaf(aabb0, contactable0)); - ASSERT_NE(idx0, DynamicTree::GetInvalidSize()); + ASSERT_NE(idx0, DynamicTree::InvalidSize); const auto aabb1 = AABB{Length2{+1_m, +1_m}, Length2{+2_m, +2_m}}; const auto contactable1 = Contactable{BodyID(1), ShapeID(2), ChildCounter(3)}; ASSERT_NO_THROW(idx1 = tree.CreateLeaf(aabb1, contactable1)); const auto contactable2 = Contactable{BodyID(0), ShapeID(2), ChildCounter(0)}; - ASSERT_NE(idx1, DynamicTree::GetInvalidSize()); + ASSERT_NE(idx1, DynamicTree::InvalidSize); - EXPECT_EQ(playrho::d2::FindIndex(tree, Contactable{}), DynamicTree::GetInvalidSize()); - EXPECT_EQ(playrho::d2::FindIndex(tree, contactable2), DynamicTree::GetInvalidSize()); + EXPECT_EQ(playrho::d2::FindIndex(tree, Contactable{}), DynamicTree::InvalidSize); + EXPECT_EQ(playrho::d2::FindIndex(tree, contactable2), DynamicTree::InvalidSize); EXPECT_EQ(playrho::d2::FindIndex(tree, contactable1), idx1); EXPECT_EQ(playrho::d2::FindIndex(tree, contactable0), idx0); } diff --git a/UnitTests/World.cpp b/UnitTests/World.cpp index 02e14203e..a3ae325ca 100644 --- a/UnitTests/World.cpp +++ b/UnitTests/World.cpp @@ -4223,10 +4223,10 @@ TEST(World, Recreate) const auto recreatedIdxB = FindIndex(GetTree(recreated), entry.first.second); const auto worldIdxA = FindIndex(GetTree(world), entry.first.first); const auto worldIdxB = FindIndex(GetTree(world), entry.first.second); - ASSERT_NE(recreatedIdxA, DynamicTree::GetInvalidSize()) << os.str(); - ASSERT_NE(recreatedIdxB, DynamicTree::GetInvalidSize()) << os.str(); - ASSERT_NE(worldIdxA, DynamicTree::GetInvalidSize()) << os.str(); - ASSERT_NE(worldIdxB, DynamicTree::GetInvalidSize()) << os.str(); + ASSERT_NE(recreatedIdxA, DynamicTree::InvalidSize) << os.str(); + ASSERT_NE(recreatedIdxB, DynamicTree::InvalidSize) << os.str(); + ASSERT_NE(worldIdxA, DynamicTree::InvalidSize) << os.str(); + ASSERT_NE(worldIdxB, DynamicTree::InvalidSize) << os.str(); EXPECT_FALSE(TestOverlap(GetTree(recreated), recreatedIdxA, recreatedIdxB)); EXPECT_TRUE(TestOverlap(GetTree(world), worldIdxA, worldIdxB)); const auto recreatedAabbA = GetAABB(GetTree(recreated).GetNode(recreatedIdxA)); @@ -4271,10 +4271,10 @@ TEST(World, Recreate) const auto recreatedIdxB = FindIndex(GetTree(recreated), entry.first.second); const auto worldIdxA = FindIndex(GetTree(world), entry.first.first); const auto worldIdxB = FindIndex(GetTree(world), entry.first.second); - ASSERT_NE(recreatedIdxA, DynamicTree::GetInvalidSize()) << os.str(); - ASSERT_NE(recreatedIdxB, DynamicTree::GetInvalidSize()) << os.str(); - ASSERT_NE(worldIdxA, DynamicTree::GetInvalidSize()) << os.str(); - ASSERT_NE(worldIdxB, DynamicTree::GetInvalidSize()) << os.str(); + ASSERT_NE(recreatedIdxA, DynamicTree::InvalidSize) << os.str(); + ASSERT_NE(recreatedIdxB, DynamicTree::InvalidSize) << os.str(); + ASSERT_NE(worldIdxA, DynamicTree::InvalidSize) << os.str(); + ASSERT_NE(worldIdxB, DynamicTree::InvalidSize) << os.str(); EXPECT_TRUE(TestOverlap(GetTree(recreated), recreatedIdxA, recreatedIdxB)); EXPECT_FALSE(TestOverlap(GetTree(world), worldIdxA, worldIdxB)); const auto recreatedAabbA = GetAABB(GetTree(recreated).GetNode(recreatedIdxA));