jalhyd
Version:
JaLHyd, a Javascript Library for Hydraulics
99 lines • 2.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Interval = void 0;
const internal_modules_1 = require("../internal_modules");
const internal_modules_2 = require("../internal_modules");
/**
* Couple de valeurs ordonnées
*/
class Interval extends internal_modules_2.Debug {
constructor(val1, val2, dbg = false) {
super(dbg);
this.val1 = val1;
this.val2 = val2;
}
setValues(v1, v2) {
this.val1 = v1;
this.val2 = v2;
}
/** "constructeur" par copie */
setInterval(i) {
this.setValues(i.val1, i.val2);
}
get min() {
return Math.min(this.val1, this.val2);
}
get max() {
return Math.max(this.val1, this.val2);
}
get length() {
return this.max - this.min;
}
intervalHasValue(v) {
return this.min <= v && v <= this.max;
}
intersect(i) {
const min = Math.max(this.min, i.min);
const max = Math.min(this.max, i.max);
let intersection = null;
if (min <= max) {
intersection = new Interval(min, max);
} // else no intersection
return intersection;
}
checkValue(v) {
if (v === undefined) {
const e = new internal_modules_1.Message(internal_modules_1.MessageCode.ERROR_INTERVAL_UNDEF);
throw e;
}
if (!this.intervalHasValue(v)) {
const e = new internal_modules_1.Message(internal_modules_1.MessageCode.ERROR_INTERVAL_OUTSIDE);
e.extraVar.value = v;
e.extraVar.interval = this.toString();
throw e;
}
}
toString() {
return "[" + this.min + "," + this.max + "]";
}
getVal(i) {
if (i < 1 || i > 2) {
throw new Error("Interval getVal n'accepte que 1 ou 2 en argument");
}
if (i === 1) {
return this.val1;
}
else {
return this.val2;
}
}
setVal(i, val) {
if (i < 1 || i > 2) {
throw new Error("Interval getVal n'accepte que 1 ou 2 en argument");
}
if (i === 1) {
this.val1 = val;
}
else {
this.val2 = val;
}
}
get minIndex() {
if (this.val1 === this.min) {
return 1;
}
else {
return 2;
}
}
get maxIndex() {
if (this.val1 === this.max) {
return 1;
}
else {
return 2;
}
}
}
exports.Interval = Interval;
//# sourceMappingURL=interval.js.map