@FloatRange(from = 0.0, to = 1.0) private fun Rect.getIntersectPercentage(realSize: IntSize, other: Rect): Float { val composableArea = realSize.height * realSize.width val heightOverlap = max(0, min(bottom, other.bottom) - max(top, other.top)) val widthOverlap = max(0, min(right, other.right) - max(left, other.left)) val intersectionArea = heightOverlap * widthOverlap return (intersectionArea.toFloat() / composableArea) }
Returns the ratio of how much this intersects with [other].