-
Notifications
You must be signed in to change notification settings - Fork 0
/
customUnit.ts
31 lines (25 loc) · 1.04 KB
/
customUnit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { UnitNameConfig } from "./nameConstruct";
import Unit, { MathematicalConfig } from "./unit";
import { UnitShape, UnitBasisType, UnitShapeMap } from "./unitShape";
export class CustomUnit<ThisUnitShapeMap extends UnitShapeMap> extends Unit<ThisUnitShapeMap> {
toBaseSIFunction: (numInThisUnit: number) => number
fromBaseSIFunction: (numInBaseSI: number) => number
constructor(
shape: UnitShape<ThisUnitShapeMap>,
toBaseSIFunction: (numInThisUnit: number) => number,
fromBaseSIFunction: (numInBaseSI: number) => number,
mathConfig: MathematicalConfig,
nameConfig: UnitNameConfig,
){
super(shape, mathConfig, nameConfig)
this.toBaseSIFunction = toBaseSIFunction
this.fromBaseSIFunction = fromBaseSIFunction
}
toBaseSI(quantityInThisUnit: number): number {
return this.toBaseSIFunction(quantityInThisUnit)
}
fromBaseSI(quantityInBaseSI: number): number {
return this.fromBaseSIFunction(quantityInBaseSI)
}
}
export default CustomUnit