#version 150

layout (lines_adjacency) in;
layout (line_strip, max_vertices=2) out;

void main(void) {
  vec4 p1=gl_in[1].gl_Position;
  vec4 p2=gl_in[2].gl_Position;
  vec4 c1=gl_in[0].gl_Position;
  vec4 c2=gl_in[3].gl_Position;
  
  p1/=p1.w;
  p2/=p2.w;
  c1/=c1.w;
  c2/=c2.w;

  c1-=p1;
  c2-=p1;
  p2-=p1;

  if (sign(p2.x*c1.y - p2.y*c1.x) == sign(p2.x*c2.y - p2.y*c2.x))
  {
    gl_FrontColor=gl_in[0].gl_FrontColor;

    gl_Position=gl_in[1].gl_Position;
    EmitVertex();

    gl_Position=gl_in[2].gl_Position;
    EmitVertex();

    EndPrimitive();
  }
}
