// https://github.com/Fil/versor v0.2.0 Copyright 2021 Mike Bostock
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).versor=n()}(this,(function(){"use strict";const t=Math.acos,n=Math.asin,e=Math.atan2,r=Math.cos,o=Math.hypot,s=Math.max,a=Math.min,i=Math.PI,c=Math.sin,l=i/180,u=180/i;class f{static fromCartesian([t,n,e]){return[0,e,-n,t]}static fromAngles([t,n,e]){n*=l/2,e=(e||0)*l/2;const o=c(t*=l/2),s=r(t),a=c(n),i=r(n),u=c(e),f=r(e);return[s*i*f+o*a*u,o*i*f-s*a*u,s*a*f+o*i*u,s*i*u-o*a*f]}static toAngles([t,r,o,i]){return[e(2*(t*r+o*i),1-2*(r*r+o*o))*u,n(s(-1,a(1,2*(t*o-i*r))))*u,e(2*(t*i+r*o),1-2*(o*o+i*i))*u]}static interpolateAngles(t,n){const e=f.interpolate(f.fromAngles(t),f.fromAngles(n));return t=>f.toAngles(e(t))}static interpolateLinear([t,n,e,r],[s,a,i,c]){s-=t,a-=n,i-=e,c-=r;const l=new Array(4);return u=>{const f=o(l[0]=t+s*u,l[1]=n+a*u,l[2]=e+i*u,l[3]=r+c*u);return l[0]/=f,l[1]/=f,l[2]/=f,l[3]/=f,l}}static interpolate([n,e,i,l],[u,p,h,d]){let m=f.dot([n,e,i,l],[u,p,h,d]);if(m<0&&(u=-u,p=-p,h=-h,d=-d,m=-m),m>.9995)return f.interpolateLinear([n,e,i,l],[u,p,h,d]);const g=t(s(-1,a(1,m))),A=new Array(4),y=o(u-=n*m,p-=e*m,h-=i*m,d-=l*m);return u/=y,p/=y,h/=y,d/=y,t=>{const o=g*t,s=c(o),a=r(o);return A[0]=n*a+u*s,A[1]=e*a+p*s,A[2]=i*a+h*s,A[3]=l*a+d*s,A}}static dot([t,n,e,r],[o,s,a,i]){return t*o+n*s+e*a+r*i}static multiply([t,n,e,r],[o,s,a,i]){return[t*o-n*s-e*a-r*i,t*s+n*o+e*i-r*a,t*a-n*i+e*o+r*s,t*i+n*a-e*s+r*o]}}const p=f.fromAngles;return p.multiply=f.multiply,p.rotation=f.toAngles,p.interpolate=f.interpolateAngles,p.cartesian=function(t){const n=t[0]*l,e=t[1]*l,o=r(e);return[o*r(n),o*c(n),c(e)]},p.delta=function(n,e,o){2==arguments.length&&(o=1);const i=Math.sqrt;function l(t,n){return[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]]}function u(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]}const f=l(n,e),p=i(u(f,f));if(!p)return[1,0,0,0];const h=o*t(s(-1,a(1,u(n,e))))/2,d=c(h);return[r(h),f[2]/p*d,-f[1]/p*d,f[0]/p*d]},p}));