Skip to content

Commit

Permalink
Make VoxelBrush::transform() into rotate().
Browse files Browse the repository at this point in the history
This accounts for all the actual uses, and avoids confusion between
points and cubes.
  • Loading branch information
kpreid committed Aug 4, 2023
1 parent 1aae8a8 commit bd163c2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-content/src/dungeon/demo_dungeon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-content/src/exhibits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
13 changes: 6 additions & 7 deletions all-is-cubes/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit bd163c2

Please sign in to comment.