mirror of
https://github.com/Krafpy/KSP-MGA-Planner.git
synced 2025-12-28 13:44:32 -08:00
- Reimplemented 2D orbital mechanics functions in physics-2d.ts and encaspulated inside a `Physics2D` namespace. - Deleted physics.ts and moved the required functions into physics-3d.ts Further cleaning and reimplemntation will be done on the physics-3d.ts content. - Forced consistency on error handling : every raised error throws an `Error` object. - Commented sections relative to 2D physics and sequence generation.
38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
export class IntegerInput {
|
|
constructor(id) {
|
|
this.element = document.getElementById(id);
|
|
this.min = parseInt(this.element.min);
|
|
this.max = parseInt(this.element.max);
|
|
this.element.onchange = () => this.validate();
|
|
}
|
|
get value() {
|
|
return parseInt(this.element.value);
|
|
}
|
|
set value(num) {
|
|
this.element.value = num.toString();
|
|
}
|
|
validate() {
|
|
let num = parseInt(this.element.value);
|
|
if (!isNaN(num)) {
|
|
num = this._clamp(num);
|
|
this.element.value = num.toString();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
_clamp(num) {
|
|
if (!isNaN(this.min) && !isNaN(this.max))
|
|
return THREE.MathUtils.clamp(num, this.min, this.max);
|
|
return num;
|
|
}
|
|
assertValidity() {
|
|
if (!this.validate())
|
|
throw new Error("Invalid numeric input.");
|
|
}
|
|
setMinMax(min, max) {
|
|
this.min = min;
|
|
this.max = max;
|
|
this.value = this._clamp(this.value);
|
|
}
|
|
}
|