webgl2-sdf 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/browser/index.min.js +1 -0
  2. package/node/bezier/bezier-curves-to-line-segs.js +31 -0
  3. package/node/bezier/bezier-curves-to-line-segs.js.map +1 -0
  4. package/node/bezier/eval-de-casteljau.js +61 -0
  5. package/node/bezier/eval-de-casteljau.js.map +1 -0
  6. package/node/bezier/from-to/from-to-2.js +134 -0
  7. package/node/bezier/from-to/from-to-2.js.map +1 -0
  8. package/node/bezier/from-to/from-to-3.js +159 -0
  9. package/node/bezier/from-to/from-to-3.js.map +1 -0
  10. package/node/bezier/from-to/from-to.js +21 -0
  11. package/node/bezier/from-to/from-to.js.map +1 -0
  12. package/node/bezier/is-cubic-obtuse.js +24 -0
  13. package/node/bezier/is-cubic-obtuse.js.map +1 -0
  14. package/node/bezier/is-quad-obtuse.js +20 -0
  15. package/node/bezier/is-quad-obtuse.js.map +1 -0
  16. package/node/bezier/is-really-point.js +19 -0
  17. package/node/bezier/is-really-point.js.map +1 -0
  18. package/node/bezier/split-by-deviation-from-straight-line-cubic.js +85 -0
  19. package/node/bezier/split-by-deviation-from-straight-line-cubic.js.map +1 -0
  20. package/node/bezier/split-by-deviation-from-straight-line-quad.js +50 -0
  21. package/node/bezier/split-by-deviation-from-straight-line-quad.js.map +1 -0
  22. package/node/bezier/split-into-line-segments.js +29 -0
  23. package/node/bezier/split-into-line-segments.js.map +1 -0
  24. package/node/generate-sdf.js +57 -0
  25. package/node/generate-sdf.js.map +1 -0
  26. package/node/index.js +2 -0
  27. package/node/index.js.map +1 -0
  28. package/node/main-program.js +100 -0
  29. package/node/main-program.js.map +1 -0
  30. package/node/max-aspect-ratio-before-stretch.js +3 -0
  31. package/node/max-aspect-ratio-before-stretch.js.map +1 -0
  32. package/node/prepare-buffers.js +114 -0
  33. package/node/prepare-buffers.js.map +1 -0
  34. package/node/row-count.js +4 -0
  35. package/node/row-count.js.map +1 -0
  36. package/node/shaders/main.fragment.js +149 -0
  37. package/node/shaders/main.fragment.js.map +1 -0
  38. package/node/shaders/main.vertex.js +53 -0
  39. package/node/shaders/main.vertex.js.map +1 -0
  40. package/node/svg/get-beziers-from-raw-paths.js +91 -0
  41. package/node/svg/get-beziers-from-raw-paths.js.map +1 -0
  42. package/node/svg/get-paths-from-str.js +14 -0
  43. package/node/svg/get-paths-from-str.js.map +1 -0
  44. package/node/svg/path-data-polyfill/parse-number.js +101 -0
  45. package/node/svg/path-data-polyfill/parse-number.js.map +1 -0
  46. package/node/svg/path-data-polyfill/parse-path-data-string.js +21 -0
  47. package/node/svg/path-data-polyfill/parse-path-data-string.js.map +1 -0
  48. package/node/svg/path-data-polyfill/source.js +147 -0
  49. package/node/svg/path-data-polyfill/source.js.map +1 -0
  50. package/node/svg/path-segment/c.js +29 -0
  51. package/node/svg/path-segment/c.js.map +1 -0
  52. package/node/svg/path-segment/h.js +23 -0
  53. package/node/svg/path-segment/h.js.map +1 -0
  54. package/node/svg/path-segment/l.js +24 -0
  55. package/node/svg/path-segment/l.js.map +1 -0
  56. package/node/svg/path-segment/q.js +23 -0
  57. package/node/svg/path-segment/q.js.map +1 -0
  58. package/node/svg/path-segment/s.js +34 -0
  59. package/node/svg/path-segment/s.js.map +1 -0
  60. package/node/svg/path-segment/t.js +28 -0
  61. package/node/svg/path-segment/t.js.map +1 -0
  62. package/node/svg/path-segment/v.js +23 -0
  63. package/node/svg/path-segment/v.js.map +1 -0
  64. package/node/svg/path-segment/z.js +21 -0
  65. package/node/svg/path-segment/z.js.map +1 -0
  66. package/node/svg/path-state.js +2 -0
  67. package/node/svg/path-state.js.map +1 -0
  68. package/node/tex-width.js +12 -0
  69. package/node/tex-width.js.map +1 -0
  70. package/node/types/attribute.js +2 -0
  71. package/node/types/attribute.js.map +1 -0
  72. package/node/types/cell.js +2 -0
  73. package/node/types/cell.js.map +1 -0
  74. package/node/types/gl-context.js +2 -0
  75. package/node/types/gl-context.js.map +1 -0
  76. package/node/types/gl-type.js +2 -0
  77. package/node/types/gl-type.js.map +1 -0
  78. package/node/types/gl-usage.js +2 -0
  79. package/node/types/gl-usage.js.map +1 -0
  80. package/node/types/program.js +2 -0
  81. package/node/types/program.js.map +1 -0
  82. package/node/types/strip.js +2 -0
  83. package/node/types/strip.js.map +1 -0
  84. package/node/types/texture.js +2 -0
  85. package/node/types/texture.js.map +1 -0
  86. package/node/utils/calc-circs.js +97 -0
  87. package/node/utils/calc-circs.js.map +1 -0
  88. package/node/utils/clip-line-segment-to-grid.js +98 -0
  89. package/node/utils/clip-line-segment-to-grid.js.map +1 -0
  90. package/node/utils/clip-line-segment-to-strips.js +150 -0
  91. package/node/utils/clip-line-segment-to-strips.js.map +1 -0
  92. package/node/utils/create-empty-grid.js +24 -0
  93. package/node/utils/create-empty-grid.js.map +1 -0
  94. package/node/utils/create-empty-strips.js +16 -0
  95. package/node/utils/create-empty-strips.js.map +1 -0
  96. package/node/utils/distance-seg-to-p.js +35 -0
  97. package/node/utils/distance-seg-to-p.js.map +1 -0
  98. package/node/utils/find-close-cells.js +130 -0
  99. package/node/utils/find-close-cells.js.map +1 -0
  100. package/node/utils/find-crossing-cells.js +31 -0
  101. package/node/utils/find-crossing-cells.js.map +1 -0
  102. package/node/utils/get-distance-to-line-function.js +45 -0
  103. package/node/utils/get-distance-to-line-function.js.map +1 -0
  104. package/node/utils/jump-idx.js +81 -0
  105. package/node/utils/jump-idx.js.map +1 -0
  106. package/node/utils/map-to-viewbox.js +29 -0
  107. package/node/utils/map-to-viewbox.js.map +1 -0
  108. package/node/utils/seg-box-x.js +69 -0
  109. package/node/utils/seg-box-x.js.map +1 -0
  110. package/node/utils/seg-strip-x.js +58 -0
  111. package/node/utils/seg-strip-x.js.map +1 -0
  112. package/node/vector/dot.js +11 -0
  113. package/node/vector/dot.js.map +1 -0
  114. package/node/vector/from-to-vec.js +11 -0
  115. package/node/vector/from-to-vec.js.map +1 -0
  116. package/node/vector/len.js +9 -0
  117. package/node/vector/len.js.map +1 -0
  118. package/node/webgl-utils/compile-shader.js +8 -0
  119. package/node/webgl-utils/compile-shader.js.map +1 -0
  120. package/node/webgl-utils/get-gl-context.js +43 -0
  121. package/node/webgl-utils/get-gl-context.js.map +1 -0
  122. package/node/webgl-utils/set-attribute.js +52 -0
  123. package/node/webgl-utils/set-attribute.js.map +1 -0
  124. package/node/webgl-utils/set-uniform-block.js +31 -0
  125. package/node/webgl-utils/set-uniform-block.js.map +1 -0
  126. package/node/webgl-utils/set-uniform.js +11 -0
  127. package/node/webgl-utils/set-uniform.js.map +1 -0
  128. package/node/webgl-utils/uniform-block.js +2 -0
  129. package/node/webgl-utils/uniform-block.js.map +1 -0
  130. package/node/webgl-utils/uniform-type.js +2 -0
  131. package/node/webgl-utils/uniform-type.js.map +1 -0
  132. package/node/webgl-utils/use-program.js +31 -0
  133. package/node/webgl-utils/use-program.js.map +1 -0
  134. package/node/webgl-utils/use-texture.js +25 -0
  135. package/node/webgl-utils/use-texture.js.map +1 -0
  136. package/package.json +4 -5
  137. package/node/debug-shaders.d.ts +0 -9
  138. package/node/helpers/calc-circs.d.ts +0 -11
  139. package/node/helpers/clip-line-segment-to-grid.d.ts +0 -14
  140. package/node/helpers/clip-line-segment-to-strips.d.ts +0 -13
  141. package/node/helpers/create-empty-grid.d.ts +0 -8
  142. package/node/helpers/create-empty-strips.d.ts +0 -7
  143. package/node/helpers/distance-seg-to-p.d.ts +0 -5
  144. package/node/helpers/find-close-cells.d.ts +0 -3
  145. package/node/helpers/find-crossing-cells.d.ts +0 -3
  146. package/node/helpers/get-distance-to-line-function.d.ts +0 -10
  147. package/node/helpers/jump-idx.d.ts +0 -2
  148. package/node/helpers/map-to-viewbox.d.ts +0 -2
  149. package/node/helpers/seg-box-x.d.ts +0 -10
  150. package/node/helpers/seg-strip-x.d.ts +0 -9
  151. package/node/webgl2.d.ts +0 -2
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Returns the ordered (by t-value) intersection points of the given line
3
+ * segment and square.
4
+ *
5
+ * @param seg a line segment given by its endpoints
6
+ * @param square a square given by its two opposing corner points, min-x, min-y
7
+ * first
8
+ */
9
+ function segBoxX(seg, square) {
10
+ const [p0, p1] = seg;
11
+ const [x0, y0] = p0;
12
+ const [x1, y1] = p1;
13
+ const [[minX, minY], [maxX, maxY]] = square;
14
+ // Check if line segment intersects any of the four square edges
15
+ const dx = x1 - x0;
16
+ const dy = y1 - y0;
17
+ // Parametric line equation: P(t) = P1 + t*(P2-P1), where 0 <= t <= 1
18
+ const ts = [];
19
+ const ps = [];
20
+ if (dx !== 0) {
21
+ // Check intersection with left edge (x = minX)
22
+ const tL = (minX - x0) / dx;
23
+ if (tL >= 0 && tL <= 1) {
24
+ const y = y0 + tL * dy;
25
+ if (y >= minY && y <= maxY) {
26
+ ts.push(tL);
27
+ ps.push([minX, y]);
28
+ }
29
+ }
30
+ // Check intersection with right edge (x = maxX)
31
+ const tR = (maxX - x0) / dx;
32
+ if (tR >= 0 && tR <= 1) {
33
+ const y = y0 + tR * dy;
34
+ if (y >= minY && y <= maxY) {
35
+ ts.push(tR);
36
+ ps.push([maxX, y]);
37
+ }
38
+ }
39
+ }
40
+ if (dy !== 0) {
41
+ // Check intersection with bottom edge (y = minY)
42
+ const tT = (minY - y0) / dy;
43
+ if (tT >= 0 && tT <= 1) {
44
+ const x = x0 + tT * dx;
45
+ if (x >= minX && x <= maxX) {
46
+ ts.push(tT);
47
+ ps.push([x, minY]);
48
+ }
49
+ }
50
+ // Check intersection with top edge (y = maxY)
51
+ const tB = (maxY - y0) / dy;
52
+ if (tB >= 0 && tB <= 1) {
53
+ const x = x0 + tB * dx;
54
+ if (x >= minX && x <= maxX) {
55
+ ts.push(tB);
56
+ ps.push([x, maxY]);
57
+ }
58
+ }
59
+ }
60
+ // TODO might be more than 2!!
61
+ if (ts.length === 2) {
62
+ return ts[0] < ts[1]
63
+ ? ps
64
+ : [ps[1], ps[0]];
65
+ }
66
+ return ps;
67
+ }
68
+ export { segBoxX };
69
+ //# sourceMappingURL=seg-box-x.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seg-box-x.js","sourceRoot":"","sources":["../../src/utils/seg-box-x.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Returns the ordered (by t-value) intersection points of the given line
3
+ * segment and half-open strip.
4
+ *
5
+ * @param seg a line segment given by its endpoints
6
+ * @param strip a half-open strip given by max-x, min-y, max-y
7
+ */
8
+ function segStripX(seg, strip) {
9
+ const [p0, p1] = seg;
10
+ const [x0, y0] = p0;
11
+ const [x1, y1] = p1;
12
+ const [maxX, minY, maxY] = strip;
13
+ // Check if line segment intersects any of the four square edges
14
+ const dx = x1 - x0;
15
+ const dy = y1 - y0;
16
+ // Parametric line equation: P(t) = P1 + t*(P2-P1), where 0 <= t <= 1
17
+ const ts = [];
18
+ const ps = [];
19
+ if (dx !== 0) {
20
+ // Check intersection with right edge (x = maxX)
21
+ const tL = (maxX - x0) / dx;
22
+ if (tL >= 0 && tL <= 1) {
23
+ const y = y0 + tL * dy;
24
+ if (y >= minY && y <= maxY) {
25
+ ts.push(tL);
26
+ ps.push([maxX, y]);
27
+ }
28
+ }
29
+ }
30
+ if (dy !== 0) {
31
+ // Check intersection with bottom edge (y = minY)
32
+ const tT = (minY - y0) / dy;
33
+ if (tT >= 0 && tT <= 1) {
34
+ const x = x0 + tT * dx;
35
+ if (x <= maxX) {
36
+ ts.push(tT);
37
+ ps.push([x, minY]);
38
+ }
39
+ }
40
+ // Check intersection with top edge (y = maxY)
41
+ const tB = (maxY - y0) / dy;
42
+ if (tB >= 0 && tB <= 1) {
43
+ const x = x0 + tB * dx;
44
+ if (x <= maxX) {
45
+ ts.push(tB);
46
+ ps.push([x, maxY]);
47
+ }
48
+ }
49
+ }
50
+ if (ts.length === 2) {
51
+ return ts[0] < ts[1]
52
+ ? ps
53
+ : [ps[1], ps[0]];
54
+ }
55
+ return ps;
56
+ }
57
+ export { segStripX };
58
+ //# sourceMappingURL=seg-strip-x.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seg-strip-x.js","sourceRoot":"","sources":["../../src/utils/seg-strip-x.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,SAAS,SAAS,CACV,GAAe,EACf,KAAe;IAEnB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;IACrB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;IAEpB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC;IAEjC,gEAAgE;IAChE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IACnB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;IAEnB,qEAAqE;IAErE,MAAM,EAAE,GAAa,EAAE,CAAC;IACxB,MAAM,EAAE,GAAe,EAAE,CAAC;IAE1B,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;QACX,gDAAgD;QAChD,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAC,EAAE,CAAC;QAC1B,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;gBACzB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACZ,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACvB,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC;QACX,iDAAiD;QACjD,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAC,EAAE,CAAC;QAC1B,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;gBACZ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACZ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;YACvB,CAAC;QACL,CAAC;QAED,8CAA8C;QAC9C,MAAM,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,GAAC,EAAE,CAAC;QAC1B,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;gBACZ,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBACZ,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;YACvB,CAAC;QACL,CAAC;IACL,CAAC;IAED,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClB,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAChB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAED,OAAO,EAAE,CAAC;AACd,CAAC;AAGD,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the dot (inner) product between two 2-vectors.
3
+ *
4
+ * @param a the first vector
5
+ * @param b the second vector
6
+ */
7
+ function dot(a, b) {
8
+ return a[0] * b[0] + a[1] * b[1];
9
+ }
10
+ export { dot };
11
+ //# sourceMappingURL=dot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dot.js","sourceRoot":"","sources":["../../src/vector/dot.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,SAAS,GAAG,CAAC,CAAW,EAAE,CAAW;IACjC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC;AAGD,OAAO,EAAE,GAAG,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Returns the second 2-vector minus the first.
3
+ *
4
+ * @param p the first vector
5
+ * @param q the second vector
6
+ */
7
+ function fromToVec(p, q) {
8
+ return [q[0] - p[0], q[1] - p[1]];
9
+ }
10
+ export { fromToVec };
11
+ //# sourceMappingURL=from-to-vec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from-to-vec.js","sourceRoot":"","sources":["../../src/vector/from-to-vec.ts"],"names":[],"mappings":"AACA;;;;;IAKI;AACJ,SAAS,SAAS,CAAC,CAAW,EAAE,CAAW;IACvC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAGD,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns the length of the given 2-vector.
3
+ * @param p a 2d vector
4
+ */
5
+ function len(p) {
6
+ return Math.sqrt(p[0] * p[0] + p[1] * p[1]);
7
+ }
8
+ export { len };
9
+ //# sourceMappingURL=len.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"len.js","sourceRoot":"","sources":["../../src/vector/len.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,SAAS,GAAG,CAAC,CAAW;IACpB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,CAAC;AAGD,OAAO,EAAE,GAAG,EAAE,CAAA"}
@@ -0,0 +1,8 @@
1
+ function compileShader(gl, src, type) {
2
+ const shader = gl.createShader(type);
3
+ gl.shaderSource(shader, src);
4
+ gl.compileShader(shader);
5
+ return shader;
6
+ }
7
+ export { compileShader };
8
+ //# sourceMappingURL=compile-shader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-shader.js","sourceRoot":"","sources":["../../src/webgl-utils/compile-shader.ts"],"names":[],"mappings":"AACA,SAAS,aAAa,CACd,EAA0B,EAC1B,GAAW,EACX,IAAyD;IAE7D,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAE,CAAC;IACtC,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC;AAClB,CAAC;AAGD,OAAO,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,43 @@
1
+ const cache = new WeakMap();
2
+ /**
3
+ * Returns a `GlContext` by reference via a cache of `WebGL2RenderingContext`s.
4
+ * * if `gl` doesn't exist in the cache yet a new context is created.
5
+ *
6
+ * @param gl the `WebGL2RenderingContext` context to wrap
7
+ * @param callback
8
+ */
9
+ function getWebGLContext(gl) {
10
+ {
11
+ const glContext = cache.get(gl);
12
+ if (glContext) {
13
+ return glContext;
14
+ }
15
+ }
16
+ const programs = {};
17
+ const textures = {};
18
+ const framebufferStack = [];
19
+ gl.canvas.addEventListener('webglcontextlost', e => {
20
+ handleContextLoss();
21
+ e.preventDefault();
22
+ }, false);
23
+ const glContext = {
24
+ gl,
25
+ onContextLoss: handleContextLoss,
26
+ textures,
27
+ programs,
28
+ framebufferStack
29
+ };
30
+ cache.set(gl, glContext);
31
+ return glContext;
32
+ ////////////////////////
33
+ function handleContextLoss() {
34
+ deleteAllProps(programs);
35
+ deleteAllProps(textures);
36
+ framebufferStack.length = 0;
37
+ }
38
+ }
39
+ function deleteAllProps(o) {
40
+ Object.keys(o).forEach(key => { delete o[key]; });
41
+ }
42
+ export { getWebGLContext };
43
+ //# sourceMappingURL=get-gl-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-gl-context.js","sourceRoot":"","sources":["../../src/webgl-utils/get-gl-context.ts"],"names":[],"mappings":"AAKA,MAAM,KAAK,GAAG,IAAI,OAAO,EAAqC,CAAC;AAG/D;;;;;;GAMG;AACH,SAAS,eAAe,CAChB,EAA0B;IAE9B,CAAC;QACG,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,SAAS,EAAE,CAAC;YAAC,OAAO,SAAS,CAAC;QAAC,CAAC;IACxC,CAAC;IAED,MAAM,QAAQ,GAAgC,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAgC,EAAE,CAAC;IACjD,MAAM,gBAAgB,GAAuB,EAAE,CAAC;IAEhD,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,CAAC,CAAC,EAAE;QAC/C,iBAAiB,EAAE,CAAC;QACpB,CAAC,CAAC,cAAc,EAAE,CAAC;IACvB,CAAC,EAAE,KAAK,CAAC,CAAC;IAEV,MAAM,SAAS,GAAc;QACzB,EAAE;QACF,aAAa,EAAE,iBAAiB;QAChC,QAAQ;QACR,QAAQ;QACR,gBAAgB;KACnB,CAAC;IAEF,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;IAEzB,OAAO,SAAS,CAAC;IAGjB,wBAAwB;IAExB,SAAS,iBAAiB;QACtB,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzB,cAAc,CAAC,QAAQ,CAAC,CAAC;QACzB,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,CAAC;AACL,CAAC;AAGD,SAAS,cAAc,CAAC,CAA6B;IACjD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC;AAGD,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,52 @@
1
+ const {
2
+ // Integer types
3
+ BYTE, // 5120
4
+ UNSIGNED_BYTE, // 5121
5
+ SHORT, // 5122
6
+ UNSIGNED_SHORT, // 5123
7
+ INT, // 5124
8
+ UNSIGNED_INT, // 5125
9
+ // Float types
10
+ FLOAT, // 5126
11
+ HALF_FLOAT, // 5131
12
+ INT_2_10_10_10_REV, // 36255
13
+ UNSIGNED_INT_2_10_10_10_REV // 33640
14
+ } = WebGL2RenderingContext;
15
+ /**
16
+ *
17
+ * @param name name used in glsl shaders
18
+ * @param size the number of components per vertex attribute. Must be 1, 2, 3, or 4.
19
+ * @param usage one of `gl.STATIC_DRAW`, `gl.DYNAMIC_DRAW`, `gl.STREAM_DRAW`, etc.
20
+ * @param data
21
+ * @param instancingDivisor defaults to 0; 0, 1, ...
22
+ * @param stride defaults to 0;
23
+ * @param offset defaults to 0;
24
+ */
25
+ function setAttribute(program) {
26
+ return (name, size, type, usage, data, instancingDivisor = 0, stride = 0, offset = 0) => {
27
+ const { gl, attributes } = program;
28
+ const attr = attributes[name] = attributes[name] ?? {
29
+ buf: gl.createBuffer(), // TODO should we destroy our buffers?
30
+ loc: gl.getAttribLocation(program.program, name),
31
+ data: null
32
+ };
33
+ const { loc, buf } = attr;
34
+ gl.bindBuffer(gl.ARRAY_BUFFER, buf);
35
+ if (type === FLOAT || type === HALF_FLOAT) {
36
+ gl.vertexAttribPointer(loc, size, type, false, stride, offset);
37
+ }
38
+ else {
39
+ gl.vertexAttribIPointer(loc, size, type, stride, offset);
40
+ }
41
+ gl.enableVertexAttribArray(loc);
42
+ if (instancingDivisor !== 0) {
43
+ gl.vertexAttribDivisor(loc, instancingDivisor);
44
+ }
45
+ if (data !== attr.data) {
46
+ gl.bufferData(gl.ARRAY_BUFFER, data, usage);
47
+ attr.data = data;
48
+ }
49
+ };
50
+ }
51
+ export { setAttribute };
52
+ //# sourceMappingURL=set-attribute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-attribute.js","sourceRoot":"","sources":["../../src/webgl-utils/set-attribute.ts"],"names":[],"mappings":"AAKA,MAAM;AACF,gBAAgB;AAChB,IAAI,EAAa,OAAO;AACxB,aAAa,EAAI,OAAO;AACxB,KAAK,EAAY,OAAO;AACxB,cAAc,EAAG,OAAO;AACxB,GAAG,EAAc,OAAO;AACxB,YAAY,EAAK,OAAO;AACxB,cAAc;AACd,KAAK,EAAY,OAAO;AACxB,UAAU,EAAO,OAAO;AAExB,kBAAkB,EAAY,QAAQ;AACtC,2BAA2B,CAAG,QAAQ;EACzC,GAAG,sBAAsB,CAAC;AAG3B;;;;;;;;;GASG;AACH,SAAS,YAAY,CACb,OAAgB;IAEpB,OAAO,CAAC,IAAY,EACZ,IAAY,EACZ,IAAgB,EAChB,KAAc,EACd,IAAoC,EACpC,iBAAiB,GAAG,CAAC,EACrB,MAAM,GAAG,CAAC,EACV,MAAM,GAAG,CAAC,EAAE,EAAE;QAElB,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;QAEnC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI;YAChD,GAAG,EAAE,EAAE,CAAC,YAAY,EAAE,EAAE,sCAAsC;YAC9D,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;YAChD,IAAI,EAAE,IAAI;SACb,CAAA;QAED,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAE1B,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC;QACpC,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YACxC,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACnE,CAAC;aAAM,CAAC;YACJ,EAAE,CAAC,oBAAoB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,CAAC;QACD,EAAE,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,iBAAiB,KAAK,CAAC,EAAE,CAAC;YAC1B,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QACnD,CAAC;QAED,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;YACrB,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC5C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC;IACL,CAAC,CAAA;AACL,CAAC;AAGD,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ *
3
+ * @param program_
4
+ * @param blockName used both as reference within the `Program` and within
5
+ * the GLSL shaders
6
+ */
7
+ function setUniformBlock(program_) {
8
+ return (blockName, bindingPoint, buffer) => {
9
+ const { gl, uniformBlocks, program } = program_;
10
+ // const sizeInBytes = buffer.byteLength;
11
+ let uniformBlock = uniformBlocks[blockName];
12
+ if (uniformBlocks[blockName] === undefined) {
13
+ const blockIndex = gl.getUniformBlockIndex(program, blockName);
14
+ gl.uniformBlockBinding(program, blockIndex, bindingPoint);
15
+ const buf = gl.createBuffer();
16
+ gl.bindBuffer(gl.UNIFORM_BUFFER, buf);
17
+ uniformBlock = { blockName, blockIndex, buf };
18
+ uniformBlocks[blockName] = uniformBlock;
19
+ }
20
+ else {
21
+ gl.bindBuffer(gl.UNIFORM_BUFFER, uniformBlock.buf);
22
+ }
23
+ const { buf } = uniformBlock;
24
+ gl.bufferData(gl.UNIFORM_BUFFER, buffer, gl.DYNAMIC_DRAW);
25
+ // gl.bindBuffer(gl.UNIFORM_BUFFER, null);
26
+ gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, buf);
27
+ // gl.bindBufferRange(gl.UNIFORM_BUFFER, bindingPoint, ubo, 0, sizeInBytes);
28
+ };
29
+ }
30
+ export { setUniformBlock };
31
+ //# sourceMappingURL=set-uniform-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-uniform-block.js","sourceRoot":"","sources":["../../src/webgl-utils/set-uniform-block.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,SAAS,eAAe,CAChB,QAAiB;IAErB,OAAO,CAAC,SAAiB,EACjB,YAAoB,EACpB,MAA+B,EAAE,EAAE;QAEvC,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QAEhD,yCAAyC;QAEzC,IAAI,YAAY,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,SAAS,EAAE,CAAC;YACzC,MAAM,UAAU,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC/D,EAAE,CAAC,mBAAmB,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;YAC1D,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC;YAE9B,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YAEtC,YAAY,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC;YAC9C,aAAa,CAAC,SAAS,CAAC,GAAG,YAAY,CAAC;QAC5C,CAAC;aAAM,CAAC;YACJ,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,EAAE,GAAG,EAAE,GAAG,YAAY,CAAC;QAE7B,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC;QAC1D,0CAA0C;QAC1C,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,cAAc,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC;QACxD,4EAA4E;IAChF,CAAC,CAAA;AACL,CAAC;AAGD,OAAO,EAAE,eAAe,EAAE,CAAA"}
@@ -0,0 +1,11 @@
1
+ function setUniform(program) {
2
+ return (type, name, ...values) => {
3
+ const { gl, uniforms } = program;
4
+ const uniformLoc = uniforms[name] ||
5
+ (uniforms[name] = gl.getUniformLocation(program.program, name));
6
+ // @ts-ignore
7
+ gl[`uniform${type}`](uniformLoc, ...values);
8
+ };
9
+ }
10
+ export { setUniform };
11
+ //# sourceMappingURL=set-uniform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-uniform.js","sourceRoot":"","sources":["../../src/webgl-utils/set-uniform.ts"],"names":[],"mappings":"AAIA,SAAS,UAAU,CACX,OAAgB;IAEpB,OAAO,CAAC,IAAiB,EACjB,IAAY,EACZ,GAAG,MAAa,EAAQ,EAAE;QAE9B,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;QAEjC,MAAM,UAAU,GACZ,QAAQ,CAAC,IAAI,CAAC;YACd,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAEpE,aAAa;QACb,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC;IAChD,CAAC,CAAA;AACL,CAAC;AAGD,OAAO,EAAE,UAAU,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=uniform-block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniform-block.js","sourceRoot":"","sources":["../../src/webgl-utils/uniform-block.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=uniform-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniform-type.js","sourceRoot":"","sources":["../../src/webgl-utils/uniform-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import { compileShader } from "./compile-shader";
2
+ /**
3
+ * Initiates a WebGL2 program by:
4
+ *
5
+ * * keeping track of `attributes` and `uniforms` locally (within the returned `Program`)
6
+ * * GL: `createProgram`
7
+ * * GL: `compileShader` and `attachShader` (for both Vertex and Fragment shaders)
8
+ * * GL: `linkProgram`
9
+ *
10
+ * @param glContext a context encapsulating our WebGl2 context
11
+ * @param name a name for us to refer to this program
12
+ * @param vert the vertex shader for this program
13
+ * @param frag the fragment shader for this program
14
+ */
15
+ function initProgram(glContext, name, vert, frag) {
16
+ const { gl, programs } = glContext;
17
+ if (programs[name]) {
18
+ return programs[name];
19
+ }
20
+ const attributes = {};
21
+ const uniforms = {};
22
+ const uniformBlocks = {};
23
+ const program = gl.createProgram();
24
+ gl.attachShader(program, compileShader(gl, vert, gl.VERTEX_SHADER));
25
+ gl.attachShader(program, compileShader(gl, frag, gl.FRAGMENT_SHADER));
26
+ gl.linkProgram(program);
27
+ programs[name] = { gl, program, attributes, uniforms, uniformBlocks };
28
+ return programs[name];
29
+ }
30
+ export { initProgram };
31
+ //# sourceMappingURL=use-program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-program.js","sourceRoot":"","sources":["../../src/webgl-utils/use-program.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGjD;;;;;;;;;;;;GAYG;AACH,SAAS,WAAW,CACR,SAAoB,EACpB,IAAY,EACZ,IAAY,EACZ,IAAY;IAEpB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAEnC,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACjB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,UAAU,GAAkC,EAAE,CAAC;IACrD,MAAM,QAAQ,GAAoD,EAAE,CAAC;IACrE,MAAM,aAAa,GAAqC,EAAE,CAAC;IAE3D,MAAM,OAAO,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IACnC,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IACpE,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IACtE,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAExB,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;IAEtE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAGD,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ *
3
+ * @param glContext
4
+ * @param textureIndex the texture index to use on the GPU
5
+ * @param name a custom name to give to the texture for caching
6
+ */
7
+ function useTexture(glContext, textureIndex, name) {
8
+ const { gl, textures } = glContext;
9
+ gl.activeTexture(gl.TEXTURE0 + textureIndex);
10
+ let texture = textures[name];
11
+ if (!texture) {
12
+ texture = textures[name] = { tex: gl.createTexture() };
13
+ gl.bindTexture(gl.TEXTURE_2D, texture.tex);
14
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
15
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
16
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
17
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
18
+ }
19
+ else {
20
+ gl.bindTexture(gl.TEXTURE_2D, texture.tex);
21
+ }
22
+ return texture;
23
+ }
24
+ export { useTexture };
25
+ //# sourceMappingURL=use-texture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-texture.js","sourceRoot":"","sources":["../../src/webgl-utils/use-texture.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,SAAS,UAAU,CACX,SAAoB,EACpB,YAAoB,EACpB,IAAY;IAEhB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IACnC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,GAAG,YAAY,CAAC,CAAC;IAC7C,IAAI,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,aAAa,EAAE,EAAE,CAAC;QACvD,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3C,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;QACnE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;QACnE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC;QACrE,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC;IACzE,CAAC;SAAM,CAAC;QACJ,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAGD,OAAO,EAAE,UAAU,EAAE,CAAA"}
package/package.json CHANGED
@@ -2,14 +2,14 @@
2
2
  "name": "webgl2-sdf",
