From c9f2ea0308847096d4f5131ba1c39f86d6d1ce4a Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 20 Nov 2023 19:14:19 -0800 Subject: [PATCH] UndirectedEdge trait --- src/model_physics.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/model_physics.rs b/src/model_physics.rs index f11f634..1a36f8a 100644 --- a/src/model_physics.rs +++ b/src/model_physics.rs @@ -5,13 +5,18 @@ use std::borrow::{Borrow,Cow}; pub struct VertId(usize); #[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)] pub struct EdgeId(usize); -impl EdgeId{ +pub trait UndirectedEdge{ + type DirectedEdge:Copy+DirectedEdge; + fn as_directed(&self,parity:bool)->Self::DirectedEdge; +} +impl UndirectedEdge for EdgeId{ + type DirectedEdge=DirectedEdgeId; fn as_directed(&self,parity:bool)->DirectedEdgeId{ DirectedEdgeId(self.0|((parity as usize)<<(usize::BITS-1))) } } pub trait DirectedEdge{ - type UndirectedEdge:Copy; + type UndirectedEdge:Copy+UndirectedEdge; fn as_undirected(&self)->Self::UndirectedEdge; fn parity(&self)->bool; } @@ -302,6 +307,15 @@ pub enum MinkowskiEdge{ EdgeVert(EdgeId,VertId), //EdgeEdge when edges are parallel } +impl UndirectedEdge for MinkowskiEdge{ + type DirectedEdge=MinkowskiDirectedEdge; + fn as_directed(&self,parity:bool)->Self::DirectedEdge{ + match self{ + MinkowskiEdge::VertEdge(v0,e1)=>MinkowskiDirectedEdge::VertEdge(*v0,e1.as_directed(parity)), + MinkowskiEdge::EdgeVert(e0,v1)=>MinkowskiDirectedEdge::EdgeVert(e0.as_directed(parity),*v1), + } + } +} #[derive(Clone,Copy)] pub enum MinkowskiDirectedEdge{ VertEdge(VertId,DirectedEdgeId),