diff --git a/src/conversions.rs b/src/conversions.rs index e2074e3..e6d214e 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -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); } } diff --git a/src/v0.rs b/src/v0.rs index a2136ce..bdff407 100644 --- a/src/v0.rs +++ b/src/v0.rs @@ -13,30 +13,30 @@ pub struct UnpackedCellID { impl From 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 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 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, } diff --git a/tests/algorithm.rs b/tests/algorithm.rs index f3042e5..b0785ca 100644 --- a/tests/algorithm.rs +++ b/tests/algorithm.rs @@ -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); } }