Rename cell_id to cellid

This commit is contained in:
Austen Adler 2023-02-28 09:20:30 -05:00
parent d1e6f536fb
commit 524d1f85d2
3 changed files with 23 additions and 23 deletions

View File

@ -34,10 +34,10 @@ mod tests {
assert_eq!(extract_binary(0b111100_0_1, 1..=1), 0b0);
// A full test from the docs
let cell_id = 0b0100101110101000_1011100010010011_1001001100100100_1100000000000000_u64;
assert_eq!(extract_binary(cell_id, 15..=24), 0b10_01001001);
assert_eq!(extract_binary(cell_id, 25..=37), 0b01001_11001001);
assert_eq!(extract_binary(cell_id, 38..=50), 0b00010_11100010);
assert_eq!(extract_binary(cell_id, 51..=63), 0b01001_01110101);
let cellid = 0b0100101110101000_1011100010010011_1001001100100100_1100000000000000_u64;
assert_eq!(extract_binary(cellid, 15..=24), 0b10_01001001);
assert_eq!(extract_binary(cellid, 25..=37), 0b01001_11001001);
assert_eq!(extract_binary(cellid, 38..=50), 0b00010_11100010);
assert_eq!(extract_binary(cellid, 51..=63), 0b01001_01110101);
}
}

View File

@ -13,30 +13,30 @@ pub struct UnpackedCellID {
impl From<CellID> for UnpackedCellID {
/// Convert a `CellID` to an `UnpackedCellID`
fn from(cell_id: CellID) -> Self {
Self::from(cell_id.0)
fn from(cellid: CellID) -> Self {
Self::from(cellid.0)
}
}
impl From<u64> for UnpackedCellID {
fn from(cell_id: u64) -> Self {
fn from(cellid: u64) -> Self {
Self {
number_bits: conversions::extract_binary(cell_id, 15..=24) as u16,
word0_bits: conversions::extract_binary(cell_id, 25..=37) as u16,
word1_bits: conversions::extract_binary(cell_id, 38..=50) as u16,
word2_bits: conversions::extract_binary(cell_id, 51..=63) as u16,
number_bits: conversions::extract_binary(cellid, 15..=24) as u16,
word0_bits: conversions::extract_binary(cellid, 25..=37) as u16,
word1_bits: conversions::extract_binary(cellid, 38..=50) as u16,
word2_bits: conversions::extract_binary(cellid, 51..=63) as u16,
}
}
}
impl From<UnpackedCellID> for Address<'_> {
fn from(unpacked_cell_id: UnpackedCellID) -> Self {
let word0 = words::NUMBER_TO_WORDS[unpacked_cell_id.word0_bits as usize][0];
let word1 = words::NUMBER_TO_WORDS[unpacked_cell_id.word1_bits as usize][0];
let word2 = words::NUMBER_TO_WORDS[unpacked_cell_id.word2_bits as usize][0];
fn from(unpacked_cellid: UnpackedCellID) -> Self {
let word0 = words::NUMBER_TO_WORDS[unpacked_cellid.word0_bits as usize][0];
let word1 = words::NUMBER_TO_WORDS[unpacked_cellid.word1_bits as usize][0];
let word2 = words::NUMBER_TO_WORDS[unpacked_cellid.word2_bits as usize][0];
Self {
number: u32::from(unpacked_cell_id.number_bits),
number: u32::from(unpacked_cellid.number_bits),
words: [word0, word1, word2],
version: Version::V0,
}

View File

@ -29,25 +29,25 @@ fn test_cellid_translation() {
eprintln!(
"Entry: ({},{}) => {:0>64b}",
entry.lat, entry.lon, entry.cell_id
entry.lat, entry.lon, entry.cellid
);
eprintln!("\taddr: {addr}");
// Make sure the rust s2 implementation is accurate
assert_eq!(entry.cell_id, CellID(entry.cell_id).0);
assert_eq!(entry.cellid, CellID(entry.cellid).0);
assert_eq!(
(entry.cell_id & CELLID_LEVEL_23_BITMASK) | CELLID_LEVEL_23_END_BIT,
CellID(entry.cell_id).parent(CELLID_LEVEL).0
(entry.cellid & CELLID_LEVEL_23_BITMASK) | CELLID_LEVEL_23_END_BIT,
CellID(entry.cellid).parent(CELLID_LEVEL).0
);
// Make sure the address is at the right level
assert_eq!(addr_cellid.level(), CELLID_LEVEL);
// Next, check if creating an address from a cellid matches itself
assert_eq!(addr, Address::from_cellid_u64(entry.cell_id));
assert_eq!(addr, Address::from_cellid_u64(entry.cellid));
// Now check if the actual cell id matches
assert_eq_u64!(addr_cellid.0, CellID(entry.cell_id).parent(CELLID_LEVEL).0);
assert_eq_u64!(addr_cellid.0, CellID(entry.cellid).parent(CELLID_LEVEL).0);
}
}