Minimum distance from point to bbox (in degrees, approximate).
(lng: f64, lat: f64, bbox: &BoundingBox)
| 134 | |
| 135 | /// Minimum distance from point to bbox (in degrees, approximate). |
| 136 | fn min_dist_point_bbox(lng: f64, lat: f64, bbox: &BoundingBox) -> f64 { |
| 137 | let dlat = if lat < bbox.min_lat { |
| 138 | bbox.min_lat - lat |
| 139 | } else if lat > bbox.max_lat { |
| 140 | lat - bbox.max_lat |
| 141 | } else { |
| 142 | 0.0 |
| 143 | }; |
| 144 | |
| 145 | let dlng = if bbox.crosses_antimeridian() { |
| 146 | if lng >= bbox.min_lng || lng <= bbox.max_lng { |
| 147 | 0.0 |
| 148 | } else { |
| 149 | (bbox.min_lng - lng).min(lng - bbox.max_lng).max(0.0) |
| 150 | } |
| 151 | } else if lng < bbox.min_lng { |
| 152 | bbox.min_lng - lng |
| 153 | } else if lng > bbox.max_lng { |
| 154 | lng - bbox.max_lng |
| 155 | } else { |
| 156 | 0.0 |
| 157 | }; |
| 158 | |
| 159 | (dlat * dlat + dlng * dlng).sqrt() |
| 160 | } |
| 161 | |
| 162 | fn insert_sorted(results: &mut Vec<NnResult>, item: NnResult, k: usize) { |
| 163 | let pos = results |
no test coverage detected