Skip to content

Instantly share code, notes, and snippets.

@svinouze
Created November 10, 2020 09:39
Show Gist options
  • Save svinouze/40cb7e11b21542b1ef90668bb43a048c to your computer and use it in GitHub Desktop.
Save svinouze/40cb7e11b21542b1ef90668bb43a048c to your computer and use it in GitHub Desktop.
class SegmentCoordinatesComputer {
fun segmentCoordinates(position: Int, segmentCount: Int, width: Float, spacing: Float): SegmentCoordinates {
val segmentWidth = (width - spacing * (segmentCount - 1)) / segmentCount
val isLast = position == segmentCount - 1
val topLeft = (segmentWidth + spacing) * position
val bottomLeft = (segmentWidth + spacing) * position
val topRight = segmentWidth * (position + 1) + spacing * position
val bottomRight = segmentWidth * (position + 1) + spacing * position
return SegmentCoordinates(topLeft, topRight, bottomLeft, bottomRight)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment