Skip to content

Commit e9c1ea7

Browse files
committed
base unit conversions
1 parent 7d23155 commit e9c1ea7

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Adheres to [Semantic Versioning](http://semver.org/).
1111
* Common Geo Datums, Ellipsoids, and Prime Meridians
1212
* Additional common Operation Method aliases
1313
* Temporal Datum method name correction, setOriginDateTime, previously setStartDateTime
14+
* Unit conversions for backwards compatible base unit types
1415

1516
## [1.0.0](https://github.com/ngageoint/coordinate-reference-systems-java/releases/tag/1.0.0) (06-24-2021)
1617

src/main/java/mil/nga/crs/common/Units.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ public static Unit createDefaultUnit(UnitType type) {
343343
*/
344344
public static boolean canConvert(Unit unit1, Unit unit2) {
345345
return unit1 != null && unit2 != null
346-
&& unit1.getType() == unit2.getType()
346+
&& (unit1.getType() == unit2.getType()
347+
|| unit1.getType() == UnitType.UNIT
348+
|| unit2.getType() == UnitType.UNIT)
347349
&& unit1.hasConversionFactor() && unit2.hasConversionFactor();
348350
}
349351

@@ -361,7 +363,8 @@ public static boolean canConvert(Unit unit1, Unit unit2) {
361363
*/
362364
public static double convert(double value, Unit from, Unit to) {
363365

364-
if (from.getType() != to.getType()) {
366+
if (from.getType() != to.getType() && from.getType() != UnitType.UNIT
367+
&& to.getType() != UnitType.UNIT) {
365368
throw new CRSException("Can't convert value '" + value
366369
+ "' from unit type " + from.getType().name()
367370
+ " to unit type " + to.getType().name());

0 commit comments

Comments
 (0)