zjfjack / JZCalendarWeekView

Calendar Week & Day View in iOS Swift
MIT License
448 stars 120 forks source link

54: cell division issue in cell rendering #65

Closed btxsqdr closed 5 years ago

btxsqdr commented 5 years ago

See issue details here: https://github.com/zjfjack/JZCalendarWeekView/issues/54

From for currentY in stride(from: minY, to: maxY, by: 1) {

To for currentY in stride(from: minY, to: maxY, by: 0.1) {

Because if minY/maxY diff is < 1, stride by 1 will skip some items if too close, therefore 0.1. It is a division issue, apparently.

zjfjack commented 5 years ago

I will reject this pull request and use a new algorithm mentioned in #54 to resolve this issue.

I will try to push the new version as soon as possible, some performance, testing, comments need to be done as well. Thanks

Swift algorithm code is showing below:

func maxOverlapIntervalCount(startY: [CGFloat], endY: [CGFloat]) -> Int {
    var maxOverlap = 0, currentOverlap = 0
    let sortedStartY = startY.sorted(), sortedEndY = endY.sorted()

    var i = 0, j = 0
    while i < sortedStartY.count && j < sortedEndY.count {
        if sortedStartY[i] < sortedEndY[j] {
            currentOverlap += 1
            maxOverlap = max(maxOverlap, currentOverlap)
            i += 1
        } else {
            currentOverlap -= 1
            j += 1
        }
    }
    return maxOverlap
}