From 35a5da8e8f4c08b73a4774aa828f7419718cf1b1 Mon Sep 17 00:00:00 2001 From: Yi-Ting Tu Date: Wed, 25 Dec 2024 22:52:51 -0500 Subject: [PATCH] Correct fractional width for float color renderer --- src/simulator/js/FloatColorRenderer.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/simulator/js/FloatColorRenderer.js b/src/simulator/js/FloatColorRenderer.js index f56aec9d..414c8f18 100644 --- a/src/simulator/js/FloatColorRenderer.js +++ b/src/simulator/js/FloatColorRenderer.js @@ -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 @@ -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); }