Skip to content

Commit

Permalink
Remove 'Error' from names of error enum variants.
Browse files Browse the repository at this point in the history
  • Loading branch information
tormeh committed Sep 26, 2023
1 parent 874647f commit 7ba3561
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,14 @@ impl Camera {
let projection_matrix = self
.computed
.projection_matrix
.ok_or(BadProjectionMatrixError::ProjectionMatrixUndefinedError)?;
.ok_or(BadProjectionMatrixError::ProjectionMatrixUndefined)?;
match projection_matrix.is_finite() {
false => Err(BadProjectionMatrixError::BadProjectionMatrixValuesError(
false => Err(BadProjectionMatrixError::BadProjectionMatrixValues(
projection_matrix,
)),
true => {
if projection_matrix == Mat4::ZERO {
Err(BadProjectionMatrixError::BadProjectionMatrixValuesError(
Err(BadProjectionMatrixError::BadProjectionMatrixValues(
projection_matrix,
))
} else {
Expand Down Expand Up @@ -280,13 +280,13 @@ impl Camera {
) -> Result<Vec2, WorldToViewportError> {
let target_size = self
.logical_viewport_size()
.map_err(WorldToViewportError::LogicalViewportSizeError)?;
.map_err(WorldToViewportError::LogicalViewportSize)?;
let ndc_space_coords = self
.world_to_ndc(camera_transform, world_position)
.map_err(WorldToViewportError::WorldToNdcError)?;
.map_err(WorldToViewportError::WorldToNdc)?;
// NDC z-values outside of 0 < z < 1 are outside the (implicit) camera frustum and are thus not in viewport-space
if ndc_space_coords.z < 0.0 || ndc_space_coords.z > 1.0 {
return Err(WorldToViewportError::NdcCoordsOutsideFrustumError(
return Err(WorldToViewportError::NdcCoordsOutsideFrustum(
ndc_space_coords,
));
}
Expand Down Expand Up @@ -315,30 +315,30 @@ impl Camera {
) -> Result<Ray, ViewportToWorldError> {
let target_size = self
.logical_viewport_size()
.map_err(ViewportToWorldError::LogicalViewportSizeError)?;
.map_err(ViewportToWorldError::LogicalViewportSize)?;
// Flip the Y co-ordinate origin from the top to the bottom.
viewport_position.y = target_size.y - viewport_position.y;
let ndc = viewport_position * 2. / target_size - Vec2::ONE;

let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform)
.map_err(ViewportToWorldError::CameraTransformNotFiniteError)?;
.map_err(ViewportToWorldError::CameraTransformNotFinite)?;
let projection_matrix = self
.checked_projection_matrix()
.map_err(ViewportToWorldError::ProjectionMatrixNotFiniteError)?;
.map_err(ViewportToWorldError::ProjectionMatrixNotFinite)?;

let ndc_to_world = camera_transform_matrix * projection_matrix.inverse();
let world_near_plane = ndc_to_world.project_point3(ndc.extend(1.));
// Using EPSILON because an ndc with Z = 0 returns NaNs.
let world_far_plane = ndc_to_world.project_point3(ndc.extend(f32::EPSILON));

if !world_near_plane.is_finite() {
return Err(ViewportToWorldError::WorldNearPlaneNotFiniteError(
return Err(ViewportToWorldError::WorldNearPlaneNotFinite(
world_near_plane,
));
}

if world_far_plane.is_nan() {
return Err(ViewportToWorldError::WorldFarPlaneNanError(world_far_plane));
return Err(ViewportToWorldError::WorldFarPlaneNan(world_far_plane));
}

Ok(Ray {
Expand All @@ -362,14 +362,14 @@ impl Camera {
) -> Result<Vec2, ViewportToWorld2DError> {
let target_size = self
.logical_viewport_size()
.map_err(ViewportToWorld2DError::LogicalViewportSizeError)?;
.map_err(ViewportToWorld2DError::LogicalViewportSize)?;
// Flip the Y co-ordinate origin from the top to the bottom.
viewport_position.y = target_size.y - viewport_position.y;
let ndc = viewport_position * 2. / target_size - Vec2::ONE;

let world_near_plane = self
.ndc_to_world(camera_transform, ndc.extend(1.))
.map_err(ViewportToWorld2DError::NdcToWorldError)?;
.map_err(ViewportToWorld2DError::NdcToWorld)?;

Ok(world_near_plane.truncate())
}
Expand All @@ -388,20 +388,18 @@ impl Camera {
world_position: Vec3,
) -> Result<Vec3, WorldToNdcError> {
let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform)
.map_err(WorldToNdcError::CameraTransformNotFiniteError)?;
.map_err(WorldToNdcError::CameraTransformNotFinite)?;

let projection_matrix = self
.checked_projection_matrix()
.map_err(WorldToNdcError::ProjectionMatrixNotFiniteError)?;
.map_err(WorldToNdcError::ProjectionMatrixNotFinite)?;

// Build a transformation matrix to convert from world space to NDC using camera data
let world_to_ndc: Mat4 = projection_matrix * camera_transform_matrix.inverse();
let ndc_space_coords: Vec3 = world_to_ndc.project_point3(world_position);

if !ndc_space_coords.is_finite() {
return Err(WorldToNdcError::NdcSpaceCoordsNotFiniteError(
ndc_space_coords,
));
return Err(WorldToNdcError::NdcSpaceCoordsNotFinite(ndc_space_coords));
}

Ok(ndc_space_coords)
Expand All @@ -422,18 +420,18 @@ impl Camera {
ndc: Vec3,
) -> Result<Vec3, NdcToWorldError> {
let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform)
.map_err(NdcToWorldError::CameraTransformNotFiniteError)?;
.map_err(NdcToWorldError::CameraTransformNotFinite)?;

let projection_matrix = self
.checked_projection_matrix()
.map_err(NdcToWorldError::ProjectionMatrixNotFiniteError)?;
.map_err(NdcToWorldError::ProjectionMatrixNotFinite)?;

// Build a transformation matrix to convert from NDC to world space using camera data
let ndc_to_world = camera_transform_matrix * projection_matrix.inverse();

let world_space_coords = ndc_to_world.project_point3(ndc);
if !world_space_coords.is_finite() {
return Err(NdcToWorldError::WorldSpaceCoordsNotFiniteError(
return Err(NdcToWorldError::WorldSpaceCoordsNotFinite(
world_space_coords,
));
}
Expand All @@ -444,16 +442,16 @@ impl Camera {

#[derive(Debug)]
pub enum NdcToWorldError {
WorldSpaceCoordsNotFiniteError(Vec3),
CameraTransformNotFiniteError(CameraTransformNotFiniteError),
ProjectionMatrixNotFiniteError(BadProjectionMatrixError),
WorldSpaceCoordsNotFinite(Vec3),
CameraTransformNotFinite(CameraTransformNotFiniteError),
ProjectionMatrixNotFinite(BadProjectionMatrixError),
}

#[derive(Debug)]
pub enum WorldToNdcError {
NdcSpaceCoordsNotFiniteError(Vec3),
CameraTransformNotFiniteError(CameraTransformNotFiniteError),
ProjectionMatrixNotFiniteError(BadProjectionMatrixError),
NdcSpaceCoordsNotFinite(Vec3),
CameraTransformNotFinite(CameraTransformNotFiniteError),
ProjectionMatrixNotFinite(BadProjectionMatrixError),
}

#[derive(Debug)]
Expand All @@ -464,30 +462,30 @@ pub struct LogicalViewportSizeError {

#[derive(Debug)]
pub enum ViewportToWorldError {
LogicalViewportSizeError(LogicalViewportSizeError),
CameraTransformNotFiniteError(CameraTransformNotFiniteError),
ProjectionMatrixNotFiniteError(BadProjectionMatrixError),
WorldNearPlaneNotFiniteError(Vec3),
WorldFarPlaneNanError(Vec3),
LogicalViewportSize(LogicalViewportSizeError),
CameraTransformNotFinite(CameraTransformNotFiniteError),
ProjectionMatrixNotFinite(BadProjectionMatrixError),
WorldNearPlaneNotFinite(Vec3),
WorldFarPlaneNan(Vec3),
}

#[derive(Debug)]
pub enum ViewportToWorld2DError {
NdcToWorldError(NdcToWorldError),
LogicalViewportSizeError(LogicalViewportSizeError),
NdcToWorld(NdcToWorldError),
LogicalViewportSize(LogicalViewportSizeError),
}

#[derive(Debug)]
pub enum WorldToViewportError {
WorldToNdcError(WorldToNdcError),
LogicalViewportSizeError(LogicalViewportSizeError),
NdcCoordsOutsideFrustumError(Vec3),
WorldToNdc(WorldToNdcError),
LogicalViewportSize(LogicalViewportSizeError),
NdcCoordsOutsideFrustum(Vec3),
}

#[derive(Debug)]
pub enum BadProjectionMatrixError {
BadProjectionMatrixValuesError(Mat4),
ProjectionMatrixUndefinedError,
BadProjectionMatrixValues(Mat4),
ProjectionMatrixUndefined,
}

#[derive(Debug)]
Expand Down

0 comments on commit 7ba3561

Please sign in to comment.