Base unit available for everyone
This commit is contained in:
@@ -329,8 +329,8 @@ public struct UnitValue<ValueType: ConvertibleToDouble>:
|
|||||||
-> Bool
|
-> Bool
|
||||||
{
|
{
|
||||||
// For equality, convert both to base unit for comparison
|
// For equality, convert both to base unit for comparison
|
||||||
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit()),
|
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit),
|
||||||
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit())
|
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit)
|
||||||
else {
|
else {
|
||||||
return false // Or handle error appropriately
|
return false // Or handle error appropriately
|
||||||
}
|
}
|
||||||
@@ -345,8 +345,8 @@ public struct UnitValue<ValueType: ConvertibleToDouble>:
|
|||||||
"Cannot compare UnitValues of different categories (\(lhs.unit.category) vs \(rhs.unit.category))"
|
"Cannot compare UnitValues of different categories (\(lhs.unit.category) vs \(rhs.unit.category))"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit()),
|
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit),
|
||||||
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit())
|
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit)
|
||||||
else {
|
else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -464,7 +464,7 @@ public struct UnitValue<ValueType: ConvertibleToDouble>:
|
|||||||
|
|
||||||
// Helper to get the base unit for a category
|
// Helper to get the base unit for a category
|
||||||
extension UnitCategory {
|
extension UnitCategory {
|
||||||
func baseUnit() -> Unit {
|
public var baseUnit: Unit {
|
||||||
switch self {
|
switch self {
|
||||||
case .mass: return .gram
|
case .mass: return .gram
|
||||||
case .length: return .meter
|
case .length: return .meter
|
||||||
|
|||||||
Reference in New Issue
Block a user