Skip to main content

Globe

Struct Globe 

Source
pub struct Globe<'a> { /* private fields */ }
Expand description

A globe widget driven by an externally-provided Camera.

Renders by rasterizing land triangles and coastline contours into a shared Braille dot grid (resolution 2W x 4H for a W x H cell area), then composing each cell’s 8 dots into a single Braille glyph. Cells that contain any contour dot render only the contour bits in CONTOUR_COLOR - the land dots in those cells are dropped to preserve the thin coastline. Cells with land but no contour render the land bits in LAND_COLOR.

Vertices on the back hemisphere (post-rotation z < 0) are culled and contour segments straddling the horizon are clipped to it. Triangles are culled by the sign of their average vertex z (a sphere-tessellation approximation of the surface normal direction).

Implementations§

Source§

impl<'a> Globe<'a>

Source

pub fn new(data: &'a MapData, camera: Camera) -> Self

Examples found in repository?
examples/smoke.rs (line 19)
10fn main() {
11    let map = MapData::embedded();
12    let area = Rect::new(0, 0, 80, 30);
13    for yaw in [0.0_f32, 1.0, 2.0, 3.0] {
14        let camera = Camera {
15            yaw,
16            ..Camera::default()
17        };
18        let mut buf = Buffer::empty(area);
19        Globe::new(&map, camera).render(area, &mut buf);
20        println!("--- yaw = {yaw:.2} rad ---");
21        for y in 0..area.height {
22            let mut line = String::new();
23            for x in 0..area.width {
24                let sym = buf[(x, y)].symbol();
25                line.push(if sym == " " || sym.is_empty() {
26                    ' '
27                } else {
28                    '#'
29                });
30            }
31            println!("{}", line.trim_end());
32        }
33        println!();
34    }
35}

Trait Implementations§

Source§

impl Widget for Globe<'_>

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

Auto Trait Implementations§

§

impl<'a> Freeze for Globe<'a>

§

impl<'a> RefUnwindSafe for Globe<'a>

§

impl<'a> Send for Globe<'a>

§

impl<'a> Sync for Globe<'a>

§

impl<'a> Unpin for Globe<'a>

§

impl<'a> UnsafeUnpin for Globe<'a>

§

impl<'a> UnwindSafe for Globe<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.