pub struct Mapping {
pub rect: Rect,
pub ppp: f32,
pub zoom: f64,
pub origin: [f64; 2],
pub center: [f64; 2],
pub image: [f64; 2],
pub rect_px: [f64; 4],
}Expand description
The mapping between image pixels, physical pixels and points for one
frame of one viewport in one window. Build it with Mapping::new;
every conversion of the viewport (drawing, tiles, hit tests, the
readout) goes through it.
Physical pixels are counted from the window’s top left corner, as the
GPU draws them; a physical pixel n covers n..n+1 and its centre is
n + 0.5.
Fields§
§rect: RectThe viewport, in points.
ppp: f32Physical pixels per point of the window drawing it.
zoom: f64Physical pixels per image pixel (fit resolved).
origin: [f64; 2]Where image point (0, 0) lands, in physical pixels: whole
numbers.
center: [f64; 2]The image point at the centre of the view.
image: [f64; 2]The image’s size in pixels.
rect_px: [f64; 4]The viewport in physical pixels, rounded: [x0, y0, x1, y1].
Implementations§
Source§impl Mapping
impl Mapping
Sourcepub fn new(view: &View, image: [f64; 2], rect: Rect, ppp: f32) -> Mapping
pub fn new(view: &View, image: [f64; 2], rect: Rect, ppp: f32) -> Mapping
The mapping of a view of an image (image, its size in pixels)
into rect (points) on a window with ppp physical pixels per
point.
Sourcepub fn image_to_screen(&self, p: [f64; 2]) -> Pos2
pub fn image_to_screen(&self, p: [f64; 2]) -> Pos2
An image point on screen, in points.
Sourcepub fn screen_to_image(&self, pos: Pos2) -> [f64; 2]
pub fn screen_to_image(&self, pos: Pos2) -> [f64; 2]
A screen position (points) in image pixels, continuous.
Sourcepub fn image_rect_to_screen(&self, r: [f64; 4]) -> Rect
pub fn image_rect_to_screen(&self, r: [f64; 4]) -> Rect
A rectangle of the image ([x0, y0, x1, y1], image pixels) on
screen, in points.
Sourcepub fn pixel_at(&self, pos: Pos2) -> Option<[i64; 2]>
pub fn pixel_at(&self, pos: Pos2) -> Option<[i64; 2]>
The image pixel drawn on the physical pixel under pos (points),
or None outside the image. This is the drawing’s own rule: the
physical pixel’s centre, mapped to the image, floored. The pixel
readout and the tests use it.
Sourcepub fn visible(&self) -> Option<[f64; 4]>
pub fn visible(&self) -> Option<[f64; 4]>
The part of the image in view, clipped to the image:
[x0, y0, x1, y1] in image pixels, or None when nothing of it is
visible.
Sourcepub fn zoom_around(&self, pos: Pos2, zoom: f64) -> View
pub fn zoom_around(&self, pos: Pos2, zoom: f64) -> View
The view centred so that image point at stays under the screen
position pos at another zoom (zooming around the pointer).
Trait Implementations§
impl Copy for Mapping
impl StructuralPartialEq for Mapping
Auto Trait Implementations§
impl Freeze for Mapping
impl RefUnwindSafe for Mapping
impl Send for Mapping
impl Sync for Mapping
impl Unpin for Mapping
impl UnsafeUnpin for Mapping
impl UnwindSafe for Mapping
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
impl<F, T, S> SimdInto<T, S> for Fwhere
T: SimdFrom<F, S>,
S: Simd,
§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.