Skip to main content

DensityWeight

Struct DensityWeight 

Source
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_lo the 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_hi the weight saturates at w_min, giving city cores the finest tolerance the model allows (with w_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 exponent k = 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: f64

The multiplier at saturation (0.1 gives dense areas one tenth the epsilon).

§d_lo: f64

The density (people/km²) below which the weight stays 1.

§d_hi: f64

The density above which the weight saturates at w_min.

Implementations§

Source§

impl DensityWeight

Source

pub const DEFAULT_D_LO: f64 = 5.0

The default for d_lo: below ~5 people/km², nobody is misassigned that matters.

Source

pub const DEFAULT_D_HI: f64 = 2000.0

The default for d_hi: ~2000 people/km² is already a dense city.

Source

pub fn new(w_min: f64) -> Self

Source

pub fn weight(&self, density: f64) -> f64

Returns the tolerance multiplier ∈ [w_min, 1] for a density in people/km². A NaN density or w_min ≥ 1 returns 1, which turns weighting off.

Trait Implementations§

Source§

impl Clone for DensityWeight

Source§

fn clone(&self) -> DensityWeight

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DensityWeight

Source§

impl Debug for DensityWeight

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for DensityWeight

Source§

fn eq(&self, other: &DensityWeight) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DensityWeight

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.