Address review feedback

This commit is contained in:
adroitwhiz
2020-05-06 16:21:18 -04:00
parent 4b7558f2d2
commit 51bceb68e5
2 changed files with 5 additions and 1 deletions

View File

@@ -234,7 +234,8 @@ void main()
// Avoid division by zero
float baDot = dot(ba, ba);
baDot = (abs(baDot) < epsilon) ? epsilon : baDot;
// the dot product of a vector and itself is always positive
baDot = max(baDot, epsilon);
// Magnitude of vector projection of this fragment onto the line (both relative to the line's start point).
// This results in a "linear gradient" which goes from 0.0 at the start point to 1.0 at the end point.

View File

@@ -42,7 +42,10 @@ void main() {
// Rotate quad to line angle
vec2 pointDiff = u_penPoints.zw - u_penPoints.xy;
// Ensure line has a nonzero length so it's rendered properly
// As long as either component is nonzero, the line length will be nonzero
pointDiff.x = abs(pointDiff.x) < epsilon ? epsilon : pointDiff.x;
// The `normalized` vector holds rotational values equivalent to sine/cosine
// We're applying the standard rotation matrix formula to the position to rotate the quad to the line angle
vec2 normalized = pointDiff / max(lineLength, epsilon);
position = mat2(normalized.x, normalized.y, -normalized.y, normalized.x) * position;
// Translate quad