Skip to content

Commit 48ed368

Browse files
committed
Fix the thickness math
1 parent 002b418 commit 48ed368

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

widgetry/src/mapspace/unzoomed.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ use geom::{Circle, Distance, PolyLine, Pt2D};
44

55
use crate::{Color, Drawable, GeomBatch, GfxCtx};
66

7-
/// Draw `Circles` and `PolyLines` with constant screen-space size, no matter how much the canvas is
8-
/// unzoomed.
9-
///
10-
/// ... But not yet. As an approximation of that, just discretize zoom into 10 buckets. Also,
11-
/// specify the behavior when barely unzoomed or zoomed in -- the shape starts being drawn in
12-
/// map-space "normally" without a constant screen-space size.
7+
/// Draw `Circles` and `PolyLines` in map-space that scale their size as the canvas is zoomed. The
8+
/// goal is to appear with roughly constant screen-space size, but for the moment, this is
9+
/// approximated by discretizing into 10 buckets. The scaling only happens when the canvas is
10+
/// zoomed out less than a value of 1.0.
1311
pub struct DrawUnzoomedShapes {
1412
lines: Vec<UnzoomedLine>,
1513
circles: Vec<UnzoomedCircle>,
@@ -53,12 +51,11 @@ impl DrawUnzoomedShapes {
5351
let (zoom, idx) = discretize_zoom(g.canvas.cam_zoom);
5452
let value = &mut self.per_zoom.borrow_mut()[idx];
5553
if value.is_none() {
56-
// Thicker shapes as we zoom out. Scale up to 5x. Never shrink past the original size.
57-
let mut thickness = (0.5 / zoom).max(1.0);
58-
// And on gigantic maps, zoom may approach 0, so avoid NaNs.
59-
if !thickness.is_finite() {
60-
thickness = 5.0;
61-
}
54+
// Never shrink past the original size -- always at least 1.0.
55+
// zoom ranges between [0.0, 1.0], and we want thicker shapes as zoom approaches 0.
56+
let max = 5.0;
57+
// So thickness ranges between [1.0, 5.0]
58+
let thickness = 1.0 + (max - 1.0) * (1.0 - zoom);
6259

6360
let mut batch = GeomBatch::new();
6461
render_lines(&mut batch, &self.lines, thickness);
@@ -98,6 +95,8 @@ impl DrawUnzoomedShapesBuilder {
9895

9996
// Continuously changing road width as we zoom looks great, but it's terribly slow. We'd have to
10097
// move line thickening into the shader to do it better. So recalculate with less granularity.
98+
//
99+
// Returns ([0.0, 1.0], [0, 10])
101100
fn discretize_zoom(zoom: f64) -> (f64, usize) {
102101
if zoom >= 1.0 {
103102
return (1.0, 10);

0 commit comments

Comments
 (0)