maplibre/legacy/
image_atlas.rs

1//! Translated from https://github.com/maplibre/maplibre-native/blob/4add9ea/src/mbgl/renderer/image_atlas.cpp
2
3use std::collections::HashMap;
4
5use crate::{
6    euclid::Rect,
7    legacy::{
8        image::{
9            Image, ImageContent, ImageManager, ImageMap, ImageStretches, ImageVersionMap,
10            PremultipliedImage,
11        },
12        TileSpace,
13    },
14};
15
16/// maplibre/maplibre-native#4add9ea original name: ImagePosition
17#[derive(Clone)]
18pub struct ImagePosition {
19    pub pixel_ratio: f64,
20    pub padded_rect: Rect<u16, TileSpace>,
21    pub version: u32,
22    pub stretch_x: ImageStretches,
23    pub stretch_y: ImageStretches,
24    pub content: Option<ImageContent>,
25}
26impl ImagePosition {
27    pub const PADDING: u16 = 1;
28
29    /// maplibre/maplibre-native#4add9ea original name: tl
30    pub fn tl(&self) -> [u16; 2] {
31        [
32            (self.padded_rect.min().x + Self::PADDING),
33            (self.padded_rect.min().y + Self::PADDING),
34        ]
35    }
36
37    /// maplibre/maplibre-native#4add9ea original name: br
38    pub fn br(&self) -> [u16; 2] {
39        [
40            (self.padded_rect.min().x + self.padded_rect.width() - Self::PADDING),
41            (self.padded_rect.min().y + self.padded_rect.height() - Self::PADDING),
42        ]
43    }
44
45    /// maplibre/maplibre-native#4add9ea original name: tlbr
46    pub fn tlbr(&self) -> [u16; 4] {
47        let _tl = self.tl();
48        let _br = self.br();
49        [_tl[0], _tl[1], _br[0], _br[1]]
50    }
51
52    /// maplibre/maplibre-native#4add9ea original name: displaySize
53    pub fn display_size(&self) -> [f64; 2] {
54        [
55            (self.padded_rect.width() - Self::PADDING * 2) as f64 / self.pixel_ratio,
56            (self.padded_rect.height() - Self::PADDING * 2) as f64 / self.pixel_ratio,
57        ]
58    }
59}
60
61/// maplibre/maplibre-native#4add9ea original name: ImagePositions
62pub type ImagePositions = HashMap<String, ImagePosition>;
63
64/// maplibre/maplibre-native#4add9ea original name: ImagePatch
65pub struct ImagePatch {
66    image: Image,
67    padded_rect: Rect<u16, TileSpace>,
68}
69
70impl ImagePatch {}
71
72/// maplibre/maplibre-native#4add9ea original name: ImageAtlas
73pub struct ImageAtlas {
74    image: PremultipliedImage,
75    icon_positions: ImagePositions,
76    pattern_positions: ImagePositions,
77}
78impl ImageAtlas {
79    /// maplibre/maplibre-native#4add9ea original name: getImagePatchesAndUpdateVersions
80    pub fn get_image_patches_and_update_versions(image_manager: &ImageManager) -> Vec<ImagePatch> {
81        todo!()
82    }
83}
84
85/// maplibre/maplibre-native#4add9ea original name: makeImageAtlas
86pub fn make_image_atlas(
87    image_map_a: &ImageMap,
88    image_map_b: &ImageMap,
89    version_map: &ImageVersionMap,
90) -> ImageAtlas {
91    todo!()
92}