mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-08-28 22:08:54 -04:00
Fix issue introduced in 0ce89fa47c
This commit is contained in:
parent
3e49e3a5f1
commit
f4baf690f8
2 changed files with 61 additions and 55 deletions
|
@ -1037,7 +1037,14 @@ new function() { // Scope for methods that require numerical integration
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, new function() { // Scope for intersection using bezier fat-line clipping
|
}, new function() { // Scope for intersection using bezier fat-line clipping
|
||||||
function addCurveIntersections(v1, v2, curve1, curve2, locations,
|
function addLocation(locations, include, curve1, t1, point1, curve2, t2,
|
||||||
|
point2) {
|
||||||
|
var loc = new CurveLocation(curve1, t1, point1, curve2, t2, point2);
|
||||||
|
if (!include || include(loc))
|
||||||
|
locations.push(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCurveIntersections(v1, v2, curve1, curve2, locations, include,
|
||||||
tMin, tMax, uMin, uMax, oldTDiff, reverse, recursion) {
|
tMin, tMax, uMin, uMax, oldTDiff, reverse, recursion) {
|
||||||
/*#*/ if (__options.fatline) {
|
/*#*/ if (__options.fatline) {
|
||||||
// Avoid deeper recursion.
|
// Avoid deeper recursion.
|
||||||
|
@ -1098,16 +1105,20 @@ new function() { // Scope for methods that require numerical integration
|
||||||
if (tMaxNew - tMinNew > uMax - uMin) {
|
if (tMaxNew - tMinNew > uMax - uMin) {
|
||||||
var parts = Curve.subdivide(v1, 0.5),
|
var parts = Curve.subdivide(v1, 0.5),
|
||||||
t = tMinNew + (tMaxNew - tMinNew) / 2;
|
t = tMinNew + (tMaxNew - tMinNew) / 2;
|
||||||
addCurveIntersections(v2, parts[0], curve2, curve1, locations,
|
addCurveIntersections(
|
||||||
|
v2, parts[0], curve2, curve1, locations, include,
|
||||||
uMin, uMax, tMinNew, t, tDiff, !reverse, ++recursion);
|
uMin, uMax, tMinNew, t, tDiff, !reverse, ++recursion);
|
||||||
addCurveIntersections(v2, parts[1], curve2, curve1, locations,
|
addCurveIntersections(
|
||||||
|
v2, parts[1], curve2, curve1, locations, include,
|
||||||
uMin, uMax, t, tMaxNew, tDiff, !reverse, recursion);
|
uMin, uMax, t, tMaxNew, tDiff, !reverse, recursion);
|
||||||
} else {
|
} else {
|
||||||
var parts = Curve.subdivide(v2, 0.5),
|
var parts = Curve.subdivide(v2, 0.5),
|
||||||
t = uMin + (uMax - uMin) / 2;
|
t = uMin + (uMax - uMin) / 2;
|
||||||
addCurveIntersections(parts[0], v1, curve2, curve1, locations,
|
addCurveIntersections(
|
||||||
|
parts[0], v1, curve2, curve1, locations, include,
|
||||||
uMin, t, tMinNew, tMaxNew, tDiff, !reverse, ++recursion);
|
uMin, t, tMinNew, tMaxNew, tDiff, !reverse, ++recursion);
|
||||||
addCurveIntersections(parts[1], v1, curve2, curve1, locations,
|
addCurveIntersections(
|
||||||
|
parts[1], v1, curve2, curve1, locations, include,
|
||||||
t, uMax, tMinNew, tMaxNew, tDiff, !reverse, recursion);
|
t, uMax, tMinNew, tMaxNew, tDiff, !reverse, recursion);
|
||||||
}
|
}
|
||||||
} else if (Math.max(uMax - uMin, tMaxNew - tMinNew) < tolerance) {
|
} else if (Math.max(uMax - uMin, tMaxNew - tMinNew) < tolerance) {
|
||||||
|
@ -1115,16 +1126,16 @@ new function() { // Scope for methods that require numerical integration
|
||||||
var t1 = tMinNew + (tMaxNew - tMinNew) / 2,
|
var t1 = tMinNew + (tMaxNew - tMinNew) / 2,
|
||||||
t2 = uMin + (uMax - uMin) / 2;
|
t2 = uMin + (uMax - uMin) / 2;
|
||||||
if (reverse) {
|
if (reverse) {
|
||||||
locations.push(new CurveLocation(
|
addLocation(locations, include,
|
||||||
curve2, t2, Curve.evaluate(v2, t2, 0),
|
curve2, t2, Curve.evaluate(v2, t2, 0),
|
||||||
curve1, t1, Curve.evaluate(v1, t1, 0)));
|
curve1, t1, Curve.evaluate(v1, t1, 0));
|
||||||
} else {
|
} else {
|
||||||
locations.push(new CurveLocation(
|
addLocation(locations, include,
|
||||||
curve1, t1, Curve.evaluate(v1, t1, 0),
|
curve1, t1, Curve.evaluate(v1, t1, 0),
|
||||||
curve2, t2, Curve.evaluate(v2, t2, 0)));
|
curve2, t2, Curve.evaluate(v2, t2, 0));
|
||||||
}
|
}
|
||||||
} else { // Iterate
|
} else { // Iterate
|
||||||
addCurveIntersections(v2, v1, curve2, curve1, locations,
|
addCurveIntersections(v2, v1, curve2, curve1, locations, include,
|
||||||
uMin, uMax, tMinNew, tMaxNew, tDiff, !reverse, ++recursion);
|
uMin, uMax, tMinNew, tMaxNew, tDiff, !reverse, ++recursion);
|
||||||
}
|
}
|
||||||
/*#*/ } else { // !__options.fatline
|
/*#*/ } else { // !__options.fatline
|
||||||
|
@ -1140,8 +1151,7 @@ new function() { // Scope for methods that require numerical integration
|
||||||
if ((Curve.isLinear(v1) || Curve.isFlatEnough(v1, tolerance))
|
if ((Curve.isLinear(v1) || Curve.isFlatEnough(v1, tolerance))
|
||||||
&& (Curve.isLinear(v2) || Curve.isFlatEnough(v2, tolerance))) {
|
&& (Curve.isLinear(v2) || Curve.isFlatEnough(v2, tolerance))) {
|
||||||
// See if the parametric equations of the lines interesct.
|
// See if the parametric equations of the lines interesct.
|
||||||
addLineIntersection(v1, v2, curve1, curve2, locations,
|
addLineIntersection(v1, v2, curve1, curve2, locations, include);
|
||||||
tMin, tMax, uMin, uMax);
|
|
||||||
} else {
|
} else {
|
||||||
// Subdivide both curves, and see if they intersect.
|
// Subdivide both curves, and see if they intersect.
|
||||||
// If one of the curves is flat already, no further subdivion
|
// If one of the curves is flat already, no further subdivion
|
||||||
|
@ -1150,11 +1160,10 @@ new function() { // Scope for methods that require numerical integration
|
||||||
v2s = Curve.subdivide(v2);
|
v2s = Curve.subdivide(v2);
|
||||||
for (var i = 0; i < 2; i++)
|
for (var i = 0; i < 2; i++)
|
||||||
for (var j = 0; j < 2; j++)
|
for (var j = 0; j < 2; j++)
|
||||||
Curve.getIntersections(v1s[i], v2s[j], curve1, curve2,
|
addCurveIntersections(v1s[i], v2s[j], curve1, curve2,
|
||||||
locations, tMin, tMax, uMin, uMax);
|
locations, include);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return locations;
|
|
||||||
/*#*/ } // !__options.fatline
|
/*#*/ } // !__options.fatline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1281,7 +1290,7 @@ new function() { // Scope for methods that require numerical integration
|
||||||
* and the curve.
|
* and the curve.
|
||||||
*/
|
*/
|
||||||
function addCurveLineIntersections(v1, v2, curve1, curve2, locations,
|
function addCurveLineIntersections(v1, v2, curve1, curve2, locations,
|
||||||
tMin, tMax, uMin, uMax) {
|
include) {
|
||||||
var flip = Curve.isLinear(v1),
|
var flip = Curve.isLinear(v1),
|
||||||
vc = flip ? v2 : v1,
|
vc = flip ? v2 : v1,
|
||||||
vl = flip ? v1 : v2,
|
vl = flip ? v1 : v2,
|
||||||
|
@ -1321,28 +1330,25 @@ new function() { // Scope for methods that require numerical integration
|
||||||
var tl = Curve.getParameterOf(rvl, x, 0),
|
var tl = Curve.getParameterOf(rvl, x, 0),
|
||||||
t1 = flip ? tl : tc,
|
t1 = flip ? tl : tc,
|
||||||
t2 = flip ? tc : tl;
|
t2 = flip ? tc : tl;
|
||||||
if (t1 >= tMin && t1 <= tMax && t2 >= uMin && t2 <= uMax)
|
addLocation(locations, include,
|
||||||
locations.push(new CurveLocation(
|
|
||||||
curve1, t1, Curve.evaluate(v1, t1, 0),
|
curve1, t1, Curve.evaluate(v1, t1, 0),
|
||||||
curve2, t2, Curve.evaluate(v2, t2, 0)));
|
curve2, t2, Curve.evaluate(v2, t2, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLineIntersection(v1, v2, curve1, curve2, locations,
|
function addLineIntersection(v1, v2, curve1, curve2, locations, include) {
|
||||||
tMin, tMax, uMin, uMax) {
|
|
||||||
var point = Line.intersect(
|
var point = Line.intersect(
|
||||||
v1[0], v1[1], v1[6], v1[7],
|
v1[0], v1[1], v1[6], v1[7],
|
||||||
v2[0], v2[1], v2[6], v2[7]);
|
v2[0], v2[1], v2[6], v2[7]);
|
||||||
if (point){
|
if (point) {
|
||||||
// We need to return the parameters for the intersection,
|
// We need to return the parameters for the intersection,
|
||||||
// since they will be used for sorting
|
// since they will be used for sorting
|
||||||
var t1 = Curve.getParameterOf(v1, point.x, point.y),
|
var t1 = Curve.getParameterOf(v1, point.x, point.y),
|
||||||
t2 = Curve.getParameterOf(v2, point.x, point.y);
|
t2 = Curve.getParameterOf(v2, point.x, point.y);
|
||||||
if (t1 >= tMin && t1 <= tMax && t2 >= uMin && t2 <= uMax)
|
addLocation(locations, include,
|
||||||
locations.push(new CurveLocation(
|
|
||||||
curve1, t1, point,
|
curve1, t1, point,
|
||||||
curve2, t2, point));
|
curve2, t2, point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1350,21 +1356,19 @@ new function() { // Scope for methods that require numerical integration
|
||||||
// We need to provide the original left curve reference to the
|
// We need to provide the original left curve reference to the
|
||||||
// #getIntersections() calls as it is required to create the resulting
|
// #getIntersections() calls as it is required to create the resulting
|
||||||
// CurveLocation objects.
|
// CurveLocation objects.
|
||||||
getIntersections: function(v1, v2, curve1, curve2, locations,
|
getIntersections: function(v1, v2, curve1, curve2, locations, include) {
|
||||||
tMin, tMax, uMin, uMax) {
|
|
||||||
var linear1 = Curve.isLinear(v1),
|
var linear1 = Curve.isLinear(v1),
|
||||||
linear2 = Curve.isLinear(v2);
|
linear2 = Curve.isLinear(v2);
|
||||||
(linear1 && linear2
|
(linear1 && linear2
|
||||||
? addLineIntersection
|
? addLineIntersection
|
||||||
: linear1 || linear2
|
: linear1 || linear2
|
||||||
? addCurveLineIntersections
|
? addCurveLineIntersections
|
||||||
: addCurveIntersections)(v1, v2, curve1, curve2, locations,
|
: addCurveIntersections)(
|
||||||
|
v1, v2, curve1, curve2, locations, include,
|
||||||
// Define the defaults for these parameters of
|
// Define the defaults for these parameters of
|
||||||
// addCurveIntersections():
|
// addCurveIntersections():
|
||||||
// tMin, tMax, uMin, uMax
|
// tMin, tMax, uMin, uMax, oldTDiff, reverse, recursion
|
||||||
tMin || 0, tMax || 1, uMin || 0, uMax || 1,
|
0, 1, 0, 1, 0, false, 0);
|
||||||
// oldTDiff, reverse, recursion
|
|
||||||
0, false, 0);
|
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
|
|
|
@ -102,32 +102,34 @@ var PathItem = Item.extend(/** @lends PathItem# */{
|
||||||
h2.multiply(2), true), false)) {
|
h2.multiply(2), true), false)) {
|
||||||
// Self intersectin is found by dividng the curve in two and
|
// Self intersectin is found by dividng the curve in two and
|
||||||
// and then applying the normal curve intersection code.
|
// and then applying the normal curve intersection code.
|
||||||
var parts = Curve.subdivide(values1),
|
var parts = Curve.subdivide(values1);
|
||||||
before = locations.length;
|
Curve.getIntersections(
|
||||||
Curve.getIntersections(parts[0], parts[1], curve1, curve1,
|
parts[0], parts[1], curve1, curve1, locations,
|
||||||
locations, 0, MAX); // tMax
|
function(loc) {
|
||||||
// Check if a location was added by comparing length before.
|
if (loc._parameter <= MAX) {
|
||||||
// Self-intersection can only lead to 0 or 1 intersections.
|
// Since the curve was split above, we need to
|
||||||
if (locations.length > before) {
|
// adjust the parameters for both locations.
|
||||||
var loc = locations[before];
|
|
||||||
// Since the curve was split above, we need to adjust
|
|
||||||
// the parameters for both locations.
|
|
||||||
loc._parameter /= 2;
|
loc._parameter /= 2;
|
||||||
loc._parameter2 = 0.5 + loc._parameter2 / 2;
|
loc._parameter2 = 0.5 + loc._parameter2 / 2;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Check for intersections with other curves. For self intersection,
|
// Check for intersections with other curves. For self intersection,
|
||||||
// we can start at i + 1 instead of 0
|
// we can start at i + 1 instead of 0
|
||||||
for (var j = path ? 0 : i + 1; j < length2; j++) {
|
for (var j = path ? 0 : i + 1; j < length2; j++) {
|
||||||
// Avoid end point intersections on consecutive curves whe self
|
Curve.getIntersections(
|
||||||
// intersecting.
|
values1, values2[j], curve1, curves2[j], locations,
|
||||||
var excludeEnds = !path
|
// Avoid end point intersections on consecutive curves whe
|
||||||
&& (j === i + 1 || j === length2 - 1 && i === 0);
|
// self intersecting.
|
||||||
Curve.getIntersections(values1, values2[j], curve1,
|
!path && (j === i + 1 || j === length2 - 1 && i === 0)
|
||||||
curves2[j], locations,
|
&& function(loc) {
|
||||||
excludeEnds ? MIN : 0, // tMin
|
var t = loc._parameter;
|
||||||
excludeEnds ? MAX : 1); // tMax
|
return t >= MIN && t <= MAX;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now filter the locations and process _expand:
|
// Now filter the locations and process _expand:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue