averbraeck / djunits

Delft Java UNIT System for using strongly-typed quantities and units
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

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

Closed averbraeck closed 1 year ago

averbraeck commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

The following changes have been made:

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.