Skip to content

Commit 6b0b07b

Browse files
committed
improve inspector
1 parent 7eae8a8 commit 6b0b07b

3 files changed

Lines changed: 50 additions & 25 deletions

File tree

src/bin/drawing/ui/views/inspector.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,24 @@ fn selected_object(ui: &mut Ui, app_state: &mut AppState) {
2929
let selector = object.selector().clone();
3030
let tags = object.tags();
3131

32-
ui.separator();
3332
ui.label(RichText::from("Tags").strong());
3433
ui.separator();
3534

36-
ui.label(format!("{tags:#?}"));
3735
let data = tags
3836
.iter()
3937
.map(|(k, v)| (k.as_str(), v.clone()))
4038
.collect::<Vec<_>>();
4139
widget_key_value_table(ui, &data);
42-
43-
ui.separator();
44-
ui.label("Applying rules");
4540
ui.separator();
4641

4742
let mut rules = app_state.css_cache.get_matching_rules_mut(&selector);
4843
for rule in rules.iter_mut() {
49-
ui.collapsing(format!("{}", rule.selector), |ui| {
50-
add_color_picker(ui, rule, "background-color");
51-
add_color_picker(ui, rule, "border-color");
52-
add_slider_float(ui, rule, "border-width");
53-
add_slider_float(ui, rule, "line-width");
54-
add_display_none(ui, rule, "display");
55-
});
44+
ui.label(format!("{}", rule.selector));
45+
add_color_picker(ui, rule, "background-color");
46+
add_color_picker(ui, rule, "border-color");
47+
add_slider_float(ui, rule, "border-width");
48+
add_slider_float(ui, rule, "line-width");
49+
add_display_none(ui, rule, "display");
5650
}
5751
} else {
5852
ui.label("No Object selected");

src/bin/drawing/ui/views/stats.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
use egui::{Frame, Ui};
2+
use human_bytes::human_bytes;
3+
use lyon::geom::point;
4+
use nalgebra_glm::vec4;
5+
use osm::math::{num2deg, world_to_tile_space};
26

37
use crate::{app_state::AppState, drawing::ui::widgets::key_value_table::widget_key_value_table};
48

59
pub fn view_stats(ui: &mut Ui, app_state: &mut AppState) {
610
Frame::default().outer_margin(5.0).show(ui, |ui| {
711
let tile_stats = app_state.tile_cache.get_stats();
12+
let z = app_state.zoom;
13+
let screen_to_global = app_state.screen.pixel_to_world(z);
14+
let p = screen_to_global
15+
* vec4(
16+
app_state.cursor().x * 2.0,
17+
app_state.cursor().y * 2.0,
18+
0.0,
19+
0.0,
20+
);
21+
let latlon = num2deg(world_to_tile_space(&point(p.x, p.y), z.floor() as u32));
822
let data = [
923
("mouse x", app_state.cursor().x.to_string()),
10-
("mouse y", app_state.cursor().x.to_string()),
11-
("cached tiles", format!("{}", tile_stats.cached_tiles)),
12-
("loading tiles", format!("{}", tile_stats.loading_tiles)),
13-
("objects", format!("{}", tile_stats.tile_stats.objects)),
14-
("features", format!("{}", tile_stats.tile_stats.features)),
15-
("vertices", format!("{}", tile_stats.tile_stats.vertices)),
16-
("indices", format!("{}", tile_stats.tile_stats.indices)),
17-
(
18-
"size",
19-
human_bytes::human_bytes(tile_stats.tile_stats.size as f64),
20-
),
24+
("mouse y", app_state.cursor().y.to_string()),
25+
("mouse lat", latlon.y.to_string()),
26+
("mouse lon", latlon.x.to_string()),
27+
("cached tiles", tile_stats.cached_tiles.to_string()),
28+
("loading tiles", tile_stats.loading_tiles.to_string()),
29+
("objects", tile_stats.tile_stats.objects.to_string()),
30+
("features", tile_stats.tile_stats.features.to_string()),
31+
("vertices", tile_stats.tile_stats.vertices.to_string()),
32+
("indices", tile_stats.tile_stats.indices.to_string()),
33+
("size", human_bytes(tile_stats.tile_stats.size as f64)),
2134
];
2235
widget_key_value_table(ui, &data);
2336
});

src/lib/math/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod tile_field;
33
mod tile_id;
44

55
use lyon::math::{point, vector, Point};
6-
use std::f32::consts::PI;
6+
use std::f32::consts::{E, PI};
77

88
pub use screen::*;
99
pub use tile_field::*;
@@ -42,6 +42,11 @@ impl EuclidVsNalgebra for Vector2 {
4242
}
4343
}
4444

45+
/// Converts radians to degrees.
46+
const fn rad2deg(rad: f32) -> f32 {
47+
rad * 360.0 / (2.0 * PI)
48+
}
49+
4550
/// Converts degrees to radians.
4651
const fn deg2rad(deg: f32) -> f32 {
4752
2.0 * PI * deg / 360.0
@@ -56,11 +61,24 @@ pub fn deg2num(lat_deg: f32, lon_deg: f32, zoom: u32) -> TileCoordinate {
5661
let lat_rad = deg2rad(lat_deg);
5762
let n = f32::powi(2.0, zoom as i32);
5863
let xtile = (lon_deg + 180.0) / 360.0 * n;
59-
let ytile = (1.0 - (f32::tan(lat_rad) + 1.0 / f32::ln(f32::cos(lat_rad))) / PI) / 2.0 * n;
64+
let ytile = (1.0 - (PI / 4.0 + lat_rad / 2.0).tan().ln() / PI) / 2.0 * n;
6065

6166
TileCoordinate::new(zoom, xtile, ytile)
6267
}
6368

69+
/// Converts euclidian x and y coordinates into latitude and longitude.
70+
///
71+
/// This is the Mercator projection and the inverse of [`deg2num`].
72+
pub fn num2deg(tile: TileCoordinate) -> Point {
73+
let n = f32::powi(2.0, tile.z as i32);
74+
75+
let lon_deg = tile.x * 360.0 / n - 180.0;
76+
let lat_rad = 2.0 * (E.powf(1.0 - tile.y * 2.0 / n).atan() * PI - PI / 4.0);
77+
let lat_deg = rad2deg(lat_rad);
78+
79+
point(lon_deg, lat_deg)
80+
}
81+
6482
pub fn tile_to_world_space(coordinate: &TileCoordinate) -> Point {
6583
point(0.0, 0.0) + vector(coordinate.x, coordinate.y) * f32::powi(2.0, -(coordinate.z as i32))
6684
}

0 commit comments

Comments
 (0)