Skip to content

Commit

Permalink
inv: Avoid numeric overflow on rotating IconRow.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Sep 6, 2024
1 parent e938869 commit e3e29b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions all-is-cubes-base/src/math/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ impl GridRotation {
///
/// May panic or wrap if `vector` has any components equal to [`GridCoordinate::MIN`].
#[inline]
#[track_caller]
pub fn transform_vector(self, vector: GridVector) -> GridVector {
#[inline(always)]
fn inner(rotation: GridRotation, vector: GridVector) -> Option<GridVector> {
Expand Down
8 changes: 6 additions & 2 deletions all-is-cubes/src/inv/inv_in_block.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Configuration of inventories owned by blocks ([`Modifier::Inventory`]).
use alloc::vec::Vec;
use euclid::Point3D;

use euclid::{Point3D, Vector3D};

use crate::block::Resolution;
use crate::math::{GridCoordinate, GridPoint, GridRotation, GridVector, Gridgid};
Expand Down Expand Up @@ -192,7 +193,10 @@ impl IconRow {
first_slot: self.first_slot,
count: self.count,
origin: transform.transform_point(self.origin), // TODO: does not account for size of icon
stride: transform.rotation.transform_vector(self.stride),
stride: transform.rotation.transform_vector(
// Kludge: clamped to avoid numeric overflow of `i32::MIN`
self.stride.max(Vector3D::splat(-i32::MAX)),
),
}
}
}
Expand Down

0 comments on commit e3e29b1

Please sign in to comment.