Struct truck_topology::Edge[][src]

pub struct Edge<P, C> { /* fields omitted */ }

Edge, which consists two vertices.

The constructors Edge::new(), Edge::try_new(), and Edge::new_unchecked() create a different edge each time, even if the end vertices are the same one. An edge is uniquely identified by their id.

let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], ());
let edge1 = Edge::new(&v[0], &v[1], ());
assert_ne!(edge0.id(), edge1.id());

Implementations

impl<P, C> Edge<P, C>[src]

pub fn try_new(
    front: &Vertex<P>,
    back: &Vertex<P>,
    curve: C
) -> Result<Edge<P, C>>
[src]

Generates the edge from front to back.

Failures

If front == back, then returns Error::SameVertex.

let v = Vertex::news(&[(), ()]);
assert!(Edge::try_new(&v[0], &v[1], ()).is_ok());
assert_eq!(Edge::try_new(&v[0], &v[0], ()), Err(Error::SameVertex));

pub fn new(front: &Vertex<P>, back: &Vertex<P>, curve: C) -> Edge<P, C>[src]

Generates the edge from front to back.

Panic

The condition front == back is not allowed.

use truck_topology::*;
let v = Vertex::new(());
Edge::new(&v, &v, ()); // panic occurs

pub fn new_unchecked(
    front: &Vertex<P>,
    back: &Vertex<P>,
    curve: C
) -> Edge<P, C>
[src]

Generates the edge from front to back.

Remarks

This method is prepared only for performance-critical development and is not recommended.
This method does NOT check the condition front == back.
The programmer must guarantee this condition before using this method.

pub fn debug_new(front: &Vertex<P>, back: &Vertex<P>, curve: C) -> Edge<P, C>[src]

Generates the edge from front to back.

Remarks

This method check the condition front == back in the debug mode.
The programmer must guarantee this condition before using this method.

pub fn orientation(&self) -> bool[src]

Returns the orientation of the curve.

Examples

use truck_topology::*;
let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], ());
let edge1 = edge0.inverse();
assert!(edge0.orientation());
assert!(!edge1.orientation());

pub fn invert(&mut self) -> &mut Self[src]

Inverts the direction of edge.

use truck_topology::*;
let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ());
let mut inv_edge = edge.clone();
inv_edge.invert();

// Two edges are the same edge.
edge.is_same(&inv_edge);

// the front and back are exchanged.
assert_eq!(edge.front(), inv_edge.back());
assert_eq!(edge.back(), inv_edge.front());

pub fn inverse(&self) -> Edge<P, C>[src]

Creates the inverse oriented edge.

let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ());
let inv_edge = edge.inverse();

// Two edges are the same edge.
assert!(edge.is_same(&inv_edge));

// Two edges has the same id.
assert_eq!(edge.id(), inv_edge.id());

// the front and back are exchanged.
assert_eq!(edge.front(), inv_edge.back());
assert_eq!(edge.back(), inv_edge.front());

pub fn front(&self) -> &Vertex<P>[src]

Returns the front vertex

let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ());
assert_eq!(edge.front(), &v[0]);

pub fn back(&self) -> &Vertex<P>[src]

Returns the back vertex

let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ());
assert_eq!(edge.back(), &v[1]);

pub fn ends(&self) -> (&Vertex<P>, &Vertex<P>)[src]

Returns the vertices at both ends.

let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ());
assert_eq!(edge.ends(), (&v[0], &v[1]));

pub fn absolute_front(&self) -> &Vertex<P>[src]

Returns the front vertex which is generated by constructor

let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ()).inverse();
assert_eq!(edge.front(), &v[1]);
assert_eq!(edge.absolute_front(), &v[0]);

pub fn absolute_back(&self) -> &Vertex<P>[src]

Returns the back vertex which is generated by constructor

let v = Vertex::news(&[(), ()]);
let edge = Edge::new(&v[0], &v[1], ()).inverse();
assert_eq!(edge.back(), &v[0]);
assert_eq!(edge.absolute_back(), &v[1]);

pub fn absolute_ends(&self) -> (&Vertex<P>, &Vertex<P>)[src]

Returns the vertices at both absolute ends.

let v = Vertex::news(&[(), ()]);
let mut edge = Edge::new(&v[0], &v[1], ());
edge.invert();
assert_eq!(edge.ends(), (&v[1], &v[0]));
assert_eq!(edge.absolute_ends(), (&v[0], &v[1]));

