package com.laseroptek.raman.utils.ext

import android.content.res.Resources
import androidx.compose.ui.unit.Dp

fun Float.spaceBetween(itemCount: Int, index: Int): Float {
    if (itemCount == 1) return 0f
    val itemSize = this / (itemCount - 1)
    val positions = (0 until itemCount).map { it * itemSize }
    val result = positions[index]
    return result
}


/**
 * Convert px to dp (x 1.5 : 1280x720 to 1920x1080 = 1.5x)
 * eg. Box(modifier = Modifier.width(100.px.dp))
 */
val Int.px: Int
    get() = (this * 1.5 / Resources.getSystem().displayMetrics.density).toInt()

val Double.px: Int
    get() = (this * 1.5 / Resources.getSystem().displayMetrics.density).toInt()

val Dp.toIntPx: Int
    get() = (this / Resources.getSystem().displayMetrics.density * 0.5f).value.toInt()