-
Notifications
You must be signed in to change notification settings - Fork 24
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
How to reproduce the same cell pattern around different indexes? #15
Comments
There is a set of functions for working with local coordinates, called |
Is there any good description of how to address specific cells? I found some here, but I can't make sense of it.
For more context here is an example of what pattern I am talking about: |
Yup that's right. To get the let local_ij = cell_index.to_local_ij(anchor); To get a let cell_index = CellIndex::try_from(local_ij); |
How do I choose anchor? |
They are the same in this context, that's two different way to call the same thing.
The origin/anchor in this case is the index you want to draw around.
The So, if I understand your use case correctly, the code you need could look like this: fn transpose_pattern(src: CellIndex, dst: CellIndex, pattern: &[CellIndex]) -> Vec<CellIndex> {
// Compute translation offset.
let src_coord = src.to_local_ij(src).expect("src coord");
let dst_coord = dst.to_local_ij(dst).expect("dst coord");
let i_offset = dst_coord.i() - src_coord.i();
let j_offset = dst_coord.j() - src_coord.j();
// Transpose the pattern from src to dst.
pattern
.iter()
.copied()
.map(|cell| {
// Compute the local IJ coordinate wrt original center cell.
let src_ij = cell.to_local_ij(src).expect("local IJ");
// Apply translation and re-anchor at destination center cell.
let dst_ij = LocalIJ::new_unchecked(dst, src_ij.i() + i_offset, src_ij.j() + j_offset);
// Convert back to cell index.
CellIndex::try_from(dst_ij).expect("dst cell")
})
.collect::<Vec<_>>()
} With:
I do plan to have a public method for that, but I've postponed it until now since I didn't have a use case for it. |
Thank you for the snippet! As I understand this can only move patterns until local coordinates are valid. I am ok with the restriction on the size of the pattern, but is there a way to reconstruct the pattern in For example, somehow to remember |
The snippet does that, it's not limited by the distance between Pattern could be stored as a struct like that: struct Pattern {
anchor: CellIndex,
pattern: Vec<(i32, i32)>,
} Where the Then you could have an API like that: impl Pattern {
pub fn new(anchor: CellIndex, pattern: &[CellIndex]) -> Self {
Self {
anchor,
pattern: pattern
.iter()
.map(|&cell| {
let coord = cell.to_local_ij(anchor).expect("local IJ");
(coord.i(), coord.j())
})
.collect(),
}
}
pub fn draw(&self, anchor: CellIndex) -> Vec<CellIndex> {
// Compute translation offset.
let src_coord = self.anchor.to_local_ij(self.anchor).expect("src coord");
let dst_coord = anchor.to_local_ij(anchor).expect("dst coord");
let i_offset = dst_coord.i() - src_coord.i();
let j_offset = dst_coord.j() - src_coord.j();
self.pattern
.iter()
.copied()
.map(|coord| {
let dst_coord =
LocalIJ::new_unchecked(anchor, coord.0 + i_offset, coord.1 + j_offset);
// Convert back to cell index.
CellIndex::try_from(dst_coord).expect("dst cell")
})
.collect::<Vec<_>>()
}
} The |
It works!!! Thank you so much |
This simplifies/makes possible use cases like #15 But now that user can create arbitrary local IJ coordinates, the code that handles it must be more robust (hence the overflow handling, the new test cases and the extra fuzz target).
I asked the same question on stackoverflow, but it seems like it won't be answered.
I need some way of address the cell's neghbours depending their relative position. As I understand the order is not determined even in the safe variants of neighbor traversal.
Is there any way to have local coordinates in h3o?
The only relevant thing I found is the
Direction
enum, but it is used for other thing.P.S. Feel free to remove the issue if it is a wrong place to ask this.
The text was updated successfully, but these errors were encountered: