Improve CurveLocation.isCrossing()

Better handles edge cases in offsetting tests
This commit is contained in:
Jürg Lehni 2019-06-22 17:31:36 +02:00
parent f66c73e534
commit 3ff5560c0c

View file

@ -450,18 +450,19 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
var v = curve.getValues(), var v = curve.getValues(),
roots = Curve.classify(v).roots || Curve.getPeaks(v), roots = Curve.classify(v).roots || Curve.getPeaks(v),
count = roots.length, count = roots.length,
t = end && count > 1 ? roots[count - 1] offset = Curve.getLength(v,
: count > 0 ? roots[0] end && count ? roots[count - 1] : 0,
: 0.5; !end && count ? roots[0] : 1);
// Then use half of the offset, for extra measure. // When no root was found, the full length was calculated. Use a
offsets.push(Curve.getLength(v, end ? t : 0, end ? 1 : t) / 2); // fraction of it. By trial & error, 64 was determined to work well.
offsets.push(count ? offset : offset / 64);
} }
function isInRange(angle, min, max) { function isInRange(angle, min, max) {
return min < max return min < max
? angle > min && angle < max ? angle > min && angle <= max
// min > max: the range wraps around -180 / 180 degrees // min > max: the range wraps around -180 / 180 degrees
: angle > min || angle < max; : angle > min || angle <= max;
} }
if (!t1Inside) { if (!t1Inside) {