covid-sim
covid-sim copied to clipboard
Extract similar Bitmap Logic from Update.cpp
In Update.cpp we have this sort of logic copy-pasted a few times:
if (P.OutputBitmap)
{
Vector2<int> pixel(Households[Hosts[ai].hh].loc * P.scale - P.bmin);
if (P.b.contains(pixel))
{
unsigned j = pixel.y * bmh->width + pixel.x;
if (j < bmh->imagesize)
{
#pragma omp atomic
bmTreated[j]++;
}
}
}
There are some minor variations, and a solution to this ticket should account for that.
It does vary between instances, I had a look about a month ago but there were too many PRs looking like causing a conflict. If #405 goes in I'll look at extracting out a set of methods of the form
void Builder::set_pixel(Vector2<float>& location)
{
if (!output_)
return;
Vector2<int> pixel(location * scale_ - min_);
if (!bounds_.contains(pixel))
return;
I was thinking it should be more like:
bool location_is_in_bounds(const Vector2<float>& location) {
if (!output) return false;
Vector2<int> pixel(location * scale - min);
return bounds.contains(pixel);
}
Or something. I was thinking more in the direction of extracting out the common conditional logic (tentatively called location_is_in_bounds). Maybe also a "location_to_pixel_position" function. Then keeping the adjustment of the variable in the host function...
Either way, minor details aside, I think we have a very similar sort of solution in mind.