#version 330 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;

uniform vec2 dpi;
uniform vec2 origin;
in vec4 near_coord[1];

out vec2 location;


void max_bound(vec4 near_coord, out vec2 _a0, out vec2 _a1, out vec2 _b0, out vec2 _b1) {

    vec2 a0 = vec2(near_coord.x, near_coord.z);
    vec2 a1 = vec2(near_coord.x, near_coord.w);

    vec2 b0 = vec2(near_coord.y, near_coord.z);
    vec2 b1 = vec2(near_coord.y, near_coord.w);

    vec2 a_c = (a1 + b1) / 2;

    float l1 = length(a_c - origin);

    float rate = near_coord.w / l1;

    vec2 r1 = a1 - origin;
    vec2 r2 = b1 - origin;

    vec2 r1_ = r1 * rate;
    vec2 r2_ = r2 * rate;

    _a0 = a0;
    _a1 = a1;
    _b0 = r2_ + origin;
    _b1 = r1_ + origin;
}

void main() {
    vec4 position = vec4(0,0,0,0);

    vec2 a0, a1, b0, b1;

    max_bound(near_coord[0], a0, a1, b0, b1);

    gl_Position = vec4(a0, 0.0, 1.0);
    EmitVertex();
    gl_Position = vec4(a1, 0.0, 1.0);
    EmitVertex();
    gl_Position = vec4(b0, 0.0, 1.0);
    EmitVertex();
    gl_Position = vec4(b1, 0.0, 1.0);
    EmitVertex();
    EndPrimitive();
}