Skip to contents

Calculate shape compactness (Miller's index).

Usage

get_compactness(x, ..., .cols = NULL)

Arguments

x

A matrix (nx2), list of matrices, or tibble with coo columns.

...

Additional arguments (reserved for future use).

.cols

Column name(s) to process when x is a tibble. If NULL, automatically detects columns containing coo objects.

Value

  • If x is a single matrix: returns a numeric scalar

  • If x is a list: returns a numeric vector

  • If x is a tibble: returns a numeric vector extracted from coo column

Details

Compactness (Miller's index) = Area / Area(bounding_box). Value of 1 for shapes that completely fill their bounding box (rectangles). Lower values indicate less compact shapes.

Note: Polsby-Popper compactness (4π × Area / Perimeter²) is available as get_circularity().

Examples

get_compactness(shapes$cat)
#> [1] 0.5346923

# Use in measure()
bot %>% measure("compactness")
#> # A tibble: 40 × 6
#>    id           coo       type   fake  price coo_compactness
#>    <chr>        <out>     <fct>  <fct> <dbl>           <dbl>
#>  1 brahma       (138 x 2) whisky a       3             0.762
#>  2 caney        (168 x 2) whisky a       1.2           0.775
#>  3 chimay       (189 x 2) whisky a       3.8           0.765
#>  4 corona       (129 x 2) whisky a       2.6           0.793
#>  5 deusventrue  (152 x 2) whisky a       1.1           0.652
#>  6 duvel        (161 x 2) whisky a       3.1           0.784
#>  7 franziskaner (124 x 2) whisky a       2.6           0.808
#>  8 grimbergen   (126 x 2) whisky a       2.9           0.766
#>  9 guiness      (183 x 2) whisky a       1.2           0.763
#> 10 hoegardeen   (193 x 2) whisky a       3.6           0.785
#> # ℹ 30 more rows