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

#pragma once

// ours
#include "AMR.ih"

/*! a reference to a given cell on a given level; this is what a 'node location' kernel will return */
struct CellRef
{
  //! lower left front position, in unit grid space
  vec3f pos;
  //! width of cell, also doubles as level indicator
  float width;
  //! value at this cell
  float value;
};

inline vec3f centerOf(const CellRef &cr)
{
  return cr.pos + make_vec3f(0.5f*cr.width);
}

inline void set(CellRef &cr, const vec3f &pos,
                const float width, const float value)
{
  cr.pos   = pos;
  cr.width = width;
  cr.value = value;
}

  /* packet-based variant of findCell kernel */
extern CellRef findCell(const AMR *uniform self,
                        const varying vec3f &_worldSpacePos,
                        const float minWidth);

extern CellRef findLeafCell(const AMR *uniform self,
                            const varying vec3f &_worldSpacePos);
