Struct voronoice::VoronoiCell
source · [−]pub struct VoronoiCell<'v> { /* private fields */ }
Expand description
Represents a Voronoi cell. This is an ergonomic way to access cell details.
Use Voronoi::cell() or Voronoi::iter_cells() to obtain an instance of this type.
Implementations
sourceimpl<'v> VoronoiCell<'v>
impl<'v> VoronoiCell<'v>
sourcepub fn site_position(&self) -> &Point
pub fn site_position(&self) -> &Point
Gets a reference to the position of the site associated with this cell.
Examples
use voronoice::*;
let sites = vec![Point { x: 0.0, y: 0.0 }, Point { x: 0.5, y: 0.0 }, Point { x: 0.0, y: 0.5 }];
let v = VoronoiBuilder::default()
.set_sites(sites.clone())
.build()
.unwrap();
// the first site generated by generate_circle_sites is at the origin
assert_eq!(&sites[0], v.cell(0).site_position());
assert_eq!(&sites[1], v.cell(1).site_position());
assert_eq!(&sites[2], v.cell(2).site_position());
sourcepub fn triangles(&self) -> &[usize]
pub fn triangles(&self) -> &[usize]
Gets a slice of indices into Voronoi::vertices used to index the Points representing the voronoi cell vertices.
Semantically these values represent the Delaunay triangles associated with this voronoi cell. The Voronoi cell vertices are the circumcenters of the associated Delaunay triangles.
If this cell is on the hull of the diagram (cell.is_on_hull() == true
), or has had one of its edges clipped, some indices will not match to
Delaunay triangles, but to virtual points added during the process of hull closing and clipping. These values will still correctly index into the Voronoi::vertices() vector.
sourcepub fn iter_vertices(&self) -> impl Iterator<Item = &Point> + Clone
pub fn iter_vertices(&self) -> impl Iterator<Item = &Point> + Clone
Gets an iterator for the vertices of this cell.
Vertices are returned in sequential counter-clockwise order. Please see Self::triangles and Voronoi::vertices for additional details regarding hull closing and clipping effects on vertices.
sourcepub fn iter_neighbors(&self) -> NeighborSiteIterator<'_>ⓘNotable traits for NeighborSiteIterator<'t>impl<'t> Iterator for NeighborSiteIterator<'t> type Item = usize;
pub fn iter_neighbors(&self) -> NeighborSiteIterator<'_>ⓘNotable traits for NeighborSiteIterator<'t>impl<'t> Iterator for NeighborSiteIterator<'t> type Item = usize;
Gets an iterator that returns the index of each site that shared an edge with this cell/site, in a counter-clockwise manner.
Example
use voronoice::*;
let sites = vec![Point { x: -0.5, y: 0.0 }, Point { x: 0.5, y: 0.0 }, Point { x: 0.0, y: 0.0 }, Point { x: 0.0, y: 0.5 }, Point { x: 0.0, y: -0.5 }];
let v = VoronoiBuilder::default()
.set_sites(sites.clone())
.build()
.unwrap();
let neighbors: Vec<usize> = v.cell(0).iter_neighbors().collect();
assert_eq!(neighbors[0], 4);
assert_eq!(neighbors[1], 2);
assert_eq!(neighbors[2], 3);
sourcepub fn iter_path<'p>(&self, dest: Point) -> impl Iterator<Item = usize> + 'v
pub fn iter_path<'p>(&self, dest: Point) -> impl Iterator<Item = usize> + 'v
Gets an iterator that returns the shortest path on the Voronoi diagram to the destination point, starting from the current cell.
sourcepub fn is_on_hull(&self) -> bool
pub fn is_on_hull(&self) -> bool
Returns a boolean indicating whether this cell is on the hull (edge) of the diagram.
A Voronoi cell is on the hull if its associated site is on the Delaunay hull or if clipping is enabled and the cell intersects with the bounding box.
Trait Implementations
sourceimpl<'v> Clone for VoronoiCell<'v>
impl<'v> Clone for VoronoiCell<'v>
sourcefn clone(&self) -> VoronoiCell<'v>
fn clone(&self) -> VoronoiCell<'v>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<'v> RefUnwindSafe for VoronoiCell<'v>
impl<'v> Send for VoronoiCell<'v>
impl<'v> Sync for VoronoiCell<'v>
impl<'v> Unpin for VoronoiCell<'v>
impl<'v> UnwindSafe for VoronoiCell<'v>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more