forked from StrafesNET/strafe-client
UndirectedEdge trait
This commit is contained in:
parent
f4db20c206
commit
c9f2ea0308
@ -5,13 +5,18 @@ use std::borrow::{Borrow,Cow};
|
|||||||
pub struct VertId(usize);
|
pub struct VertId(usize);
|
||||||
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
||||||
pub struct EdgeId(usize);
|
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{
|
fn as_directed(&self,parity:bool)->DirectedEdgeId{
|
||||||
DirectedEdgeId(self.0|((parity as usize)<<(usize::BITS-1)))
|
DirectedEdgeId(self.0|((parity as usize)<<(usize::BITS-1)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub trait DirectedEdge{
|
pub trait DirectedEdge{
|
||||||
type UndirectedEdge:Copy;
|
type UndirectedEdge:Copy+UndirectedEdge;
|
||||||
fn as_undirected(&self)->Self::UndirectedEdge;
|
fn as_undirected(&self)->Self::UndirectedEdge;
|
||||||
fn parity(&self)->bool;
|
fn parity(&self)->bool;
|
||||||
}
|
}
|
||||||
@ -302,6 +307,15 @@ pub enum MinkowskiEdge{
|
|||||||
EdgeVert(EdgeId,VertId),
|
EdgeVert(EdgeId,VertId),
|
||||||
//EdgeEdge when edges are parallel
|
//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)]
|
#[derive(Clone,Copy)]
|
||||||
pub enum MinkowskiDirectedEdge{
|
pub enum MinkowskiDirectedEdge{
|
||||||
VertEdge(VertId,DirectedEdgeId),
|
VertEdge(VertId,DirectedEdgeId),
|
||||||
|
Loading…
Reference in New Issue
Block a user