common, voxygen: Consistent Err/Error naming

* Types are named `...Error`
* Enum variants are named `...Err`
This commit is contained in:
haslersn
2019-08-27 15:30:38 +02:00
parent e6ed834882
commit 4bc1a644ec
9 changed files with 60 additions and 60 deletions

View File

@ -53,7 +53,7 @@ impl<'a, V: ReadVol, F: RayUntil<V::Vox>, G: RayForEach> Ray<'a, V, F, G> {
self
}
pub fn cast(mut self) -> (f32, Result<Option<&'a V::Vox>, V::Err>) {
pub fn cast(mut self) -> (f32, Result<Option<&'a V::Vox>, V::Error>) {
// TODO: Fully test this!
const PLANCK: f32 = 0.001;

View File

@ -3,7 +3,7 @@ use crate::{
BaseVol, DefaultVolIterator, IntoVolIterator, ReadVol, SizedVol, VolSize, Vox, WriteVol,
},
volumes::{
chunk::{Chunk, ChunkErr},
chunk::{Chunk, ChunkError},
morton::{morton_to_xyz, xyz_to_morton, MortonIter},
},
};
@ -13,7 +13,7 @@ use vek::*;
#[derive(Debug)]
pub enum ChonkError {
SubChunkError(ChunkErr),
SubChunkError(ChunkError),
OutOfBounds,
}
@ -88,7 +88,7 @@ impl<V: Vox, S: VolSize, M: Clone> Chonk<V, S, M> {
impl<V: Vox, S: VolSize, M: Clone> BaseVol for Chonk<V, S, M> {
type Vox = V;
type Err = ChonkError;
type Error = ChonkError;
}
impl<V: Vox, S: VolSize, M: Clone> SizedVol for Chonk<V, S, M> {
@ -105,7 +105,7 @@ impl<V: Vox, S: VolSize, M: Clone> SizedVol for Chonk<V, S, M> {
impl<V: Vox, S: VolSize, M: Clone> ReadVol for Chonk<V, S, M> {
#[inline(always)]
fn get(&self, pos: Vec3<i32>) -> Result<&V, Self::Err> {
fn get(&self, pos: Vec3<i32>) -> Result<&V, Self::Error> {
if pos.z < self.get_min_z() {
// Below the terrain
Ok(&self.below)
@ -120,14 +120,14 @@ impl<V: Vox, S: VolSize, M: Clone> ReadVol for Chonk<V, S, M> {
* (self.z_offset + sub_chunk_idx * SubChunkSize::<S>::SIZE.z as i32);
self.sub_chunks[sub_chunk_idx as usize]
.get(rpos)
.map_err(Self::Err::SubChunkError)
.map_err(Self::Error::SubChunkError)
}
}
}
impl<V: Vox, S: VolSize, M: Clone> WriteVol for Chonk<V, S, M> {
#[inline(always)]
fn set(&mut self, pos: Vec3<i32>, block: Self::Vox) -> Result<(), Self::Err> {
fn set(&mut self, pos: Vec3<i32>, block: Self::Vox) -> Result<(), Self::Error> {
let mut sub_chunk_idx = self.sub_chunk_idx(pos.z);
if pos.z < self.get_min_z() {
@ -148,7 +148,7 @@ impl<V: Vox, S: VolSize, M: Clone> WriteVol for Chonk<V, S, M> {
- Vec3::unit_z() * (self.z_offset + sub_chunk_idx * SubChunkSize::<S>::SIZE.z as i32);
self.sub_chunks[sub_chunk_idx as usize] // TODO (haslersn): self.sub_chunks.get(...).and_then(...)
.set(rpos, block)
.map_err(Self::Err::SubChunkError)
.map_err(Self::Error::SubChunkError)
}
}

View File

@ -2,7 +2,7 @@ use super::{Block, BlockKind};
use crate::{
assets::{self, Asset},
vol::{BaseVol, ReadVol, SizedVol, Vox, WriteVol},
volumes::dyna::{Dyna, DynaErr},
volumes::dyna::{Dyna, DynaError},
};
use dot_vox::DotVoxData;
use std::fs::File;
@ -72,7 +72,7 @@ impl Structure {
impl BaseVol for Structure {
type Vox = StructureBlock;
type Err = StructureError;
type Error = StructureError;
}
impl ReadVol for Structure {
@ -80,7 +80,7 @@ impl ReadVol for Structure {
fn get(&self, pos: Vec3<i32>) -> Result<&Self::Vox, StructureError> {
match self.vol.get(pos + self.center) {
Ok(block) => Ok(block),
Err(DynaErr::OutOfBounds) => Ok(&self.empty),
Err(DynaError::OutOfBounds) => Ok(&self.empty),
}
}
}

View File

@ -19,12 +19,12 @@ pub trait Vox: Sized + Clone {
/// A volume that contains voxel data.
pub trait BaseVol {
type Vox: Vox;
type Err: Debug;
type Error: Debug;
}
impl<'a, T: BaseVol> BaseVol for &'a T {
type Vox = T::Vox;
type Err = T::Err;
type Error = T::Error;
}
// Utility types
@ -46,7 +46,7 @@ pub trait SizedVol: BaseVol {
/// A volume that provides read access to its voxel data.
pub trait ReadVol: BaseVol {
/// Get a reference to the voxel at the provided position in the volume.
fn get<'a>(&'a self, pos: Vec3<i32>) -> Result<&'a Self::Vox, Self::Err>;
fn get<'a>(&'a self, pos: Vec3<i32>) -> Result<&'a Self::Vox, Self::Error>;
fn ray<'a>(
&'a self,
@ -70,13 +70,13 @@ pub trait SampleVol<I>: BaseVol {
///
/// Note that the resultant volume has a coordinate space relative to the sample, not the
/// original volume.
fn sample(&self, range: I) -> Result<Self::Sample, Self::Err>;
fn sample(&self, range: I) -> Result<Self::Sample, Self::Error>;
}
/// A volume that provides write access to its voxel data.
pub trait WriteVol: BaseVol {
/// Set the voxel at the provided position in the volume to the provided value.
fn set(&mut self, pos: Vec3<i32>, vox: Self::Vox) -> Result<(), Self::Err>;
fn set(&mut self, pos: Vec3<i32>, vox: Self::Vox) -> Result<(), Self::Error>;
}
/// A volume that shall be iterable.

View File

@ -8,7 +8,7 @@ use std::marker::PhantomData;
use vek::*;
#[derive(Debug)]
pub enum ChunkErr {
pub enum ChunkError {
OutOfBounds,
}
@ -163,9 +163,9 @@ impl<V: Vox, S: VolSize, M> Chunk<V, S, M> {
}
}
fn get_from_morton(&self, morton: u32) -> Result<&V, ChunkErr> {
fn get_from_morton(&self, morton: u32) -> Result<&V, ChunkError> {
if morton as usize >= Self::BLOCK_COUNT {
Err(ChunkErr::OutOfBounds)
Err(ChunkError::OutOfBounds)
} else {
Ok(self.get_from_morton_unchecked(morton))
}
@ -176,9 +176,9 @@ impl<V: Vox, S: VolSize, M> Chunk<V, S, M> {
self.vox[idx] = vox;
}
fn set_from_morton(&mut self, morton: u32, vox: V) -> Result<(), ChunkErr> {
fn set_from_morton(&mut self, morton: u32, vox: V) -> Result<(), ChunkError> {
if morton as usize >= Self::BLOCK_COUNT {
Err(ChunkErr::OutOfBounds)
Err(ChunkError::OutOfBounds)
} else {
Ok(self.set_from_morton_unchecked(morton, vox))
}
@ -187,7 +187,7 @@ impl<V: Vox, S: VolSize, M> Chunk<V, S, M> {
impl<V: Vox, S: VolSize, M> BaseVol for Chunk<V, S, M> {
type Vox = V;
type Err = ChunkErr;
type Error = ChunkError;
}
impl<V: Vox, S: VolSize, M> SizedVol for Chunk<V, S, M> {
@ -204,14 +204,14 @@ impl<V: Vox, S: VolSize, M> SizedVol for Chunk<V, S, M> {
impl<V: Vox, S: VolSize, M> ReadVol for Chunk<V, S, M> {
#[inline(always)]
fn get(&self, pos: Vec3<i32>) -> Result<&Self::Vox, ChunkErr> {
fn get(&self, pos: Vec3<i32>) -> Result<&Self::Vox, ChunkError> {
self.get_from_morton(xyz_to_morton(pos))
}
}
impl<V: Vox, S: VolSize, M> WriteVol for Chunk<V, S, M> {
#[inline(always)]
fn set(&mut self, pos: Vec3<i32>, vox: Self::Vox) -> Result<(), ChunkErr> {
fn set(&mut self, pos: Vec3<i32>, vox: Self::Vox) -> Result<(), ChunkError> {
self.set_from_morton(xyz_to_morton(pos), vox)
}
}

View File

@ -3,7 +3,7 @@ use serde_derive::{Deserialize, Serialize};
use vek::*;
#[derive(Debug, Clone)]
pub enum DynaErr {
pub enum DynaError {
OutOfBounds,
}
@ -40,7 +40,7 @@ impl<V: Vox, M> Dyna<V, M> {
impl<V: Vox, M> BaseVol for Dyna<V, M> {
type Vox = V;
type Err = DynaErr;
type Error = DynaError;
}
impl<V: Vox, M> SizedVol for Dyna<V, M> {
@ -57,20 +57,20 @@ impl<V: Vox, M> SizedVol for Dyna<V, M> {
impl<V: Vox, M> ReadVol for Dyna<V, M> {
#[inline(always)]
fn get(&self, pos: Vec3<i32>) -> Result<&V, DynaErr> {
fn get(&self, pos: Vec3<i32>) -> Result<&V, DynaError> {
Self::idx_for(self.sz, pos)
.and_then(|idx| self.vox.get(idx))
.ok_or(DynaErr::OutOfBounds)
.ok_or(DynaError::OutOfBounds)
}
}
impl<V: Vox, M> WriteVol for Dyna<V, M> {
#[inline(always)]
fn set(&mut self, pos: Vec3<i32>, vox: Self::Vox) -> Result<(), DynaErr> {
fn set(&mut self, pos: Vec3<i32>, vox: Self::Vox) -> Result<(), DynaError> {
Self::idx_for(self.sz, pos)
.and_then(|idx| self.vox.get_mut(idx))
.map(|old_vox| *old_vox = vox)
.ok_or(DynaErr::OutOfBounds)
.ok_or(DynaError::OutOfBounds)
}
}

View File

@ -1,16 +1,16 @@
use crate::{
vol::{BaseVol, ReadVol, SampleVol, VolSize, WriteVol},
volumes::dyna::DynaErr,
volumes::dyna::DynaError,
};
use hashbrown::{hash_map, HashMap};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug, Clone)]
pub enum VolMap2dErr<V: BaseVol> {
pub enum VolMap2dError<V: BaseVol> {
NoSuchChunk,
ChunkErr(V::Err),
DynaErr(DynaErr),
ChunkError(V::Error),
DynaError(DynaError),
InvalidChunkSize,
}
@ -39,19 +39,19 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
impl<V: BaseVol + Debug, S: VolSize> BaseVol for VolMap2d<V, S> {
type Vox = V::Vox;
type Err = VolMap2dErr<V>;
type Error = VolMap2dError<V>;
}
impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolMap2d<V, S> {
#[inline(always)]
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolMap2dErr<V>> {
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolMap2dError<V>> {
let ck = Self::chunk_key(pos);
self.chunks
.get(&ck)
.ok_or(VolMap2dErr::NoSuchChunk)
.ok_or(VolMap2dError::NoSuchChunk)
.and_then(|chunk| {
let co = Self::chunk_offs(pos);
chunk.get(co).map_err(VolMap2dErr::ChunkErr)
chunk.get(co).map_err(VolMap2dError::ChunkError)
})
}
}
@ -64,7 +64,7 @@ impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I>
/// Take a sample of the terrain by cloning the voxels within the provided range.
///
/// Note that the resultant volume does not carry forward metadata from the original chunks.
fn sample(&self, range: I) -> Result<Self::Sample, VolMap2dErr<V>> {
fn sample(&self, range: I) -> Result<Self::Sample, VolMap2dError<V>> {
let range = range.into();
let mut sample = VolMap2d::new()?;
@ -88,22 +88,22 @@ impl<I: Into<Aabr<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I>
impl<V: BaseVol + WriteVol + Clone + Debug, S: VolSize + Clone> WriteVol for VolMap2d<V, S> {
#[inline(always)]
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolMap2dErr<V>> {
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolMap2dError<V>> {
let ck = Self::chunk_key(pos);
self.chunks
.get_mut(&ck)
.ok_or(VolMap2dErr::NoSuchChunk)
.ok_or(VolMap2dError::NoSuchChunk)
.and_then(|chunk| {
let co = Self::chunk_offs(pos);
Arc::make_mut(chunk)
.set(co, vox)
.map_err(VolMap2dErr::ChunkErr)
.map_err(VolMap2dError::ChunkError)
})
}
}
impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
pub fn new() -> Result<Self, VolMap2dErr<V>> {
pub fn new() -> Result<Self, VolMap2dError<V>> {
if Self::chunk_size()
.map(|e| e.is_power_of_two() && e > 0)
.reduce_and()
@ -113,7 +113,7 @@ impl<V: BaseVol, S: VolSize> VolMap2d<V, S> {
phantom: PhantomData,
})
} else {
Err(VolMap2dErr::InvalidChunkSize)
Err(VolMap2dError::InvalidChunkSize)
}
}

View File

@ -1,16 +1,16 @@
use crate::{
vol::{BaseVol, ReadVol, SampleVol, VolSize, WriteVol},
volumes::dyna::DynaErr,
volumes::dyna::DynaError,
};
use hashbrown::{hash_map, HashMap};
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
use vek::*;
#[derive(Debug)]
pub enum VolMap3dErr<V: BaseVol> {
pub enum VolMap3dError<V: BaseVol> {
NoSuchChunk,
ChunkErr(V::Err),
DynaErr(DynaErr),
ChunkErr(V::Error),
DynaError(DynaError),
InvalidChunkSize,
}
@ -44,19 +44,19 @@ impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
impl<V: BaseVol + Debug, S: VolSize> BaseVol for VolMap3d<V, S> {
type Vox = V::Vox;
type Err = VolMap3dErr<V>;
type Error = VolMap3dError<V>;
}
impl<V: BaseVol + ReadVol + Debug, S: VolSize> ReadVol for VolMap3d<V, S> {
#[inline(always)]
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolMap3dErr<V>> {
fn get(&self, pos: Vec3<i32>) -> Result<&V::Vox, VolMap3dError<V>> {
let ck = Self::chunk_key(pos);
self.chunks
.get(&ck)
.ok_or(VolMap3dErr::NoSuchChunk)
.ok_or(VolMap3dError::NoSuchChunk)
.and_then(|chunk| {
let co = Self::chunk_offs(pos);
chunk.get(co).map_err(VolMap3dErr::ChunkErr)
chunk.get(co).map_err(VolMap3dError::ChunkErr)
})
}
}
@ -69,7 +69,7 @@ impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I>
/// Take a sample of the terrain by cloning the voxels within the provided range.
///
/// Note that the resultant volume does not carry forward metadata from the original chunks.
fn sample(&self, range: I) -> Result<Self::Sample, VolMap3dErr<V>> {
fn sample(&self, range: I) -> Result<Self::Sample, VolMap3dError<V>> {
let range = range.into();
let mut sample = VolMap3d::new()?;
let chunk_min = Self::chunk_key(range.min);
@ -94,22 +94,22 @@ impl<I: Into<Aabb<i32>>, V: BaseVol + ReadVol + Debug, S: VolSize> SampleVol<I>
impl<V: BaseVol + WriteVol + Clone + Debug, S: VolSize + Clone> WriteVol for VolMap3d<V, S> {
#[inline(always)]
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolMap3dErr<V>> {
fn set(&mut self, pos: Vec3<i32>, vox: V::Vox) -> Result<(), VolMap3dError<V>> {
let ck = Self::chunk_key(pos);
self.chunks
.get_mut(&ck)
.ok_or(VolMap3dErr::NoSuchChunk)
.ok_or(VolMap3dError::NoSuchChunk)
.and_then(|chunk| {
let co = Self::chunk_offs(pos);
Arc::make_mut(chunk)
.set(co, vox)
.map_err(VolMap3dErr::ChunkErr)
.map_err(VolMap3dError::ChunkErr)
})
}
}
impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
pub fn new() -> Result<Self, VolMap3dErr<V>> {
pub fn new() -> Result<Self, VolMap3dError<V>> {
if Self::chunk_size()
.map(|e| e.is_power_of_two() && e > 0)
.reduce_and()
@ -119,7 +119,7 @@ impl<V: BaseVol, S: VolSize> VolMap3d<V, S> {
phantom: PhantomData,
})
} else {
Err(VolMap3dErr::InvalidChunkSize)
Err(VolMap3dError::InvalidChunkSize)
}
}

View File

@ -11,7 +11,7 @@ use common::{
figure::Segment,
terrain::{Block, BlockKind, TerrainChunkSize, TerrainMap},
vol::{ReadVol, SampleVol, VolSize, Vox},
volumes::vol_map_2d::VolMap2dErr,
volumes::vol_map_2d::VolMap2dError,
};
use crossbeam::channel;
use dot_vox::DotVoxData;
@ -467,7 +467,7 @@ impl Terrain {
Ok(sample) => sample,
// Either this chunk or its neighbours doesn't yet exist, so we keep it in the
// queue to be processed at a later date when we have its neighbours.
Err(VolMap2dErr::NoSuchChunk) => return,
Err(VolMap2dError::NoSuchChunk) => return,
_ => panic!("Unhandled edge case"),
};