mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Boolean: Fix sort function to produce correct resutls on all browsers.
This commit is contained in:
parent
0b672cfb62
commit
2c8f4f9453
2 changed files with 24 additions and 14 deletions
|
@ -563,13 +563,13 @@ new function() { // Scope for statics
|
||||||
path2 = loc2.getPath(),
|
path2 = loc2.getPath(),
|
||||||
// NOTE: equals() takes the intersection location into account,
|
// NOTE: equals() takes the intersection location into account,
|
||||||
// while this calculation of diff doesn't!
|
// while this calculation of diff doesn't!
|
||||||
diff = path1 === path2
|
diff = path1 !== path2
|
||||||
//Sort by both index and time. The two values added
|
|
||||||
// together provides a convenient sorting index.
|
|
||||||
? (loc.getIndex() + loc.getTime())
|
|
||||||
- (loc2.getIndex() + loc2.getTime())
|
|
||||||
// Sort by path id to group all locs on same path.
|
// Sort by path id to group all locs on same path.
|
||||||
: path1._id - path2._id;
|
? path1._id - path2._id
|
||||||
|
// Sort by both index and time on the same path. The two values
|
||||||
|
// added together provides a convenient sorting index.
|
||||||
|
: (loc.getIndex() + loc.getTime())
|
||||||
|
- (loc2.getIndex() + loc2.getTime());
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
r = m - 1;
|
r = m - 1;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -633,15 +633,25 @@ PathItem.inject(new function() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort segments to give non-ambiguous segments the preference as
|
// Sort segments to give non-overlapping segments the preference as
|
||||||
// starting points when tracing: prefer segments with no intersections
|
// starting points when tracing.
|
||||||
// over intersections, and process intersections with overlaps last:
|
|
||||||
segments.sort(function(a, b) {
|
segments.sort(function(a, b) {
|
||||||
var i1 = a._intersection,
|
var path1 = a._path,
|
||||||
i2 = b._intersection,
|
path2 = b._path,
|
||||||
o1 = !!(i1 && i1._overlap),
|
inter1 = a._intersection,
|
||||||
o2 = !!(i2 && i2._overlap);
|
inter2 = b._intersection,
|
||||||
return !i1 && !i2 ? -1 : o1 ^ o2 ? o1 ? 1 : -1 : 0;
|
over1 = !!(inter1 && inter1._overlap),
|
||||||
|
over2 = !!(inter2 && inter2._overlap);
|
||||||
|
return path1 !== path2
|
||||||
|
// Sort by path id to group all segments on same path.
|
||||||
|
? path1._id - path2._id
|
||||||
|
// If only one of the two segments on the same path is an
|
||||||
|
// overlap, sort it so it comes after the other.
|
||||||
|
: over1 ^ over2
|
||||||
|
? over1 ? 1 : -1
|
||||||
|
// All other segments, intersection or not, are sorted
|
||||||
|
// by their natural order within the path.
|
||||||
|
: a._index - b._index;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i = 0, l = segments.length; i < l; i++) {
|
for (var i = 0, l = segments.length; i < l; i++) {
|
||||||
|
|
Loading…
Reference in a new issue