-
Notifications
You must be signed in to change notification settings - Fork 4
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 precision argument with default value #13
Comments
Looking at this with reference to the cheatsheet here: https://floating-point-gui.de/languages/rust/ |
OK maybe not, only has 4 stars on GitHub: https://github.com/0x022b/libmath-rs Any advice @dabreegster ? I'm still looking and learning. |
Latest thinking: fmt lines only works for printing. Planning to try this approach: https://stackoverflow.com/questions/63214346/how-to-truncate-f64-to-2-decimal-places |
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=608a9849b07c0916a651d18b7e1a744c The stackoverflow approach is good. I would advise creating a new utility method |
Sounds like a good idea. Do I need another for loop to iterate over every element? So far I have this but fn round(poly: &mut Polygon<f64>, precision: usize) {
poly.exterior_mut(f64::trunc(before * 100.0) / 100.0;)
} |
https://docs.rs/geo/0.17.1/geo/struct.Polygon.html#method.exterior_mut In this case, the closure is given a mutable ... But actually as I look at the docs, I spotted https://docs.rs/geo/0.17.1/geo/algorithm/map_coords/trait.MapCoordsInplace.html. This is implemented for |
Awesome, guessed there would be a more direct way. Will give it a spin! |
OK follow-up question, I now have this which seems to be working: fn round(poly: &mut Polygon<f64>, precision: usize) {
poly.map_coords_inplace(|&(x, y)| (x + 1000., y * 2.))
}
pub fn clockboard(
centerpoint: Point<f64>,
params: Params,
boundary: Option<Polygon<f64>>,
) -> Vec<Polygon<f64>> {
let mut polygons = Vec::new();
let circle = makecircle(centerpoint, params.distances[0], params.num_vertices);
polygons.push(circle);
polygons
} How do apply to round function to polygon option? Like this in the penultimate line would seem reasonable to me:
But that fails with
|
The error says Your next issue is that you can't do |
Think this is good to go. Please review/merge Dustin when you get a chance. Many thanks! |
Closed in #16 |
As stated by @mvl22 here cyipt/actdev#10 5 decimal places ~1m accuracy which is probably enough for many purposes assuming 1 km starting size (1/1000 accuracy).
Could be a new arg in the new Params struct, concept I've just discovered!
The text was updated successfully, but these errors were encountered: