Skip to content

Commit

Permalink
Fix some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
17cupsofcoffee committed Dec 10, 2024
1 parent 84788c9 commit a50d77c
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 101 deletions.
12 changes: 6 additions & 6 deletions src/graphics/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl CanvasBuilder {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn build(&self, ctx: &mut Context) -> Result<Canvas> {
let attachments = ctx.device.new_canvas(
self.width,
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Canvas {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn new(ctx: &mut Context, width: i32, height: i32) -> Result<Canvas> {
CanvasBuilder::new(width, height).build(ctx)
}
Expand Down Expand Up @@ -213,8 +213,8 @@ impl Canvas {
/// # Errors
///
/// * [`TetraError::NotEnoughData`](crate::TetraError::NotEnoughData) will be returned
/// if not enough data is provided to fill the target rectangle. This is to prevent
/// the graphics API from trying to read uninitialized memory.
/// if not enough data is provided to fill the target rectangle. This is to prevent
/// the graphics API from trying to read uninitialized memory.
///
/// # Panics
///
Expand Down Expand Up @@ -246,8 +246,8 @@ impl Canvas {
/// # Errors
///
/// * [`TetraError::NotEnoughData`](crate::TetraError::NotEnoughData) will be returned
/// if not enough data is provided to fill the target rectangle. This is to prevent
/// the graphics API from trying to read uninitialized memory.
/// if not enough data is provided to fill the target rectangle. This is to prevent
/// the graphics API from trying to read uninitialized memory.
pub fn replace_data(&self, ctx: &mut Context, data: &[u8]) -> Result {
self.texture.replace_data(ctx, data)
}
Expand Down
15 changes: 6 additions & 9 deletions src/graphics/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use crate::math::Vec4;
/// can be enabled via the `serde` feature.
#[repr(C)]
#[derive(Debug, Default, Copy, Clone, PartialEq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Color {
/// The red component of the color.
pub r: f32,
Expand Down Expand Up @@ -188,7 +185,7 @@ impl Color {
}

fn clamp_f32(val: f32) -> f32 {
f32::min(f32::max(0.0, val), 1.0)
val.clamp(0.0, 1.0)
}

impl From<Color> for Vec4<f32> {
Expand Down Expand Up @@ -544,9 +541,9 @@ mod tests {
}

fn same_color(a: Color, b: Color) -> bool {
(a.r - b.r).abs() < std::f32::EPSILON
&& (a.g - b.g).abs() < std::f32::EPSILON
&& (a.b - b.b).abs() < std::f32::EPSILON
&& (a.a - b.a).abs() < std::f32::EPSILON
(a.r - b.r).abs() < f32::EPSILON
&& (a.g - b.g).abs() < f32::EPSILON
&& (a.b - b.b).abs() < f32::EPSILON
&& (a.a - b.a).abs() < f32::EPSILON
}
}
2 changes: 1 addition & 1 deletion src/graphics/image_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ImageData {
/// # Errors
///
/// * [`TetraError::NotEnoughData`] will be returned if not enough data is provided to fill
/// the image.
/// the image.
pub fn from_data<D>(
width: i32,
height: i32,
Expand Down
48 changes: 24 additions & 24 deletions src/graphics/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl VertexBuffer {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn new(ctx: &mut Context, vertices: &[Vertex]) -> Result<VertexBuffer> {
VertexBuffer::with_usage(ctx, vertices, BufferUsage::Dynamic)
}
Expand All @@ -140,7 +140,7 @@ impl VertexBuffer {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn with_usage(
ctx: &mut Context,
vertices: &[Vertex],
Expand Down Expand Up @@ -210,7 +210,7 @@ impl IndexBuffer {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn new(ctx: &mut Context, indices: &[u32]) -> Result<IndexBuffer> {
IndexBuffer::with_usage(ctx, indices, BufferUsage::Dynamic)
}
Expand All @@ -222,7 +222,7 @@ impl IndexBuffer {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn with_usage(
ctx: &mut Context,
indices: &[u32],
Expand Down Expand Up @@ -512,9 +512,9 @@ impl Mesh {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn rectangle(ctx: &mut Context, style: ShapeStyle, rectangle: Rectangle) -> Result<Mesh> {
GeometryBuilder::new()
.rectangle(style, rectangle)?
Expand All @@ -529,9 +529,9 @@ impl Mesh {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn rounded_rectangle(
ctx: &mut Context,
style: ShapeStyle,
Expand All @@ -551,9 +551,9 @@ impl Mesh {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn circle(
ctx: &mut Context,
style: ShapeStyle,
Expand All @@ -573,9 +573,9 @@ impl Mesh {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn ellipse(
ctx: &mut Context,
style: ShapeStyle,
Expand All @@ -595,9 +595,9 @@ impl Mesh {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn polygon(ctx: &mut Context, style: ShapeStyle, points: &[Vec2<f32>]) -> Result<Mesh> {
GeometryBuilder::new()
.polygon(style, points)?
Expand All @@ -612,9 +612,9 @@ impl Mesh {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn polyline(ctx: &mut Context, stroke_width: f32, points: &[Vec2<f32>]) -> Result<Mesh> {
GeometryBuilder::new()
.polyline(stroke_width, points)?
Expand Down Expand Up @@ -690,7 +690,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
pub fn rectangle(
&mut self,
style: ShapeStyle,
Expand Down Expand Up @@ -724,7 +724,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
pub fn rounded_rectangle(
&mut self,
style: ShapeStyle,
Expand Down Expand Up @@ -759,7 +759,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
pub fn circle(
&mut self,
style: ShapeStyle,
Expand Down Expand Up @@ -806,7 +806,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
pub fn ellipse(
&mut self,
style: ShapeStyle,
Expand Down Expand Up @@ -857,7 +857,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
pub fn polygon(
&mut self,
style: ShapeStyle,
Expand Down Expand Up @@ -903,7 +903,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::TessellationError`](crate::TetraError::TessellationError) will be returned if the shape
/// could not be turned into vertex data.
/// could not be turned into vertex data.
pub fn polyline(
&mut self,
stroke_width: f32,
Expand Down Expand Up @@ -971,7 +971,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn build_buffers(&self, ctx: &mut Context) -> Result<(VertexBuffer, IndexBuffer)> {
Ok((
VertexBuffer::new(ctx, &self.data.vertices)?,
Expand All @@ -986,7 +986,7 @@ impl GeometryBuilder {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the underlying
/// graphics API encounters an error.
/// graphics API encounters an error.
pub fn build_mesh(&self, ctx: &mut Context) -> Result<Mesh> {
let (vertex_buffer, index_buffer) = self.build_buffers(ctx)?;

Expand Down
30 changes: 15 additions & 15 deletions src/graphics/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ impl Shader {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the
/// underlying graphics API encounters an error.
/// underlying graphics API encounters an error.
/// * [`TetraError::FailedToLoadAsset`](crate::TetraError::FailedToLoadAsset) will be returned
/// if the files could not be loaded.
/// if the files could not be loaded.
/// * [`TetraError::InvalidShader`](crate::TetraError::InvalidShader) will be returned if the
/// shader could not be compiled.
/// shader could not be compiled.
pub fn new<P>(ctx: &mut Context, vertex_path: P, fragment_path: P) -> Result<Shader>
where
P: AsRef<Path>,
Expand All @@ -130,11 +130,11 @@ impl Shader {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the
/// underlying graphics API encounters an error.
/// underlying graphics API encounters an error.
/// * [`TetraError::FailedToLoadAsset`](crate::TetraError::FailedToLoadAsset) will be returned
/// if the file could not be loaded.
/// if the file could not be loaded.
/// * [`TetraError::InvalidShader`](crate::TetraError::InvalidShader) will be returned if the
/// shader could not be compiled.
/// shader could not be compiled.
pub fn from_vertex_file<P>(ctx: &mut Context, path: P) -> Result<Shader>
where
P: AsRef<Path>,
Expand All @@ -153,11 +153,11 @@ impl Shader {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the
/// underlying graphics API encounters an error.
/// underlying graphics API encounters an error.
/// * [`TetraError::FailedToLoadAsset`](crate::TetraError::FailedToLoadAsset) will be returned
/// if the file could not be loaded.
/// if the file could not be loaded.
/// * [`TetraError::InvalidShader`](crate::TetraError::InvalidShader) will be returned if the
/// shader could not be compiled.
/// shader could not be compiled.
pub fn from_fragment_file<P>(ctx: &mut Context, path: P) -> Result<Shader>
where
P: AsRef<Path>,
Expand All @@ -174,9 +174,9 @@ impl Shader {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the
/// underlying graphics API encounters an error.
/// underlying graphics API encounters an error.
/// * [`TetraError::InvalidShader`](crate::TetraError::InvalidShader) will be returned if the
/// shader could not be compiled.
/// shader could not be compiled.
pub fn from_string(
ctx: &mut Context,
vertex_shader: &str,
Expand All @@ -192,9 +192,9 @@ impl Shader {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the
/// underlying graphics API encounters an error.
/// underlying graphics API encounters an error.
/// * [`TetraError::InvalidShader`](crate::TetraError::InvalidShader) will be returned if the
/// shader could not be compiled.
/// shader could not be compiled.
pub fn from_vertex_string(ctx: &mut Context, shader: &str) -> Result<Shader> {
Shader::with_device(&mut ctx.device, shader, DEFAULT_FRAGMENT_SHADER)
}
Expand All @@ -206,9 +206,9 @@ impl Shader {
/// # Errors
///
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the
/// underlying graphics API encounters an error.
/// underlying graphics API encounters an error.
/// * [`TetraError::InvalidShader`](crate::TetraError::InvalidShader) will be returned if the
/// shader could not be compiled.
/// shader could not be compiled.
pub fn from_fragment_string(ctx: &mut Context, shader: &str) -> Result<Shader> {
Shader::with_device(&mut ctx.device, DEFAULT_VERTEX_SHADER, shader)
}
Expand Down
14 changes: 7 additions & 7 deletions src/graphics/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ impl Font {
/// # Errors
///
/// * [`TetraError::FailedToLoadAsset`](crate::TetraError::FailedToLoadAsset) will be returned
/// if the file could not be loaded.
/// if the file could not be loaded.
/// * [`TetraError::InvalidFont`](crate::TetraError::InvalidFont) will be returned if the font
/// data was invalid.
/// data was invalid.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the GPU cache for the font
/// could not be created.
#[cfg(feature = "font_ttf")]
Expand All @@ -98,9 +98,9 @@ impl Font {
/// # Errors
///
/// * [`TetraError::InvalidFont`](crate::TetraError::InvalidFont) will be returned if the font
/// data was invalid.
/// data was invalid.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the GPU cache for the font
/// could not be created.
/// could not be created.
#[cfg(feature = "font_ttf")]
pub fn from_vector_file_data(
ctx: &mut Context,
Expand Down Expand Up @@ -137,11 +137,11 @@ impl Font {
/// # Errors
///
/// * [`TetraError::FailedToLoadAsset`](crate::TetraError::FailedToLoadAsset) will be returned
/// if the font or the associated images could not be loaded.
/// if the font or the associated images could not be loaded.
/// * [`TetraError::InvalidFont`](crate::TetraError::InvalidFont) will be returned if the font
/// data was invalid.
/// data was invalid.
/// * [`TetraError::PlatformError`](crate::TetraError::PlatformError) will be returned if the GPU cache for the font
/// could not be created.
/// could not be created.
pub fn bmfont<P>(ctx: &mut Context, path: P) -> Result<Font>
where
P: AsRef<Path>,
Expand Down
Loading

0 comments on commit a50d77c

Please sign in to comment.