Program: 27734
Project: 27734
Buggy source:
/** 
 * Tests for intersection between the box and a ray defined by a starting point and a direction.
 * @param start The starting point of the ray
 * @param direction The direction of the ray
 * @return An intersection point its normal, if any
 */
public Optional<Tuple<Vector3d,Vector3d>> intersects(Vector3d start,Vector3d direction){
  final double txMin;
  final double txMax;
  final Vector3d xNormal;
  if (direction.getX() >= 0) {
    txMin=(this.min.getX() - start.getX()) / direction.getX();
    txMax=(this.max.getX() - start.getX()) / direction.getX();
    xNormal=Vector3d.UNIT_X;
  }
 else {
    txMin=(this.max.getX() - start.getX()) / direction.getX();
    txMax=(this.min.getX() - start.getX()) / direction.getX();
    xNormal=Vector3d.UNIT_X.negate();
  }
  final double tyMin;
  final double tyMax;
  final Vector3d yNormal;
  if (direction.getY() >= 0) {
    tyMin=(this.min.getY() - start.getY()) / direction.getY();
    tyMax=(this.max.getY() - start.getY()) / direction.getY();
    yNormal=Vector3d.UNIT_Y;
  }
 else {
    tyMin=(this.max.getY() - start.getY()) / direction.getY();
    tyMax=(this.min.getY() - start.getY()) / direction.getY();
    yNormal=Vector3d.UNIT_Y.negate();
  }
  if (txMin > tyMax || txMax < tyMin) {
    return Optional.empty();
  }
  Vector3d normalMax;
  Vector3d normalMin;
  double tMin;
  if (tyMin == txMin) {
    tMin=tyMin;
    normalMin=xNormal.negate().sub(yNormal);
  }
 else   if (tyMin > txMin) {
    tMin=tyMin;
    normalMin=yNormal.negate();
  }
 else {
    tMin=txMin;
    normalMin=xNormal.negate();
  }
  double tMax;
  if (tyMax == txMax) {
    tMax=tyMax;
    normalMax=xNormal.add(yNormal);
  }
 else   if (tyMax < txMax) {
    tMax=tyMax;
    normalMax=yNormal;
  }
 else {
    tMax=txMax;
    normalMax=xNormal;
  }
  final double tzMin;
  final double tzMax;
  final Vector3d zNormal;
  if (direction.getZ() >= 0) {
    tzMin=(this.min.getZ() - start.getZ()) / direction.getZ();
    tzMax=(this.max.getZ() - start.getZ()) / direction.getZ();
    zNormal=Vector3d.UNIT_Z;
  }
 else {
    tzMin=(this.max.getZ() - start.getZ()) / direction.getZ();
    tzMax=(this.min.getZ() - start.getZ()) / direction.getZ();
    zNormal=Vector3d.UNIT_Z.negate();
  }
  if (tMin > tzMax || tMax < tzMin) {
    return Optional.empty();
  }
  if (tzMin == tMin) {
    normalMin=normalMin.sub(zNormal);
  }
 else   if (tzMin > tMin) {
    tMin=tzMin;
    normalMin=zNormal.negate();
  }
  if (tzMax == tMax) {
    normalMax=normalMax.add(zNormal);
  }
 else   if (tzMax < tMax) {
    tMax=tzMax;
    normalMax=zNormal;
  }
  if (tMax < 0) {
    return Optional.empty();
  }
  final double t;
  Vector3d normal;
  if (tMin < 0) {
    t=tMax;
    normal=normalMax;
  }
 else {
    t=tMin;
    normal=normalMin;
  }
  normal=normal.normalize();
  final double x;
  final double y;
  final double z;
  if (normal.getX() > 0) {
    x=max.getX();
  }
 else   if (normal.getX() < 0) {
    x=min.getX();
  }
 else {
    x=direction.getX() * t + start.getX();
  }
  if (normal.getY() > 0) {
    y=max.getY();
  }
 else   if (normal.getY() < 0) {
    y=min.getY();
  }
 else {
    y=direction.getY() * t + start.getY();
  }
  if (normal.getZ() > 0) {
    z=max.getZ();
  }
 else   if (normal.getZ() < 0) {
    z=min.getZ();
  }
 else {
    z=direction.getZ() * t + start.getZ();
  }
  return Optional.of(new Tuple<>(new Vector3d(x,y,z),normal));
}

