mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Fix issue in Curve#divide() that lead to intersection segments being linked up wrongly.
Relates to #784
This commit is contained in:
parent
53dd726057
commit
c77165be3a
3 changed files with 29 additions and 26 deletions
|
@ -471,36 +471,32 @@ var Curve = Base.extend(/** @lends Curve# */{
|
||||||
// Only divide if not at the beginning or end.
|
// Only divide if not at the beginning or end.
|
||||||
if (parameter >= tMin && parameter <= tMax) {
|
if (parameter >= tMin && parameter <= tMax) {
|
||||||
var parts = Curve.subdivide(this.getValues(), parameter),
|
var parts = Curve.subdivide(this.getValues(), parameter),
|
||||||
setHandles = _setHandles || this.hasHandles(),
|
|
||||||
left = parts[0],
|
left = parts[0],
|
||||||
right = parts[1];
|
right = parts[1],
|
||||||
|
setHandles = _setHandles || this.hasHandles(),
|
||||||
// Write back the results:
|
segment1 = this._segment1,
|
||||||
|
segment2 = this._segment2,
|
||||||
|
path = this._path;
|
||||||
if (setHandles) {
|
if (setHandles) {
|
||||||
this._segment1._handleOut.set(left[2] - left[0],
|
// Adjust the handles on the existing segments. The new segment
|
||||||
left[3] - left[1]);
|
// will be inserted between the existing segment1 and segment2:
|
||||||
// segment2 is the end segment. By inserting newSegment
|
|
||||||
// between segment1 and 2, 2 becomes the end segment.
|
|
||||||
// Convert absolute -> relative
|
// Convert absolute -> relative
|
||||||
this._segment2._handleIn.set(right[4] - right[6],
|
segment1._handleOut.set(left[2] - left[0],
|
||||||
|
left[3] - left[1]);
|
||||||
|
segment2._handleIn.set(right[4] - right[6],
|
||||||
right[5] - right[7]);
|
right[5] - right[7]);
|
||||||
}
|
}
|
||||||
|
// Create the new segment:
|
||||||
// Create the new segment, convert absolute -> relative:
|
|
||||||
var x = left[6], y = left[7],
|
var x = left[6], y = left[7],
|
||||||
segment = new Segment(new Point(x, y),
|
segment = new Segment(new Point(x, y),
|
||||||
setHandles && new Point(left[4] - x, left[5] - y),
|
setHandles && new Point(left[4] - x, left[5] - y),
|
||||||
setHandles && new Point(right[2] - x, right[3] - y));
|
setHandles && new Point(right[2] - x, right[3] - y));
|
||||||
|
|
||||||
// Insert it in the segments list, if needed:
|
// Insert it in the segments list, if needed:
|
||||||
if (this._path) {
|
if (path) {
|
||||||
// Insert at the end if this curve is a closing curve of a
|
// By inserting at segment1.index + 1, we make sure to insert at
|
||||||
// closed path, since otherwise it would be inserted at 0.
|
// the end if this curve is a closing curve of a closed path,
|
||||||
if (this._segment1._index > 0 && this._segment2._index === 0) {
|
// as with segment2.index it would be inserted at 0.
|
||||||
this._path.add(segment);
|
path.insert(segment1._index + 1, segment);
|
||||||
} else {
|
|
||||||
this._path.insert(this._segment2._index, segment);
|
|
||||||
}
|
|
||||||
// The way Path#_add handles curves, this curve will always
|
// The way Path#_add handles curves, this curve will always
|
||||||
// become the owner of the newly inserted segment.
|
// become the owner of the newly inserted segment.
|
||||||
// TODO: I expect this.getNext() to produce the correct result,
|
// TODO: I expect this.getNext() to produce the correct result,
|
||||||
|
@ -509,8 +505,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
||||||
res = this; // this.getNext();
|
res = this; // this.getNext();
|
||||||
} else {
|
} else {
|
||||||
// otherwise create it from the result of split
|
// otherwise create it from the result of split
|
||||||
var end = this._segment2;
|
var end = segment2;
|
||||||
this._segment2 = segment;
|
segment2 = segment;
|
||||||
res = new Curve(segment, end);
|
res = new Curve(segment, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,10 +374,10 @@ var Path = PathItem.extend(/** @lends Path# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private method that adds a segment to the segment list. It assumes that
|
* Private method that adds segments to the segment list. It assumes that
|
||||||
* the passed object is a segment already and does not perform any checks.
|
* the passed object is an array of segments already and does not perform
|
||||||
* If a curves list was requested, it will kept in sync with the segments
|
* any checks. If a curves list was requested, it will be kept in sync with
|
||||||
* list automatically.
|
* the segments list automatically.
|
||||||
*/
|
*/
|
||||||
_add: function(segs, index) {
|
_add: function(segs, index) {
|
||||||
// Local short-cuts:
|
// Local short-cuts:
|
||||||
|
|
|
@ -471,6 +471,13 @@ PathItem.inject(new function() {
|
||||||
text.pivot = text.globalToLocal(text.point);
|
text.pivot = text.globalToLocal(text.point);
|
||||||
text.scale(scaleFactor);
|
text.scale(scaleFactor);
|
||||||
text.rotate(textAngle);
|
text.rotate(textAngle);
|
||||||
|
new Path.Line({
|
||||||
|
from: text.point,
|
||||||
|
to: seg.point,
|
||||||
|
strokeColor: color,
|
||||||
|
strokeScaling: false
|
||||||
|
});
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawSegment(seg, other, text, index, color) {
|
function drawSegment(seg, other, text, index, color) {
|
||||||
|
|
Loading…
Reference in a new issue