Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benches/benchmark_utilities.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::fmt::{self, Display, Formatter};

use criterion::{measurement::WallTime, BenchmarkGroup, BenchmarkId, Throughput};
use rand::{distributions::uniform::SampleUniform, Rng, SeedableRng};
use rand::{distr::uniform::SampleUniform, Rng, SeedableRng};
use spade::{
DelaunayTriangulation, HierarchyHintGenerator, LastUsedVertexHintGenerator, Point2, SpadeNum,
Triangulation,
Expand All @@ -27,7 +27,7 @@ pub fn uniform_distribution<S: SpadeNum + SampleUniform>(
where
S::Sampler: Copy,
{
let range = rand::distributions::Uniform::new_inclusive(-range, range);
let range = rand::distr::Uniform::new_inclusive(-range, range).unwrap();
let mut rng = rand::rngs::StdRng::from_seed(seed);
core::iter::from_fn(move || Some(Point2::new(rng.sample(range), rng.sample(range))))
}
Expand All @@ -43,7 +43,7 @@ pub fn random_walk_distribution<S: SpadeNum + SampleUniform>(
where
S::Sampler: Copy,
{
let range = rand::distributions::Uniform::new_inclusive(-step_size, step_size);
let range = rand::distr::Uniform::new_inclusive(-step_size, step_size).unwrap();
let mut last_x = S::zero();
let mut last_y = S::one();

Expand Down
2 changes: 1 addition & 1 deletion benches/locate_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;

use criterion::{measurement::WallTime, BenchmarkGroup, Criterion};
use rand::distributions::uniform::SampleUniform;
use rand::distr::uniform::SampleUniform;
use spade::{
DelaunayTriangulation, HierarchyHintGeneratorWithBranchFactor, HintGenerator, Point2, SpadeNum,
Triangulation,
Expand Down
13 changes: 7 additions & 6 deletions delaunay_compare/examples/real_data_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ fn main() -> anyhow::Result<()> {
vertices.shrink_to_fit();
edges.shrink_to_fit();

load_with_spade(&vertices, &edges)?;
println!();

load_with_cdt_crate(&vertices, &edges)?;
println!();
load_with_spade(vertices, edges)?;

Ok(())
}

fn load_with_spade(vertices: &Vec<Point2<f64>>, edges: &Vec<[usize; 2]>) -> anyhow::Result<()> {
fn load_with_spade(vertices: Vec<Point2<f64>>, edges: Vec<[usize; 2]>) -> anyhow::Result<()> {
let vertices_clone = vertices.clone();
let edges_clone = edges.clone();

Expand Down Expand Up @@ -172,8 +171,10 @@ fn draw_to_pixmap(cdt: ConstrainedDelaunayTriangulation<Point2<f64>>) -> anyhow:
.post_scale(scale_x as f32, -scale_y as f32)
.post_translate(0.0, res_y as f32);

let mut stroke = Stroke::default();
stroke.width = 0.1 / scale_x as f32;
let mut stroke = Stroke {
width: 0.1 / scale_x as f32,
..Default::default()
};

let mut paint = Paint::default();

Expand Down
21 changes: 14 additions & 7 deletions examples/interpolation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const VERTICES: &[PointWithHeight] = &[
PointWithHeight::new(-10.0, 10.0, 0.0),
PointWithHeight::new(-10.0, -10.0, 0.1),
PointWithHeight::new(-15.0, 20.0, 0.5),
PointWithHeight::new(-20.0, 20.0, 0.0),
PointWithHeight::new(-5.0, 0.0, 0.25),
PointWithHeight::new(5.0, 7.0, 0.75),
PointWithHeight::new(12.0, -10.0, 0.4),
Expand All @@ -71,7 +70,9 @@ pub fn main() -> Result<()> {
let dimensions = 512;
let mut nn_c0_pixmap =
Pixmap::new(dimensions, dimensions).context("Failed to allocate image")?;
let mut nn_c1_pixmap =
let mut nn_c1_pixmap_1 =
Pixmap::new(dimensions, dimensions).context("Failed to allocate image")?;
let mut nn_c1_pixmap_05 =
Pixmap::new(dimensions, dimensions).context("Failed to allocate image")?;
let mut barycentric_pixmap =
Pixmap::new(dimensions, dimensions).context("Failed to allocate image")?;
Expand All @@ -92,15 +93,19 @@ pub fn main() -> Result<()> {
let nn = t.natural_neighbor();
let barycentric = t.barycentric();

let grads = nn.estimate_gradients(|v| v.data().height);

for y in 0..dimensions {
for x in 0..dimensions {
let coords = px_to_coords(x, y);
let value_nn_c0 = nn.interpolate(|v| v.data().height, coords);
set_pixel(&mut nn_c0_pixmap, x, y, value_nn_c0);

let value_nn_c1 =
nn.interpolate_gradient(|v| v.data().height, |_| [0.0, 0.0], 1.0, coords);
set_pixel(&mut nn_c1_pixmap, x, y, value_nn_c1);
let value_nn_c1_1 = nn.interpolate_gradient(|v| v.data().height, &grads, 1.0, coords);
set_pixel(&mut nn_c1_pixmap_1, x, y, value_nn_c1_1);

let value_nn_c1_05 = nn.interpolate_gradient(|v| v.data().height, &grads, 0.5, coords);
set_pixel(&mut nn_c1_pixmap_05, x, y, value_nn_c1_05);

let value_barycentric = barycentric.interpolate(|v| v.data().height, coords);
set_pixel(&mut barycentric_pixmap, x, y, value_barycentric);
Expand Down Expand Up @@ -133,7 +138,8 @@ pub fn main() -> Result<()> {

for pixmap in [
&mut nn_c0_pixmap,
&mut nn_c1_pixmap,
&mut nn_c1_pixmap_1,
&mut nn_c1_pixmap_05,
&mut barycentric_pixmap,
&mut nearest_neighbor_pixmap,
] {
Expand Down Expand Up @@ -170,7 +176,8 @@ pub fn main() -> Result<()> {
}

save_pixmap(nn_c0_pixmap, "interpolation_nn_c0")?;
save_pixmap(nn_c1_pixmap, "interpolation_nn_c1")?;
save_pixmap(nn_c1_pixmap_1, "interpolation_nn_c1_flatness_1")?;
save_pixmap(nn_c1_pixmap_05, "interpolation_nn_c1_flatness_05")?;
save_pixmap(barycentric_pixmap, "interpolation_barycentric")?;
save_pixmap(nearest_neighbor_pixmap, "interpolation_nearest_neighbor")?;

Expand Down
2 changes: 1 addition & 1 deletion images/interpolation_barycentric.img

Large diffs are not rendered by default.

Binary file modified images/interpolation_barycentric.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/interpolation_nearest_neighbor.img

Large diffs are not rendered by default.

Binary file modified images/interpolation_nearest_neighbor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/interpolation_nn_c0.img

Large diffs are not rendered by default.

Binary file modified images/interpolation_nn_c0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion images/interpolation_nn_c1.img

This file was deleted.

Binary file removed images/interpolation_nn_c1.jpg
Binary file not shown.
1 change: 1 addition & 0 deletions images/interpolation_nn_c1_flatness_05.img

Large diffs are not rendered by default.

Binary file added images/interpolation_nn_c1_flatness_05.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions images/interpolation_nn_c1_flatness_1.img

Large diffs are not rendered by default.

Binary file added images/interpolation_nn_c1_flatness_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/cdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ mod test {

assert_eq!(cdt.num_vertices(), initial_num_vertices + 1);
assert_eq!(edges.len(), 2);
check_returned_edges(&mut cdt, &edges, from, to);
check_returned_edges(&cdt, &edges, from, to);

Ok(())
}
Expand All @@ -2021,7 +2021,7 @@ mod test {
// 3 new points should be added as the constraint intersects all 3 existing edges
assert_eq!(cdt.num_vertices(), initial_num_vertices + 3);
assert_eq!(edges.len(), 4);
check_returned_edges(&mut cdt, &edges, from, to);
check_returned_edges(&cdt, &edges, from, to);

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/bulk_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ impl Hull {

const INVALID: usize = usize::MAX;
self.buckets
.extend(core::iter::repeat(INVALID).take(target_size));
.extend(core::iter::repeat_n(INVALID, target_size));

let (first_index, current_node) = self
.data
Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/hint_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use alloc::vec::Vec;
/// fulfill most needs:
/// - A heuristic that uses the last inserted vertex as hint ([LastUsedVertexHintGenerator])
/// - A hint generator based on a hierarchy of triangulations that improves walk time to `O(log(n))`
/// ([HierarchyHintGenerator])
/// ([HierarchyHintGenerator])
pub trait HintGenerator<S: SpadeNum>: Default {
/// Returns a vertex handle that should be close to a given position.
///
Expand Down
Loading
Loading