Geometry APIs

借助 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 实现,请务必触发重组,以便 从而有效消除了笔触例如,您可以使用 rememberCoroutineScope,并将协程作用域传递给 触摸监听器,让您可以在作用域内修改 finishedStrokesState 功能。