Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract similar Bitmap Logic from Update.cpp #391

Open
CloneDeath opened this issue Jun 17, 2020 · 2 comments
Open

Extract similar Bitmap Logic from Update.cpp #391

CloneDeath opened this issue Jun 17, 2020 · 2 comments

Comments

@CloneDeath
Copy link
Contributor

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.

@zebmason
Copy link
Contributor

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;

@CloneDeath
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants