Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created February 9, 2018 12:57
Show Gist options
  • Save Sciss/9efbc2988ea869f16a9545b45dfebf34 to your computer and use it in GitHub Desktop.
Save Sciss/9efbc2988ea869f16a9545b45dfebf34 to your computer and use it in GitHub Desktop.
test
// given w = width in pixels, h = height in pixels, inches = diagonal in inches,
// calculate display density in ppi
// ex. calcPPI(640, 384, 7.5) = 84 ppi
def calcPPI(w: Int, h: Int, inches: Double): Double = {
val aspect = w.toDouble / h
h / (inches.squared / (aspect + 1)).sqrt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment