Skip to content

Commit

Permalink
chore: consolidate imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed May 30, 2024
1 parent e798774 commit 6ea2f27
Show file tree
Hide file tree
Showing 22 changed files with 205 additions and 101 deletions.
78 changes: 78 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Auto"
indent_style = "Block"
use_small_heuristics = "Default"
fn_call_width = 60
attr_fn_like_width = 70
struct_lit_width = 18
struct_variant_width = 35
array_width = 60
chain_width = 60
single_line_if_else_max_width = 50
single_line_let_else_max_width = 50
wrap_comments = false
format_code_in_doc_comments = false
doc_comment_code_block_width = 100
comment_width = 80
normalize_comments = false
normalize_doc_attributes = false
format_strings = false
format_macro_matchers = false
format_macro_bodies = true
skip_macro_invocations = []
hex_literal_case = "Preserve"
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Mixed"
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Front"
remove_nested_parens = true
combine_control_expr = true
short_array_element_width_threshold = 10
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
match_arm_leading_pipes = "Never"
force_multiline_blocks = false
fn_params_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2015"
version = "One"
inline_attribute_width = 0
format_generated_files = true
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Auto"
required_version = "1.7.0"
unstable_features = false
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
error_on_line_overflow = false
error_on_unformatted = false
ignore = []
emit_mode = "Files"
make_backup = false
14 changes: 9 additions & 5 deletions src/compression/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use crate::error::Error;
use crate::reader::{read_point_from, PointReader};
use crate::writer::{write_header_and_vlrs_to, write_point_to, PointWriter};
use crate::{Header, Point, Result, Vlr};
use laz::las::laszip::LazVlr;
use std::fmt::Debug;
/// Module with functions and structs specific to brigde the las crate and laz crate to allow
/// writing & reading LAZ data
use std::io::{Cursor, Read, Seek, SeekFrom, Write};

use laz::las::laszip::LazVlr;

use crate::{
error::Error,
reader::{read_point_from, PointReader},
writer::{write_header_and_vlrs_to, write_point_to, PointWriter},
Header, Point, Result, Vlr,
};

fn is_laszip_vlr(vlr: &Vlr) -> bool {
vlr.user_id == LazVlr::USER_ID && vlr.record_id == LazVlr::RECORD_ID
}
Expand Down
7 changes: 4 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{header, point, reader, vlr, writer, Transform, Version};
use std::io;
use std::str;
use std::{io, str};

use thiserror::Error;

use crate::{header, point, reader, vlr, writer, Transform, Version};

