Base unit available for everyone

This commit is contained in:
cdricms
2025-09-27 19:16:54 +02:00
parent 4aa420a793
commit 7f23aaa674

View File

@@ -329,8 +329,8 @@ public struct UnitValue<ValueType: ConvertibleToDouble>:
-> Bool
{
// For equality, convert both to base unit for comparison
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit()),
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit())
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit),
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit)
else {
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))"
)
}
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit()),
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit())
guard let lhsBase = lhs.converted(to: lhs.unit.category.baseUnit),
let rhsBase = rhs.converted(to: rhs.unit.category.baseUnit)
else {
return false
}
@@ -464,7 +464,7 @@ public struct UnitValue<ValueType: ConvertibleToDouble>:
// Helper to get the base unit for a category
extension UnitCategory {
func baseUnit() -> Unit {
public var baseUnit: Unit {
switch self {
case .mass: return .gram
case .length: return .meter