Skip to content

Commit

Permalink
Refer to Vertex via Handle
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Dec 13, 2024
1 parent 4780753 commit 23d73c5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions experiments/2024-12-09/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn export(shape: &Shape) -> anyhow::Result<()> {

for triangle in shape_triangles {
let triangle = triangle.vertices.map(|vertex| {
let vertex = vertex.get();
*indices_by_vertex.entry(vertex).or_insert_with(|| {
let index = vertices.len();
vertices.push(vertex);
Expand Down
18 changes: 9 additions & 9 deletions experiments/2024-12-09/src/geometry/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::fmt;

use crate::math::Point;

use super::{operation::HandleAny, Operation};
use super::{
operation::{Handle, HandleAny},
Operation,
};

#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Vertex {
Expand Down Expand Up @@ -41,13 +44,13 @@ impl Operation for Vertex {

#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Triangle {
pub vertices: [Vertex; 3],
pub vertices: [Handle<Vertex>; 3],
}

impl From<[&Vertex; 3]> for Triangle {
fn from(vertices: [&Vertex; 3]) -> Self {
impl From<[&Handle<Vertex>; 3]> for Triangle {
fn from(vertices: [&Handle<Vertex>; 3]) -> Self {
Self {
vertices: vertices.map(|vertex| *vertex),
vertices: vertices.map(|vertex| vertex.clone()),
}
}
}
Expand All @@ -66,9 +69,6 @@ impl Operation for Triangle {
}

fn children(&self) -> Vec<HandleAny> {
self.vertices
.iter()
.map(|vertex| HandleAny::new(*vertex))
.collect()
self.vertices.iter().map(|vertex| vertex.to_any()).collect()
}
}
3 changes: 0 additions & 3 deletions experiments/2024-12-09/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ pub fn model(shape: &mut Shape) {
.vertex([0.5, 0.5, 0.5])
.results();

let [a, b, c, d, e, f, g, h] =
[a, b, c, d, e, f, g, h].map(|vertex| vertex.get());

shape
.triangle([&a, &e, &g]) // left
.triangle([&a, &g, &c])
Expand Down
3 changes: 2 additions & 1 deletion experiments/2024-12-09/src/render/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ impl Geometry<triangles::Vertex> {
let mut vertices = Vec::new();

for triangle in &mesh_triangles {
let triangle = triangle.vertices.map(|vertex| {
let triangle = triangle.vertices.each_ref().map(|vertex| {
Vec3::from(
vertex
.as_ref()
.point
.coords
.components
Expand Down

0 comments on commit 23d73c5

Please sign in to comment.