mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -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.
|
||||
area = new Path({ internal: true, closed: true });
|
||||
if (isJoin) {
|
||||
// It's a join. See that it's not a round one (collinear
|
||||
// handles).
|
||||
// _addBevelJoin() handles both 'bevel' and 'miter' joins.
|
||||
Path._addBevelJoin(segment, join, strokeRadius,
|
||||
miterLimit, null, strokeMatrix, addToArea, true);
|
||||
// Only add bevels to segments that aren't smooth.
|
||||
if (!segment.isSmooth()) {
|
||||
// _addBevelJoin() handles both 'bevel' and 'miter'.
|
||||
Path._addBevelJoin(segment, join, strokeRadius,
|
||||
miterLimit, null, strokeMatrix, addToArea, true);
|
||||
}
|
||||
} else if (cap === 'square') {
|
||||
Path._addSquareCap(segment, cap, strokeRadius, null,
|
||||
strokeMatrix, addToArea, true);
|
||||
|
@ -2714,10 +2715,7 @@ statics: {
|
|||
function addJoin(segment, join) {
|
||||
// When both handles are set in a segment and they are collinear,
|
||||
// the join setting is ignored and round is always used.
|
||||
var handleIn = segment._handleIn,
|
||||
handleOut = segment._handleOut;
|
||||
if (join === 'round' || !handleIn.isZero() && !handleOut.isZero()
|
||||
&& handleIn.isCollinear(handleOut)) {
|
||||
if (join === 'round' || segment.isSmooth()) {
|
||||
addRound(segment);
|
||||
} else {
|
||||
// _addBevelJoin() handles both 'bevel' and 'miter' joins.
|
||||
|
|
|
@ -243,6 +243,20 @@ var Segment = Base.extend(/** @lends Segment# */{
|
|||
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,
|
||||
* turning the segment into a corner.
|
||||
|
|
Loading…
Reference in a new issue