mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge upstream
This commit is contained in:
commit
debce28bc4
2 changed files with 33 additions and 22 deletions
|
@ -716,7 +716,9 @@ statics: {
|
|||
// We need to provide the original left curve reference to the
|
||||
// #getIntersections() calls as it is required to create the resulting
|
||||
// CurveLocation objects.
|
||||
getIntersections: function(v1, v2, curve1, curve2, locations) {
|
||||
getIntersections: function(v1, v2, curve1, curve2, locations,
|
||||
// Pass on isFlat1 / isFlat2 parameters in iterative calls
|
||||
isFlat1, isFlat2) {
|
||||
var bounds1 = this.getBounds(v1),
|
||||
bounds2 = this.getBounds(v2);
|
||||
/*#*/ if (options.debug) {
|
||||
|
@ -734,10 +736,15 @@ statics: {
|
|||
if (bounds1.touches(bounds2)) {
|
||||
// See if both curves are flat enough to be treated as lines, either
|
||||
// because they have no control points at all, or are "flat enough"
|
||||
if ((this.isLinear(v1)
|
||||
|| this.isFlatEnough(v1, /*#=*/ Numerical.TOLERANCE))
|
||||
&& (this.isLinear(v2)
|
||||
|| this.isFlatEnough(v2, /*#=*/ Numerical.TOLERANCE))) {
|
||||
// If the curve was flat in a previous iteration, we don't need to
|
||||
// recalculate since it does not need further subdivision then.
|
||||
if (!isFlat1)
|
||||
isFlat1 = this.isLinear(v1)
|
||||
|| this.isFlatEnough(v1, /*#=*/ Numerical.TOLERANCE);
|
||||
if (!isFlat2)
|
||||
isFlat2 = this.isLinear(v2)
|
||||
|| this.isFlatEnough(v2, /*#=*/ Numerical.TOLERANCE);
|
||||
if (isFlat1 && isFlat2) {
|
||||
/*#*/ if (options.debug) {
|
||||
new Path.Line({
|
||||
from: [v1[0], v1[1]],
|
||||
|
@ -769,11 +776,14 @@ statics: {
|
|||
}
|
||||
} else {
|
||||
// Subdivide both curves, and see if they intersect.
|
||||
var v1s = this.subdivide(v1),
|
||||
v2s = this.subdivide(v2);
|
||||
for (var i = 0; i < 2; i++)
|
||||
for (var j = 0; j < 2; j++)
|
||||
this.getIntersections(v1s[i], v2s[j], curve1, curve2, locations);
|
||||
// If one of the curves is flat already, no further subdivion
|
||||
// is required.
|
||||
var v1s = isFlat1 ? [v1] : this.subdivide(v1),
|
||||
v2s = isFlat2 ? [v2] : this.subdivide(v2);
|
||||
for (var i = 0, l = v1s.length; i < l; i++)
|
||||
for (var j = 0, k = v2s.length; j < k; j++)
|
||||
this.getIntersections(v1s[i], v2s[j], curve1, curve2,
|
||||
locations, isFlat1, isFlat2);
|
||||
}
|
||||
}
|
||||
return locations;
|
||||
|
|
|
@ -200,21 +200,21 @@ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
|
|||
var unionOp = function union( isPath1, isInsidePath1, isInsidePath2 ){
|
||||
return ( isInsidePath1 || isInsidePath2 )? false : true;
|
||||
};
|
||||
return computeBoolean( this, path, unionOp, _cache );
|
||||
return this._computeBoolean( this, path, unionOp, _cache );
|
||||
},
|
||||
|
||||
intersect: function( path, _cache ){
|
||||
var intersectionOp = function intersection( isPath1, isInsidePath1, isInsidePath2 ){
|
||||
return ( !isInsidePath1 && !isInsidePath2 )? false : true;
|
||||
};
|
||||
return computeBoolean( this, path, intersectionOp, _cache );
|
||||
return this._computeBoolean( this, path, intersectionOp, _cache );
|
||||
},
|
||||
|
||||
subtract: function( path, _cache ){
|
||||
var subtractionOp = function subtraction( isPath1, isInsidePath1, isInsidePath2 ){
|
||||
return ( (isPath1 && isInsidePath2) || (!isPath1 && !isInsidePath1) )? false : true;
|
||||
};
|
||||
return computeBoolean( this, path, subtractionOp, _cache );
|
||||
return this._computeBoolean( this, path, subtractionOp, _cache );
|
||||
},
|
||||
|
||||
/*
|
||||
|
@ -351,7 +351,7 @@ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
|
|||
return baseWinding;
|
||||
},
|
||||
|
||||
reversePath: function( path ){
|
||||
_reversePath: function( path ){
|
||||
var baseWinding;
|
||||
if( path instanceof CompoundPath ){
|
||||
var children = path.children, i, len;
|
||||
|
@ -378,8 +378,8 @@ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
|
|||
_path2 = path2.clone();
|
||||
_path1.style = _path2.style = null;
|
||||
_path1.selected = _path2.selected = false;
|
||||
path1Clockwise = _reorientCompoundPath( _path1 );
|
||||
path2Clockwise = _reorientCompoundPath( _path2 );
|
||||
path1Clockwise = this._reorientCompoundPath( _path1 );
|
||||
path2Clockwise = this._reorientCompoundPath( _path2 );
|
||||
path1Id = _path1.id;
|
||||
path2Id = _path2.id;
|
||||
// Calculate all the intersections
|
||||
|
@ -391,13 +391,13 @@ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
|
|||
_splitCache.intersections = ixs;
|
||||
return;
|
||||
}
|
||||
_splitPath( ixs );
|
||||
_splitPath( ixs, true );
|
||||
this._splitPath( ixs );
|
||||
this._splitPath( ixs, true );
|
||||
path1Id = _path1.id;
|
||||
path2Id = _path2.id;
|
||||
// Do operator specific calculations before we begin
|
||||
if( operator.name === "subtraction" ) {
|
||||
path2Clockwise = _reversePath( _path2 );
|
||||
path2Clockwise = this._reversePath( _path2 );
|
||||
}
|
||||
|
||||
var i, j, len, path, crv;
|
||||
|
@ -428,14 +428,15 @@ var PathItem = this.PathItem = Item.extend(/** @lends PathItem# */{
|
|||
crv = nextNode.curve;
|
||||
midPoint = crv.getPoint( 0.5 );
|
||||
if( thisId !== path1Id ){
|
||||
contains = _path1.contains( midPoint );
|
||||
contains = _path1.
|
||||
contains( midPoint );
|
||||
insidePath1 = (thisWinding === path1Clockwise || subtractionOp )? contains :
|
||||
contains && !_testOnCurve( _path1, midPoint );
|
||||
contains && !this._testOnCurve( _path1, midPoint );
|
||||
}
|
||||
if( thisId !== path2Id ){
|
||||
contains = _path2.contains( midPoint );
|
||||
insidePath2 = (thisWinding === path2Clockwise )? contains :
|
||||
contains && !_testOnCurve( _path2, midPoint );
|
||||
contains && !this._testOnCurve( _path2, midPoint );
|
||||
}
|
||||
if( !operator( thisId === path1Id, insidePath1, insidePath2 ) ){
|
||||
crv._INVALID = true;
|
||||
|
|
Loading…
Reference in a new issue