Skip to content

Commit

Permalink
Merge pull request #201 from tpietzsch/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
trautmane authored Jan 24, 2025
2 parents 2df09b3 + d8907b9 commit 82949cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,11 @@ private static Exception mapTriangle(final Pair<AffineModel2D, double[][]> ai,
final double dy = affineTransform2D.d(0).getDoublePosition(1);
final double[] source = new double[2];
for (int targetY = minY; targetY <= maxY; ++targetY) {
final Range xRange = triangle.intersect(targetY, minX, maxX);
/* TODO: Actually, "maxX" should be "maxX + 1" here, but we compensate for the additional "+1" below.
"maxX + 1" would be correct because intersect range upper bound is exclusive.
*/
final Range xRange = triangle.intersect(targetY, minX, maxX + 1);
source[0] = xRange.from();
source[1] = targetY;
affineTransform2D.apply(source, source);
lineMapper.map(source[0], source[1], dx, dy, xRange.from(), targetY,
xRange.length() + 1
/* TODO: This "+1" is to fix the tests and be compatible to the old code.
However, it leads to pixels on the edge of neighboring triangles to be drawn twice.
*/
);
lineMapper.map(source[0], source[1], dx, dy, xRange.from(), targetY, xRange.length());
}

return null;
Expand Down
11 changes: 10 additions & 1 deletion render-app/src/main/java/org/janelia/alignment/Triangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ static WindingOrder of(final double ax, final double ay, final double bx, final
this.cy = cy;
}

@Override
public String toString() {
return "Triangle{" +
"A=(" + ax + ", " + ay + "), " +
"B=(" + bx + ", " + by + "), " +
"C=(" + cx + ", " + cy + ")" +
'}';
}

static class Range {
private final int from;
private final int length;
Expand Down Expand Up @@ -84,7 +93,7 @@ int length() {
Range intersect(final double y, final int rangeMinX, final int rangeMaxX) {
final double[] bounds = new double[]{rangeMinX, rangeMaxX};
intersect(y, bounds);
return new Range((int) Math.ceil(bounds[0]), (int) Math.ceil(bounds[1]));
return new Range((int) Math.ceil(bounds[0]), Math.min(rangeMaxX, (int) Math.floor(bounds[1] + 1)));
}

void intersect(final double y, final double[] bounds) {
Expand Down

0 comments on commit 82949cb

Please sign in to comment.