You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the Mechanical Domain in the Semantics library, introducing quantities such as Force, Energy, Pressure, and their associated calculations. Centralize physical constants management in PhysicalConstants.cs, ensuring type-safe access to constants like standard gravity and atmospheric pressure. Update PhysicalDimensions and Units to incorporate new mechanical dimensions and units. Achieve comprehensive testing with 100% passing tests, marking the Mechanical domain as fully implemented in the updated implementation plan and progress tracker.
Copy file name to clipboardExpand all lines: .cursor/rules/derived-cursor-rules.mdc
+46-27Lines changed: 46 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,13 @@ This file defines all project rules, coding standards, workflow guidelines, refe
30
30
* Create a `docs/complete-library-guide.md` file to provide a comprehensive overview of all features and components in the ktsu.Semantics library.
31
31
* Before we continue implementing more domains, search the quantities, units, and dimensions for hard coded values that should be defined as physical constants and define them somewhere appropriate. Add this to the TODO document as part of the implementation guidelines.
32
32
* Apply the constants in any appropriate calculations in the quantities units and dimensions, you may define derived constants as well and create unit tests comparing the constant derived values vs calculated derived values using the fundamental constants
33
+
* **Management Rules for Physical Constants:**
34
+
1. Use `PhysicalConstants.Generic` methods for type-safe access
35
+
2. Add new constants to `PhysicalConstants.cs` before using them
36
+
3. Refactor existing hard-coded values when implementing new domains
* Before we continue implementing more domains, search the quantities, units, and dimensions for hard coded values that should be defined as physical constants and define them somewhere appropriate. Add this to the TODO document as part of the implementation guidelines
39
+
* Apply the constants in any appropriate calculations in the quantities units and dimensions, you may define derived constants as well and create unit tests comparing the constant derived values vs calculated derived values using the fundamental constants
33
40
* **Management Rules for Physical Constants:**
34
41
1. Use `PhysicalConstants.Generic` methods for type-safe access
35
42
2. Add new constants to `PhysicalConstants.cs` before using them
@@ -46,6 +53,44 @@ When adding XML documentation comments:
46
53
* Use detailed `<list>` elements for enumerated information.
47
54
* Follow Microsoft's documentation standards.
48
55
* Remove all of the example documentation from the XML comments.
56
+
* **Domain Implementation Workflow**
57
+
1. Use the Chemical domain as a template.
58
+
2. Before coding, search for any hard-coded constants and add them to `PhysicalConstants.cs`.
59
+
3. Implement quantities with full unit conversions and dimensional analysis.
60
+
4. Add comprehensive unit tests, including mathematical relationship checks.
61
+
5. Document all new quantities and constants.
62
+
* **Always centralize physical constants** in `PhysicalConstants.cs` before using them in any domain.
63
+
* **Use type-safe generic accessors** for all constants.
64
+
* **Refactor any hard-coded values** found in new or existing code.
65
+
* **Document all sources** for constants (CODATA, NIST, ISO/IEC).
66
+
* **Follow the established code and documentation standards** (file headers, XML docs, null safety, generic constraints).
67
+
* **Test thoroughly**: unit tests, mathematical verification, integration tests.
* Implement quantities like Force, Energy, Power, Pressure, etc., with full unit conversions and dimensional analysis.
70
+
* Add comprehensive unit tests, including mathematical relationship checks (e.g., F = m·a, P = F/A, E = F·d).
71
+
* Document all new quantities and constants.
72
+
* **Integration Tests**
73
+
* Create tests that use quantities from multiple domains in calculations.
74
+
* Verify that units and conversions work seamlessly across domains.
75
+
* **Performance Benchmarks**
76
+
* Add benchmarks for common operations (e.g., unit conversions, arithmetic).
77
+
* Optimize as needed.
78
+
* **Documentation Expansion**
79
+
* Update the `docs/complete-library-guide.md` with new domains and features.
80
+
* Add usage examples for new quantities.
81
+
* Ensure all references in `README.md` and other docs are accurate (e.g., `docs/examples/`).
82
+
* **Implementation Plan and Tracker**
83
+
* **Physical Constants First**: Identify all mechanical constants needed (e.g., gravitational acceleration, standard atmospheric pressure, Planck’s constant if needed for mechanics, etc.). Add them to `PhysicalConstants.cs` under appropriate categories (Fundamental, Mechanical, etc.). Use the `PhysicalConstants.Generic` pattern for type-safe access. Include XML docs and source references (CODATA, NIST, etc.).
84
+
* **Define Quantities**:
85
+
* Location: `Quantities/Mechanics/`
86
+
* Quantities to Implement: Force (`Force.cs`), Pressure (`Pressure.cs`), Energy (`Energy.cs`), Power (`Power.cs`), Torque (`Torque.cs`), Momentum (`Momentum.cs`), AngularVelocity (`AngularVelocity.cs`), AngularAcceleration (`AngularAcceleration.cs`), MomentOfInertia (`MomentOfInertia.cs`), Density (`Density.cs`), SpecificGravity (`SpecificGravity.cs`), and any others listed in your TODOs. Follow the template from the Chemical domain (generic, type-safe, XML docs, unit conversions, etc.).
87
+
* **Units and Dimensions**: For each quantity, define the SI and common units in `Units.cs`. Add or update `PhysicalDimensions.cs` as needed for new dimensions (e.g., force, energy).
88
+
* **Mathematical Relationships**: Implement relationships (e.g., F = m·a, P = F/A, E = F·d) as static methods or extension methods. Add unit tests to verify these relationships using both constants and calculated values.
89
+
* **Testing**: For each quantity: Create unit tests for creation, conversion, and validation. Add mathematical verification tests (e.g., compare calculated force to expected value). Add edge case and error handling tests.
90
+
* **Documentation**: Update or create: XML docs for all new types and members. Update `docs/complete-library-guide.md` with new mechanical quantities and usage examples. Update `README.md` and any references to examples (ensure they point to `docs/examples/`).
91
+
* **Integration and Performance**: Create tests that use both chemical and mechanical quantities together (e.g., energy calculations involving moles and force). Add benchmarks for common operations (unit conversions, arithmetic, etc.).
92
+
* **Review and Refactor**: As you implement, refactor any hard-coded values found in other domains to use the new constants. Ensure all code follows the standards (headers, null safety, XML docs, etc.).
93
+
* **Next Domains**: After Mechanical, move to Electromagnetic, then Thermal, then Optical, Acoustic, Nuclear, and Fluid Dynamics, following the same process.
49
94
50
95
## CODING STANDARDS
51
96
@@ -318,30 +363,4 @@ When adding XML documentation comments:
318
363
* When resolving CS1503 errors (Argument cannot convert from type X to type Y), carefully examine the method signature and the types of the arguments being passed. Ensure that the arguments are of the correct type or can be implicitly converted to the expected type. Review the relevant interfaces and classes to ensure they are being used correctly.
319
364
* When resolving CA1859 errors (Change type of variable 'variableName' from 'InterfaceName' to 'ClassName' for improved performance), consider changing the variable type as suggested by the analyzer to improve performance.
320
365
* If a `CS8600` error ("Converting null literal or possible null value to non-nullable type") persists despite null-checking and handling, review the project's nullable reference types configuration and ensure it aligns with the intended behavior. The error might be a false positive or require project-specific adjustments.
321
-
* When debugging `FormatException` errors originating from `SemanticString<TDest>.PerformValidation`, especially during `RelativeDirectoryPath_Contents_ReturnsRelativePathTypes`, `SemanticPath_PathTypes`, or `SemanticPath_MakeCanonical_WithMixedSeparators_ShouldNormalize` tests, carefully review the validation logic and ensure that the input string adheres to the expected format for the target type `TDest`. Pay close attention to the following:
322
-
* **Relative vs. Absolute Paths**: Ensure that the input string matches the expected type (e.g., `RelativeDirectoryPath` should not start with a root directory).
323
-
* **Path Separators**: Verify that the path separators are consistent and correctly normalized (if normalization is expected).
324
-
* **Invalid Characters**: Ensure that the path does not contain any invalid characters or sequences.
325
-
* When a test expects `System.ArgumentException` but gets `System.FormatException`, it indicates that the validation logic is throwing a `FormatException` when it should be throwing an `ArgumentException`. Review the validation logic and update it to throw the correct exception type based on the nature of the error. For example, if the error is due to an invalid argument value, throw `ArgumentException`; if it's due to an invalid format, throw `FormatException`.
326
-
* When debugging `RelativeDirectoryPath_Contents_ReturnsRelativePathTypes` test failures, ensure that the test uses `AbsoluteDirectoryPath` instances when testing contents of absolute directory paths. Ensure there are no tab characters in the test file.
327
-
* When debugging `SemanticPath_RootPath_Unix` test failures, ensure that path canonicalization correctly handles Unix root paths ("/") and doesn't convert them to Windows path separators ("\\").
328
-
* When debugging `SemanticPath_PathTypes` test failures, ensure that the correct path type (e.g., `AbsolutePath`, `RelativePath`) is used in the test case based on whether the path is absolute or relative.
329
-
* When debugging `SemanticPath_PathLength_TooLong` tests, be aware that the validation logic throws `FormatException` for path length violations. The tests should expect `FormatException`.
330
-
* When debugging `IndexOf` and `LastIndexOf` methods, and tests are failing, it's important to check the following:
331
-
* Verify that all method overloads work correctly with their underlying `WeakString` implementations.
332
-
* Verify that the `WeakString` property is properly initialized with the correct string value.
333
-
* Check for any issues with named parameter delegation.
334
-
* When debugging `SpanPathUtilities.GetFileName` and encountering failing tests with trailing separators, ensure that the method returns an empty span when the path ends with a directory separator.
335
-
* When encountering CS0122 errors related to `SemanticString<T>.FromString<TDest>(string?)` being inaccessible, replace all calls to `FromString<TDest>` with `Create<TDest>`.
336
-
* When encountering CS1715 errors (type must be 'PhysicalDimension' to match overridden member), ensure that the type of the overriding property or member matches the type of the overridden property or member in the base class.
337
-
* When encountering CA1032 errors in `UnitConversionException.cs` (Failure to provide the full set of constructors), ensure that the exception class provides all the standard exception constructors.
338
-
* When encountering CS8862 errors in `UnitConversionException.cs` (A constructor declared in a type with parameter list must have 'this' constructor initializer), ensure that constructors with parameters call the primary constructor using `this(...)`.
339
-
* When encountering CA1062 errors in `UnitExtensions.cs` (An externally visible method dereferences one of its reference arguments without verifying whether that argument is 'null'), add null checks (e.g., `ArgumentNullException.ThrowIfNull()`) for all reference arguments in externally visible methods.
340
-
* When encountering CS1591 errors (The /doc compiler option was specified, but one or more constructs did not have comments), add XML documentation comments to all public types and members.
341
-
* When encountering CA1502 errors, refactor the code to decrease its complexity.
342
-
* When encountering CS1503 errors (Argument 1: cannot convert from 'int' to 'ktsu.Semantics.IUnit') in `PhysicalDimension.cs` during operator overloading, ensure that the constructor calls include the required `IUnit` parameter with a proper base unit.
343
-
* When encountering CS0108 errors, 'SoundPressureLevel<T>.Create(T)' hides inherited member, add the `new` keyword if hiding was intended.
344
-
* When encountering CS0200 errors, Property or indexer 'PhysicalQuantity<SoundIntensityLevel<T>, T>.Value' cannot be assigned to -- it is read only, make sure you are not trying to assign to a read-only property.
345
-
* When encountering CA1062 errors, In externally visible method 'SoundPressureLevel<T> SoundPressureLevel<T>.FromSoundPressure(SoundPressure<T> soundPressure)', validate parameter 'soundPressure' is non-null before using it. If appropriate, throw an 'ArgumentNullException' when the argument is 'null' add a null check for the reference parameter.
346
-
* When fixing CS0704 errors (Cannot do non-virtual member lookup in 'T' because it is a type parameter), add the appropriate generic constraints (e.g., `where T : struct, INumber<T>, IFloatingPoint<T>`).
347
-
* When fixing CA1062 errors (In externally visible method X, validate parameter Y is non-null before using it), add `ArgumentNullException.ThrowIfNull(parameterName
366
+
* When debugging `FormatException` errors originating from `SemanticString<TDest>.PerformValidation`, especially during `RelativeDirectoryPath_Contents_ReturnsRelativePathTypes`, `SemanticPath_PathTypes`, or `SemanticPath
0 commit comments