From cca40bcb8e490e2ce5689c566bf93062b5231096 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 27 Mar 2020 12:08:17 +0100 Subject: [PATCH] library: render: mesh: from_slice to build Vector --- pathtracer/src/render/mesh.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/pathtracer/src/render/mesh.rs b/pathtracer/src/render/mesh.rs index 6c41ae3..e1ca64c 100644 --- a/pathtracer/src/render/mesh.rs +++ b/pathtracer/src/render/mesh.rs @@ -1,7 +1,7 @@ use std::convert::TryFrom; use std::path::PathBuf; -use nalgebra::{Similarity3, Unit}; +use nalgebra::{Similarity3, Unit, VectorSlice3}; use serde::Deserialize; @@ -69,27 +69,18 @@ impl TryFrom for Mesh { // We apply the (arguably useless) scaling to the vectors in case it is // negative, which would invert their direction let norm_a = { - let vec = Vector::new( - mesh.normals[a * 3], - mesh.normals[a * 3 + 1], - mesh.normals[a * 3 + 2], - ); + let vec: Vector = + VectorSlice3::from_slice(&mesh.normals[(a * 3)..(a * 3 + 3)]).into(); Unit::new_normalize(transform * vec) }; let norm_b = { - let vec = Vector::new( - mesh.normals[b * 3], - mesh.normals[b * 3 + 1], - mesh.normals[b * 3 + 2], - ); + let vec: Vector = + VectorSlice3::from_slice(&mesh.normals[(b * 3)..(b * 3 + 3)]).into(); Unit::new_normalize(transform * vec) }; let norm_c = { - let vec = Vector::new( - mesh.normals[c * 3], - mesh.normals[c * 3 + 1], - mesh.normals[c * 3 + 2], - ); + let vec: Vector = + VectorSlice3::from_slice(&mesh.normals[(c * 3)..(c * 3 + 3)]).into(); Unit::new_normalize(transform * vec) };