From e2da7d491f46bb623bcc36e3125e5235f86bbf17 Mon Sep 17 00:00:00 2001 From: Frithjof Winkelmann Date: Thu, 26 Sep 2024 22:20:12 +0200 Subject: [PATCH] Safety margin, kml file download --- backend-rust/src/search.rs | 42 ++++++++++++++++++++++++++++---------- frontend/src/App.css | 4 ++++ frontend/src/App.tsx | 15 ++++++++++++-- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/backend-rust/src/search.rs b/backend-rust/src/search.rs index 445c79d..c70547e 100644 --- a/backend-rust/src/search.rs +++ b/backend-rust/src/search.rs @@ -680,23 +680,43 @@ pub fn is_line_intersecting(to: &Node, ix: GridIx, config: &SearchConfig) -> boo let x_indices = linspace(u16_f32(to.ix.0), u16_f32(ix.0), i_len); let y_indices = linspace(u16_f32(to.ix.1), u16_f32(ix.1), i_len); - /*let safety_margins = config.safety_margin; - if to.distance < config.start_distance: - safety_margins = np.ones(i_len)*config.safety_margin - n_no_safety_margin = math.ceil(i_len*((config.start_distance - to.distance)/length)) - safety_margins[:n_no_safety_margin] = 0*/ - // TODO: Safety margin + let distance = length * config.grid.cell_size; let real_heights = linspace( to.height, - to.height - length * config.grid.cell_size * effective_glide.glide_ratio, + to.height - distance * effective_glide.glide_ratio, i_len, ); - //TODO: Use brennans line algorithm - for ((x_i, y_i), real_height) in zip(zip(x_indices, y_indices), real_heights) { - if real_height < config.grid.heights[[f32_usize(x_i), f32_usize(y_i)]] as f32 { - return true; + if config.safety_margin == 0.0 || to.distance + distance <= config.start_distance { + for ((x_i, y_i), real_height) in zip(zip(x_indices, y_indices), real_heights) { + if real_height < config.grid.heights[[f32_usize(x_i), f32_usize(y_i)]] as f32 { + return true; + } + } + } else if to.distance < config.start_distance && to.distance + distance > config.start_distance + { + let mut cur_distance = to.distance; + let distance_step = distance / (i_len - 1) as f32; + + for ((x_i, y_i), real_height) in zip(zip(x_indices, y_indices), real_heights) { + let check_height = if cur_distance < config.start_distance { + real_height + } else { + real_height - config.safety_margin + }; + if check_height < config.grid.heights[[f32_usize(x_i), f32_usize(y_i)]] as f32 { + return true; + } + cur_distance += distance_step; + } + } else { + for ((x_i, y_i), real_height) in zip(zip(x_indices, y_indices), real_heights) { + if real_height - config.safety_margin + < config.grid.heights[[f32_usize(x_i), f32_usize(y_i)]] as f32 + { + return true; + } } } return false; diff --git a/frontend/src/App.css b/frontend/src/App.css index 432cacd..250b538 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -53,4 +53,8 @@ img.gridImage { .right { position: absolute; right: 0px; +} + +.marginRight { + margin-right: 10px; } \ No newline at end of file diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d7e0c56..b37a5d2 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -388,6 +388,15 @@ function SettingsCard({ settings, setSettings, setImageState, setGrid, grid, pat } } + let kmlUrl = undefined; + if (grid.startPosition !== undefined) { + const searchParams = getSearchParams(grid.startPosition.lat, grid.startPosition.lat, settings).toString(); + let kml = new URL(window.location.origin + "/kml"); + kml.search = searchParams; + + kmlUrl = kml.toString(); + } + return (
{grid.response !== undefined ? <> + -