Skip to content

Commit

Permalink
Remove workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Feb 19, 2022
1 parent 5006040 commit 1677ca2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 44 deletions.
8 changes: 1 addition & 7 deletions src/graphics/vertices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use nalgebra::{vector, Point};
use crate::{
debug::DebugInfo,
math::Triangle,
mesh::{HashVector, Index, MeshMaker},
mesh::{Index, MeshMaker},
};

#[derive(Debug)]
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
debug::DebugInfo,
graphics::{DrawConfig, Renderer},
kernel::Shape as _,
mesh::{HashVector, MeshMaker},
mesh::MeshMaker,
model::Model,
window::Window,
};
Expand Down Expand Up @@ -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);
}
}

Expand Down
35 changes: 0 additions & 35 deletions src/mesh.rs
Original file line number Diff line number Diff line change
@@ -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>,
Expand Down Expand Up @@ -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;

0 comments on commit 1677ca2

Please sign in to comment.