Repository Public
1import Foundation2@testable import SheetCharts34/// Reference values generated by Generators/gen_fixtures.py (numpy, scipy, matplotlib).5struct Reference: Decodable {6 struct TickCase: Decodable { let min: Double; let max: Double; let intervals: Int; let ticks: [Double] }7 struct LogCase: Decodable { let min: Double; let max: Double; let base: Double; let powers: [Double] }8 struct DateCase: Decodable { let min: Double; let max: Double; let unit: String; let step: Int; let ticks: [Double]; let labels: [String] }9 struct DateSerialCase: Decodable { let iso: String; let serial: Double }10 struct BinCase: Decodable { let data: String; let rule: String; let edges: [Double]; let counts: [Int]; let density: [Double] }11 struct QuantileCase: Decodable { let data: String; let method: String; let p: [Double]; let q: [Double] }12 struct BoxCase: Decodable { let data: String; let q1: Double; let median: Double; let q3: Double; let whiskerLow: Double; let whiskerHigh: Double; let outliers: [Double]; let mean: Double }13 struct KDECase: Decodable { let data: String; let rule: String; let bandwidth: Double; let grid: [Double]; let density: [Double] }14 struct Fit: Decodable { let kind: String; let order: Int; let coefficients: [Double]; let r2: Double; let probe: [Double] }15 struct TrendCase: Decodable { let name: String; let x: [Double]; let y: [Double]; let fits: [Fit]; let movingAverage5: [Double] }16 struct Stack: Decodable { let values: [[Double]]; let top: [[Double]]; let base: [[Double]]; let percentTop: [[Double]]; let percentBase: [[Double]] }17 struct Contour: Decodable { let z: [[Double]]; let levels: [Double]; let lengths: [Double]; let segments: [Int] }1819 let datasets: [String: [Double]]20 let ticks: [TickCase]21 let logTicks: [LogCase]22 let dateTicks: [DateCase]23 let dateSerials: [DateSerialCase]24 let bins: [BinCase]25 let quantiles: [QuantileCase]26 let box: [BoxCase]27 let kde: [KDECase]28 let trend: [TrendCase]29 let stack: Stack30 let contour: Contour3132 static let shared: Reference = {33 let url = Bundle.module.url(forResource: "reference", withExtension: "json", subdirectory: "Fixtures")!34 return try! JSONDecoder().decode(Reference.self, from: Data(contentsOf: url))35 }()3637 static let colormaps: [String: [[Int]]] = {38 let url = Bundle.module.url(forResource: "colormaps", withExtension: "json", subdirectory: "Fixtures")!39 return try! JSONDecoder().decode([String: [[Int]]].self, from: Data(contentsOf: url))40 }()41}4243/// |a − b| ≤ atol + rtol·|b|44func close(_ a: Double, _ b: Double, rtol: Double = 1e-9, atol: Double = 0) -> Bool {45 if a == b { return true }46 return abs(a - b) <= atol + rtol * abs(b)47}48