mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Implement Segment#isSmooth() and use it in handling of stroke-joins.
This commit is contained in:
parent
f19a50093b
commit
919c42af27
2 changed files with 21 additions and 9 deletions
|
@ -1733,11 +1733,12 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
// graph to run the hit-test on it.
|
// graph to run the hit-test on it.
|
||||||
area = new Path({ internal: true, closed: true });
|
area = new Path({ internal: true, closed: true });
|
||||||
if (isJoin) {
|
if (isJoin) {
|
||||||
// It's a join. See that it's not a round one (collinear
|
// Only add bevels to segments that aren't smooth.
|
||||||
// handles).
|
if (!segment.isSmooth()) {
|
||||||
// _addBevelJoin() handles both 'bevel' and 'miter' joins.
|
// _addBevelJoin() handles both 'bevel' and 'miter'.
|
||||||
Path._addBevelJoin(segment, join, strokeRadius,
|
Path._addBevelJoin(segment, join, strokeRadius,
|
||||||
miterLimit, null, strokeMatrix, addToArea, true);
|
miterLimit, null, strokeMatrix, addToArea, true);
|
||||||
|
}
|
||||||
} else if (cap === 'square') {
|
} else if (cap === 'square') {
|
||||||
Path._addSquareCap(segment, cap, strokeRadius, null,
|
Path._addSquareCap(segment, cap, strokeRadius, null,
|
||||||
strokeMatrix, addToArea, true);
|
strokeMatrix, addToArea, true);
|
||||||
|
@ -2714,10 +2715,7 @@ statics: {
|
||||||
function addJoin(segment, join) {
|
function addJoin(segment, join) {
|
||||||
// When both handles are set in a segment and they are collinear,
|
// When both handles are set in a segment and they are collinear,
|
||||||
// the join setting is ignored and round is always used.
|
// the join setting is ignored and round is always used.
|
||||||
var handleIn = segment._handleIn,
|
if (join === 'round' || segment.isSmooth()) {
|
||||||
handleOut = segment._handleOut;
|
|
||||||
if (join === 'round' || !handleIn.isZero() && !handleOut.isZero()
|
|
||||||
&& handleIn.isCollinear(handleOut)) {
|
|
||||||
addRound(segment);
|
addRound(segment);
|
||||||
} else {
|
} else {
|
||||||
// _addBevelJoin() handles both 'bevel' and 'miter' joins.
|
// _addBevelJoin() handles both 'bevel' and 'miter' joins.
|
||||||
|
|
|
@ -243,6 +243,20 @@ var Segment = Base.extend(/** @lends Segment# */{
|
||||||
return !this._handleIn.isZero() || !this._handleOut.isZero();
|
return !this._handleIn.isZero() || !this._handleOut.isZero();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the segment connects two curves smoothly, meaning that its two
|
||||||
|
* handles are collinear and segment does not form a corner.
|
||||||
|
*
|
||||||
|
* @return {Boolean} {@true if the segment is smooth}
|
||||||
|
* @see Point#isCollinear()
|
||||||
|
*/
|
||||||
|
isSmooth: function() {
|
||||||
|
var handleIn = this._handleIn,
|
||||||
|
handleOut = this._handleOut;
|
||||||
|
return !handleIn.isZero() && !handleOut.isZero()
|
||||||
|
&& handleIn.isCollinear(handleOut);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the segment's handles by setting their coordinates to zero,
|
* Clears the segment's handles by setting their coordinates to zero,
|
||||||
* turning the segment into a corner.
|
* turning the segment into a corner.
|
||||||
|
|
Loading…
Reference in a new issue