From 68cbd50781b58d146c324c0c2522af83b318972e Mon Sep 17 00:00:00 2001 From: Tim Alenus Date: Fri, 24 Jul 2026 09:48:28 +0200 Subject: [PATCH 1/3] feat: add isSI getter --- lib/src/core/unit.dart | 4 ++++ lib/src/units/acceleration/acceleration_unit.dart | 4 ++++ lib/src/units/angle/angle_unit.dart | 4 ++++ lib/src/units/angular_velocity/angular_velocity_unit.dart | 4 ++++ lib/src/units/area/area_unit.dart | 4 ++++ lib/src/units/current/current_unit.dart | 4 ++++ lib/src/units/density/density_unit.dart | 4 ++++ lib/src/units/electric_charge/electric_charge_unit.dart | 4 ++++ lib/src/units/energy/energy_unit.dart | 4 ++++ lib/src/units/force/force_unit.dart | 4 ++++ lib/src/units/frequency/frequency_unit.dart | 4 ++++ lib/src/units/fuel_consumption/fuel_consumption_unit.dart | 5 +++++ lib/src/units/information/information_unit.dart | 5 +++++ lib/src/units/length/length_unit.dart | 4 ++++ lib/src/units/level_ratio/level_ratio_unit.dart | 5 +++++ lib/src/units/luminous/luminous_intensity_unit.dart | 4 ++++ lib/src/units/mass/mass_unit.dart | 4 ++++ lib/src/units/molar/molar_unit.dart | 4 ++++ lib/src/units/power/power_unit.dart | 4 ++++ lib/src/units/power_level/power_level_unit.dart | 5 +++++ lib/src/units/pressure/pressure_unit.dart | 4 ++++ lib/src/units/resistance/resistance_unit.dart | 4 ++++ lib/src/units/solid_angle/solid_angle_unit.dart | 4 ++++ .../sound_pressure_level/sound_pressure_level_unit.dart | 5 +++++ lib/src/units/specific_energy/specific_energy_unit.dart | 4 ++++ lib/src/units/speed/speed_unit.dart | 4 ++++ lib/src/units/temperature/temperature_delta_unit.dart | 4 ++++ lib/src/units/temperature/temperature_unit.dart | 4 ++++ lib/src/units/time/time_unit.dart | 4 ++++ lib/src/units/torque/torque_unit.dart | 4 ++++ lib/src/units/voltage/voltage_unit.dart | 4 ++++ lib/src/units/voltage_level/voltage_level_unit.dart | 5 +++++ lib/src/units/volume/volume_unit.dart | 4 ++++ 33 files changed, 138 insertions(+) diff --git a/lib/src/core/unit.dart b/lib/src/core/unit.dart index 6d6e9b9..509c352 100644 --- a/lib/src/core/unit.dart +++ b/lib/src/core/unit.dart @@ -12,6 +12,10 @@ abstract class Unit> { /// A human-readable symbol or abbreviation for the unit. String get symbol; + + /// Returns `true` if this unit is part of the International System of Units (SI). + /// if the unit is SI derived, this will return `true` only for the base unit of that dimension. + bool get isSI; } /// A contract for units that scale linearly (via a simple multiplier). diff --git a/lib/src/units/acceleration/acceleration_unit.dart b/lib/src/units/acceleration/acceleration_unit.dart index efabd1b..073d426 100644 --- a/lib/src/units/acceleration/acceleration_unit.dart +++ b/lib/src/units/acceleration/acceleration_unit.dart @@ -107,6 +107,10 @@ enum AccelerationUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [meterPerSecondSquared], the SI derived unit of acceleration. + @override + bool get isSI => this == AccelerationUnit.meterPerSecondSquared; + // --- Pre-calculated direct conversion factors --- final double _factorToMeterPerSecondSquared; final double _factorToStandardGravity; diff --git a/lib/src/units/angle/angle_unit.dart b/lib/src/units/angle/angle_unit.dart index c169b7b..ab806f2 100644 --- a/lib/src/units/angle/angle_unit.dart +++ b/lib/src/units/angle/angle_unit.dart @@ -57,6 +57,10 @@ enum AngleUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [radian], the SI derived unit of plane angle. + @override + bool get isSI => this == AngleUnit.radian; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToRadian; final double _factorToDegree; diff --git a/lib/src/units/angular_velocity/angular_velocity_unit.dart b/lib/src/units/angular_velocity/angular_velocity_unit.dart index e1ff7b0..2e31743 100644 --- a/lib/src/units/angular_velocity/angular_velocity_unit.dart +++ b/lib/src/units/angular_velocity/angular_velocity_unit.dart @@ -65,6 +65,10 @@ enum AngularVelocityUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [radianPerSecond], the SI derived unit of angular velocity. + @override + bool get isSI => this == AngularVelocityUnit.radianPerSecond; + // --- Pre-calculated direct conversion factors --- final double _factorToRadianPerSecond; final double _factorToDegreePerSecond; diff --git a/lib/src/units/area/area_unit.dart b/lib/src/units/area/area_unit.dart index 29b5b76..27753f8 100644 --- a/lib/src/units/area/area_unit.dart +++ b/lib/src/units/area/area_unit.dart @@ -80,6 +80,10 @@ enum AreaUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [squareMeter], the SI derived unit of area. + @override + bool get isSI => this == AreaUnit.squareMeter; + // --- Pre-calculated direct conversion factors --- final double _factorToSquareMeter; final double _factorToSquareDecimeter; diff --git a/lib/src/units/current/current_unit.dart b/lib/src/units/current/current_unit.dart index 3f651a2..f027939 100644 --- a/lib/src/units/current/current_unit.dart +++ b/lib/src/units/current/current_unit.dart @@ -80,6 +80,10 @@ enum CurrentUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [ampere], the SI base unit of electric current. + @override + bool get isSI => this == CurrentUnit.ampere; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToAmpere; final double _factorToMilliampere; diff --git a/lib/src/units/density/density_unit.dart b/lib/src/units/density/density_unit.dart index bdeef2d..c98445c 100644 --- a/lib/src/units/density/density_unit.dart +++ b/lib/src/units/density/density_unit.dart @@ -58,6 +58,10 @@ enum DensityUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [kilogramPerCubicMeter], the SI derived unit of density. + @override + bool get isSI => this == DensityUnit.kilogramPerCubicMeter; + // --- Pre-calculated direct conversion factors --- final double _factorToKilogramPerCubicMeter; final double _factorToGramPerCubicCentimeter; diff --git a/lib/src/units/electric_charge/electric_charge_unit.dart b/lib/src/units/electric_charge/electric_charge_unit.dart index 67d5e58..67d7114 100644 --- a/lib/src/units/electric_charge/electric_charge_unit.dart +++ b/lib/src/units/electric_charge/electric_charge_unit.dart @@ -69,6 +69,10 @@ enum ElectricChargeUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [coulomb], the SI derived unit of electric charge. + @override + bool get isSI => this == ElectricChargeUnit.coulomb; + // --- Pre-calculated direct conversion factors --- final double _factorToCoulomb; final double _factorToKilocoulomb; diff --git a/lib/src/units/energy/energy_unit.dart b/lib/src/units/energy/energy_unit.dart index df2f945..52feb51 100644 --- a/lib/src/units/energy/energy_unit.dart +++ b/lib/src/units/energy/energy_unit.dart @@ -95,6 +95,10 @@ enum EnergyUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [joule], the SI derived unit of energy. + @override + bool get isSI => this == EnergyUnit.joule; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToJoule; final double _factorToMillijoule; diff --git a/lib/src/units/force/force_unit.dart b/lib/src/units/force/force_unit.dart index 27c47ca..3a78c37 100644 --- a/lib/src/units/force/force_unit.dart +++ b/lib/src/units/force/force_unit.dart @@ -68,6 +68,10 @@ enum ForceUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [newton], the SI derived unit of force. + @override + bool get isSI => this == ForceUnit.newton; + // --- Pre-calculated direct conversion factors --- final double _factorToNewton; final double _factorToNanonewton; diff --git a/lib/src/units/frequency/frequency_unit.dart b/lib/src/units/frequency/frequency_unit.dart index 36beea1..f50cbd3 100644 --- a/lib/src/units/frequency/frequency_unit.dart +++ b/lib/src/units/frequency/frequency_unit.dart @@ -60,6 +60,10 @@ enum FrequencyUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [hertz], the SI derived unit of frequency. + @override + bool get isSI => this == FrequencyUnit.hertz; + // --- Pre-calculated direct conversion factors --- final double _factorToHertz; final double _factorToTerahertz; diff --git a/lib/src/units/fuel_consumption/fuel_consumption_unit.dart b/lib/src/units/fuel_consumption/fuel_consumption_unit.dart index 30503f4..d2c704d 100644 --- a/lib/src/units/fuel_consumption/fuel_consumption_unit.dart +++ b/lib/src/units/fuel_consumption/fuel_consumption_unit.dart @@ -26,6 +26,11 @@ enum FuelConsumptionUnit implements Unit { @override final String symbol; + /// None of these fuel-economy units are part of the SI, so this always + /// returns `false`. + @override + bool get isSI => false; + /// Unit symbols matched strictly case-sensitive. /// /// Note: The unqualified abbreviation `mpg` defaults to US gallons. diff --git a/lib/src/units/information/information_unit.dart b/lib/src/units/information/information_unit.dart index e87fc1d..c67f77c 100644 --- a/lib/src/units/information/information_unit.dart +++ b/lib/src/units/information/information_unit.dart @@ -147,6 +147,11 @@ enum InformationUnit implements LinearUnit { @override final String symbol; + /// The SI does not define a unit for digital information, so this always + /// returns `false`, even for units that use SI decimal prefixes (e.g. [kilobit]). + @override + bool get isSI => false; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToBit; final double _factorToByte; diff --git a/lib/src/units/length/length_unit.dart b/lib/src/units/length/length_unit.dart index de7a71b..762209f 100644 --- a/lib/src/units/length/length_unit.dart +++ b/lib/src/units/length/length_unit.dart @@ -119,6 +119,10 @@ enum LengthUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [meter], the SI base unit of length. + @override + bool get isSI => this == LengthUnit.meter; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToMeter; final double _factorToKilometer; diff --git a/lib/src/units/level_ratio/level_ratio_unit.dart b/lib/src/units/level_ratio/level_ratio_unit.dart index 0a9dfdf..1055f4e 100644 --- a/lib/src/units/level_ratio/level_ratio_unit.dart +++ b/lib/src/units/level_ratio/level_ratio_unit.dart @@ -23,6 +23,11 @@ enum LevelRatioUnit implements LinearUnit { @override final String symbol; + /// The decibel and neper are non-SI units accepted for use with the SI, + /// but neither is itself an SI unit, so this always returns `false`. + @override + bool get isSI => false; + final double _factorToDecibel; final double _factorToNeper; diff --git a/lib/src/units/luminous/luminous_intensity_unit.dart b/lib/src/units/luminous/luminous_intensity_unit.dart index 2284dec..f0e6269 100644 --- a/lib/src/units/luminous/luminous_intensity_unit.dart +++ b/lib/src/units/luminous/luminous_intensity_unit.dart @@ -92,6 +92,10 @@ enum LuminousIntensityUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [candela], the SI base unit of luminous intensity. + @override + bool get isSI => this == LuminousIntensityUnit.candela; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToCandela; final double _factorToMillicandela; diff --git a/lib/src/units/mass/mass_unit.dart b/lib/src/units/mass/mass_unit.dart index abea816..3cb0936 100644 --- a/lib/src/units/mass/mass_unit.dart +++ b/lib/src/units/mass/mass_unit.dart @@ -117,6 +117,10 @@ enum MassUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [kilogram], the SI base unit of mass. + @override + bool get isSI => this == MassUnit.kilogram; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToKilogram; final double _factorToHectogram; diff --git a/lib/src/units/molar/molar_unit.dart b/lib/src/units/molar/molar_unit.dart index cce25d7..9b21ee5 100644 --- a/lib/src/units/molar/molar_unit.dart +++ b/lib/src/units/molar/molar_unit.dart @@ -108,6 +108,10 @@ enum MolarUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [mole], the SI base unit for amount of substance. + @override + bool get isSI => this == MolarUnit.mole; + // --- Pre-calculated direct conversion factors from this unit to all others --- // These are calculated once in the const constructor for performance. diff --git a/lib/src/units/power/power_unit.dart b/lib/src/units/power/power_unit.dart index e5499cb..c55223d 100644 --- a/lib/src/units/power/power_unit.dart +++ b/lib/src/units/power/power_unit.dart @@ -74,6 +74,10 @@ enum PowerUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [watt], the SI derived unit of power. + @override + bool get isSI => this == PowerUnit.watt; + // --- Pre-calculated direct conversion factors --- final double _factorToWatt; final double _factorToNanowatt; diff --git a/lib/src/units/power_level/power_level_unit.dart b/lib/src/units/power_level/power_level_unit.dart index 84e6d89..e90d611 100644 --- a/lib/src/units/power_level/power_level_unit.dart +++ b/lib/src/units/power_level/power_level_unit.dart @@ -20,6 +20,11 @@ enum PowerLevelUnit implements Unit { @override final String symbol; + /// Logarithmic decibel-based power levels are not SI units, so this + /// always returns `false`. + @override + bool get isSI => false; + /// Unit symbols matched strictly case-sensitive. @internal static const Map symbolAliases = { diff --git a/lib/src/units/pressure/pressure_unit.dart b/lib/src/units/pressure/pressure_unit.dart index ac242b2..96cd5cf 100644 --- a/lib/src/units/pressure/pressure_unit.dart +++ b/lib/src/units/pressure/pressure_unit.dart @@ -91,6 +91,10 @@ enum PressureUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [pascal], the SI derived unit of pressure. + @override + bool get isSI => this == PressureUnit.pascal; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToPascal; final double _factorToMicropascal; diff --git a/lib/src/units/resistance/resistance_unit.dart b/lib/src/units/resistance/resistance_unit.dart index 160f529..f70130c 100644 --- a/lib/src/units/resistance/resistance_unit.dart +++ b/lib/src/units/resistance/resistance_unit.dart @@ -59,6 +59,10 @@ enum ResistanceUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [ohm], the SI derived unit of electrical resistance. + @override + bool get isSI => this == ResistanceUnit.ohm; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToOhm; final double _factorToNanoohm; diff --git a/lib/src/units/solid_angle/solid_angle_unit.dart b/lib/src/units/solid_angle/solid_angle_unit.dart index 4f4efc0..847040f 100644 --- a/lib/src/units/solid_angle/solid_angle_unit.dart +++ b/lib/src/units/solid_angle/solid_angle_unit.dart @@ -49,6 +49,10 @@ enum SolidAngleUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [steradian], the SI derived unit of solid angle. + @override + bool get isSI => this == SolidAngleUnit.steradian; + // --- Pre-calculated direct conversion factors --- final double _factorToSteradian; final double _factorToSquareDegree; diff --git a/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart b/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart index 10f58dc..8b3b347 100644 --- a/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart +++ b/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart @@ -14,6 +14,11 @@ enum SoundPressureLevelUnit implements Unit { @override final String symbol; + /// Logarithmic decibel-based sound pressure levels are not SI units, so + /// this always returns `false`. + @override + bool get isSI => false; + /// Unit symbols matched strictly case-sensitive. @internal static const Map symbolAliases = { diff --git a/lib/src/units/specific_energy/specific_energy_unit.dart b/lib/src/units/specific_energy/specific_energy_unit.dart index 52ff4d3..bab2089 100644 --- a/lib/src/units/specific_energy/specific_energy_unit.dart +++ b/lib/src/units/specific_energy/specific_energy_unit.dart @@ -65,6 +65,10 @@ enum SpecificEnergyUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [joulePerKilogram], the SI derived unit of specific energy. + @override + bool get isSI => this == SpecificEnergyUnit.joulePerKilogram; + // --- Pre-calculated direct conversion factors --- final double _factorToJoulePerKilogram; final double _factorToKilojoulePerKilogram; diff --git a/lib/src/units/speed/speed_unit.dart b/lib/src/units/speed/speed_unit.dart index 1744a88..2c4b7c8 100644 --- a/lib/src/units/speed/speed_unit.dart +++ b/lib/src/units/speed/speed_unit.dart @@ -51,6 +51,10 @@ enum SpeedUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [meterPerSecond], the SI derived unit of speed. + @override + bool get isSI => this == SpeedUnit.meterPerSecond; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToMeterPerSecond; final double _factorToKilometerPerSecond; diff --git a/lib/src/units/temperature/temperature_delta_unit.dart b/lib/src/units/temperature/temperature_delta_unit.dart index 30351c3..9586747 100644 --- a/lib/src/units/temperature/temperature_delta_unit.dart +++ b/lib/src/units/temperature/temperature_delta_unit.dart @@ -76,6 +76,10 @@ enum TemperatureDeltaUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [kelvinDelta], based on the SI base unit Kelvin. + @override + bool get isSI => this == TemperatureDeltaUnit.kelvinDelta; + // --- Pre-calculated direct conversion factors --- final double _factorToKelvinDelta; final double _factorToCelsiusDelta; diff --git a/lib/src/units/temperature/temperature_unit.dart b/lib/src/units/temperature/temperature_unit.dart index 27c4ada..f7810b2 100644 --- a/lib/src/units/temperature/temperature_unit.dart +++ b/lib/src/units/temperature/temperature_unit.dart @@ -27,6 +27,10 @@ enum TemperatureUnit implements Unit { @override final String symbol; + /// Returns `true` only for [kelvin], the SI base unit of thermodynamic temperature. + @override + bool get isSI => this == TemperatureUnit.kelvin; + /// SI and unit symbols matched **strictly case-sensitive**. static const Map symbolAliases = { '°C': celsius, diff --git a/lib/src/units/time/time_unit.dart b/lib/src/units/time/time_unit.dart index 81abe0e..f658195 100644 --- a/lib/src/units/time/time_unit.dart +++ b/lib/src/units/time/time_unit.dart @@ -117,6 +117,10 @@ enum TimeUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [second], the SI base unit of time. + @override + bool get isSI => this == TimeUnit.second; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToSecond; final double _factorToMicrosecond; diff --git a/lib/src/units/torque/torque_unit.dart b/lib/src/units/torque/torque_unit.dart index 9de7008..836c705 100644 --- a/lib/src/units/torque/torque_unit.dart +++ b/lib/src/units/torque/torque_unit.dart @@ -68,6 +68,10 @@ enum TorqueUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [newtonMeter], the SI derived unit of torque. + @override + bool get isSI => this == TorqueUnit.newtonMeter; + // --- Pre-calculated direct conversion factors --- final double _factorToNewtonMeter; final double _factorToMillinewtonMeter; diff --git a/lib/src/units/voltage/voltage_unit.dart b/lib/src/units/voltage/voltage_unit.dart index edd3c95..3f59c2c 100644 --- a/lib/src/units/voltage/voltage_unit.dart +++ b/lib/src/units/voltage/voltage_unit.dart @@ -67,6 +67,10 @@ enum VoltageUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [volt], the SI derived unit of electric potential. + @override + bool get isSI => this == VoltageUnit.volt; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToVolt; final double _factorToNanovolt; diff --git a/lib/src/units/voltage_level/voltage_level_unit.dart b/lib/src/units/voltage_level/voltage_level_unit.dart index e642523..25949cf 100644 --- a/lib/src/units/voltage_level/voltage_level_unit.dart +++ b/lib/src/units/voltage_level/voltage_level_unit.dart @@ -17,6 +17,11 @@ enum VoltageLevelUnit implements Unit { @override final String symbol; + /// Logarithmic decibel-based voltage levels are not SI units, so this + /// always returns `false`. + @override + bool get isSI => false; + /// Unit symbols matched strictly case-sensitive. @internal static const Map symbolAliases = { diff --git a/lib/src/units/volume/volume_unit.dart b/lib/src/units/volume/volume_unit.dart index ae70a20..2e6caf2 100644 --- a/lib/src/units/volume/volume_unit.dart +++ b/lib/src/units/volume/volume_unit.dart @@ -125,6 +125,10 @@ enum VolumeUnit implements LinearUnit { @override final String symbol; + /// Returns `true` only for [cubicMeter], the SI derived unit of volume. + @override + bool get isSI => this == VolumeUnit.cubicMeter; + // --- Pre-calculated direct conversion factors --- final double _factorToCubicMeter; final double _factorToCubicDecameter; From 69878a3261c9f0df186415829bf9d7596bf5f51c Mon Sep 17 00:00:00 2001 From: Tim Alenus Date: Fri, 24 Jul 2026 09:57:51 +0200 Subject: [PATCH 2/3] docs: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 170d640..730a780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to the `quantify` package will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Added + +* Added `Unit.isSI`, returning `true` only for the actual SI unit of each quantity family (e.g. `LengthUnit.meter`, `MassUnit.kilogram`, `TimeUnit.second`). Logarithmic and non-SI-only families (`LevelRatio`, `PowerLevel`, `VoltageLevel`, `SoundPressureLevel`, `FuelConsumption`, `Information`) always return `false`. + ## [0.20.1] ### Fixed From b501cf616a1b85873e2a8254d85df1afcf1d78d3 Mon Sep 17 00:00:00 2001 From: Tim Alenus Date: Tue, 28 Jul 2026 12:46:18 +0200 Subject: [PATCH 3/3] feat: add isMetric getter --- CHANGELOG.md | 1 + lib/src/core/unit.dart | 3 +++ .../units/acceleration/acceleration_unit.dart | 12 ++++++++++++ lib/src/units/angle/angle_unit.dart | 9 +++++++++ .../angular_velocity/angular_velocity_unit.dart | 6 ++++++ lib/src/units/area/area_unit.dart | 12 ++++++++++++ lib/src/units/current/current_unit.dart | 8 ++++++++ lib/src/units/density/density_unit.dart | 5 +++++ .../electric_charge/electric_charge_unit.dart | 12 ++++++++++++ lib/src/units/energy/energy_unit.dart | 9 +++++++++ lib/src/units/force/force_unit.dart | 9 +++++++++ lib/src/units/frequency/frequency_unit.dart | 11 +++++++++++ .../fuel_consumption/fuel_consumption_unit.dart | 6 ++++++ lib/src/units/information/information_unit.dart | 16 ++++++++++++++++ lib/src/units/length/length_unit.dart | 15 +++++++++++++++ lib/src/units/level_ratio/level_ratio_unit.dart | 5 +++++ .../units/luminous/luminous_intensity_unit.dart | 5 +++++ lib/src/units/mass/mass_unit.dart | 15 +++++++++++++++ lib/src/units/molar/molar_unit.dart | 5 +++++ lib/src/units/power/power_unit.dart | 9 +++++++++ lib/src/units/power_level/power_level_unit.dart | 5 +++++ lib/src/units/pressure/pressure_unit.dart | 14 ++++++++++++++ lib/src/units/resistance/resistance_unit.dart | 5 +++++ lib/src/units/solid_angle/solid_angle_unit.dart | 5 +++++ .../sound_pressure_level_unit.dart | 5 +++++ .../specific_energy/specific_energy_unit.dart | 5 +++++ lib/src/units/speed/speed_unit.dart | 9 +++++++++ .../temperature/temperature_delta_unit.dart | 6 ++++++ lib/src/units/temperature/temperature_unit.dart | 5 +++++ lib/src/units/time/time_unit.dart | 17 +++++++++++++++++ lib/src/units/torque/torque_unit.dart | 13 +++++++++++++ lib/src/units/voltage/voltage_unit.dart | 8 ++++++++ .../units/voltage_level/voltage_level_unit.dart | 5 +++++ lib/src/units/volume/volume_unit.dart | 17 +++++++++++++++++ 34 files changed, 292 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 730a780..cc40225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added `Unit.isSI`, returning `true` only for the actual SI unit of each quantity family (e.g. `LengthUnit.meter`, `MassUnit.kilogram`, `TimeUnit.second`). Logarithmic and non-SI-only families (`LevelRatio`, `PowerLevel`, `VoltageLevel`, `SoundPressureLevel`, `FuelConsumption`, `Information`) always return `false`. +* Added `Unit.isMetric`, returning `true` for units that are part of the metric system (including non-SI metric units like `LengthUnit.kilometer`, `MassUnit.tonne`, `VolumeUnit.litre`, and `TemperatureUnit.celsius`), and `false` for imperial/US customary, nautical, astronomical, CGS, and other non-metric units. Purely logarithmic ratio families (`LevelRatio`, `PowerLevel`, `VoltageLevel`, `SoundPressureLevel`) always return `false`. ## [0.20.1] diff --git a/lib/src/core/unit.dart b/lib/src/core/unit.dart index 509c352..d4164e4 100644 --- a/lib/src/core/unit.dart +++ b/lib/src/core/unit.dart @@ -16,6 +16,9 @@ abstract class Unit> { /// Returns `true` if this unit is part of the International System of Units (SI). /// if the unit is SI derived, this will return `true` only for the base unit of that dimension. bool get isSI; + + /// Indicates whether the unit is part of the metric system. + bool get isMetric; } /// A contract for units that scale linearly (via a simple multiplier). diff --git a/lib/src/units/acceleration/acceleration_unit.dart b/lib/src/units/acceleration/acceleration_unit.dart index 073d426..d825cd2 100644 --- a/lib/src/units/acceleration/acceleration_unit.dart +++ b/lib/src/units/acceleration/acceleration_unit.dart @@ -111,6 +111,18 @@ enum AccelerationUnit implements LinearUnit { @override bool get isSI => this == AccelerationUnit.meterPerSecondSquared; + /// Returns `true` only for [meterPerSecondSquared], + /// [centimeterPerSecondSquared], and [kilometerPerHourPerSecond]; `false` + /// for the imperial/nautical units and the physical constant + /// [standardGravity]. + @override + bool get isMetric => switch (this) { + AccelerationUnit.meterPerSecondSquared || + AccelerationUnit.centimeterPerSecondSquared || + AccelerationUnit.kilometerPerHourPerSecond => true, + _ => false, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToMeterPerSecondSquared; final double _factorToStandardGravity; diff --git a/lib/src/units/angle/angle_unit.dart b/lib/src/units/angle/angle_unit.dart index ab806f2..f9383d9 100644 --- a/lib/src/units/angle/angle_unit.dart +++ b/lib/src/units/angle/angle_unit.dart @@ -61,6 +61,15 @@ enum AngleUnit implements LinearUnit { @override bool get isSI => this == AngleUnit.radian; + /// Returns `true` only for [radian], [milliradian], and [gradian] (the + /// decimal metric angle unit); `false` for [degree], [revolution], + /// [arcminute], and [arcsecond], which are sexagesimal/non-decimal units. + @override + bool get isMetric => switch (this) { + AngleUnit.radian || AngleUnit.milliradian || AngleUnit.gradian => true, + _ => false, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToRadian; final double _factorToDegree; diff --git a/lib/src/units/angular_velocity/angular_velocity_unit.dart b/lib/src/units/angular_velocity/angular_velocity_unit.dart index 2e31743..28c3529 100644 --- a/lib/src/units/angular_velocity/angular_velocity_unit.dart +++ b/lib/src/units/angular_velocity/angular_velocity_unit.dart @@ -69,6 +69,12 @@ enum AngularVelocityUnit implements LinearUnit { @override bool get isSI => this == AngularVelocityUnit.radianPerSecond; + /// Returns `true` only for [radianPerSecond]; `false` for [degreePerSecond], + /// [revolutionPerMinute], and [revolutionPerSecond], which are not decimal + /// metric units. + @override + bool get isMetric => this == AngularVelocityUnit.radianPerSecond; + // --- Pre-calculated direct conversion factors --- final double _factorToRadianPerSecond; final double _factorToDegreePerSecond; diff --git a/lib/src/units/area/area_unit.dart b/lib/src/units/area/area_unit.dart index 27753f8..b3aa5d9 100644 --- a/lib/src/units/area/area_unit.dart +++ b/lib/src/units/area/area_unit.dart @@ -84,6 +84,18 @@ enum AreaUnit implements LinearUnit { @override bool get isSI => this == AreaUnit.squareMeter; + /// Returns `false` for imperial/US customary land-area units; `true` for + /// all decimal metric units (including [hectare]). + @override + bool get isMetric => switch (this) { + AreaUnit.squareInch || + AreaUnit.squareFoot || + AreaUnit.squareYard || + AreaUnit.squareMile || + AreaUnit.acre => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToSquareMeter; final double _factorToSquareDecimeter; diff --git a/lib/src/units/current/current_unit.dart b/lib/src/units/current/current_unit.dart index f027939..6ad0b53 100644 --- a/lib/src/units/current/current_unit.dart +++ b/lib/src/units/current/current_unit.dart @@ -84,6 +84,14 @@ enum CurrentUnit implements LinearUnit { @override bool get isSI => this == CurrentUnit.ampere; + /// Returns `false` for the CGS units [statampere] and [abampere]; + /// `true` for all decimal metric units. + @override + bool get isMetric => switch (this) { + CurrentUnit.statampere || CurrentUnit.abampere => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToAmpere; final double _factorToMilliampere; diff --git a/lib/src/units/density/density_unit.dart b/lib/src/units/density/density_unit.dart index c98445c..5cbe0a7 100644 --- a/lib/src/units/density/density_unit.dart +++ b/lib/src/units/density/density_unit.dart @@ -62,6 +62,11 @@ enum DensityUnit implements LinearUnit { @override bool get isSI => this == DensityUnit.kilogramPerCubicMeter; + /// Returns `true` for all units, since every `DensityUnit` member is a + /// decimal metric unit. + @override + bool get isMetric => true; + // --- Pre-calculated direct conversion factors --- final double _factorToKilogramPerCubicMeter; final double _factorToGramPerCubicCentimeter; diff --git a/lib/src/units/electric_charge/electric_charge_unit.dart b/lib/src/units/electric_charge/electric_charge_unit.dart index 67d7114..eb34db5 100644 --- a/lib/src/units/electric_charge/electric_charge_unit.dart +++ b/lib/src/units/electric_charge/electric_charge_unit.dart @@ -73,6 +73,18 @@ enum ElectricChargeUnit implements LinearUnit { @override bool get isSI => this == ElectricChargeUnit.coulomb; + /// Returns `false` for the physics-constant [elementaryCharge] and the CGS + /// units [statcoulomb], [franklin], and [abcoulomb]; `true` for all decimal + /// metric units (including [ampereHour]). + @override + bool get isMetric => switch (this) { + ElectricChargeUnit.elementaryCharge || + ElectricChargeUnit.statcoulomb || + ElectricChargeUnit.franklin || + ElectricChargeUnit.abcoulomb => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToCoulomb; final double _factorToKilocoulomb; diff --git a/lib/src/units/energy/energy_unit.dart b/lib/src/units/energy/energy_unit.dart index 52feb51..e47e11c 100644 --- a/lib/src/units/energy/energy_unit.dart +++ b/lib/src/units/energy/energy_unit.dart @@ -99,6 +99,15 @@ enum EnergyUnit implements LinearUnit { @override bool get isSI => this == EnergyUnit.joule; + /// Returns `false` for the physics-constant [electronvolt] and the + /// imperial [btu]; `true` for all decimal metric units (including + /// [calorie] and [wattHour] families). + @override + bool get isMetric => switch (this) { + EnergyUnit.electronvolt || EnergyUnit.btu => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToJoule; final double _factorToMillijoule; diff --git a/lib/src/units/force/force_unit.dart b/lib/src/units/force/force_unit.dart index 3a78c37..fd339e1 100644 --- a/lib/src/units/force/force_unit.dart +++ b/lib/src/units/force/force_unit.dart @@ -72,6 +72,15 @@ enum ForceUnit implements LinearUnit { @override bool get isSI => this == ForceUnit.newton; + /// Returns `false` for the imperial [poundForce] and [poundal], and the + /// CGS [dyne]; `true` for all decimal metric units (including the + /// gravitational metric units [kilogramForce] and [gramForce]). + @override + bool get isMetric => switch (this) { + ForceUnit.poundForce || ForceUnit.dyne || ForceUnit.poundal => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToNewton; final double _factorToNanonewton; diff --git a/lib/src/units/frequency/frequency_unit.dart b/lib/src/units/frequency/frequency_unit.dart index f50cbd3..f75477f 100644 --- a/lib/src/units/frequency/frequency_unit.dart +++ b/lib/src/units/frequency/frequency_unit.dart @@ -64,6 +64,17 @@ enum FrequencyUnit implements LinearUnit { @override bool get isSI => this == FrequencyUnit.hertz; + /// Returns `false` for [revolutionsPerMinute], [beatsPerMinute], and + /// [degreePerSecond], which are not decimal metric units; `true` for all + /// SI-prefixed hertz units and [radianPerSecond]. + @override + bool get isMetric => switch (this) { + FrequencyUnit.revolutionsPerMinute || + FrequencyUnit.beatsPerMinute || + FrequencyUnit.degreePerSecond => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToHertz; final double _factorToTerahertz; diff --git a/lib/src/units/fuel_consumption/fuel_consumption_unit.dart b/lib/src/units/fuel_consumption/fuel_consumption_unit.dart index d2c704d..282ba29 100644 --- a/lib/src/units/fuel_consumption/fuel_consumption_unit.dart +++ b/lib/src/units/fuel_consumption/fuel_consumption_unit.dart @@ -31,6 +31,12 @@ enum FuelConsumptionUnit implements Unit { @override bool get isSI => false; + /// Returns `true` only for [litersPer100Km] and [kilometerPerLiter], the + /// metric fuel-consumption units; `false` for [mpgUs] and [mpgUk]. + @override + bool get isMetric => + this == FuelConsumptionUnit.litersPer100Km || this == FuelConsumptionUnit.kilometerPerLiter; + /// Unit symbols matched strictly case-sensitive. /// /// Note: The unqualified abbreviation `mpg` defaults to US gallons. diff --git a/lib/src/units/information/information_unit.dart b/lib/src/units/information/information_unit.dart index c67f77c..639367a 100644 --- a/lib/src/units/information/information_unit.dart +++ b/lib/src/units/information/information_unit.dart @@ -152,6 +152,22 @@ enum InformationUnit implements LinearUnit { @override bool get isSI => false; + /// Returns `false` for the IEC/binary units ([kibibyte] through + /// [yobibyte]), which use binary (base-2) prefixes; `true` for [bit], + /// [byte], and all SI/decimal-prefixed bit and byte units. + @override + bool get isMetric => switch (this) { + InformationUnit.kibibyte || + InformationUnit.mebibyte || + InformationUnit.gibibyte || + InformationUnit.tebibyte || + InformationUnit.pebibyte || + InformationUnit.exbibyte || + InformationUnit.zebibyte || + InformationUnit.yobibyte => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToBit; final double _factorToByte; diff --git a/lib/src/units/length/length_unit.dart b/lib/src/units/length/length_unit.dart index 762209f..980e6fd 100644 --- a/lib/src/units/length/length_unit.dart +++ b/lib/src/units/length/length_unit.dart @@ -123,6 +123,21 @@ enum LengthUnit implements LinearUnit { @override bool get isSI => this == LengthUnit.meter; + /// Returns `false` for imperial/US customary, nautical, and astronomical + /// units; `true` for all decimal metric units (including [angstrom]). + @override + bool get isMetric => switch (this) { + LengthUnit.inch || + LengthUnit.foot || + LengthUnit.yard || + LengthUnit.mile || + LengthUnit.nauticalMile || + LengthUnit.astronomicalUnit || + LengthUnit.lightYear || + LengthUnit.parsec => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToMeter; final double _factorToKilometer; diff --git a/lib/src/units/level_ratio/level_ratio_unit.dart b/lib/src/units/level_ratio/level_ratio_unit.dart index 1055f4e..bc7b8a2 100644 --- a/lib/src/units/level_ratio/level_ratio_unit.dart +++ b/lib/src/units/level_ratio/level_ratio_unit.dart @@ -28,6 +28,11 @@ enum LevelRatioUnit implements LinearUnit { @override bool get isSI => false; + /// Returns `false` for all units, since logarithmic ratio units are not + /// tied to any unit system. + @override + bool get isMetric => false; + final double _factorToDecibel; final double _factorToNeper; diff --git a/lib/src/units/luminous/luminous_intensity_unit.dart b/lib/src/units/luminous/luminous_intensity_unit.dart index f0e6269..2d0bc16 100644 --- a/lib/src/units/luminous/luminous_intensity_unit.dart +++ b/lib/src/units/luminous/luminous_intensity_unit.dart @@ -96,6 +96,11 @@ enum LuminousIntensityUnit implements LinearUnit { @override bool get isSI => this == LuminousIntensityUnit.candela; + /// Returns `true` for all units, since every `LuminousIntensityUnit` member + /// is a decimal metric (SI-prefixed) unit. + @override + bool get isMetric => true; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToCandela; final double _factorToMillicandela; diff --git a/lib/src/units/mass/mass_unit.dart b/lib/src/units/mass/mass_unit.dart index 3cb0936..1388a5e 100644 --- a/lib/src/units/mass/mass_unit.dart +++ b/lib/src/units/mass/mass_unit.dart @@ -121,6 +121,21 @@ enum MassUnit implements LinearUnit { @override bool get isSI => this == MassUnit.kilogram; + /// Returns `false` for imperial/US customary units and the physics-constant + /// [atomicMassUnit]; `true` for all decimal metric units (including [tonne] + /// and [carat]). + @override + bool get isMetric => switch (this) { + MassUnit.pound || + MassUnit.ounce || + MassUnit.stone || + MassUnit.slug || + MassUnit.shortTon || + MassUnit.longTon || + MassUnit.atomicMassUnit => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToKilogram; final double _factorToHectogram; diff --git a/lib/src/units/molar/molar_unit.dart b/lib/src/units/molar/molar_unit.dart index 9b21ee5..1363dc9 100644 --- a/lib/src/units/molar/molar_unit.dart +++ b/lib/src/units/molar/molar_unit.dart @@ -112,6 +112,11 @@ enum MolarUnit implements LinearUnit { @override bool get isSI => this == MolarUnit.mole; + /// Returns `false` only for the imperial [poundMole]; `true` for all + /// decimal metric units. + @override + bool get isMetric => this != MolarUnit.poundMole; + // --- Pre-calculated direct conversion factors from this unit to all others --- // These are calculated once in the const constructor for performance. diff --git a/lib/src/units/power/power_unit.dart b/lib/src/units/power/power_unit.dart index c55223d..d923136 100644 --- a/lib/src/units/power/power_unit.dart +++ b/lib/src/units/power/power_unit.dart @@ -78,6 +78,15 @@ enum PowerUnit implements LinearUnit { @override bool get isSI => this == PowerUnit.watt; + /// Returns `false` for the imperial [horsepower] and [btuPerHour], and the + /// CGS [ergPerSecond]; `true` for all SI-prefixed watt units and + /// [metricHorsepower]. + @override + bool get isMetric => switch (this) { + PowerUnit.horsepower || PowerUnit.btuPerHour || PowerUnit.ergPerSecond => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToWatt; final double _factorToNanowatt; diff --git a/lib/src/units/power_level/power_level_unit.dart b/lib/src/units/power_level/power_level_unit.dart index e90d611..409b9c9 100644 --- a/lib/src/units/power_level/power_level_unit.dart +++ b/lib/src/units/power_level/power_level_unit.dart @@ -25,6 +25,11 @@ enum PowerLevelUnit implements Unit { @override bool get isSI => false; + /// Returns `false` for all units, since logarithmic ratio units are not + /// tied to any unit system. + @override + bool get isMetric => false; + /// Unit symbols matched strictly case-sensitive. @internal static const Map symbolAliases = { diff --git a/lib/src/units/pressure/pressure_unit.dart b/lib/src/units/pressure/pressure_unit.dart index 96cd5cf..527eeaf 100644 --- a/lib/src/units/pressure/pressure_unit.dart +++ b/lib/src/units/pressure/pressure_unit.dart @@ -95,6 +95,20 @@ enum PressureUnit implements LinearUnit { @override bool get isSI => this == PressureUnit.pascal; + /// Returns `false` for [atmosphere], the imperial [psi], [inchOfMercury], + /// and [inchOfWater], and the non-decimal [torr]; `true` for all + /// SI-prefixed pascal units, [bar], [millibar], [millimeterOfMercury], and + /// [centimeterOfWater]. + @override + bool get isMetric => switch (this) { + PressureUnit.atmosphere || + PressureUnit.psi || + PressureUnit.torr || + PressureUnit.inchOfMercury || + PressureUnit.inchOfWater => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToPascal; final double _factorToMicropascal; diff --git a/lib/src/units/resistance/resistance_unit.dart b/lib/src/units/resistance/resistance_unit.dart index f70130c..e34f630 100644 --- a/lib/src/units/resistance/resistance_unit.dart +++ b/lib/src/units/resistance/resistance_unit.dart @@ -63,6 +63,11 @@ enum ResistanceUnit implements LinearUnit { @override bool get isSI => this == ResistanceUnit.ohm; + /// Returns `true` for all units, since every `ResistanceUnit` member is a + /// decimal metric (SI-prefixed) unit. + @override + bool get isMetric => true; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToOhm; final double _factorToNanoohm; diff --git a/lib/src/units/solid_angle/solid_angle_unit.dart b/lib/src/units/solid_angle/solid_angle_unit.dart index 847040f..744ae58 100644 --- a/lib/src/units/solid_angle/solid_angle_unit.dart +++ b/lib/src/units/solid_angle/solid_angle_unit.dart @@ -53,6 +53,11 @@ enum SolidAngleUnit implements LinearUnit { @override bool get isSI => this == SolidAngleUnit.steradian; + /// Returns `true` only for [steradian]; `false` for [squareDegree] and + /// [spat], which are not decimal metric units. + @override + bool get isMetric => this == SolidAngleUnit.steradian; + // --- Pre-calculated direct conversion factors --- final double _factorToSteradian; final double _factorToSquareDegree; diff --git a/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart b/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart index 8b3b347..406b71d 100644 --- a/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart +++ b/lib/src/units/sound_pressure_level/sound_pressure_level_unit.dart @@ -19,6 +19,11 @@ enum SoundPressureLevelUnit implements Unit { @override bool get isSI => false; + /// Returns `false` for all units, since logarithmic ratio units are not + /// tied to any unit system. + @override + bool get isMetric => false; + /// Unit symbols matched strictly case-sensitive. @internal static const Map symbolAliases = { diff --git a/lib/src/units/specific_energy/specific_energy_unit.dart b/lib/src/units/specific_energy/specific_energy_unit.dart index bab2089..e4bd0e2 100644 --- a/lib/src/units/specific_energy/specific_energy_unit.dart +++ b/lib/src/units/specific_energy/specific_energy_unit.dart @@ -69,6 +69,11 @@ enum SpecificEnergyUnit implements LinearUnit { @override bool get isSI => this == SpecificEnergyUnit.joulePerKilogram; + /// Returns `true` for all units, since every `SpecificEnergyUnit` member is + /// a decimal metric unit. + @override + bool get isMetric => true; + // --- Pre-calculated direct conversion factors --- final double _factorToJoulePerKilogram; final double _factorToKilojoulePerKilogram; diff --git a/lib/src/units/speed/speed_unit.dart b/lib/src/units/speed/speed_unit.dart index 2c4b7c8..b1ab97f 100644 --- a/lib/src/units/speed/speed_unit.dart +++ b/lib/src/units/speed/speed_unit.dart @@ -55,6 +55,15 @@ enum SpeedUnit implements LinearUnit { @override bool get isSI => this == SpeedUnit.meterPerSecond; + /// Returns `false` for the imperial [milePerHour] and [footPerSecond], and + /// the nautical [knot]; `true` for all metric units (including + /// [kilometerPerHour]). + @override + bool get isMetric => switch (this) { + SpeedUnit.milePerHour || SpeedUnit.knot || SpeedUnit.footPerSecond => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToMeterPerSecond; final double _factorToKilometerPerSecond; diff --git a/lib/src/units/temperature/temperature_delta_unit.dart b/lib/src/units/temperature/temperature_delta_unit.dart index 9586747..1d5ec88 100644 --- a/lib/src/units/temperature/temperature_delta_unit.dart +++ b/lib/src/units/temperature/temperature_delta_unit.dart @@ -80,6 +80,12 @@ enum TemperatureDeltaUnit implements LinearUnit { @override bool get isSI => this == TemperatureDeltaUnit.kelvinDelta; + /// Returns `true` only for [kelvinDelta] and [celsiusDelta], the metric + /// temperature-delta scales; `false` for [fahrenheitDelta] and [rankineDelta]. + @override + bool get isMetric => + this == TemperatureDeltaUnit.kelvinDelta || this == TemperatureDeltaUnit.celsiusDelta; + // --- Pre-calculated direct conversion factors --- final double _factorToKelvinDelta; final double _factorToCelsiusDelta; diff --git a/lib/src/units/temperature/temperature_unit.dart b/lib/src/units/temperature/temperature_unit.dart index f7810b2..3a390b0 100644 --- a/lib/src/units/temperature/temperature_unit.dart +++ b/lib/src/units/temperature/temperature_unit.dart @@ -31,6 +31,11 @@ enum TemperatureUnit implements Unit { @override bool get isSI => this == TemperatureUnit.kelvin; + /// Returns `true` only for [celsius] and [kelvin], the metric temperature + /// scales; `false` for [fahrenheit] and [rankine]. + @override + bool get isMetric => this == TemperatureUnit.celsius || this == TemperatureUnit.kelvin; + /// SI and unit symbols matched **strictly case-sensitive**. static const Map symbolAliases = { '°C': celsius, diff --git a/lib/src/units/time/time_unit.dart b/lib/src/units/time/time_unit.dart index f658195..e01d0ac 100644 --- a/lib/src/units/time/time_unit.dart +++ b/lib/src/units/time/time_unit.dart @@ -121,6 +121,23 @@ enum TimeUnit implements LinearUnit { @override bool get isSI => this == TimeUnit.second; + /// Returns `false` for calendar/civil units ([minute] through [century]), + /// which are not decimal subdivisions of the second; `true` for all + /// decimal metric multiples and sub-multiples of the second. + @override + bool get isMetric => switch (this) { + TimeUnit.minute || + TimeUnit.hour || + TimeUnit.day || + TimeUnit.week || + TimeUnit.fortnight || + TimeUnit.month || + TimeUnit.year || + TimeUnit.decade || + TimeUnit.century => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToSecond; final double _factorToMicrosecond; diff --git a/lib/src/units/torque/torque_unit.dart b/lib/src/units/torque/torque_unit.dart index 836c705..9693a46 100644 --- a/lib/src/units/torque/torque_unit.dart +++ b/lib/src/units/torque/torque_unit.dart @@ -72,6 +72,19 @@ enum TorqueUnit implements LinearUnit { @override bool get isSI => this == TorqueUnit.newtonMeter; + /// Returns `false` for the imperial [poundFoot], [poundInch], and + /// [ounceForceInch], and the CGS [dyneCentimeter]; `true` for all + /// SI-prefixed newton-meter units and the gravitational metric + /// [kilogramForceMeter]. + @override + bool get isMetric => switch (this) { + TorqueUnit.poundFoot || + TorqueUnit.poundInch || + TorqueUnit.ounceForceInch || + TorqueUnit.dyneCentimeter => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToNewtonMeter; final double _factorToMillinewtonMeter; diff --git a/lib/src/units/voltage/voltage_unit.dart b/lib/src/units/voltage/voltage_unit.dart index 3f59c2c..1c9c8e2 100644 --- a/lib/src/units/voltage/voltage_unit.dart +++ b/lib/src/units/voltage/voltage_unit.dart @@ -71,6 +71,14 @@ enum VoltageUnit implements LinearUnit { @override bool get isSI => this == VoltageUnit.volt; + /// Returns `false` for the CGS units [statvolt] and [abvolt]; `true` for + /// all decimal metric units. + @override + bool get isMetric => switch (this) { + VoltageUnit.statvolt || VoltageUnit.abvolt => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors from this unit to all others --- final double _factorToVolt; final double _factorToNanovolt; diff --git a/lib/src/units/voltage_level/voltage_level_unit.dart b/lib/src/units/voltage_level/voltage_level_unit.dart index 25949cf..facfa86 100644 --- a/lib/src/units/voltage_level/voltage_level_unit.dart +++ b/lib/src/units/voltage_level/voltage_level_unit.dart @@ -22,6 +22,11 @@ enum VoltageLevelUnit implements Unit { @override bool get isSI => false; + /// Returns `false` for all units, since logarithmic ratio units are not + /// tied to any unit system. + @override + bool get isMetric => false; + /// Unit symbols matched strictly case-sensitive. @internal static const Map symbolAliases = { diff --git a/lib/src/units/volume/volume_unit.dart b/lib/src/units/volume/volume_unit.dart index 2e6caf2..6e02a18 100644 --- a/lib/src/units/volume/volume_unit.dart +++ b/lib/src/units/volume/volume_unit.dart @@ -129,6 +129,23 @@ enum VolumeUnit implements LinearUnit { @override bool get isSI => this == VolumeUnit.cubicMeter; + /// Returns `false` for imperial/US customary cubic and liquid units; + /// `true` for all decimal metric cubic and litre-based units. + @override + bool get isMetric => switch (this) { + VolumeUnit.cubicInch || + VolumeUnit.cubicFoot || + VolumeUnit.cubicMile || + VolumeUnit.gallon || + VolumeUnit.imperialGallon || + VolumeUnit.quart || + VolumeUnit.pint || + VolumeUnit.fluidOunce || + VolumeUnit.tablespoon || + VolumeUnit.teaspoon => false, + _ => true, + }; + // --- Pre-calculated direct conversion factors --- final double _factorToCubicMeter; final double _factorToCubicDecameter;