Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt, clippy, version updates #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ travis-ci = { repository = "Turbo87/aeroscore-rs", branch = "master" }
default = ["rayon"]

[dependencies]
cfg-if = "0.1"
cfg-if = "1.0"
failure = "^0.1.1"
flat_projection = "0.3.0"
flat_projection = "0.4.0"
log = "0.4.8"
ord_subset = "^3.1.0"
rayon = { version = "^1.0", optional = true }
Expand All @@ -28,7 +28,7 @@ rayon = { version = "^1.0", optional = true }
assert_approx_eq = "^1.0.0"
criterion = "^0.3.0"
igc = "0.2.2"
env_logger = "0.7.1"
env_logger = "0.8.3"
serde_json = "^1.0.0"

[[bench]]
Expand Down
16 changes: 12 additions & 4 deletions benches/haversine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate criterion;
extern crate aeroscore;
extern crate igc;

use criterion::Criterion;
use aeroscore::haversine::haversine_distance;
use criterion::Criterion;

struct Point {
latitude: f32,
Expand All @@ -25,9 +25,17 @@ impl aeroscore::Point for Point {
}

fn criterion_benchmark(c: &mut Criterion) {
let point1 = Point { latitude: 51.301389, longitude: 6.953333 };
let point2 = Point { latitude: 50.823194, longitude: 6.186389 };
c.bench_function("haversine", |b| b.iter(|| haversine_distance(&point1, &point2)));
let point1 = Point {
latitude: 51.301389,
longitude: 6.953333,
};
let point2 = Point {
latitude: 50.823194,
longitude: 6.186389,
};
c.bench_function("haversine", |b| {
b.iter(|| haversine_distance(&point1, &point2))
});
}

criterion_group!(benches, criterion_benchmark);
Expand Down
35 changes: 20 additions & 15 deletions benches/olc_classic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ extern crate criterion;
extern crate aeroscore;
extern crate igc;

use criterion::Criterion;
use aeroscore::olc;
use criterion::Criterion;

struct Point {
latitude: f32,
Expand All @@ -26,20 +26,25 @@ impl aeroscore::Point for Point {
}

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("olc_classic", |b| b.iter(|| {
let fixes = include_str!("../tests/fixtures/2017-08-14-fla-6ng-01.igc")
.lines()
.filter(|l| l.starts_with('B'))
.filter_map(|line| igc::records::BRecord::parse(&line).ok()
.map(|record| Point {
latitude: record.pos.lat.into(),
longitude: record.pos.lon.into(),
altitude: record.pressure_alt,
}))
.collect::<Vec<_>>();

olc::optimize(&fixes).unwrap()
}));
c.bench_function("olc_classic", |b| {
b.iter(|| {
let fixes = include_str!("../tests/fixtures/2017-08-14-fla-6ng-01.igc")
.lines()
.filter(|l| l.starts_with('B'))
.filter_map(|line| {
igc::records::BRecord::parse(&line)
.ok()
.map(|record| Point {
latitude: record.pos.lat.into(),
longitude: record.pos.lon.into(),
altitude: record.pressure_alt,
})
})
.collect::<Vec<_>>();

olc::optimize(&fixes).unwrap()
})
});
}

criterion_group! {
Expand Down
19 changes: 11 additions & 8 deletions examples/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ extern crate aeroscore;
extern crate igc;

use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;

use aeroscore::olc;

Expand Down Expand Up @@ -67,13 +67,16 @@ fn analyze(path: &str) {
.lines()
.filter_map(|l| l.ok())
.filter(|l| l.starts_with('B'))
.filter_map(|line| igc::records::BRecord::parse(&line).ok()
.map(|record| Point {
time: record.timestamp,
latitude: record.pos.lat.into(),
longitude: record.pos.lon.into(),
altitude: record.pressure_alt,
}))
.filter_map(|line| {
igc::records::BRecord::parse(&line)
.ok()
.map(|record| Point {
time: record.timestamp,
latitude: record.pos.lat.into(),
longitude: record.pos.lon.into(),
altitude: record.pressure_alt,
})
})
.collect::<Vec<_>>();

println!("num points: {}", fixes.len());
Expand Down
21 changes: 13 additions & 8 deletions examples/geojson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ extern crate aeroscore;
extern crate igc;

use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::fs::File;

use aeroscore::olc;

Expand Down Expand Up @@ -46,17 +46,22 @@ fn analyze(path: &str) {
.lines()
.filter_map(|l| l.ok())
.filter(|l| l.starts_with('B'))
.filter_map(|line| igc::records::BRecord::parse(&line).ok()
.map(|record| Point {
latitude: record.pos.lat.into(),
longitude: record.pos.lon.into(),
altitude: record.pressure_alt,
}))
.filter_map(|line| {
igc::records::BRecord::parse(&line)
.ok()
.map(|record| Point {
latitude: record.pos.lat.into(),
longitude: record.pos.lon.into(),
altitude: record.pressure_alt,
})
})
.collect::<Vec<_>>();

let result = olc::optimize(&fixes).unwrap();

let result_coords = result.path.iter()
let result_coords = result
.path
.iter()
.map(|i| &fixes[*i])
.map(|p| (p.longitude, p.latitude))
.collect::<Vec<_>>();
Expand Down
12 changes: 6 additions & 6 deletions src/flat.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use flat_projection::{FlatProjection, FlatPoint};
use flat_projection::{FlatPoint, FlatProjection};
use ord_subset::OrdSubsetIterExt;

use crate::Point;
use crate::parallel::*;
use crate::Point;

/// Projects all geographic points onto a flat surface for faster geodesic calculation
///
Expand All @@ -17,11 +17,11 @@ pub fn to_flat_points<T: Point>(points: &[T]) -> Vec<FlatPoint<f32>> {
}

trait CenterLatitude {
fn center_lat(self: &Self) -> Option<f32>;
fn center_lat(&self) -> Option<f32>;
}

impl<T: Point> CenterLatitude for [T] {
fn center_lat(self: &Self) -> Option<f32> {
fn center_lat(&self) -> Option<f32> {
let lat_min = self.iter().map(|fix| fix.latitude()).ord_subset_min()?;
let lat_max = self.iter().map(|fix| fix.latitude()).ord_subset_max()?;

Expand All @@ -30,11 +30,11 @@ impl<T: Point> CenterLatitude for [T] {
}

trait CenterLongitude {
fn center_lon(self: &Self) -> Option<f32>;
fn center_lon(&self) -> Option<f32>;
}

impl<T: Point> CenterLongitude for [T] {
fn center_lon(self: &Self) -> Option<f32> {
fn center_lon(&self) -> Option<f32> {
let lon_min = self.iter().map(|fix| fix.longitude()).ord_subset_min()?;
let lon_max = self.iter().map(|fix| fix.longitude()).ord_subset_max()?;

Expand Down
5 changes: 2 additions & 3 deletions src/haversine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ pub fn haversine_distance(fix1: &dyn Point, fix2: &dyn Point) -> f32 {
let delta_phi = (fix2.latitude() - fix1.latitude()).to_radians();
let delta_rho = (fix2.longitude() - fix1.longitude()).to_radians();

let a = (delta_phi / 2.).sin() * (delta_phi / 2.).sin() +
phi1.cos() * phi2.cos() *
(delta_rho / 2.).sin() * (delta_rho / 2.).sin();
let a = (delta_phi / 2.).sin() * (delta_phi / 2.).sin()
+ phi1.cos() * phi2.cos() * (delta_rho / 2.).sin() * (delta_rho / 2.).sin();

let c = 2. * a.sqrt().atan2((1. - a).sqrt());

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod olc;
pub mod flat;
pub mod haversine;
mod point;
pub mod olc;
mod parallel;
mod point;

pub use crate::point::Point;
Loading