Skip to content

Commit

Permalink
Trying out using Spade
Browse files Browse the repository at this point in the history
Seems nice and featureful, but now having strange issues with Kani. And of course output is a whole 'nother thing.

Commented out original source code in case I need to back out.

CI Kani is going to fail.
  • Loading branch information
acgetchell committed Sep 18, 2023
1 parent 2a6616a commit 8542cf4
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 218 deletions.
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ readme = "README.md"
clap = { version = "4.4.3", features = ["derive"] }
float-ord = "0.3.2"
rand = "0.8.5"
spade = { version = "2.2.0", features = ["serde"] }

[dev-dependencies]
assert_cmd = "2.0.12"
Expand Down
195 changes: 0 additions & 195 deletions src/delaunay.rs

This file was deleted.

54 changes: 34 additions & 20 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use clap::Parser;
use spade::InsertionError;
use spade::Triangulation;

pub mod delaunay;
pub mod triangulation;

pub mod utilities;

Expand All @@ -26,7 +28,10 @@ impl Config {
}
}

pub fn run(config: Config) -> Result<Vec<delaunay::Triangle>, Box<dyn std::error::Error>> {
// pub fn run(config: Config) -> Result<Vec<triangulation::Triangle>, Box<dyn std::error::Error>> {
pub fn run(
config: &Config,
) -> Result<spade::DelaunayTriangulation<spade::Point2<f64>>, InsertionError> {
let vertices = config.vertices;
let timeslices = config.timeslices;

Expand All @@ -39,29 +44,35 @@ pub fn run(config: Config) -> Result<Vec<delaunay::Triangle>, Box<dyn std::error
println!("Number of vertices: {}", vertices);
println!("Number of timeslices: {}", timeslices);

let scale = 10.0; // The size of the grid
let mut points = Vec::new();
let triangulation = triangulation::generate_random_delaunay2(vertices)?;

for _n in 1..vertices {
let x = utilities::generate_random_float() * scale;
let y = utilities::generate_random_float() * scale;
points.push(delaunay::Point { x, y });
}
// let scale = 10.0; // The size of the grid
// let mut points = Vec::new();

let triangulation = delaunay::bowyer_watson(points);
for triangle in &triangulation {
println!(
"Triangle: {:?} Center: {:?}",
triangle.vertices,
triangle.center()
);
// for _n in 1..vertices {
// let x = utilities::generate_random_float() * scale;
// let y = utilities::generate_random_float() * scale;
// points.push(triangulation::Point { x, y });
// }

// let triangulation = triangulation::bowyer_watson(points);
// for triangle in &triangulation {
// println!(
// "Triangle: {:?} Center: {:?}",
// triangle.vertices,
// triangle.center()
// );
// }

for vertex in triangulation.fixed_vertices() {
println!("Vertex: {:?}", vertex);
}

Ok(triangulation)
}

#[cfg(test)]
mod tests {
mod lib_tests {
use super::*;
#[test]
fn test_run() {
Expand All @@ -71,7 +82,7 @@ mod tests {
timeslices: 3,
};
assert!(config.dimension.is_some());
assert!(run(config).is_ok());
assert!(run(&config).is_ok());
}

#[test]
Expand All @@ -81,7 +92,10 @@ mod tests {
vertices: 32,
timeslices: 3,
};
let triangulation = run(config).unwrap();
assert!(triangulation.len() > 42);
let triangulation = run(&config).unwrap();
assert_eq!(
triangulation.num_vertices(),
config.vertices.try_into().unwrap()
);
}
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use cdt_rs::Config;
fn main() {
let config = Config::build();

if let Err(e) = cdt_rs::run(config) {
if let Err(e) = cdt_rs::run(&config) {
eprintln!("Application error: {}", e);
std::process::exit(1);
}
Expand Down
Loading

0 comments on commit 8542cf4

Please sign in to comment.