1
+ #![ allow( missing_docs) ]
1
2
//! Data and operations on d-dimensional cells or [simplices](https://en.wikipedia.org/wiki/Simplex).
2
3
3
4
use super :: { facet:: Facet , point:: Point , utilities:: make_uuid, vertex:: Vertex } ;
@@ -7,7 +8,7 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
7
8
use std:: { collections:: HashMap , fmt:: Debug , hash:: Hash , iter:: Sum , ops:: Div } ;
8
9
use uuid:: Uuid ;
9
10
10
- #[ derive( Clone , Debug , Default , Deserialize , Eq , Serialize ) ]
11
+ #[ derive( Builder , Clone , Debug , Default , Deserialize , Eq , Serialize ) ]
11
12
/// The [Cell] struct represents a d-dimensional
12
13
/// [simplex](https://en.wikipedia.org/wiki/Simplex) with vertices, a unique
13
14
/// identifier, optional neighbors, and optional data.
@@ -36,10 +37,13 @@ where
36
37
/// The vertices of the cell.
37
38
pub vertices : Vec < Vertex < T , U , D > > ,
38
39
/// The unique identifier of the cell.
40
+ #[ builder( setter( skip) , default = "make_uuid()" ) ]
39
41
pub uuid : Uuid ,
40
42
/// The neighboring cells connected to the current cell.
43
+ #[ builder( setter( skip) , default = "None" ) ]
41
44
pub neighbors : Option < Vec < Uuid > > ,
42
45
/// The optional data associated with the cell.
46
+ #[ builder( setter( into, strip_option) , default ) ]
43
47
pub data : Option < V > ,
44
48
}
45
49
52
56
f64 : From < T > ,
53
57
[ T ; D ] : Copy + Default + DeserializeOwned + Serialize + Sized ,
54
58
{
55
- /// The function `new` creates a new [Cell] object with the given
56
- /// vertices. A D-dimensional cell has D + 1 vertices, so the number of
57
- /// vertices must be less than or equal to D + 1.
58
- ///
59
- /// # Arguments:
60
- ///
61
- /// * `vertices`: The vertices of the [Cell] to be constructed.
62
- ///
63
- /// # Returns:
64
- ///
65
- /// a [Result] type. If the condition `vertices.len() > D + 1` is true, it
66
- /// returns an [Err] variant with the message "Number of vertices must be
67
- /// less than or equal to D + 1". Otherwise, it returns an [Ok] variant
68
- /// with a [Cell] containing the provided `vertices`, a generated [Uuid],
69
- /// and optional neighbor and data fields.
70
- ///
71
- /// Neighbors will be calculated by the
72
- /// `delaunay_core::triangulation_data_structure::Tds`.
73
- ///
74
- /// # Example
75
- ///
76
- /// ```
77
- /// use d_delaunay::delaunay_core::cell::Cell;
78
- /// use d_delaunay::delaunay_core::vertex::{Vertex, VertexBuilder};
79
- /// use d_delaunay::delaunay_core::point::Point;
80
- /// let vertex1 = VertexBuilder::default().point(Point::new([0.0, 0.0, 1.0])).build().unwrap();
81
- /// let vertex2 = VertexBuilder::default().point(Point::new([0.0, 1.0, 0.0])).build().unwrap();
82
- /// let vertex3 = VertexBuilder::default().point(Point::new([1.0, 0.0, 0.0])).build().unwrap();
83
- /// let vertex4 = VertexBuilder::default().point(Point::new([1.0, 1.0, 1.0])).build().unwrap();
84
- /// let cell: Cell<f64, Option<()>, Option<()>, 3> = Cell::new(vec![vertex1, vertex2, vertex3, vertex4]).unwrap();
85
- /// assert!(cell.vertices.contains(&vertex1));
86
- /// ```
59
+ #[ deprecated( since = "0.1.0" , note = "Please use `CellBuilder` instead." ) ]
87
60
pub fn new ( vertices : Vec < Vertex < T , U , D > > ) -> Result < Self , & ' static str > {
88
61
if vertices. len ( ) > D + 1 {
89
62
return Err ( "Number of vertices must be less than or equal to D + 1!" ) ;
99
72
} )
100
73
}
101
74
102
- /// The function `new_with_data` creates a new [Cell] object with the given
103
- /// vertices and data. A D-dimensional cell has D + 1 vertices, so the
104
- /// number of vertices must be less than or equal to D + 1.
105
- ///
106
- /// # Arguments:
107
- ///
108
- /// * `vertices`: The vertices of the [Cell] to be constructed.
109
- /// * `data`: The data associated with the [Cell].
110
- ///
111
- /// # Returns:
112
- ///
113
- /// a [Result] type. If the condition `vertices.len() > D + 1` is true, it
114
- /// returns an [Err] variant with the message "Number of vertices must be
115
- /// less than or equal to D + 1". Otherwise, it returns an [Ok] variant
116
- /// with a [Cell] containing the provided `vertices`, a generated [Uuid],
117
- /// the provided data, and optional neighbor fields which will be later be
118
- /// calculated by the
119
- /// `delaunay_core::triangulation_data_structure::Tds`.
120
- ///
121
- /// # Example
122
- ///
123
- /// ```
124
- /// use d_delaunay::delaunay_core::cell::Cell;
125
- /// use d_delaunay::delaunay_core::vertex::{Vertex, VertexBuilder};
126
- /// use d_delaunay::delaunay_core::point::Point;
127
- /// let vertex1: Vertex<f64, i32, 3> = VertexBuilder::default().point(Point::new([0.0, 0.0, 1.0])).data(1).build().unwrap();
128
- /// let vertex2: Vertex<f64, i32, 3> = VertexBuilder::default().point(Point::new([0.0, 1.0, 0.0])).data(1).build().unwrap();
129
- /// let vertex3: Vertex<f64, i32, 3> = VertexBuilder::default().point(Point::new([1.0, 0.0, 0.0])).data(1).build().unwrap();
130
- /// let vertex4: Vertex<f64, i32, 3> = VertexBuilder::default().point(Point::new([1.0, 1.0, 1.0])).data(2).build().unwrap();
131
- /// let cell = Cell::new_with_data(vec![vertex1, vertex2, vertex3, vertex4], "three-one cell").unwrap();
132
- /// assert_eq!(cell.data.unwrap(), "three-one cell");
133
- /// ```
75
+ #[ deprecated( since = "0.1.0" , note = "Please use `CellBuilder` instead." ) ]
134
76
pub fn new_with_data ( vertices : Vec < Vertex < T , U , D > > , data : V ) -> Result < Self , & ' static str > {
135
77
if vertices. len ( ) > D + 1 {
136
78
return Err ( "Number of vertices must be less than or equal to D + 1!" ) ;
@@ -160,15 +102,15 @@ where
160
102
/// # Example
161
103
///
162
104
/// ```
163
- /// use d_delaunay::delaunay_core::cell::Cell;
105
+ /// use d_delaunay::delaunay_core::cell::{ Cell, CellBuilder} ;
164
106
/// use d_delaunay::delaunay_core::facet::Facet;
165
107
/// use d_delaunay::delaunay_core::vertex::{Vertex, VertexBuilder};
166
108
/// use d_delaunay::delaunay_core::point::Point;
167
109
/// let vertex1 = VertexBuilder::default().point(Point::new([0.0, 0.0, 1.0])).build().unwrap();
168
110
/// let vertex2 = VertexBuilder::default().point(Point::new([0.0, 1.0, 0.0])).build().unwrap();
169
111
/// let vertex3 = VertexBuilder::default().point(Point::new([1.0, 0.0, 0.0])).build().unwrap();
170
112
/// let vertex4 = VertexBuilder::default().point(Point::new([1.0, 1.0, 1.0])).build().unwrap();
171
- /// let cell: Cell<f64, Option<()>, Option<()>,3> = Cell::new( vec![vertex1, vertex2, vertex3, vertex4]).unwrap();
113
+ /// let cell: Cell<f64, Option<()>, Option<()>, 3> = CellBuilder::default().vertices( vec![vertex1, vertex2, vertex3, vertex4]).build( ).unwrap();
172
114
/// let facet = Facet::new(cell.clone(), vertex4).unwrap();
173
115
/// let vertex5 = VertexBuilder::default().point(Point::new([0.0, 0.0, 0.0])).build().unwrap();
174
116
/// let new_cell = Cell::from_facet_and_vertex(facet, vertex5).unwrap();
@@ -547,8 +489,10 @@ mod tests {
547
489
. data ( 2 )
548
490
. build ( )
549
491
. unwrap ( ) ;
550
- let cell: Cell < f64 , i32 , Option < ( ) > , 3 > =
551
- Cell :: new ( vec ! [ vertex1, vertex2, vertex3, vertex4] ) . unwrap ( ) ;
492
+ let cell: Cell < f64 , i32 , Option < ( ) > , 3 > = CellBuilder :: default ( )
493
+ . vertices ( vec ! [ vertex1, vertex2, vertex3, vertex4] )
494
+ . build ( )
495
+ . unwrap ( ) ;
552
496
553
497
assert_eq ! ( cell. vertices, [ vertex1, vertex2, vertex3, vertex4] ) ;
554
498
assert_eq ! ( cell. vertices[ 0 ] . data. unwrap( ) , 1 ) ;
@@ -593,6 +537,7 @@ mod tests {
593
537
. unwrap ( ) ;
594
538
let cell: Result < Cell < f64 , i32 , Option < ( ) > , 3 > , & ' static str > =
595
539
Cell :: new ( vec ! [ vertex1, vertex2, vertex3, vertex4, vertex5] ) ;
540
+ // let cell: Cell<f64, i32, Option<()>,3> = CellBuilder::default().vertices(vec![vertex1, vertex2, vertex3, vertex4, vertex5]).build().unwrap();
596
541
597
542
assert ! ( cell. is_err( ) ) ;
598
543
0 commit comments