UNPKG

dive-deco

Version:

A TypeScript implementation of decompression calculation algorithms for scuba diving, featuring Bühlmann ZH-L16C algorithm with gradient factors, gas management, and oxygen toxicity tracking.

91 lines (90 loc) 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Depth = void 0; const types_1 = require("./types"); class Depth { m; constructor(meters = 0) { this.m = meters; } static zero() { return new Depth(0); } static fromMeters(val) { return new Depth(val); } static fromFeet(val) { return new Depth(Depth.ftToM(val)); } static fromUnits(val, units) { switch (units) { case types_1.Units.Metric: return Depth.fromMeters(val); case types_1.Units.Imperial: return Depth.fromFeet(val); } } asMeters() { return this.m; } asFeet() { return Depth.mToFt(this.m); } toUnits(units) { switch (units) { case types_1.Units.Metric: return this.asMeters(); case types_1.Units.Imperial: return this.asFeet(); } } baseUnit() { return this.m; } add(other) { return new Depth(this.m + other.m); } subtract(other) { return new Depth(this.m - other.m); } multiply(other) { if (typeof other === 'number') { return new Depth(this.m * other); } return new Depth(this.m * other.m); } divide(other) { if (typeof other === 'number') { return new Depth(this.m / other); } return new Depth(this.m / other.m); } addAssign(other) { this.m += other.m; } equals(other) { return this.m === other.m; } lessThan(other) { return this.m < other.m; } lessThanOrEqual(other) { return this.m <= other.m; } greaterThan(other) { return this.m > other.m; } greaterThanOrEqual(other) { return this.m >= other.m; } toString() { return `${this.asMeters()}m / ${this.asFeet()}ft`; } static mToFt(m) { return m * 3.28084; } static ftToM(ft) { return ft * 0.3048; } } exports.Depth = Depth;