Remove workaround

This commit is contained in:
Hanno Braun 2022-02-19 11:47:52 +01:00
parent 500604044d
commit 1677ca2549
3 changed files with 3 additions and 44 deletions

View File

@ -4,7 +4,7 @@ use nalgebra::{vector, Point};
use crate::{
debug::DebugInfo,
math::Triangle,
mesh::{HashVector, Index, MeshMaker},
mesh::{Index, MeshMaker},
};
#[derive(Debug)]
@ -57,12 +57,6 @@ impl From<&Vec<Triangle>> for Vertices {
let normal = (b - a).cross(&(c - a)).normalize();
let a = HashVector::from(&a.to_na());
let b = HashVector::from(&b.to_na());
let c = HashVector::from(&c.to_na());
let normal = HashVector::from(&normal.to_na());
mesh.push((a, normal));
mesh.push((b, normal));
mesh.push((c, normal));

View File

@ -28,7 +28,7 @@ use crate::{
debug::DebugInfo,
graphics::{DrawConfig, Renderer},
kernel::Shape as _,
mesh::{HashVector, MeshMaker},
mesh::MeshMaker,
model::Model,
window::Window,
};
@ -97,7 +97,7 @@ fn main() -> anyhow::Result<()> {
for triangle in triangles {
for vertex in triangle.vertices() {
mesh_maker.push(HashVector::from(&vertex.to_na()));
mesh_maker.push(vertex);
}
}

View File

@ -1,8 +1,5 @@
use std::{collections::HashMap, hash::Hash};
use decorum::R64;
use nalgebra::{Point, SVector};
/// API for creating a mesh
pub struct MeshMaker<V> {
vertices: Vec<V>,
@ -47,37 +44,5 @@ where
}
}
/// A point/vector type that can be used as a [`HashMap`] key
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct HashVector(pub [R64; 3]);
impl From<&Point<f64, 3>> for HashVector {
fn from(point: &Point<f64, 3>) -> Self {
Self([R64::from(point.x), R64::from(point.y), R64::from(point.z)])
}
}
impl From<&SVector<f64, 3>> for HashVector {
fn from(vector: &SVector<f64, 3>) -> Self {
Self([
R64::from(vector.x),
R64::from(vector.y),
R64::from(vector.z),
])
}
}
impl From<HashVector> for [f32; 3] {
fn from(hash_vector: HashVector) -> Self {
hash_vector.0.map(|coord| coord.into_inner() as f32)
}
}
impl From<HashVector> for [f64; 3] {
fn from(hash_vector: HashVector) -> Self {
hash_vector.0.map(|coord| coord.into_inner())
}
}
/// An index that refers to a vertex in a mesh
pub type Index = u32;