Program Listing for File unicell_entity3D.hpp

Return to documentation for file (cosm/repr/unicell_entity3D.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <type_traits>

#include "rcppsw/math/range.hpp"
#include "rcppsw/math/vector3.hpp"
#include "rcppsw/types/discretize_ratio.hpp"
#include "rcppsw/spatial/euclidean_dist.hpp"

#include "cosm/cosm.hpp"
#include "cosm/repr/entity3D.hpp"

/*******************************************************************************
 * Namespaces
 ******************************************************************************/
namespace cosm::repr {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class unicell_entity3D : public entity3D, public rer::client<unicell_entity3D> {
 public:
  using entity3D::danchor3D;
  using entity3D::ranchor3D;

  ~unicell_entity3D(void) override = default;

  rmath::vector3z dcenter3D(void) const {
    ER_ASSERT(RCPPSW_IS_ODD(dbb().xsize()) && RCPPSW_IS_ODD(dbb().ysize()) &&
                  RCPPSW_IS_ODD(dbb().zsize()),
              "dcenter3D() called on entity without defined center");
    return entity3D::dcenter3D();
  }

  bool contains_point(const rmath::vector2d& point) const {
    return xrspan().contains(point.x()) && yrspan().contains(point.y());
  }
  bool contains_point(const rmath::vector3d& point) const {
    return xrspan().contains(point.x()) && yrspan().contains(point.y()) &&
           zrspan().contains(point.z());
  }

 protected:
  unicell_entity3D(const rtypes::type_uuid& id,
                   const rmath::vector3d& dims,
                   const rtypes::discretize_ratio& resolution)
      : entity3D(id, dims, rspatial::euclidean_dist(resolution.v())),
        ER_CLIENT_INIT("cosm.repr.unicell_entity3D"),
        mc_arena_res(resolution) {}

  unicell_entity3D(const rtypes::type_uuid& id,
                   const rmath::vector3d& dims,
                   const rmath::vector3d& center,
                   const rtypes::discretize_ratio& resolution)
      : entity3D(id, dims, center, rspatial::euclidean_dist(resolution.v())),
        ER_CLIENT_INIT("cosm.repr.unicell_entity3D"),
        mc_arena_res(resolution) {}

  const rtypes::discretize_ratio& arena_res(void) const { return mc_arena_res; }

  template <typename T, RCPPSW_SFINAE_DECLDEF(T::is_movable())>
  void ranchor3D(const rmath::vector3d& ranchor) {
    rbb().update(ranchor);
  }

  template <typename T, RCPPSW_SFINAE_DECLDEF(T::is_movable())>
  void danchor3D(const rmath::vector3z& danchor) {
    dbb().update(danchor);
  }

 private:
  /* clang-format off */
  const rtypes::discretize_ratio mc_arena_res;
  /* clang-format on */
};

} /* namespace cosm::repr */