extension Numeric where Self: Comparable /* NORMALIZER */ { /// normalize the current value between a min and a max interval, by adding optionaly a value. this works just like the compass normalization. for Ex, 357°, by adding +4 became 1° for [0 - 360] interval /// /// - Parameters: /// - value: the value to add /// - min: the minimum interval /// - max: the maximum interval /// - Returns: the new, transformed and normalized value func norm(byAdding value: Self,_ min: Self = 0, _ max: Self = 360) -> Self { let this = self + value return this.norm(min, max) } /// normalize the current value between a min and a max interval. This works just like the compass normalization. for Ex, -1° became 359° for [0 - 360] interval /// /// - Parameters: /// - min: the minimum interval /// - max: the maximum interval /// - Returns: the new, transformed and normalized value func norm(_ min: Self = 0, _ max: Self = 360) -> Self { var this = self while this < min { this += max } while this > max { this -= max } return this } }