private Intersection[] lineQuadIntersect(LineSegment l, QuadSegment c)
Intersection[] lineQuadIntersect(LineSegment l, QuadSegment c)
  private Intersection[] lineQuadIntersect(LineSegment l, QuadSegment c)  {    double[] y = new double[3];    double[] x = new double[3];    double[] r = new double[3];    int nRoots;    double x0 = c.P1.getX();    double y0 = c.P1.getY();    double x1 = c.cp.getX();    double y1 = c.cp.getY();    double x2 = c.P2.getX();    double y2 = c.P2.getY();    double lx0 = l.P1.getX();    double ly0 = l.P1.getY();    double lx1 = l.P2.getX();    double ly1 = l.P2.getY();    double dx = lx1 - lx0;    double dy = ly1 - ly0;    // form r(t) = y(t) - x(t) for the bezier    y[0] = y0;    y[1] = 2 * (y1 - y0);    y[2] = (y2 - 2 * y1 + y0);    x[0] = x0;    x[1] = 2 * (x1 - x0);    x[2] = (x2 - 2 * x1 + x0);    // a point, not a line    if (dy == 0 && dx == 0)      return null;    // line on y axis    if (dx == 0 || (dy / dx) > 1.0)      {	double k = dx / dy;	x[0] -= lx0;	y[0] -= ly0;	y[0] *= k;	y[1] *= k;	y[2] *= k;      }    else      {	double k = dy / dx;	x[0] -= lx0;	y[0] -= ly0;	x[0] *= k;	x[1] *= k;	x[2] *= k;      }    for (int i = 0; i < 3; i++)      r[i] = y[i] - x[i];    if ((nRoots = QuadCurve2D.solveQuadratic(r)) > 0)      {	Intersection[] temp = new Intersection[nRoots];	int intersections = 0;	for (int i = 0; i < nRoots; i++)	  {	    double t = r[i];	    if (t >= 0.0 && t <= 1.0)	      {		Point2D p = c.evaluatePoint(t);		// if the line is on an axis, snap the point to that axis.		if (dx == 0)		  p.setLocation(lx0, p.getY());		if (dy == 0)		  p.setLocation(p.getX(), ly0);		if (p.getX() <= Math.max(lx0, lx1)		    && p.getX() >= Math.min(lx0, lx1)		    && p.getY() <= Math.max(ly0, ly1)		    && p.getY() >= Math.min(ly0, ly1))		  {		    double lineparameter = p.distance(l.P1) / l.P2.distance(l.P1);		    temp[i] = new Intersection(p, lineparameter, t);		    intersections++;		  }	      }	    else	      temp[i] = null;	  }	if (intersections == 0)	  return null;	Intersection[] rValues = new Intersection[intersections];	for (int i = 0; i < nRoots; i++)	  if (temp[i] != null)	    rValues[--intersections] = temp[i];	return (rValues);      }    return null;  }