davinci-newton
Version:
Physics Modeling and Engine using Geometric Algebra
12 lines (11 loc) • 595 kB
JavaScript
/**
* davinci-newton 1.0.107
* (c) David Geo Holmes david.geo.holmes@gmail.com
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.NEWTON = {}));
})(this, (function (exports) { 'use strict';
const t=[0,0],i=[];class s{numer_;denom_;constructor(t,i){let s;if(0===i)throw new Error("denominator must not be zero");s=0===t?1:function(t,i){let s;for(t<0&&(t=-t),i<0&&(i=-i),i>t&&(s=t,t=i,i=s);;){if(0==(t%=i))return i;if(0==(i%=t))return t}}(Math.abs(t),Math.abs(i)),i<0&&(t=-t,i=-i),this.numer_=t/s,this.denom_=i/s;}get numer(){return this.numer_}get denom(){return this.denom_}add(t){return s.valueOf(this.numer_*t.denom_+this.denom_*t.numer_,this.denom_*t.denom_)}sub(t){return s.valueOf(this.numer_*t.denom_-this.denom_*t.numer_,this.denom_*t.denom_)}mul(t){return s.valueOf(this.numer_*t.numer_,this.denom_*t.denom_)}div(t){const i=this.numer_*t.denom_,e=this.denom_*t.numer_;return 0===i?0===e?s.valueOf(i,e):s.ZERO:s.valueOf(i,e)}isOne(){return 1===this.numer_&&1===this.denom_}isZero(){return 0===this.numer_&&1===this.denom_}hashCode(){return 37*this.numer_+13*this.denom_}inv(){return s.valueOf(this.denom_,this.numer_)}neg(){return s.valueOf(-this.numer_,this.denom_)}equals(t){return this===t||t instanceof s&&this.numer_*t.denom_==this.denom_*t.numer_}toString(t){return this.numer_.toString(t)+"/"+this.denom_.toString(t)}__add__(t){return t instanceof s?this.add(t):void 0}__radd__(t){return t instanceof s?t.add(this):void 0}__sub__(t){return t instanceof s?this.sub(t):void 0}__rsub__(t){return t instanceof s?t.sub(this):void 0}__mul__(t){return t instanceof s?this.mul(t):void 0}__rmul__(t){return t instanceof s?t.mul(this):void 0}__div__(t){return t instanceof s?this.div(t):void 0}__rdiv__(t){return t instanceof s?t.div(this):void 0}__pos__(){return this}__neg__(){return this.neg()}static ZERO=new s(0,1);static valueOf(e,r){!function(t,i,s){let e;if(0===i)throw new Error("denominator must not be zero");e=0===t?1:function(t,i){let s;for(t<0&&(t=-t),i<0&&(i=-i),i>t&&(s=t,t=i,i=s);;){if(0==(t%=i))return i;if(0==(i%=t))return t}}(Math.abs(t),Math.abs(i)),i<0&&(t=-t,i=-i),s[0]=t/e,s[1]=i/e;}(e,r,t),e=t[0],r=t[1];for(const t of i)if(t.numer_===e&&t.denom_===r)return t;const o=new s(e,r);return i.push(o),o}}var e;!function(t){t[t.AMOUNT_OF_SUBSTANCE=0]="AMOUNT_OF_SUBSTANCE",t[t.ANGULAR_MOMENTUM=1]="ANGULAR_MOMENTUM",t[t.AREA=2]="AREA",t[t.ELECTRIC_CHARGE=3]="ELECTRIC_CHARGE",t[t.ELECTRIC_CURRENT=4]="ELECTRIC_CURRENT",t[t.ELECTRIC_FIELD=5]="ELECTRIC_FIELD",t[t.ELECTRIC_PERMITTIVITY_TIMES_AREA=6]="ELECTRIC_PERMITTIVITY_TIMES_AREA",t[t.ENERGY_OR_TORQUE=7]="ENERGY_OR_TORQUE",t[t.FORCE=8]="FORCE",t[t.FRICTION_COEFFICIENT=9]="FRICTION_COEFFICIENT",t[t.INV_LENGTH=10]="INV_LENGTH",t[t.INV_MASS=11]="INV_MASS",t[t.INV_MOMENT_OF_INERTIA=12]="INV_MOMENT_OF_INERTIA",t[t.INV_TIME=13]="INV_TIME",t[t.LENGTH=14]="LENGTH",t[t.LUMINOUS_INTENSITY=15]="LUMINOUS_INTENSITY",t[t.MASS=16]="MASS",t[t.MOMENT_OF_INERTIA=17]="MOMENT_OF_INERTIA",t[t.MOMENTUM=18]="MOMENTUM",t[t.MOMENTUM_SQUARED=19]="MOMENTUM_SQUARED",t[t.ONE=20]="ONE",t[t.RATE_OF_CHANGE_OF_AREA=21]="RATE_OF_CHANGE_OF_AREA",t[t.STIFFNESS=22]="STIFFNESS",t[t.THERMODYNAMIC_TEMPERATURE=23]="THERMODYNAMIC_TEMPERATURE",t[t.TIME=24]="TIME",t[t.TIME_SQUARED=25]="TIME_SQUARED",t[t.VELOCITY=26]="VELOCITY",t[t.VELOCITY_SQUARED=27]="VELOCITY_SQUARED",t[t.VOLUME=28]="VOLUME";}(e||(e={}));const r=[],o=s.valueOf(0,1),n=s.valueOf(1,1),h=s.valueOf(2,1),u=s.valueOf(3,1),c=s.valueOf(-1,1),a=s.valueOf(-2,1);function m(t,i){if(i instanceof s)return i;throw new Error(`Argument ${t} => ${i} must be a QQ`)}let l="strict";function d(t){switch(t){case"strict":case"none":l=t;break;default:throw new Error("mode must be 'none' or 'strict'.")}}class y{static ONE=new y(o,o,o,o,o,o,o,e.ONE);static MASS=new y(n,o,o,o,o,o,o,e.MASS);static LENGTH=new y(o,n,o,o,o,o,o,e.LENGTH);static AREA=new y(o,h,o,o,o,o,o,e.AREA);static VOLUME=new y(o,u,o,o,o,o,o,e.VOLUME);static INV_LENGTH=new y(o,c,o,o,o,o,o,e.INV_LENGTH);static TIME=new y(o,o,n,o,o,o,o,e.TIME);static ELECTRIC_CHARGE=new y(o,o,o,n,o,o,o,e.ELECTRIC_CHARGE);static ELECTRIC_CURRENT=new y(o,o,c,n,o,o,o,e.ELECTRIC_CURRENT);static THERMODYNAMIC_TEMPERATURE=new y(o,o,o,o,n,o,o,e.THERMODYNAMIC_TEMPERATURE);static AMOUNT_OF_SUBSTANCE=new y(o,o,o,o,o,n,o,e.AMOUNT_OF_SUBSTANCE);static LUMINOUS_INTENSITY=new y(o,o,o,o,o,o,n,e.LUMINOUS_INTENSITY);static ANGULAR_MOMENTUM=new y(n,h,c,o,o,o,o,e.ANGULAR_MOMENTUM);static RATE_OF_CHANGE_OF_AREA=new y(o,h,c,o,o,o,o,e.RATE_OF_CHANGE_OF_AREA);static ELECTRIC_FIELD=new y(n,n,a,c,o,o,o,e.ELECTRIC_FIELD);static ELECTRIC_PERMITTIVITY_TIMES_AREA=new y(c,c,h,h,o,o,o,e.ELECTRIC_PERMITTIVITY_TIMES_AREA);static ENERGY_OR_TORQUE=new y(n,h,a,o,o,o,o,e.ENERGY_OR_TORQUE);static FORCE=new y(n,n,a,o,o,o,o,e.FORCE);static INV_MASS=new y(c,o,o,o,o,o,o,e.INV_MASS);static INV_MOMENT_OF_INERTIA=new y(c,a,o,o,o,o,o,e.INV_MOMENT_OF_INERTIA);static INV_TIME=new y(o,o,c,o,o,o,o,e.INV_TIME);static MOMENT_OF_INERTIA=new y(n,h,o,o,o,o,o,e.MOMENT_OF_INERTIA);static MOMENTUM=new y(n,n,c,o,o,o,o,e.MOMENTUM);static MOMENTUM_SQUARED=new y(h,h,a,o,o,o,o,e.MOMENTUM_SQUARED);static STIFFNESS=new y(n,o,a,o,o,o,o,e.STIFFNESS);static FRICTION_COEFFICIENT=new y(n,o,c,o,o,o,o,e.FRICTION_COEFFICIENT);static TIME_SQUARED=new y(o,o,h,o,o,o,o,e.TIME_SQUARED);static VELOCITY=new y(o,n,c,o,o,o,o,e.VELOCITY);static VELOCITY_SQUARED=new y(o,h,a,o,o,o,o,e.VELOCITY_SQUARED);M;L;T;Q;temperature;amount;intensity;summary_;constructor(t,i,s,e,r,o,n,h){this.M=m("M",t),this.L=m("L",i),this.T=m("T",s),this.Q=m("Q",e),this.temperature=m("temperature",r),this.amount=m("amount",o),this.intensity=m("intensity",n),this.summary_=h;}get summary(){return this.summary_}compatible(t){if("number"==typeof this.summary_&&this.summary_===t.summary_)return this;if(this.M.equals(t.M)&&this.L.equals(t.L)&&this.T.equals(t.T)&&this.Q.equals(t.Q)&&this.temperature.equals(t.temperature)&&this.amount.equals(t.amount)&&this.intensity.equals(t.intensity))return this;if(this.isOne()){if(t.isOne())throw new Error;if("none"===l)return t;throw new Error(`Dimensions must be equal (dimensionless, ${t})`)}if(t.isOne()){if("none"===l)return this;throw new Error(`Dimensions must be equal (${this}, dimensionless)`)}if("none"===l)return this;throw new Error(`Dimensions must be equal (${this}, ${t})`)}equals(t){return this===t||this.M.equals(t.M)&&this.L.equals(t.L)&&this.T.equals(t.T)&&this.Q.equals(t.Q)&&this.temperature.equals(t.temperature)&&this.amount.equals(t.amount)&&this.intensity.equals(t.intensity)}mul(t){return y.valueOf(this.M.add(t.M),this.L.add(t.L),this.T.add(t.T),this.Q.add(t.Q),this.temperature.add(t.temperature),this.amount.add(t.amount),this.intensity.add(t.intensity))}div(t){return y.valueOf(this.M.sub(t.M),this.L.sub(t.L),this.T.sub(t.T),this.Q.sub(t.Q),this.temperature.sub(t.temperature),this.amount.sub(t.amount),this.intensity.sub(t.intensity))}pow(t){return y.valueOf(this.M.mul(t),this.L.mul(t),this.T.mul(t),this.Q.mul(t),this.temperature.mul(t),this.amount.mul(t),this.intensity.mul(t))}sqrt(){return y.valueOf(this.M.div(h),this.L.div(h),this.T.div(h),this.Q.div(h),this.temperature.div(h),this.amount.div(h),this.intensity.div(h))}isOne(){return this===y.ONE||this.M.isZero()&&this.L.isZero()&&this.T.isZero()&&this.Q.isZero()&&this.temperature.isZero()&&this.amount.isZero()&&this.intensity.isZero()}inv(){return y.valueOf(this.M.neg(),this.L.neg(),this.T.neg(),this.Q.neg(),this.temperature.neg(),this.amount.neg(),this.intensity.neg())}toString(){const t=function(t,i){return 0===t.numer?null:1===t.denom?1===t.numer?""+i:i+" ** "+t.numer:i+" ** "+t};return [t(this.M,"mass"),t(this.L,"length"),t(this.T,"time"),t(this.Q,"charge"),t(this.temperature,"thermodynamic temperature"),t(this.amount,"amount of substance"),t(this.intensity,"luminous intensity")].filter((function(t){return "string"==typeof t})).join(" * ")}__add__(t){return t instanceof y?this.compatible(t):void 0}__radd__(t){return t instanceof y?t.compatible(this):void 0}__sub__(t){return t instanceof y?this.compatible(t):void 0}__rsub__(t){return t instanceof y?t.compatible(this):void 0}__mul__(t){return t instanceof y?this.mul(t):void 0}__rmul__(t){return t instanceof y?t.mul(this):void 0}__div__(t){return t instanceof y?this.div(t):void 0}__rdiv__(t){return t instanceof y?t.div(this):void 0}__pos__(){return this}__neg__(){return this}static valueOf(t,i,s,o,n,h,u){const c=function(t,i,s,r,o,n,h){if(-1===t.numer){if(1===t.denom)if(-2===i.numer){if(1===i.denom&&0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.INV_MOMENT_OF_INERTIA}else if(-1===i.numer){if(1===i.denom&&2===s.numer&&1===s.denom&&2===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.ELECTRIC_PERMITTIVITY_TIMES_AREA}else if(0===i.numer&&1===i.denom&&0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.INV_MASS}else if(0===t.numer){if(1===t.denom)if(-1===i.numer){if(1===i.denom&&0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.INV_LENGTH}else if(0===i.numer){if(1===i.denom)if(-1===s.numer){if(1===s.denom)if(0===r.numer){if(1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.INV_TIME}else if(1===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.ELECTRIC_CURRENT}else if(0===s.numer){if(1===s.denom)if(0===r.numer){if(1===r.denom)if(0===o.numer){if(1===o.denom)if(0===n.numer){if(1===n.denom)if(0===h.numer){if(1===h.denom)return e.ONE}else if(1===h.numer&&1===h.denom)return e.LUMINOUS_INTENSITY}else if(1===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.AMOUNT_OF_SUBSTANCE}else if(1===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.THERMODYNAMIC_TEMPERATURE}else if(1===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.ELECTRIC_CHARGE}else if(1===s.numer){if(1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.TIME}else if(2===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.TIME_SQUARED}else if(1===i.numer){if(1===i.denom)if(-1===s.numer){if(1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.VELOCITY}else if(0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.LENGTH}else if(2===i.numer){if(1===i.denom){if(-2===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.VELOCITY_SQUARED;if(-1===s.numer){if(1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.RATE_OF_CHANGE_OF_AREA}else if(0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.AREA}}else if(3===i.numer&&1===i.denom&&0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.VOLUME}else if(1===t.numer){if(1===t.denom)if(0===i.numer){if(1===i.denom)if(-2===s.numer){if(1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.STIFFNESS}else if(0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.MASS}else if(1===i.numer){if(1===i.denom)if(-2===s.numer){if(1===s.denom)if(-1===r.numer){if(1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.ELECTRIC_FIELD}else if(0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.FORCE}else if(-1===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.MOMENTUM}else if(2===i.numer&&1===i.denom)if(-2===s.numer){if(1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.ENERGY_OR_TORQUE}else if(-1===s.numer){if(1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.ANGULAR_MOMENTUM}else if(0===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.MOMENT_OF_INERTIA}else if(2===t.numer&&1===t.denom&&2===i.numer&&1===i.denom&&-2===s.numer&&1===s.denom&&0===r.numer&&1===r.denom&&0===o.numer&&1===o.denom&&0===n.numer&&1===n.denom&&0===h.numer&&1===h.denom)return e.MOMENTUM_SQUARED}(t,i,s,o,n,h,u);switch(c){case e.AMOUNT_OF_SUBSTANCE:return y.AMOUNT_OF_SUBSTANCE;case e.ANGULAR_MOMENTUM:return y.ANGULAR_MOMENTUM;case e.AREA:return y.AREA;case e.ELECTRIC_CHARGE:return y.ELECTRIC_CHARGE;case e.ELECTRIC_CURRENT:return y.ELECTRIC_CURRENT;case e.ELECTRIC_FIELD:return y.ELECTRIC_FIELD;case e.ELECTRIC_PERMITTIVITY_TIMES_AREA:return y.ELECTRIC_PERMITTIVITY_TIMES_AREA;case e.ENERGY_OR_TORQUE:return y.ENERGY_OR_TORQUE;case e.FORCE:return y.FORCE;case e.LUMINOUS_INTENSITY:return y.LUMINOUS_INTENSITY;case e.INV_LENGTH:return y.INV_LENGTH;case e.INV_MASS:return y.INV_MASS;case e.INV_MOMENT_OF_INERTIA:return y.INV_MOMENT_OF_INERTIA;case e.INV_TIME:return y.INV_TIME;case e.LENGTH:return y.LENGTH;case e.MASS:return y.MASS;case e.MOMENT_OF_INERTIA:return y.MOMENT_OF_INERTIA;case e.MOMENTUM:return y.MOMENTUM;case e.MOMENTUM_SQUARED:return y.MOMENTUM_SQUARED;case e.ONE:return y.ONE;case e.RATE_OF_CHANGE_OF_AREA:return y.RATE_OF_CHANGE_OF_AREA;case e.STIFFNESS:return y.STIFFNESS;case e.THERMODYNAMIC_TEMPERATURE:return y.THERMODYNAMIC_TEMPERATURE;case e.TIME:return y.TIME;case e.TIME_SQUARED:return y.TIME_SQUARED;case e.VELOCITY:return y.VELOCITY;case e.VELOCITY_SQUARED:return y.VELOCITY_SQUARED;case e.VOLUME:return y.VOLUME;default:{for(const e of r)if(e.M.equals(t)&&e.L.equals(i)&&e.T.equals(s)&&e.Q.equals(o)&&e.temperature.equals(n)&&e.amount.equals(h)&&e.intensity.equals(u))return e;const e=new y(t,i,s,o,n,h,u,c);return r.push(e),e}}}}function M(t,i,s,e){i||function(t,i,s){const e=i?i():"satisfy some condition",r=s?" in "+s():"";throw new Error(t+" must "+e+r+".")}(t,s,e);}function f(){return "be a string"}function x(t,i,s){return M(t,"string"==typeof i,f,s),i}function E(t){x("name",t);return {get message(){return "Property `"+t+"` is readonly."}}}const b=-1*Math.random();class p{$unit;lock_=b;constructor(t){this.$unit=t;}get uom(){return this.$unit}set uom(t){if(!this.isMutable())throw new Error(E("uom").message);this.$unit=t;}isLocked(){return this.lock_!==b}isMutable(){return this.lock_===b}lock(){if(this.lock_!==b)throw new Error("already locked");return this.lock_=Math.random(),this.lock_}unlock(t){if(this.lock_===b)throw new Error("not locked");if(this.lock_===t)return this.lock_=b,this;throw new Error("unlock denied")}permlock(){return this.lock(),this}}const $=Math.abs;function v(t,i,s){let e=$(t[i][i]),r=i;for(let o=i+1;o<s;o++)$(t[o][i])>e&&(e=$(t[o][i]),r=o);return r}function k(t,i,s,e){const r=e+1;for(let e=i;e<r;e++){const r=t[s][e];t[s][e]=t[i][e],t[i][e]=r;}}function z(t,i,s){for(let e=i+1;e<s;e++){const r=-t[e][i]/t[i][i];for(let o=i;o<s+1;o++)i===o?t[e][o]=0:t[e][o]+=r*t[i][o];}}function N(t,i){const s=t.length;for(let e=0;e<s;e++){const s=t[e],r=i[e];s.push(r);}for(let i=0;i<s;i++)k(t,i,v(t,i,s),s),z(t,i,s);return function(t,i){const s=function(t,i){const s=[];for(let e=0;e<t;e++)s.push(i);return s}(i,0);for(let e=i-1;e>-1;e--){s[e]=t[e][i]/t[e][e];for(let r=e-1;r>-1;r--)t[r][i]-=t[r][e]*s[e];}return s}(t,s)}const T=[],O=["kg","m","s","C","K","mol","cd"],L$1=[[-1,1,-3,1,2,1,2,1,0,1,0,1,0,1],[-1,1,-2,1,1,1,2,1,0,1,0,1,0,1],[-1,1,-2,1,2,1,2,1,0,1,0,1,0,1],[-1,1,-1,1,2,1,2,1,0,1,0,1,0,1],[-1,1,0,1,0,1,1,1,0,1,0,1,0,1],[-1,1,3,1,-2,1,0,1,0,1,0,1,0,1],[0,1,-3,1,0,1,1,1,0,1,0,1,0,1],[0,1,-2,1,0,1,1,1,0,1,0,1,0,1],[0,1,-1,1,0,1,1,1,0,1,0,1,0,1],[0,1,2,1,-2,1,0,1,0,1,0,1,0,1],[0,1,0,1,-1,1,0,1,0,1,0,1,0,1],[0,1,0,1,-1,1,1,1,0,1,0,1,0,1],[0,1,1,1,-2,1,0,1,0,1,0,1,0,1],[0,1,1,1,-1,1,0,1,0,1,0,1,0,1],[1,1,1,1,-1,1,0,1,0,1,0,1,0,1],[1,1,-1,1,-2,1,0,1,0,1,0,1,0,1],[1,1,-1,1,-1,1,0,1,0,1,0,1,0,1],[1,1,0,1,-3,1,0,1,0,1,0,1,0,1],[1,1,0,1,-2,1,0,1,0,1,0,1,0,1],[1,1,0,1,-1,1,-1,1,0,1,0,1,0,1],[1,1,1,1,-3,1,0,1,-1,1,0,1,0,1],[1,1,1,1,-2,1,-1,1,0,1,0,1,0,1],[1,1,1,1,-2,1,0,1,0,1,0,1,0,1],[1,1,1,1,0,1,-2,1,0,1,0,1,0,1],[1,1,2,1,-2,1,0,1,-1,1,0,1,0,1],[0,1,2,1,-2,1,0,1,-1,1,0,1,0,1],[1,1,2,1,-2,1,0,1,-1,1,-1,1,0,1],[1,1,2,1,-2,1,0,1,0,1,-1,1,0,1],[1,1,2,1,-2,1,0,1,0,1,0,1,0,1],[1,1,2,1,-1,1,0,1,0,1,0,1,0,1],[1,1,2,1,-3,1,0,1,0,1,0,1,0,1],[1,1,2,1,-2,1,-1,1,0,1,0,1,0,1],[1,1,2,1,-1,1,-2,1,0,1,0,1,0,1],[1,1,2,1,0,1,-2,1,0,1,0,1,0,1],[1,1,2,1,-1,1,-1,1,0,1,0,1,0,1],[1,1,3,1,-2,1,-2,1,0,1,0,1,0,1]],I=[["F/m or C**2/N·m**2"],["S or A/V"],["F or C/V"],["C**2/N"],["C/kg"],["N·m·m/kg·kg"],["C/m**3"],["C/m**2"],["C/m"],["J/kg"],["Hz"],["A"],["m/s**2"],["m/s"],["kg·m/s"],["Pa or N/m**2 or J/m**3"],["Pa·s"],["W/m**2"],["N/m"],["T or Wb/m**2"],["W/(m·K)"],["V/m or N/C"],["N"],["H/m"],["J/K"],["J/(kg·K)"],["J/(mol·K)"],["J/mol"],["J or N·m"],["J·s"],["W or J/s"],["V or W/A"],["Ω or V/A"],["H or Wb/A"],["Wb"],["N·m**2/C**2"]],R=function(t,i,s,e,r){const o=s.M,n=s.L,h=s.T,u=s.Q,c=s.temperature,a=s.amount,m=s.intensity;for(let i=0,s=L$1.length;i<s;i++){const s=L$1[i];if(o.numer===s[0]&&o.denom===s[1]&&n.numer===s[2]&&n.denom===s[3]&&h.numer===s[4]&&h.denom===s[5]&&u.numer===s[6]&&u.denom===s[7]&&c.numer===s[8]&&c.denom===s[9]&&a.numer===s[10]&&a.denom===s[11]&&m.numer===s[12]&&m.denom===s[13])return r?1!==t?t+" * "+I[i][0]:I[i][0]:t+" * "+I[i][0]}return function(t,i,s,e,r){const o=function(t,i){return 0===t.numer?null:1===t.denom?1===t.numer?i:`${i}**${t.numer}`:`${i}**${t}`},n=(1===t||s.isOne())&&r?"":" ";return ""+(1===t&&r?"":i)+n+[o(s.M,e[0]),o(s.L,e[1]),o(s.T,e[2]),o(s.Q,e[3]),o(s.temperature,e[4]),o(s.amount,e[5]),o(s.intensity,e[6])].filter((function(t){return "string"==typeof t})).join(" ")}(t,i,s,e,r)};function w(t,i){return U.valueOf(t.multiplier+i.multiplier,t.dimensions.compatible(i.dimensions),t.labels)}function S(t,i){return U.valueOf(t.multiplier-i.multiplier,t.dimensions.compatible(i.dimensions),t.labels)}function C(t,i){return U.valueOf(t.multiplier*i.multiplier,t.dimensions.mul(i.dimensions),t.labels)}function A(t,i){return U.valueOf(t*i.multiplier,i.dimensions,i.labels)}function g(t,i){return U.valueOf(t.multiplier/i.multiplier,t.dimensions.div(i.dimensions),t.labels)}class U{multiplier;dimensions;labels;static isOne(t){if(void 0===t)return !0;if(t instanceof U)return t.isOne();throw new Error("isOne argument must be a Unit or undefined.")}static assertDimensionless(t){if(!U.isOne(t))throw new Error(`uom ${t} must be dimensionless.`)}static compatible(t,i){if(t){if(i)return t.compatible(i);if(t.isOne())return;throw new Error(t+" is incompatible with 1")}if(i){if(i.isOne())return;throw new Error("1 is incompatible with "+i)}}static isCompatible(t,i){return t?i?t.isCompatible(i):!!t.isOne():!i||!!i.isOne()}static mul(t,i){return t?i?t.mul(i):U.isOne(i)?t:void 0:U.isOne(t)?i:void 0}static div(t,i){return t?i?t.div(i):t:i?i.inv():U.ONE}static inv(t){return t instanceof U?t.isOne()?U.ONE:t.inv():U.ONE}static mustBeUnit(t,i){if(i instanceof U)return i;if(void 0===i)return U.ONE;throw new Error(`${t} must be a Unit or undefined (meaning 1).`)}static pow(t,i){return t instanceof U?t.isOne()||i.isZero()?void 0:t.pow(i):void 0}static sqrt(t){return t instanceof U?t.isOne()?void 0:t.sqrt():void 0}static valueOf(t,i,s){if(1===t)switch(i.summary){case e.AMOUNT_OF_SUBSTANCE:return U.MOLE;case e.ANGULAR_MOMENTUM:return U.JOULE_SECOND;case e.AREA:return U.METER_SQUARED;case e.ELECTRIC_CHARGE:return U.COULOMB;case e.ELECTRIC_CURRENT:return U.AMPERE;case e.ELECTRIC_FIELD:return U.ELECTRIC_FIELD;case e.ELECTRIC_PERMITTIVITY_TIMES_AREA:return U.COULOMB_SQUARED_PER_NEWTON;case e.ENERGY_OR_TORQUE:return U.JOULE;case e.FORCE:return U.NEWTON;case e.FRICTION_COEFFICIENT:return U.FRICTION_COEFFICIENT;case e.INV_LENGTH:return U.INV_METER;case e.INV_MASS:return U.INV_KILOGRAM;case e.INV_MOMENT_OF_INERTIA:return U.INV_KILOGRAM_METER_SQUARED;case e.INV_TIME:return U.INV_SECOND;case e.LENGTH:return U.METER;case e.LUMINOUS_INTENSITY:return U.CANDELA;case e.MASS:return U.KILOGRAM;case e.MOMENT_OF_INERTIA:return U.KILOGRAM_METER_SQUARED;case e.MOMENTUM:return U.KILOGRAM_METER_PER_SECOND;case e.MOMENTUM_SQUARED:return U.KILOGRAM_SQUARED_METER_SQUARED_PER_SECOND_SQUARED;case e.ONE:return U.ONE;case e.RATE_OF_CHANGE_OF_AREA:return U.METER_SQUARED_PER_SECOND;case e.STIFFNESS:return U.STIFFNESS;case e.THERMODYNAMIC_TEMPERATURE:return U.KELVIN;case e.TIME:return U.SECOND;case e.TIME_SQUARED:return U.SECOND_SQUARED;case e.VELOCITY:return U.METER_PER_SECOND;case e.VELOCITY_SQUARED:return U.METER_SQUARED_PER_SECOND_SQUARED;case e.VOLUME:return U.METER_CUBED}for(const s of T)if(s.multiplier===t&&s.dimensions.equals(i))return s;const r=new U(t,i,s);return T.push(r),r}static ONE=new U(1,y.ONE,O);static KILOGRAM=new U(1,y.MASS,O);static METER=new U(1,y.LENGTH,O);static SECOND=new U(1,y.TIME,O);static COULOMB=new U(1,y.ELECTRIC_CHARGE,O);static AMPERE=new U(1,y.ELECTRIC_CURRENT,O);static KELVIN=new U(1,y.THERMODYNAMIC_TEMPERATURE,O);static MOLE=new U(1,y.AMOUNT_OF_SUBSTANCE,O);static CANDELA=new U(1,y.LUMINOUS_INTENSITY,O);static COULOMB_SQUARED_PER_NEWTON=new U(1,y.ELECTRIC_PERMITTIVITY_TIMES_AREA,O);static ELECTRIC_FIELD=new U(1,y.ELECTRIC_FIELD,O);static NEWTON=new U(1,y.FORCE,O);static JOULE=new U(1,y.ENERGY_OR_TORQUE,O);static JOULE_SECOND=new U(1,y.ANGULAR_MOMENTUM,O);static METER_SQUARED=new U(1,y.AREA,O);static METER_CUBED=new U(1,y.VOLUME,O);static SECOND_SQUARED=new U(1,y.TIME_SQUARED,O);static INV_KILOGRAM=new U(1,y.INV_MASS,O);static INV_METER=new U(1,y.INV_LENGTH,O);static INV_SECOND=new U(1,y.INV_TIME,O);static KILOGRAM_METER_SQUARED=new U(1,y.MOMENT_OF_INERTIA,O);static KILOGRAM_METER_PER_SECOND=new U(1,y.MOMENTUM,O);static KILOGRAM_SQUARED_METER_SQUARED_PER_SECOND_SQUARED=new U(1,y.MOMENTUM_SQUARED,O);static INV_KILOGRAM_METER_SQUARED=new U(1,y.INV_MOMENT_OF_INERTIA,O);static STIFFNESS=new U(1,y.STIFFNESS,O);static FRICTION_COEFFICIENT=new U(1,y.FRICTION_COEFFICIENT,O);static METER_PER_SECOND=new U(1,y.VELOCITY,O);static METER_SQUARED_PER_SECOND=new U(1,y.RATE_OF_CHANGE_OF_AREA,O);static METER_SQUARED_PER_SECOND_SQUARED=new U(1,y.VELOCITY_SQUARED,O);constructor(t,i,s){if(this.multiplier=t,this.dimensions=i,this.labels=s,7!==s.length)throw new Error("Expecting 7 elements in the labels array.");this.multiplier=t,this.dimensions=i,this.labels=s;}compatible(t){if(t instanceof U){try{this.dimensions.compatible(t.dimensions);}catch(i){const s=i instanceof Error?i.message:`${i}`;throw new Error(`${this} is not compatible with ${t}. Cause: ${s}`)}return this}throw new Error("Illegal Argument for Unit.compatible: "+t)}div(t){return g(this,t)}isCompatible(t){if(t instanceof U)return this.dimensions.equals(t.dimensions);throw new Error("Illegal Argument for Unit.compatible: "+t)}isOne(){return this.dimensions.isOne()&&1===this.multiplier}inv(){return U.valueOf(1/this.multiplier,this.dimensions.inv(),this.labels)}mul(t){return C(this,t)}neg(){return U.valueOf(-this.multiplier,this.dimensions,this.labels)}pow(t){return U.valueOf(Math.pow(this.multiplier,t.numer/t.denom),this.dimensions.pow(t),this.labels)}sqrt(){return U.valueOf(Math.sqrt(this.multiplier),this.dimensions.sqrt(),this.labels)}toExponential(t,i){return R(this.multiplier,this.multiplier.toExponential(t),this.dimensions,this.labels,i)}toFixed(t,i){return R(this.multiplier,this.multiplier.toFixed(t),this.dimensions,this.labels,i)}toPrecision(t,i){return R(this.multiplier,this.multiplier.toPrecision(t),this.dimensions,this.labels,i)}toString(t,i){return R(this.multiplier,this.multiplier.toString(t),this.dimensions,this.labels,i)}__add__(t){return t instanceof U?w(this,t):void 0}__radd__(t){return t instanceof U?w(t,this):void 0}__sub__(t){return t instanceof U?S(this,t):void 0}__rsub__(t){return t instanceof U?S(t,this):void 0}__mul__(t){return t instanceof U?C(this,t):"number"==typeof t?A(t,this):void 0}__rmul__(t){return t instanceof U?C(t,this):"number"==typeof t?A(t,this):void 0}__div__(t){return t instanceof U?g(this,t):"number"==typeof t?U.valueOf(this.multiplier/t,this.dimensions,this.labels):void 0}__rdiv__(t){return t instanceof U?g(t,this):"number"==typeof t?U.valueOf(t/this.multiplier,this.dimensions.inv(),this.labels):void 0}__pos__(){return this}__neg__(){return this.neg()}}function F(t,i,s,e){if(0!==t){t>=0?e.length>0&&e.push("+"):e.push("-");const r=Math.abs(t);1===r?e.push(s):(e.push(i(r)),"1"!==s&&(e.push("*"),e.push(s)));}}function V(t,i,s,e){const r=[];for(let e=0,o=t.length;e<o;e++){F(t[e],i,s[e],r);}return U.isOne(e)?r.length>0?r.join(""):"0":r.length>0?`${r.join("")} ${e.toString(10,!0)}`:"0"}const B=function(t){const i=[0,0];return i[Q]=t,i};function q(t){return new H([t.a,t.x],t.uom)}function D(t){return t.lock(),t}const G=function(t){const i=[0,0];return i[Q]=t.a,i[P]=t.x,i};const Q=0,P=1,Y=["1","e1"];Y[Q]="1",Y[P]="e1";const Z=["1","e_{1}"];Z[Q]="1",Z[P]="e_{1}";class H extends p{static scalar(t,i){return new H([t,0],i)}static vector(t,i){return new H([0,t],i)}static zero=D(new H([0,0],void 0));static one=D(new H(B(1),void 0));static e1=D(new H(function(t){const i=[0,0];return i[P]=t,i}(1),void 0));static meter=D(new H(B(1),U.METER));static kilogram=D(new H(B(1),U.KILOGRAM));static second=D(new H(B(1),U.SECOND));static ampere=D(new H(B(1),U.AMPERE));static kelvin=D(new H(B(1),U.KELVIN));static mole=D(new H(B(1),U.MOLE));static candela=D(new H(B(1),U.CANDELA));static coulomb=D(new H(B(1),U.COULOMB));static newton=D(new H(B(1),U.NEWTON));static joule=D(new H(B(1),U.JOULE));coords;constructor(t=[0,0],i){if(super(i),2!==t.length)throw new Error("coords.length must be 2.");this.coords=t;}get grades(){const t=this.coords;let i=0;return 0!==t[Q]&&(i+=1),0!==t[P]&&(i+=2),i}add(t,i=1){return this.isLocked()?D(this.clone().add(t,i)):this.isZero()?(this.a=t.a*i,this.x=t.x*i,this.uom=t.uom,this):(t.isZero()||(this.a+=t.a*i,this.x+=t.x*i,this.uom=U.compatible(this.uom,t.uom)),this)}addVector(t,i=1){if(this.isLocked())return D(this.clone().addVector(t,i));if(this.isZero())this.uom=t.uom;else {if(0===t.x)return this;this.uom=U.compatible(this.uom,t.uom);}return this.x+=t.x*i,this}addScalar(t,i,s=1){return this.isLocked()?D(this.clone().addScalar(t,i,s)):this.isZero()?(this.a=t*s,this.uom=i,this):(0===t||0===s||(this.a+=t*s,this.uom=U.compatible(this.uom,i)),this)}clone(){return q(this)}conj(){return this.isLocked()?D(this.clone().conj()):(this.x=-this.x,this)}copy(t){return this.isMutable()?(this.a=t.a,this.x=t.x,this.uom=t.uom,this):D(q(this).copy(t))}copyVector(t){return this.isMutable()?(this.a=0,this.x=t.x,this.uom=t.uom,this):this.clone().copyVector(t).permlock()}dual(){if(this.isLocked())return this.clone().dual().permlock();{const t=this.b,i=this.a;return this.a=t,this.b=i,this}}equals(t){return t===this||t instanceof H&&(function(t,i){for(let s=0;s<2;s++)if(t[s]!==i[s])return !1;return !0}(this.coords,t.coords)&&U.isCompatible(this.uom,t.uom))}lco(t){return this.isLocked()?D(this.clone().lco(t)):this.lco2(this,t)}lco2(t,i){const s=t.a,e=t.x,r=i.a,o=i.x;return this.a=s*r+e*o,this.x=s*o,this.uom=U.mul(this.uom,i.uom),this}div(t){return this.isLocked()?D(this.clone().div(t)):0===t.x?this.divByScalar(t.a,t.uom):this.mul(q(t).inv())}divByVector(t){throw new Error("Method not implemented.")}ext(t){if(this.isLocked())return D(this.clone().ext(t));{const i=this.a,s=this.x,e=t.a,r=t.x;return this.a=i*e,this.x=i*r+s*e,this.uom=U.mul(this.uom,t.uom),this}}grade(t){if(this.isLocked())return D(this.clone().grade(t));switch(t){case 0:this.x=0;break;case 1:this.a=0;break;default:this.a=0,this.x=0;}return this}isBivector(){return 0===this.coords[Q]&&0===this.coords[P]}isOne(){return 1===this.coords[Q]&&0===this.coords[P]&&U.isOne(this.uom)}isScalar(){return 0===this.coords[P]}isSpinor(){return !!U.isOne(this.uom)&&0===this.coords[P]}isVector(){return 0===this.coords[Q]}magnitude(){return this.isMutable()?(this.a=this.magnitudeNoUnits(),this.x=0,this):D(this.clone().magnitude())}magnitudeNoUnits(){return Math.sqrt(this.quaditudeNoUnits())}mul(t){return this.isLocked()?D(this.clone().mul(t)):this.mul2(this,t)}mul2(t,i){const s=t.a,e=t.x,r=i.a,o=i.x;return this.a=s*r+e*o,this.x=s*o+e*r,this.uom=U.mul(this.uom,i.uom),this}mulByNumber(t){return this.isLocked()?D(this.clone().mulByNumber(t)):(this.a*=t,this.x*=t,this)}mulByVector(t){if(this.isLocked())return D(this.clone().mulByVector(t));{const i=this.a,s=this.x,e=t.x;return this.a=s*e,this.x=i*e,this.uom=U.mul(this.uom,t.uom),this}}rco(t){return this.isLocked()?D(this.clone().rco(t)):this.rco2(this,t)}rco2(t,i){const s=t.a,e=t.x,r=i.a,o=i.x;return this.a=s*r+e*o,this.x=e*r,this.uom=U.mul(this.uom,i.uom),this}rev(){return this.isMutable()?(this.a=+this.a,this.x=+this.x,this):D(this.clone().rev())}quaditude(){return this.isMutable()?(this.a=this.quaditudeNoUnits(),this.x=0,this.uom=U.mul(this.uom,this.uom),this):D(this.clone().quaditude())}quaditudeNoUnits(){const t=this.a,i=this.x;return t*t+i*i}subScalar(t,i,s=1){return this.isLocked()?D(this.clone().subScalar(t,i,s)):this.isZero()?(this.a=-t*s,this.uom=i,this):(0===t||0===s||(this.a-=t*s,this.uom=U.compatible(this.uom,i)),this)}scp(t){return this.isLocked()?D(this.clone().scp(t)):this.scp2(this,t)}scp2(t,i){const s=t.a,e=t.x,r=s*i.a+e*i.x;return this.a=r,this.x=0,this.uom=U.mul(t.uom,i.uom),this}sqrt(){return this.isLocked()?this.clone().sqrt().permlock():(this.a=Math.sqrt(this.a),this.x=0,this.uom=U.sqrt(this.uom),this)}squaredNorm(){return this.isMutable()?(this.a=this.quaditudeNoUnits(),this.x=0,this.uom=U.mul(this.uom,this.uom),this):D(this.clone().quaditude())}subVector(t,i=1){if(this.isLocked())return D(this.clone().subVector(t,i));if(this.isZero())this.uom=t.uom;else {if(0===t.x)return this;this.uom=U.compatible(this.uom,t.uom);}return this.x-=t.x*i,this}divByScalar(t,i){return this.isLocked()?D(this.clone().divByScalar(t,i)):(this.uom=U.div(this.uom,i),this.a/=t,this.x/=t,this)}scale(t){return this.isMutable()?(this.a=this.a*t,this.x=this.x*t,this):D(q(this).scale(t))}reflect(t){if(this.isLocked())return D(this.clone().reflect(t));{const i=t.x,s=t.uom,e=this.a,r=this.x,o=this.uom,n=i*i,h=n,u=n;return this.a=-u*e,this.x=-h*r,this.uom=U.mul(s,U.mul(o,s)),this}}rotate(t){if(this.isLocked())return D(this.clone().rotate(t));{U.assertDimensionless(t.uom);const i=this.a,s=this.x,e=t.a,r=e*e,o=r,n=r;return this.a=n*i,this.x=o*s,this}}sub(t,i=1){if(this.isLocked())return D(this.clone().sub(t,i));if(this.isZero())this.a=-t.a*i,this.x=-t.x*i,this.uom=t.uom;else {if(t.isZero())return this;this.a-=t.a*i,this.x-=t.x*i,this.uom=U.compatible(this.uom,t.uom);}return this}toExponential(t){return V(G(this),(function(i){return i.toExponential(t)}),Y,this.uom)}toFixed(t){return V(G(this),(function(i){return i.toFixed(t)}),Y,this.uom)}toLaTeX(t){return V(G(this),(function(i){return i.toString(t)}),Z,this.uom)}toPrecision(t){return V(G(this),(function(i){return i.toPrecision(t)}),Y,this.uom)}toString(t){return V(G(this),(function(i){return i.toString(t)}),Y,this.uom)}zero(){return this.isMutable()?(this.a=0,this.x=0,this.uom=U.ONE,this):D(q(this).zero())}__div__(t){return t instanceof H?D(this.clone().div(t)):"number"==typeof t?D(this.clone().divByNumber(t)):t instanceof U?D(this.clone().divByScalar(1,t)):void 0}divByNumber(t){return this.isLocked()?D(this.clone().divByNumber(t)):(this.a/=t,this.x/=t,this)}__rdiv__(t){return t instanceof H?D(q(t).div(this)):"number"==typeof t?D(H.scalar(t,void 0).div(this)):void 0}__vbar__(t){return t instanceof H?D(q(this).scp(t)):"number"==typeof t?D(q(this).scp(H.scalar(t))):void 0}__rvbar__(t){return t instanceof H?D(q(t).scp(this)):"number"==typeof t?D(H.scalar(t).scp(this)):void 0}__wedge__(t){return t instanceof H?D(q(this).ext(t)):"number"==typeof t?D(q(this).mulByNumber(t)):void 0}__rwedge__(t){return t instanceof H?D(q(t).ext(this)):"number"==typeof t?D(q(this).mulByNumber(t)):void 0}__lshift__(t){return t instanceof H?D(q(this).lco(t)):"number"==typeof t?D(q(this).lco(H.scalar(t))):void 0}__rlshift__(t){return t instanceof H?D(q(t).lco(this)):"number"==typeof t?D(H.scalar(t).lco(this)):void 0}__rshift__(t){return t instanceof H?D(q(this).rco(t)):"number"==typeof t?D(q(this).rco(H.scalar(t))):void 0}__rrshift__(t){return t instanceof H?D(q(t).rco(this)):"number"==typeof t?D(H.scalar(t).rco(this)):void 0}__bang__(){return D(q(this).inv())}inv(){if(this.isLocked())return D(this.clone().inv());{const t=this.a,i=this.x,s=N([[t,i],[i,t]],[1,0]);return this.a=s[0],this.x=s[1],this.uom=U.inv(this.uom),this}}__eq__(t){return t instanceof H?this.equals(t):"number"==typeof t?this.equals(H.scalar(t)):t instanceof U&&this.equals(H.scalar(1,t))}__ne__(t){return t instanceof H?!this.equals(t):"number"==typeof t?!this.equals(H.scalar(t)):!(t instanceof U)||!this.equals(H.scalar(1,t))}__tilde__(){return D(q(this).rev())}__add__(t){return t instanceof H?D(this.clone().add(t)):"number"==typeof t?D(this.clone().addScalar(t,void 0,1)):t instanceof U?D(this.clone().addScalar(1,t,1)):void 0}__radd__(t){return t instanceof H?D(q(t).add(this)):"number"==typeof t?D(H.scalar(t).add(this)):t instanceof U?D(H.scalar(1,t).add(this)):void 0}__sub__(t){return t instanceof H?D(this.clone().sub(t)):"number"==typeof t?D(this.clone().subScalar(t,void 0,1)):t instanceof U?D(this.clone().subScalar(1,t,1)):void 0}__rsub__(t){return t instanceof H?D(q(t).sub(this)):"number"==typeof t?D(H.scalar(t).sub(this)):void 0}__pos__(){return D(q(this))}__neg__(){return D(q(this).neg())}neg(){return this.isLocked()?D(this.clone().neg()):(this.a=-this.a,this.x=-this.x,this)}isZero(){return 0===this.coords[Q]&&0===this.coords[P]}__mul__(t){return t instanceof H?D(this.clone().mul(t)):"number"==typeof t?D(this.clone().mulByNumber(t)):t instanceof U?D(this.clone().mulByScalar(1,t)):void 0}__rmul__(t){return t instanceof H?D(q(t).mul(this)):"number"==typeof t?D(q(this).mulByNumber(t)):void 0}mulByScalar(t,i){return this.isLocked()?D(this.clone().mulByScalar(t,i)):(this.a*=t,this.x*=t,this.uom=U.mul(this.uom,i),this)}get a(){return this.coords[Q]}set a(t){if(!this.isMutable())throw new Error(E("a").message);this.coords[Q]=t;}get x(){return this.coords[P]}set x(t){if(!this.isMutable())throw new Error(E("x").message);this.coords[P]=t;}get b(){return this.coords[P]}set b(t){if(!this.isMutable())throw new Error(E("b").message);this.coords[P]=t;}}function K(t){return "number"==typeof t}function j(){return "be a `number`"}function J(t,i,s){return M(t,K(i),j,s),i}function W(t){x("name",t);return {get message(){return `'${t}' method is not yet implemented.`}}}function X(t,i){let s=0;const e=t.length;for(let i=0;i<e;i++)s=Math.max(s,Math.abs(t[i]));const r=s*Math.pow(10,-i);for(let i=0;i<e;i++)Math.abs(t[i])<r&&(t[i]=0);}function tt(t){return 0===t.x&&0===t.y}function it(t){return tt(t)&&function(t){return 0===t.xy}(t)&&0===t.a&&0===t.b}function st(t){const i=t.x,s=t.y;return i*i+s*s}const et=Math.sqrt;const rt=["1","e1","e2","e12"];rt[0]="1",rt[1]="e1",rt[2]="e2",rt[3]="e12";const ot=["1","e_{1}","e_{2}","I"];ot[0]="1",ot[1]="e_{1}",ot[2]="e_{2}",ot[3]="I";const nt=function(t){const i=[0,0,0,0];return i[0]=t,i},ht=function(t,i){const s=[0,0,0,0];return s[1]=t,s[2]=i,s},ut=function(t,i){const s=[0,0,0,0];return s[0]=t,s[3]=i,s},ct=function(t){const i=[0,0,0,0];return i[0]=t.a,i[1]=t.x,i[2]=t.y,i[3]=t.b,i};function at(t){return 0===t.x&&0===t.y&&0===t.b}function mt(t){return t.lock(),t}class lt extends p{static scalar(t,i){return new lt(nt(t),i)}static bivector(t,i){return lt.spinor(0,t,i)}static spinor(t,i,s){return new lt(ut(t,i),s)}static vector(t,i,s){const e=()=>"Geometric2.vector(x: number, y: number, uom?: Unit): Geometric2";return J("x",t,e),J("y",i,e),new lt(ht(t,i),s)}static copy(t){return new lt(ct(t),t.uom)}static fromBivector(t){return new lt(function(t){const i=[0,0,0,0];return i[3]=t,i}(t.xy),t.uom)}static fromScalar(t){return new lt(nt(t.a),t.uom)}static fromSpinor(t){return new lt(ut(t.a,t.xy),t.uom)}static fromVector(t){return new lt(ht(t.x,t.y),t.uom)}static rotorFromDirections(t,i){return new lt([0,0,0,0]).rotorFromDirections(t,i)}static rotorFromVectorToVector(t,i){return new lt([0,0,0,0]).rotorFromVectorToVector(t,i)}static zero=mt(new lt([0,0,0,0],void 0));static one=mt(new lt(nt(1),void 0));static e1=mt(new lt(ht(1,0),void 0));static e2=mt(new lt(ht(0,1),void 0));static I=mt(new lt(function(t){const i=[0,0,0,0];return i[3]=t,i}(1),void 0));static meter=mt(new lt(nt(1),U.METER));static kilogram=mt(new lt(nt(1),U.KILOGRAM));static second=mt(new lt(nt(1),U.SECOND));static ampere=mt(new lt(nt(1),U.AMPERE));static kelvin=mt(new lt(nt(1),U.KELVIN));static mole=mt(new lt(nt(1),U.MOLE));static candela=mt(new lt(nt(1),U.CANDELA));static coulomb=mt(new lt(nt(1),U.COULOMB));static newton=mt(new lt(nt(1),U.NEWTON));static joule=mt(new lt(nt(1),U.JOULE));coords_;constructor(t=[0,0,0,0],i){if(super(i),4!==t.length)throw new Error("coords.length must be 4");this.coords_=t;}scale(t){return this.mulByNumber(t)}__div__(t){return t instanceof lt?mt(this.clone().div(t)):"number"==typeof t?mt(this.clone().divByNumber(t)):t instanceof U?mt(this.clone().divByScalar(1,t)):void 0}__rdiv__(t){return t instanceof lt?mt(lt.copy(t).div(this)):"number"==typeof t?mt(lt.scalar(t,void 0).div(this)):void 0}__vbar__(t){return t instanceof lt?mt(lt.copy(this).scp(t)):"number"==typeof t?mt(lt.copy(this).scp(lt.scalar(t))):void 0}__rvbar__(t){return t instanceof lt?mt(lt.copy(t).scp(this)):"number"==typeof t?mt(lt.scalar(t).scp(this)):void 0}__wedge__(t){return t instanceof lt?mt(lt.copy(this).ext(t)):"number"==typeof t?mt(lt.copy(this).mulByNumber(t)):void 0}__rwedge__(t){return t instanceof lt?mt(lt.copy(t).ext(this)):"number"==typeof t?mt(lt.copy(this).mulByNumber(t)):void 0}__lshift__(t){return t instanceof lt?mt(lt.copy(this).lco(t)):"number"==typeof t?mt(lt.copy(this).lco(lt.scalar(t))):void 0}__rlshift__(t){return t instanceof lt?mt(lt.copy(t).lco(this)):"number"==typeof t?mt(lt.scalar(t).lco(this)):void 0}__rshift__(t){return t instanceof lt?mt(lt.copy(this).rco(t)):"number"==typeof t?mt(lt.copy(this).rco(lt.scalar(t))):void 0}__rrshift__(t){return t instanceof lt?mt(lt.copy(t).rco(this)):"number"==typeof t?mt(lt.scalar(t).rco(this)):void 0}__bang__(){return mt(lt.copy(this).inv())}__eq__(t){return t instanceof lt?this.equals(t):"number"==typeof t?this.equals(lt.scalar(t)):t instanceof U&&this.equals(lt.scalar(1,t))}__ne__(t){return t instanceof lt?!this.equals(t):"number"==typeof t?!this.equals(lt.scalar(t)):!(t instanceof U)||!this.equals(lt.scalar(1,t))}__tilde__(){return mt(lt.copy(this).rev())}__add__(t){return t instanceof lt?mt(this.clone().add(t)):"number"==typeof t?mt(this.clone().addScalar(t,void 0,1)):t instanceof U?mt(this.clone().addScalar(1,t,1)):void 0}__radd__(t){return t instanceof lt?mt(lt.copy(t).add(this)):"number"==typeof t?mt(lt.scalar(t).add(this)):t instanceof U?mt(lt.scalar(1,t).add(this)):void 0}__sub__(t){return t instanceof lt?mt(this.clone().sub(t)):"number"==typeof t?mt(this.clone().subScalar(t,void 0,1)):t instanceof U?mt(this.clone().subScalar(1,t,1)):void 0}__rsub__(t){return t instanceof lt?mt(lt.copy(t).sub(this)):"number"==typeof t?mt(lt.scalar(t).sub(this)):void 0}__pos__(){return mt(lt.copy(this))}__neg__(){return mt(lt.copy(this).neg())}__mul__(t){return t instanceof lt?mt(this.clone().mul(t)):"number"==typeof t?mt(this.clone().mulByNumber(t)):t instanceof U?mt(this.clone().mulByScalar(1,t)):void 0}__rmul__(t){return t instanceof lt?mt(lt.copy(t).mul(this)):"number"==typeof t?mt(lt.copy(this).mulByNumber(t)):void 0}add2(t,i){return it(t)?this.uom=i.uom:it(i)?this.uom=t.uom:this.uom=U.compatible(t.uom,i.uom),this.a=t.a+i.a,this.x=t.x+i.x,this.y=t.y+i.y,this.b=t.b+i.b,this}addPseudo(t,i){if(this.isLocked())return mt(this.clone().addPseudo(t,i));if(this.isZero())this.uom=i;else {if(0===t)return this;this.uom=U.compatible(this.uom,i);}return this.b+=t,this}addScalar(t,i,s=1){return this.isLocked()?mt(this.clone().addScalar(t,i,s)):this.isZero()?(this.a=t*s,this.uom=i,this):(0===t||0===s||(this.a+=t*s,this.uom=U.compatible(this.uom,i)),this)}approx(t){return this.isLocked()?mt(this.clone().approx(t)):(X(this.coords_,t),this)}conj(){return this.isLocked()?mt(this.clone().conj()):(this.x=-this.x,this.y=-this.y,this.b=-this.b,this)}copySpinor(t){const i=t.a,s=t.xy;return this.setCoordinate(0,i,"a"),this.setCoordinate(1,0,"x"),this.setCoordinate(2,0,"y"),this.setCoordinate(3,s,"b"),this.uom=t.uom,this}div(t){return this.isLocked()?mt(this.clone().div(t)):at(t)?this.divByScalar(t.a,t.uom):this.mul(lt.copy(t).inv())}div2(t,i){throw new Error(W("div2").message)}divByNumber(t){return this.isLocked()?mt(this.clone().divByNumber(t)):(this.a/=t,this.x/=t,this.y/=t,this.b/=t,this)}divByVector(t){if(this.isLocked())return mt(this.clone().divByVector(t));{const i=t.x,e=t.y;return this.mulByVector(t).divByScalar(i*i+e*e,U.pow(t.uom,s.valueOf(2,1)))}}dual(){if(this.isLocked())return this.clone().dual().permlock();{const t=this.b,i=-this.x,s=this.y,e=-this.a;return this.a=t,this.x=s,this.y=i,this.b=e,this}}equals(t){return t===this||t instanceof lt&&(function(t,i){for(let s=0;s<4;s++)if(t[s]!==i[s])return !1;return !0}(this.coords_,t.coords_)&&U.isCompatible(this.uom,t.uom))}ext2(t,i){const s=t.a,e=t.x,r=t.y,o=t.b,n=i.a,h=i.x,u=i.y,c=i.b;return this.a=s*n,this.x=s*h+e*n,this.y=s*u+r*n,this.b=s*c+e*u-r*h+o*n,this.uom=U.mul(this.uom,i.uom),this}grade(t){if(this.isLocked())return mt(this.clone().grade(t));switch(t){case 0:this.x=0,this.y=0,this.b=0;break;case 1:this.a=0,this.b=0;break;case 2:this.a=0,this.x=0,this.y=0;break;default:this.a=0,this.x=0,this.y=0,this.b=0;}return this}I(){return this.a=0,this.x=0,this.y=0,this.b=1,this.uom=void 0,this}lco(t){return this.isLocked()?mt(this.clone().lco(t)):this.lco2(this,t)}lco2(t,i){const s=t.a,e=t.x,r=t.y,o=t.b,n=i.a,h=i.x,u=i.y,c=i.b;return this.a=s*n+e*h+r*u-o*c,this.x=s*h-r*c,this.y=s*u+e*c,this.b=s*c,this.uom=U.mul(this.uom,i.uom),this}one(){return this.a=1,this.x=0,this.y=0,this.b=0,this.uom=void 0,this}rco(t){return this.isLocked()?mt(this.clone().rco(t)):this.rco2(this,t)}rco2(t,i){const s=t.a,e=t.x,r=t.y,o=t.b,n=i.a,h=i.x,u=i.y,c=i.b;return this.a=s*n+e*h+r*u-o*c,this.x=e*n+o*u,this.y=r*n-o*h,this.b=o*n,this.uom=U.mul(this.uom,i.uom),this}reflect(t){if(this.isLocked())return mt(this.clone().reflect(t));{const i=t.x,s=t.y,e=t.uom,r=this.a,o=this.x,n=this.y,h=this.b,u=this.uom,c=i*i,a=s*s,m=c-a,l=-2*i*s,d=c+a;return this.a=-d*r,this.x=l*n-m*o,this.y=l*o+m*n,this.b=d*h,this.uom=U.mul(e,U.mul(u,e)),this}}rotorFromDirections(t,i){return this.isLocked()?mt(this.clone().rotorFromDirections(t,i)):(function(t,i,s){const e=st(t),r=et(e),o=st(i),n=et(o)*r,h=function(t,i){return t.x*i.x+t.y*i.y}(i,t),u=et(2*(o*e+n*h));0!==u&&(s.versor(i,t),s.addScalar(n,void 0,1),s.divByScalar(u));}(t,i,this),this)}rotorFromFrameToFrame(t,i){throw new Error(W("rotorFromFrameToFrame").message)}rotorFromGeneratorAngle(t,i){throw new Error(W("rotorFromGeneratorAngle").message)}rotorFromVectorToVector(t,i){if(this.isLocked())return mt(this.clone().rotorFromVectorToVector(t,i));{const s=t.x,e=t.y,r=i.x,o=i.y,n=Math.sqrt(r*r+o*o),h=Math.sqrt(s*s+e*e),u=n*h,c=r*s+o*e,a=r*e-o*s,m=Math.sqrt(2*u*(u+c)),l=Math.sqrt(n)/(Math.sqrt(h)*m);return this.a=l*(u+c),this.x=0,this.y=0,this.b=l*a,this.uom=U.sqrt(U.div(i.uom,t.uom)),this}}sqrt(){return this.isLocked()?this.clone().sqrt().permlock():(this.a=Math.sqrt(this.a),this.x=0,this.y=0,this.b=0,this.uom=U.sqrt(this.uom),this)}squaredNorm(){return this.quaditude()}sub2(t,i){return it(t)?(this.a=-i.a,this.x=-i.x,this.y=-i.y,this.b=-i.b,this.uom=i.uom):it(i)?(this.a=t.a,this.x=t.x,this.y=t.y,this.b=t.b,this.uom=t.uom):(this.a=t.a-i.a,this.x=t.x-i.x,this.y=t.y-i.y,this.b=t.b-i.b,this.uom=U.compatible(t.uom,i.uom)),this}versor(t,i){return this.a=t.x*i.x+t.y*i.y,this.x=0,this.y=0,this.b=t.x*i.y-t.y*i.x,this.uom=U.mul(t.uom,i.uom),this}setCoordinate(t,i,s){if(!this.isMutable())throw new Error(E(s).message);{const s=this.coords_;i!==s[t]&&(s[t]=i);}}get a(){return this.coords_[0]}set a(t){this.setCoordinate(0,t,"a");}get b(){return this.coords_[3]}set b(t){this.setCoordinate(3,t,"b");}get xy(){return this.coords_[3]}set xy(t){this.setCoordinate(3,t,"xy");}get grades(){const t=this.coords_,i=t[0],s=t[1],e=t[2];let r=0;return 0!==i&&(r+=1),0===s&&0===e||(r+=2),0!==t[3]&&(r+=4),r}get x(){return this.coords_[1]}set x(t){this.setCoordinate(1,t,"x");}get y(){return this.coords_[2]}set y(t){this.setCoordinate(2,t,"y");}add(t,i=1){return this.isLocked()?mt(this.clone().add(t,i)):this.isZero()?(this.a=t.a*i,this.x=t.x*i,this.y=t.y*i,this.b=t.b*i,this.uom=t.uom,this):(it(t)||(this.a+=t.a*i,this.x+=t.x*i,this.y+=t.y*i,this.b+=t.b*i,this.uom=U.compatible(this.uom,t.uom)),this)}addVector(t,i=1){if(this.isLocked())return mt(this.clone().addVector(t,i));if(this.isZero())this.uom=t.uom;else {if(tt(t))return this;this.uom=U.compatible(this.uom,t.uom);}return this.x+=t.x*i,this.y+=t.y*i,this}clone(){return lt.copy(this)}copy(t){return this.a=t.a,this.x=t.x,this.y=t.y,this.b=t.b,this.uom=t.uom,this}copyBivector(t){const i=t.xy;return this.setCoordinate(0,0,"a"),this.setCoordinate(1,0,"x"),this.setCoordinate(2,0,"y"),this.setCoordinate(3,i,"b"),this.uom=t.uom,this}copyScalar(t,i){return this.setCoordinate(0,t,"a"),this.setCoordinate(1,0,"x"),this.setCoordinate(2,0,"y"),this.setCoordinate(3,0,"b"),this.uom=i,this}copyVector(t){const i=t.x,s=t.y;return this.setCoordinate(0,0,"a"),this.setCoordinate(1,i,"x"),this.setCoordinate(2,s,"y"),this.setCoordinate(3,0,"b"),this.uom=t.uom,this}direction(){if(this.isMutable()){const t=this.magnitudeNoUnits();return 0!==t&&(this.a=this.a/t,this.x=this.x/t,this.y=this.y/t,this.b=this.b/t),this.uom=void 0,this}return mt(this.clone().direction())}divByPseudo(t,i){if(this.isMutable()){const s=this.a,e=this.x,r=this.y,o=this.b;return this.a=o/t,this.x=r/t,this.y=-e/t,this.b=-s/t,this.uom=U.div(this.uom,i),this}return mt(this.clone().divByPseudo(t,i))}divByScalar(t,i){return this.isLocked()?mt(this.clone().divByScalar(t,i)):(this.uom=U.div(this.uom,i),this.a/=t,this.x/=t,this.y/=t,this.b/=t,this)}ext(t){if(this.isLocked())return mt(this.clone().ext(t));{const i=this.a,s=this.x,e=this.y,r=this.b,o=t.a,n=t.x,h=t.y,u=t.b;return this.a=i*o,this.x=i*n+s*o,this.y=i*h+e*o,this.b=i*u+s*h-e*n+r*o,this.uom=U.mul(this.uom,t.uom),this}}inv(){if(this.isLocked())return mt(this.clone().inv());{const t=this.a,i=this.x,s=this.y,e=this.b,r=N([[+t,+i,+s,-e],[+i,+t,-e,+s],[+s,+e,+t,-i],[+e,+s,-i,+t]],[1,0,0,0]);return this.a=r[0],this.x=r[1],this.y=r[2],this.b=r[3],this.uom=U.inv(this.uom),this}}isBivector(){return 0===this.a&&0===this.x&&0===this.y}isOne(){return !!U.isOne(this.uom)&&(1===this.a&&0===this.x&&0===this.y&&0===this.b)}isScalar(){return at(this)}isSpinor(){return !!U.isOne(this.uom)&&(0===this.x&&0===this.y)}isVector(){return 0===this.a&&0===this.b}isZero(){return 0===this.a&&0===this.x&&0===this.y&&0===this.b}magnitude(){return this.isMutable()?(this.a=this.magnitudeNoUnits(),this.x=0,this.y=0,this.b=0,this):mt(this.clone().magnitude())}magnitudeNoUnits(){return Math.sqrt(this.quaditudeNoUnits())}mul(t){return this.isLocked()?mt(this.clone().mul(t)):this.mul2(this,t)}mul2(t,i){const s=t.a,e=t.x,r=t.y,o=t.b,n=i.a,h=i.x,u=i.y,c=i.b;return this.a=s*n+e*h+r*u-o*c,this.x=s*h+e*n-r*c+o*u,this.y=s*u+e*c+r*n-o*h,this.b=s*c+e*u-r*h+o*n,this.uom=U.mul(this.uom,i.uom),this}mulByBivector(t){if(this.isLocked())return mt(this.clone().mulByBivector(t));{this.uom=U.mul(this.uom,t.uom);const i=this.a,s=this.x,e=this.y,r=this.b,o=t.xy;return this.a=-r*o,this.x=-e*o,this.y=+s*o,this.b=i*o,this}}mulByNumber(t){return this.isLocked()?mt(this.clone().mulByNumber(t)):(this.a*=t,this.x*=t,this.y*=t,this.b*=t,this)}mulByScalar(t,i){return this.isLocked()?mt(this.clone().mulByScalar(t,i)):(this.a*=t,this.x*=t,this.y*=t,this.b*=t,this.uom=U.mul(this.uom,i),this)}mulByVector(t){if(this.isLocked())return mt(this.clone().mulByVector(t));{this.uom=U.mul(this.uom,t.uom);const i=this.a,s=this.x,e=this.y,r=this.xy,o=t.x,n=t.y;return this.a=s*o+e*n,this.x=i*o+r*n,this.y=i*n-r*o,this.b=s*n-e*o,this}}neg(){return this.isLocked()?mt(this.clone().neg()):(this.a=-this.a,this.x=-this.x,this.y=-this.y,this.b=-this.b,this)}quaditude(){return this.isMutable()?(this.a=this.quaditudeNoUnits(),this.x=0,this.y=0,this.b=0,this.uom=U.mul(this.uom,this.uom),this):mt(this.clone().quaditude())}rev(){return this.isMutable()?(this.a=+this.a,this.x=+this.x,this.y=+this.y,this.b=-this.b,this):mt(this.clone().rev())}rotate(t){if(this.isLocked())return mt(this.clone().rotate(t));{U.assertDimensionless(t.uom);const i=this.a,s=this.x,e=this.y,r=this.b,o=t.a,n=t.xy,h=o*o,u=n*n,c=h-u,a=2*o*n,m=h+u;return this.a=m*i,this.x=c*s+a*e,this.y=c*e-a*s,this.b=m*r,this}}scp(t){return this.isLocked()?mt(this.clone().scp(t)):this.scp2(this,t)}scp2(t,i){const s=t.a,e=t.x,r=t.y,o=t.b,n=s*i.a+e*i.x+r*i.y-o*i.b;return this.a=n,this.x=0,this.y=0,this.b=0,this.uom=U.mul(t.uom,i.uom),this}quaditudeNoUnits(){const t=this.a,i=this.x,s=this.y,