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

Some Position utility methods for approximate offsets #243

Merged
merged 1 commit into from
Nov 17, 2020

Conversation

daboross
Copy link
Collaborator

@daboross daboross commented Sep 2, 2019

Just some methods which could be useful?

I'm on the edge for whether these do belong in this library, but if they're useful to people they shouldn't hurt too much.

If not, maybe now would be a good time to add a "position_utils" addon library?

@daboross daboross force-pushed the approximate-offset-position-methods branch from 6a262a8 to 7f9f0d3 Compare September 2, 2019 21:51
Copy link
Collaborator

@ASalvail ASalvail left a comment

Choose a reason for hiding this comment

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

The documentation needs some refining.

As to whether to include this in the api... I'd say "no", but it's very useful 😂 It's definitely not just an interface to screeps in js. This opens the door to more code that makes life easier. As the main author, it's your call.

If we're not sure, maybe keep a separate branch from master that has goodies included (although I feel we'll eventually just merge it with master anyway).

use super::Position;

impl Position {
/// Calculates an approximate midpoint between this point and the target.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a midpoint (as in, it's not in the middle). It's distance_towards_target from this point towards the other point. (with big caveats)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, this line is suspiciously like the first one of the next function 😛

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe: midpoint -> offset

///
/// If `distance_from_target` is bigger than the distance to the target,
/// this position is returned.
pub fn between<T>(self, target: &T, distance_from_target: i32) -> Position
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that the other is toward, wouldn't this be more understandable as from?

/// Calculates an approximate midpoint between this point and the target.
///
/// In case of a tie, rounds towards the target.
pub fn midpoint_between<T>(self, target: &T) -> Position
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: midpoint_between -> midpoint_to
It reads better.

self + (new_offset_x, new_offset_y)
}

/// Calculates an approximate midpoint between this point and the target.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same: midpoint offset

.map(|s| s.parse().unwrap())
}

fn pos(room: RoomName, x: u32, y: u32) -> Position {
Copy link
Collaborator

Choose a reason for hiding this comment

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

use super::Position::new as pos;? 😛

@daboross
Copy link
Collaborator Author

Sorry I've just kind of left this. Really glad to have your review, and once I have the time to be more active again, I'll be fixing the things! (and possibly just sending the code into a separate crate anyways...)

@ASalvail ASalvail merged commit c5f0e23 into master Nov 17, 2020
@ASalvail
Copy link
Collaborator

Just for cleanup's sake.

@ASalvail ASalvail deleted the approximate-offset-position-methods branch November 17, 2020 03:34
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.

2 participants