3
3
  "sideEffects": false,
4
4
  "description": "Fast sdf generator from bezier curves or svg string.",
5
- "version": "0.0.1",
5
+ "version": "0.0.2",
6
6
  "author": {
7
7
  "name": "Floris Steenkamp"
8
8
  },
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "main": "./dist/index.js",
12
- "exports": "./dist/index.js",
11
+ "main": "./node/index.js",
12
+ "exports": "./node/index.js",
13
13
  "engines": {
14
14
  "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
15
15
  },
@@ -29,8 +29,7 @@
29
29
  "webgl",
30
30
  "webgl2"
31
31
  ],
32
- "dependencies": {
33
- },
32
+ "dependencies": {},
34
33
  "devDependencies": {
35
34
  "@types/node": "^25.0.9",
36
35
  "c8": "^10.1.3",
@@ -1,9 +0,0 @@
1
- /**
2
- *
3
- * @param gl
4
- * @param type `gl.VERTEX_SHADER | gl.FRAGMENT_SHADER`
5
- * @param shaderStr
6
- */
7
- declare function debugGlsl(gl: WebGL2RenderingContext, type: typeof gl.VERTEX_SHADER | typeof gl.FRAGMENT_SHADER, shaderStr: string): void;
8
- declare function debugShaders(gl: WebGL2RenderingContext): void;
9
- export { debugShaders, debugGlsl };
@@ -1,11 +0,0 @@
1
- /**
2
- * Represents the max distance (in cell side length units) from one corner of
3
- * the viewbox to the opposing corner.
4
- */
5
- declare const circsCache: Range[];
6
- interface Range {
7
- readonly from: number;
8
- readonly u: number;
9
- readonly v: number;
10
- }
11
- export { circsCache };
@@ -1,14 +0,0 @@
1
- import type { Cell } from "../types/cell";
2
- /**
3
- * Clips a line segment to grid boundaries and returns multiple segments.
4
- *
5
- * * modifies grid by adding line segments to cells
6
- * * size/count *must* be a power of 2
7
- *
8
- * @param count the number of grid cells per dimension
9
- * @param width
10
- * @param height
11
- * @param seg the line segment (array of 2 points)
12
- */
13
- declare function clipLineSegmentToGrid(grid: Cell[][], width: number, height: number, colCount: number, cellSize: number, seg: number[][], padCount: number): void;
14
- export { clipLineSegmentToGrid };
@@ -1,13 +0,0 @@
1
- import type { Strip } from "../types/strip";
2
- /**
3
- * Clips a line segment to strip boundaries and returns multiple segments.
4
- *
5
- * * modifies strips by adding line segments to each strip
6
- * * size/count *must* be a power of 2
7
- *
8
- * @param count the number of strips
9
- * @param height the height of a strip
10
- * @param seg the line segment (array of 2 points)
11
- */
12
- declare function clipLineSegmentToStrips(strips: Strip[], height: number, seg: number[][]): void;
13
- export { clipLineSegmentToStrips };
@@ -1,8 +0,0 @@
1
- import { Cell } from "../types/cell";
2
- /**
3
- *
4
- * @param colCount
5
- * @param padCount
6
- */
7
- declare function createEmptyGrid(colCount: number, padCount: number): Cell[][];
8
- export { createEmptyGrid };
@@ -1,7 +0,0 @@
1
- import { Strip } from "../types/strip";
2
- /**
3
- *
4
- * @param count the number of strips
5
- */
6
- declare function createEmptyStrips(): Strip[];
7
- export { createEmptyStrips };
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns the minimum distance from the given line segment to the origin.
3
- */
4
- declare function distanceSegToP(seg: number[][], p: number[]): number;
5
- export { distanceSegToP };
@@ -1,3 +0,0 @@
1
- import type { Cell } from "../types/cell";
2
- declare function findCloseCells(grid: Cell[][], colCount: number, cellSize: number, maxDistance: number, padCount: number): void;
3
- export { findCloseCells };
@@ -1,3 +0,0 @@
1
- import type { Cell } from "../types/cell";
2
- declare function findCrossingCells(grid: Cell[][], colCount: number, padCount: number): void;
3
- export { findCrossingCells };
@@ -1,10 +0,0 @@
1
- /**
2
- * Returns a function that returns the signed distance to the given line from
3
- * the given point.
4
- *
5
- * @param pS a point on the line
6
- * @param pE a different point on the line; if `pS` is the same as `pE` then
7
- * the distance to the point `pS` (or `pE`) will be returned.
8
- */
9
- declare function getDistanceToLineFunction(pS: number[], pE: number[]): (p: number[]) => number;
10
- export { getDistanceToLineFunction };
@@ -1,2 +0,0 @@
1
- declare function jumpIdx(c: number): number;
2
- export { jumpIdx };
@@ -1,2 +0,0 @@
1
- declare function mapToViewbox(viewbox: [number, number, number, number], width: number, height: number, psss: (number[][])[][]): (number[][])[][];
2
- export { mapToViewbox };
@@ -1,10 +0,0 @@
1
- /**
2
- * Returns the ordered (by t-value) intersection points of the given line
3
- * segment and square.
4
- *
5
- * @param seg a line segment given by its endpoints
6
- * @param square a square given by its two opposing corner points, min-x, min-y
7
- * first
8
- */
9
- declare function segBoxX(seg: number[][], square: number[][]): number[][];
10
- export { segBoxX };
@@ -1,9 +0,0 @@
1
- /**
2
- * Returns the ordered (by t-value) intersection points of the given line
3
- * segment and half-open strip.
4
- *
5
- * @param seg a line segment given by its endpoints
6
- * @param strip a half-open strip given by max-x, min-y, max-y
7
- */
8
- declare function segStripX(seg: number[][], strip: number[]): number[][];
9
- export { segStripX };
package/node/webgl2.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare function generateIntoFramebuffer(gl: WebGL2RenderingContext, psss: (number[][])[][] | string, width: number, height: number, viewbox: [number, number, number, number], maxDistance: number, sdfExponent?: number, inclInside?: boolean, inclOutside?: boolean, x?: number, y?: number, channel?: number, resolution?: 0.5 | 1): void;
2
- export { generateIntoFramebuffer };