MvtCurvedTextPlacer

Arc-length parameterised glyph placement along a polyline. Given a polyline in screen coordinates, a text string with its per-character advance widths in pixels, and a desired label-repeat interval, produces one GlyphRun per repeat position covering as much of the line as fits.

Each GlyphRun holds the per-glyph (screen position, tangent angle) pairs so the caller can emit one rotated earth.worldwind.shape.Label per glyph. The first repeat starts with enough margin from the line's start that the label's left edge sits on or after the line's first vertex; subsequent repeats begin at previousRunEnd + repeatGapPx.

Curvature handling: each glyph's tangent angle is sampled at its position along the curve (the segment containing its arc-length offset). On a sinuous river this produces a snake-along-the-curve effect; on a straight road every glyph in a run shares the same angle.

The placer is pure: no global state, no allocations beyond the returned list.

Types

Link copied to clipboard
class GlyphPlacement(val char: Char, val x: Float, val y: Float, val angleRad: Float, val segIndex: Int, val segU: Float)
Link copied to clipboard
class GlyphRun(val glyphs: List<MvtCurvedTextPlacer.GlyphPlacement>, val centerX: Float, val centerY: Float)

Functions

Link copied to clipboard
fun place(polyline: List<Vec2>, text: String, charWidths: FloatArray, textWidth: Float, repeatGapPx: Float = 250.0f): List<MvtCurvedTextPlacer.GlyphRun>

Lay out text along polyline using one GlyphRun per repeat. Returns empty when the polyline is too short to fit a single full repeat (length < textWidth).

Link copied to clipboard
fun rotatedGlyphCorners(anchorX: Float, anchorY: Float, angleRad: Float, glyphWidth: Float, glyphHeight: Float, out: FloatArray)

Rotate the per-glyph anchor offsets into screen space. Useful when emitting one Label per glyph and you need to compute the glyph's screen bbox for collision. Returns (dx, dy) screen offsets from the anchor centerX, centerY for a glyph that would otherwise sit at the anchor with width glyphWidth and height glyphHeight.