mln_engine/camera/
tile_projector.rs1use mln_style::geometry::Point;
2
3use crate::camera::projection::{ProjectedTilePoint, ProjectionData};
4use crate::camera::view::View;
5use crate::tile::UnwrappedTileID;
6
7#[derive(Clone, Copy)]
10pub struct TileProjector<'a> {
11 view: &'a View,
12 tile_id: UnwrappedTileID,
13 data: ProjectionData,
14}
15
16impl<'a> TileProjector<'a> {
17 #[must_use]
18 pub fn new(view: &'a View, tile_id: &UnwrappedTileID) -> Self {
19 Self::with_data(view, tile_id, view.projection_data(tile_id))
20 }
21
22 #[must_use]
23 #[expect(clippy::large_types_passed_by_value, reason = "the projector keeps `data`")]
24 pub fn with_data(view: &'a View, tile_id: &UnwrappedTileID, data: ProjectionData) -> Self {
25 TileProjector { view, tile_id: *tile_id, data }
26 }
27
28 #[must_use]
31 pub fn project(&self, point: &Point<f64>, elevation: f64) -> ProjectedTilePoint {
32 self.view.projection().project_tile_point(&self.data, &self.tile_id, point, elevation)
33 }
34
35 #[must_use]
37 pub fn project_as_drawn(&self, point: &Point<f64>, elevation: f64) -> ProjectedTilePoint {
38 self.view.projection().drawn_tile_point(&self.data, &self.tile_id, point, elevation)
39 }
40
41 #[must_use]
42 #[cfg(test)]
43 pub(crate) fn map_aligned_scale(&self) -> f64 {
44 self.view.projection().map_aligned_scale(self.view)
45 }
46
47 #[must_use]
56 pub fn map_aligned_scale_at(&self, tile_anchor: &Point<f64>) -> f64 {
57 self.view.projection().map_aligned_scale_at(self.view, tile_anchor, &self.tile_id)
58 }
59
60 #[must_use]
63 pub fn is_past_mercator_horizon(&self, signed_distance_from_camera: f64) -> bool {
64 !self.view.is_globe() && self.view.shows_horizon() && signed_distance_from_camera > self.view.far_z()
65 }
66
67 #[must_use]
71 pub fn is_behind_camera_or_horizon(&self, projected: &ProjectedTilePoint) -> bool {
72 projected.occluded
73 || projected.signed_distance_from_camera <= 0.0
74 || self.is_past_mercator_horizon(projected.signed_distance_from_camera)
75 }
76
77 #[must_use]
78 pub fn view(&self) -> &View {
79 self.view
80 }
81
82 #[must_use]
83 pub fn tile_id(&self) -> &UnwrappedTileID {
84 &self.tile_id
85 }
86}