Refer to Vertex via Handle

This commit is contained in:
Hanno Braun 2024-12-13 19:48:14 +01:00
parent 4780753fb6
commit 23d73c5410
4 changed files with 12 additions and 13 deletions

View File

@ -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);

View File

@ -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 {
@ -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()),
}
}
}
@ -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()
}
}

View File

@ -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])

View File

@ -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