File: triangle.glsl

package info (click to toggle)
python-vispy 0.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,840 kB
  • sloc: python: 59,436; javascript: 6,800; makefile: 69; sh: 6
file content (97 lines) | stat: -rw-r--r-- 2,481 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
 * Copyright (c) Vispy Development Team
 * Distributed under the (new) BSD License. See LICENSE.txt for more info.
 *
 * This file contains the code for drawing complete triangles as arrow heads.
 * this includes triangles with a top corner of 30, 60 and 90 degrees.
 */

#include "arrowheads/util.glsl"

/**
 * Computes the signed distance to a triangle arrow. This is a helper function,
 * and in general you'll use arrow_triangle_30, arrow_triangle_60, or
 * arrow_triangle_90.
 *
 * Parameters:
 * -----------
 *
 * texcoord 
 *     Point to compute distance to
 * size
 *     Size of the arrow head in pixels
 * linewidth
 *     Width of the line
 * antialias
 *     Anti alias width
 * height
 *     Height of the head (pixel)
 * 
 * See also
 * --------
 * arrow_triangle_30, arrow_triangle_60, arrow_triangle_90
 *
 * Return:
 * -------
 * Signed distance to the arrow
 *
 */
float arrow_triangle(vec2 texcoord, float size, 
                     float linewidth, float antialias, float height)
{
    vec2 start = -vec2(size/2.0, 0.0);
    vec2 end   = +vec2(size/2.0, 0.0);

    // Head : 3 lines
    vec2 p1 = start + size*vec2(0.0, +height);
    vec2 p2 = start + size*vec2(0.0, -height);

    float d1 = line_distance(texcoord, end, p1);
    float d2 = line_distance(texcoord, p2, end);
    float d3 = start.x - texcoord.x;


    return max(max(d1, d2), d3);
}

/**
 * Returns the signed distance to an triangle arrow head with a tip corner
 * of 30 degrees.
 *
 * See also
 * --------
 * arrow_triangle, arrow_triangle_60, arrow_triangle_90
 */
float arrow_triangle_30(vec2 texcoord, float size,
                        float linewidth, float antialias)
{
    return arrow_triangle(texcoord, size, linewidth, antialias, 0.25);
}

/**
 * Returns the signed distance to an triangle arrow head with a tip corner
 * of 60 degrees.
 *
 * See also
 * --------
 * arrow_triangle, arrow_triangle_30, arrow_triangle_90
 */
float arrow_triangle_60(vec2 texcoord, float size,
                        float linewidth, float antialias)
{
    return arrow_triangle(texcoord, size, linewidth, antialias, 0.5);
}

/**
 * Returns the signed distance to an triangle arrow head with a tip corner
 * of 90 degrees.
 *
 * See also
 * --------
 * arrow_triangle, arrow_triangle_30, arrow_triangle_60
 */
float arrow_triangle_90(vec2 texcoord, float size,
                        float linewidth, float antialias)
{
    return arrow_triangle(texcoord, size, linewidth, antialias, 1.0);
}