mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
feat: add temperature unit conversions (#5315)
Co-authored-by: Bama Charan Chhandogi <b.c.chhandogi@gmail.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.thealgorithms.conversions;
|
||||
|
||||
public final class AffineConverter {
|
||||
private final double slope;
|
||||
private final double intercept;
|
||||
public AffineConverter(final double inSlope, final double inIntercept) {
|
||||
slope = inSlope;
|
||||
intercept = inIntercept;
|
||||
}
|
||||
|
||||
public double convert(final double inValue) {
|
||||
return slope * inValue + intercept;
|
||||
}
|
||||
|
||||
public AffineConverter invert() {
|
||||
assert slope != 0.0;
|
||||
return new AffineConverter(1.0 / slope, -intercept / slope);
|
||||
}
|
||||
|
||||
public AffineConverter compose(final AffineConverter other) {
|
||||
return new AffineConverter(slope * other.slope, slope * other.intercept + intercept);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user