Clean-up @hkrish's changes a bit.

This commit is contained in:
Jürg Lehni 2013-06-09 18:37:08 -07:00
parent f8e5fae826
commit 7faf2a9e70
2 changed files with 18 additions and 22 deletions

View file

@ -864,7 +864,8 @@ statics: {
step /= 2; step /= 2;
} }
var pt = Curve.evaluate(values, minT, true, 0); var pt = Curve.evaluate(values, minT, true, 0);
return new CurveLocation(this, minT, pt, null, point.getDistance(pt)); return new CurveLocation(this, minT, pt, null, null,
point.getDistance(pt));
}, },
getNearestPoint: function(point) { getNearestPoint: function(point) {
@ -1024,13 +1025,13 @@ new function() { // Scope for methods that require numerical integration
} }
}; };
}, new function() { // Scope for intersection using bezier fat-line clipping }, new function() { // Scope for intersection using bezier fat-line clipping
function addLocation(locations, curve1, parameter, point, curve2, parameter2) { function addLocation(locations, curve1, t1, point, curve2, t2) {
// Avoid duplicates when hitting segments (closed paths too) // Avoid duplicates when hitting segments (closed paths too)
var first = locations[0], var first = locations[0],
last = locations[locations.length - 1]; last = locations[locations.length - 1];
if ((!first || !point.equals(first._point)) if ((!first || !point.equals(first._point))
&& (!last || !point.equals(last._point))) && (!last || !point.equals(last._point)))
locations.push(new CurveLocation(curve1, parameter, point, curve2, null, parameter2)); locations.push(new CurveLocation(curve1, t1, point, curve2, t2));
} }
function addCurveIntersections(v1, v2, curve1, curve2, locations, function addCurveIntersections(v1, v2, curve1, curve2, locations,
@ -1117,10 +1118,10 @@ new function() { // Scope for methods that require numerical integration
// (according to Numerical.TOLERANCE). // (according to Numerical.TOLERANCE).
if (Math.abs(range1[1] - range1[0]) < /*#=*/ Numerical.TOLERANCE && if (Math.abs(range1[1] - range1[0]) < /*#=*/ Numerical.TOLERANCE &&
Math.abs(range2[1] - range2[0]) < /*#=*/ Numerical.TOLERANCE) { Math.abs(range2[1] - range2[0]) < /*#=*/ Numerical.TOLERANCE) {
var t = (range1[0] + range1[1]) / 2; var t1 = (range1[0] + range1[1]) / 2,
var t2 = (range2[0] + range2[1]) / 2; t2 = (range2[0] + range2[1]) / 2;
addLocation(locations, curve1, t, addLocation(locations, curve1, t1,
Curve.evaluate(v1, t, true, 0), curve2, t2); Curve.evaluate(v1, t1, true, 0), curve2, t2);
break; break;
} }
} }

View file

@ -37,7 +37,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
* @param {Point} point * @param {Point} point
*/ */
initialize: function CurveLocation(curve, parameter, point, _otherCurve, initialize: function CurveLocation(curve, parameter, point, _otherCurve,
_distance, _otherParameter) { _otherParameter, _distance) {
// Define this CurveLocation's unique id. // Define this CurveLocation's unique id.
this._id = CurveLocation._id = (CurveLocation._id || 0) + 1; this._id = CurveLocation._id = (CurveLocation._id || 0) + 1;
this._curve = curve; this._curve = curve;
@ -111,21 +111,16 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
getIntersection: function() { getIntersection: function() {
var intersection = this._intersection; var intersection = this._intersection;
if (!intersection && this._otherCurve) { if (!intersection && this._otherCurve) {
if( this._otherParameter ){ var param = this._otherParameter;
// if we have the parameter on the other curve use that for intersection // If we have the parameter on the other curve use that for
// rather than the point. // intersection rather than the point.
intersection = this._intersection = new CurveLocation( this._intersection = intersection = new CurveLocation(
this._otherCurve, this._otherParameter, null, this); this._otherCurve, param, param ? null : this._point, this);
// Force calculate the other point from the parameter. // Force calculate the other point from the parameter.
// DEBUG: @jlehni - Not sure why we have to do this? Shouldn't it auto-calculate // DEBUG: @jlehni - Not sure why we have to do this? Shouldn't
// upon first access?! // it auto-calculate upon first access?!
if (param)
intersection.getPoint(); intersection.getPoint();
} else {
// _point is always defined for intersection
intersection = this._intersection = new CurveLocation(
this._otherCurve, null, this._point, this);
// Link both ways
}
intersection._intersection = this; intersection._intersection = this;
} }
return intersection; return intersection;