function addCurveLineIntersections(v1, v2, curve1, curve2, locations,
			include) {
		var flip = Curve.isLinear(v1),
			vc = flip ? v2 : v1,
			vl = flip ? v1 : v2,
			lx1 = vl[0], ly1 = vl[1],
			lx2 = vl[6], ly2 = vl[7],
			// Rotate both curve and line around l1 so that line is on x axis.
			ldx = lx2 - lx1,
			ldy = ly2 - ly1,
			// Calculate angle to the x-axis (1, 0).
			angle = Math.atan2(-ldy, ldx),
			sin = Math.sin(angle),
			cos = Math.cos(angle),
			// (rlx1, rly1) = (0, 0)
			rlx2 = ldx * cos - ldy * sin,
			// The curve values for the rotated line.
			rvl = [0, 0, 0, 0, rlx2, 0, rlx2, 0],
			// Calculate the curve values of the rotated curve.
			rvc = [];
		for(var i = 0; i < 8; i += 2) {
			var x = vc[i] - lx1,
				y = vc[i + 1] - ly1;
			rvc.push(
				x * cos - y * sin,
				y * cos + x * sin);
		}
		var roots = [],
			count = Curve.solveCubic(rvc, 1, 0, roots, 0, 1);
		// NOTE: count could be -1 for inifnite solutions, but that should only
		// happen with lines, in which case we should not be here.
		for (var i = 0; i < count; i++) {
			var tc = roots[i],
				x = Curve.evaluate(rvc, tc, 0).x;
			// We do have a point on the infinite line. Check if it falls on
			// the line *segment*.
			if (x >= 0 && x <= rlx2) {
				// Find the parameter of the intersection on the rotated line. 
				var tl = Curve.getParameterOf(rvl, x, 0),
					t1 = flip ? tl : tc,
					t2 = flip ? tc : tl;
				addLocation(locations, include,
						curve1, t1, Curve.evaluate(v1, t1, 0),
						curve2, t2, Curve.evaluate(v2, t2, 0));
			}
		}
	}
/**
	 * Intersections between curve and line becomes rather simple here mostly
	 * because of Numerical class. We can rotate the curve and line so that the
	 * line is on the X axis, and solve the implicit equations for the X axis
	 * and the curve.
	 */
Intersections between curve and line becomes rather simple here mostly
because of Numerical class. We can rotate the curve and line so that the
line is on the X axis, and solve the implicit equations for the X axis
and the curve.
Intersections between curve and line becomes rather simple here mostly because of Numerical class . We can rotate the curve and line so that the line is on the X axis and solve the implicit equations for the X axis and the curve .
function addCurveLineIntersections(v1, v2, curve1, curve2, locations,
			include) {
		var flip = Curve.isLinear(v1),
			vc = flip ? v2 : v1,
			vl = flip ? v1 : v2,
			lx1 = vl[0], ly1 = vl[1],
			lx2 = vl[6], ly2 = vl[7],
			ldx = lx2 - lx1,
			ldy = ly2 - ly1,
			angle = Math.atan2(-ldy, ldx),
			sin = Math.sin(angle),
			cos = Math.cos(angle),
			rlx2 = ldx * cos - ldy * sin,
			rvl = [0, 0, 0, 0, rlx2, 0, rlx2, 0],
			rvc = [];
		for(var i = 0; i < 8; i += 2) {
			var x = vc[i] - lx1,
				y = vc[i + 1] - ly1;
			rvc.push(
				x * cos - y * sin,
				y * cos + x * sin);
		}
		var roots = [],
			count = Curve.solveCubic(rvc, 1, 0, roots, 0, 1);
		for (var i = 0; i < count; i++) {
			var tc = roots[i],
				x = Curve.evaluate(rvc, tc, 0).x;
			if (x >= 0 && x <= rlx2) {
				var tl = Curve.getParameterOf(rvl, x, 0),
					t1 = flip ? tl : tc,
					t2 = flip ? tc : tl;
				addLocation(locations, include,
						curve1, t1, Curve.evaluate(v1, t1, 0),
						curve2, t2, Curve.evaluate(v2, t2, 0));
			}
		}
	}
function addCurveLineIntersections ( v1 , v2 , curve1 , curve2 , locations , include ) { var flip = Curve . isLinear ( v1 ) , vc = flip ? v2 : v1 , vl = flip ? v1 : v2 , lx1 = vl [ 0 ] , ly1 = vl [ 1 ] , lx2 = vl [ 6 ] , ly2 = vl [ 7 ] , ldx = lx2 - lx1 , ldy = ly2 - ly1 , angle = Math . atan2 ( - ldy , ldx ) , sin = Math . sin ( angle ) , cos = Math . cos ( angle ) , rlx2 = ldx * cos - ldy * sin , rvl = [ 0 , 0 , 0 , 0 , rlx2 , 0 , rlx2 , 0 ] , rvc = [ ] ; for ( var i = 0 ; i < 8 ; i += 2 ) { var x = vc [ i ] - lx1 , y = vc [ i + 1 ] - ly1 ; rvc . push ( x * cos - y * sin , y * cos + x * sin ) ; } var roots = [ ] , count = Curve . solveCubic ( rvc , 1 , 0 , roots , 0 , 1 ) ; for ( var i = 0 ; i < count ; i ++ ) { var tc = roots [ i ] , x = Curve . evaluate ( rvc , tc , 0 ) . x ; if ( x >= 0 && x <= rlx2 ) { var tl = Curve . getParameterOf ( rvl , x , 0 ) , t1 = flip ? tl : tc , t2 = flip ? tc : tl ; addLocation ( locations , include , curve1 , t1 , Curve . evaluate ( v1 , t1 , 0 ) , curve2 , t2 , Curve . evaluate ( v2 , t2 , 0 ) ) ; } } }
Intersections between curve and line becomes rather simple here mostly
 because of Numerical class.
Intersections between curve and line becomes rather simple here mostly because of Numerical class .
// Rotate both curve and line around l1 so that line is on x axis. // Calculate angle to the x-axis (1, 0). // (rlx1, rly1) = (0, 0) // The curve values for the rotated line. // Calculate the curve values of the rotated curve. // NOTE: count could be -1 for inifnite solutions, but that should only // happen with lines, in which case we should not be here. // We do have a point on the infinite line. Check if it falls on // the line *segment*. // Find the parameter of the intersection on the rotated line. 