package com.isidroid.rendering.ext

import com.isidroid.rendering.model.PrintCanvas
import kotlin.math.max
import kotlin.math.min

private const val dpiValue = 0.0393701f
internal fun convertMmToPixels(size: Int, dpi: Int) = ((size / 100).toFloat() * dpiValue * dpi)


internal fun createOriginalSizes(
    width: Float,
    height: Float,
    printWidth: Float,
    printHeight: Float,
    marginTop: Float,
    marginLeft: Float
): PrintCanvas {
    val resultWidth = min(width, height)
    val resultHeight = max(width, height)
    val resPrintWidth = min(printWidth, printHeight)
    val resPrintHeight = max(printWidth, printHeight)

    val isSquare = resPrintWidth == printHeight
    return PrintCanvas(
        width = resultWidth,
        height = resultHeight,
        printWidth = resPrintWidth,
        printHeight = resPrintHeight,
        marginLeft = if (isSquare) marginLeft else marginTop,
        marginTop = if (!isSquare) marginLeft else marginTop,
    )
}