Skip to main content

Node

Struct Node 

Source
pub struct Node {
    pub position: Point,
    pub exact: [f32; 2],
    pub offset: f32,
    pub kind: NodeKind,
    pub sources: Vec<EdgeId>,
}
Expand description

A vertex of the skeleton graph.

§Examples

use straight_skeleton::{skeleton, NodeKind, Point, Polygon};

let square = Polygon::from_outer(&[
    Point::new(0, 0), Point::new(10, 0), Point::new(10, 10), Point::new(0, 10),
])?;
let skel = skeleton(&square)?;

// Every input vertex gets a boundary node at offset 0.
let boundary: Vec<_> = skel.nodes().iter().filter(|n| n.is_boundary()).collect();
assert_eq!(boundary.len(), 4);
assert!(boundary.iter().all(|n| n.offset == 0.0));

Fields§

§position: Point

The node’s position, rounded to the integer lattice.

Skeleton nodes are generally irrational even for integer input, so this is the nearest lattice point. Use Node::exact when the rounding matters.

§exact: [f32; 2]

The node’s unrounded position.

The algorithm computes in f32 throughout, so this is the value it actually arrived at, not a narrowing of something wider.

§offset: f32

How far the wavefront had travelled when this node was created.

For a plain skeleton, this is the node’s distance to the supporting line of each of its Node::sources. It is the node’s height on a roof, and the offset at which the node appears on an offset curve.

For a skeleton_constrained, it is the wavefront’s time, which is no longer the same thing: an edge that stopped at limit stays limit away however long the wavefront runs on. The distance to a source edge e’s line is min(offset, limit_e).

§kind: NodeKind

What produced this node.

§sources: Vec<EdgeId>

The input edges whose wavefronts arrived here together.

Always at least 2 entries, and 3 or more where several skeleton arcs meet. Each one’s supporting line is Node::offset away (see that field for the constrained case).

§This is not quite “nearest”

For a convex polygon these really are the nearest input edges, since there the straight skeleton coincides with the medial axis.

Elsewhere they may not be, and the difference is the definition of a straight skeleton rather than a wrinkle in this implementation. A straight skeleton bisects edges’ infinite supporting lines, which is what keeps every arc straight. A medial axis bisects the nearest features, and so grows parabolic arcs around reflex vertices. Around a reflex corner the two part company: a plus-shape’s centre is at offset 5 from the four arms’ walls, but the nearest input feature is a reflex corner 7.07 away.

So read sources as “the input edges whose faces meet here” — which is the useful notion anyway, and the one a roof needs. See Arc::sources.

Implementations§

Source§

impl Node

Source

pub fn is_boundary(&self) -> bool

Whether this node lies on the input boundary.

Source

pub fn input_vertex(&self) -> Option<VertexId>

The input vertex this node sits on, if it is a boundary node.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Node

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Node

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Node

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Node

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

§

impl UnwindSafe for Node

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.