pub trait Coord: Sync + Send + Clone {
    // Required methods
    fn from_xy(x: f64, y: f64) -> Self;
    fn x(&self) -> f64;
    fn y(&self) -> f64;

    // Provided method
    fn magnitude2(&self) -> f64 { ... }
}
Expand description

Trait for a coordinate (point) used to generate a Voronoi diagram. The default included struct Point is included below as an example.

use voronator::delaunator::{Coord, Vector};
 
#[derive(Clone, PartialEq)]
/// Represents a point in the 2D space.
pub struct Point {
   /// X coordinate of the point
   pub x: f64,
   /// Y coordinate of the point
   pub y: f64,
}

impl Coord for Point {
   // Inline these methods as otherwise we incur a heavy performance penalty
   #[inline(always)]
   fn from_xy(x: f64, y: f64) -> Self {
       Point{x, y}
   }
   #[inline(always)]
   fn x(&self) -> f64 {
      self.x
   }
   #[inline(always)]
   fn y(&self) -> f64 {
       self.y
   }
}

impl Vector<Point> for Point {}

Required Methods§

source

fn from_xy(x: f64, y: f64) -> Self

Create a coordinate from (x, y) positions

source

fn x(&self) -> f64

Return x coordinate

source

fn y(&self) -> f64

Return y coordinate

Provided Methods§

source

fn magnitude2(&self) -> f64

Return the magnitude of the 2D vector represented by (x, y)

Implementors§