You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm doing this, to generate a list of stops for a scale bar on a map:
privatefunbuildStops(mantissas:List<Length>, exponents:IntRange) = buildList {
for (e in exponents) for (m in mantissas) add(m *10.0.pow(e))
}
val metricStops = buildStops(mantissas =listOf(1, 2, 5).map { it.meters }, exponents =-1..7)
It generates a list like
0.1 m
0.2 m
0.5 m
1 m
2 m
5 m
10 m
...
10000 km
20000 km
50000 km
but 10.0.pow(e) is a Double, and this library only has an operator overload for Length x Int. So I needed to add this helper:
Such a helper should probably be provided by the library. Looking at kotlin.time.Duration, they already have this:
publicoperatorfuntimes(scale:Double): Duration {
val intScale = scale.roundToInt()
if (intScale.toDouble() == scale) {
return times(intScale)
}
val unit = storageUnit
val result = toDouble(unit) * scale
return result.toDuration(unit)
}
If this is acceptable, I'd be happy to PR it.
The text was updated successfully, but these errors were encountered:
I'm doing this, to generate a list of stops for a scale bar on a map:
It generates a list like
but
10.0.pow(e)
is aDouble
, and this library only has an operator overload forLength
xInt
. So I needed to add this helper:Such a helper should probably be provided by the library. Looking at
kotlin.time.Duration
, they already have this:If this is acceptable, I'd be happy to PR it.
The text was updated successfully, but these errors were encountered: