@@ -4,12 +4,10 @@ use geom::{Circle, Distance, PolyLine, Pt2D};
4
4
5
5
use crate :: { Color , Drawable , GeomBatch , GfxCtx } ;
6
6
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.
13
11
pub struct DrawUnzoomedShapes {
14
12
lines : Vec < UnzoomedLine > ,
15
13
circles : Vec < UnzoomedCircle > ,
@@ -53,12 +51,11 @@ impl DrawUnzoomedShapes {
53
51
let ( zoom, idx) = discretize_zoom ( g. canvas . cam_zoom ) ;
54
52
let value = & mut self . per_zoom . borrow_mut ( ) [ idx] ;
55
53
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) ;
62
59
63
60
let mut batch = GeomBatch :: new ( ) ;
64
61
render_lines ( & mut batch, & self . lines , thickness) ;
@@ -98,6 +95,8 @@ impl DrawUnzoomedShapesBuilder {
98
95
99
96
// Continuously changing road width as we zoom looks great, but it's terribly slow. We'd have to
100
97
// move line thickening into the shader to do it better. So recalculate with less granularity.
98
+ //
99
+ // Returns ([0.0, 1.0], [0, 10])
101
100
fn discretize_zoom ( zoom : f64 ) -> ( f64 , usize ) {
102
101
if zoom >= 1.0 {
103
102
return ( 1.0 , 10 ) ;
0 commit comments