-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes some edge cases for regular DT bulk loading.
- Loading branch information
Showing
14 changed files
with
826 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![no_main] | ||
mod fuzz_shared; | ||
use fuzz_shared::FuzzPoint; | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
use spade::{ConstrainedDelaunayTriangulation, HasPosition, Triangulation}; | ||
|
||
fuzz_target!(|input: (Vec<FuzzPoint>, Vec<[usize; 2]>)| { | ||
let (data, mut edges) = input; | ||
for p in &data { | ||
if spade::validate_coordinate(p.x).is_err() || spade::validate_coordinate(p.y).is_err() { | ||
return; | ||
} | ||
if p.x.abs() > 20.0 || p.y.abs() > 20.0 { | ||
return; | ||
} | ||
} | ||
|
||
for &[from, to] in &edges { | ||
if from >= data.len() || to >= data.len() || from == to { | ||
return; | ||
} | ||
} | ||
|
||
let mut reference_cdt = | ||
ConstrainedDelaunayTriangulation::<FuzzPoint>::bulk_load(data.clone()).unwrap(); | ||
|
||
let mut last_index = 0; | ||
for (index, [from, to]) in edges.iter().copied().enumerate() { | ||
let from = reference_cdt | ||
.locate_vertex(data[from].position()) | ||
.unwrap() | ||
.fix(); | ||
let to = reference_cdt | ||
.locate_vertex(data[to].position()) | ||
.unwrap() | ||
.fix(); | ||
|
||
if reference_cdt.can_add_constraint(from, to) { | ||
reference_cdt.add_constraint(from, to); | ||
} else { | ||
last_index = index; | ||
break; | ||
} | ||
} | ||
|
||
edges.truncate(last_index); | ||
|
||
let bulk_loaded = | ||
ConstrainedDelaunayTriangulation::<FuzzPoint>::bulk_load_cdt(data, edges).unwrap(); | ||
|
||
bulk_loaded.cdt_sanity_check(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use spade::{HasPosition, Point2}; | ||
|
||
#[derive(Clone, Copy, arbitrary::Arbitrary)] | ||
pub struct FuzzPoint { | ||
pub x: f64, | ||
pub y: f64, | ||
} | ||
|
||
impl HasPosition for FuzzPoint { | ||
type Scalar = f64; | ||
fn position(&self) -> Point2<f64> { | ||
Point2::new(self.x, self.y) | ||
} | ||
} | ||
|
||
impl core::fmt::Debug for FuzzPoint { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
f.write_fmt(format_args!("Point2::new({:?}, {:?})", self.x, self.y)) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.