Geometry API

Geometry API की मदद से, इरेज़र और चुनने के तरीके.

Geometry API के इस्तेमाल के बारे में जानने के लिए, मिटाने वाले टूल को लागू करने का उदाहरण देखें.

पूरे स्ट्रोक को मिटाने वाला टूल

fun eraseWholeStrokes(
    eraserBox: ImmutableBox,
    finishedStrokesState: MutableState<Set<Stroke>>,
) {
    val threshold = 0.1f

    val strokesToErase = finishedStrokesState.value.filter { stroke ->
        stroke.shape.computeCoverageIsGreaterThan(
            box = eraserBox,
            coverageThreshold = threshold,
        )
    }
    if (strokesToErase.isNotEmpty()) {
        Snapshot.withMutableSnapshot {
            finishedStrokesState.value -= strokesToErase
        }
    }
}

Compose का इस्तेमाल करने के लिए, रीकंपोज़िशन को ट्रिगर करना न भूलें. ऐसा करने से, स्ट्रोक सफलतापूर्वक हटा दिए जाते हैं. उदाहरण के लिए, एक तरीका यह है कि आप अपने composable में rememberCoroutineScope का इस्तेमाल करें और कोरुटाइन स्कोप को अपने टच ऑडियंस को पास करें. इससे, आपको Compose के दायरे में finishedStrokesState में बदलाव करने की अनुमति मिलती है.