Fix false positives in Curve#isLinear() and Segment#isLinear().

This commit is contained in:
Jürg Lehni 2015-09-03 09:01:07 +02:00
parent 041c31a88a
commit af355dc82c
2 changed files with 10 additions and 6 deletions

View file

@ -666,9 +666,11 @@ statics: {
// See Segment#isLinear(): // See Segment#isLinear():
var p1x = v[0], p1y = v[1], var p1x = v[0], p1y = v[1],
p2x = v[6], p2y = v[7], p2x = v[6], p2y = v[7],
l = new Point(p2x - p1x, p2y - p1y); l = new Point(p2x - p1x, p2y - p1y),
return l.isCollinear(new Point(v[2] - p1x, v[3] - p1y)) h1 = new Point(v[2] - p1x, v[3] - p1y),
&& l.isCollinear(new Point(v[4] - p2x, v[5] - p2y)); h2 = new Point(v[4] - p2x, v[5] - p2y);
return l.isZero() ? h1.isZero() && h2.isZero()
: l.isCollinear(h2) && l.isCollinear(h2);
}, },
isFlatEnough: function(v, tolerance) { isFlatEnough: function(v, tolerance) {

View file

@ -571,9 +571,11 @@ var Segment = Base.extend(/** @lends Segment# */{
// these methods that are implemented in both places. // these methods that are implemented in both places.
isLinear: function(seg1, seg2) { isLinear: function(seg1, seg2) {
var l = seg2._point.subtract(seg1._point); var l = seg2._point.subtract(seg1._point),
return l.isCollinear(seg1._handleOut) h1 = seg1._handleOut,
&& l.isCollinear(seg2._handleIn); h2 = seg2._handleIn;
return l.isZero() ? h1.isZero() && h2.isZero()
: l.isCollinear(h2) && l.isCollinear(h2);
}, },
isCollinear: function(seg1, seg2, seg3, seg4) { isCollinear: function(seg1, seg2, seg3, seg4) {