diff --git a/client/aux.js b/client/aux.js new file mode 100644 index 0000000..1ff534b --- /dev/null +++ b/client/aux.js @@ -0,0 +1,9 @@ +function find_touch(touchlist, id) { + for (const touch of touchlist) { + if (touch.identifier === id) { + return touch; + } + } + + return null; +} \ No newline at end of file diff --git a/client/math.js b/client/math.js index 938c3bb..d542a75 100644 --- a/client/math.js +++ b/client/math.js @@ -1,3 +1,11 @@ +function screen_to_canvas(state, p) { + // should be called with coordinates obtained from MouseEvent.clientX/clientY * window.devicePixelRatio + const xc = (p.x - state.canvas.offset.x) / state.canvas.zoom; + const yc = (p.y - state.canvas.offset.y) / state.canvas.zoom; + + return {'x': xc, 'y': yc}; +} + function point_right_of_line(a, b, p) { // a bit of cross-product tomfoolery (we check sign of z of the crossproduct) return ((b.x - a.x) * (a.y - p.y) - (a.y - b.y) * (p.x - a.x)) <= 0; @@ -229,6 +237,13 @@ function dist_v2(a, b) { return Math.sqrt(dx * dx + dy * dy); } +function mid_v2(a, b) { + return { + 'x': (a.x + b.x) / 2.0, + 'y': (a.y + b.y) / 2.0, + }; +} + function perpendicular(ax, ay, bx, by, width) { // Place points at (stroke_width / 2) distance from the line const dirx = bx - ax; diff --git a/client/webgl.html b/client/webgl.html index 99a5e0a..8bc937c 100644 --- a/client/webgl.html +++ b/client/webgl.html @@ -5,12 +5,13 @@