//---------------------------------------------------------
// draw endless line through point A and B with radius r
//---------------------------------------------------------
float line(vec2 P, vec2 A, vec2 B, float r)
{
vec2 g = B - A;
float d = abs(dot(normalize(vec2(g.y, -g.x)), P - A));
return smoothstep(r, 0.5*r, d);
}
//---------------------------------------------------------
// draw segment line from point A to point B and radius r
// see also sdCapsule(p,a,b,r) from inigo quilez
// http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
//---------------------------------------------------------
float segment(vec2 P, vec2 A, vec2 B, float r)
{
vec2 g = B - A;
vec2 h = P - A;
float d = length(h - g * clamp(dot(g, h) / dot(g,g), 0.0, 1.0));
return smoothstep(r, 0.5*r, d);
}
//---------------------------------------------------------
float segment2(vec2 P, vec2 A, vec2 B, float r)
{
float d = length((P-=A)-(B-=A)*clamp(dot(P,B)/dot(B,B), 0.0, 1.0 ));
return smoothstep(r, 0.5*r, d);;
}