You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
//
|
|
// SeedInterval.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 01/04/2024.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
struct SeedInterval: Hashable, Comparable {
|
|
let first: Int
|
|
let last: Int
|
|
|
|
func pointsRange(tournamentLevel: TournamentLevel, teamsCount: Int) -> String {
|
|
let range = [tournamentLevel.points(for: last - 1, count: teamsCount),
|
|
tournamentLevel.points(for: first - 1, count: teamsCount)]
|
|
return range.map { $0.formatted(.number.sign(strategy: .always())) }.joined(separator: " / ") + " pts"
|
|
}
|
|
|
|
static func <(lhs: SeedInterval, rhs: SeedInterval) -> Bool {
|
|
return lhs.first < rhs.first
|
|
}
|
|
|
|
func isFixed() -> Bool {
|
|
first == 1 && last == 2
|
|
}
|
|
|
|
var count: Int {
|
|
dimension
|
|
}
|
|
|
|
private var dimension: Int {
|
|
(last - (first - 1))
|
|
}
|
|
|
|
func chunks() -> [SeedInterval]? {
|
|
if dimension > 3 {
|
|
let split = dimension / 2
|
|
if split%2 == 0 {
|
|
let firstHalf = SeedInterval(first: first, last: first + split - 1)
|
|
let secondHalf = SeedInterval(first: first + split, last: last)
|
|
return [firstHalf, secondHalf]
|
|
} else {
|
|
let firstHalf = SeedInterval(first: first, last: first + split)
|
|
let secondHalf = SeedInterval(first: first + split + 1, last: last)
|
|
return [firstHalf, secondHalf]
|
|
}
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
|
|
if dimension < 2 {
|
|
return "#\(first) / #\(last)"
|
|
} else {
|
|
return "#\(first) à #\(last)"
|
|
}
|
|
}
|
|
}
|
|
|