Skip to content

Commit e6fdde7

Browse files
committed
Fix example
1 parent fafdc12 commit e6fdde7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

examples/ex.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
use contour::ContourBuilder;
1+
use contour::{ContourBuilder, Float};
22
use geojson::{FeatureCollection, GeoJson};
33
use std::fs::File;
44
use std::io::{BufWriter, Write};
55

66
fn main() {
77
let pot_pop_fr = include_str!("../tests/fixtures/pot_pop_fr.json");
88
let raw_data: serde_json::Value = serde_json::from_str(pot_pop_fr).unwrap();
9-
let matrix: Vec<f64> = raw_data["data"]
9+
let matrix: Vec<Float> = raw_data["data"]
1010
.as_array()
1111
.unwrap()
1212
.iter()
13-
.map(|x| x.as_f64().unwrap())
13+
.map(|x| {
14+
#[cfg(not(feature = "f32"))]
15+
{
16+
x.as_f64().unwrap()
17+
}
18+
#[cfg(feature = "f32")]
19+
{
20+
x.as_f64().unwrap() as f32
21+
}
22+
})
1423
.collect();
1524
let h = raw_data["height"].as_u64().unwrap() as u32;
1625
let w = raw_data["width"].as_u64().unwrap() as u32;
@@ -51,11 +60,20 @@ fn main() {
5160

5261
let volcano = include_str!("../tests/fixtures/volcano.json");
5362
let raw_data: serde_json::Value = serde_json::from_str(volcano).unwrap();
54-
let matrix: Vec<f64> = raw_data["data"]
63+
let matrix: Vec<Float> = raw_data["data"]
5564
.as_array()
5665
.unwrap()
5766
.iter()
58-
.map(|x| x.as_f64().unwrap())
67+
.map(|x| {
68+
#[cfg(not(feature = "f32"))]
69+
{
70+
x.as_f64().unwrap()
71+
}
72+
#[cfg(feature = "f32")]
73+
{
74+
x.as_f64().unwrap() as f32
75+
}
76+
})
5977
.collect();
6078
let h = raw_data["height"].as_u64().unwrap() as u32;
6179
let w = raw_data["width"].as_u64().unwrap() as u32;

0 commit comments

Comments
 (0)