Skip to content

Commit f280034

Browse files
committed
code cleanup
1 parent 749df9a commit f280034

File tree

4 files changed

+93
-87
lines changed

4 files changed

+93
-87
lines changed

Package.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ let package = Package(
1313
// .watchOS(.v3)
1414
],
1515
products: [
16-
// Products define the executables and libraries produced by a package, and make them visible to other packages.
1716
.library(
1817
name: "SwiftVizScale",
1918
targets: ["SwiftVizScale"]
@@ -24,8 +23,6 @@ let package = Package(
2423
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.0"),
2524
],
2625
targets: [
27-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
28-
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2926
.target(
3027
name: "SwiftVizScale",
3128
dependencies: [.product(name: "Numerics", package: "swift-numerics")]

Sources/VisualTests/SwiftUIView.swift renamed to Sources/VisualTests/InterpolationView.swift

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -82,89 +82,6 @@ struct InterpolationSetView: View {
8282
}
8383
}
8484

85-
struct LCHValues: View {
86-
var values: [CGFloat]
87-
var name: String
88-
var body: some View {
89-
HStack {
90-
Text(name)
91-
Text("L: \(values[0])")
92-
Text("C: \(values[1])")
93-
Text("H: \(values[2])")
94-
Text("a: \(values[3])")
95-
}
96-
}
97-
98-
public init(color: CGColor, name: String) {
99-
values = LCH.components(from: color)
100-
self.name = name
101-
}
102-
}
103-
104-
@available(macOS 12.0, iOS 15.0, *)
105-
struct LCHAssembler: View {
106-
static let red = CGColor(srgbRed: 1, green: 0, blue: 0, alpha: 1)
107-
static let blue = CGColor(srgbRed: 0, green: 0, blue: 1, alpha: 1)
108-
static let green = CGColor(srgbRed: 0, green: 1, blue: 0, alpha: 1)
109-
static let white = CGColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
110-
static let black = CGColor(srgbRed: 0, green: 0, blue: 0, alpha: 1)
111-
112-
static let yellow = CGColor(srgbRed: 1, green: 1, blue: 0, alpha: 1)
113-
static let purple = CGColor(srgbRed: 1, green: 0, blue: 1, alpha: 1)
114-
static let teal = CGColor(srgbRed: 0, green: 1, blue: 1, alpha: 1)
115-
@State private var L: CGFloat = 100 // luminance ( 0 - 100 )
116-
@State private var C: CGFloat = 130 // chroma ( 0 - 130 )
117-
@State private var H: CGFloat = 0 // hue ( iterations of 2*.pi )
118-
119-
let decimal: NumberFormatter = {
120-
let formatter = NumberFormatter()
121-
formatter.numberStyle = .decimal
122-
return formatter
123-
}()
124-
125-
var tau: CGFloat {
126-
CGFloat(Double.pi * 2)
127-
}
128-
129-
func colorFromLCHComponents(_ l: CGFloat, _ c: CGFloat, _ h: CGFloat) -> CGColor {
130-
LCH.color(from: [l, c, h, 1.0])
131-
}
132-
133-
var body: some View {
134-
VStack {
135-
Group {
136-
LCHValues(color: LCHAssembler.red, name: "red")
137-
LCHValues(color: LCHAssembler.blue, name: "blue")
138-
LCHValues(color: LCHAssembler.green, name: "green")
139-
140-
LCHValues(color: LCHAssembler.white, name: "white")
141-
LCHValues(color: LCHAssembler.black, name: "black")
142-
143-
LCHValues(color: LCHAssembler.yellow, name: "yellow")
144-
LCHValues(color: LCHAssembler.purple, name: "purple")
145-
LCHValues(color: LCHAssembler.teal, name: "teal")
146-
}
147-
Form {
148-
TextField("L", value: $L, formatter: decimal)
149-
TextField("C", value: $C, formatter: decimal)
150-
TextField("H", value: $H, formatter: decimal)
151-
Slider(value: $H, in: -tau ... tau, step: 0.1)
152-
}
153-
Text("\(L), \(C), \(H)")
154-
Color(cgColor: colorFromLCHComponents(L, C, H))
155-
.frame(width: 40, height: 40)
156-
}
157-
.padding()
158-
}
159-
}
160-
161-
@available(macOS 12.0, iOS 15.0, *)
162-
struct LCHAssembler_Previews: PreviewProvider {
163-
static var previews: some View {
164-
LCHAssembler()
165-
}
166-
}
167-
16885
@available(macOS 12.0, iOS 15.0, *)
16986
struct InterpolationView_Previews: PreviewProvider {
17087
static let red = CGColor(srgbRed: 1, green: 0, blue: 0, alpha: 1)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
//
2+
// LCHAssembler.swift
3+
//
4+
5+
import SwiftUI
6+
@testable import SwiftVizScale
7+
8+
/// Displays the Luminance, Chroma, Hue, and gamma values for LCH components of the color you provide.
9+
struct LCHValues: View {
10+
var values: [CGFloat]
11+
var name: String
12+
var body: some View {
13+
HStack {
14+
Text(name)
15+
Text("L: \(values[0])")
16+
Text("C: \(values[1])")
17+
Text("H: \(values[2])")
18+
Text("a: \(values[3])")
19+
}
20+
}
21+
22+
public init(color: CGColor, name: String) {
23+
values = LCH.components(from: color)
24+
self.name = name
25+
}
26+
}
27+
28+
@available(macOS 12.0, iOS 15.0, *)
29+
struct LCHAssembler: View {
30+
static let red = CGColor(srgbRed: 1, green: 0, blue: 0, alpha: 1)
31+
static let blue = CGColor(srgbRed: 0, green: 0, blue: 1, alpha: 1)
32+
static let green = CGColor(srgbRed: 0, green: 1, blue: 0, alpha: 1)
33+
static let white = CGColor(srgbRed: 1, green: 1, blue: 1, alpha: 1)
34+
static let black = CGColor(srgbRed: 0, green: 0, blue: 0, alpha: 1)
35+
36+
static let yellow = CGColor(srgbRed: 1, green: 1, blue: 0, alpha: 1)
37+
static let purple = CGColor(srgbRed: 1, green: 0, blue: 1, alpha: 1)
38+
static let teal = CGColor(srgbRed: 0, green: 1, blue: 1, alpha: 1)
39+
@State private var L: CGFloat = 100 // luminance ( 0 - 100 )
40+
@State private var C: CGFloat = 130 // chroma ( 0 - 130 )
41+
@State private var H: CGFloat = 0 // hue ( iterations of 2*.pi )
42+
43+
let decimal: NumberFormatter = {
44+
let formatter = NumberFormatter()
45+
formatter.numberStyle = .decimal
46+
return formatter
47+
}()
48+
49+
var tau: CGFloat {
50+
CGFloat(Double.pi * 2)
51+
}
52+
53+
func colorFromLCHComponents(_ l: CGFloat, _ c: CGFloat, _ h: CGFloat) -> CGColor {
54+
LCH.color(from: [l, c, h, 1.0])
55+
}
56+
57+
var body: some View {
58+
VStack {
59+
Group {
60+
LCHValues(color: LCHAssembler.red, name: "red")
61+
LCHValues(color: LCHAssembler.blue, name: "blue")
62+
LCHValues(color: LCHAssembler.green, name: "green")
63+
64+
LCHValues(color: LCHAssembler.white, name: "white")
65+
LCHValues(color: LCHAssembler.black, name: "black")
66+
67+
LCHValues(color: LCHAssembler.yellow, name: "yellow")
68+
LCHValues(color: LCHAssembler.purple, name: "purple")
69+
LCHValues(color: LCHAssembler.teal, name: "teal")
70+
}
71+
Form {
72+
TextField("L", value: $L, formatter: decimal)
73+
TextField("C", value: $C, formatter: decimal)
74+
TextField("H", value: $H, formatter: decimal)
75+
Slider(value: $H, in: -tau ... tau, step: 0.1)
76+
}
77+
Text("\(L), \(C), \(H)")
78+
Color(cgColor: colorFromLCHComponents(L, C, H))
79+
.frame(width: 40, height: 40)
80+
}
81+
.padding()
82+
}
83+
}
84+
85+
@available(macOS 12.0, iOS 15.0, *)
86+
struct LCHAssembler_Previews: PreviewProvider {
87+
static var previews: some View {
88+
LCHAssembler()
89+
}
90+
}

Tests/SwiftVizScaleTests/LCHTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ final class LCHTests: XCTestCase {
1717
for step in 0 ... 99 {
1818
let interpolatedColor = LCH.interpolate(black, white, t: CGFloat(step) / 100.0)
1919
let components = LCH.components(from: interpolatedColor)
20+
// This has notably looser bounds on "0" on iOS while testing w/ Github Actions simulator
2021
XCTAssertEqual(components[1], 0.0, accuracy: 0.1)
21-
// XCTAssertEqual(components[2], 0.0, accuracy: 0.001)
22+
// Hue doesn't apparently stay at 0 while testing w/ Github Actions simulator (Xcode 13.2.1)
23+
// XCTAssertEqual(components[2], 0.0, accuracy: 0.001)
2224
XCTAssertEqual(components[3], 1.0, accuracy: 0.001)
2325
}
2426
}

0 commit comments

Comments
 (0)