mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Clean up boolean code comments a bit.
This commit is contained in:
parent
4a10fe33d3
commit
1132de0415
1 changed files with 8 additions and 7 deletions
|
@ -26,11 +26,17 @@
|
||||||
* http://hkrish.com/playground/paperjs/booleanStudy.html
|
* http://hkrish.com/playground/paperjs/booleanStudy.html
|
||||||
*/
|
*/
|
||||||
PathItem.inject(new function() {
|
PathItem.inject(new function() {
|
||||||
|
// Set up lookup tables for each operator, to decide if a given segment is
|
||||||
|
// to be considered a part of the solution, or to be discarded, based on its
|
||||||
|
// winding contribution, as calculated by propagateWinding().
|
||||||
|
// Boolean operators return true if a segment with the given winding
|
||||||
|
// contribution contributes to the final result or not. They are applied to
|
||||||
|
// for each segment after the paths are split at crossings.
|
||||||
var operators = {
|
var operators = {
|
||||||
unite: { 0: true, 1: true },
|
unite: { 0: true, 1: true },
|
||||||
intersect: { 2: true },
|
intersect: { 2: true },
|
||||||
subtract: { 1: true },
|
subtract: { 1: true },
|
||||||
exclude: { 1 : true }
|
exclude: { 1: true }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -60,10 +66,6 @@ PathItem.inject(new function() {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boolean operators return true if a curve with the given winding
|
|
||||||
// contribution contributes to the final result or not. They are called
|
|
||||||
// for each curve in the graph after curves in the operands are
|
|
||||||
// split at crossings.
|
|
||||||
function computeBoolean(path1, path2, operation) {
|
function computeBoolean(path1, path2, operation) {
|
||||||
// If path1 is open, delegate to computeOpenBoolean()
|
// If path1 is open, delegate to computeOpenBoolean()
|
||||||
if (!path1._children && !path1._closed)
|
if (!path1._children && !path1._closed)
|
||||||
|
@ -74,8 +76,7 @@ PathItem.inject(new function() {
|
||||||
// i.e. subtraction(A:Path, B:Path):CompoundPath etc.
|
// i.e. subtraction(A:Path, B:Path):CompoundPath etc.
|
||||||
var _path1 = preparePath(path1, true),
|
var _path1 = preparePath(path1, true),
|
||||||
_path2 = path2 && path1 !== path2 && preparePath(path2, true),
|
_path2 = path2 && path1 !== path2 && preparePath(path2, true),
|
||||||
// Retrieve the operator lookup table to decide if a given winding
|
// Retrieve the operator lookup table for winding numbers.
|
||||||
// number is to be considered part of the solution.
|
|
||||||
lookup = operators[operation],
|
lookup = operators[operation],
|
||||||
// Create the operator structure, holding the lookup table and a
|
// Create the operator structure, holding the lookup table and a
|
||||||
// simple boolean check for an operation, e.g. `if (operator.unite)`
|
// simple boolean check for an operation, e.g. `if (operator.unite)`
|
||||||
|
|
Loading…
Reference in a new issue