Calculate shape compactness (Miller's index).
Value
If
xis a single matrix: returns a numeric scalarIf
xis a list: returns a numeric vectorIf
xis 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 × 4
#> coo type dummy coo_compactness
#> <out> <fct> <fct> <dbl>
#> 1 (138 x 2) whisky a 0.762
#> 2 (168 x 2) whisky a 0.775
#> 3 (189 x 2) whisky a 0.765
#> 4 (129 x 2) whisky a 0.793
#> 5 (152 x 2) whisky a 0.652
#> 6 (161 x 2) whisky a 0.784
#> 7 (124 x 2) whisky a 0.808
#> 8 (126 x 2) whisky a 0.766
#> 9 (183 x 2) whisky a 0.763
#> 10 (193 x 2) whisky a 0.785
#> # ℹ 30 more rows
