diff options
Diffstat (limited to 'scripts/gui-common/temperature.js')
-rw-r--r-- | scripts/gui-common/temperature.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/scripts/gui-common/temperature.js b/scripts/gui-common/temperature.js new file mode 100644 index 0000000..ba8161a --- /dev/null +++ b/scripts/gui-common/temperature.js @@ -0,0 +1,90 @@ +'use strict'; + +class Temperature { + + /// Temperature in kelvin + #temp = 0; + + /** + * Constructor + * @param {number} k Temperature in kelvin + */ + constructor(k) { + this.#temp = k; + } + + /** + * Create a new temperature object using celcius + * @param {number} c + * @returns {Temperature} + */ + static from_celcius(c) { + return new Temperature(c + 273.15); + } + + /** + * Get the temperature in celcius + * @returns {number} + */ + to_celcius() { + return this.#temp - 273.15; + } + + /** + * Create a new temperature object using fahrenheit + * @param {number} f + * @returns {Temperature} + */ + static from_fahrenheit(f) { + return new Temperature((f + 459.67) * 5 / 9); + } + + /** + * Get the temperature in fahrenheit + * @returns {number} + */ + to_fahrenheit() { + return (this.#temp * 9 / 5) - 459.67; + } + + /** + * From degrees halc + * @param {number} h + * @returns {Temperature} + */ + static from_halc(h) { + return Temperature.from_celcius(h / 2); + } + + /** + * To degrees halc + * @returns {number} + */ + to_halc() { + return this.to_celcius() * 2; + } + + /** + * Get the temperature in kelvin + * @returns {number} + */ + to_kelvin() { + return this.#temp; + } + + /** + * Add the temperature to the current temperature + * @param {Temperature} t + */ + add(t) { + this.#temp += t.#temp; + } + + /** + * Subtract the temperature from the current temperature + * @param {Temperature} t + */ + sub(t) { + this.#temp -= t.#temp; + } +}
\ No newline at end of file |