mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Some more minor tweaks.
This commit is contained in:
parent
1e8947af63
commit
3ab20ea3e9
1 changed files with 21 additions and 21 deletions
|
@ -101,17 +101,17 @@ PathItem.inject(new function() {
|
||||||
// We do not modify the operands themselves
|
// We do not modify the operands themselves
|
||||||
// The result might not belong to the same type
|
// The result might not belong to the same type
|
||||||
// i.e. subtraction(A:Path, B:Path):CompoundPath etc.
|
// i.e. subtraction(A:Path, B:Path):CompoundPath etc.
|
||||||
var _path1 = reorientPath(path1.clone()),
|
path1 = reorientPath(path1.clone());
|
||||||
_path2 = reorientPath(path2.clone()),
|
path2 = reorientPath(path2.clone());
|
||||||
path1Clockwise = _path1.isClockwise(),
|
var path1Clockwise = path1.isClockwise(),
|
||||||
path2Clockwise = _path2.isClockwise(),
|
path2Clockwise = path2.isClockwise(),
|
||||||
// Calculate all the intersections
|
// Calculate all the intersections
|
||||||
intersections = _cache && _cache.intersections
|
intersections = _cache && _cache.intersections
|
||||||
|| _path1.getIntersections(_path2);
|
|| path1.getIntersections(path2);
|
||||||
// if we have a empty _cache object as an operand, skip calculating
|
// if we have a empty _cache object as an operand, skip calculating
|
||||||
// boolean and cache the intersections
|
// boolean and cache the intersections
|
||||||
// if (_cache && !_cache.intersections) {
|
// if (_cache && !_cache.intersections) {
|
||||||
// // TODO: Don't we need to clear up and remove _path1 & _path2 again?
|
// // TODO: Don't we need to clear up and remove path1 & path2 again?
|
||||||
// return _cache.intersections = intersections;
|
// return _cache.intersections = intersections;
|
||||||
// }
|
// }
|
||||||
// Now split intersections on both curves, by asking the first call to
|
// Now split intersections on both curves, by asking the first call to
|
||||||
|
@ -120,12 +120,12 @@ PathItem.inject(new function() {
|
||||||
splitPath(splitPath(intersections, true));
|
splitPath(splitPath(intersections, true));
|
||||||
// Do operator specific calculations before we begin
|
// Do operator specific calculations before we begin
|
||||||
if (subtract) {
|
if (subtract) {
|
||||||
_path2.reverse();
|
path2.reverse();
|
||||||
path2Clockwise = !path2Clockwise;
|
path2Clockwise = !path2Clockwise;
|
||||||
}
|
}
|
||||||
var paths = []
|
var paths = []
|
||||||
.concat(_path1._children || [_path1])
|
.concat(path1._children || [path1])
|
||||||
.concat(_path2._children || [_path2]),
|
.concat(path2._children || [path2]),
|
||||||
segments = [],
|
segments = [],
|
||||||
result = new CompoundPath();
|
result = new CompoundPath();
|
||||||
// Step 1: Discard invalid links according to the boolean operator
|
// Step 1: Discard invalid links according to the boolean operator
|
||||||
|
@ -138,13 +138,13 @@ PathItem.inject(new function() {
|
||||||
for (var j = segs.length - 1; j >= 0; j--) {
|
for (var j = segs.length - 1; j >= 0; j--) {
|
||||||
var segment = segs[j],
|
var segment = segs[j],
|
||||||
midPoint = segment.getCurve().getPoint(0.5),
|
midPoint = segment.getCurve().getPoint(0.5),
|
||||||
insidePath1 = path !== _path1 && _path1.contains(midPoint)
|
insidePath1 = path !== path1 && path1.contains(midPoint)
|
||||||
&& (clockwise === path1Clockwise || subtract
|
&& (clockwise === path1Clockwise || subtract
|
||||||
|| !testOnCurve(_path1, midPoint)),
|
|| !testOnCurve(path1, midPoint)),
|
||||||
insidePath2 = path !== _path2 && _path2.contains(midPoint)
|
insidePath2 = path !== path2 && path2.contains(midPoint)
|
||||||
&& (clockwise === path2Clockwise
|
&& (clockwise === path2Clockwise
|
||||||
|| !testOnCurve(_path2, midPoint));
|
|| !testOnCurve(path2, midPoint));
|
||||||
if (operator(path === _path1, insidePath1, insidePath2)) {
|
if (operator(path === path1, insidePath1, insidePath2)) {
|
||||||
// Mark as invalid, but do not remove yet, so the graph
|
// Mark as invalid, but do not remove yet, so the graph
|
||||||
// structure is preserved.
|
// structure is preserved.
|
||||||
segment._invalid = true;
|
segment._invalid = true;
|
||||||
|
@ -165,12 +165,12 @@ PathItem.inject(new function() {
|
||||||
segment.setHandleIn(last ? last._handleIn : Point.create(0, 0));
|
segment.setHandleIn(last ? last._handleIn : Point.create(0, 0));
|
||||||
do {
|
do {
|
||||||
segment._visited = true;
|
segment._visited = true;
|
||||||
if (segment._intersection && segment._invalid) {
|
if (segment._invalid && segment._intersection) {
|
||||||
var next = segment._intersection.getSegment(true);
|
var other = segment._intersection.getSegment(true);
|
||||||
path.add(new Segment(segment._point, segment._handleIn,
|
path.add(new Segment(segment._point, segment._handleIn,
|
||||||
next._handleOut));
|
other._handleOut));
|
||||||
next._visited = true;
|
other._visited = true;
|
||||||
segment = next;
|
segment = other;
|
||||||
} else {
|
} else {
|
||||||
path.add(segment.clone());
|
path.add(segment.clone());
|
||||||
}
|
}
|
||||||
|
@ -185,8 +185,8 @@ PathItem.inject(new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Delete the proxies
|
// Delete the proxies
|
||||||
_path1.remove();
|
path1.remove();
|
||||||
_path2.remove();
|
path2.remove();
|
||||||
// And then, we are done.
|
// And then, we are done.
|
||||||
return result.reduce();
|
return result.reduce();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue