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

Class GeometricPath

valdi/src/java/com/snap/valdi/utils/GeometricPath.kt:13–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11import kotlin.math.min
12
13class GeometricPath {
14
15 val path: Path
16 get() {
17 updatePathIfNeeded()
18 return innerPath
19 }
20
21 var width: Int = 0
22 set(newValue) {
23 if (field != newValue) {
24 field = newValue
25 setDirty()
26 }
27 }
28
29 var height: Int = 0
30 set(newValue) {
31 if (field != newValue) {
32 field = newValue
33 setDirty()
34 }
35 }
36
37 val isEmpty: Boolean
38 get() = pathData == null
39
40 private val innerPath = Path()
41 private var dirty = false
42 private var pathData: ByteArray? = null
43
44 fun setPathData(pathData: ByteArray?) {
45 this.pathData = pathData
46 setDirty()
47 }
48
49 private fun setDirty() {
50 dirty = true
51 }
52
53 private fun updatePathIfNeeded() {
54 /**
55 * The `synchronized(this)` here is a speculative fix for ticket 4485
56 */
57 synchronized(this) {
58 if (dirty) {
59 dirty = false
60 innerPath.reset()
61 val pathData = pathData
62 if (pathData != null) {
63 pathDataToPath(pathData, width, height, innerPath)
64 }
65 }
66 }
67 }
68
69 companion object {
70 private fun readValue(buffer: ByteBuffer, ratio: Double, offset: Double): Float {

Callers 2

ShapeViewClass · 0.50
MaskPathRendererClass · 0.50

Calls 1

PathClass · 0.50

Tested by

no test coverage detected