Skip to content
Snippets Groups Projects
Commit 8f6e2469 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[function.checkerboard] fixed possible overflow

parent 7a59ea07
No related branches found
No related tags found
No related merge requests found
...@@ -132,13 +132,19 @@ public: ...@@ -132,13 +132,19 @@ public:
return 0; return 0;
} }
/**
* \todo put this stuff in an expression, that is expanded at compile time (dimension dependent)
*/
virtual void evaluate(const DomainType& x, RangeType& ret) const virtual void evaluate(const DomainType& x, RangeType& ret) const
{ {
// decide on the subdomain the point x belongs to // decide on the subdomain the point x belongs to
std::vector<size_t> whichPartition; std::vector<size_t> whichPartition;
for (int d = 0; d < dimDomain; ++d) { for (int d = 0; d < dimDomain; ++d) {
// for points that are on upperRight_[d], this selects one partition too much
// so we need to cap this
whichPartition.push_back( whichPartition.push_back(
std::floor(numElements_[d] * ((x[d] - lowerLeft_[d]) / (upperRight_[d] - lowerLeft_[d])))); std::min(size_t(std::floor(numElements_[d] * ((x[d] - lowerLeft_[d]) / (upperRight_[d] - lowerLeft_[d])))),
numElements_[d] - 1));
} }
size_t subdomain = 0; size_t subdomain = 0;
if (dimDomain == 1) if (dimDomain == 1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment