1 line
12 KiB
Plaintext
1 line
12 KiB
Plaintext
![]() |
{"version":3,"file":"CSGSubtract.worker.cjs","sources":["../src/Nest/Common/Util.ts","../src/csg/core/constants.ts","../src/csg/core/FuzzyFactory.ts","../src/Geometry/CSGSubtract/CSGSubtract.ts","../src/Geometry/CSGSubtract/CSGSubtract.worker.ts"],"sourcesContent":["export function equaln(v1: number, v2: number, fuzz = 1e-5)\r\n{\r\n return Math.abs(v1 - v2) <= fuzz;\r\n}\r\n\r\nexport function FixIndex(index: number, arr: Array<any> | number)\r\n{\r\n let count = (arr instanceof Array) ? arr.length : arr;\r\n if (index < 0)\r\n return count + index;\r\n else if (index >= count)\r\n return index - count;\r\n else\r\n return index;\r\n}\r\n\r\n/**\r\n * @param compart true => t2 , false => t1\r\n * @returns 索引\r\n */\r\nexport function Max<T>(arr: T[], compart: (t1: T, t2: T) => boolean): number\r\n{\r\n let best: T = arr[0];\r\n let bestIndex = 0;\r\n for (let i = 1; i < arr.length; i++)\r\n {\r\n let t1 = arr[i];\r\n if (compart(best, t1))\r\n {\r\n best = t1;\r\n bestIndex = i;\r\n }\r\n }\r\n return bestIndex;\r\n}\r\n","export const _CSGDEBUG = false;\r\n\r\n/** Epsilon used during determination of near zero distances.\r\n * @default\r\n */\r\nexport const EPS = 5e-2;\r\n\r\n// Tag factory: we can request a unique tag through CSG.getTag()\r\nexport let staticTag = 1;\r\nexport const getTag = () => staticTag++;\r\n","\r\n// //////////////////////////////\r\n// ## class fuzzyFactory\r\n// This class acts as a factory for objects. We can search for an object with approximately\r\n// the desired properties (say a rectangle with width 2 and height 1)\r\n// The lookupOrCreate() method looks for an existing object (for example it may find an existing rectangle\r\n// with width 2.0001 and height 0.999. If no object is found, the user supplied callback is\r\n// called, which should generate a new object. The new object is inserted into the database\r\n// so it can be found by future lookupOrCreate() calls.\r\n// Constructor:\r\n// numdimensions: the number of parameters for each object\r\n// for example for a 2D rectangle this would be 2\r\n\r\nimport { EPS } from \"./constants\";\r\n\r\n// tolerance: The maximum difference for each parameter allowed to be considered a match\r\nexport class FuzzyFactory\r\n{\r\n lookuptable: {};\r\n multiplier: number;\r\n constructor(numdimensions: number = 3, tolerance: number = EPS)\r\n {\r\n this.lookuptable = {};\r\n this.multiplier = 1.0 / tolerance;\r\n }\r\n\r\n // let obj = f.lookupOrCreate([el1, el2, el3], function(elements) {/* create the new object */});\r\n // Performs a fuzzy lookup of the object with the specified elements.\r\n // If found, returns the existing object\r\n // If not found, calls the supplied callback function which should create a new object with\r\n // the specified properties. This object is inserted in the lookup database.\r\n lookupOrCreate<T>(els: number[], object: T): T\r\n {\r\n let hash = \"\";\r\n let multiplier = this.multiplier;\r\n for (let el of els)\r\n {\r\n let valueQuantized = Math.round(el * multiplier);\r\n hash += valueQuantized + \"/\";\r\n }\r\n if (hash in this.lookuptable) return this.lookuptable[hash];\r\n else\r\n {\r\n let hashparts = els.map(el =>\r\n {\r\n let q0 = Math.floor(el * multiplier);\r\n let q1 = q0 + 1;\r\n return [\"\" + q0 + \"/\", \"\" + q1 + \"/\"];\r\n });\r\n let numelements = els.length;\r\n let numhashes = 1 << numelements;\r\n for (let hashmask = 0; hashmask < numhashes; ++hashmask)\r\n {\r\n let hashmaskShifted = hashmask;\r\n hash = \"\";\r\n hashparts.forEach(hashpart =>\r\n {\r\n hash += hashpart[hashmaskShifted & 1];\r\n hashmaskShifted >>= 1;\r\n
|