Skip to content

Commit

Permalink
Rename FaceMap::repeat() to splat().
Browse files Browse the repository at this point in the history
This is consistent with `euclid` vector types. Also, it's shorter.
  • Loading branch information
kpreid committed Sep 7, 2024
1 parent c3b220d commit f078f3f
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- `block::EvalBlockError` is now a `struct` with an inner `ErrorKind` enum, instead of an enum, and contains more information.
- `block::Move`’s means of construction have been changed to be more systematic and orthogonal. In particular, paired moves are constructed from unpaired ones.

- `math::FaceMap::repeat()` has been renamed to `splat()`, for consistency with the same concept in the `euclid` vector types which we use.
- `math::GridAab::expand()` now takes unsigned values; use `GridAab::shrink()` instead of negative ones. This allows both versions to never panic.

- `all-is-cubes-gpu` library:
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-base/src/math/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ impl<V> FaceMap<V> {
impl<V: Clone> FaceMap<V> {
/// Constructs a [`FaceMap`] containing clones of the provided value.
#[inline]
pub fn repeat(value: V) -> Self {
pub fn splat(value: V) -> Self {
Self {
nx: value.clone(),
ny: value.clone(),
Expand All @@ -809,11 +809,11 @@ impl<V: Clone> FaceMap<V> {
impl<V: Copy> FaceMap<V> {
/// Constructs a [`FaceMap`] containing copies of the provided value.
///
/// This is practically identical to [`FaceMap::repeat()`] except that it is a
/// This is practically identical to [`FaceMap::splat()`] except that it is a
/// `const fn`. It may be removed from future major versions once Rust supports const
/// trait function calls.
#[inline]
pub const fn repeat_copy(value: V) -> Self {
pub const fn splat_copy(value: V) -> Self {
Self {
nx: value,
ny: value,
Expand Down
3 changes: 0 additions & 3 deletions all-is-cubes-base/src/math/vol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ where
}

/// Constructs a `Vol<C>` by cloning the provided value for each point.
///
/// TODO: This feels like it should be called 'filled' or 'cloned', but if so,
/// maybe [`FaceMap::repeat`](crate::math::FaceMap::repeat) should also change?
#[inline]
pub fn repeat(bounds: GridAab, value: V) -> Self
where
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-base/src/raycast/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ fn intersection_point_random_test() {
// A one-cube box, so that all possible rays should either intersect
// exactly this cube, or none at all.
let bounds = GridAab::from_lower_size([0, 0, 0], [1, 1, 1]);
let ray_origins: Aab = bounds.expand(FaceMap::repeat(1)).to_free();
let ray_origins: Aab = bounds.expand(FaceMap::splat(1)).to_free();

let mut rng = rand_xoshiro::Xoshiro256Plus::seed_from_u64(0);
for _ in 0..1000 {
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-content/src/city.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ fn place_one_exhibit<I: Instant>(
// Amount by which the exhibit's own size is expanded to form walls and empty space
// for displaying it and allowing players to move around it.
let enclosure_thickness = match exhibit.placement {
Placement::Surface => FaceMap::repeat(1),
Placement::Surface => FaceMap::splat(1),
// Underground exhibits get no enclosure; they are expected to play nicely with being
// buried in stone except for the entranceway.
Placement::Underground => FaceMap::repeat(0),
Placement::Underground => FaceMap::splat(0),
};

// Now that we know the size of the exhibit, find a place for it that fits its bounds.
Expand Down Expand Up @@ -902,7 +902,7 @@ impl CityPlanner {
}

let for_occupancy_check =
transformed.expand(FaceMap::repeat(Self::GAP_BETWEEN_PLOTS));
transformed.expand(FaceMap::splat(Self::GAP_BETWEEN_PLOTS));

if self.is_occupied(for_occupancy_check) {
continue 'search;
Expand Down
8 changes: 4 additions & 4 deletions all-is-cubes-content/src/city/exhibits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ fn COLOR_LIGHTS(_: Context<'_>) {
[0, 0, 0],
Size3D::new(room_width, room_height, room_length).to_u32(),
);
let mut space = Space::empty(interior.expand(FaceMap::repeat(1)));
let mut space = Space::empty(interior.expand(FaceMap::splat(1)));

fn normalize(color: Rgb) -> Rgb {
color * color.luminance().recip()
Expand Down Expand Up @@ -1054,7 +1054,7 @@ fn COLOR_LIGHTS(_: Context<'_>) {
Some(wall_block.clone()),
Some(corner.rotate(GridRotation::RxYz)),
)
.create_box(interior.expand(FaceMap::repeat(1)))
.create_box(interior.expand(FaceMap::splat(1)))
.execute(&mut space, &mut transaction::no_outputs)?;

// Separators between floors
Expand Down Expand Up @@ -1159,7 +1159,7 @@ fn COLORED_BOUNCE(_: Context<'_>) {
GridPoint::splat(-interior_radius),
GridSize::splat(u32::try_from(interior_radius).unwrap() * 2 + 1),
);
let mut space = Space::empty(interior.expand(FaceMap::repeat(wall_thickness)));
let mut space = Space::empty(interior.expand(FaceMap::splat(wall_thickness)));

// Thick walls + interior cavity
space.fill_uniform(space.bounds(), &wall_block).unwrap();
Expand All @@ -1176,7 +1176,7 @@ fn COLORED_BOUNCE(_: Context<'_>) {

// Central reflecting block
space.fill_uniform(
GridAab::ORIGIN_CUBE.expand(FaceMap::repeat(1)),
GridAab::ORIGIN_CUBE.expand(FaceMap::splat(1)),
&reflecting_block,
)?;

Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes-content/src/dungeon/demo_dungeon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl DemoTheme {
None,
)
.with_interior(Some(AIR))
.create_box(interior.expand(FaceMap::repeat(1)))
.create_box(interior.expand(FaceMap::splat(1)))
.execute(space, &mut transaction::no_outputs)?;

Ok(())
Expand Down Expand Up @@ -309,7 +309,7 @@ impl Theme<Option<DemoRoom>> for DemoTheme {
.y
+ 1;
four_walls(
interior.expand(FaceMap::repeat(1)),
interior.expand(FaceMap::splat(1)),
|origin, along_wall, length, wall_excluding_corners_box| {
let wall = GridRotation::CLOCKWISE.transform(along_wall); // TODO: make four_walls provide this in a nice name
if let WallFeature::Window = room_data.wall_features[wall] {
Expand Down Expand Up @@ -411,7 +411,7 @@ pub(crate) async fn demo_dungeon(

let dungeon_grid = DungeonGrid {
room_box: GridAab::from_lower_size([0, 0, 0], [9, 5, 9]),
room_wall_thickness: FaceMap::repeat(1),
room_wall_thickness: FaceMap::splat(1),
gap_between_walls: Size3D::new(1, 1, 1),
};
let perimeter_margin: GridSizeCoord = 30;
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-content/src/dungeon/maze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn generate_maze(seed: u64, requested_rooms: GridSize) -> Maze {
GridAab::from_lower_size([0, 0, 0], requested_rooms),
MazeRoom {
kind: MazeRoomKind::Unoccupied,
passages: FaceMap::repeat(false),
passages: FaceMap::splat(false),
},
);

Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-content/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ async fn islands(
&& cell_bounds.size().depth >= margin * 2
{
let occupied_bounds = cell_bounds
.shrink(FaceMap::repeat(10).with(Face6::PY, 25))
.shrink(FaceMap::splat(10).with(Face6::PY, 25))
.unwrap();
wavy_landscape(occupied_bounds, &mut space, &landscape_blocks, 0.5)?;
}
Expand Down Expand Up @@ -464,7 +464,7 @@ async fn arbitrary_space(
// Patch spawn position to be reasonable
let bounds = space.bounds();
let mut spawn = space.spawn().clone();
spawn.set_bounds(bounds.expand(FaceMap::repeat(20)));
spawn.set_bounds(bounds.expand(FaceMap::splat(20)));
spawn.set_eye_position(bounds.center());
space.set_spawn(spawn);

Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes-gpu/src/in_wgpu/light_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn visible_light_volume(space_bounds: GridAab, camera: &Camera) -> GridAab {
.round_up_to_grid();
// Extra volume of 1 extra cube around all sides automatically captures sky light.
visible_bounds
.intersection_cubes(space_bounds.expand(FaceMap::repeat(1)))
.intersection_cubes(space_bounds.expand(FaceMap::splat(1)))
.unwrap_or(GridAab::ORIGIN_CUBE)
}

Expand Down Expand Up @@ -163,7 +163,7 @@ impl LightTexture {
///
/// Returns the volume (number of cubes) that needed to be copied to the texture.
pub fn ensure_mapped(&mut self, queue: &wgpu::Queue, space: &Space, region: GridAab) -> usize {
let Some(region) = region.intersection_cubes(space.bounds().expand(FaceMap::repeat(1)))
let Some(region) = region.intersection_cubes(space.bounds().expand(FaceMap::splat(1)))
else {
return 0;
};
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-mesh/examples/visualize-block-mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn make_transparent_block(universe: &mut Universe) -> Block {
.build();
let resolution = Resolution::R16;
let solid_box = GridAab::for_block(resolution)
.shrink(FaceMap::repeat(2))
.shrink(FaceMap::splat(2))
.unwrap();
let transparent_box = GridAab::for_block(resolution).abut(Face6::PX, -4).unwrap();
let emissive_box = GridAab::for_block(resolution).abut(Face6::NX, -4).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-mesh/src/block_mesh/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn unflatten(
impl Analysis {
pub fn empty() -> Self {
Analysis {
occupied_planes: FaceMap::repeat([EMPTY_PLANE_BOX; MAX_PLANES]),
occupied_planes: FaceMap::splat([EMPTY_PLANE_BOX; MAX_PLANES]),
needs_texture: false,
resolution: Resolution::R1,
}
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-mesh/src/space_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ impl Snapshot {
#[allow(dead_code)]
pub(crate) fn new(space: &Space, bounds: GridAab) -> Snapshot {
let expanded_bounds = bounds
.expand(FaceMap::repeat(1))
.expand(FaceMap::splat(1))
.intersection_box(space.bounds())
.unwrap_or(GridAab::ORIGIN_EMPTY);
Snapshot {
Expand Down
8 changes: 4 additions & 4 deletions all-is-cubes-mesh/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,15 @@ fn opacities<M: MeshTypes>(mesh: &BlockMesh<M>) -> FaceMap<bool> {
fn atom_transparency() {
assert_eq!(
opacities(&test_block_mesh(color_block!(Rgba::WHITE))),
FaceMap::repeat(true)
FaceMap::splat(true)
);
assert_eq!(
opacities(&test_block_mesh(color_block!(Rgba::TRANSPARENT))),
FaceMap::repeat(false)
FaceMap::splat(false)
);
assert_eq!(
opacities(&test_block_mesh(color_block!(1.0, 1.0, 1.0, 0.5))),
FaceMap::repeat(false)
FaceMap::splat(false)
);
}

Expand Down Expand Up @@ -610,7 +610,7 @@ fn invisible_voxel_block() {
"sanity check test data"
);

assert_eq!(opacities(&test_block_mesh(block)), FaceMap::repeat(false));
assert_eq!(opacities(&test_block_mesh(block)), FaceMap::splat(false));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn generate_light_ray_pattern() -> Vec<OneRay> {
{
let direction = Vector3D::new(x as f32, y as f32, z as f32).normalize();

let mut cosines = FaceMap::repeat(0.0f32);
let mut cosines = FaceMap::splat(0.0f32);
for face in Face6::ALL {
let unit_vector: FreeVector = face.normal_vector();
let cosine = unit_vector.to_f32().dot(direction.to_f32()).max(0.0);
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes/src/block/eval/derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ pub(in crate::block::eval) fn compute_derived(
let visible = !color.fully_transparent() || emission != Rgb::ZERO;
return Derived {
color,
face_colors: FaceMap::repeat(color),
face_colors: FaceMap::splat(color),
light_emission: emission,
opaque: FaceMap::repeat(color.fully_opaque()),
opaque: FaceMap::splat(color.fully_opaque()),
visible,
uniform_collision: Some(collision),
voxel_opacity_mask: VoxelOpacityMask::new_r1(voxel),
Expand All @@ -116,7 +116,7 @@ pub(in crate::block::eval) fn compute_derived(
// of all six faces by tracing in from the edges, and then averages them.
let (color, face_colors, emission): (Rgba, FaceMap<Rgba>, Rgb) = {
let mut all_faces_sum = VoxSum::default();
let mut face_colors = FaceMap::repeat(Rgba::TRANSPARENT);
let mut face_colors = FaceMap::splat(Rgba::TRANSPARENT);

// Loop over all face voxels.
// (This is a similar structure to the algorithm we use for mesh generation.)
Expand Down
8 changes: 4 additions & 4 deletions all-is-cubes/src/block/eval/evaluated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl fmt::Debug for EvaluatedBlock {
ds.field("attributes", attributes);
}
ds.field("color", color);
if *face_colors != FaceMap::repeat(*color) {
if *face_colors != FaceMap::splat(*color) {
ds.field("face_colors", face_colors);
}
if *light_emission != Rgb::ZERO {
Expand Down Expand Up @@ -256,7 +256,7 @@ impl EvaluatedBlock {
/// TODO: Review uses of .opaque and .visible and see if they can be usefully replaced
/// by this.
pub(crate) fn opacity_as_category(&self) -> OpacityCategory {
if self.derived.opaque == FaceMap::repeat(true) {
if self.derived.opaque == FaceMap::splat(true) {
OpacityCategory::Opaque
} else if !self.derived.visible {
OpacityCategory::Invisible
Expand Down Expand Up @@ -368,9 +368,9 @@ const AIR_ATTRIBUTES: BlockAttributes = BlockAttributes {

const AIR_DERIVED: Derived = Derived {
color: Rgba::TRANSPARENT,
face_colors: FaceMap::repeat_copy(Rgba::TRANSPARENT),
face_colors: FaceMap::splat_copy(Rgba::TRANSPARENT),
light_emission: Rgb::ZERO,
opaque: FaceMap::repeat_copy(false),
opaque: FaceMap::splat_copy(false),
visible: false,
uniform_collision: Some(BlockCollision::None),
voxel_opacity_mask: VoxelOpacityMask::R1_INVISIBLE,
Expand Down
6 changes: 3 additions & 3 deletions all-is-cubes/src/block/eval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ fn from_voxels_zero_bounds() {
attributes,
derived: Derived {
color: Rgba::TRANSPARENT,
face_colors: FaceMap::repeat(Rgba::TRANSPARENT),
face_colors: FaceMap::splat(Rgba::TRANSPARENT),
light_emission: Rgb::ZERO,
opaque: FaceMap::repeat(false),
opaque: FaceMap::splat(false),
visible: false,
uniform_collision: Some(BlockCollision::None),
voxel_opacity_mask: block::VoxelOpacityMask::new(resolution, voxels.as_vol_ref()),
Expand All @@ -189,7 +189,7 @@ fn from_voxels_zero_bounds() {
fn overall_color_ignores_interior() {
let resolution = R8;
let outer_bounds = GridAab::for_block(resolution);
let inner_bounds = outer_bounds.shrink(FaceMap::repeat(1)).unwrap();
let inner_bounds = outer_bounds.shrink(FaceMap::splat(1)).unwrap();
let outer_color = Rgba::new(1.0, 0.0, 0.0, 1.0);
let inner_color = Rgba::new(0.0, 1.0, 0.0, 1.0);
let voxels = Evoxels::from_many(
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes/src/block/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ mod tests {
color: be.color(),
face_colors: be.face_colors().rotate(rotation),
light_emission: Rgb::ZERO,
opaque: FaceMap::repeat(false).with(rotation.transform(Face6::NY), true),
opaque: FaceMap::splat(false).with(rotation.transform(Face6::NY), true),
visible: true,
uniform_collision: Some(BlockCollision::Hard),
voxel_opacity_mask: block::VoxelOpacityMask::new_raw(
Expand Down
4 changes: 2 additions & 2 deletions all-is-cubes/src/block/modifier/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ mod tests {
pz: color.to_rgb().with_alpha(notnan!(0.5)),
},
light_emission: Rgb::ZERO,
opaque: FaceMap::repeat(false).with(Face6::PY, true),
opaque: FaceMap::splat(false).with(Face6::PY, true),
visible: true,
uniform_collision: None,
voxel_opacity_mask: VoxelOpacityMask::new_raw(
Expand Down Expand Up @@ -333,7 +333,7 @@ mod tests {
pz: color.to_rgb().with_alpha(notnan!(0.5)),
},
light_emission: Rgb::ZERO,
opaque: FaceMap::repeat(false).with(Face6::PY, true),
opaque: FaceMap::splat(false).with(Face6::PY, true),
visible: true,
uniform_collision: None,
voxel_opacity_mask: VoxelOpacityMask::new_raw(
Expand Down
Loading

0 comments on commit f078f3f

Please sign in to comment.