Skip to content

Add new QuantityFamilies and To/From SI - #179

Open
Chrisshort92 wants to merge 1 commit into
developfrom
#178-add-fromunitstring-and-tounitstring-extension-methods-to-bhengineunits
Open

Add new QuantityFamilies and To/From SI#179
Chrisshort92 wants to merge 1 commit into
developfrom
#178-add-fromunitstring-and-tounitstring-extension-methods-to-bhengineunits

Conversation

@Chrisshort92

Copy link
Copy Markdown

This pull request introduces a new, extensible framework for unit symbol resolution and conversion between SI and other units. The main changes include the creation of a unified UnitSpec class, a QuantityFamily enum to categorize physical quantities, and new methods for resolving unit symbols and performing conversions in both directions.

Unit conversion framework:

  • Added the UnitSpec class to encapsulate a unit's quantity family and enumeration value, providing a standard way to represent units throughout the codebase.
  • Introduced the QuantityFamily enum to categorize physical quantities (e.g., Length, Area, Force, etc.), supporting dispatch to the correct conversion logic.

Unit symbol resolution:

  • Implemented the Query.ResolveUnit method, which maps unit symbol strings (e.g., "mm", "kN") to their corresponding UnitSpec, including support for symbol aliases and error handling for unrecognized units.

SI and unit conversions:

  • Added Convert.FromUnit and Convert.ToUnit extension methods, allowing conversion from a value in a specified unit symbol to SI, and vice versa, by dispatching to the correct conversion method based on the resolved QuantityFamily. [1] [2]

Issues addressed by this PR

Closes #178

Test files

Changelog

Additional comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add FromUnit(string) and ToUnit(string) extension methods to BH.Engine.Units

1 participant