/// Crate-specific error enum.
#[derive(Error, Debug)]
pub enum Error {
Expand Down
17 changes: 11 additions & 6 deletions src/header/builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::header::Error;
use crate::point::Format;
use crate::{raw, Bounds, GpsTimeType, Header, Result, Transform, Vector, Version, Vlr};
use chrono::NaiveDate;
use std::{cmp::Ordering, collections::HashMap};

use chrono::NaiveDate;
use uuid::Uuid;

use crate::{
header::Error, point::Format, raw, Bounds, GpsTimeType, Header, Result, Transform, Vector,
Version, Vlr,
};

/// Builds headers.
#[derive(Clone, Debug, Default)]
pub struct Builder {
Expand Down Expand Up @@ -173,8 +176,10 @@ impl Builder {
/// let header = Builder::new(Default::default()).unwrap().into_header().unwrap();
/// ```
pub fn into_header(mut self) -> Result<Header> {
use crate::feature::{Evlrs, FileSourceId, GpsStandardTime, SyntheticReturnNumbers};
use crate::raw::POINT_DATA_START_SIGNATURE;
use crate::{
feature::{Evlrs, FileSourceId, GpsStandardTime, SyntheticReturnNumbers},
raw::POINT_DATA_START_SIGNATURE,
};

let n = self.vlr_padding.len();
if self.version.requires_point_data_start_signature()
Expand Down
18 changes: 9 additions & 9 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,17 @@
//! assert_eq!(b"LASF", &raw_header.file_signature);
//! ```

use std::collections::HashMap;
use std::iter::Chain;
use std::slice::Iter;
use std::{collections::HashMap, iter::Chain, slice::Iter};

use chrono::{Datelike, NaiveDate, Utc};
use thiserror::Error;
use uuid::Uuid;

use crate::point::Format;
use crate::utils::FromLasStr;
use crate::{raw, Bounds, GpsTimeType, Point, Result, Transform, Vector, Version, Vlr};

pub use self::builder::Builder;
use crate::{
point::Format, raw, utils::FromLasStr, Bounds, GpsTimeType, Point, Result, Transform, Vector,
Version, Vlr,
};

mod builder;

Expand Down Expand Up @@ -605,9 +603,10 @@ impl Header {
}

fn number_of_points_raw(&self) -> Result<u32> {
use crate::feature::LargeFiles;
use std::u32;

use crate::feature::LargeFiles;

if self.number_of_points > u64::from(u32::MAX) {
if self.version.supports::<LargeFiles>() {
Ok(0)
Expand All @@ -624,9 +623,10 @@ impl Header {
}

fn number_of_points_by_return_raw(&self) -> Result<[u32; 5]> {
use crate::feature::LargeFiles;
use std::u32;

use crate::feature::LargeFiles;

let mut number_of_points_by_return = [0; 5];
for (&i, &n) in &self.number_of_points_by_return {
if i > 5 {
Expand Down
28 changes: 15 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,21 @@ mod utils;
mod vector;
mod version;

pub use crate::bounds::Bounds;
pub use crate::color::Color;
pub use crate::error::Error;
pub use crate::feature::Feature;
pub use crate::gps_time_type::GpsTimeType;
pub use crate::header::{Builder, Header};
pub use crate::point::Point;
pub use crate::reader::{Read, Reader};
pub use crate::transform::Transform;
pub use crate::vector::Vector;
pub use crate::version::Version;
pub use crate::vlr::Vlr;
pub use crate::writer::{Write, Writer};
pub use crate::{
bounds::Bounds,
color::Color,
error::Error,
feature::Feature,
gps_time_type::GpsTimeType,
header::{Builder, Header},
point::Point,
reader::{Read, Reader},
transform::Transform,
vector::Vector,
version::Version,
vlr::Vlr,
writer::{Write, Writer},
};

/// Crate-specific result type.
pub type Result<T> = std::result::Result<T, Error>;
Expand Down
3 changes: 1 addition & 2 deletions src/point/classification.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::point::Error;
use crate::Result;
use crate::{point::Error, Result};

/// The ASPRS classification table.
///
Expand Down
3 changes: 1 addition & 2 deletions src/point/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fmt;

use crate::point::Error;
use crate::Result;
use crate::{point::Error, Result};

const TIME_FORMATS: &[u8] = &[1, 3, 4, 5, 6, 7, 8, 9, 10];
const COLOR_FORMATS: &[u8] = &[2, 3, 5, 7, 8, 10];
Expand Down
10 changes: 3 additions & 7 deletions src/point/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ mod classification;
mod format;
mod scan_direction;

pub use self::classification::Classification;
pub use self::format::Format;
pub use self::scan_direction::ScanDirection;

use crate::raw;
use crate::raw::point::Waveform;
use crate::{Color, Result, Transform, Vector};
use thiserror::Error;

pub use self::{classification::Classification, format::Format, scan_direction::ScanDirection};
use crate::{raw, raw::point::Waveform, Color, Result, Transform, Vector};

/// Point-specific errors
#[derive(Debug, Clone, Copy, Error)]
pub enum Error {
Expand Down
21 changes: 13 additions & 8 deletions src/raw/header.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
//! Raw file metadata.

use crate::feature::{Evlrs, LargeFiles, Waveforms};
use crate::raw::LASF;
use crate::{Result, Version};
use byteorder::{LittleEndian, ReadBytesExt};
use std::io::{Read, Write};

use byteorder::{LittleEndian, ReadBytesExt};

use crate::{
feature::{Evlrs, LargeFiles, Waveforms},
raw::LASF,
Result, Version,
};

/// A las header.
///
/// The documentation for each member is taken directly from the las 1.2 spec, except in cases
Expand Down Expand Up @@ -253,8 +257,7 @@ impl Header {
/// let header = Header::read_from(&mut file).unwrap();
/// ```
pub fn read_from<R: Read>(mut read: R) -> Result<Header> {
use crate::header::Error;
use crate::utils;
use crate::{header::Error, utils};

let mut header = Header::default();
read.read_exact(&mut header.file_signature)?;
Expand Down Expand Up @@ -504,9 +507,10 @@ impl LargeFile {

#[cfg(test)]
mod tests {
use super::*;
use std::io::Cursor;

use super::*;

fn write_read(header: Header) -> Result<()> {
let mut cursor = Cursor::new(Vec::new());
header.write_to(&mut cursor).unwrap();
Expand Down Expand Up @@ -559,9 +563,10 @@ mod tests {
mod $name {
#[test]
fn roundtrip() {
use super::*;
use std::io::Cursor;

use super::*;

let version = Version::new(1, $minor);
let mut header = Header {
version,
Expand Down
4 changes: 1 addition & 3 deletions src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ pub mod header;
pub mod point;
pub mod vlr;

pub use self::header::Header;
pub use self::point::Point;
pub use self::vlr::Vlr;
pub use self::{header::Header, point::Point, vlr::Vlr};

/// The file magic number used for all las files.
pub const LASF: [u8; 4] = *b"LASF";
Expand Down
13 changes: 9 additions & 4 deletions src/raw/point.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//! Defines raw las points and some enums required to handle the various point formats.

use crate::point::{Classification, Error, Format, ScanDirection};
use crate::{Color, Result};
use std::io::{Read, Write};

use crate::{
point::{Classification, Error, Format, ScanDirection},
Color, Result,
};

const SCAN_ANGLE_SCALE_FACTOR: f32 = 0.006;
const OVERLAP_CLASSIFICATION_CODE: u8 = 12;

Expand Down Expand Up @@ -355,9 +358,10 @@ impl Point {
/// ```
#[allow(clippy::field_reassign_with_default)]
pub fn read_from<R: Read>(mut read: R, format: &Format) -> Result<Point> {
use crate::utils;
use byteorder::{LittleEndian, ReadBytesExt};

use crate::utils;

let mut point = Point::default();
point.x = read.read_i32::<LittleEndian>()?;
point.y = read.read_i32::<LittleEndian>()?;
Expand Down Expand Up @@ -840,9 +844,10 @@ mod tests {
mod $name {
#[test]
fn roundtrip() {
use super::*;
use std::io::Cursor;

use super::*;

let mut format = Format::new($format).unwrap();
format.extra_bytes = 1;
let mut point = Point::default();
Expand Down
6 changes: 4 additions & 2 deletions src/raw/vlr.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Variable length records, both extended and regular.

use crate::Result;
use std::io::{Read, Write};

use crate::Result;

/// A raw variable length record.
#[derive(Debug, Default, PartialEq)]
pub struct Vlr {
Expand Down Expand Up @@ -137,9 +138,10 @@ impl Default for RecordLength {

#[cfg(test)]
mod tests {
use super::*;
use std::io::Cursor;

use super::*;

#[test]
fn roundtrip() {
let vlr = Vlr::default();
Expand Down
Loading

0 comments on commit 6ea2f27

Please sign in to comment.