Skip to content

Commit c0aff19

Browse files
committed
Use integer divisibility methods across the workspace
1 parent c47db5f commit c0aff19

12 files changed

Lines changed: 37 additions & 34 deletions

File tree

copc-core/src/columns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl ColumnSpec {
271271
let width = self.extra_byte_width().ok_or_else(|| {
272272
Error::InvalidInput("ExtraBytes column requires a non-zero byte width".into())
273273
})?;
274-
if data.len() % width != 0 {
274+
if !data.len().is_multiple_of(width) {
275275
return Err(Error::InvalidInput(format!(
276276
"ExtraBytes column has {} bytes, which is not divisible by byte width {width}",
277277
data.len()

copc-core/src/hierarchy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl HierarchyPage {
211211
}
212212

213213
pub fn from_le_bytes(bytes: &[u8]) -> Result<Self> {
214-
if bytes.len() % HIERARCHY_ENTRY_BYTES != 0 {
214+
if !bytes.len().is_multiple_of(HIERARCHY_ENTRY_BYTES) {
215215
return Err(Error::InvalidData(format!(
216216
"hierarchy page is {} bytes, not a multiple of {}",
217217
bytes.len(),

copc-core/src/info.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ impl CopcInfo {
8686
"COPC root hierarchy page is empty".into(),
8787
));
8888
}
89-
if self.root_hier_size % HIERARCHY_ENTRY_BYTES as u64 != 0 {
89+
if !self
90+
.root_hier_size
91+
.is_multiple_of(HIERARCHY_ENTRY_BYTES as u64)
92+
{
9093
return Err(Error::InvalidData(format!(
9194
"COPC root hierarchy size {} is not a multiple of {HIERARCHY_ENTRY_BYTES}",
9295
self.root_hier_size

copc-reader/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn read_hierarchy_page_at<R: Read + Seek>(
369369
if byte_size == 0 {
370370
return Err(Error::InvalidData("hierarchy page is empty".into()));
371371
}
372-
if byte_size % HIERARCHY_ENTRY_BYTES as u64 != 0 {
372+
if !byte_size.is_multiple_of(HIERARCHY_ENTRY_BYTES as u64) {
373373
return Err(Error::InvalidData(format!(
374374
"hierarchy page is {byte_size} bytes, not a multiple of {HIERARCHY_ENTRY_BYTES}"
375375
)));

copc-reader/src/points.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl ChunkColumnDecoder {
306306
let mut point_buf = vec![0u8; self.record_size];
307307
let mut accepted = 0usize;
308308
for decoded in 0..points_in_chunk {
309-
if decoded % CANCEL_POLL_STRIDE == 0 {
309+
if decoded.is_multiple_of(CANCEL_POLL_STRIDE) {
310310
if let Some(cancel) = cancel {
311311
cancel.check()?;
312312
}
@@ -780,7 +780,7 @@ impl<'a, R: Read + Seek + Send> PointIter<'a, R> {
780780
}
781781
}
782782

783-
if self.decoded_points % CANCEL_POLL_STRIDE == 0 {
783+
if self.decoded_points.is_multiple_of(CANCEL_POLL_STRIDE) {
784784
if let Some(cancel) = self.cancel {
785785
cancel.check()?;
786786
}

copc-reader/src/ranged.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<S: RangeRead> CopcRangeReader<S> {
310310
if !self.visited_pages.insert((page_entry.offset, byte_size)) {
311311
return Ok(());
312312
}
313-
if byte_size == 0 || byte_size % copc_core::HIERARCHY_ENTRY_BYTES as u64 != 0 {
313+
if byte_size == 0 || !byte_size.is_multiple_of(copc_core::HIERARCHY_ENTRY_BYTES as u64) {
314314
return Err(Error::InvalidData(format!(
315315
"hierarchy page is {byte_size} bytes, not a multiple of {}",
316316
copc_core::HIERARCHY_ENTRY_BYTES

copc-writer/src/lod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<S: CopcPointSource, W: Write> LodIndexBuilder<'_, S, W> {
155155
fn write_root_index_run(total_points: u32, cancel: &dyn CancelCheck) -> Result<IndexRun> {
156156
let mut writer = BufWriter::with_capacity(INDEX_IO_BUFFER_BYTES, new_index_tempfile("root")?);
157157
for index in 0..total_points {
158-
if index as usize % CANCEL_POLL_STRIDE == 0 {
158+
if (index as usize).is_multiple_of(CANCEL_POLL_STRIDE) {
159159
cancel.check()?;
160160
}
161161
writer
@@ -183,7 +183,7 @@ fn partition_index_run<S: CopcPointSource>(
183183
let mut counts = [0usize; 8];
184184
let center = bounds.center();
185185
for read_index in 0..run.count {
186-
if read_index % CANCEL_POLL_STRIDE == 0 {
186+
if read_index.is_multiple_of(CANCEL_POLL_STRIDE) {
187187
cancel.check()?;
188188
}
189189
let index = reader
@@ -276,7 +276,7 @@ fn append_index_run_to_order<W: Write>(
276276
) -> Result<()> {
277277
let mut reader = open_index_run(run)?;
278278
for read_index in 0..run.count {
279-
if read_index % CANCEL_POLL_STRIDE == 0 {
279+
if read_index.is_multiple_of(CANCEL_POLL_STRIDE) {
280280
cancel.check()?;
281281
}
282282
let index = reader

copc-writer/src/spill.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ mod tests {
276276
return_number: (seed % 5) as u8,
277277
number_of_returns: 5,
278278
classification: (seed % 32) as u8,
279-
scan_direction_flag: seed % 2 == 0,
280-
edge_of_flight_line: seed % 3 == 0,
279+
scan_direction_flag: seed.is_multiple_of(2),
280+
edge_of_flight_line: seed.is_multiple_of(3),
281281
scan_angle: (seed as f32) - 100.25,
282282
user_data: (seed % 256) as u8,
283283
point_source_id: seed as u16,
284-
synthetic: seed % 4 == 0,
284+
synthetic: seed.is_multiple_of(4),
285285
key_point: seed % 4 == 1,
286286
withheld: seed % 4 == 2,
287287
overlap: false,

copc-writer/src/validate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub(crate) fn validate_source_points<S: CopcPointSource>(
142142
let mut stats = PointStats::new();
143143
let mut fields = CopcPointFields::default();
144144
for index in 0..source.len() {
145-
if index % CANCEL_POLL_STRIDE == 0 {
145+
if index.is_multiple_of(CANCEL_POLL_STRIDE) {
146146
cancel.check()?;
147147
}
148148
let (x, y, z) = source.xyz(index)?;

copc-writer/src/writer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ where
123123
validate_streaming_layout_supported(&layout)?;
124124
let mut spill = SpillWriter::create(spill_dir, layout)?;
125125
for (index, item) in points.into_iter().enumerate() {
126-
if index % CANCEL_POLL_STRIDE == 0 {
126+
if index.is_multiple_of(CANCEL_POLL_STRIDE) {
127127
cancel.check()?;
128128
}
129129
spill.push(&item?)?;
@@ -193,7 +193,7 @@ fn convert_las_to_copc_streaming_inner(
193193
break;
194194
}
195195
for result in point_data.points() {
196-
if index % CANCEL_POLL_STRIDE == 0 {
196+
if index.is_multiple_of(CANCEL_POLL_STRIDE) {
197197
cancel.check()?;
198198
}
199199
let point = result.map_err(|e| Error::Las(e.to_string()))?;
@@ -597,7 +597,7 @@ fn encode_node_points<S: CopcPointSource>(
597597
.seek(SeekFrom::Start(node.start))
598598
.map_err(|e| Error::io("seek LOD order", e))?;
599599
for point_index in 0..node.count {
600-
if point_index % CANCEL_POLL_STRIDE == 0 {
600+
if point_index.is_multiple_of(CANCEL_POLL_STRIDE) {
601601
cancel.check()?;
602602
}
603603
let source_index = index_reader

0 commit comments

Comments
 (0)