Program Listing for File unicell_entity2D.hpp
↰ Return to documentation for file (cosm/repr/unicell_entity2D.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <type_traits>
#include "rcppsw/math/range.hpp"
#include "rcppsw/math/vector2.hpp"
#include "rcppsw/types/discretize_ratio.hpp"
#include "cosm/cosm.hpp"
#include "cosm/repr/entity2D.hpp"
/*******************************************************************************
* Namespaces
******************************************************************************/
namespace cosm::repr {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class unicell_entity2D : public entity2D, public rer::client<unicell_entity2D> {
public:
using entity2D::danchor2D;
using entity2D::ranchor2D;
~unicell_entity2D(void) override = default;
rmath::vector2z dcenter2D(void) const {
ER_ASSERT(RCPPSW_IS_ODD(dbb().xsize()) && RCPPSW_IS_ODD(dbb().ysize()),
"%s called on entity without defined center",
__FUNCTION__);
return entity2D::dcenter2D();
}
bool contains_point(const rmath::vector2d& point) const {
return xrspan().contains(point.x()) && yrspan().contains(point.y());
}
bool contains_cell(const rmath::vector2z& cell) const {
return xdspan().contains(cell.x()) && ydspan().contains(cell.y());
}
protected:
unicell_entity2D(const rtypes::type_uuid& id,
const rmath::vector2d& dims,
const rtypes::discretize_ratio& resolution)
: entity2D(id,
rmath::vector3d(dims, 0.0),
rspatial::euclidean_dist(resolution.v())),
ER_CLIENT_INIT("cosm.repr.unicell_entity2D"),
mc_arena_res(resolution) {}
unicell_entity2D(const rtypes::type_uuid& id,
const rmath::vector2d& dims,
const rmath::vector2d& center,
const rtypes::discretize_ratio& resolution)
: entity2D(id,
rmath::vector3d(dims, 0.0),
rmath::vector3d(center, 0.0),
rspatial::euclidean_dist(resolution.v())),
ER_CLIENT_INIT("cosm.repr.unicell_entity2D"),
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 ranchor2D(const rmath::vector2d& ranchor) {
rbb().update(rmath::vector3d(ranchor, 0.0));
}
template <typename T, RCPPSW_SFINAE_DECLDEF(T::is_movable())>
void danchor2D(const rmath::vector2z& danchor) {
dbb().update(rmath::vector3z(danchor, 0));
}
private:
/* clang-format off */
const rtypes::discretize_ratio mc_arena_res;
/* clang-format on */
};
} /* namespace cosm::repr */