Struct ViewState

Source
pub struct ViewState {
    zoom: ChangeObserver<Zoom>,
    camera: ChangeObserver<Camera>,
    perspective: Perspective,
    width: f64,
    height: f64,
    edge_insets: EdgeInsets,
}

Fields§

§zoom: ChangeObserver<Zoom>§camera: ChangeObserver<Camera>§perspective: Perspective§width: f64§height: f64§edge_insets: EdgeInsets

Implementations§

Source§

impl ViewState

Source

pub fn new<F: Into<Rad<f64>>, P: Into<Deg<f64>>>( window_size: PhysicalSize, position: WorldCoords, zoom: Zoom, pitch: P, fovy: F, ) -> Self

Source

pub fn set_edge_insets(&mut self, edge_insets: EdgeInsets)

Source

pub fn edge_insets(&self) -> &EdgeInsets

Source

pub fn resize(&mut self, size: LogicalSize)

Source

pub fn create_view_region( &self, visible_level: ZoomLevel, padding: ViewStatePadding, ) -> Option<ViewRegion>

Source

fn get_intersection_time( ray_origin: Vector3<f64>, ray_direction: Vector3<f64>, plane_origin: Vector3<f64>, plane_normal: Vector3<f64>, ) -> f64

Source

fn furthest_distance( &self, camera_height: f64, center_offset: Point2<f64>, ) -> f64

Source

pub fn camera_to_center_distance(&self) -> f64

Source

pub fn view_projection(&self) -> ViewProjection

This function matches how maplibre-gl-js implements perspective and cameras at the time of the mapbox -> maplibre fork: src/geo/transform.ts#L680

Source

pub fn zoom(&self) -> Zoom

Source

pub fn did_zoom_change(&self) -> bool

Source

pub fn update_zoom(&mut self, new_zoom: Zoom)

Source

pub fn camera(&self) -> &Camera

Source

pub fn camera_mut(&mut self) -> &mut Camera

Source

pub fn did_camera_change(&self) -> bool

Source

pub fn update_references(&mut self)

Source

pub(crate) fn clip_to_window_transform(&self) -> Matrix4<f64>

A transform which can be used to transform between clip and window space. Adopted from here (Direct3D).

Source

pub(crate) fn clip_to_window(&self, clip: &Vector4<f64>) -> Vector4<f64>

Transforms coordinates in clip space to window coordinates.

Adopted from here (Direct3D).

Source

pub(crate) fn clip_to_window_maplibre( &self, clip: &Vector4<f64>, ) -> Vector4<f64>

The way how maplibre converts from clip to window space: https://github.com/maplibre/maplibre-native/blob/4add9ead08799577a37c465b8cb1266676b6c41e/src/mbgl/text/collision_index.cpp/#L437-L438

Source

fn clip_to_window_vulkan(&self, clip: &Vector4<f64>) -> Vector3<f64>

Alternative implementation to clip_to_window. Transforms coordinates in clip space to window coordinates.

Adopted from here and here (Vulkan).

Source

fn window_to_world( &self, window: &Vector3<f64>, inverted_view_proj: &InvertedViewProjection, ) -> Vector3<f64>

Order of transformations reversed: https://computergraphics.stackexchange.com/questions/6087/screen-space-coordinates-to-eye-space-conversion/6093 w is lost.

OpenGL explanation: https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space#From_window_to_ndc

Source

fn window_to_world_nalgebra( window: &Vector3<f64>, inverted_view_proj: &InvertedViewProjection, width: f64, height: f64, ) -> Vector3<f64>

Alternative implementation to window_to_world

Adopted from here.

Source

pub fn window_to_world_at_ground( &self, window: &Vector2<f64>, inverted_view_proj: &InvertedViewProjection, bound: bool, ) -> Option<Vector2<f64>>

Gets the world coordinates for the specified window coordinates on the z=0 plane.

Source

pub fn view_region_bounding_box( &self, inverted_view_proj: &InvertedViewProjection, ) -> Option<Aabb2<f64>>

Calculates an Aabb2 bounding box which contains at least the visible area on the z=0 plane. One can think of it as being the bounding box of the geometry which forms the intersection between the viewing frustum and the z=0 plane.

This implementation works in the world 3D space. It casts rays from the corners of the window to calculate intersections points with the z=0 plane. Then a bounding box is calculated.

Note: It is possible that no such bounding box exists. This is the case if the z=0 plane is not in view.

Source

pub fn view_region_bounding_box_ndc(&self) -> Option<Aabb2<f64>>

An alternative implementation for view_region_bounding_box.

This implementation works in the NDC space. We are creating a plane in the world 3D space. Then we are transforming it to the NDC space. In NDC space it is easy to calculate the intersection points between an Aabb3 and a plane. The resulting Aabb2 is returned.

Source

pub fn height(&self) -> f64

Source

pub fn width(&self) -> f64

Trait Implementations§

Source§

impl Clone for ViewState

Source§

fn clone(&self) -> ViewState

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> Resource for T
where T: 'static,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,