diff options
| author | HampusM <hampus@hampusmat.com> | 2026-09-22 18:22:46 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-09-22 18:22:46 +0200 |
| commit | c73ab25c9dbe40284cfd38beaf31e2a20a9810de (patch) | |
| tree | 51c5817a0c252a172c03a47e36886e563a4e623d /engine/src/file_format/wavefront | |
| parent | 2ccda0cd5f81909fddc74d95f960f781a64bcae1 (diff) | |
refactor(engine): fix portion of clippy lints
Diffstat (limited to 'engine/src/file_format/wavefront')
| -rw-r--r-- | engine/src/file_format/wavefront/obj.rs | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/engine/src/file_format/wavefront/obj.rs b/engine/src/file_format/wavefront/obj.rs index dbcee33..d1a1bf3 100644 --- a/engine/src/file_format/wavefront/obj.rs +++ b/engine/src/file_format/wavefront/obj.rs @@ -43,7 +43,7 @@ pub fn parse(obj_content: &str) -> Result<Obj, Error> continue; } - let Some((keyword, _)) = line.split_once(" ") else { + let Some((keyword, _)) = line.split_once(' ') else { continue; }; @@ -119,19 +119,18 @@ impl Obj for face in &self.faces { for face_vertex in &face.vertices { - if let Some(index) = added_face_vertices.get(&face_vertex) { + if let Some(index) = added_face_vertices.get(face_vertex) { indices.push(*index); continue; } - let pos = self + let pos = *self .vertex_positions .get(face_vertex.position as usize - 1) .ok_or(Error::FaceVertexPositionNotFound { vertex_pos_index: face_vertex.position, - })? - .clone(); + })?; let texture_pos = face_vertex.texture.map_or_else( || { @@ -154,10 +153,11 @@ impl Obj }, )?; - let texture_pos = options - .y_flip_uvs - .then(|| Vec2 { x: texture_pos.x, y: -texture_pos.y }) - .unwrap_or(texture_pos); + let texture_pos = if options.y_flip_uvs { + Vec2 { x: texture_pos.x, y: -texture_pos.y } + } else { + texture_pos + }; let normal = face_vertex.normal.map_or_else( || { @@ -243,14 +243,12 @@ impl Obj fn with_capacities_from_item_cnts(item_counts: ItemCounts) -> Self { Self { - vertex_positions: Vec::with_capacity(item_counts.pos_cnt), - vertex_normals: Vec::with_capacity(item_counts.normal_cnt), - texture_positions: Vec::with_capacity(item_counts.uv_cnt), - faces: Vec::with_capacity(item_counts.face_cnt), - mtl_libs: Vec::with_capacity(item_counts.mtl_lib_cnt), - unique_used_material_names: Vec::with_capacity( - item_counts.material_usage_cnt, - ), + vertex_positions: Vec::with_capacity(item_counts.pos), + vertex_normals: Vec::with_capacity(item_counts.normal), + texture_positions: Vec::with_capacity(item_counts.uv), + faces: Vec::with_capacity(item_counts.face), + mtl_libs: Vec::with_capacity(item_counts.mtl_lib), + unique_used_material_names: Vec::with_capacity(item_counts.material_usage), } } @@ -286,7 +284,7 @@ impl Obj return Err(Error::UnsupportedArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -294,7 +292,7 @@ impl Obj return Err(Error::InvalidArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -319,7 +317,7 @@ impl Obj return Err(Error::UnsupportedArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -327,7 +325,7 @@ impl Obj return Err(Error::InvalidArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -351,7 +349,7 @@ impl Obj return Err(Error::InvalidArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -377,7 +375,7 @@ impl Obj return Err(Error::InvalidArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -408,7 +406,7 @@ impl Obj return Err(Error::UnsupportedArgumentCount { keyword: statement.keyword.to_string(), arg_count: statement.arguments.len(), - line_no: line_no, + line_no, }); } @@ -459,6 +457,7 @@ impl ToMeshOptions /// their origin at the bottom left corner of the image /// /// The default is `true`. + #[must_use] pub fn y_flip_uvs(mut self, y_flip_uvs: bool) -> Self { self.y_flip_uvs = y_flip_uvs; @@ -578,12 +577,12 @@ struct ParsingState #[derive(Debug, Default)] struct ItemCounts { - pos_cnt: usize, - uv_cnt: usize, - normal_cnt: usize, - face_cnt: usize, - mtl_lib_cnt: usize, - material_usage_cnt: usize, + pos: usize, + uv: usize, + normal: usize, + face: usize, + mtl_lib: usize, + material_usage: usize, } impl ItemCounts @@ -591,12 +590,12 @@ impl ItemCounts fn increment_item_cnt_by_keyword(&mut self, keyword: Keyword) { match keyword { - Keyword::V => self.pos_cnt += 1, - Keyword::Vn => self.normal_cnt += 1, - Keyword::Vt => self.uv_cnt += 1, - Keyword::F => self.face_cnt += 1, - Keyword::Mtllib => self.mtl_lib_cnt += 1, - Keyword::Usemtl => self.material_usage_cnt += 1, + Keyword::V => self.pos += 1, + Keyword::Vn => self.normal += 1, + Keyword::Vt => self.uv += 1, + Keyword::F => self.face += 1, + Keyword::Mtllib => self.mtl_lib += 1, + Keyword::Usemtl => self.material_usage += 1, Keyword::O | Keyword::S => {} } } |
