Given height & width vectors representing input proportions, this function identifies the nearest harmonious ratio.
Usage
round_ratios(
h,
w = 1,
target = c("nearest", "taller", "wider"),
tolerance = 0.01
)Arguments
- h, w
pairwise height & width vectors representing input proportions
- target
whether to identify nearest harmonious ratio (default) or to limit to solutions where the input proportion may only be taller/wider than the harmonious ratio, see Details & Examples
- tolerance
only consider harmonious ratios within ±tolerance of input ratios, in degrees
Value
Returns a named vector of rounded proportions. Proportions that are
not within ±tolerance of a harmonious ratio with be NA.
Details
Input proportions are compared to harmonious ratios after converting to
angles with degrees(). Rounding only considers harmonious ratios that are
within ±tolerance (in degrees) of the input proportion.
By default, the nearest harmonious ratio is returned, but the target
argument can be used to favor actual proportions that run tall or wide. When
making page layout decisions, it can be useful to prefer proportions along
the spine that are a little wider than the ideal ratio. Once bound, optical
foreshortening along the spine tends to bring the perceived ratio back into
harmony.
Examples
round_ratios(3, 2)
#> fifth
#> 1.5
round_ratios(2.9999, 2)
#> fifth
#> 1.5
round_ratios(3.0001, 2)
#> fifth
#> 1.5
round_ratios(c(2.9999, 3.0001), 2, tolerance = 1e-6)
#> <NA> <NA>
#> NA NA
round_ratios(c(2.9999, 3.0001), 2, target = "taller")
#> <NA> fifth
#> NA 1.5
round_ratios(c(2.9999, 3.0001), 2, target = "wider")
#> fifth <NA>
#> 1.5 NA
