three-hilbert-geometry 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // Version 1.1.0 three-hilbert-geometry - https://github.com/vasturiano/three-hilbert-geometry
1
+ // Version 1.1.1 three-hilbert-geometry - https://github.com/vasturiano/three-hilbert-geometry
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('three')) :
4
4
  typeof define === 'function' && define.amd ? define(['three'], factory) :
@@ -1,2 +1,2 @@
1
- // Version 1.1.0 three-hilbert-geometry - https://github.com/vasturiano/three-hilbert-geometry
1
+ // Version 1.1.1 three-hilbert-geometry - https://github.com/vasturiano/three-hilbert-geometry
2
2
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("three")):"function"==typeof define&&define.amd?define(["three"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).HilbertGeometry=e(t.THREE)}(this,function(t){"use strict";const e=[[0,3,4,7,6,5,2,1],[0,7,6,1,2,5,4,3],[0,7,6,1,2,5,4,3],[2,3,0,1,6,7,4,5],[2,3,0,1,6,7,4,5],[4,3,2,5,6,1,0,7],[4,3,2,5,6,1,0,7],[6,5,2,1,0,3,4,7]],n=[[0,1,2,3,4,5,6,7]],r=[],o=new Map([[n[0].join(""),0]]);for(let t=0;t<n.length;t++){const i=n[t],s=[];for(const t of e){const e=t.map(t=>i[t]),r=e.join("");let a=o.get(r);void 0===a&&(a=n.length,n.push(e),o.set(r,a)),s.push(a)}r.push(s)}const i=[0n,1n,2n,3n,4n,5n,6n,7n],s=new t.Vector3(0,0,0);function a(e=s,n=10,r=1,o=0,i,a=0,h=1,d=2,p=3,w=4,b=5,y=6,m=7){if(r<0)return[new t.Vector3(0,0,0)];if(!Number.isInteger(r))throw new TypeError("Order must be an integer.");const g=[];if("bigint"==typeof o||"bigint"==typeof i){const t=f(o),s=8n**BigInt(r+1),c=void 0===i?s:f(i),A=t<0n?0n:t,V=A+(c>0n?c:0n),F=V>s?s:V;if(A>=F)return g;const B=[a,h,d,p,w,b,y,m];return F-A===1n?(l(g,e.x,e.y,e.z,n,r,A,BigInt(3*r),0,B),g):(u(g,e.x,e.y,e.z,n,r,0n,s/8n,0,A,F,B),g)}const A=8**(r+1),V=Math.floor(o),F=Math.max(0,V),B=void 0===i?A:Math.max(0,Math.floor(i)),x=Math.min(A,F+B);if(F>=x)return g;const v=[a,h,d,p,w,b,y,m];return c(g,e.x,e.y,e.z,n,r,0,A/8,0,F,x,v),g}function c(e,o,i,s,a,u,l,f,h,d,p,w){const b=n[h],y=r[h],m=a/2;for(let n=0;n<8;n++){const r=l+n*f;if(r+f<=d||r>=p)continue;const a=w[b[n]],h=o+(a<4?-m:m),g=i+(a<2||a>5?m:-m),A=s+(a%4==1||a%4==2?m:-m);0===u?e.push(new t.Vector3(h,g,A)):c(e,h,g,A,m,u-1,r,f/8,y[n],d,p,w)}}function u(e,o,s,a,c,l,f,h,d,p,w,b){const y=n[d],m=r[d],g=c/2,A=h/8n,V=f+8n*h,F=p<=f?0:Number((p-f)/h),B=w>=V?7:Number((w-1n-f)/h);let x=f+i[F]*h;for(let n=F;n<=B;n++,x+=h){const r=b[y[n]],i=o+(r<4?-g:g),c=s+(r<2||r>5?g:-g),f=a+(r%4==1||r%4==2?g:-g);0===l?e.push(new t.Vector3(i,c,f)):u(e,i,c,f,g,l-1,x,A,m[n],p,w,b)}}function l(e,o,i,s,a,c,u,f,h,d){const p=n[h],w=Number(u>>f&7n),b=d[p[w]],y=a/2,m=o+(b<4?-y:y),g=i+(b<2||b>5?y:-y),A=s+(b%4==1||b%4==2?y:-y);0===c?e.push(new t.Vector3(m,g,A)):l(e,m,g,A,y,c-1,u,f-3n,r[h][w],d)}function f(t){if("bigint"==typeof t)return t;if(!Number.isSafeInteger(t))throw new TypeError("BigInt ranges require integer values.");return BigInt(t)}const h=[[0,1,5,4],[1,2,6,5],[2,3,7,6],[3,0,4,7],[0,3,2,1],[4,5,6,7]],d=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]],p=new Float32Array(48),w=new Float32Array(72),b=new Uint16Array(36),y=[[0,-1,0],[1,0,0],[0,1,0],[-1,0,0],[0,0,-1],[0,0,1]];for(let t=0;t<h.length;t++){const e=h[t],n=y[t];for(let r=0;r<4;r++){const o=4*t+r,i=e[r];p[2*o]=i%2,p[2*o+1]=Math.floor(i/2)%2,w.set(n,3*o)}const r=4*t,o=6*t;b.set([r,r+1,r+2,r,r+2,r+3],o)}class m extends t.BufferGeometry{constructor(e=[],n=1){if(super(),!Array.isArray(e))throw new TypeError("points must be an array of Vector3 instances");if(!Number.isFinite(n)||n<0)throw new RangeError("width must be a non-negative finite number");if(this.type="SquareTubeGeometry",e.length<=1){const r=e[0];if(!(1!==e.length||r&&Number.isFinite(r.x)&&Number.isFinite(r.y)&&Number.isFinite(r.z)))throw new TypeError("points[0] must have finite x, y, and z coordinates");if(this.parameters={points:r?[new t.Vector3(r.x,r.y,r.z)]:[],width:n},!r||0===n)return this.setIndex([]),this.setAttribute("position",new t.Float32BufferAttribute([],3)),void this.setAttribute("uv",new t.Float32BufferAttribute([],2));const o=n/2,i=r.x,s=r.y,a=r.z,c=new Float32Array(72);let u=0;for(const t of h)for(const e of t){const t=d[e];c[u++]=i+t[0]*o,c[u++]=s+t[1]*o,c[u++]=a+t[2]*o}return this.setIndex(new t.Uint16BufferAttribute(b.slice(),1)),this.setAttribute("position",new t.Float32BufferAttribute(c,3)),this.setAttribute("uv",new t.Float32BufferAttribute(p.slice(),2)),this.setAttribute("normal",new t.Float32BufferAttribute(w.slice(),3)),this.boundingBox=new t.Box3(new t.Vector3(i-o,s-o,a-o),new t.Vector3(i+o,s+o,a+o)),void(this.boundingSphere=new t.Sphere(new t.Vector3(i,s,a),Math.sqrt(3)*o))}const r=[];for(let n=0;n<e.length;n++){const o=e[n];if(!(o&&Number.isFinite(o.x)&&Number.isFinite(o.y)&&Number.isFinite(o.z)))throw new TypeError(`points[${n}] must have finite x, y, and z coordinates`);const i=new t.Vector3(o.x,o.y,o.z);(0===n||i.distanceToSquared(r[r.length-1])>0)&&r.push(i)}if(this.parameters={points:r.map(t=>t.clone()),width:n},0===r.length||0===n)return this.setIndex([]),this.setAttribute("position",new t.Float32BufferAttribute([],3)),void this.setAttribute("uv",new t.Float32BufferAttribute([],2));if(1===r.length){const[e,o,i]=r[0].toArray(),s=n/2,a=new Float32Array(72);let c=0;for(const t of h)for(const n of t){const t=d[n];a[c++]=e+t[0]*s,a[c++]=o+t[1]*s,a[c++]=i+t[2]*s}return this.setIndex(new t.Uint16BufferAttribute(b.slice(),1)),this.setAttribute("position",new t.Float32BufferAttribute(a,3)),this.setAttribute("uv",new t.Float32BufferAttribute(p.slice(),2)),this.setAttribute("normal",new t.Float32BufferAttribute(w.slice(),3)),this.computeBoundingBox(),void this.computeBoundingSphere()}const o=new Array(r.length-1);for(let t=0;t<o.length;t++)o[t]=r[t+1].clone().sub(r[t]).normalize();const i=1e-6,s=r.length>2&&0===r[0].distanceToSquared(r[r.length-1]);for(let t=1;t<o.length;t++){const e=o[t-1].dot(o[t]);if(!(Math.abs(e)<=i)&&!(e>=.999999))throw new RangeError("path turns must be 90 degrees; straight segments are also allowed")}if(s){const t=o[o.length-1].dot(o[0]);if(Math.abs(t)>i&&t<.999999)throw new RangeError("path turns must be 90 degrees; straight segments are also allowed")}const a=new Float64Array(r.length);for(let t=1;t<r.length;t++)a[t]=a[t-1]+r[t].distanceTo(r[t-1]);const c=a[a.length-1],u=n/2,l=c+(s?0:n),f=new Array(o.length),y=new t.Vector3,m=new t.Vector3,g=new t.Quaternion;for(let t=0;t<o.length;t++){if(0===t){const e=o[t],n=Math.abs(e.x),r=Math.abs(e.y),i=Math.abs(e.z);y.set(n<=r&&n<=i?1:0,r<n&&r<=i?1:0,i<n&&i<r?1:0),y.addScaledVector(e,-y.dot(e)).normalize()}else g.setFromUnitVectors(o[t-1],o[t]),y.applyQuaternion(g),y.addScaledVector(o[t],-y.dot(o[t])).normalize();m.crossVectors(o[t],y).normalize(),f[t]={normal:y.clone(),binormal:m.clone()}}const A=4*o.length+(s?0:2),V=4*A,F=new Float32Array(3*V),B=new Float32Array(2*V),x=V>65535,v=x?t.Uint32BufferAttribute:t.Uint16BufferAttribute,M=x?new Uint32Array(6*A):new Uint16Array(6*A),z=[0,1,2,3],S=Array.from({length:4},()=>new t.Vector3),N=Array.from({length:4},()=>new t.Vector3),T=Array.from({length:4},()=>new t.Vector3),I=new t.Vector3,E=new t.Vector3,U=new t.Vector3,q=new t.Vector3,j=new t.Vector3,G=new t.Vector3,R=new t.Vector3,H=[null,null,null,null],C=new Float32Array(8),O=new Float32Array([0,0,.75,0,.5,0,.25,0]),Q=new Float32Array([0,1,.25,1,.5,1,.75,1]);let $=0,k=0,D=0,J=0;function K(t,e,n,r,o,i=0){for(let r=0;r<4;r++){const s=0===r||3===r?1:-1,a=r<2?1:-1;o[r].copy(t).addScaledVector(n,i*u).addScaledVector(e.normal,s*u).addScaledVector(e.binormal,a*u)}if(r){j.copy(n).add(r).normalize();const e=j.dot(n);for(const r of o)G.copy(r).sub(t),r.addScaledVector(n,-j.dot(G)/e)}}function L(t,e,n,r,o,i){const s=void 0!==i;if(I.copy(e).sub(t),E.copy(n).sub(t),U.crossVectors(I,E).dot(o)<0){const t=e;if(e=r,r=t,s){const t=i[2],e=i[3];i[2]=i[6],i[3]=i[7],i[6]=t,i[7]=e}}H[0]=t,H[1]=e,H[2]=n,H[3]=r;for(let t=0;t<4;t++){const e=H[t];F[$++]=e.x,F[$++]=e.y,F[$++]=e.z,s?(B[k++]=i[2*t],B[k++]=i[2*t+1]):(B[k++]=1===t||2===t?1:0,B[k++]=t>=2?1:0)}M[J++]=D,M[J++]=D+1,M[J++]=D+2,M[J++]=D,M[J++]=D+2,M[J++]=D+3,D+=4}for(let t=0;t<o.length;t++){const e=o[t],n=t>0?o[t-1]:s?o[o.length-1]:void 0,c=t<o.length-1?o[t+1]:s?o[0]:void 0,h=n&&Math.abs(n.dot(e))<=i?n:void 0,d=c&&Math.abs(e.dot(c))<=i?c:void 0;if(K(r[t],f[t],e,h,S,0!==t||s?0:-1),K(r[t+1],f[t],e,d,N,t!==o.length-1||s?0:1),0===t)for(let t=0;t<4;t++)T[t].copy(S[t]);R.copy(r[t]).add(r[t+1]).multiplyScalar(.5);const p=0!==t||s?(a[t]+(s?0:u))/l:0,w=t!==o.length-1||s?(a[t+1]+(s?0:u))/l:1;for(const t of z){const e=(t+1)%4,n=0,r=1;C[0]=n,C[1]=p,C[2]=r,C[3]=p,C[4]=r,C[5]=w,C[6]=n,C[7]=w,q.copy(S[t]).add(S[e]).add(N[t]).add(N[e]).multiplyScalar(.25).sub(R),L(S[t],S[e],N[e],N[t],q,C)}}s||(G.copy(o[0]).negate(),L(T[0],T[3],T[2],T[1],G,O),L(N[0],N[1],N[2],N[3],o[o.length-1],Q)),this.setIndex(new v(M,1)),this.setAttribute("position",new t.Float32BufferAttribute(F,3)),this.setAttribute("uv",new t.Float32BufferAttribute(B,2)),this.computeVertexNormals(),this.computeBoundingBox(),this.computeBoundingSphere()}copy(t){return super.copy(t),this.parameters={points:t.parameters.points.map(t=>t.clone()),width:t.parameters.width},this}}return class extends m{constructor(t,e,n,{padding:r=0,simplifyCurves:o=!0}={}){super(...function(){if("bigint"!=typeof e&&(e=Math.round(e)),"bigint"!=typeof n&&(n=Math.round(n)),o){const r="bigint"==typeof e?8n:8;for(;!(e%r)&&!(n%r)&&t>0;)e/=r,n/=r,t-=1}const i=a(void 0,1,t-1,e,n),s=1/2**(t-1)*(1-Math.min(1,r));return[i,s]}()),this.type="HilbertGeometry";const i=this.parameters;this.parameters={...i,order:t,start:e,length:n,padding:r,simplifyCurves:o}}clone(){return new this.constructor(0,1,0).copy(this)}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters,{points:t.parameters.points.map(t=>t.clone())}),this}}});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-hilbert-geometry",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "ThreeJS geometry for drawing a Hilbert curve segment",
5
5
  "type": "module",
6
6
  "unpkg": "dist/three-hilbert-geometry.min.js",