Last active
October 26, 2018 09:15
-
-
Save kaosat-dev/7bb1273ddfee9c006611ef652a4c4b1f to your computer and use it in GitHub Desktop.
Laying out the differences (pun intended) between boolean difference & the proposed 'negate()/negative()' operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with difference only, assuming that the details of partWithCuts are known (otherwise it cannot work) | |
const partWithCuts = () => { | |
const block = cube() | |
const cutOut = cylinder() | |
const cutOut2 = cylinder() | |
// not useable, information about cut is lost | |
// return difference(block, cutOut, cutout2) | |
return {keep: [block], remove: [cutOut, cutOut2]} | |
} | |
const main = () => { | |
const somePart = cube() | |
const pwc = partWithCuts() | |
let tmpResult = somePart | |
// ugh | |
if('keep' in pwc){ | |
tmpResult = union(tmpResult, pwc.keep) | |
} | |
if('remove' in pwc){ | |
tmpResult = difference(tmpResult, pwc.remove) | |
} | |
return tmpResult | |
} | |
///////////////////////////////////////////////////////////////////////// | |
// with negate, works even when assuming that the details of partWithCuts are not known ! | |
const partWithCuts = () => { | |
const block = cube() | |
const cutOut = negate(cylinder()) | |
const cutOut2 = negate(cylinder()) | |
return [union(block, cutOutn cutOut2), cutOut, cutOut2]// negativity is baked in (no jokes :) | |
// this also would work, but has a slightly different meaning/ implication | |
return [block, cutOut, cutOut2] | |
} | |
const main = () => { | |
const somePart = cube() | |
const pwc = toArray(partWithCuts())// toArray to ensure array/iterable data | |
return union(somePart, pwc) | |
// if we want to reuse the cutouts to the next , higher scope we could do: | |
return [union(somePart, pwc), pwc.filter(x => isNegative(x)] | |
} | |
// with negate & nested parts | |
const partWithCuts = () => { | |
const block = cube() | |
const cutOut = negate(cylinder()) | |
const cutOut2 = negate(cylinder()) | |
return [union(block, cutOutn cutOut2), cutOut, cutOut2]// negativity is baked in (no jokes :) | |
// this also would work, but has a slightly different meaning/ implication | |
return [block, cutOut, cutOut2] | |
} | |
const nestedPart = () => { | |
const pwc = toArray(partWithCuts())// toArray to ensure array/iterable data | |
const someStuff = cube() | |
return [union(somePart, pwc), pwc.filter(x => isNegative(x)] // we just return the cutouts | |
} | |
const main = () => { | |
const somePart = cube() | |
const nested = toArray(nestedPart())// toArray to ensure array/iterable data | |
return union(somePart, nested) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment