Skip to content

Commit

Permalink
Safety margin, kml file download
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoff97 committed Sep 26, 2024
1 parent d15cc84 commit e2da7d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
42 changes: 31 additions & 11 deletions backend-rust/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ img.gridImage {
.right {
position: absolute;
right: 0px;
}

.marginRight {
margin-right: 10px;
}
15 changes: 13 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="settings">
<Section
Expand Down Expand Up @@ -463,12 +472,14 @@ function SettingsCard({ settings, setSettings, setImageState, setGrid, grid, pat
labelStepSize={50} stepSize={10}></Slider>
{grid.response !== undefined ?
<>
<Button text="Rerun" onClick={rerun} className="marginRight" />
<a href={kmlUrl} download="glideArea.kml" className="marginRight"><Button text="KML File" /></a>
<Button
icon={<Share />}
onClick={copyUrlToClipBoard}
style={{ marginRight: "10px" }}>
className="marginRight"
text="Share">
</Button>
<Button text="Rerun from current location" onClick={rerun} />
</> : <></>}
</SectionCard>
</Section>
Expand Down

0 comments on commit e2da7d4

Please sign in to comment.