@@ -69,23 +69,7 @@ extension Measurement where UnitType : Dimension {
69
69
public mutating func convert( to otherUnit: UnitType ) {
70
70
self = converted ( to: otherUnit)
71
71
}
72
-
73
- }
74
-
75
- extension Measurement {
76
- /// Add two measurements of the same Unit.
77
- /// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
78
- /// - returns: A measurement of value `lhs.value + rhs.value` and unit `lhs.unit`.
79
- public static func + ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
80
- if lhs. unit. isEqual ( rhs. unit) {
81
- return Measurement ( value: lhs. value + rhs. value, unit: lhs. unit)
82
- } else {
83
- fatalError ( " Attempt to add measurements with non-equal units " )
84
- }
85
- }
86
- }
87
72
88
- extension Measurement where UnitType : Dimension {
89
73
/// Add two measurements of the same Dimension.
90
74
///
91
75
/// If the `unit` of the `lhs` and `rhs` are `isEqual`, then this returns the result of adding the `value` of each `Measurement`. If they are not equal, then this will convert both to the base unit of the `Dimension` and return the result as a `Measurement` of that base unit.
@@ -99,22 +83,7 @@ extension Measurement where UnitType : Dimension {
99
83
return Measurement ( value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: type ( of: lhs. unit) . baseUnit ( ) )
100
84
}
101
85
}
102
- }
103
86
104
- extension Measurement {
105
- /// Subtract two measurements of the same Unit.
106
- /// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
107
- /// - returns: A measurement of value `lhs.value - rhs.value` and unit `lhs.unit`.
108
- public static func - ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
109
- if lhs. unit. isEqual ( rhs. unit) {
110
- return Measurement ( value: lhs. value - rhs. value, unit: lhs. unit)
111
- } else {
112
- fatalError ( " Attempt to subtract measurements with non-equal units " )
113
- }
114
- }
115
- }
116
-
117
- extension Measurement where UnitType : Dimension {
118
87
/// Subtract two measurements of the same Dimension.
119
88
///
120
89
/// If the `unit` of the `lhs` and `rhs` are `==`, then this returns the result of subtracting the `value` of each `Measurement`. If they are not equal, then this will convert both to the base unit of the `Dimension` and return the result as a `Measurement` of that base unit.
@@ -128,41 +97,7 @@ extension Measurement where UnitType : Dimension {
128
97
return Measurement ( value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: type ( of: lhs. unit) . baseUnit ( ) )
129
98
}
130
99
}
131
- }
132
-
133
- extension Measurement {
134
- /// Multiply a measurement by a scalar value.
135
- /// - returns: A measurement of value `lhs.value * rhs` with the same unit as `lhs`.
136
- public static func * ( lhs: Measurement < UnitType > , rhs: Double ) -> Measurement < UnitType > {
137
- return Measurement ( value: lhs. value * rhs, unit: lhs. unit)
138
- }
139
-
140
- /// Multiply a scalar value by a measurement.
141
- /// - returns: A measurement of value `lhs * rhs.value` with the same unit as `rhs`.
142
- public static func * ( lhs: Double , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
143
- return Measurement ( value: lhs * rhs. value, unit: rhs. unit)
144
- }
145
-
146
- /// Divide a measurement by a scalar value.
147
- /// - returns: A measurement of value `lhs.value / rhs` with the same unit as `lhs`.
148
- public static func / ( lhs: Measurement < UnitType > , rhs: Double ) -> Measurement < UnitType > {
149
- return Measurement ( value: lhs. value / rhs, unit: lhs. unit)
150
- }
151
-
152
- /// Divide a scalar value by a measurement.
153
- /// - returns: A measurement of value `lhs / rhs.value` with the same unit as `rhs`.
154
- public static func / ( lhs: Double , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
155
- return Measurement ( value: lhs / rhs. value, unit: rhs. unit)
156
- }
157
-
158
- /// Compare two measurements of the same `Unit`.
159
- /// - returns: `true` if `lhs.value == rhs.value && lhs.unit == rhs.unit`.
160
- public static func == ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
161
- return lhs. value == rhs. value && lhs. unit == rhs. unit
162
- }
163
- }
164
100
165
- extension Measurement where UnitType : Dimension {
166
101
/// Compare two measurements of the same `Dimension`.
167
102
///
168
103
/// If `lhs.unit == rhs.unit`, returns `lhs.value == rhs.value`. Otherwise, converts `rhs` to the same unit as `lhs` and then compares the resulting values.
@@ -175,18 +110,7 @@ extension Measurement where UnitType : Dimension {
175
110
return lhs. value == rhsInLhs. value
176
111
}
177
112
}
178
- }
179
113
180
- extension Measurement {
181
- /// Compare two measurements of the same `Unit`.
182
- /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
183
- /// - returns: `lhs.value < rhs.value`
184
- public static func < ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
185
- return lhs. value < rhs. value
186
- }
187
- }
188
-
189
- extension Measurement where UnitType : Dimension {
190
114
/// Compare two measurements of the same `Dimension`.
191
115
///
192
116
/// If `lhs.unit == rhs.unit`, returns `lhs.value < rhs.value`. Otherwise, converts `rhs` to the same unit as `lhs` and then compares the resulting values.
@@ -199,18 +123,7 @@ extension Measurement where UnitType : Dimension {
199
123
return lhs. value < rhsInLhs. value
200
124
}
201
125
}
202
- }
203
126
204
- extension Measurement {
205
- /// Compare two measurements of the same `Unit`.
206
- /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
207
- /// - returns: `lhs.value > rhs.value`
208
- public static func > ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
209
- return lhs. value > rhs. value
210
- }
211
- }
212
-
213
- extension Measurement where UnitType : Dimension {
214
127
/// Compare two measurements of the same `Dimension`.
215
128
///
216
129
/// If `lhs.unit == rhs.unit`, returns `lhs.value > rhs.value`. Otherwise, converts `rhs` to the same unit as `lhs` and then compares the resulting values.
@@ -223,18 +136,7 @@ extension Measurement where UnitType : Dimension {
223
136
return lhs. value > rhsInLhs. value
224
137
}
225
138
}
226
- }
227
139
228
- extension Measurement {
229
- /// Compare two measurements of the same `Unit`.
230
- /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
231
- /// - returns: `lhs.value <= rhs.value`
232
- public static func <= ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
233
- return lhs. value <= rhs. value
234
- }
235
- }
236
-
237
- extension Measurement where UnitType : Dimension {
238
140
/// Compare two measurements of the same `Dimension`.
239
141
///
240
142
/// If `lhs.unit == rhs.unit`, returns `lhs.value < rhs.value`. Otherwise, converts `rhs` to the same unit as `lhs` and then compares the resulting values.
@@ -247,18 +149,7 @@ extension Measurement where UnitType : Dimension {
247
149
return lhs. value <= rhsInLhs. value
248
150
}
249
151
}
250
- }
251
-
252
- extension Measurement {
253
- /// Compare two measurements of the same `Unit`.
254
- /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
255
- /// - returns: `lhs.value >= rhs.value`
256
- public static func >= ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
257
- return lhs. value >= rhs. value
258
- }
259
- }
260
152
261
- extension Measurement where UnitType : Dimension {
262
153
/// Compare two measurements of the same `Dimension`.
263
154
///
264
155
/// If `lhs.unit == rhs.unit`, returns `lhs.value >= rhs.value`. Otherwise, converts `rhs` to the same unit as `lhs` and then compares the resulting values.
@@ -273,6 +164,86 @@ extension Measurement where UnitType : Dimension {
273
164
}
274
165
}
275
166
167
+ extension Measurement {
168
+ /// Add two measurements of the same Unit.
169
+ /// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
170
+ /// - returns: A measurement of value `lhs.value + rhs.value` and unit `lhs.unit`.
171
+ public static func + ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
172
+ if lhs. unit. isEqual ( rhs. unit) {
173
+ return Measurement ( value: lhs. value + rhs. value, unit: lhs. unit)
174
+ } else {
175
+ fatalError ( " Attempt to add measurements with non-equal units " )
176
+ }
177
+ }
178
+
179
+ /// Subtract two measurements of the same Unit.
180
+ /// - precondition: The `unit` of `lhs` and `rhs` must be `isEqual`.
181
+ /// - returns: A measurement of value `lhs.value - rhs.value` and unit `lhs.unit`.
182
+ public static func - ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
183
+ if lhs. unit. isEqual ( rhs. unit) {
184
+ return Measurement ( value: lhs. value - rhs. value, unit: lhs. unit)
185
+ } else {
186
+ fatalError ( " Attempt to subtract measurements with non-equal units " )
187
+ }
188
+ }
189
+
190
+ public static func * ( lhs: Measurement < UnitType > , rhs: Double ) -> Measurement < UnitType > {
191
+ return Measurement ( value: lhs. value * rhs, unit: lhs. unit)
192
+ }
193
+
194
+ /// Multiply a scalar value by a measurement.
195
+ /// - returns: A measurement of value `lhs * rhs.value` with the same unit as `rhs`.
196
+ public static func * ( lhs: Double , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
197
+ return Measurement ( value: lhs * rhs. value, unit: rhs. unit)
198
+ }
199
+
200
+ /// Divide a measurement by a scalar value.
201
+ /// - returns: A measurement of value `lhs.value / rhs` with the same unit as `lhs`.
202
+ public static func / ( lhs: Measurement < UnitType > , rhs: Double ) -> Measurement < UnitType > {
203
+ return Measurement ( value: lhs. value / rhs, unit: lhs. unit)
204
+ }
205
+
206
+ /// Divide a scalar value by a measurement.
207
+ /// - returns: A measurement of value `lhs / rhs.value` with the same unit as `rhs`.
208
+ public static func / ( lhs: Double , rhs: Measurement < UnitType > ) -> Measurement < UnitType > {
209
+ return Measurement ( value: lhs / rhs. value, unit: rhs. unit)
210
+ }
211
+
212
+ /// Compare two measurements of the same `Unit`.
213
+ /// - returns: `true` if `lhs.value == rhs.value && lhs.unit == rhs.unit`.
214
+ public static func == ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
215
+ return lhs. value == rhs. value && lhs. unit == rhs. unit
216
+ }
217
+
218
+ /// Compare two measurements of the same `Unit`.
219
+ /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
220
+ /// - returns: `lhs.value < rhs.value`
221
+ public static func < ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
222
+ return lhs. value < rhs. value
223
+ }
224
+
225
+ /// Compare two measurements of the same `Unit`.
226
+ /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
227
+ /// - returns: `lhs.value > rhs.value`
228
+ public static func > ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
229
+ return lhs. value > rhs. value
230
+ }
231
+
232
+ /// Compare two measurements of the same `Unit`.
233
+ /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
234
+ /// - returns: `lhs.value <= rhs.value`
235
+ public static func <= ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
236
+ return lhs. value <= rhs. value
237
+ }
238
+
239
+ /// Compare two measurements of the same `Unit`.
240
+ /// - note: This function does not check `==` for the `unit` property of `lhs` and `rhs`.
241
+ /// - returns: `lhs.value >= rhs.value`
242
+ public static func >= ( lhs: Measurement < UnitType > , rhs: Measurement < UnitType > ) -> Bool {
243
+ return lhs. value >= rhs. value
244
+ }
245
+ }
246
+
276
247
// Implementation note: similar to NSArray, NSDictionary, etc., NSMeasurement's import as an ObjC generic type is suppressed by the importer. Eventually we will need a more general purpose mechanism to correctly import generic types.
277
248
278
249
extension Measurement : _ObjectTypeBridgeable {
0 commit comments