Thanks to visit codestin.com
Credit goes to github.com

Skip to content

improve snapping algorithm #726

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

Closed
wants to merge 2 commits into from

Conversation

leejjoon
Copy link
Contributor

I think the current snapping gives somewhat wrong result.

            *x = mpl_round(*x) + m_snap_value;      
            *y = mpl_round(*y) + m_snap_value;

For example, consider m_snap_value=0.5 and (x, y) = (0.45, 0.55). This is supposed to be snapped to (0.5, 0.5) but the above code gives (0.5, 1.5). And I think the right thing to do is subtract m_snap_value before rounding.

             *x = mpl_round(*x-m_snap_value) + m_snap_value;
             *y = mpl_round(*y-m_snap_value) + m_snap_value;

@leejjoon
Copy link
Contributor Author

@mdboom: Can you check this?

@mdboom
Copy link
Member

mdboom commented Feb 28, 2012

Looks right. Interestingly, it doesn't seem to cause any additional test failures -- but as we drift further and further from the baseline images, we'll probably want to update them at some point.

@WeatherGod
Copy link
Member

Do we want this for v1.1.1?

@mdboom
Copy link
Member

mdboom commented Feb 28, 2012

Given that 1.1.1 is imminent, I would think no. This feels like a pretty pervasive change to me -- I would hate to later discover things like images aligning correctly to the edges of the axes breaks in some corner cases because of this change.

@leejjoon
Copy link
Contributor Author

The commit f4f2a1a introduces one pixel offset between lines and markers for integer coordinates, e.g., (0, 0). I believe that this is related to how maker paths are snapped.

    snap_t             marker_path_snapped(marker_path_transformed,
                                           gc.snap_mode,
                                           marker_path.total_vertices(),
                                           gc.linewidth);

If we consider a marker path (0, 0.5) - (0, 1.5) and linewidth of 1, I believe that the path actually snapped and becomes (-0.5, 0.5) - (0.5, 0.5) as round(-0.5) returns -1, while it is supposed to (or used to) become (0.5, 0.5) - (0.5, 1.5).

I think one option is just to translate the marker path by (0.5, 0.5) before the snapping (cbc5fed). But @mdboom may have different (and better) idea.

@mdboom
Copy link
Member

mdboom commented Feb 29, 2012

Closing -- this was merged as part of #695.

@mdboom mdboom closed this Feb 29, 2012
@leejjoon
Copy link
Contributor Author

leejjoon commented Mar 1, 2012

I don't see these changes in #695. Did you mean that #695 also solves the current issue? Just in case, with the changes in this PR applied, it seems that #695 still shows 1 pixel offset.

@mdboom
Copy link
Member

mdboom commented Mar 1, 2012

Ok -- I see. This PR was incorporated in #695, but I missed the fact that it had problems. I'm looking into this now and am reopening #695 to do the work over there.

EDIT: @leejjoon: you can see a solution to the problems presented here on top of #695 in #734. Can you test with all of your use cases? It seems to a) have pixel markers align with the ticks correctly, b) have the ticks align with the axes rectangle correctly, c) have the clipbox align with the axes rectangle, d) not distort the shape of the markers and e) makes evenly spaced data look reasonably even.

@mdboom mdboom mentioned this pull request Mar 1, 2012
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.

3 participants