Program: 175808
Project: 175808
Buggy source:
@Override public void drawCoarse(MultiMap<MiniRoof,FacState> todo) throws IOException {
  RoofTexApp rta=mr.roofTexApp;
  BufferedImage src=ImageIO.read(Tweed.toWorkspace(rta.coarse));
  NetInfo ni=NetInfo.get(this);
  int count=0;
  for (  Loop<Point2d> verticalPts : mr.getAllFaces()) {
    TwoRects toPix=new TwoRects(rta.textureRect,new DRectangle(src.getWidth(),src.getHeight()),ni.resolution);
    Loop<Point2d> pixPts=toPix.tranform(verticalPts);
    Color mean=Color.darkGray;
    mean=meanColor(src,mean,pixPts);
    Face origin=mr.origins.get(verticalPts);
    if (origin == null)     continue;
    RoofTag rt=(RoofTag)GreebleHelper.getTag(origin.profile,RoofTag.class);
    Point2d start=toPix.transform(origin.edge.start), end=toPix.transform(origin.edge.end);
    Line startEnd=new Line(start,end);
    AffineTransform toOrigin=AffineTransform.getTranslateInstance(-start.x,-start.y), rot=AffineTransform.getRotateInstance(-startEnd.aTan2()), deslope=AffineTransform.getScaleInstance(1,1 / Math.cos(origin.edge.getAngle()));
    AffineTransform t=AffineTransform.getTranslateInstance(0,0);
    t.preConcatenate(toOrigin);
    t.preConcatenate(rot);
    t.preConcatenate(deslope);
    double[] bounds=Loopz.minMax2d(Loopz.transform(verticalPts,rot));
    double[] pixBounds=Loopz.minMax2d(Loopz.transform(pixPts,t));
    int outWidth=(int)Math.ceil(((bounds[1] - bounds[0]) * scale) / tileWidth) * tileWidth, outHeight=(int)Math.ceil(((bounds[3] - bounds[2]) * scale) / tileWidth) * tileWidth;
    BufferedImage bigCoarse=new BufferedImage(outWidth + overlap * 2,outHeight + overlap * 2,BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g=bigCoarse.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    t.preConcatenate(AffineTransform.getTranslateInstance(-pixBounds[0],0));
    t.preConcatenate(AffineTransform.getScaleInstance(outWidth / (pixBounds[1] - pixBounds[0]),outHeight / (pixBounds[3] - pixBounds[2])));
    t.preConcatenate(AffineTransform.getTranslateInstance(overlap,outHeight + overlap));
    g.setTransform(t);
    g.drawImage(src,0,0,null);
    if (true) {
      g.setColor(mean);
      g.setStroke(new BasicStroke(overlap / 8));
      for (      Loopable<Point2d> lp : pixPts.loopableIterator()) {
        g.drawLine((int)lp.get().x,(int)lp.get().y,(int)lp.next.get().x,(int)lp.next.get().y);
      }
      if (false)       for (      HalfEdge e : mr.superFace) {
        MiniFacade mf=((SuperEdge)e).toEdit;
        for (        FRect f : mf.featureGen.getRects(Feature.WINDOW)) {
          PanesLabelApp pla=f.panesLabelApp;
          if (pla.coveringRoof != null) {
            for (            Loopable<Point2d> pt : pla.coveringRoof.loopableIterator()) {
              g.drawLine((int)pt.get().x,(int)pt.get().y,(int)pt.getNext().get().x,(int)pt.getNext().get().y);
            }
          }
        }
      }
    }
    g.dispose();
    FacState state=new FacState(bigCoarse,mr,new DRectangle(0,0,bounds[1] - bounds[0],bounds[3] - bounds[2]),rt);
    for (int x=0; x <= outWidth / tileWidth; x++)     for (int y=0; y <= outHeight / tileWidth; y++)     state.nextTiles.add(new TileState(state,x,y));
    todo.put(mr,state);
  }
}

Fixed version (ground truth):
@Override public void drawCoarse(MultiMap<MiniRoof,FacState> todo) throws IOException {
  RoofTexApp rta=mr.roofTexApp;
  BufferedImage src=ImageIO.read(Tweed.toWorkspace(rta.coarse));
  NetInfo ni=NetInfo.get(this);
  int count=0;
  for (  Loop<Point2d> verticalPts : mr.getAllFaces()) {
    TwoRects toPix=new TwoRects(rta.textureRect,new DRectangle(src.getWidth(),src.getHeight()),ni.resolution);
    Loop<Point2d> pixPts=toPix.tranform(verticalPts);
    Color mean=Color.darkGray;
    mean=meanColor(src,mean,pixPts);
    Face origin=mr.origins.get(verticalPts);
    if (origin == null)     continue;
    RoofTag rt=(RoofTag)GreebleHelper.getTag(origin.profile,RoofTag.class);
    Point2d start=toPix.transform(origin.edge.start), end=toPix.transform(origin.edge.end);
    Line startEnd=new Line(start,end);
    AffineTransform toOrigin=AffineTransform.getTranslateInstance(-start.x,-start.y), rot=AffineTransform.getRotateInstance(-startEnd.aTan2()), deslope=AffineTransform.getScaleInstance(1,1 / Math.cos(origin.edge.getAngle()));
    AffineTransform t=AffineTransform.getTranslateInstance(0,0);
    double[] bounds=Loopz.minMax2d(Loopz.transform(verticalPts,rot));
    t.preConcatenate(toOrigin);
    t.preConcatenate(rot);
    t.preConcatenate(deslope);
    AffineTransform geom2Big=new AffineTransform(t);
    double[] pixBounds=Loopz.minMax2d(Loopz.transform(pixPts,geom2Big));
    int outWidth=(int)Math.ceil(((bounds[1] - bounds[0]) * scale) / tileWidth) * tileWidth, outHeight=(int)Math.ceil(((bounds[3] - bounds[2]) * scale) / tileWidth) * tileWidth;
    BufferedImage bigCoarse=new BufferedImage(outWidth + overlap * 2,outHeight + overlap * 2,BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g=bigCoarse.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
    t.preConcatenate(AffineTransform.getTranslateInstance(-pixBounds[0],0));
    t.preConcatenate(AffineTransform.getScaleInstance(outWidth / (pixBounds[1] - pixBounds[0]),outHeight / (pixBounds[3] - pixBounds[2])));
    t.preConcatenate(AffineTransform.getTranslateInstance(overlap,outHeight + overlap));
    g.setTransform(t);
    g.drawImage(src,0,-256,null);
    if (true) {
      g.setColor(mean);
      g.setStroke(new BasicStroke(overlap / 8));
      for (      Loopable<Point2d> lp : pixPts.loopableIterator()) {
        g.drawLine((int)lp.get().x,(int)lp.get().y,(int)lp.next.get().x,(int)lp.next.get().y);
      }
      g.setColor(Colourz.transparent(mean,128));
      for (      HalfEdge e : mr.superFace) {
        MiniFacade mf=((SuperEdge)e).toEdit;
        for (        FRect f : mf.featureGen.getRects(Feature.WINDOW)) {
          PanesLabelApp pla=f.panesLabelApp;
          if (pla.coveringRoof != null) {
            int c=0;
            for (            Loopable<Point2d> pt : toPix.tranform(pla.coveringRoof).loopableIterator()) {
              if (c++ == 3)               continue;
              g.drawLine((int)pt.get().x,(int)pt.get().y,(int)pt.getNext().get().x,(int)pt.getNext().get().y);
            }
          }
        }
      }
    }
    g.dispose();
    FacState state=new FacState(bigCoarse,mr,new DRectangle(0,0,bounds[1] - bounds[0],bounds[3] - bounds[2]),rt);
    for (int x=0; x <= outWidth / tileWidth; x++)     for (int y=0; y <= outHeight / tileWidth; y++)     state.nextTiles.add(new TileState(state,x,y));
    todo.put(mr,state);
  }
}