Skip to content

Commit

Permalink
planner_cspace: fix debug build compatibility (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat authored Aug 15, 2019
1 parent a26750a commit 48634ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit 48634ac

Please sign in to comment.