Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner_cspace: fix debug build compatibility #368

Merged
merged 3 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion planner_cspace/include/planner_cspace/blockmem_gridmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ class BlockMemGridmap
return v && ((v & (v - 1)) == 0);
}
static_assert(isPowOf2(BLOCK_WIDTH), "BLOCK_WIDTH must be power of 2");
static_assert(BLOCK_WIDTH > 0, "BLOCK_WIDTH must be >0");

static constexpr size_t log2Recursive(const size_t v, const size_t depth = 0)
{
return v == 1 ? depth : log2Recursive(v >> 1, depth + 1);
}

protected:
constexpr static size_t block_bit_ = std::lround(std::log2(BLOCK_WIDTH));
constexpr static size_t block_bit_ = log2Recursive(BLOCK_WIDTH);
constexpr static size_t block_bit_mask_ = (1 << block_bit_) - 1;

std::unique_ptr<T[]> c_;
Expand Down
17 changes: 17 additions & 0 deletions planner_cspace/test/src/test_blockmem_gridmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@

#include <planner_cspace/blockmem_gridmap.h>

template <int BLOCK_WIDTH>
class BlockMemGridmapHelper : public BlockMemGridmap<int, 1, 1, BLOCK_WIDTH, false>
{
public:
size_t getBlockBit() const
{
return this->block_bit_;
}
};
TEST(BlockmemGridmap, BlockWidth)
{
ASSERT_EQ(4u, BlockMemGridmapHelper<0x10>().getBlockBit());
ASSERT_EQ(8u, BlockMemGridmapHelper<0x100>().getBlockBit());
ASSERT_EQ(12u, BlockMemGridmapHelper<0x1000>().getBlockBit());
ASSERT_EQ(16u, BlockMemGridmapHelper<0x10000>().getBlockBit());
}

TEST(BlockmemGridmap, ResetClear)
{
BlockMemGridmap<float, 3, 3, 0x20> gm;
Expand Down