@@ -296,14 +296,21 @@ geodesic.Accumulator = {};
296296 m.sincosd = function(x) {
297297 // In order to minimize round-off errors, this function exactly reduces
298298 // the argument to the range [-45, 45] before converting it to radians.
299- var r, q, s, c, sinx, cosx;
300- r = x % 360;
301- q = Math.round(r / 90); // If r is NaN this returns NaN
302- r -= 90 * q;
303- // now abs(r ) <= 45
304- r *= this.degree;
299+ var d, r, q, s, c, sinx, cosx;
300+ d = x % 360;
301+ q = Math.round(d / 90); // If d is NaN this returns NaN
302+ d -= 90 * q;
303+ // now abs(d ) <= 45
304+ r = d * this.degree;
305305 // Possibly could call the gnu extension sincos
306306 s = Math.sin(r); c = Math.cos(r);
307+ if (Math.abs(d) === 45) {
308+ c = Math.sqrt(0.5);
309+ s = m.copysign(c, r);
310+ } else if (Math.abs(d) === 30) {
311+ c = Math.sqrt(0.75);
312+ s = m.copysign(0.5, r)
313+ }
307314 switch (q & 3) {
308315 case 0: sinx = s; cosx = c; break;
309316 case 1: sinx = c; cosx = -s; break;
@@ -325,22 +332,29 @@ geodesic.Accumulator = {};
325332 m.sincosde = function(x, t) {
326333 // In order to minimize round-off errors, this function exactly reduces
327334 // the argument to the range [-45, 45] before converting it to radians.
328- var r, q, s, c, sinx, cosx;
329- r = x % 360;
330- q = Math.round(r / 90); // If r is NaN this returns NaN
331- r = m.AngRound((r - 90 * q) + t);
332- // now abs(r ) <= 45
333- r *= this.degree;
335+ var d, r, q, s, c, sinx, cosx;
336+ d = x % 360;
337+ q = Math.round(d / 90); // If d is NaN this returns NaN
338+ d = m.AngRound((d - 90 * q) + t);
339+ // now abs(d ) <= 45
340+ r = d * this.degree;
334341 // Possibly could call the gnu extension sincos
335342 s = Math.sin(r); c = Math.cos(r);
343+ if (Math.abs(d) === 45) {
344+ c = Math.sqrt(0.5);
345+ s = m.copysign(c, r);
346+ } else if (Math.abs(d) === 30) {
347+ c = Math.sqrt(0.75);
348+ s = m.copysign(0.5, r)
349+ }
336350 switch (q & 3) {
337351 case 0: sinx = s; cosx = c; break;
338352 case 1: sinx = c; cosx = -s; break;
339353 case 2: sinx = -s; cosx = -c; break;
340354 default: sinx = -c; cosx = s; break; // case 3
341355 }
342356 cosx += 0;
343- if (sinx === 0) sinx = m.copysign(sinx, x);
357+ if (sinx === 0) sinx = m.copysign(sinx, x+t );
344358 return {s: sinx, c: cosx};
345359 };
346360
0 commit comments