Move Vertex to dedicated module

This commit is contained in:
Hanno Braun 2024-12-18 21:22:45 +01:00
parent cf30a152fd
commit 87e03ced94
9 changed files with 58 additions and 43 deletions

View File

@ -5,7 +5,7 @@ mod sketch;
pub use self::{
operation::{AnyOp, Handle, Operation},
primitives::{Triangle, Vertex},
primitives::Triangle,
shape::Shape,
sketch::Sketch,
};

View File

@ -1,6 +1,8 @@
use std::{fmt, ops::Deref, rc::Rc};
use super::{Triangle, Vertex};
use crate::topology::Vertex;
use super::Triangle;
pub trait Operation: fmt::Display {
fn vertices(&self, vertices: &mut Vec<Vertex>);

View File

@ -1,44 +1,9 @@
use std::fmt;
use crate::math::Point;
use crate::{math::Point, topology::Vertex};
use super::{operation::AnyOp, Operation};
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Vertex {
pub point: Point<3>,
}
impl<P> From<P> for Vertex
where
P: Into<Point<3>>,
{
fn from(point: P) -> Self {
Self {
point: point.into(),
}
}
}
impl fmt::Display for Vertex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let [x, y, z] = self.point.coords.components.map(|s| s.value());
write!(f, "vertex {x:.2}, {y:.2}, {z:.2}")
}
}
impl Operation for Vertex {
fn vertices(&self, vertices: &mut Vec<Vertex>) {
vertices.push(*self);
}
fn triangles(&self, _: &mut Vec<Triangle>) {}
fn children(&self) -> Vec<AnyOp> {
Vec::new()
}
}
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Triangle {
pub vertices: [Point<3>; 3],

View File

@ -2,11 +2,11 @@ use std::fmt;
use tuples::CombinRight;
use crate::storage::Store;
use crate::{storage::Store, topology::Vertex};
use super::{
operation::{AnyOp, Handle},
Operation, Triangle, Vertex,
Operation, Triangle,
};
#[derive(Default)]

View File

@ -7,6 +7,7 @@ mod math;
mod model;
mod render;
mod storage;
mod topology;
mod view;
fn main() -> anyhow::Result<()> {

View File

@ -1,7 +1,7 @@
use crate::{
geometry::{Shape, Sketch, Triangle, Vertex},
geometry::{Shape, Sketch, Triangle},
math::{Bivector, Plane, Point, Vector},
storage::Store,
storage::Store, topology::Vertex,
};
pub fn model(shape: &mut Shape) {

View File

@ -0,0 +1,3 @@
mod vertex;
pub use self::vertex::Vertex;

View File

@ -0,0 +1,41 @@
use std::fmt;
use crate::{
geometry::{AnyOp, Operation, Triangle},
math::Point,
};
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct Vertex {
pub point: Point<3>,
}
impl<P> From<P> for Vertex
where
P: Into<Point<3>>,
{
fn from(point: P) -> Self {
Self {
point: point.into(),
}
}
}
impl fmt::Display for Vertex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let [x, y, z] = self.point.coords.components.map(|s| s.value());
write!(f, "vertex {x:.2}, {y:.2}, {z:.2}")
}
}
impl Operation for Vertex {
fn vertices(&self, vertices: &mut Vec<Vertex>) {
vertices.push(*self);
}
fn triangles(&self, _: &mut Vec<Triangle>) {}
fn children(&self) -> Vec<AnyOp> {
Vec::new()
}
}

View File

@ -1,6 +1,9 @@
use std::{fmt, iter};
use crate::geometry::{AnyOp, Operation, Triangle, Vertex};
use crate::{
geometry::{AnyOp, Operation, Triangle},
topology::Vertex,
};
#[derive(Clone)]
pub struct OperationView {