pub struct DensityMap<F, Z> {
    pub dimension: Rect<F>,
    pub data: Array2<Z>,
}
Expand description

Pixelized representation of the cell locations. Cells are drawn to the DensityMap like to a rasterized image. The 2D array is the input to the FFT based electrostatic force computation.

Use DensityMap::new() and DensityMap::from_data() to create a DensityMap struct.

  • F: Data type of coordinates.
  • Z: Data type of values.

Example

use libreda_pnr::db;
use libreda_pnr::metrics::placement_density::DensityMap;

// Create a 'bin image' for accumulating densities.
let mut c = DensityMap::new(
    db::Rect::new((0.0, 0.0), (10.0, 10.0)),
    (10, 10)
);
// Draw a rectangle to the density image.
let r = db::Rect::new((1.0, 1.0), (2.0, 3.0));
c.draw_rect(&r, 1.0);

// Query the density.
assert_eq!(c.density_at((1.5, 1.5).into()), 1.);

// Directly access the density bins.
// The indices may not coincide with the coordinates!
// Here this is only the case because of the very specific dimension of the density map.
assert_eq!(c.data[[0, 0]], 0.0);
assert_eq!(c.data[[1, 1]], 1.0);
assert_eq!(c.data[[2, 3]], 0.0);

Fields

dimension: Rect<F>

Offset and dimension of the drawable DensityMap.

data: Array2<Z>

Raster data of the DensityMap. Hold the sum of values, not densities.

Implementations

Consume this object and return the underlying data array.

Get reference to underlying data array.

Get mutable reference to underlying data array.

Get the area of the DensityMap as a rectangle.

Read the density at a given coordinate p. The values are interpolated by the ‘nearest neighbour’ strategy.

Panics

Panics when the point p is outside of the defined area of the density map.

Read the density at a given coordinate p. The values are interpolated by the ‘nearest neighbour’ strategy.

Returns None if p is outside of the defined region.

Get real dimension (width, height) of a bin.

Get the area of a bin.

Convert a coordinate into array indices.

Read the accumulated value at a given coordinate p. The values are interpolated by the ‘nearest neighbour’ strategy.

Panics

Panics when the point p is outside of the defined area of the density map. get_value_at() returns an Option instead of panicking.

Read the accumulated value at a given coordinate p. The values are interpolated by the ‘nearest neighbour’ strategy. Returns None if p is outside of the map region.

Create an all-zero wxh array. r defines the spanned region in the euclidean plane.

Create a DensityMap from existing data. r defines the spanned region in the euclidean plane.

Set all values to zero.

Get the location of the center of bin with index [x, y].

Get the rectangle shape of the bin at index (i, j).

Draw the rectangle r to the DensityMap by adding the value to all bins that interact with r. If a bin overlaps only partially with r then a*value is added to it where a is the fraction of the overlap.

Create a density map with lower resolution.

Down-sampling is done by creating n*n bins. Therefore the reduction_factor must divide the number of bins in both x and y direction.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.