diff --git a/src/app.js b/src/app.js index a848c2b051070c67e518b4f05017b1d020b05198..2b3f9b3a3a02ba6bc899a9d4331db783c9ba187d 100644 --- a/src/app.js +++ b/src/app.js @@ -145,7 +145,9 @@ const onRoomConnect = (room_) => { ) } -const mp = (x, y) => [x, y, 1, "#00000033"] +function faintPoint(x, y) { + return [x, y, 1, "#00000033"] +} function attributedPoint(x, y, pressure = 0) { return [ @@ -156,24 +158,28 @@ function attributedPoint(x, y, pressure = 0) { ] } +const INF_LINE_OFFSET = 2000 + function getRecognizedShapePoints(points) { const recognizedShape = recognizeFromPoints(points) - if (recognizedShape.shape === Shapes.line) { - console.log(recognizedShape) - const [x, y] = points[0] - const a = (recognizedShape.angle * Math.PI) / 180 - const p1 = [x - 2000 * Math.cos(a), y + 2000 * Math.sin(a)] - const p2 = [x + 2000 * Math.cos(a), y - 2000 * Math.sin(a)] - return [p1, p2] - } else if (recognizedShape.shape === Shapes.rectangle) { - console.log(recognizedShape) - return recognizedShape.boundingPoints + if (!recognizedShape.shape) return undefined + switch (recognizedShape.shape) { + case Shapes.line: { + const [x, y] = points[0] + const a = (recognizedShape.angle * Math.PI) / 180 + const dx = INF_LINE_OFFSET * Math.cos(a) + const dy = INF_LINE_OFFSET * Math.sin(a) + const p1 = [x - dx, y + dy] + const p2 = [x + dx, y - dy] + return [p1, p2] + } + case Shapes.rectangle: { + return recognizedShape.boundingPoints + } } return undefined } -const LAST_RECOGNIZED_PATH_ID = "LSP" - function drawIfRecognized(points, callback, notRecCallback) { const recognizedPoints = getRecognizedShapePoints(points) if (recognizedPoints) { @@ -183,6 +189,8 @@ function drawIfRecognized(points, callback, notRecCallback) { } } +const LAST_RECOGNIZED_PATH_ID = "LSP" + function clearRecognizedUpcoming() { canvas.renderPath(LAST_RECOGNIZED_PATH_ID, []) } @@ -193,7 +201,7 @@ function drawRecognizedUpcoming(points) { (recognizedPoints) => canvas.renderPath( LAST_RECOGNIZED_PATH_ID, - recognizedPoints.map((x) => mp(...x)), + recognizedPoints.map((x) => faintPoint(...x)), ), clearRecognizedUpcoming, ) diff --git a/src/room.js b/src/room.js index 6edba8f2fac6239b8d68499ae92b6ec0d9eb4551..af3bfbf9697cfc899b7bb1b7ae31583e12606bd0 100644 --- a/src/room.js +++ b/src/room.js @@ -54,7 +54,7 @@ class Room extends EventTarget { [flattenErasureIntervals({ [pointID]: newIntervals })], )[0] const postJSON = JSON.stringify(combinedIntervals) - console.log(postJSON) + if (prevJSON == postJSON) { return } @@ -63,6 +63,7 @@ class Room extends EventTarget { }) } + // TODO: Refactor duplication replacePath(pathID, newPoints) { const self = this