Skip to content

Instantly share code, notes, and snippets.

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