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

Add translation trait #128

Merged
merged 1 commit into from
Aug 5, 2017
Merged

Add translation trait #128

merged 1 commit into from
Aug 5, 2017

Conversation

urschrei
Copy link
Member

No description provided.

.map(|point| {
let new_x = point.x() + x_offset;
let new_y = point.y() + y_offset;
Point::new(new_x, new_y)
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should add a Points::map method to map coordinates to new values

Copy link
Member

Choose a reason for hiding this comment

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

I am working on something like this which would do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I follow, but if @rory does, I'll just wait on the PR!
IMO rotate / translate / skew / scale should all be implemented on top of a more general affine impl that populates an affine transformation matrix with the relevant values depending on the transformation type, but that would require us to pull in a linear algebra crate…

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I follow, but if @rory does, I'll just wait on the PR!

for example:

fn translation_matrix<T>(x_offset: T, y_offset: T, points: &[Point<T>]) -> Vec<Point<T>>
    where T: Float
{
    points
        .iter()
        .map(|point| point.map(|x, y| (x + x_offset, y + y_offset))
        .collect::<Vec<_>>()
}

Copy link
Member

Choose a reason for hiding this comment

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

My WIP is here: https://github.com/rory/rust-geo/tree/coord_change. Specifically you can see the file here amandasaurus@b7a01f5 . My idea is to allow you to pass in a function which will take a Coordinate and return a new Coordinate, which gives you maximum flexibility. I don't like the name (coord_change), but can't think of much better.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe map_coords? That's what python-geojson calls it https://pypi.python.org/pypi/geojson#map-coords

@frewsxcv
Copy link
Member

frewsxcv commented Aug 5, 2017

bors r+

bors bot added a commit that referenced this pull request Aug 5, 2017
128: Add translation trait r=frewsxcv
@bors
Copy link
Contributor

bors bot commented Aug 5, 2017

Build succeeded

@bors bors bot merged commit 6e822d5 into georust:master Aug 5, 2017
@urschrei urschrei deleted the translate branch August 5, 2017 15:21
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