Skip to content

Instantly share code, notes, and snippets.

@oas004
Created December 7, 2022 22:21
Show Gist options
  • Save oas004/a5f901ae16e1e7ec436c7fbc5842f804 to your computer and use it in GitHub Desktop.
Save oas004/a5f901ae16e1e7ec436c7fbc5842f804 to your computer and use it in GitHub Desktop.
private val straightWidth: Float = width - (2 * cornerRadius)
private val straightHeight: Float = height - (2 * cornerRadius)
private val cornerArcLength: Float = (0.5 * Math.PI * cornerRadius).toFloat()
private val total = (2 * straightWidth) + (2 * straightHeight) + (4 * cornerArcLength)
internal val topRightPercent = straightWidth / 2 / total
internal val rightTopCornerPercent = topRightPercent + (cornerArcLength / total)
private val rightPercent = rightTopCornerPercent + (straightHeight / total)
private val rightBottomCornerPercent = rightPercent + (cornerArcLength / total)
private val bottomPercent = rightBottomCornerPercent + (straightWidth / total)
internal val leftBottomCornerPercent = bottomPercent + (cornerArcLength / total)
private val leftPercent = leftBottomCornerPercent + (straightHeight / total)
private val leftTopCornerPercent = leftPercent + (cornerArcLength / total)
internal val topLeftPercent = leftTopCornerPercent + (straightWidth / 2 / total)
private val topRightRange = 0f..topRightPercent
private val rightTopCornerRange = topRightPercent..rightTopCornerPercent
private val rightRange = rightTopCornerPercent..rightPercent
private val rightBottomCornerRange = rightPercent..rightBottomCornerPercent
private val bottomRange = rightBottomCornerPercent..bottomPercent
private val leftBottomCornerRange = bottomPercent..leftBottomCornerPercent
private val leftRange = leftBottomCornerPercent..leftPercent
private val leftTopCornerRange = leftPercent..leftTopCornerPercent
private val topLeftRange = leftTopCornerPercent..topLeftPercent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment