Skip to content

Commit

Permalink
applied changes throughout all tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
josfeenstra committed Nov 3, 2023
1 parent e26cf04 commit a81a0e4
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 204 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ You can read the complete documentation [here](https://docs.rs/startin)
```rust
extern crate startin;
fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
let mut pts = Vec::new();
pts.push([20.0, 30.0, 2.0]);
pts.push([120.0, 33.0, 12.5]);
pts.push([124.0, 222.0, 7.65]);
Expand Down
2 changes: 1 addition & 1 deletion examples/example1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn read_xyz_file() -> Result<Vec<[f64; 3]>, Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
.delimiter(b' ')
.from_reader(io::stdin());
let mut vpts: Vec<[f64; 3]> = Vec::new();
let mut vpts = Vec::new();
for result in rdr.deserialize() {
let record: CSVPoint = result?;
vpts.push([record.x, record.y, record.z]);
Expand Down
8 changes: 4 additions & 4 deletions examples/example10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ fn main() {
// println!("Duplicates? none.\n");
// }

let _re = dt.insert(&vec, startin::InsertionStrategy::AsIs);
let _re = dt.insert(vec, startin::InsertionStrategy::AsIs);
// let _re = dt.insert(&vec, Some(vec![434366.0, 19722.0, 900289.0, 337914.0]));
println!("{}", dt);
}

fn read_xyz_file() -> Result<Vec<[f64; 3]>, Box<dyn Error>> {
fn read_xyz_file() -> Result<Vec<(f64, f64, f64)>, Box<dyn Error>> {
let mut rdr = csv::ReaderBuilder::new()
.delimiter(b' ')
.from_reader(io::stdin());
let mut vpts: Vec<[f64; 3]> = Vec::new();
let mut vpts = Vec::new();
for result in rdr.deserialize() {
let record: CSVPoint = result?;
if record.z != -9999.0 {
vpts.push([record.x, record.y, record.z]);
vpts.push((record.x, record.y, record.z));
}
}
Ok(vpts)
Expand Down
22 changes: 11 additions & 11 deletions examples/example11.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([1.1, 1.07, 12.5]);
pts.push([11.0, 1.02, 7.65]);
pts.push([11.05, 11.1, 33.0]);
pts.push([1.0, 11.0, 21.0]);
pts.push([9.0, 5.0, 21.0]);
pts.push([12.0, 5.1, 21.0]);
pts.push([8.0, 8.0, 21.0]);
pts.push([12.0, 8.1, 21.0]);
pts.push([4.0, 5.15, 33.0]);
let mut pts = Vec::new();
pts.push((1.1, 1.07, 12.5));
pts.push((11.0, 1.02, 7.65));
pts.push((11.05, 11.1, 33.0));
pts.push((1.0, 11.0, 21.0));
pts.push((9.0, 5.0, 21.0));
pts.push((12.0, 5.1, 21.0));
pts.push((8.0, 8.0, 21.0));
pts.push((12.0, 8.1, 21.0));
pts.push((4.0, 5.15, 33.0));

let mut dt = startin::Triangulation::new();
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);

let mut _re = dt.remove(7);
_re = dt.remove(2);
Expand Down
18 changes: 9 additions & 9 deletions examples/example2.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([20 as f64, 30.0, 0.0]);
pts.push([20 as f64, 30.0, 1.1]);
pts.push([120.0, 33.0, 12.5]);
pts.push([124.0, 222.0, 7.65]);
pts.push([20.0, 133.0, 21.0]);
pts.push([60.0, 60.0, 33.0]);
let mut pts = Vec::new();
pts.push((20 as f64, 30.0, 0.0));
pts.push((20 as f64, 30.0, 1.1));
pts.push((120.0, 33.0, 12.5));
pts.push((124.0, 222.0, 7.65));
pts.push((20.0, 133.0, 21.0));
pts.push((60.0, 60.0, 33.0));

let mut dt = startin::Triangulation::new();
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);

println!("*****");
println!("Number of points in DT: {}", dt.number_of_vertices());
Expand All @@ -20,7 +20,7 @@ fn main() {
for (i, each) in dt.all_vertices().iter().enumerate() {
// skip the first one, the infinite vertex
if i > 0 {
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each[0], each[1], each[2]);
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each.0, each.1, each.2);
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/example4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use rand::prelude::*;

fn main() {
let num_pts = 1000;
let mut pts: Vec<[f64; 3]> = Vec::new();
let mut pts = Vec::new();

let mut rng = rand::thread_rng();
for _i in 0..num_pts {
let x: f64 = rng.gen();
let y: f64 = rng.gen();
pts.push([x * 100.0, y * 100.0, 2.0]);
pts.push((x * 100.0, y * 100.0, 2.0));
}

let mut dt = startin::Triangulation::new();
dt.set_jump_and_walk(false);
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);
println!("{}", dt.printme(false));

//-- delete 5 vertices on convex hull
Expand Down
18 changes: 9 additions & 9 deletions examples/example5.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([0.0, 0.0, 12.5]);
pts.push([1.0, 0.0, 7.65]);
pts.push([1.1, 1.1, 33.0]);
pts.push([0.0, 1.0, 33.0]);
pts.push([0.5, 0.9, 33.0]);
pts.push([0.9, 0.5, 33.0]);
pts.push([0.67, 0.66, 33.0]);
let mut pts = Vec::new();
pts.push((0.0, 0.0, 12.5));
pts.push((1.0, 0.0, 7.65));
pts.push((1.1, 1.1, 33.0));
pts.push((0.0, 1.0, 33.0));
pts.push((0.5, 0.9, 33.0));
pts.push((0.9, 0.5, 33.0));
pts.push((0.67, 0.66, 33.0));
let mut dt = startin::Triangulation::new();
dt.set_jump_and_walk(false);
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);
println!("{}", dt.printme(true));

// let _re = dt.remove(3);
Expand Down
8 changes: 4 additions & 4 deletions examples/example7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ fn main() {
break;
}
let num_pts = 20;
let mut pts: Vec<[f64; 3]> = Vec::new();
let mut pts = Vec::new();

let mut rng = rand::thread_rng();
for _i in 0..num_pts {
let x: f64 = rng.gen();
let y: f64 = rng.gen();
pts.push([x * 100.0, y * 100.0, 2.0]);
pts.push((x * 100.0, y * 100.0, 2.0));
}

let mut dt = startin::Triangulation::new();
dt.set_jump_and_walk(false);
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts.clone(), startin::InsertionStrategy::AsIs);
// println!("{}", dt.printme(false));

loop {
Expand All @@ -28,7 +28,7 @@ fn main() {
let _re = dt.remove(j);
if dt.is_valid() == false {
for p in pts {
println!("{} {} {}", p[0], p[1], p[2]);
println!("{} {} {}", p.0, p.1, p.2);
// s.push_str(&format!("\t{:?}\n", self.stars[i].pt));
}
println!("vertex === {}", j);
Expand Down
30 changes: 15 additions & 15 deletions examples/example9.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([0.0, 0.0, 0.125]);
pts.push([0.0, 0.0, 0.1111]);
pts.push([1.0, 0.0, 0.2222]);
pts.push([1.0, 1.0, 0.3333]);
pts.push([0.0, 1.0, 0.440]);
pts.push([0.5, 0.49, 0.440]);
pts.push([0.45, 0.69, 0.440]);
pts.push([0.65, 0.49, 0.440]);
pts.push([0.75, 0.29, 0.440]);
pts.push([1.5, 1.49, 0.440]);
pts.push([0.6, 0.2, 0.440]);
pts.push([0.45, 0.4, 0.440]);
pts.push([0.1, 0.8, 0.440]);
let mut pts = Vec::new();
pts.push((0.0, 0.0, 0.125));
pts.push((0.0, 0.0, 0.1111));
pts.push((1.0, 0.0, 0.2222));
pts.push((1.0, 1.0, 0.3333));
pts.push((0.0, 1.0, 0.440));
pts.push((0.5, 0.49, 0.440));
pts.push((0.45, 0.69, 0.440));
pts.push((0.65, 0.49, 0.440));
pts.push((0.75, 0.29, 0.440));
pts.push((1.5, 1.49, 0.440));
pts.push((0.6, 0.2, 0.440));
pts.push((0.45, 0.4, 0.440));
pts.push((0.1, 0.8, 0.440));

let mut dt = startin::Triangulation::new();

dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);

// let re = dt.interpolate_nn(2., 1.);
// let re = dt.interpolate_nn(11., 11.);
Expand Down
2 changes: 1 addition & 1 deletion examples/geotiff2tin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
// println!("rasterband y-size: {:?}", rasterband.y_size());
// println!("no_data: {:?}", rasterband.no_data_value());

// let mut pts: Vec<[f64; 3]> = Vec::new();
// let mut pts = Vec::new();

// let nodatavalue = rasterband.no_data_value().unwrap();
// let xsize = rasterband.x_size();
Expand Down
16 changes: 8 additions & 8 deletions examples/readme_snippet.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
extern crate startin;

fn main() {
let mut pts: Vec<[f64; 3]> = Vec::new();
pts.push([20.0, 30.0, 2.0]);
pts.push([120.0, 33.0, 12.5]);
pts.push([124.0, 222.0, 7.65]);
pts.push([20.0, 133.0, 21.0]);
pts.push([60.0, 60.0, 33.0]);
let mut pts: Vec<(f64, f64, f64)> = Vec::new();
pts.push((20.0, 30.0, 2.0));
pts.push((120.0, 33.0, 12.5));
pts.push((124.0, 222.0, 7.65));
pts.push((20.0, 133.0, 21.0));
pts.push((60.0, 60.0, 33.0));
let mut dt = startin::Triangulation::new();
dt.insert(&pts, startin::InsertionStrategy::AsIs);
dt.insert(pts, startin::InsertionStrategy::AsIs);
println!("{}", dt);
//-- print all the vertices
for (i, each) in dt.all_vertices().iter().enumerate() {
// skip the first one, the infinite vertex
if i > 0 {
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each[0], each[1], each[2]);
println!("#{}: ({:.3}, {:.3}, {:.3})", i, each.0, each.1, each.2);
}
}
//-- insert a new vertex
Expand Down
Loading

0 comments on commit a81a0e4

Please sign in to comment.