diff --git a/client/src/services/fetches.ts b/client/src/services/fetches.ts index c278e8ef..86a86b61 100644 --- a/client/src/services/fetches.ts +++ b/client/src/services/fetches.ts @@ -205,7 +205,6 @@ export async function clusteringRouting(): Promise { } const json = await res.json() const fetch_time = Date.now() - startTime - console.log({ fenceRef }) setStatic('loading', (prev) => ({ ...prev, [fenceRef diff --git a/server/Cargo.lock b/server/Cargo.lock index 0ec8c5c5..f4ade9e2 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -305,7 +305,7 @@ dependencies = [ [[package]] name = "algorithms" -version = "0.4.1" +version = "0.4.2" dependencies = [ "geo", "geohash", diff --git a/server/algorithms/Cargo.toml b/server/algorithms/Cargo.toml index 9f41b701..123a877a 100644 --- a/server/algorithms/Cargo.toml +++ b/server/algorithms/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "algorithms" -version = "0.4.1" +version = "0.4.2" edition = "2021" publish = false diff --git a/server/algorithms/src/bootstrapping.rs b/server/algorithms/src/bootstrapping.rs index ccc7b607..21e6ffa7 100644 --- a/server/algorithms/src/bootstrapping.rs +++ b/server/algorithms/src/bootstrapping.rs @@ -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); @@ -24,7 +24,7 @@ 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) -> f64 { +pub fn point_line_distance(input: &Vec, point: &Point) -> f64 { let mut distance: f64 = std::f64::MAX; for (i, line) in input.iter().enumerate() { let next = if i == input.len() - 1 { @@ -32,7 +32,7 @@ pub fn point_line_distance(input: Vec, point: Point) -> f64 { } else { input[i + 1] }; - distance = distance.min(distance_to_segment(point, *line, next)); + distance = distance.min(distance_to_segment(point, line, &next)); } distance } @@ -114,7 +114,11 @@ fn generate_circles(geometry: Geometry, radius: f64) -> Vec { let mut circles: Vec = vec![]; let polygon = Polygon::::try_from(geometry).unwrap(); - let get_points = || polygon.exterior().points().collect::>(); + let external_points = polygon.exterior().points().collect::>(); + let internal_points = polygon + .interiors() + .iter() + .map(|interior| interior.points().collect::>()); let x_mod: f64 = 0.75_f64.sqrt(); let y_mod: f64 = 0.568_f64.sqrt(); @@ -136,8 +140,12 @@ fn generate_circles(geometry: Geometry, radius: f64) -> Vec { 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(¤t) { + if polygon.contains(¤t) + || point_line_distance(&external_points, ¤t) <= radius + || internal_points + .clone() + .any(|internal| point_line_distance(&internal, ¤t) <= radius) + { circles.push(current); } current = current.haversine_destination(bearing, x_mod * radius * 2.)