Move #getInteriorPoint() to PathItem, and refactor it a bit more.

This commit is contained in:
Jürg Lehni 2016-07-17 23:04:42 +02:00
parent ac97b9d9d7
commit e94e872cda

View file

@ -1024,9 +1024,7 @@ PathItem.inject(new function() {
return item; return item;
} }
}; };
}); }, /** @lends PathItem# */{
Path.inject(/** @lends Path# */{
/** /**
* Returns a point that is guaranteed to be inside the path. * Returns a point that is guaranteed to be inside the path.
* *
@ -1052,23 +1050,23 @@ Path.inject(/** @lends Path# */{
o1 = v[3], o1 = v[3],
o2 = v[5], o2 = v[5],
o3 = v[7]; o3 = v[7];
if ((o0 <= y || o1 <= y || o2 <= y || o3 <= y) && if (y >= Math.min(o0, o1, o2, o3) &&
(o0 >= y || o1 >= y || o2 >= y || o3 >= y)) { y <= Math.max(o0, o1, o2, o3)) {
var monos = Curve.getMonoCurves(v); var monos = Curve.getMonoCurves(v);
for (var j = 0, m = monos.length; j < m; j++) { for (var j = 0, m = monos.length; j < m; j++) {
var m = monos[j], var mv = monos[j],
mo0 = m[1], mo0 = mv[1],
mo3 = m[7]; mo3 = mv[7];
// Filter out horizontal monotone curves by comparing // Filter out horizontal monotone curves by comparing
// their ordinate values, and make sure the y coordinate // their ordinate values, and make sure the y coordinate
// is within the curve before testing for intercepts. // is within the curve before testing for intercepts.
if ((mo0 !== mo3) && if ((mo0 !== mo3) &&
(y >= mo0 && y <= mo3 || y >= mo3 && y <= mo0)) { (y >= mo0 && y <= mo3 || y >= mo3 && y <= mo0)) {
var x = y === mo0 ? m[0] var x = y === mo0 ? mv[0]
: y === mo3 ? m[6] : y === mo3 ? mv[6]
: Curve.solveCubic(m, 1, y, roots, 0, 1) === 1 : Curve.solveCubic(mv, 1, y, roots, 0, 1) === 1
? Curve.getPoint(m, roots[0]).x ? Curve.getPoint(mv, roots[0]).x
: (m[0] + m[6]) / 2; : (mv[0] + mv[6]) / 2;
intercepts.push(x); intercepts.push(x);
} }
} }