mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 10:48:38 -05:00
Various boolean code clean-ups.
This commit is contained in:
parent
d0332f843f
commit
30f1441c26
3 changed files with 32 additions and 27 deletions
|
@ -1662,7 +1662,7 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
||||||
if (pairs.length === 1 && pair[0] < pairs[0][0]) {
|
if (pairs.length === 1 && pair[0] < pairs[0][0]) {
|
||||||
pairs.unshift(pair);
|
pairs.unshift(pair);
|
||||||
} else if (pairs.length === 0
|
} else if (pairs.length === 0
|
||||||
// TODO: Compare distance of points instead!
|
// TODO: Compare distance of the actual points instead!
|
||||||
|| abs(pair[0] - pairs[0][0]) > timeEpsilon
|
|| abs(pair[0] - pairs[0][0]) > timeEpsilon
|
||||||
|| abs(pair[1] - pairs[0][1]) > timeEpsilon) {
|
|| abs(pair[1] - pairs[0][1]) > timeEpsilon) {
|
||||||
pairs.push(pair);
|
pairs.push(pair);
|
||||||
|
|
|
@ -149,7 +149,7 @@ PathItem.inject(new function() {
|
||||||
path1, path2);
|
path1, path2);
|
||||||
}
|
}
|
||||||
|
|
||||||
var scaleFactor = 0.25; // 1 / 3000;
|
var scaleFactor = 1; // 1 / 3000;
|
||||||
var textAngle = 33;
|
var textAngle = 33;
|
||||||
var fontSize = 5;
|
var fontSize = 5;
|
||||||
|
|
||||||
|
@ -167,12 +167,12 @@ PathItem.inject(new function() {
|
||||||
if (inter._other)
|
if (inter._other)
|
||||||
return;
|
return;
|
||||||
var other = inter._intersection;
|
var other = inter._intersection;
|
||||||
var log = ['CurveLocation', inter._id, 'p', inter.getPath()._id,
|
var log = ['CurveLocation', inter._id, 'id', inter.getPath()._id,
|
||||||
'i', inter.getIndex(), 't', inter._parameter,
|
'i', inter.getIndex(), 't', inter._parameter,
|
||||||
'o', !!inter._overlap,
|
'o', !!inter._overlap, 'p', inter.getPoint(),
|
||||||
'Other', other._id, 'p', other.getPath()._id,
|
'Other', other._id, 'id', other.getPath()._id,
|
||||||
'i', other.getIndex(), 't', other._parameter,
|
'i', other.getIndex(), 't', other._parameter,
|
||||||
'o', !!other._overlap];
|
'o', !!other._overlap, 'p', other.getPoint()];
|
||||||
new Path.Circle({
|
new Path.Circle({
|
||||||
center: inter.point,
|
center: inter.point,
|
||||||
radius: fontSize / 2 * scaleFactor,
|
radius: fontSize / 2 * scaleFactor,
|
||||||
|
@ -189,16 +189,20 @@ PathItem.inject(new function() {
|
||||||
var tMin = /*#=*/Numerical.CURVETIME_EPSILON,
|
var tMin = /*#=*/Numerical.CURVETIME_EPSILON,
|
||||||
tMax = 1 - tMin,
|
tMax = 1 - tMin,
|
||||||
noHandles = false,
|
noHandles = false,
|
||||||
clearSegments = [];
|
clearSegments = [],
|
||||||
|
curve,
|
||||||
|
prev,
|
||||||
|
prevT;
|
||||||
|
|
||||||
for (var i = intersections.length - 1, curve, prev; i >= 0; i--) {
|
for (var i = intersections.length - 1; i >= 0; i--) {
|
||||||
var loc = intersections[i],
|
var loc = intersections[i],
|
||||||
t = loc._parameter;
|
t = loc._parameter,
|
||||||
|
locT = t;
|
||||||
// Check if we are splitting same curve multiple times, but avoid
|
// Check if we are splitting same curve multiple times, but avoid
|
||||||
// dividing with zero.
|
// dividing with zero.
|
||||||
if (prev && prev._curve === loc._curve && prev._parameter > 0) {
|
if (prev && prev._curve === loc._curve && prevT > 0) {
|
||||||
// Scale parameter after previous split.
|
// Scale parameter after previous split.
|
||||||
t /= prev._parameter;
|
t /= prevT;
|
||||||
} else {
|
} else {
|
||||||
curve = loc._curve;
|
curve = loc._curve;
|
||||||
noHandles = !curve.hasHandles();
|
noHandles = !curve.hasHandles();
|
||||||
|
@ -220,10 +224,14 @@ PathItem.inject(new function() {
|
||||||
clearSegments.push(segment);
|
clearSegments.push(segment);
|
||||||
}
|
}
|
||||||
// Link the new segment with the intersection on the other curve
|
// Link the new segment with the intersection on the other curve
|
||||||
|
if (segment._intersection)
|
||||||
|
console.log('Oh dear there was one already: ' + segment._intersection);
|
||||||
segment._intersection = loc._intersection;
|
segment._intersection = loc._intersection;
|
||||||
// loc._setCurve(segment.getCurve());
|
// loc._setCurve(segment.getCurve());
|
||||||
loc._segment = segment;
|
loc._segment = segment;
|
||||||
|
loc._parameter = t;
|
||||||
prev = loc;
|
prev = loc;
|
||||||
|
prevT = locT;
|
||||||
}
|
}
|
||||||
// Clear segment handles if they were part of a curve with no handles,
|
// Clear segment handles if they were part of a curve with no handles,
|
||||||
// once we are done with the entire curve.
|
// once we are done with the entire curve.
|
||||||
|
@ -486,18 +494,15 @@ PathItem.inject(new function() {
|
||||||
labelSegment(seg, '#' + pathCount + '.'
|
labelSegment(seg, '#' + pathCount + '.'
|
||||||
+ (path ? path._segments.length + 1 : 1)
|
+ (path ? path._segments.length + 1 : 1)
|
||||||
+ ' ' + (segmentCount++) + '/' + index + ': ' + text
|
+ ' ' + (segmentCount++) + '/' + index + ': ' + text
|
||||||
+ ' v: ' + !!seg._visited
|
+ ' id: ' + seg._path._id
|
||||||
+ ' p: ' + seg._path._id
|
+ ' v: ' + (seg._visited ? 1 : 0)
|
||||||
+ ' x: ' + seg._point.x
|
+ ' p: ' + seg._point
|
||||||
+ ' y: ' + seg._point.y
|
|
||||||
+ ' op: ' + operator(seg._winding)
|
+ ' op: ' + operator(seg._winding)
|
||||||
+ ' o: ' + (inter && inter._overlap || 0)
|
+ ' ov: ' + (inter && inter._overlap || 0)
|
||||||
+ ' w: ' + seg._winding
|
+ ' wi: ' + seg._winding
|
||||||
, color);
|
, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (var i = 0; i < (window.reportWindings ? segments.length : 0); i++) {
|
for (var i = 0; i < (window.reportWindings ? segments.length : 0); i++) {
|
||||||
var seg = segments[i];
|
var seg = segments[i];
|
||||||
path = seg._path,
|
path = seg._path,
|
||||||
|
@ -509,11 +514,10 @@ PathItem.inject(new function() {
|
||||||
|
|
||||||
labelSegment(seg, '#' + pathIndex + '.' + (i + 1)
|
labelSegment(seg, '#' + pathIndex + '.' + (i + 1)
|
||||||
+ ' i: ' + !!inter
|
+ ' i: ' + !!inter
|
||||||
+ ' p: ' + seg._path._id
|
+ ' id: ' + seg._path._id
|
||||||
+ ' x: ' + seg._point.x
|
+ ' pt: ' + seg._point
|
||||||
+ ' y: ' + seg._point.y
|
+ ' ov: ' + (inter && inter._overlap || 0)
|
||||||
+ ' o: ' + (inter && inter._overlap || 0)
|
+ ' wi: ' + seg._winding
|
||||||
+ ' w: ' + seg._winding
|
|
||||||
, 'green');
|
, 'green');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +564,8 @@ PathItem.inject(new function() {
|
||||||
// We need to handle exclusion separately, as we want to
|
// We need to handle exclusion separately, as we want to
|
||||||
// switch at each crossing, and at each intersection within
|
// switch at each crossing, and at each intersection within
|
||||||
// the exclusion area even if it is not a crossing.
|
// the exclusion area even if it is not a crossing.
|
||||||
if (inter.isCrossing() || path2.contains(seg._point)) {
|
if (inter.isCrossing()
|
||||||
|
|| path2 && path2.contains(seg._point)) {
|
||||||
drawSegment(seg, 'exclude-cross', i, 'green');
|
drawSegment(seg, 'exclude-cross', i, 'green');
|
||||||
seg = other;
|
seg = other;
|
||||||
} else {
|
} else {
|
||||||
|
@ -593,7 +598,7 @@ PathItem.inject(new function() {
|
||||||
seg = seg.getNext();
|
seg = seg.getNext();
|
||||||
inter = seg && seg._intersection;
|
inter = seg && seg._intersection;
|
||||||
other = inter && inter._segment;
|
other = inter && inter._segment;
|
||||||
if (seg === start || seg === otherStart) {
|
if (seg === start || seg === otherStart) {
|
||||||
drawSegment(seg, 'close', i, 'red');
|
drawSegment(seg, 'close', i, 'red');
|
||||||
}
|
}
|
||||||
if (seg._visited && (!other || other._visited)) {
|
if (seg._visited && (!other || other._visited)) {
|
||||||
|
|
|
@ -286,7 +286,7 @@ function asyncTest(testName, expected) {
|
||||||
var project = new Project();
|
var project = new Project();
|
||||||
expected(function() {
|
expected(function() {
|
||||||
project.remove();
|
project.remove();
|
||||||
start();
|
QUnit.start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue