Skip to content

Commit

Permalink
Merge pull request #86 from TurtIeSocks/bootstrapping-improvements
Browse files Browse the repository at this point in the history
improve bootstrapping
  • Loading branch information
TurtIeSocks authored Mar 2, 2023
2 parents b7aeaba + 2b29c6e commit 8dac780
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 0 additions & 1 deletion client/src/services/fetches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export async function clusteringRouting(): Promise<FeatureCollection> {
}
const json = await res.json()
const fetch_time = Date.now() - startTime
console.log({ fenceRef })
setStatic('loading', (prev) => ({
...prev,
[fenceRef
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.lock

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

2 changes: 1 addition & 1 deletion server/algorithms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "algorithms"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
publish = false

Expand Down
20 changes: 14 additions & 6 deletions server/algorithms/src/bootstrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn dot(u: &Point, v: &Point) -> f64 {
u.x() * v.x() + u.y() * v.y()
}

fn distance_to_segment(p: Point, a: Point, b: Point) -> f64 {
fn distance_to_segment(p: &Point, a: &Point, b: &Point) -> f64 {
let v = Point::new(b.x() - a.x(), b.y() - a.y());
let w = Point::new(p.x() - a.x(), p.y() - a.y());
let c1 = dot(&w, &v);
Expand All @@ -24,15 +24,15 @@ fn distance_to_segment(p: Point, a: Point, b: Point) -> f64 {
return p.haversine_distance(&pb);
}

pub fn point_line_distance(input: Vec<Point>, point: Point) -> f64 {
pub fn point_line_distance(input: &Vec<Point>, point: &Point) -> f64 {
let mut distance: f64 = std::f64::MAX;
for (i, line) in input.iter().enumerate() {
let next = if i == input.len() - 1 {
input[0]
} else {
input[i + 1]
};
distance = distance.min(distance_to_segment(point, *line, next));
distance = distance.min(distance_to_segment(point, line, &next));
}
distance
}
Expand Down Expand Up @@ -114,7 +114,11 @@ fn generate_circles(geometry: Geometry, radius: f64) -> Vec<Point> {
let mut circles: Vec<Point> = vec![];

let polygon = Polygon::<f64>::try_from(geometry).unwrap();
let get_points = || polygon.exterior().points().collect::<Vec<Point>>();
let external_points = polygon.exterior().points().collect::<Vec<Point>>();
let internal_points = polygon
.interiors()
.iter()
.map(|interior| interior.points().collect::<Vec<Point>>());

let x_mod: f64 = 0.75_f64.sqrt();
let y_mod: f64 = 0.568_f64.sqrt();
Expand All @@ -136,8 +140,12 @@ fn generate_circles(geometry: Geometry, radius: f64) -> Vec<Point> {
while (bearing == 270. && current.x() > end.x())
|| (bearing == 90. && current.x() < start.x())
{
let point_distance = point_line_distance(get_points(), current);
if point_distance <= radius || point_distance == 0. || polygon.contains(&current) {
if polygon.contains(&current)
|| point_line_distance(&external_points, &current) <= radius
|| internal_points
.clone()
.any(|internal| point_line_distance(&internal, &current) <= radius)
{
circles.push(current);
}
current = current.haversine_destination(bearing, x_mod * radius * 2.)
Expand Down

0 comments on commit 8dac780

Please sign in to comment.