import { Pointing } from './Pointing.js'; import { Vec3 } from './Vec3.js'; import { Zphi } from './Zphi.js'; export class Hploc { constructor(ptg) { Hploc.PI4_A = 0.7853981554508209228515625; Hploc.PI4_B = 0.794662735614792836713604629039764404296875e-8; Hploc.PI4_C = 0.306161699786838294306516483068750264552437361480769e-16; Hploc.M_1_PI = 0.3183098861837906715377675267450287; if (ptg) { this.sth = 0.0; this.have_sth = false; this.z = Hploc.cos(ptg.theta); this._phi = ptg.phi; if (Math.abs(this.z) > 0.99) { this.sth = Hploc.sin(ptg.theta); this.have_sth = true; } } } setZ(z) { this.z = z; } ; get phi() { return this._phi; } ; set phi(phi) { this._phi = phi; } ; setSth(sth) { this.sth = sth; } ; toPointing(mirror) { const st = this.have_sth ? this.sth : Math.sqrt((1.0 - this.z) * (1.0 + this.z)); return new Pointing(null, false, Hploc.atan2(st, this.z), this._phi); } toVec3() { var st = this.have_sth ? this.sth : Math.sqrt((1.0 - this.z) * (1.0 + this.z)); var vector = new Vec3(st * Hploc.cos(this.phi), st * Hploc.sin(this.phi), this.z); // var vector = new Vec3(st*Math.cos(this.phi),st*Math.sin(this.phi),this.z); return vector; } ; toZphi() { return new Zphi(this.z, this.phi); } static sin(d) { let u = d * Hploc.M_1_PI; let q = Math.floor(u < 0 ? u - 0.5 : u + 0.5); let x = 4.0 * q; d -= x * Hploc.PI4_A; d -= x * Hploc.PI4_B; d -= x * Hploc.PI4_C; if ((q & 1) != 0) { d = -d; } return this.sincoshelper(d); } ; static cos(d) { // let u = d * Hploc.M_1_PI - 0.5; let u = d * Hploc.M_1_PI - 0.5; // u -= 0.5; let q = 1 + 2 * Math.floor(u < 0 ? u - 0.5 : u + 0.5); let x = 2.0 * q; let t = x * Hploc.PI4_A; d = d - t; d -= x * Hploc.PI4_B; d -= x * Hploc.PI4_C; if ((q & 2) == 0) { d = -d; } return Hploc.sincoshelper(d); } ; static sincoshelper(d) { let s = d * d; let u = -7.97255955009037868891952e-18; u = u * s + 2.81009972710863200091251e-15; u = u * s - 7.64712219118158833288484e-13; u = u * s + 1.60590430605664501629054e-10; u = u * s - 2.50521083763502045810755e-08; u = u * s + 2.75573192239198747630416e-06; u = u * s - 0.000198412698412696162806809; u = u * s + 0.00833333333333332974823815; u = u * s - 0.166666666666666657414808; return s * u * d + d; } ; /** This method calculates the arc sine of x in radians. The return value is in the range [-pi/2, pi/2]. The results may have maximum error of 3 ulps. */ static asin(d) { return Hploc.mulsign(Hploc.atan2k(Math.abs(d), Math.sqrt((1 + d) * (1 - d))), d); } ; /** This method calculates the arc cosine of x in radians. The return value is in the range [0, pi]. The results may have maximum error of 3 ulps. */ static acos(d) { return Hploc.mulsign(Hploc.atan2k(Math.sqrt((1 + d) * (1 - d)), Math.abs(d)), d) + (d < 0 ? Math.PI : 0); } ; static mulsign(x, y) { let sign = Hploc.copySign(1, y); return sign * x; } ; static copySign(magnitude, sign) { return sign < 0 ? -Math.abs(magnitude) : Math.abs(magnitude); // let finalsign = 1; // if (Object.is(finalsign , -0)){ // sign = -1; // }else if (Object.is(finalsign , 0)){ // sign = 1; // }else { // sign = Math.sign(finalsign); // } // return finalsign * magnitude; } static atanhelper(s) { let t = s * s; let u = -1.88796008463073496563746e-05; u = u * t + (0.000209850076645816976906797); u = u * t + (-0.00110611831486672482563471); u = u * t + (0.00370026744188713119232403); u = u * t + (-0.00889896195887655491740809); u = u * t + (0.016599329773529201970117); u = u * t + (-0.0254517624932312641616861); u = u * t + (0.0337852580001353069993897); u = u * t + (-0.0407629191276836500001934); u = u * t + (0.0466667150077840625632675); u = u * t + (-0.0523674852303482457616113); u = u * t + (0.0587666392926673580854313); u = u * t + (-0.0666573579361080525984562); u = u * t + (0.0769219538311769618355029); u = u * t + (-0.090908995008245008229153); u = u * t + (0.111111105648261418443745); u = u * t + (-0.14285714266771329383765); u = u * t + (0.199999999996591265594148); u = u * t + (-0.333333333333311110369124); return u * t * s + s; } ; static atan2k(y, x) { let q = 0.; if (x < 0) { x = -x; q = -2.; } if (y > x) { let t = x; x = y; y = -t; q += 1.; } return Hploc.atanhelper(y / x) + q * (Math.PI / 2); } ; /** This method calculates the arc tangent of y/x in radians, using the signs of the two arguments to determine the quadrant of the result. The results may have maximum error of 2 ulps. */ static atan2(y, x) { let r = Hploc.atan2k(Math.abs(y), x); r = Hploc.mulsign(r, x); if (Hploc.isinf(x) || x == 0) { r = Math.PI / 2 - (Hploc.isinf(x) ? (Hploc.copySign(1, x) * (Math.PI / 2)) : 0); } if (Hploc.isinf(y)) { r = Math.PI / 2 - (Hploc.isinf(x) ? (Hploc.copySign(1, x) * (Math.PI * 1 / 4)) : 0); } if (y == 0) { r = (Hploc.copySign(1, x) == -1 ? Math.PI : 0); } return Hploc.isnan(x) || Hploc.isnan(y) ? NaN : Hploc.mulsign(r, y); } ; /** Checks if the argument is a NaN or not. */ static isnan(d) { return d != d; } ; /** Checks if the argument is either positive or negative infinity. */ static isinf(d) { return Math.abs(d) === +Infinity; } ; } Hploc.PI4_A = 0.7853981554508209228515625; Hploc.PI4_B = 0.794662735614792836713604629039764404296875e-8; Hploc.PI4_C = 0.306161699786838294306516483068750264552437361480769e-16; Hploc.M_1_PI = 0.3183098861837906715377675267450287; //# sourceMappingURL=Hploc.js.map