From bd163c28387116dc4b11b703cba5dc9d25af2967 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Fri, 4 Aug 2023 11:40:36 -0700 Subject: [PATCH] Make `VoxelBrush::transform()` into `rotate()`. This accounts for all the actual uses, and avoids confusion between points and cubes. --- CHANGELOG.md | 2 ++ all-is-cubes-content/src/dungeon/demo_dungeon.rs | 2 +- all-is-cubes-content/src/exhibits.rs | 2 +- all-is-cubes/src/drawing.rs | 13 ++++++------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4603be653..9b2057edc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ - `math::GridMatrix::decompose()` - `space::Space::draw_target()` - `space::SpaceTransaction::draw_target()` + - `drawing::VoxelBrush::transform()` is renamed to `rotate()` and only accepts a rotation. + This avoids confusion between points in space and cube-identifying coordinates. ### Removed diff --git a/all-is-cubes-content/src/dungeon/demo_dungeon.rs b/all-is-cubes-content/src/dungeon/demo_dungeon.rs index 4fbcdfe56..799299d36 100644 --- a/all-is-cubes-content/src/dungeon/demo_dungeon.rs +++ b/all-is-cubes-content/src/dungeon/demo_dungeon.rs @@ -660,7 +660,7 @@ pub async fn install_dungeon_blocks( space_from_image(include_image!("floor.png"), GridRotation::RXZY, |pixel| { let block = Block::from(Rgba::from_srgb8(pixel.0)); VoxelBrush::with_thickness(block, 0..resolution.into()) - .transform(GridRotation::RXZY.to_rotation_matrix()) + .rotate(GridRotation::RXZY) })?; Block::builder() .display_name("Floor Tile") diff --git a/all-is-cubes-content/src/exhibits.rs b/all-is-cubes-content/src/exhibits.rs index 083ecfa9f..01fe12cb3 100644 --- a/all-is-cubes-content/src/exhibits.rs +++ b/all-is-cubes-content/src/exhibits.rs @@ -1072,7 +1072,7 @@ async fn IMAGES(_: &Exhibit, universe: &mut Universe) { let image::Rgba([r, g, b, a]) = pixel; if (r > b || g > b) && a > 0 { let block = Block::from(Rgba::from_srgb8(pixel.0)); - VoxelBrush::with_thickness(block, 0..2).transform(rotation.to_rotation_matrix()) + VoxelBrush::with_thickness(block, 0..2).rotate(rotation) } else { default_srgb(pixel) } diff --git a/all-is-cubes/src/drawing.rs b/all-is-cubes/src/drawing.rs index 72b6f2589..2a0558005 100644 --- a/all-is-cubes/src/drawing.rs +++ b/all-is-cubes/src/drawing.rs @@ -15,7 +15,7 @@ //! and rectangles have inclusive upper bounds (whereas our [`GridAab`]s have //! exclusive upper bounds). -use cgmath::{EuclideanSpace as _, Transform as _}; +use cgmath::EuclideanSpace as _; use embedded_graphics::geometry::{Dimensions, Point, Size}; use embedded_graphics::pixelcolor::{PixelColor, Rgb888, RgbColor}; use embedded_graphics::prelude::{DrawTarget, Drawable, Pixel}; @@ -29,8 +29,8 @@ pub use embedded_graphics; use crate::block::{space_to_blocks, Block, BlockAttributes, Resolution}; use crate::math::{ - Face6, FaceMap, GridAab, GridCoordinate, GridMatrix, GridPoint, GridRotation, GridVector, - Gridgid, Rgb, Rgba, + Face6, FaceMap, GridAab, GridCoordinate, GridPoint, GridRotation, GridVector, Gridgid, Rgb, + Rgba, }; use crate::space::{SetCubeError, Space, SpacePhysics, SpaceTransaction}; use crate::universe::Universe; @@ -365,12 +365,11 @@ impl<'a> VoxelBrush<'a> { self } - /// Apply the given transform to the position of each block. + /// Apply the given rotation (about the no-offset block) to the position of each block. #[must_use] - pub fn transform(mut self, transform: GridMatrix) -> Self { + pub fn rotate(mut self, rotation: GridRotation) -> Self { for (block_offset, _) in self.0.iter_mut() { - // TODO: shouldn't this be transform_cube? - *block_offset = transform.transform_point(*block_offset); + *block_offset = GridPoint::from_vec(rotation.transform_vector(block_offset.to_vec())); } self }