Skip to content

Commit

Permalink
[terrain] use slow math
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed Oct 5, 2023
1 parent a5b220f commit 71b1067
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 41 deletions.
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ clap = { version = "4.4.2", features = ["derive"] }
criterion = { version = "0.5", features = ["html_reports"] }
dashmap = "5.5.3"
env_logger = "0.10.0"
fast-math = "0.1.1"
geo = "0.26.0"
itertools = "0.11.0"
log = "0.4.20"
Expand Down
1 change: 0 additions & 1 deletion terrain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
dashmap = { workspace = true }
fast-math = { workspace = true }
geo = { workspace = true }
log = { workspace = true }
nasadem = { path = "../nasadem" }
Expand Down
26 changes: 5 additions & 21 deletions terrain/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<T: CoordFloat> HaversineIter<T> {
}
}

impl<T: CoordFloat + Atan2 + AsPrimitive<usize>> Iterator for HaversineIter<T> {
impl<T: CoordFloat + AsPrimitive<usize>> Iterator for HaversineIter<T> {
type Item = Point<T>;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -60,7 +60,7 @@ impl<T: CoordFloat + Atan2 + AsPrimitive<usize>> Iterator for HaversineIter<T> {
}
}

impl<T: CoordFloat + Atan2 + AsPrimitive<usize>> ExactSizeIterator for HaversineIter<T> {
impl<T: CoordFloat + AsPrimitive<usize>> ExactSizeIterator for HaversineIter<T> {
fn len(&self) -> usize {
self.total_points.as_() - self.current_point.as_()
}
Expand All @@ -80,7 +80,7 @@ struct HaversineParams<T> {
#[allow(clippy::many_single_char_names)]
fn get_point<T>(params: &HaversineParams<T>, f: T) -> Point<T>
where
T: CoordFloat + Atan2,
T: CoordFloat,
{
let one = T::one();

Expand All @@ -101,8 +101,8 @@ where
let y = a * p + b * q;
let z = a * r + b * s;

let lat = Atan2::atan2(z, x.hypot(y));
let lon = Atan2::atan2(y, x);
let lat = z.atan2(x.hypot(y));
let lon = y.atan2(x);

Point::new(lon.to_degrees(), lat.to_degrees())
}
Expand Down Expand Up @@ -147,22 +147,6 @@ where
}
}

pub trait Atan2 {
fn atan2(lhs: Self, rhs: Self) -> Self;
}

impl Atan2 for f32 {
fn atan2(lhs: Self, rhs: Self) -> Self {
fast_math::atan2(lhs, rhs)
}
}

impl Atan2 for f64 {
fn atan2(lhs: Self, rhs: Self) -> Self {
lhs.atan2(rhs)
}
}

/// Returns the up/down angle (in radians) from a to b.
pub fn elevation_angle<T>(start_elev_m: T, distance_m: T, end_elev_m: T) -> T
where
Expand Down
4 changes: 2 additions & 2 deletions terrain/src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
math::{elevation_angle, linspace, Atan2, HaversineIter},
math::{elevation_angle, linspace, HaversineIter},
TerrainError, Tiles,
};
use geo::{
Expand Down Expand Up @@ -120,7 +120,7 @@ where

pub fn build(&self, tiles: &Tiles) -> Result<Profile<C>, TerrainError>
where
C: Atan2 + FloatConst + AsPrimitive<usize>,
C: FloatConst + AsPrimitive<usize>,
{
let start = self.start.ok_or(TerrainError::Builder("start"))?;
let max_step_m = self.max_step_m.ok_or(TerrainError::Builder("max_step"))?;
Expand Down

0 comments on commit 71b1067

Please sign in to comment.