Skip to content

Commit

Permalink
Correct fractional width for float color renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
ricktu288 committed Dec 26, 2024
1 parent 3c1adde commit 35a5da8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/simulator/js/FloatColorRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ class FloatColorRenderer {
gl.uniform1i(this.isScreenSpaceLocation, false);

// Set line width
const lineWidth = Math.max(1.0, 1.0 * this.lengthScale * this.scale);
const lineWidth = Math.round(Math.max(1.0, 1.0 * this.lengthScale * this.scale));
gl.lineWidth(lineWidth);

// Draw rays
Expand Down Expand Up @@ -713,10 +713,12 @@ class FloatColorRenderer {
const length = Math.sqrt(dx * dx + dy * dy);
if (length === 0) return color;

const intendedLineWidth = 1.0 * this.lengthScale * this.scale;
// Calculate correction factor based on direction
// For diagonal lines (45 degrees), the correction is sqrt(2)
// For horizontal/vertical lines, the correction is 1
const correctionFactor = length / Math.max(Math.abs(dx), Math.abs(dy));
// Also correct for line width
const correctionFactor = length / Math.max(Math.abs(dx), Math.abs(dy)) * (intendedLineWidth / Math.round(Math.max(1.0, intendedLineWidth)));

return color.map(component => component * correctionFactor);
}
Expand Down

0 comments on commit 35a5da8

Please sign in to comment.