Skip to content

Commit da59459

Browse files
Refactor Units and PhysicalConstants for Consistency and Maintainability
This update migrates hardcoded constants in the Units class to the PhysicalConstants class, ensuring all unit conversions are derived from a single source. New constants for various unit conversions, including length, area, and time, have been added to PhysicalConstants. The Units class now references these constants, enhancing code clarity and maintainability. Additionally, the implementation of generic getters for these constants improves type safety across the library.
1 parent ab59a41 commit da59459

4 files changed

Lines changed: 750 additions & 35 deletions

File tree

.cursor/rules/derived-cursor-rules.mdc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,11 @@ When adding XML documentation comments:
213213
1. **ElementaryCharge**
214214
2. **PlanckConstant**
215215
3. **BoltzmannConstant**
216-
4. **FeetToMeters** (from Conversion class)
216+
4. **FeetToMeters** (from Conversion class)
217+
* **Units.cs Constants Migration:**
218+
* When defining units in `Units.cs`, use `PhysicalConstants.Generic` or `PhysicalConstants.Conversion` where applicable, instead of hardcoding numerical values.
219+
* **Units.cs Hardcoded Constants Exceptions**:
220+
* Metric prefixes (handled by `MetricMagnitudes` class): `0.001`, `1000.0`, etc.
221+
* Mathematical constants (like `Math.PI`): Already using C# standard library
222+
* Derived unit relationships (like time conversions): `60.0` (seconds per minute), `3600.0` (seconds per hour)
223+
* Imperial unit conversions not in PhysicalConstants: Many specific imperial conversions that aren't fundamental physical constants

0 commit comments

Comments
 (0)