Intersection intersect(Ray r, num prevBestDistance)

Performs a ray - primitive intersection test. Returns an Intersection object with the associated information.

If the ray did not hit the primitive, the distance will be negative.

Source

Intersection intersect(Ray r, num prevBestDistance) {
  Variable x = new Variable('x'), y = new Variable('y'), z = new Variable('z');
  Variable t = new Variable('t');

  Expression xExpr = new Number(r.origin.x) + (t * new Number(r.direction.x));
  Expression yExpr = new Number(r.origin.y) + (t * new Number(r.direction.y));
  Expression zExpr = new Number(r.origin.z) + (t * new Number(r.direction.z));

  cm.bindVariable(x, xExpr);
  cm.bindVariable(y, yExpr);
  cm.bindVariable(z, zExpr);

  // Composition G(t) = F(x,y,z) o r(t)
  //Function g = compose(f, r);

  // Replace all numbers with intervals
  //g.replace();

  // Starting interval [0, maxDistance]
  Interval i = new Interval(0, maxDistance);

  //Interval i = f.evaluate(Expr.EvaluationType.INTERVAL, cm);
  //print(i);

  double distance = findRootBF(f, i);

  //TODO f needs to be composite for this to work, or have x, y, z substituted.
  //num distance = findRoot(f, i);
  //findRoot(g, i);

  Intersection int = new Intersection(distance, this, r.getPoint3(distance));
  return int;
}