Fixed version (ground truth):
/** 
 * Tests for intersection between the box and a ray defined by a starting point and a direction.
 * @param start The starting point of the ray
 * @param direction The direction of the ray
 * @return An intersection point its normal, if any
 */
public Optional<Tuple<Vector3d,Vector3d>> intersects(Vector3d start,Vector3d direction){
  final double txMin;
  final double txMax;
  final Vector3d xNormal;
  if (Math.copySign(1,direction.getX()) > 0) {
    txMin=(this.min.getX() - start.getX()) / direction.getX();
    txMax=(this.max.getX() - start.getX()) / direction.getX();
    xNormal=Vector3d.UNIT_X;
  }
 else {
    txMin=(this.max.getX() - start.getX()) / direction.getX();
    txMax=(this.min.getX() - start.getX()) / direction.getX();
    xNormal=Vector3d.UNIT_X.negate();
  }
  final double tyMin;
  final double tyMax;
  final Vector3d yNormal;
  if (Math.copySign(1,direction.getY()) > 0) {
    tyMin=(this.min.getY() - start.getY()) / direction.getY();
    tyMax=(this.max.getY() - start.getY()) / direction.getY();
    yNormal=Vector3d.UNIT_Y;
  }
 else {
    tyMin=(this.max.getY() - start.getY()) / direction.getY();
    tyMax=(this.min.getY() - start.getY()) / direction.getY();
    yNormal=Vector3d.UNIT_Y.negate();
  }
  if (txMin > tyMax || txMax < tyMin) {
    return Optional.empty();
  }
  Vector3d normalMax;
  Vector3d normalMin;
  double tMin;
  if (tyMin == txMin) {
    tMin=tyMin;
    normalMin=xNormal.negate().sub(yNormal);
  }
 else   if (tyMin > txMin) {
    tMin=tyMin;
    normalMin=yNormal.negate();
  }
 else {
    tMin=txMin;
    normalMin=xNormal.negate();
  }
  double tMax;
  if (tyMax == txMax) {
    tMax=tyMax;
    normalMax=xNormal.add(yNormal);
  }
 else   if (tyMax < txMax) {
    tMax=tyMax;
    normalMax=yNormal;
  }
 else {
    tMax=txMax;
    normalMax=xNormal;
  }
  final double tzMin;
  final double tzMax;
  final Vector3d zNormal;
  if (Math.copySign(1,direction.getZ()) > 0) {
    tzMin=(this.min.getZ() - start.getZ()) / direction.getZ();
    tzMax=(this.max.getZ() - start.getZ()) / direction.getZ();
    zNormal=Vector3d.UNIT_Z;
  }
 else {
    tzMin=(this.max.getZ() - start.getZ()) / direction.getZ();
    tzMax=(this.min.getZ() - start.getZ()) / direction.getZ();
    zNormal=Vector3d.UNIT_Z.negate();
  }
  if (tMin > tzMax || tMax < tzMin) {
    return Optional.empty();
  }
  if (tzMin == tMin) {
    normalMin=normalMin.sub(zNormal);
  }
 else   if (tzMin > tMin) {
    tMin=tzMin;
    normalMin=zNormal.negate();
  }
  if (tzMax == tMax) {
    normalMax=normalMax.add(zNormal);
  }
 else   if (tzMax < tMax) {
    tMax=tzMax;
    normalMax=zNormal;
  }
  if (tMax < 0) {
    return Optional.empty();
  }
  final double t;
  Vector3d normal;
  if (tMin < 0) {
    t=tMax;
    normal=normalMax;
  }
 else {
    t=tMin;
    normal=normalMin;
  }
  normal=normal.normalize();
  final double x;
  final double y;
  final double z;
  if (normal.getX() > 0) {
    x=max.getX();
  }
 else   if (normal.getX() < 0) {
    x=min.getX();
  }
 else {
    x=direction.getX() * t + start.getX();
  }
  if (normal.getY() > 0) {
    y=max.getY();
  }
 else   if (normal.getY() < 0) {
    y=min.getY();
  }
 else {
    y=direction.getY() * t + start.getY();
  }
  if (normal.getZ() > 0) {
    z=max.getZ();
  }
 else   if (normal.getZ() < 0) {
    z=min.getZ();
  }
 else {
    z=direction.getZ() * t + start.getZ();
  }
  return Optional.of(new Tuple<>(new Vector3d(x,y,z),normal));
}