@@ -146,6 +146,50 @@ where
146
146
} )
147
147
}
148
148
149
+ /// The function `from_facet_and_vertex` creates a new [Cell] object from a [Facet] and a [Vertex].
150
+ ///
151
+ /// # Arguments:
152
+ ///
153
+ /// * `facet`: The [Facet] to be used to create the [Cell].
154
+ /// * `vertex`: The [Vertex] to be added to the [Cell].
155
+ ///
156
+ /// # Returns:
157
+ ///
158
+ /// A [Result] type containing the new [Cell] or an error message.
159
+ ///
160
+ /// # Example
161
+ ///
162
+ /// ```
163
+ /// use d_delaunay::delaunay_core::cell::Cell;
164
+ /// use d_delaunay::delaunay_core::facet::Facet;
165
+ /// use d_delaunay::delaunay_core::vertex::Vertex;
166
+ /// use d_delaunay::delaunay_core::point::Point;
167
+ /// let vertex1: Vertex<f64, Option<()>, 3> = Vertex::new(Point::new([0.0, 0.0, 1.0]));
168
+ /// let vertex2: Vertex<f64, Option<()>, 3> = Vertex::new(Point::new([0.0, 1.0, 0.0]));
169
+ /// let vertex3: Vertex<f64, Option<()>, 3> = Vertex::new(Point::new([1.0, 0.0, 0.0]));
170
+ /// let vertex4: Vertex<f64, Option<()>, 3> = Vertex::new(Point::new([1.0, 1.0, 1.0]));
171
+ /// let cell: Cell<f64, Option<()>, Option<()>,3> = Cell::new(vec![vertex1, vertex2, vertex3, vertex4]).unwrap();
172
+ /// let facet = Facet::new(cell.clone(), vertex4).unwrap();
173
+ /// let vertex5 = Vertex::new(Point::new([0.0, 0.0, 0.0]));
174
+ /// let new_cell = Cell::from_facet_and_vertex(facet, vertex5).unwrap();
175
+ /// assert!(new_cell.vertices.contains(&vertex5));
176
+ pub fn from_facet_and_vertex (
177
+ mut facet : Facet < T , U , V , D > ,
178
+ vertex : Vertex < T , U , D > ,
179
+ ) -> Result < Self , & ' static str > {
180
+ let mut vertices = facet. vertices ( ) ;
181
+ vertices. push ( vertex) ;
182
+ let uuid = make_uuid ( ) ;
183
+ let neighbors = None ;
184
+ let data = None ;
185
+ Ok ( Cell {
186
+ vertices,
187
+ uuid,
188
+ neighbors,
189
+ data,
190
+ } )
191
+ }
192
+
149
193
/// The function `into_hashmap` converts a [Vec] of cells into a [HashMap],
150
194
/// using the [Cell] [Uuid]s as keys.
151
195
pub fn into_hashmap ( cells : Vec < Self > ) -> HashMap < Uuid , Self > {
@@ -239,6 +283,34 @@ where
239
283
self . vertices . contains ( & vertex)
240
284
}
241
285
286
+ /// The function `contains_vertex_of` checks if the [Cell] contains any [Vertex] of a given [Cell].
287
+ ///
288
+ /// # Arguments:
289
+ ///
290
+ /// * `cell`: The [Cell] to check.
291
+ ///
292
+ /// # Returns:
293
+ ///
294
+ /// Returns `true` if the given [Cell] has any [Vertex] in common with the [Cell].
295
+ ///
296
+ /// # Example
297
+ ///
298
+ /// ```
299
+ /// use d_delaunay::delaunay_core::cell::Cell;
300
+ /// use d_delaunay::delaunay_core::vertex::Vertex;
301
+ /// use d_delaunay::delaunay_core::point::Point;
302
+ /// let vertex1 = Vertex::new_with_data(Point::new([0.0, 0.0, 1.0]), 1);
303
+ /// let vertex2 = Vertex::new_with_data(Point::new([0.0, 1.0, 0.0]), 1);
304
+ /// let vertex3 = Vertex::new_with_data(Point::new([1.0, 0.0, 0.0]), 1);
305
+ /// let vertex4 = Vertex::new_with_data(Point::new([1.0, 1.0, 1.0]), 2);
306
+ /// let cell = Cell::new_with_data(vec![vertex1, vertex2, vertex3, vertex4], "three-one cell").unwrap();
307
+ /// let vertex5 = Vertex::new_with_data(Point::new([0.0, 0.0, 0.0]), 0);
308
+ /// let cell2 = Cell::new_with_data(vec![vertex1, vertex2, vertex3, vertex5], "one-three cell").unwrap();
309
+ /// assert!(cell.contains_vertex_of(cell2));
310
+ pub fn contains_vertex_of ( & self , cell : Cell < T , U , V , D > ) -> bool {
311
+ self . vertices . iter ( ) . any ( |v| cell. vertices . contains ( v) )
312
+ }
313
+
242
314
/// The function `circumcenter` returns the circumcenter of the cell.
243
315
///
244
316
/// Using the approach from:
@@ -407,37 +479,6 @@ where
407
479
408
480
facets
409
481
}
410
-
411
- /// The function `contains_facet` checks if a given [Facet] is present in
412
- /// the [Cell].
413
- ///
414
- /// # Arguments:
415
- ///
416
- /// * facet: The [Facet] to check.
417
- ///
418
- /// # Returns:
419
- ///
420
- /// Returns `true` if the given [Facet] is present in the [Cell], and
421
- /// `false` otherwise.
422
- ///
423
- /// # Example
424
- ///
425
- /// ```
426
- /// use d_delaunay::delaunay_core::cell::Cell;
427
- /// use d_delaunay::delaunay_core::facet::Facet;
428
- /// use d_delaunay::delaunay_core::vertex::Vertex;
429
- /// use d_delaunay::delaunay_core::point::Point;
430
- /// let vertex1 = Vertex::new_with_data(Point::new([0.0, 0.0, 1.0]), 1);
431
- /// let vertex2 = Vertex::new_with_data(Point::new([0.0, 1.0, 0.0]), 1);
432
- /// let vertex3 = Vertex::new_with_data(Point::new([1.0, 0.0, 0.0]), 1);
433
- /// let vertex4 = Vertex::new_with_data(Point::new([1.0, 1.0, 1.0]), 2);
434
- /// let cell = Cell::new_with_data(vec![vertex1, vertex2, vertex3, vertex4], "three-one cell").unwrap();
435
- /// let facet = Facet::new(cell.clone(), vertex1).unwrap();
436
- /// assert!(cell.contains_facet(facet));
437
- /// ```
438
- pub fn contains_facet ( & self , facet : Facet < T , U , V , D > ) -> bool {
439
- self . facets ( ) . contains ( & facet)
440
- }
441
482
}
442
483
443
484
/// Equality of cells is based on equality of sorted vector of vertices.
@@ -577,6 +618,27 @@ mod tests {
577
618
assert_eq ! ( cell1, cell2) ;
578
619
}
579
620
621
+ #[ test]
622
+ fn cell_from_facet_and_vertex ( ) {
623
+ let vertex1 = Vertex :: new_with_data ( Point :: new ( [ 0.0 , 0.0 , 1.0 ] ) , 1 ) ;
624
+ let vertex2 = Vertex :: new_with_data ( Point :: new ( [ 0.0 , 1.0 , 0.0 ] ) , 1 ) ;
625
+ let vertex3 = Vertex :: new_with_data ( Point :: new ( [ 1.0 , 0.0 , 0.0 ] ) , 1 ) ;
626
+ let vertex4 = Vertex :: new_with_data ( Point :: new ( [ 1.0 , 1.0 , 1.0 ] ) , 2 ) ;
627
+ let cell: Cell < f64 , i32 , Option < ( ) > , 3 > =
628
+ Cell :: new ( vec ! [ vertex1, vertex2, vertex3, vertex4] ) . unwrap ( ) ;
629
+ let facet = Facet :: new ( cell. clone ( ) , vertex4) . unwrap ( ) ;
630
+ let vertex5 = Vertex :: new ( Point :: new ( [ 0.0 , 0.0 , 0.0 ] ) ) ;
631
+ let new_cell = Cell :: from_facet_and_vertex ( facet, vertex5) . unwrap ( ) ;
632
+
633
+ assert ! ( new_cell. vertices. contains( & vertex1) ) ;
634
+ assert ! ( new_cell. vertices. contains( & vertex2) ) ;
635
+ assert ! ( new_cell. vertices. contains( & vertex3) ) ;
636
+ assert ! ( new_cell. vertices. contains( & vertex5) ) ;
637
+
638
+ // Human readable output for cargo test -- --nocapture
639
+ println ! ( "New Cell: {:?}" , new_cell) ;
640
+ }
641
+
580
642
#[ test]
581
643
fn cell_into_hashmap ( ) {
582
644
let vertex1 = Vertex :: new_with_data ( Point :: new ( [ 0.0 , 0.0 , 1.0 ] ) , 1 ) ;
@@ -636,6 +698,24 @@ mod tests {
636
698
println ! ( "Cell: {:?}" , cell) ;
637
699
}
638
700
701
+ #[ test]
702
+ fn cell_contains_vertex_of ( ) {
703
+ let vertex1 = Vertex :: new_with_data ( Point :: new ( [ 0.0 , 0.0 , 1.0 ] ) , 1 ) ;
704
+ let vertex2 = Vertex :: new_with_data ( Point :: new ( [ 0.0 , 1.0 , 0.0 ] ) , 1 ) ;
705
+ let vertex3 = Vertex :: new_with_data ( Point :: new ( [ 1.0 , 0.0 , 0.0 ] ) , 1 ) ;
706
+ let vertex4 = Vertex :: new_with_data ( Point :: new ( [ 1.0 , 1.0 , 1.0 ] ) , 2 ) ;
707
+ let cell = Cell :: new_with_data ( vec ! [ vertex1, vertex2, vertex3, vertex4] , "three-one cell" )
708
+ . unwrap ( ) ;
709
+ let vertex5 = Vertex :: new_with_data ( Point :: new ( [ 0.0 , 0.0 , 0.0 ] ) , 0 ) ;
710
+ let cell2 = Cell :: new_with_data ( vec ! [ vertex1, vertex2, vertex3, vertex5] , "one-three cell" )
711
+ . unwrap ( ) ;
712
+
713
+ assert ! ( cell. contains_vertex_of( cell2) ) ;
714
+
715
+ // Human readable output for cargo test -- --nocapture
716
+ println ! ( "Cell: {:?}" , cell) ;
717
+ }
718
+
639
719
#[ test]
640
720
fn cell_circumcenter ( ) {
641
721
let points = vec ! [
@@ -742,7 +822,7 @@ mod tests {
742
822
743
823
assert_eq ! ( facets. len( ) , 4 ) ;
744
824
for facet in facets. iter ( ) {
745
- assert ! ( cell. contains_facet ( facet . clone ( ) ) ) ;
825
+ assert ! ( cell. facets ( ) . contains ( facet ) )
746
826
}
747
827
748
828
// Human readable output for cargo test -- --nocapture
0 commit comments