// Copyright 2019 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "KDTreeShared.h"

inline uint32 getDim(const KDTreeNode & node)
{
  return node.dim_and_ofs >> 30;
}

inline uint32 getOfs(const KDTreeNode & node)
{
  return node.dim_and_ofs & ((1<<30)-1);
}

inline bool isLeaf(const KDTreeNode & node)
{
  return getDim(node) == 3;
}

inline float getPos(const KDTreeNode & node)
{
  return floatbits(node.pos_or_numItems);
}

inline float getNumItems(const KDTreeNode & node)
{
  return node.pos_or_numItems;
}

inline uniform uint32 getDim(const uniform KDTreeNode & node)
{
  return node.dim_and_ofs >> 30;
}

inline uniform uint32 getOfs(const uniform KDTreeNode & node)
{
  return node.dim_and_ofs & ((1<<30)-1);
}

inline uniform bool isLeaf(const uniform KDTreeNode & node)
{
  return getDim(node) == 3;
}

inline uniform float getPos(const uniform KDTreeNode & node)
{
  return floatbits(node.pos_or_numItems);
}

inline uniform float getNumItems(const uniform KDTreeNode & node)
{
  return node.pos_or_numItems;
}