pub fn is_same(&self, other: &Edge<P, C>) -> bool[src]

Returns whether two edges are the same. Returns true even if the orientaions are different.

use truck_topology::{Vertex, Edge};
let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], ());
let edge1 = Edge::new(&v[0], &v[1], ());
let edge2 = edge0.clone();
let edge3 = edge0.inverse();
assert!(!edge0.is_same(&edge1)); // edges whose ids are different are not the same.
assert!(edge0.is_same(&edge2)); // The cloned edge is the same edge.
assert!(edge0.is_same(&edge3)); // The inversed edge is the "same" edge

pub fn try_lock_curve(&self) -> TryLockResult<MutexGuard<'_, C>>[src]

Tries to lock the mutex of the contained curve. The thread will not blocked.

Examples

use truck_topology::*;
let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], 0);
let edge1 = edge0.clone();

// Two vertices have the same content.
assert_eq!(*edge0.try_lock_curve().unwrap(), 0);
assert_eq!(*edge1.try_lock_curve().unwrap(), 0);

{
    let mut curve = edge0.try_lock_curve().unwrap();
    *curve = 1;
}
// The contents of two vertices are synchronized.
assert_eq!(*edge0.try_lock_curve().unwrap(), 1);
assert_eq!(*edge1.try_lock_curve().unwrap(), 1);

// The thread is not blocked even if the curve is already locked.
let lock = edge0.try_lock_curve();
assert!(edge1.try_lock_curve().is_err());    

pub fn lock_curve(&self) -> LockResult<MutexGuard<'_, C>>[src]

Acquires the mutex of the contained curve, blocking the current thread until it is able to do so.

Examples

use truck_topology::*;
let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], 0);
let edge1 = edge0.clone();

// Two edges have the same content.
assert_eq!(*edge0.lock_curve().unwrap(), 0);
assert_eq!(*edge1.lock_curve().unwrap(), 0);

{
    let mut curve = edge0.lock_curve().unwrap();
    *curve = 1;
}
// The contents of two edges are synchronized.
assert_eq!(*edge0.lock_curve().unwrap(), 1);
assert_eq!(*edge1.lock_curve().unwrap(), 1);

// Check the behavior of `lock`.
std::thread::spawn(move || {
    *edge0.lock_curve().unwrap() = 2;
}).join().expect("thread::spawn failed");
assert_eq!(*edge1.lock_curve().unwrap(), 2);    

pub fn id(&self) -> EdgeID<C>[src]

Returns the id that does not depend on the direction of the edge.

Examples

use truck_topology::*;
let v = Vertex::news(&[(), ()]);
let edge0 = Edge::new(&v[0], &v[1], ());
let edge1 = edge0.inverse();
assert_ne!(edge0, edge1);
assert_eq!(edge0.id(), edge1.id());

impl<P, C: Curve<Point = P>> Edge<P, C>[src]

pub fn oriented_curve(&self) -> C[src]

Returns the cloned curve in edge. If edge is inverted, then the returned curve is also inverted.

pub fn is_geometric_consistent(&self) -> bool where
    P: Tolerance
[src]

Returns the consistence of the geometry of end vertices and the geometry of edge.

Trait Implementations

impl<P, C> Clone for Edge<P, C>[src]

impl<P: Debug, C: Debug> Debug for Edge<P, C>[src]

impl<P, C> Eq for Edge<P, C>[src]

impl<P, C> Extend<Edge<P, C>> for Wire<P, C>[src]

impl<'a, P, C> FromIterator<&'a Edge<P, C>> for Wire<P, C>[src]

impl<P, C> FromIterator<Edge<P, C>> for Wire<P, C>[src]

impl<P, C> Hash for Edge<P, C>[src]

impl<P, C> PartialEq<Edge<P, C>> for Edge<P, C>[src]

Auto Trait Implementations

impl<P, C> RefUnwindSafe for Edge<P, C>[src]

impl<P, C> Send for Edge<P, C> where
    C: Send,
    P: Send
[src]

impl<P, C> Sync for Edge<P, C> where
    C: Send,
    P: Send
[src]

impl<P, C> Unpin for Edge<P, C>[src]

impl<P, C> UnwindSafe for Edge<P, C>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.