pub fn stroke_line(
coords: &[GeoCoord],
half_width: f64,
) -> (Vec<[f64; 2]>, Vec<u32>)Expand description
Expand a polyline into a thick triangle-strip ribbon.
Each input vertex is extruded along its local normal (perpendicular
to the tangent) by +/- half_width, producing two output vertices.
Adjacent quads are then connected with two triangles each.
§Tangent computation
| Vertex position | Tangent source |
|---|---|
| First | Forward difference to next vertex |
| Interior | Central difference (average of prev->curr and curr->next) |
| Last | Backward difference from previous vertex |
At sharp bends the averaged tangent may cause the ribbon to narrow or self-intersect. A miter-limit strategy is planned for a future release.
§Returns
(positions, indices) where:
positions–[lon, lat]pairs in degree space, two per input vertex (left and right of the centreline).indices– triangle indices intopositions(6 per segment).
§Edge cases
| Input | Result |
|---|---|
| Fewer than 2 coordinates | (empty, empty) |
half_width <= 0.0 | Degenerate zero-area ribbon (positions collapse onto the centreline) |
| Coincident consecutive vertices | Zero-length tangent yields zero normal – the two extruded vertices coincide, producing degenerate triangles that are invisible on screen |
§Example
use rustial_engine::stroke_line;
use rustial_engine::GeoCoord;
let line = vec![
GeoCoord::from_lat_lon(0.0, 0.0),
GeoCoord::from_lat_lon(0.0, 1.0),
];
let (positions, indices) = stroke_line(&line, 0.01);
assert_eq!(positions.len(), 4); // 2 vertices * 2 sides
assert_eq!(indices.len(), 6); // 1 segment * 6 indices