use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use approx::{assert_abs_diff_eq, assert_relative_eq};
use geometry::Point;
use mln_style::constants::{LATITUDE_MAX, TILE_SIZE_D};
use mln_style::crs::{Crs, CrsConverter, WorldMapping};
use mln_style::geo::{LatLng, LatLngBounds};
use crate::geo::constants::EARTH_RADIUS_M;
use crate::geo::projection::Projection;
use crate::tests::crs::{self, crs, identity, mapping};
fn ll(lat: f64, lng: f64) -> LatLng {
LatLng::new(lat, lng).unwrap()
}
fn lat_lng(world: &WorldMapping, x: f64, y: f64) -> LatLng {
world.lat_lng_from_world(&Point::new(x, y)).unwrap()
}
const SAMPLES: [[f64; 2]; 6] =
[[0.0, 0.0], [-89.0, -89.0], [89.0, 89.0], [12.5, 41.9], [-73.98, 40.75], [174.77, -41.29]];
fn identity_answering_inside() -> WorldMapping {
mapping(crs(
"test:identity-answering-inside",
|position| position,
|[x, y]| if x.abs() <= 90.0 && y.abs() <= 90.0 { [x, y] } else { [f64::NAN; 2] },
[-90.0, 90.0],
180.0,
))
}
fn rotate([lng, lat]: [f64; 2]) -> [f64; 2] {
let (sin, cos) = (std::f64::consts::PI / 6.0).sin_cos();
[lng * cos - lat * sin, lng * sin + lat * cos]
}
fn rotated() -> WorldMapping {
let (sin, cos) = (std::f64::consts::PI / 6.0).sin_cos();
mapping(crs("test:rotated", rotate, move |[x, y]| [x * cos + y * sin, -x * sin + y * cos], [-150.0, 150.0], 300.0))
}
fn mercator_as_crs() -> WorldMapping {
let half_circumference = std::f64::consts::PI * EARTH_RADIUS_M;
mapping(crs(
"test:mercator-as-crs",
|[lng, lat]| {
let phi = lat.to_radians();
[lng.to_radians() * EARTH_RADIUS_M, EARTH_RADIUS_M * (std::f64::consts::FRAC_PI_4 + phi / 2.0).tan().ln()]
},
|[x, y]| {
[
(x / EARTH_RADIUS_M).to_degrees(),
(2.0 * (y / EARTH_RADIUS_M).exp().atan() - std::f64::consts::FRAC_PI_2).to_degrees(),
]
},
[-half_circumference, half_circumference],
2.0 * half_circumference,
))
}
#[test]
fn the_identity_takes_lng_lat_as_its_coordinates() {
let world = identity();
assert_eq!("identity", world.name());
assert!(!world.wraps());
assert_eq!(Point::new(0.75, 0.25), world.world_from_lat_lng(&ll(45.0, 45.0)));
assert_eq!(ll(45.0, 45.0), lat_lng(&world, 0.75, 0.25));
assert_eq!(180.0, world.height_meters_per_world_unit(&lat_lng(&world, 0.5, 0.5)));
}
#[test]
fn the_identity_maps_the_tile_0_square_to_90_degrees_each_way() {
let world = identity();
assert_eq!(Point::new(0.0, 0.0), world.world_from_lat_lng(&ll(90.0, -90.0)));
assert_eq!(Point::new(1.0, 1.0), world.world_from_lat_lng(&ll(-90.0, 90.0)));
assert_eq!(Point::new(0.5, 0.5), world.world_from_lat_lng(&ll(0.0, 0.0)));
}
#[test]
fn the_identity_round_trips_lng_lat() {
let world = identity();
for [lng, lat] in SAMPLES {
let back = world.lat_lng_from_world(&world.world_from_lat_lng(&ll(lat, lng))).unwrap();
assert_abs_diff_eq!(lng, back.longitude(), epsilon = 5e-13);
assert_abs_diff_eq!(lat, back.latitude(), epsilon = 5e-13);
}
}
#[test]
fn the_identity_takes_its_extent_as_meters_per_world_unit_everywhere() {
let world = identity();
assert_eq!(180.0, world.height_meters_per_world_unit(&lat_lng(&world, 0.5, 0.5)));
assert_eq!(180.0, world.height_meters_per_world_unit(&lat_lng(&world, 0.95, 0.05)));
}
#[test]
fn mercator_measures_the_ground_in_closed_form() {
let mercator = WorldMapping::default();
for latitude in [0.0, 45.0, -60.0, LATITUDE_MAX, 89.0] {
let expected = Projection::meters_per_pixel_at_latitude(latitude, 0.0) * TILE_SIZE_D;
for step in [[1e-3, 0.0], [0.0, 1e-3], [0.5, 0.5]] {
let measured = mercator.ground_meters_per_world_unit([10.0, latitude], step);
assert_relative_eq!(expected, measured, max_relative = 1e-15);
}
}
}
#[test]
fn the_identity_measures_the_ground_across_a_step() {
let world = identity();
let half_meridian = std::f64::consts::PI * 6_371_008.8;
let step = 1e-4;
let along_x = |latitude| world.ground_meters_per_world_unit([0.0, latitude], [step, 0.0]);
assert_relative_eq!(half_meridian, along_x(0.0), max_relative = 1e-6);
assert_relative_eq!(half_meridian / 2.0, along_x(60.0), max_relative = 1e-6);
assert_relative_eq!(
half_meridian,
world.ground_meters_per_world_unit([0.0, 60.0], [0.0, step]),
max_relative = 1e-6
);
}
#[test]
fn a_lat_lng_past_the_edge_of_the_square_is_unclamped() {
let world = identity();
assert_eq!(ll(0.0, 135.0), lat_lng(&world, 1.25, 0.5));
assert!(world.has_lat_lng(&Point::new(1.25, 0.5)));
assert_eq!(ll(90.0, 0.0), lat_lng(&world, 0.5, -0.5));
}
#[test]
fn a_latitude_past_the_poles_is_clamped() {
let world = identity();
assert_eq!(90.0, lat_lng(&world, 0.5, -0.1).latitude());
assert_eq!(-90.0, lat_lng(&world, 0.5, 1.1).latitude());
assert!(!world.has_lat_lng(&Point::new(0.5, -0.1)));
}
#[test]
fn a_position_without_an_answer_uses_the_edge_toward_the_center() {
let world = mapping(crs::disc("test:disc"));
assert!(!world.has_lat_lng(&Point::new(1.0, 1.0)));
assert!(world.has_lat_lng(&Point::new(0.5, 0.5)));
let edge = lat_lng(&world, 2.0, 2.0);
assert_abs_diff_eq!(90.0, edge.longitude().hypot(edge.latitude()), epsilon = 1e-6);
assert_abs_diff_eq!(-edge.latitude(), edge.longitude(), epsilon = 1e-9);
assert_eq!(ll(0.0, 90.0), lat_lng(&world, 1.5, 0.5));
}
struct CountingForward {
converter: Box<dyn CrsConverter>,
forward_calls: Arc<AtomicUsize>,
}
impl CrsConverter for CountingForward {
fn forward(&self, lng_lats: &[[f64; 2]], positions: &mut [[f64; 2]]) {
self.forward_calls.fetch_add(1, Ordering::SeqCst);
self.converter.forward(lng_lats, positions);
}
fn inverse(&self, positions: &[[f64; 2]], lng_lats: &mut [[f64; 2]]) {
self.converter.inverse(positions, lng_lats);
}
}
#[test]
fn a_hole_in_a_batch_stays_while_its_neighbors_convert() {
let Crs { converter, tile_matrix_set, .. } = crs::disc("test:batch");
let forward_calls = Arc::new(AtomicUsize::new(0));
let converter = Box::new(CountingForward { converter, forward_calls: Arc::clone(&forward_calls) });
let world = mapping(Crs { name: "test:batch".to_owned(), converter, tile_matrix_set });
let mut places = [[0.0; 2]; 3];
world.world_from_lng_lats(&[[-45.0, 45.0], [f64::NAN, f64::NAN], [45.0, -45.0]], &mut places);
assert_eq!(1, forward_calls.load(Ordering::SeqCst));
assert_eq!([0.25, 0.25], places[0]);
assert!(places[1][0].is_nan() && places[1][1].is_nan());
assert_eq!([0.75, 0.75], places[2]);
let mut answers = [[0.0; 2]; 3];
world.lng_lats_from_world(&[[0.25, 0.25], [1.0, 1.0], [0.75, 0.75]], &mut answers);
assert_eq!([-45.0, 45.0], answers[0]);
assert_abs_diff_eq!(90.0, answers[1][0].hypot(answers[1][1]), epsilon = 1e-6);
assert_abs_diff_eq!(-answers[1][1], answers[1][0], epsilon = 1e-9);
assert_eq!([45.0, -45.0], answers[2]);
}
#[test]
fn a_position_past_the_east_edge_takes_the_nearest_answer_inside() {
assert_eq!(ll(45.0, 90.0), lat_lng(&identity_answering_inside(), 1.5, 0.25));
}
#[test]
fn a_position_past_the_edge_of_the_world_takes_the_edge_where_the_inverse_wraps() {
let world = mapping(crs(
"test:wrapping-world",
|position| position,
|[x, y]| [(x + 540.0) % 360.0 - 180.0, y],
[-360.0, 360.0],
720.0,
));
let past_the_east_edge = lat_lng(&world, 0.875, 0.5);
assert_abs_diff_eq!(180.0, past_the_east_edge.longitude(), epsilon = 5e-6);
assert_abs_diff_eq!(0.0, past_the_east_edge.latitude(), epsilon = 5e-6);
}
#[test]
fn a_nearly_invertible_converter_keeps_its_inverse() {
let world = mapping(crs("test:approximate", |position| position, |[x, y]| [x * 1.0001, y], [-90.0, 90.0], 180.0));
assert_abs_diff_eq!(45.0045, lat_lng(&world, 0.75, 0.5).longitude(), epsilon = 5e-7);
}
#[test]
fn a_converter_that_never_leads_back_keeps_its_own_answer() {
let world = mapping(crs("test:imprecise", |position| position, |[x, y]| [x + 1.0, y], [-90.0, 90.0], 180.0));
assert_eq!(ll(0.0, 1.0), lat_lng(&world, 0.5, 0.5));
}
#[test]
fn a_position_has_no_location_where_the_inverse_never_answers() {
let world = mapping(crs("test:never", |position| position, |_| [f64::NAN; 2], [-90.0, 90.0], 180.0));
assert!(world.lat_lng_from_world(&Point::new(0.5, 0.5)).is_err());
let mut lng_lats = [[0.0; 2]];
world.lng_lats_from_world(&[[0.5, 0.5]], &mut lng_lats);
assert!(lng_lats[0][0].is_nan() && lng_lats[0][1].is_nan());
}
#[test]
fn a_rotated_crs_measures_from_its_origin_with_y_down() {
let world = rotated();
for [lng, lat] in SAMPLES {
let back = world.lat_lng_from_world(&world.world_from_lat_lng(&ll(lat, lng))).unwrap();
assert_abs_diff_eq!(lng, back.longitude(), epsilon = 5e-11);
assert_abs_diff_eq!(lat, back.latitude(), epsilon = 5e-11);
}
let location = lat_lng(&world, 0.25, 0.75);
let position = rotate([location.longitude(), location.latitude()]);
assert_abs_diff_eq!(-150.0 + 0.25 * 300.0, position[0], epsilon = 5e-11);
assert_abs_diff_eq!(150.0 - 0.75 * 300.0, position[1], epsilon = 5e-11);
assert_eq!(300.0, world.height_meters_per_world_unit(&lat_lng(&world, 0.5, 0.5)));
}
#[test]
fn mercator_written_as_a_crs_maps_as_mercator() {
let world = mercator_as_crs();
let mercator = WorldMapping::default();
let within_limit = SAMPLES.into_iter().filter(|[_, lat]| lat.abs() <= LATITUDE_MAX);
for [lng, lat] in within_limit.chain([[-180.0, -85.0], [180.0, 85.0]]) {
let expected = mercator.world_from_lat_lng(&ll(lat, lng));
let actual = world.world_from_lat_lng(&ll(lat, lng));
assert_abs_diff_eq!(expected.x, actual.x, epsilon = 1e-12);
assert_abs_diff_eq!(expected.y, actual.y, epsilon = 1e-12);
}
for [x, y] in [[0.5, 0.5], [0.1, 0.9], [0.999, 0.001], [0.25, 0.75]] {
let expected = lat_lng(&mercator, x, y);
let actual = lat_lng(&world, x, y);
assert_abs_diff_eq!(expected.longitude(), actual.longitude(), epsilon = 5e-11);
assert_abs_diff_eq!(expected.latitude(), actual.latitude(), epsilon = 5e-11);
}
let equator = ll(0.0, 0.0);
assert_abs_diff_eq!(
mercator.height_meters_per_world_unit(&equator),
world.height_meters_per_world_unit(&equator),
epsilon = 5e-7
);
}
#[test]
fn a_north_polar_projection_stops_its_latitude_range_short_of_the_south_pole() {
let world = mapping(crs::north_polar_stereographic("test:polar"));
assert_eq!([-53.0, 90.0], world.latitude_range());
let world = mapping(crs::polar_stereographic("test:polar"));
assert_eq!([-53.0, 90.0], world.latitude_range());
}
#[test]
fn a_south_polar_projection_stops_its_latitude_range_short_of_the_north_pole() {
let Crs { converter: north, .. } = crs::polar_stereographic("test:north");
let north = Arc::new(north);
let forward = Arc::clone(&north);
let world = mapping(crs(
"test:south-polar",
move |[lng, lat]| {
let mut position = [[0.0; 2]];
forward.forward(&[[lng, -lat]], &mut position);
position[0]
},
move |position| {
let mut lng_lat = [[0.0; 2]];
north.inverse(&[position], &mut lng_lat);
[lng_lat[0][0], -lng_lat[0][1]]
},
[-4_194_304.0, 4_194_304.0],
8_388_608.0,
));
assert_eq!([-90.0, 53.0], world.latitude_range());
}
#[test]
fn the_identity_keeps_every_latitude() {
assert_eq!([-90.0, 90.0], identity().latitude_range());
}
#[test]
fn a_mercator_box_is_the_rectangle_of_its_corners() {
let world = WorldMapping::default();
let bounds = LatLngBounds::hull(ll(-10.0, -20.0), ll(30.0, 40.0));
let southwest = world.world_from_lat_lng(&bounds.southwest());
let northeast = world.world_from_lat_lng(&bounds.northeast());
let world_box = world.lng_lat_box_to_world_box(&bounds);
assert_eq!(Point::new(southwest.x, northeast.y), world_box.min);
assert_eq!(Point::new(northeast.x, southwest.y), world_box.max);
}
#[test]
fn a_polar_cap_box_holds_its_parallel_around_the_pole() {
let world = mapping(crs::north_polar_stereographic("test:polar"));
let radius = world.world_from_lat_lng(&ll(60.0, 0.0)).y - 0.5;
let world_box = world.lng_lat_box_to_world_box(&LatLngBounds::hull(ll(60.0, -180.0), ll(90.0, 180.0)));
for (inner, outer) in [(0.5 - radius, world_box.min.x), (0.5 - radius, world_box.min.y)] {
assert!(outer <= inner && outer >= inner - 0.05 * radius, "{outer} around {inner}");
}
for (inner, outer) in [(0.5 + radius, world_box.max.x), (0.5 + radius, world_box.max.y)] {
assert!(outer >= inner && outer <= inner + 0.05 * radius, "{outer} around {inner}");
}
}
#[test]
fn mercator_projects_as_web_mercator_does() {
use mln_style::geo::WrapMode;
use crate::geo::projection::Projection;
let world = WorldMapping::default();
assert!(world.wraps());
assert_eq!("mercator", world.name());
assert_eq!([-LATITUDE_MAX, LATITUDE_MAX], world.latitude_range());
let lat_lng = ll(40.75, -73.98);
let (expected, actual) = (Projection::project(&lat_lng, 3.5), world.project(&lat_lng, 3.5));
assert_abs_diff_eq!(expected.x, actual.x, epsilon = 1e-12);
assert_abs_diff_eq!(expected.y, actual.y, epsilon = 1e-12);
let point = Point::new(1000.0, 700.0);
for wrap_mode in [WrapMode::Unwrapped, WrapMode::Wrapped] {
let expected = Projection::unproject(&point, 3.5, wrap_mode).unwrap();
let actual = world.unproject(&point, 3.5, wrap_mode).unwrap();
assert_abs_diff_eq!(expected.latitude(), actual.latitude(), epsilon = 1e-12);
assert_abs_diff_eq!(expected.longitude(), actual.longitude(), epsilon = 1e-12);
}
let extent = world.tile_matrix_set().extent_at_zoom0;
assert_abs_diff_eq!(2.0 * std::f64::consts::PI * EARTH_RADIUS_M, extent, epsilon = 1e-6);
}
mod formulas {
use std::f64::consts::PI;
use mln_style::constants::{DEGREES_MAX, LATITUDE_MAX, LONGITUDE_MAX, TILE_SIZE_D};
use mln_style::geo::{LatLng, WrapMode};
use mln_style::math::{clamp_f64, deg2rad, rad2deg};
use crate::geo::constants::M2PI;
pub(super) fn center_offset(center: &LatLng, scale: f64) -> (f64, f64) {
let world_size = scale * TILE_SIZE_D;
let latitude = deg2rad(center.latitude());
(-center.longitude() * (world_size / 360.0), world_size / M2PI * latitude.tan().asinh())
}
pub(super) fn center(x: f64, y: f64, scale: f64) -> LatLng {
let world_size = scale * TILE_SIZE_D;
LatLng::saturating(
rad2deg(2.0 * (y / (world_size / M2PI)).exp().atan() - 0.5 * PI),
-x / (world_size / 360.0),
WrapMode::Unwrapped,
)
}
pub(super) fn project(lat_lng: &LatLng, scale: f64) -> (f64, f64) {
let latitude = clamp_f64(lat_lng.latitude(), -LATITUDE_MAX, LATITUDE_MAX);
let k = scale * TILE_SIZE_D / DEGREES_MAX;
(
(LONGITUDE_MAX + lat_lng.longitude()) * k,
(LONGITUDE_MAX - rad2deg((PI / 4.0 + latitude * PI / DEGREES_MAX).tan().ln())) * k,
)
}
pub(super) fn unproject(x: f64, y: f64, scale: f64) -> (f64, f64) {
let world_size = scale * TILE_SIZE_D;
let (x, y) = (x * DEGREES_MAX / world_size, y * DEGREES_MAX / world_size);
(deg2rad(LONGITUDE_MAX - y).exp().atan() * DEGREES_MAX / PI - 90.0, x - LONGITUDE_MAX)
}
}
fn sweep_latitudes() -> impl Iterator<Item = f64> {
(-1800..=1800).map(|step| f64::from(step) / 20.0).chain([
LATITUDE_MAX,
-LATITUDE_MAX,
85.06,
-85.06,
89.999_999,
-89.999_999,
37.7749,
-33.8688,
79.5,
1e-9,
])
}
const SWEEP_LONGITUDES: [f64; 6] = [-200.0, -122.4194, 0.0, 12.5, 151.2093, 180.0];
fn sweep_scales() -> impl Iterator<Item = f64> {
[-1.5, 0.0, 1.7, 3.5, 10.0, 12.5, 22.0, 25.5].into_iter().map(f64::exp2).chain([1.0 / TILE_SIZE_D])
}
fn assert_close(expected: f64, actual: f64, magnitude: f64, what: &str, at: [f64; 3]) {
let tolerance = 1e-12 * expected.abs().max(actual.abs()).max(magnitude).max(1.0);
assert!(
expected == actual || (expected - actual).abs() <= tolerance,
"{what} at {at:?}: {expected:e} and {actual:e}"
);
}
#[test]
fn mercator_converts_the_center_as_the_closed_forms_do() {
use mln_style::geo::WrapMode;
let mercator = WorldMapping::default();
for scale in sweep_scales() {
for longitude in SWEEP_LONGITUDES {
for latitude in sweep_latitudes() {
let at = [latitude, longitude, scale];
let center = ll(latitude, longitude);
let (x, y) = formulas::center_offset(¢er, scale);
let point = mercator.project_from_center(¢er, scale);
assert_close(x, -point.x, scale * TILE_SIZE_D, "x", at);
assert_close(y, -point.y, scale * TILE_SIZE_D, "y", at);
let expected = formulas::center(x, y, scale);
let actual = mercator.unproject_from_center(&point, scale, WrapMode::Unwrapped);
assert_abs_diff_eq!(expected.latitude(), actual.latitude(), epsilon = 1e-9);
assert_abs_diff_eq!(expected.longitude(), actual.longitude(), epsilon = 1e-9);
assert_abs_diff_eq!(latitude, actual.latitude(), epsilon = 1e-9);
}
}
}
}
#[test]
fn mercator_converts_points_as_the_closed_forms_do() {
use mln_style::geo::WrapMode;
let mercator = WorldMapping::default();
for longitude in SWEEP_LONGITUDES {
for latitude in sweep_latitudes() {
let location = ll(latitude, longitude);
let expected = Projection::meters_per_pixel_at_latitude(latitude, 0.0) * TILE_SIZE_D;
assert_close(
expected,
mercator.height_meters_per_world_unit(&location),
0.0,
"height",
[latitude, longitude, 0.0],
);
}
}
for scale in sweep_scales() {
for longitude in SWEEP_LONGITUDES {
for latitude in sweep_latitudes() {
let at = [latitude, longitude, scale];
let (x, y) = formulas::project(&ll(latitude, longitude), scale);
let point = mercator.project(&ll(latitude, longitude), scale);
assert_close(x, point.x, scale * TILE_SIZE_D, "x", at);
assert_close(y, point.y, scale * TILE_SIZE_D, "y", at);
}
}
let world_size = scale * TILE_SIZE_D;
for column in -20..=40 {
for row in -20..=40 {
let place = [f64::from(column) / 20.0 + 0.012_3, f64::from(row) / 20.0 + 0.004_56];
let (latitude, longitude) = formulas::unproject(place[0] * world_size, place[1] * world_size, scale);
let point = Point::new(place[0] * world_size, place[1] * world_size);
let actual = mercator.unproject(&point, scale, WrapMode::Unwrapped).unwrap();
assert_abs_diff_eq!(latitude, actual.latitude(), epsilon = 1e-9);
assert_abs_diff_eq!(longitude, actual.longitude(), epsilon = 1e-9);
let mut lng_lat = [[0.0; 2]];
mercator.lng_lats_from_world(&[place], &mut lng_lat);
assert_abs_diff_eq!(latitude, lng_lat[0][1], epsilon = 1e-9);
assert_abs_diff_eq!(longitude, lng_lat[0][0], epsilon = 1e-9);
}
}
}
}
#[test]
fn a_mercator_view_keeps_its_center() {
use mln_style::geo::WrapMode;
use mln_style::size::Size;
use mln_style::types::{ProjectionDefinition, ProjectionType};
use crate::camera::{Camera, LogicalExtent, MapView, ProjectionMode, Viewport, zoom_scale};
for (projection, zoom) in [
(ProjectionType::Mercator, 1.7),
(ProjectionType::Mercator, 12.5),
(ProjectionType::VerticalPerspective, 3.5),
(ProjectionType::VerticalPerspective, 10.0),
] {
for latitude in [-79.5, -33.8688, 0.0, 10.0, 37.7749, 79.5] {
for longitude in [-200.0, -122.4194, 151.2093] {
let at = [latitude, longitude, zoom];
let center = ll(latitude, longitude);
let view = MapView {
camera: Camera { center, zoom, fov: 36.87, ..Camera::default() },
extent: LogicalExtent::new(Size::new(512, 512), 1.0),
projection_mode: ProjectionMode::default(),
viewport: Viewport::default(),
projection: ProjectionDefinition::new(projection).into(),
}
.to_view()
.unwrap();
assert_eq!(projection == ProjectionType::VerticalPerspective, view.is_globe());
let (x, y) = formulas::center_offset(¢er, zoom_scale(zoom));
assert_close(x, view.x(), zoom_scale(zoom) * TILE_SIZE_D, "x", at);
assert_close(y, view.y(), zoom_scale(zoom) * TILE_SIZE_D, "y", at);
let actual = view.center(WrapMode::Unwrapped);
assert_abs_diff_eq!(latitude, actual.latitude(), epsilon = 1e-12);
assert_abs_diff_eq!(longitude, actual.longitude(), epsilon = 1e-12);
let meters = Projection::meters_per_pixel_at_latitude(latitude, view.zoom());
assert_close(meters, view.meters_per_pixel(), 0.0, "meters per pixel", at);
}
}
}
}
#[test]
fn mappings_are_equal_when_they_are_the_same_one() {
let a = identity();
assert_eq!(a, a.clone());
assert_ne!(a, identity());
assert_ne!(a, WorldMapping::default());
assert_eq!(WorldMapping::default(), WorldMapping::default());
}
#[test]
fn a_world_that_doesnt_wrap_has_no_latitude_range() {
let id = crate::tile::UnwrappedTileID::new(12, 758, 100);
assert_eq!([0.0, 0.0], crate::geo::lat_range(&id, &identity()));
let mercator = crate::geo::lat_range(&id, &WorldMapping::default());
assert!(mercator[1] > 84.0, "{mercator:?}");
assert!(mercator[0] > mercator[1], "{mercator:?}");
}
#[test]
fn a_tile_of_the_bottom_row_spans_to_the_worlds_south_edge() {
let world = WorldMapping::default();
let max = LATITUDE_MAX as f32;
let whole = crate::geo::lat_range(&crate::tile::UnwrappedTileID::new(0, 0, 0), &world);
assert_abs_diff_eq!(whole[0], max, epsilon = 1e-4);
assert_abs_diff_eq!(whole[1], -max, epsilon = 1e-4);
let south = crate::geo::lat_range(&crate::tile::UnwrappedTileID::new(1, 1, 1), &world);
assert_abs_diff_eq!(south[0], 0.0, epsilon = 1e-4);
assert_abs_diff_eq!(south[1], -max, epsilon = 1e-4);
}