Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unit for printing a dimensionless SiScalar to be blank #14

Closed
averbraeck opened this issue Jul 23, 2023 · 4 comments
Closed

Change unit for printing a dimensionless SiScalar to be blank #14

averbraeck opened this issue Jul 23, 2023 · 4 comments
Assignees
Labels
simplification Simplification o code

Comments

@averbraeck
Copy link
Owner

Currently, a dimensionless SIScalar prints a unit of '1'. Now that the Dimensionless prints a blank unit, the SIScalar has to be changed as well to be consistent. As an example, the following code:

  SIScalar s1 = Torque.of(1.33, "N.m").divide(Energy.valueOf("2.1 J"));
  System.out.println("|" + s1 + "|");

prints:

|0.63333333 1|
@averbraeck averbraeck self-assigned this Jul 23, 2023
@averbraeck averbraeck added the simplification Simplification o code label Jul 23, 2023
averbraeck added a commit that referenced this issue Jul 23, 2023
This now returns a dimensionless SIScalar.
averbraeck added a commit to averbraeck/djunits-generator that referenced this issue Jul 23, 2023
averbraeck added a commit to averbraeck/djunits-demo that referenced this issue Jul 23, 2023
Especially for a dimensionless SIScalar and SIVector.
Relates to averbraeck/djunits#14
@averbraeck
Copy link
Owner Author

The code:

  SIScalar s1 = Torque.of(1.33, "N.m").divide(Energy.valueOf("2.1 J"));
  System.out.println("|" + s1 + "|");

now displays:

|0.63333333 |

A demo called DimensionlessExample has been added to the djunits-demo project to show the parsing and printing of Dimensionless and FloatDimensionless scalars, as well as SIScalar and FloatSIScalar where the SI dimensions are 1. Examples for Vector, FloatVector, SIVector and FloatSIVector are also included.

averbraeck added a commit that referenced this issue Jul 23, 2023
DIMLESS is defined as the SIUnit with all dimensions equal to zero:
SIUnit.of(new SIDimensions(0, 0, 0, 0, 0, 0, 0, 0, 0))
@averbraeck
Copy link
Owner Author

A helper static constant for the SIUnit class called DIMLESS is added. It is the DIMLESS is defined as the SIUnit with all dimensions equal to zero:

  SIUnit DIMLESS = SIUnit.of(new SIDimensions(0, 0, 0, 0, 0, 0, 0, 0, 0));

averbraeck added a commit to averbraeck/djunits-generator that referenced this issue Jul 24, 2023
averbraeck added a commit that referenced this issue Jul 24, 2023
The Dimensionless unit and SI quantity for dimensionless now display ""
instead of "1" (or even "unit").
@averbraeck
Copy link
Owner Author

All 283 unit tests pass again after the changes of the SIDimensions and SIUnit to accept and print an empty string for a dimensionless quantity.

@averbraeck
Copy link
Owner Author

The following changes have been made:

  • DimensionlessUnit has an empty string as the default unit id and unit name.
  • Dimensionless can parse an empty string as the unit in the of(...) and valueOf(...) methods
  • FloatDimensionless can parse an empty string as the unit in the of(...) and valueOf(...) methods
  • SIDimensions accepts an empty string as the unit in the of(...) and parse(...) methods
  • SIDimensions has a static constant called DIMLESS to indicate a dimensionless SI tuple
  • SIUnit has a static constant called DIMLESS to indicate a dimensionless SI unit
  • SIScalar accepts an empty string as the unit in the of(...) and valueOf(...) methods
  • FloatSIScalar accepts an empty string as the unit in the of(...) and valueOf(...) methods
  • SIVector can parse an empty string as the unit in the three of(...) methods
  • FloatSIVector can parse an empty string as the unit in the three of(...) methods
  • SIMatrix can parse an empty string as the unit in the of(...) method
  • FloatSIMatrix can parse an empty string as the unit in the of(...) method
  • A demo called DimensionlessExample has been added to the djunits-demo project
  • All generating classes and templates in the djunits-generator project have been adapted
  • All unit tests in the djunits project have been updated with the new behavior for dimensionless SI values

This covers all known issues with dimensionless SI values to not print or use '1' anymore as the unit, but leave it blank in the exact way that Dimensionless now prints it unit after Issue #12 was completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
simplification Simplification o code
Projects
None yet
Development

No branches or pull requests

2 participants