mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Implement simplification of #getInteriorPoint()
As suggested by @iconexperience in https://github.com/paperjs/paper.js/issues/1075#issuecomment-233196940
This commit is contained in:
parent
4bb2f7a8fc
commit
fc18f821b1
1 changed files with 4 additions and 13 deletions
|
@ -1045,8 +1045,7 @@ Path.inject(/** @lends Path# */{
|
||||||
y = point.y,
|
y = point.y,
|
||||||
intercepts = [],
|
intercepts = [],
|
||||||
monoCurves = [],
|
monoCurves = [],
|
||||||
roots = [],
|
roots = [];
|
||||||
windingPrev = 0;
|
|
||||||
// Get values for all y-monotone curves that intersect the ray at y.
|
// Get values for all y-monotone curves that intersect the ray at y.
|
||||||
for (var i = 0, l = curves.length; i < l; i++) {
|
for (var i = 0, l = curves.length; i < l; i++) {
|
||||||
var v = curves[i].getValues(),
|
var v = curves[i].getValues(),
|
||||||
|
@ -1064,11 +1063,7 @@ Path.inject(/** @lends Path# */{
|
||||||
if (y >= mo0 && y <= mo3 || y >= mo3 && y <= mo0) {
|
if (y >= mo0 && y <= mo3 || y >= mo3 && y <= mo0) {
|
||||||
var winding = mo0 > mo3 ? 1 : mo0 < mo3 ? -1 : 0;
|
var winding = mo0 > mo3 ? 1 : mo0 < mo3 ? -1 : 0;
|
||||||
if (winding) {
|
if (winding) {
|
||||||
monoCurves.push({
|
monoCurves.push(mono);
|
||||||
values: mono,
|
|
||||||
winding: winding
|
|
||||||
});
|
|
||||||
windingPrev = winding;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1078,17 +1073,13 @@ Path.inject(/** @lends Path# */{
|
||||||
if (!monoCurves.length)
|
if (!monoCurves.length)
|
||||||
return point;
|
return point;
|
||||||
for (var i = 0, l = monoCurves.length; i < l; i++) {
|
for (var i = 0, l = monoCurves.length; i < l; i++) {
|
||||||
var entry = monoCurves[i],
|
var v = monoCurves[i];
|
||||||
v = entry.values,
|
|
||||||
winding = entry.winding,
|
|
||||||
x = y === v[1] ? v[0]
|
x = y === v[1] ? v[0]
|
||||||
: y === v[7] ? v[6]
|
: y === v[7] ? v[6]
|
||||||
: Curve.solveCubic(v, 1, y, roots, 0, 1) === 1
|
: Curve.solveCubic(v, 1, y, roots, 0, 1) === 1
|
||||||
? Curve.getPoint(v, roots[0]).x
|
? Curve.getPoint(v, roots[0]).x
|
||||||
: (v[0] + v[6]) / 2;
|
: (v[0] + v[6]) / 2;
|
||||||
// if (y != v[1] || winding != windingPrev)
|
intercepts.push(x);
|
||||||
intercepts.push(x);
|
|
||||||
windingPrev = winding;
|
|
||||||
}
|
}
|
||||||
intercepts.sort(function(a, b) {
|
intercepts.sort(function(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
|
|
Loading…
Reference in a new issue