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

numpy-replacements for image-drawing #161

Merged
merged 4 commits into from
Nov 2, 2015
Merged

Conversation

tcld
Copy link
Contributor

@tcld tcld commented Oct 29, 2015

Another portion of the code in #141 . Some very small changes and quite a lot of changes in the draw- and drawing_functions-modules.

This again is based off of #146 .

Tests will fail for now due to some differences in rounding for the grayscale-map.

c = numpy.empty(e.shape, dtype=numpy.float)
c[numpy.invert(world.ocean)] = (e[numpy.invert(world.ocean)] - min_elev_land) * 127 / elev_delta_land + 128
c[world.ocean] = (e[world.ocean] - min_elev_sea) * 127 / elev_delta_sea
c = numpy.rint(c).astype(dtype=numpy.int32) # proper rounding
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not rounded before, which might even be preferable.

@tcld tcld mentioned this pull request Oct 29, 2015
@@ -590,7 +588,8 @@ def _draw_a_mountain(pixels, x, y, w=3, h=3):
pixels[x + modx, y + mody] = mcr


def _pseudo_random_land_pos(world, i):
def _pseudo_random_land_pos(world, i): # What is this good for? Why is it not truly random?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this method actually doing that cannot be done by world.random_land(), a truly random function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fully repeatable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should remove my comment then.^^ Due to the recent changes to the RNG this function could technically be removed, I guess. It would require a couple of small changes on top of it, though.

@ftomassetti
Copy link
Member

we still want to merge this, right? Rerunning the tests

@tcld
Copy link
Contributor Author

tcld commented Oct 30, 2015

Sure.^^ I closed the PR that doesn't have to be merged, these new ones are the replacements.
I did a rebase, too, so now the changed code actually reflects what has been changed.

@@ -351,7 +350,7 @@ def sea_level(self):
# Tiles around
#

def on_tiles_around_factor(self, factor, pos, radius=1, action=None):
def on_tiles_around_factor(self, factor, pos, action, radius=1):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action=None seemed unsafe since that case wasn't even handled by the function. In other words: action was a required parameter disguised as an optional one. (The same goes for line 364.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, have you checked all the invokation of this method, given we are changing the order of the parameters? Same goes for the following function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have, and they were all called using the keyword.
Although I didn't find a call to on_tiles_around.

if max_elev is None or e > max_elev:
max_elev = e
# elev_delta = max_elev - min_elev # TODO: no longer used?
#min_elev = world.elevation['data'].min()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm why do we keep code commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was there before, I didn't know if I could remove it. (In the previous version of the code the loop was still run, even though the variables weren't needed anywhere. So it looked less dead than it was.)

@tcld
Copy link
Contributor Author

tcld commented Oct 30, 2015

Updated.

@tcld
Copy link
Contributor Author

tcld commented Oct 31, 2015

Except for the difference in rounding of the heightmaps (line 229 of this PR) this passes the tests and is otherwise finished. I added another PR to worldengine-data Mindwerks/worldengine-data#8 (even though the heightmaps will be changed again when moving them to 16 Bit) and then this is as ready is it gets (aside from code-critique).

@tcld
Copy link
Contributor Author

tcld commented Nov 1, 2015

Rebased and conflicts solved.

mask = numpy.ma.array(e, mask = False) # the whole map
min_elev_land = mask.min()
max_elev_land = mask.max()
elev_delta_land = (max_elev_land - min_elev_land) / 11.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :)

@ftomassetti
Copy link
Member

Some minor comments but it seems good to go, sorry if it took a while to review it

@tcld
Copy link
Contributor Author

tcld commented Nov 2, 2015

Changes are up, hopefully it's fine now.

@tcld
Copy link
Contributor Author

tcld commented Nov 2, 2015

Oh, and don't forget: For this to pass the tests, worldengine-data needs to be updated (Mindwerks/worldengine-data#8).

@ftomassetti
Copy link
Member

Ok, I ran the code locally with the patch for worldengine-data and this one and tests pass. Merging both.

ftomassetti added a commit that referenced this pull request Nov 2, 2015
numpy-replacements for image-drawing
@ftomassetti ftomassetti merged commit c95f3c3 into Mindwerks:master Nov 2, 2015
@tcld tcld deleted the numpy_fin branch November 2, 2015 10:19
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

Successfully merging this pull request may close these issues.

None yet

2 participants