Skip to main content

stroke_line

Function stroke_line 

Source
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 positionTangent source
FirstForward difference to next vertex
InteriorCentral difference (average of prev->curr and curr->next)
LastBackward 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 into positions (6 per segment).

§Edge cases

InputResult
Fewer than 2 coordinates(empty, empty)
half_width <= 0.0Degenerate zero-area ribbon (positions collapse onto the centreline)
Coincident consecutive verticesZero-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