Page MenuHomec4science

subtraction.cc
No OneTemporary

File Metadata

Created
Thu, Jul 18, 17:23

subtraction.cc

/**
* @file subtraction.cc
* @author Till Junge <till.junge@epfl.ch>
* @date Thu Jul 10 17:41:34 2014
*
* @brief
*
* @section LICENSE
*
* <insert lisence here>
*
*/
/* -------------------------------------------------------------------------- */
#include "subtraction.hh"
#include <stdexcept>
/* -------------------------------------------------------------------------- */
template <Uint DIM>
Subtraction<DIM>::Subtraction(const Geometry<DIM> & includeGeom,
const Geometry<DIM> & excludeGeom,
std::string name)
:Geometry<DIM>(name), includeGeom(*includeGeom.resolveType()),
excludeGeom(*excludeGeom.resolveType()) {}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
Subtraction<DIM>::Subtraction(const Subtraction<DIM> & other)
:Geometry<DIM>(other.get_name()),
includeGeom(*other.getIncludeGeom().resolveType()),
excludeGeom(*other.getExcludeGeom().resolveType()) {}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
Subtraction<DIM>::~Subtraction() {
delete &this->includeGeom;
delete &this->excludeGeom;
}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
void Subtraction<DIM>::printself(std::ostream & stream, int indent) const {
indent_space(stream, indent);
stream << "Subtraction of geometry which" << std::endl;
indent_space(stream, indent);
stream << " includes " << this->includeGeom.get_name() << " and" << std::endl;
indent_space(stream, indent);
stream << " excludes " << this->excludeGeom.get_name() << std::endl;
}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
void Subtraction<DIM>::shift(const PointRef<DIM> & offset) {
this->includeGeom.shift(offset);
this->excludeGeom.shift(offset);
}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
Geometry <DIM> * Subtraction<DIM>::resolveType() const {
return newGeom<DIM>(*this);
}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
bool Subtraction<DIM>::is_inside(const Real * point, Real tol) const {
return this->includeGeom.is_inside(point, tol) &&
!this->excludeGeom.is_inside(point, tol);
}
/* -------------------------------------------------------------------------- */
template <Uint DIM>
InsideObject Subtraction<DIM>::from_border(const Real * point, Real tol) const {
InsideObject ioIn = this->includeGeom.from_border(point, tol);
InsideObject ioEx = this->excludeGeom.from_border(point, tol);
ioEx.distance = -ioEx.distance;
ioEx.is_inside = !ioEx.is_inside;
if (ioIn.distance < ioEx.distance) {
return ioIn;
} else {
return ioEx;
}
}
/* -------------------------------------------------------------------------- */
template<Uint DIM>
Real Subtraction<DIM>::min_in_direction(const Real * dir,
const Real & unit) const {
throw std::runtime_error("Can't compute min in direction for subtractions");
}
/* -------------------------------------------------------------------------- */
template<Uint DIM>
Real Subtraction<DIM>::max_in_direction(const Real * dir,
const Real & unit) const {
throw std::runtime_error("Can't compute max in direction for subtractions");
}
/* -------------------------------------------------------------------------- */
template class Subtraction<twoD>;
template class Subtraction<threeD>;

Event Timeline