Struct Triangulation

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

This struct contains all of the data needed to generate a (constrained) Delaunay triangulation of a set of input points and edges. It is a low-level API; consider using the module-level functions if you don’t need total control.

Implementations§

Source§

impl Triangulation

Source

pub fn build(points: &[(f64, f64)]) -> Result<Triangulation, Error>

Builds a complete triangulation from the given points

§Errors

This may return Error::EmptyInput, Error::InvalidInput, or Error::CannotInitialize if the input is invalid.

Source

pub fn build_with_edges<'a, E>( points: &[(f64, f64)], edges: E, ) -> Result<Triangulation, Error>
where E: IntoIterator<Item = &'a (usize, usize)> + Copy,

Builds a complete triangulation from the given points and edges. The points are a flat array of positions in 2D spaces; edges are undirected and expressed as indexes into the points list.

§Errors

This may return Error::EmptyInput, Error::InvalidInput, Error::InvalidEdge, or Error::CannotInitialize if the input is invalid.

Source

pub fn build_from_contours<V>( points: &[(f64, f64)], contours: &[V], ) -> Result<Triangulation, Error>
where for<'b> &'b V: IntoIterator<Item = &'b usize>,

Builds a complete triangulation from the given points and contours (which are represented as indexes into the points array).

§Errors

This may return Error::EmptyInput, Error::InvalidInput, Error::InvalidEdge, Error::OpenContour or Error::CannotInitialize if the input is invalid.

Source

pub fn new_with_edges<'a, E>( points: &[(f64, f64)], edges: E, ) -> Result<Triangulation, Error>
where E: IntoIterator<Item = &'a (usize, usize)> + Copy,

Constructs a new triangulation of the given points. The points are a flat array of positions in 2D spaces; edges are undirected and expressed as indexes into the points list.

The triangulation is not actually run in this constructor; use Triangulation::step or Triangulation::run to triangulate, or Triangulation::build_with_edges to get a complete triangulation right away.

§Errors

This may return Error::EmptyInput, Error::InvalidInput, Error::InvalidEdge, or Error::CannotInitialize if the input is invalid.

Source

pub fn new(points: &[(f64, f64)]) -> Result<Triangulation, Error>

Constructs a new unconstrained triangulation

The triangulation is not actually run in this constructor; use Triangulation::step or Triangulation::run to triangulate, or Triangulation::build to get a complete triangulation right away.

§Errors

This may return Error::EmptyInput, Error::InvalidInput, or Error::CannotInitialize if the input is invalid.

Source

pub fn new_from_contours<'a, V>( pts: &[(f64, f64)], contours: &[V], ) -> Result<Triangulation, Error>
where for<'b> &'b V: IntoIterator<Item = &'b usize>,

Triangulates a set of contours, given as indexed paths into the point list. Each contour must be closed (i.e. the last point in the contour must equal the first point), otherwise Error::OpenContour will be returned.

The triangulation is not actually run in this constructor; use Triangulation::step or Triangulation::run to triangulate, or Triangulation::build_from_contours to get a complete triangulation right away.

§Errors

This may return Error::EmptyInput, Error::InvalidInput, Error::InvalidEdge, Error::OpenContour or Error::CannotInitialize if the input is invalid.

Source

pub fn run(&mut self) -> Result<(), Error>

Runs the triangulation algorithm until completion

§Errors

This may return Error::PointOnFixedEdge, Error::NoMorePoints, or Error::CrossingFixedEdge if those error conditions are met.

Source

pub fn done(&self) -> bool

Checks whether the triangulation is done

Source

pub fn check(&self)

Checks that invariants of the algorithm are maintained. This is a slow operation and should only be used for debugging.

§Panics

Panics if invariants are not correct

Source

pub fn step(&mut self) -> Result<(), Error>

Advances the triangulation by one step.

§Errors

This may return Error::PointOnFixedEdge, Error::NoMorePoints, or Error::CrossingFixedEdge if those error conditions are met.

Source

pub fn triangles(&self) -> impl Iterator<Item = (usize, usize, usize)> + '_

Returns all of the resulting triangles, as indexes into the original points array from the constructor.

Source

pub fn inside(&self, p: (f64, f64)) -> bool

Checks whether the given point is inside or outside the triangulation. This is extremely inefficient, and should only be used for debugging or unit tests.

Source

pub fn save_svg(&self, filename: &str) -> Result<()>

Writes the current state of the triangulation to an SVG file, without debug visualizations.

Source

pub fn save_debug_svg(&self, filename: &str) -> Result<()>

Writes the current state of the triangulation to an SVG file, including the upper hull as a debugging visualization.

Source

pub fn to_svg(&self, debug: bool) -> String

Converts the current state of the triangulation to an SVG. When debug is true, includes the upper hull and to-be-fixed edges; otherwise, just shows points, triangles, and fixed edges from the half-edge graph.

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