You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
23 KiB

4 months ago
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).BubbleSets={})}(this,(function(t){"use strict";function e(t,e,i,s,n,r){const h=i-t,o=s-e;let a=n-t,c=r-e,u=a*h+c*o,l=0;u<=0?l=0:(a=h-a,c=o-c,u=a*h+c*o,l=u<=0?0:u*u/(h*h+o*o));const x=a*a+c*c-l;return x<0?0:x}function i(t,e,i,s){return(t-i)*(t-i)+(e-s)*(e-s)}function s(t,e,s,n,r){return i(t,e,s,n)<r*r}function n(t){const e=Math.min(t.x1,t.x2),i=Math.max(t.x1,t.x2),s=Math.min(t.y1,t.y2),n=Math.max(t.y1,t.y2);return{x:e,y:s,x2:i,y2:n,width:i-e,height:n-s}}class r{constructor(t,e,i,s){this.x1=t,this.y1=e,this.x2=i,this.y2=s}equals(t){return this.x1===t.x1&&this.y1===t.y1&&this.x2===t.x2&&this.y2===t.y2}draw(t){t.moveTo(this.x1,this.y1),t.lineTo(this.x2,this.y2)}toString(){return`Line(from=(${this.x1},${this.y1}),to=(${this.x2},${this.y2}))`}static from(t){return new r(t.x1,t.y1,t.x2,t.y2)}cuts(t,e){if(this.y1===this.y2)return!1;if(e<this.y1&&e<=this.y2||e>this.y1&&e>=this.y2)return!1;if(t>this.x1&&t>=this.x2)return!1;if(t<this.x1&&t<=this.x2)return!0;return t<=this.x1+(e-this.y1)*(this.x2-this.x1)/(this.y2-this.y1)}distSquare(t,i){return e(this.x1,this.y1,this.x2,this.y2,t,i)}ptClose(t,e,i){if(this.x1<this.x2){if(t<this.x1-i||t>this.x2+i)return!1}else if(t<this.x2-i||t>this.x1+i)return!1;if(this.y1<this.y2){if(e<this.y1-i||e>this.y2+i)return!1}else if(e<this.y2-i||e>this.y1+i)return!1;return!0}}var h,o;!function(t){t[t.POINT=1]="POINT",t[t.PARALLEL=2]="PARALLEL",t[t.COINCIDENT=3]="COINCIDENT",t[t.NONE=4]="NONE"}(h||(h={}));class a{constructor(t,e=0,i=0){this.state=t,this.x=e,this.y=i}}function c(t,e){const i=(e.x2-e.x1)*(t.y1-e.y1)-(e.y2-e.y1)*(t.x1-e.x1),s=(t.x2-t.x1)*(t.y1-e.y1)-(t.y2-t.y1)*(t.x1-e.x1),n=(e.y2-e.y1)*(t.x2-t.x1)-(e.x2-e.x1)*(t.y2-t.y1);if(n){const e=i/n,r=s/n;return 0<=e&&e<=1&&0<=r&&r<=1?new a(h.POINT,t.x1+e*(t.x2-t.x1),t.y1+e*(t.y2-t.y1)):new a(h.NONE)}return new a(0===i||0===s?h.COINCIDENT:h.PARALLEL)}function u(t,e){const i=(e.x2-e.x1)*(t.y1-e.y1)-(e.y2-e.y1)*(t.x1-e.x1),s=(t.x2-t.x1)*(t.y1-e.y1)-(t.y2-t.y1)*(t.x1-e.x1),n=(e.y2-e.y1)*(t.x2-t.x1)-(e.x2-e.x1)*(t.y2-t.y1);if(n){const t=i/n,e=s/n;if(0<=t&&t<=1&&0<=e&&e<=1)return t}return Number.POSITIVE_INFINITY}function l(t,e,i){const s=new Set;return t.width<=0?(s.add(o.LEFT),s.add(o.RIGHT)):e<t.x?s.add(o.LEFT):e>t.x+t.width&&s.add(o.RIGHT),t.height<=0?(s.add(o.TOP),s.add(o.BOTTOM)):i<t.y?s.add(o.TOP):i>t.y+t.height&&s.add(o.BOTTOM),s}function x(t,e){let i=e.x1,s=e.y1;const n=e.x2,r=e.y2,h=Array.from(l(t,n,r));if(0===h.length)return!0;let a=l(t,i,s);for(;0!==a.size;){for(const t of h)if(a.has(t))return!1;if(a.has(o.RIGHT)||a.has(o.LEFT)){let e=t.x;a.has(o.RIGHT)&&(e+=t.width),s+=(e-i)*(r-s)/(n-i),i=e}else{let e=t.y;a.has(o.BOTTOM)&&(e+=t.height),i+=(e-s)*(n-i)/(r-s),s=e}a=l(t,i,s)}return!0}function f(t,e){let i=Number.POSITIVE_INFINITY,s=0;function n(t,n,h,o){let a=u(e,new r(t,n,h,o));a=Math.abs(a-.5),a>=0&&a<=1&&(s++,a<i&&(i=a))}return n(t.x,t.y,t.x2,t.y),n(t.x,t.y,t.x,t.y2),s>1?i:(n(t.x,t.y2,t.x2,t.y2),s>1?i:(n(t.x2,t.y,t.x2,t.y2),0===s?-1:i))}function y(t,e){let i=0;const s=c(t,new r(e.x,e.y,e.x2,e.y));i+=s.state===h.POINT?1:0;const n=c(t,new r(e.x,e.y,e.x,e.y2));i+=n.state===h.POINT?1:0;const o=c(t,new r(e.x,e.y2,e.x2,e.y2));i+=o.state===h.POINT?1:0;const a=c(t,new r(e.x2,e.y,e.x2,e.y2));return i+=a.state===h.POINT?1:0,{top:s,left:n,bottom:o,right:a,count:i}}!function(t){t[t.LEFT=0]="LEFT",t[t.TOP=1]="TOP",t[t.RIGHT=2]="RIGHT",t[t.BOTTOM=3]="BOTTOM"}(o||(o={}));class d{constructor(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s}get x2(){return this.x+this.width}get y2(){return this.y+this.height}get cx(){return this.x+this.width/2}get cy(){return this.y+this.height/2}get radius(){return Math.max(this.width,this.height)/2}static from(t){return new d(t.x,t.y,t.width,t.height)}equals(t){return this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height}clone(){return new d(this.x,this.y,this.width,this.height)}add(t){const e=Math.min(this.x,t.
//# sourceMappingURL=index.umd.min.js.map