Geometry API ช่วยให้คุณสร้างเครื่องมือแบบอินเทอร์แอกทีฟ เช่น กลไกการเลือกและยางลบ
ส่วนนี้จะแสดงวิธีใช้ Geometry API เพื่อใช้ยางลบ
private fun eraseIntersectingStrokes(
currentX: Float,
currentY: Float,
currentStrokes: MutableList<Stroke>,
): Unit {
val prev = previousPoint
previousPoint = MutableVec(currentX, currentY)
if (prev == null) return
val segment = MutableSegment(prev, MutableVec(currentX, currentY))
val parallelogram = MutableParallelogram().populateFromSegmentAndPadding(
segment,
eraserPadding
)
currentStrokes.removeAll {
it.shape.intersects(parallelogram, AffineTransform.IDENTITY)
}
}