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
impl Triangulation
Sourcepub fn build(points: &[(f64, f64)]) -> Result<Triangulation, Error>
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.
Sourcepub fn build_with_edges<'a, E>(
points: &[(f64, f64)],
edges: E,
) -> Result<Triangulation, Error>
pub fn build_with_edges<'a, E>( points: &[(f64, f64)], edges: E, ) -> Result<Triangulation, Error>
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.
Sourcepub fn build_from_contours<V>(
points: &[(f64, f64)],
contours: &[V],
) -> Result<Triangulation, Error>
pub fn build_from_contours<V>( points: &[(f64, f64)], contours: &[V], ) -> Result<Triangulation, Error>
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.
Sourcepub fn new_with_edges<'a, E>(
points: &[(f64, f64)],
edges: E,
) -> Result<Triangulation, Error>
pub fn new_with_edges<'a, E>( points: &[(f64, f64)], edges: E, ) -> Result<Triangulation, Error>
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.
Sourcepub fn new(points: &[(f64, f64)]) -> Result<Triangulation, Error>
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.
Sourcepub fn new_from_contours<'a, V>(
pts: &[(f64, f64)],
contours: &[V],
) -> Result<Triangulation, Error>
pub fn new_from_contours<'a, V>( pts: &[(f64, f64)], contours: &[V], ) -> Result<Triangulation, Error>
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.
Sourcepub fn run(&mut self) -> Result<(), Error>
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.
Sourcepub fn check(&self)
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
Sourcepub fn step(&mut self) -> Result<(), Error>
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.
Sourcepub fn triangles(&self) -> impl Iterator<Item = (usize, usize, usize)> + '_
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.
Sourcepub fn inside(&self, p: (f64, f64)) -> bool
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.
Sourcepub fn save_svg(&self, filename: &str) -> Result<()>
pub fn save_svg(&self, filename: &str) -> Result<()>
Writes the current state of the triangulation to an SVG file, without debug visualizations.
Sourcepub fn save_debug_svg(&self, filename: &str) -> Result<()>
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.