Skip to content

Commit

Permalink
Fix for _vox_models_are_equal comparing two models with the same volu…
Browse files Browse the repository at this point in the history
…me but different dimensions as equal
  • Loading branch information
dougbinks authored and jpaver committed Sep 30, 2023
1 parent c40fe60 commit 69b2b99
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/ogt_vox.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,13 +1162,12 @@
// if hashes match, they might be equal OR there might be a hash collision.
if (lhs->voxel_hash != rhs->voxel_hash)
return false;
// early out: if number of voxels in the model's grid don't match, they can't be equal.
uint32_t num_voxels_lhs = lhs->size_x * lhs->size_y * lhs->size_z;
uint32_t num_voxels_rhs = rhs->size_x * rhs->size_y * rhs->size_z;
if (num_voxels_lhs != num_voxels_rhs)
// early out: if size of voxels in the model's grid don't match, they can't be equal.
if (lhs->size_x != rhs->size_x || lhs->size_y != rhs->size_y || lhs->size_z != rhs->size_z )
return false;
// Finally, we know their hashes are the same, and their dimensions are the same
// but they are only equal if they have exactly the same voxel data.
uint32_t num_voxels_lhs = lhs->size_x * lhs->size_y * lhs->size_z;
return memcmp(lhs->voxel_data, rhs->voxel_data, num_voxels_lhs) == 0 ? true : false;
}

Expand Down

0 comments on commit 69b2b99

Please sign in to comment.