Skip to content

Commit f555429

Browse files
committed
Cleanup: NumericTextStyles/(Bounds, Precision).
1 parent aad1526 commit f555429

File tree

3 files changed

+56
-58
lines changed

3 files changed

+56
-58
lines changed

Sources/DiffableTextStylesXNumeric/Models/Bounds.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,16 @@ public struct Bounds<Value: NumericTextValue>: Equatable {
2727
@inlinable init(unchecked: (min: Value, max: Value)) {
2828
(self.min, self.max) = unchecked; precondition(min <= max)
2929
}
30+
}
31+
32+
//=----------------------------------------------------------------------------=
33+
// MARK: + Initializers
34+
//=----------------------------------------------------------------------------=
35+
36+
extension Bounds {
3037

3138
//=------------------------------------------------------------------------=
32-
// MARK: Initializers - Indirect
39+
// MARK: Indirect
3340
//=------------------------------------------------------------------------=
3441

3542
@inlinable init() {
@@ -50,7 +57,7 @@ public struct Bounds<Value: NumericTextValue>: Equatable {
5057
}
5158

5259
//=------------------------------------------------------------------------=
53-
// MARK: Initializers - Helpers
60+
// MARK: Helpers
5461
//=------------------------------------------------------------------------=
5562

5663
@inlinable static func unchecked(

Sources/DiffableTextStylesXNumeric/Models/Precision+Modes.swift

Lines changed: 0 additions & 39 deletions
This file was deleted.

Sources/DiffableTextStylesXNumeric/Models/Precision.swift

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//=----------------------------------------------------------------------------=
99

1010
import DiffableTextKit
11+
import Foundation
1112

1213
//*============================================================================*
1314
// MARK: * Precision
@@ -30,9 +31,38 @@ public struct Precision<Value: NumericTextValue>: Equatable {
3031
@inlinable init(unchecked: (lower: Count, upper: Count)) {
3132
(self.lower, self.upper) = unchecked
3233
}
34+
35+
//=------------------------------------------------------------------------=
36+
// MARK: Modes
37+
//=------------------------------------------------------------------------=
38+
39+
@inlinable func inactive() -> NumberFormatStyleConfiguration.Precision {
40+
.integerAndFractionLength(
41+
integerLimits: lower.integer ... Int.max,
42+
fractionLimits: lower.fraction ... Int.max)
43+
}
44+
45+
@inlinable func active() -> NumberFormatStyleConfiguration.Precision {
46+
.integerAndFractionLength(
47+
integerLimits: Namespace.lower.integer ... upper.integer,
48+
fractionLimits: Namespace.lower.fraction ... upper.fraction)
49+
}
50+
51+
@inlinable func interactive(_ count: Count) -> NumberFormatStyleConfiguration.Precision {
52+
.integerAndFractionLength(
53+
integerLimits: max(Namespace.lower.integer, count.integer) ... count.integer,
54+
fractionLimits: max(Namespace.lower.fraction, count.fraction) ... count.fraction)
55+
}
56+
}
57+
58+
//=----------------------------------------------------------------------------=
59+
// MARK: + Initializers
60+
//=----------------------------------------------------------------------------=
61+
62+
extension Precision {
3363

3464
//=------------------------------------------------------------------------=
35-
// MARK: Initializers - Indirect
65+
// MARK: Indirect
3666
//=------------------------------------------------------------------------=
3767

3868
@inlinable init() {
@@ -54,7 +84,7 @@ public struct Precision<Value: NumericTextValue>: Equatable {
5484
}
5585

5686
//=------------------------------------------------------------------------=
57-
// MARK: Initializers - Helpers
87+
// MARK: Helpers
5888
//=------------------------------------------------------------------------=
5989

6090
@inlinable static func unchecked(
@@ -92,6 +122,21 @@ public struct Precision<Value: NumericTextValue>: Equatable {
92122
}
93123
}
94124

125+
//=----------------------------------------------------------------------------=
126+
// MARK: + Conversions
127+
//=----------------------------------------------------------------------------=
128+
129+
extension Precision: Brrr {
130+
131+
//=------------------------------------------------------------------------=
132+
// MARK: Description
133+
//=------------------------------------------------------------------------=
134+
135+
@inlinable public var descriptors: [(key: Any, value: Any)] {
136+
Count.components.map({($0, (self.lower[$0], self.upper[$0]))})
137+
}
138+
}
139+
95140
//*============================================================================*
96141
// MARK: * Precision x Namespace
97142
//*============================================================================*
@@ -116,18 +161,3 @@ public struct Precision<Value: NumericTextValue>: Equatable {
116161
return lower...upper
117162
}
118163
}
119-
120-
//=----------------------------------------------------------------------------=
121-
// MARK: + Conversions
122-
//=----------------------------------------------------------------------------=
123-
124-
extension Precision: Brrr {
125-
126-
//=------------------------------------------------------------------------=
127-
// MARK: Description
128-
//=------------------------------------------------------------------------=
129-
130-
@inlinable public var descriptors: [(key: Any, value: Any)] {
131-
Count.components.map({($0, (self.lower[$0], self.upper[$0]))})
132-
}
133-
}

0 commit comments

Comments
 (0)