MCPcopy Create free account
hub / github.com/Snapchat/Valdi / CoordinateResolver

Class CoordinateResolver

valdi/src/java/com/snap/valdi/utils/CoordinateResolver.kt:9–44  ·  view source on GitHub ↗

* Converts coordinates from and to pixel independent units into raw pixels */

Source from the content-addressed store, hash-verified

7 * Converts coordinates from and to pixel independent units into raw pixels
8 */
9class CoordinateResolver(pixelDensity: Float) {
10
11 private val pixelDensityF = pixelDensity
12 private val pixelDensityD = pixelDensityF.toDouble()
13
14 constructor(context: Context) : this(context.resources.displayMetrics.density)
15
16 fun toPixel(point: Float): Int {
17 return (point * pixelDensityF).roundToInt()
18 }
19
20 fun toPixel(point: Double): Int {
21 return (point * pixelDensityD).roundToInt()
22 }
23
24 fun toPixelF(point: Float): Float {
25 return (point * pixelDensityF)
26 }
27
28 fun toPixelF(point: Double): Float {
29 return (point * pixelDensityD).toFloat()
30 }
31
32 fun fromPixel(pixel: Int): Double {
33 return pixel.toDouble() / pixelDensityD
34 }
35
36 fun fromPixel(pixel: Float): Double {
37 return pixel.toDouble() / pixelDensityD
38 }
39
40 fun fromPixel(pixel: Double): Double {
41 return pixel / pixelDensityD
42 }
43
44}

Callers 7

ValdiRuntimeManagerClass · 0.50
ValdiImageViewClass · 0.50
ValdiScrollViewClass · 0.50
ShapeViewClass · 0.50
TextViewHelperClass · 0.50

Calls 1

toDoubleMethod · 0.45

Tested by

no test coverage detected