mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Handle CurveLocation on path with only one segment
This commit is contained in:
parent
a2069fc73d
commit
efcdd7bda8
2 changed files with 15 additions and 5 deletions
|
@ -57,13 +57,16 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
||||||
this._intersection = this._next = this._previous = null;
|
this._intersection = this._next = this._previous = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
_setCurve: function(curve) {
|
_setPath: function(path) {
|
||||||
var path = curve._path;
|
|
||||||
// We only store the path to verify versions for cached values.
|
// We only store the path to verify versions for cached values.
|
||||||
// To ensure we use the right path (e.g. after splitting), we shall
|
// To ensure we use the right path (e.g. after splitting), we shall
|
||||||
// always access the path on the result of getCurve().
|
// always access the path on the result of getCurve().
|
||||||
this._path = path;
|
this._path = path;
|
||||||
this._version = path ? path._version : 0;
|
this._version = path ? path._version : 0;
|
||||||
|
},
|
||||||
|
|
||||||
|
_setCurve: function(curve) {
|
||||||
|
this._setPath(curve._path);
|
||||||
this._curve = curve;
|
this._curve = curve;
|
||||||
this._segment = null; // To be determined, see #getSegment()
|
this._segment = null; // To be determined, see #getSegment()
|
||||||
// Also store references to segment1 and segment2, in case path
|
// Also store references to segment1 and segment2, in case path
|
||||||
|
@ -74,7 +77,14 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
_setSegment: function(segment) {
|
_setSegment: function(segment) {
|
||||||
this._setCurve(segment.getCurve());
|
var curve = segment.getCurve();
|
||||||
|
if (curve) {
|
||||||
|
this._setCurve(curve);
|
||||||
|
} else {
|
||||||
|
this._setPath(segment._path);
|
||||||
|
this._segment1 = segment;
|
||||||
|
this._segment2 = null;
|
||||||
|
}
|
||||||
this._segment = segment;
|
this._segment = segment;
|
||||||
this._time = segment === this._segment1 ? 0 : 1;
|
this._time = segment === this._segment1 ? 0 : 1;
|
||||||
// To avoid issues with imprecision in getCurve() / trySegment()
|
// To avoid issues with imprecision in getCurve() / trySegment()
|
||||||
|
@ -455,7 +465,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
||||||
!end && count ? roots[0] : 1);
|
!end && count ? roots[0] : 1);
|
||||||
// When no root was found, the full length was calculated. Use a
|
// When no root was found, the full length was calculated. Use a
|
||||||
// fraction of it. By trial & error, 64 was determined to work well.
|
// fraction of it. By trial & error, 64 was determined to work well.
|
||||||
offsets.push(count ? offset : offset / 64);
|
offsets.push(count ? offset : offset / 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isInRange(angle, min, max) {
|
function isInRange(angle, min, max) {
|
||||||
|
|
|
@ -201,7 +201,7 @@ test('#1073#issuecomment-234305530', function() {
|
||||||
true]);
|
true]);
|
||||||
testIntersections(path1.getIntersections(path2), [
|
testIntersections(path1.getIntersections(path2), [
|
||||||
{ point: { x: 426.61172, y: 448 }, index: 0, time: 0.27769, crossing: true },
|
{ point: { x: 426.61172, y: 448 }, index: 0, time: 0.27769, crossing: true },
|
||||||
{ point: { x: 376, y: 480 }, index: 1, time: 0, crossing: false },
|
{ point: { x: 376, y: 480 }, index: 1, time: 0, crossing: true },
|
||||||
{ point: { x: 343.68011, y: 469.7389 }, index: 1, time: 0.77843, crossing: true },
|
{ point: { x: 343.68011, y: 469.7389 }, index: 1, time: 0.77843, crossing: true },
|
||||||
{ point: { x: 336.40125, y: 463.59875 }, index: 2, time: 0.00608, crossing: true }
|
{ point: { x: 336.40125, y: 463.59875 }, index: 2, time: 0.00608, crossing: true }
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Reference in a new issue