1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use crate::prelude::*;
use num_traits::AsPrimitive;
impl<T: InputType + nalgebra::Scalar> From<nalgebra::Point2<T>> for Point<T> {
#[inline]
/// Converts to `boostvoronoi::geometry::Point` from `nalgebra::Point2`
/// ```
/// # use boostvoronoi::prelude::*;
/// let c = nalgebra::Point2::new(1,2);
/// let p:Point<i32> = Point::from(c);
/// assert_eq!(p.x,c.x);
/// assert_eq!(p.y,c.y);
/// ```
fn from(p: nalgebra::Point2<T>) -> Self {
Self { x: p.x, y: p.y }
}
}
impl<T: InputType + nalgebra::Scalar> From<&nalgebra::Point2<T>> for Point<T> {
#[inline]
/// Converts to `boostvoronoi::geometry::Point` from `&nalgebra::Point2`
/// ```
/// # use boostvoronoi::prelude::*;
/// let c = nalgebra::Point2::new(1,2);
/// let p:Point<i32> = Point::from(&c);
/// assert_eq!(p.x,c.x);
/// assert_eq!(p.y,c.y);
/// ```
fn from(p: &nalgebra::Point2<T>) -> Self {
Self { x: p.x, y: p.y }
}
}
impl<T: InputType + nalgebra::Scalar> From<Point<T>> for nalgebra::Point2<T> {
#[inline]
/// Converts to `geo::Coord` from `boostvoronoi::geometry::Point`
/// ```
/// # use boostvoronoi::prelude::*;
/// let p = Point{x:1,y:2};
/// let c = nalgebra::Point2::<i32>::from(p);
/// assert_eq!(p.x,c.x);
/// assert_eq!(p.y,c.y);
/// ```
fn from(p: Point<T>) -> Self {
Self::new(p.x, p.y)
}
}
impl<F: nalgebra::Scalar + Copy> From<&Vertex> for nalgebra::Point2<F>
where
f64: AsPrimitive<F>,
{
#[inline]
/// Converts to `nalgebra::Point2` from `&boostvoronoi::diagram::Vertex`
/// ```
/// # use boostvoronoi::prelude::*;
/// # use num_traits::AsPrimitive;
///
/// let v = Vertex::new_3(VertexIndex::default(),1.0,2.0,false);
/// let p = nalgebra::Point2::<f32>::from(&v);
/// assert_eq!(v.x(),p.x.as_());
/// assert_eq!(v.y(),p.y.as_());
/// ```
fn from(v: &Vertex) -> Self {
Self::new(v.x().as_(), v.y().as_())
}
}
impl<F: nalgebra::Scalar + Copy> From<Vertex> for nalgebra::Point2<F>
where
f64: AsPrimitive<F>,
{
#[inline]
/// Converts to `nalgebra::Point2` from `boostvoronoi::diagram::Vertex`
/// ```
/// # use boostvoronoi::prelude::*;
/// # use num_traits::AsPrimitive;
///
/// let v = Vertex::new_3(VertexIndex::default(),1.0,2.0,false);
/// let p = nalgebra::Point2::<f32>::from(v.clone());
/// assert_eq!(v.x(),p.x.as_());
/// assert_eq!(v.y(),p.y.as_());
/// ```
fn from(v: Vertex) -> Self {
Self::new(v.x().as_(), v.y().as_())
}
}