Program: 133398
Project: 133398
Buggy source:
/** 
 * Creates a JavaFX PipeController from a RELAP7 Pipe.
 * @param plantComp The pipe to be converted.
 * @return The converted pipe.
 */
public PipeController createPipe(Pipe plantComp){
  PipeMesh mesh=new PipeMesh();
  mesh.setProperty("String_Node_Str",Integer.toString(plantComp.getId()));
  mesh.setLength(plantComp.getLength() * SCALE);
  mesh.setRadius(plantComp.getRadius() * SCALE);
  mesh.setInnerRadius(plantComp.getRadius() * SCALE);
  mesh.setAxialSamples(plantComp.getNumElements());
  PipeController pipe=(PipeController)factory.createController(mesh);
  double[] position=plantComp.getPosition();
  position[0]=position[0] * SCALE;
  position[1]=position[1] * SCALE;
  position[2]=position[2] * SCALE;
  double[] orientation=plantComp.getOrientation();
  double[] normalized=new double[3];
  double length=Math.sqrt(Math.pow(orientation[0],2) + Math.pow(orientation[1],2) + Math.pow(orientation[2],2));
  normalized[0]=orientation[0] / length;
  normalized[1]=orientation[1] / length;
  normalized[2]=orientation[2] / length;
  double pipeLength=plantComp.getLength() * SCALE;
  position[0]+=pipeLength / 2 * normalized[0];
  position[1]+=pipeLength / 2 * normalized[1];
  position[2]+=pipeLength / 2 * normalized[2];
  pipe.setTranslation(position[0],position[1],position[2]);
  double yRotation;
  if (normalized[1] != 0 || normalized[0] != 0) {
    yRotation=normalized[2] / Math.sqrt(Math.pow(normalized[0],2) + Math.pow(normalized[1],2));
  }
 else {
    yRotation=0d;
  }
  double zRotation;
  if (normalized[0] != 0) {
    zRotation=normalized[1] / normalized[0];
  }
 else {
    zRotation=0d;
  }
  if ((yRotation != 0 && zRotation != 0)) {
    pipe.setRotation(0,-Math.atan(yRotation),-Math.atan(zRotation));
  }
 else {
    if (normalized[0] > 0) {
      pipe.setRotation(0,0,-Math.PI / 2);
    }
 else     if (normalized[0] < 0) {
      pipe.setRotation(0,0,Math.PI / 2);
    }
 else     if (normalized[2] > 0) {
      pipe.setRotation(Math.PI / 2,0,0);
    }
 else     if (normalized[2] < 0) {
      pipe.setRotation(-Math.PI / 2,0,0);
    }
 else     if (normalized[1] < 0) {
      pipe.setRotation(-Math.PI,0,0);
    }
  }
  return pipe;
}

Fixed version (ground truth):
/** 
 * Creates a JavaFX PipeController from a RELAP7 Pipe.
 * @param plantComp The pipe to be converted.
 * @return The converted pipe.
 */
public PipeController createPipe(Pipe plantComp){
  PipeMesh mesh=new PipeMesh();
  mesh.setProperty("String_Node_Str",Integer.toString(plantComp.getId()));
  mesh.setLength(plantComp.getLength() * SCALE);
  mesh.setRadius(plantComp.getRadius() * SCALE);
  mesh.setInnerRadius(plantComp.getRadius() * SCALE);
  mesh.setAxialSamples(plantComp.getNumElements());
  mesh.setProperty("String_Node_Str",plantComp.getName());
  PipeController pipe=(PipeController)factory.createController(mesh);
  double[] position=plantComp.getPosition();
  position[0]=position[0] * SCALE;
  position[1]=position[1] * SCALE;
  position[2]=position[2] * SCALE;
  double[] orientation=plantComp.getOrientation();
  double[] normalized=new double[3];
  double length=Math.sqrt(Math.pow(orientation[0],2) + Math.pow(orientation[1],2) + Math.pow(orientation[2],2));
  normalized[0]=orientation[0] / length;
  normalized[1]=orientation[1] / length;
  normalized[2]=orientation[2] / length;
  double pipeLength=plantComp.getLength() * SCALE;
  position[0]+=pipeLength / 2 * normalized[0];
  position[1]+=pipeLength / 2 * normalized[1];
  position[2]+=pipeLength / 2 * normalized[2];
  pipe.setTranslation(position[0],position[1],position[2]);
  double yRotation;
  if (normalized[1] != 0 || normalized[0] != 0) {
    yRotation=normalized[2] / Math.sqrt(Math.pow(normalized[0],2) + Math.pow(normalized[1],2));
  }
 else {
    yRotation=0d;
  }
  double zRotation;
  if (normalized[0] != 0) {
    zRotation=normalized[1] / normalized[0];
  }
 else {
    zRotation=0d;
  }
  if ((yRotation != 0 && zRotation != 0)) {
    pipe.setRotation(0,-Math.atan(yRotation),-Math.atan(zRotation));
  }
 else {
    if (normalized[0] > 0) {
      pipe.setRotation(0,0,-Math.PI / 2);
    }
 else     if (normalized[0] < 0) {
      pipe.setRotation(0,0,Math.PI / 2);
    }
 else     if (normalized[2] > 0) {
      pipe.setRotation(Math.PI / 2,0,0);
    }
 else     if (normalized[2] < 0) {
      pipe.setRotation(-Math.PI / 2,0,0);
    }
 else     if (normalized[1] < 0) {
      pipe.setRotation(-Math.PI,0,0);
    }
  }
  return pipe;
}