Buffer a point into an approximate circle polygon.
(lng: f64, lat: f64, meters: f64, segments: usize)
| 108 | |
| 109 | /// Buffer a point into an approximate circle polygon. |
| 110 | fn buffer_point(lng: f64, lat: f64, meters: f64, segments: usize) -> Geometry { |
| 111 | let dlat = meters / 110_540.0; |
| 112 | let dlng = meters / (111_320.0 * lat.to_radians().cos().max(0.001)); |
| 113 | |
| 114 | let mut ring = Vec::with_capacity(segments + 1); |
| 115 | for i in 0..segments { |
| 116 | let angle = 2.0 * std::f64::consts::PI * (i as f64) / (segments as f64); |
| 117 | ring.push([lng + dlng * angle.cos(), lat + dlat * angle.sin()]); |
| 118 | } |
| 119 | // Close the ring. |
| 120 | ring.push(ring[0]); |
| 121 | |
| 122 | Geometry::Polygon { |
| 123 | coordinates: vec![ring], |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /// Buffer a linestring by creating a corridor (parallel offset on both sides + end caps). |
| 128 | fn buffer_linestring(line: &[[f64; 2]], meters: f64, segments: usize) -> Geometry { |
no test coverage detected