Struct TileRect

Source
pub struct TileRect {
    pub zoom: u8,
    pub min_x: u32,
    pub min_y: u32,
    pub max_x: u32,
    pub max_y: u32,
}
Expand description

A rectangular region in tile coordinate space.

Represents a rectangle defined by zoom level and tile coordinates. The rectangle is inclusive of both min and max coordinates. Use append_rect to merge rectangles without overlapping.

§Examples

let rect = TileRect::new(10, 0, 0, 255, 255);
assert_eq!(rect.size(), 256 * 256);

Fields§

§zoom: u8

The zoom level of the tiles

§min_x: u32

The minimum X coordinate (inclusive)

§min_y: u32

The minimum Y coordinate (inclusive)

§max_x: u32

The maximum X coordinate (inclusive)

§max_y: u32

The maximum Y coordinate (inclusive)

Implementations§

Source§

impl TileRect

Source

pub fn new(zoom: u8, min_x: u32, min_y: u32, max_x: u32, max_y: u32) -> Self

Creates a new TileRect with the specified coordinates.

§Arguments
  • zoom - The zoom level
  • min_x - The minimum X coordinate (inclusive)
  • min_y - The minimum Y coordinate (inclusive)
  • max_x - The maximum X coordinate (inclusive)
  • max_y - The maximum Y coordinate (inclusive)
§Panics

Panics if min_x > max_x or min_y > max_y.

§Examples
let rect = TileRect::new(0, 0, 0, 1, 1);
assert_eq!(rect.size(), 4);
Source

pub fn is_overlapping(&self, other: &Self) -> bool

Checks if two rectangles overlap.

Two rectangles overlap if

  • they share the same zoom level and
  • their coordinate ranges intersect in both X and Y dimensions.
§Examples
let rect1 = TileRect::new(0, 0, 0, 1, 1);
let rect2 = TileRect::new(0, 1, 1, 2, 2);
assert!(rect1.is_overlapping(&rect2));

let rect3 = TileRect::new(0, 2, 2, 3, 3);
assert!(!rect1.is_overlapping(&rect3));
Source

pub fn size(&self) -> u64

Total number of tiles contained in this rectangle.

The size is calculated as (max_x - min_x + 1) * (max_y - min_y + 1).

§Examples
// x = 0..=2 => 3 tiles
// y = 0..=3 => 4 tiles
let rect = TileRect::new(0, 0, 0, 2, 3);
assert_eq!(rect.size(), 3 * 4);

Trait Implementations§

Source§

impl Clone for TileRect

Source§

fn clone(&self) -> TileRect

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TileRect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for TileRect

Source§

fn eq(&self, other: &TileRect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TileRect

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for TileRect

Source§

impl StructuralPartialEq for TileRect

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
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> 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.