Skip to content

Commit b417e7d

Browse files
authored
Merge pull request #7 from nivalis-studio/refactor-string-path
2 parents af7284d + a2a1a33 commit b417e7d

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/convert_file.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
extern crate rayon;
22
use rayon::prelude::*;
3+
use std::path::Path;
34

45
use anyhow::{Context, Result};
56

@@ -59,7 +60,7 @@ pub fn convert_file(
5960
.try_for_each(|(index, pointcloud)| -> Result<()> {
6061
println!("Saving pointcloud {}...", index);
6162

62-
convert_pointcloud(index, pointcloud, &input_path, &output_path, &las_version)
63+
convert_pointcloud(index, pointcloud, Path::new(&input_path), Path::new(&output_path), &las_version)
6364
.context(format!("Error while converting pointcloud {}", index))?;
6465

6566
Ok(())
@@ -68,7 +69,7 @@ pub fn convert_file(
6869

6970
save_stations(output_path, pointclouds)?;
7071
} else {
71-
convert_pointclouds(e57_reader, &output_path, &las_version)
72+
convert_pointclouds(e57_reader, Path::new(&output_path), &las_version)
7273
.context("Error during the parallel processing of pointclouds")?;
7374
}
7475
Ok(())

src/convert_pointcloud.rs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ use rayon::prelude::*;
2323
///
2424
/// # Example
2525
/// ```ignore
26-
/// use e57_to_las::convert_pointcloud;
27-
/// let pointcloud = e57::Pointcloud { };
28-
/// let input_path = String::from("path/to/input.e57");
29-
/// let output_path = String::from("path/to/output");
30-
/// convert_pointcloud(0, &pointcloud, input_path, output_path);
26+
/// use std::path::Path;
27+
/// use e57_to_las::{convert_pointcloud, LasVersion};
28+
///
29+
/// # fn example() -> anyhow::Result<()> {
30+
/// let input_path = Path::new("path/to/input.e57");
31+
/// let output_path = Path::new("path/to/output");
32+
/// let las_version = LasVersion::new(1, 4)?;
33+
/// // pointcloud would be obtained from E57Reader in practice
34+
/// # let pointcloud = todo!();
35+
/// convert_pointcloud(0, &pointcloud, input_path, output_path, &las_version)?;
36+
/// # Ok(())
37+
/// # }
3138
/// ```
3239
pub fn convert_pointcloud(
3340
index: usize,
3441
pointcloud: &PointCloud,
35-
input_path: &String,
36-
output_path: &String,
42+
input_path: &Path,
43+
output_path: &Path,
3744
las_version: &LasVersion,
3845
) -> Result<()> {
3946
let mut e57_reader = E57Reader::from_file(input_path).context("Failed to open e57 file: ")?;
@@ -69,7 +76,7 @@ pub fn convert_pointcloud(
6976
let max_cartesian = max_x.max(max_y).max(max_z);
7077

7178
let path = create_path(
72-
Path::new(&output_path)
79+
output_path
7380
.join("las")
7481
.join(format!("{}{}", index, ".las")),
7582
)
@@ -104,14 +111,22 @@ pub fn convert_pointcloud(
104111
///
105112
/// # Example
106113
/// ```ignore
107-
/// use e57_to_las::convert_pointclouds;
108-
/// let e57_reader = e57::E57Reader::from_file("path/to/input.e56").context("Failed to open e57 file")?;
109-
/// let output_path = String::from("path/to/output");
110-
/// convert_pointclouds(e57_reader, output_path);
114+
/// use std::path::Path;
115+
/// use e57_to_las::{convert_pointclouds, LasVersion};
116+
/// use anyhow::Context;
117+
///
118+
/// # fn example() -> anyhow::Result<()> {
119+
/// let input_path = Path::new("path/to/input.e57");
120+
/// let e57_reader = e57::E57Reader::from_file(input_path).context("Failed to open e57 file")?;
121+
/// let output_path = Path::new("path/to/output");
122+
/// let las_version = LasVersion::new(1, 4)?;
123+
/// convert_pointclouds(e57_reader, output_path, &las_version)?;
124+
/// # Ok(())
125+
/// # }
111126
/// ```
112127
pub fn convert_pointclouds(
113128
e57_reader: E57Reader<BufReader<File>>,
114-
output_path: &String,
129+
output_path: &Path,
115130
las_version: &LasVersion,
116131
) -> Result<()> {
117132
let pointclouds = e57_reader.pointclouds();
@@ -164,7 +179,7 @@ pub fn convert_pointclouds(
164179
.context("Error while converting pointcloud")?;
165180

166181
let path = create_path(
167-
Path::new(&output_path)
182+
output_path
168183
.join("las")
169184
.join(format!("{}{}", 0, ".las")),
170185
)

0 commit comments

Comments
 (0)