Skip to main content

Contours

Struct Contours 

Source
pub struct Contours { /* private fields */ }
Expand description

A collection of Contours, representing a set.

Can be indexed with a ContourIdx.

A Contour represents a set as a hierarchical collection of closed paths, where each path has the set on its left (in a Y-down coordinate system). A very simple set is represented as just a single closed path:

  ╭───<───╮
  │xxxxxxx│
  │xxxxxxx│
  ╰───>───╯

(The xs represent the interior of the set, and the arrows show the orientation of the curve.)

Two disjoint sets are represented as two unrelated closed paths:

  ╭───<───╮
  │xxxxxxx│
  │xxxxxxx│  ╭───<───╮
  ╰───>───╯  │xxxxxxx│
             │xxxxxxx│
             ╰───>───╯

The hierarchical structure appears when you have sets with holes: a set with a single hole is represented as a contour (the outer boundary) with a child contour (the inner boundary). Notice how the curves are oriented so that the set is always on the left.

  ╭───<──────╮
  │xxxxxxxxxx│
  │xxx╭>─╮xxx│
  │xxx│  │xxx│
  │xxx╰─<╯xxx│
  │xxxxxxxxxx│
  ╰──────>───╯

A set can have multiple holes (and so a contour can have multiple children), and those holes can contain more parts of the set. So in general, the collection of contours forms a forest.

Because of the way we organize the contour directions, the set described by our contours has a winding number of 1 and its complement has a winding number of 0. In particular, if you gather up all the contours and put them in an SVG, it won’t make a difference whether you fill them with a non-zero or an even-odd fill rule.

Implementations§

Source§

impl Contours

Source

pub fn grouped(&self) -> Vec<Vec<ContourIdx>>

Returns all of the contour indices, grouped by containment.

For each of the inner vecs, the first element is an outer contour with no parent. All of the other contours in that inner vec lie inside that outer contour.

Source

pub fn contours(&self) -> impl Iterator<Item = &Contour> + '_

Iterates over all of the contours, ignoring the hierarchical structure.

For example, if you’re creating an SVG path out of all these contours then you don’t need the hierarchical structure: the SVG renderer can figure that out by itself.

Trait Implementations§

Source§

impl Clone for Contours

Source§

fn clone(&self) -> Contours

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Contours

Source§

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

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

impl Default for Contours

Source§

fn default() -> Contours

Returns the “default value” for a type. Read more
Source§

impl Index<ContourIdx> for Contours

Source§

type Output = Contour

The returned type after indexing.
Source§

fn index(&self, index: ContourIdx) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

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> 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.