diff --git a/README.md b/README.md index 876deeb..c93f3b7 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ A JavaScript library for doing geometry. ### Web browser In vanilla, a `geometric` global is exported. You can use the latest version from unpkg. ```html - - + + ``` If you'd rather host it yourself, download the latest release from the [`build` directory](https://github.com/HarryStevens/geometric/tree/master/build). diff --git a/build/geometric.js b/build/geometric.js index c9e46d8..7c2f980 100644 --- a/build/geometric.js +++ b/build/geometric.js @@ -1,4 +1,4 @@ -// https://github.com/HarryStevens/geometric#readme Version 2.5.3. Copyright 2023 Harry Stevens. +// https://github.com/HarryStevens/geometric#readme Version 2.5.4. Copyright 2023 Harry Stevens. (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : diff --git a/build/geometric.min.js b/build/geometric.min.js new file mode 100644 index 0000000..589e0c3 --- /dev/null +++ b/build/geometric.min.js @@ -0,0 +1 @@ +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.geometric={})}(this,function(n){"use strict";function t(n){return 180*n/Math.PI}function r(n){return t(Math.atan2(n[1][1]-n[0][1],n[1][0]-n[0][0]))}function e(n,t){return a(n)||l(n,t)||c()}function o(n){return i(n)||u(n)||f()}function i(n){if(Array.isArray(n)){for(var t=0,r=new Array(n.length);t1&&void 0!==arguments[1]&&arguments[1],r=e(n,2),o=e(r[0],2),i=o[0],a=o[1],u=e(r[1],2),l=u[0],f=u[1],c=function(n){return(l-i)*n+i},h=function(n){return(f-a)*n+a};return function(n){var r=t?n<0?0:n>1?1:n:n;return[c(r),h(r)]}}function g(n){return Math.sqrt(Math.pow(n[1][0]-n[0][0],2)+Math.pow(n[1][1]-n[0][1],2))}function v(n){return[(n[0][0]+n[1][0])/2,(n[0][1]+n[1][1])/2]}function p(n){return n/180*Math.PI}function s(n,t,r){var e=p(t||0);return!r||0===r[0]&&0===r[1]?y(n,e):y(n.map(function(n,t){return n-r[t]}),e).map(function(n,t){return n+r[t]})}function y(n,t){return[n[0]*Math.cos(t)-n[1]*Math.sin(t),n[0]*Math.sin(t)+n[1]*Math.cos(t)]}function d(n,t,r){return n.map(function(e){return s(e,t,r||v(n))})}function M(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,e=p(t);return[n[0]+r*Math.cos(e),n[1]+r*Math.sin(e)]}function m(n,t,r){return n.map(function(n){return M(n,t,r)})}function b(n){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=0,e=0,o=n.length;er&&(r=f),co&&(o=c))}return i?[[t,e],[r,o]]:null}function A(n){for(var t=0,r=0,e=0,o=n.length,i=0;i=2&&w(r[r.length-2],r[r.length-1],t[e])<=0;)r.pop();r.push(t[e])}for(var o=[],i=t.length-1;i>=0;i--){for(;o.length>=2&&w(o[o.length-2],o[o.length-1],t[i])<=0;)o.pop();o.push(t[i])}return o.pop(),r.pop(),r.concat(o)}function R(n){return k(n)?n:[].concat(o(n),[n[0]])}function k(n){var t=n[0],r=n[n.length-1];return t[0]===r[0]&&t[1]===r[1]}function L(n){if(0===n.length)return 0;for(var t,r,e=-1,o=n.length,i=n[o-1],a=i[0],u=i[1],l=0;++e=1)return e[e.length-1];for(var o=L(e)*t,i=[],a=0,u=0;u0&&void 0!==arguments[0]?arguments[0]:3,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[0,0],o=Math.sqrt(t/Math.PI),i=Array.from({length:n},function(){return 2*o*Math.random()}),a=Array.from({length:n},function(){return 2*o*Math.random()});i.sort(function(n,t){return n-t}),a.sort(function(n,t){return n-t});var u=O(i,i[0],i[i.length-1]),l=O(a,a[0],a[a.length-1]);E(l);var f=[],c=0,h=0,v=(u.map(function(n,t){return[n,l[t]]}).sort(function(n,t){return Math.atan2(t[1],t[0])-Math.atan2(n[1],n[0])}).forEach(function(n){c+=1*n[0],h+=1*n[1],f.push([c,h])}),A(f));return j(x(f,t/b(f)),r([v,e]),g([v,e]))}function O(n,t,r){for(var e=t,o=t,i=[],a=1;a.5?(i.push(u-e),e=u):(i.push(o-u),o=u)}return i.push(r-e),i.push(o-r),i}function E(n){for(var t=n.length-1;t>0;t--){var r=Math.floor(Math.random()*(t+1)),e=[n[r],n[t]];n[t]=e[0],n[r]=e[1]}}function F(n){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=I(n),o=e(r,2),i=e(o[0],2),a=i[0],u=(i[1],e(o[1],2)),l=u[0],f=(u[1],[]),c=0,g=n.length;c1&&void 0!==arguments[1]?arguments[1]:1,r=I(n),o=e(r,2),i=e(o[0],2),a=(i[0],i[1]),u=e(o[1],2),l=(u[0],u[1]),f=[],c=0,g=n.length;c0&&void 0!==arguments[0]?arguments[0]:3,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,e=arguments.length>2?arguments[2]:void 0,o=[],i=[0,0],a=[0,0],u=0,l=0;l1&&void 0!==arguments[1]?arguments[1]:"ccw";if(n.length<3)return null;var r=n.slice().reverse(),e=b(n,!0)>0;return"cw"===t||"clockwise"===t?e?n:r:e?r:n}function H(n){return n[1][1]>n[0][1]?n:[n[1],n[0]]}function z(n,t){var r=H(t);return w(n,r[1],r[0])<0}function G(n,t){var r=H(t);return w(n,r[1],r[0])>0}function J(n,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,e=g(t);return K(n,t,r)&&g([t[0],n])<=e&&g([t[1],n])<=e}function K(n,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return Math.abs(w(n,t[0],t[1]))<=r}function N(n,t){var r=e(n,2),o=e(r[0],2),i=o[0],a=o[1],u=e(r[1],2),l=u[0],f=u[1],c=e(t,2),h=e(c[0],2),g=h[0],v=h[1],p=e(c[1],2),s=p[0],y=p[1];if(i===g&&a===v)return!0;if(l===s&&f===y)return!0;if(J(n[0],t)||J(n[1],t))return!0;if(J(t[0],n)||J(t[1],n))return!0;var d=(y-v)*(l-i)-(s-g)*(f-a);if(0===d)return!1;var M=a-v,m=i-g,b=(s-g)*M-(y-v)*m,I=(l-i)*M-(f-a)*m,A=b/d,w=I/d;return A>0&&A<1&&w>0&&w<1}function Q(n,t){for(var r=!1,e=R(t),o=0,i=e.length-1;oe!=c>e&&r<(f-u)*(e-l)/(c-l)+u&&(o=!o)}return o}function V(n,t){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,e=!1,o=R(t),i=0,a=o.length-1;i=360?r-360:r<0?r+360:r}n.lineAngle=r,n.lineInterpolate=h,n.lineLength=g,n.lineMidpoint=v,n.lineRotate=d,n.lineTranslate=m,n.pointRotate=s,n.pointTranslate=M,n.polygonArea=b,n.polygonBounds=I,n.polygonCentroid=A,n.polygonHull=P,n.polygonInterpolate=S,n.polygonLength=L,n.polygonMean=T,n.polygonRandom=q,n.polygonReflectX=F,n.polygonReflectY=W,n.polygonRegular=X,n.polygonRotate=Y,n.polygonScale=_,n.polygonScaleArea=x,n.polygonScaleX=B,n.polygonScaleY=C,n.polygonTranslate=j,n.polygonWind=D,n.lineIntersectsLine=N,n.lineIntersectsPolygon=Q,n.pointInPolygon=U,n.pointOnPolygon=V,n.pointLeftofLine=z,n.pointRightofLine=G,n.pointOnLine=J,n.pointWithLine=K,n.polygonInPolygon=Z,n.polygonIntersectsPolygon=$,n.angleReflect=nn,n.angleToDegrees=t,n.angleToRadians=p,Object.defineProperty(n,"__esModule",{value:!0})}); \ No newline at end of file diff --git a/build/geometric.zip b/build/geometric.zip new file mode 100644 index 0000000..7089df9 Binary files /dev/null and b/build/geometric.zip differ