pub struct DensityWeight {
pub w_min: f64,
pub d_lo: f64,
pub d_hi: f64,
}Expand description
The map from population density to tolerance multiplier: the
weight() method takes a density in people/km² and
returns the multiplier to apply to the simplification tolerance there.
The map is shared by the builder and the live viewer (it is compiled
into the WASM module so the browser’s weighting slider runs the same
code).
weight() evaluates a piecewise curve over density d,
shaped by two knees (d_lo, d_hi) and a floor (w_min):
- Below
d_lothe weight is 1, leaving the baseline tolerance untouched. Oceans, deserts, and other empty areas therefore simplify exactly as they would unweighted, so enabling weighting causes zero size regression there. - Above
d_hithe weight saturates atw_min, giving city cores the finest tolerance the model allows (withw_min = 0.1, one tenth of the baseline). - Between the knees the curve is the power law
weight(d) = (d / d_lo)^-k, which is a straight line in log-log space. The exponentk = ln(1/w_min) / ln(d_hi/d_lo)is the unique one that meets both knees continuously. A power law fits because population density spans orders of magnitude: each doubling of density tightens the weight by the same factor, rather than spending the whole ramp on the first sliver of the range as a linear interpolation would.
Every weight is ≤ 1, so the map only ever refines: weighted simplification keeps at least the boundary detail of the unweighted baseline and adds more where people live.
Fields§
§w_min: f64The multiplier at saturation (0.1 gives dense areas one tenth the epsilon).
d_lo: f64The density (people/km²) below which the weight stays 1.
d_hi: f64The density above which the weight saturates at w_min.
Implementations§
Source§impl DensityWeight
impl DensityWeight
Sourcepub const DEFAULT_D_LO: f64 = 5.0
pub const DEFAULT_D_LO: f64 = 5.0
The default for d_lo: below ~5 people/km², nobody is misassigned
that matters.
Sourcepub const DEFAULT_D_HI: f64 = 2000.0
pub const DEFAULT_D_HI: f64 = 2000.0
The default for d_hi: ~2000 people/km² is already a dense city.
pub fn new(w_min: f64) -> Self
Trait Implementations§
Source§impl Clone for DensityWeight
impl Clone for DensityWeight
Source§fn clone(&self) -> DensityWeight
fn clone(&self) -> DensityWeight
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more