Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/org/parts3492/partslib/PARTsUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,14 @@ public double to(PARTsUnitType unitType) {
String message = "No to type for unit.";
switch (this.unitType) {
case Angle:
if (unitType == PARTsUnitType.Radian) return this.value * Math.PI / 180.0;
else if (unitType == this.unitType) return this.value;
throw new RuntimeException(message);
switch (unitType) {
case Radian:
return this.value * Math.PI / 180.0;
case Angle:
return this.value;
default:
throw new RuntimeException(message);
}
case Radian:
if (unitType == PARTsUnitType.Angle) return this.value * 180.0 / Math.PI;
else if (unitType == this.unitType) return this.value;
Expand Down Expand Up @@ -120,23 +125,34 @@ public double to(PARTsUnitType unitType) {
switch (unitType) {
case Angle:
return this.value * 360;
case Rotations:
return this.value;
default:
throw new RuntimeException(message);
}
case Percent:
throw new RuntimeException(
message + " Percent cannot not be translated to any other type.");
switch (unitType) {
case Percent:
return this.value;
default:
throw new RuntimeException(
message + " Percent cannot not be translated to any other type.");
}
case Pound:
switch (unitType) {
case Kilogram:
return this.value * 0.453592;
case Pound:
return this.value;
default:
throw new RuntimeException(message);
}
case Kilogram:
switch (unitType) {
case Pound:
return this.value * 2.2046226218;
case Kilogram:
return this.value;
default:
throw new RuntimeException(message);
}
Expand Down
Loading