PageSourceSearch

https://astro-apps.org/OrbitalElements/src/astro_math.js

js astro-apps.org collected 2026-10-06 21:27:31 UTC 2,640 bytes, 131 lines download raw bytes

1/*!
2   @file:   astro_math.js
3   @author: Thomas Mueller, HdA/MPIA
4  
5 */
6
7export function frac(x) {
8    return x - Math.floor(x)
9}
10
11export function modulo(x, y) {
12    return y * frac(x / y);
13}
14
15export function toDegree(val) {
16    return val / Math.PI * 180;
17}
18
19export function toRadian(val) {
20    return val / 180 * Math.PI;
21}
22
23export function arcsec2rad(val) {
24    return toRadian(val / 3600);
25}
26
27export function arcmin2rad(val) {
28    return toRadian(val / 60);
29}
30
31export function rad2arcsec(val) {
32    return toDegree(val) * 3600;
33}
34
35export function rad2arcmin(val) {
36    return toDegree(val) * 60;
37}
38
39export function Ddd(d, m, s) {
40    let sig = 1.0;
41    if (d < 0 || m < 0 || s < 0) {
42        sig = -1.0;
43    }
44    return sig * (Math.abs(d) + Math.abs(m) / 60 + Math.abs(s) / 3600);
45}
46
47export function clamp(x, xmin, xmax) {
48    return Math.max(xmin, Math.min(xmax, x));
49}
50
51export const MapRangeType = {
52    Linear: 0,
53    Quadratic: 1,
54    Cubic: 2,
55    Quartic: 3
56}
57
58export class MapRange {
59    constructor() {
60        this.minValue = 0.0;
61        this.maxValue = 1.0;
62
63        this.type = MapRangeType.Linear;
64    }
65
66    getValue(t) {
67        let x = this.resolve_forward(clamp(t, 0.0, 1.0));
68        return this.minValue * (1.0 - x) + x * this.maxValue;
69    }
70
71    getParam(val) {        
72        let x = (val - this.minValue) / (this.maxValue - this.minValue);        
73        x = clamp(x, 0.0, 1.0);
74        return this.resolve_backward(x);
75    }
76
77    setRange(vmin, vmax) {
78        this.minValue = vmin;
79        this.maxValue = vmax;
80    }
81
82    setType(type) {
83        this.type = type;
84    }
85
86    resolve_forward(t) {
87        if (this.type == MapRangeType.Linear) {
88            return t;
89        }
90        else if (this.type == MapRangeType.Quadratic) {
91            return t * t;
92        }
93        else if (this.type == MapRangeType.Cubic) {
94            return t * t * t;
95        }
96        else if (this.type == MapRangeType.Quartic) {
97            return Math.pow(t, 4.0);
98        }
99    }
100
101    resolve_backward(x) {
102        if (this.type == MapRangeType.Linear) {
103            return x;
104        }
105        else if (this.type == MapRangeType.Quadratic) {
106            return Math.sqrt(x);
107        }
108        else if (this.type == MapRangeType.Cubic) {
109            return Math.pow(x, 1.0/3.0);
110        }
111        else if (this.type == MapRangeType.Quartic) {
112            return Math.pow(x, 0.25);
113        }
114    }
115
116    get vmin() {
117        return this.minValue;
118    }
119
120    get vmax() {
121        return this.maxValue;
122    }
123
124    set vmin(val) {
125        this.minValue = val;
126    }
127
128    set vmax(val) {
129        this.maxValue = val;
130    }
131}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.