Skip to content

Commit 6d53729

Browse files
committed
Fix line angle calculation.
In calculating angles related to lines, two angles were averaged using (a + b) / 2, which doesn't work in the general case.
1 parent 8d68527 commit 6d53729

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/gl/lineFeature.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ var gl_lineFeature = function (arg) {
6161
'uniform float pixelWidth;',
6262
'uniform float aspect;',
6363

64-
'varying vec3 strokeColorVar;',
65-
'varying float strokeOpacityVar;',
64+
'varying vec4 strokeColorVar;',
6665

6766
'void main(void)',
6867
'{',
@@ -85,8 +84,7 @@ var gl_lineFeature = function (arg) {
8584
' if (worldPrev.w != 0.0) {',
8685
' worldPrev = worldPrev/worldPrev.w;',
8786
' }',
88-
' strokeColorVar = strokeColor;',
89-
' strokeOpacityVar = strokeOpacity;',
87+
' strokeColorVar = vec4(strokeColor, strokeOpacity);',
9088
' vec2 deltaNext = worldNext.xy - worldPos.xy;',
9189
' vec2 deltaPrev = worldPos.xy - worldPrev.xy;',
9290
' float angleNext = 0.0, anglePrev = 0.0;',
@@ -96,6 +94,8 @@ var gl_lineFeature = function (arg) {
9694
' else anglePrev = atan(deltaPrev.y / aspect, deltaPrev.x);',
9795
' if (deltaNext.xy == vec2(0.0, 0.0)) angleNext = anglePrev;',
9896
' float angle = (anglePrev + angleNext) / 2.0;',
97+
' if (abs(anglePrev - angleNext) >= PI)',
98+
' angle += PI;',
9999
' float cosAngle = cos(anglePrev - angle);',
100100
' if (cosAngle < 0.1) { cosAngle = sign(cosAngle) * 1.0; angle = 0.0; }',
101101
' float distance = (offset * strokeWidth * pixelWidth) /',
@@ -115,10 +115,9 @@ var gl_lineFeature = function (arg) {
115115
'#ifdef GL_ES',
116116
' precision highp float;',
117117
'#endif',
118-
'varying vec3 strokeColorVar;',
119-
'varying float strokeOpacityVar;',
118+
'varying vec4 strokeColorVar;',
120119
'void main () {',
121-
' gl_FragColor = vec4 (strokeColorVar, strokeOpacityVar);',
120+
' gl_FragColor = strokeColorVar;',
122121
'}'
123122
].join('\n'),
124123
shader = new vgl.shader(vgl.GL.FRAGMENT_SHADER);

0 commit comments

Comments
 (0)