covid-sim icon indicating copy to clipboard operation
covid-sim copied to clipboard

Extract similar Bitmap Logic from Update.cpp

Open CloneDeath opened this issue 4 years ago • 2 comments

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.

CloneDeath avatar Jun 17 '20 12:06 CloneDeath

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;

zebmason avatar Jun 19 '20 17:06 zebmason

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.

CloneDeath avatar Jun 23 '20 13:06 CloneDeath