diff --git a/src/app.js b/src/app.js index 28e4e12bccf9a05c7bc9626632617303da71b7a0..94e64a2e9c1b67227c17b7aa247747e1ed204535 100644 --- a/src/app.js +++ b/src/app.js @@ -45,19 +45,23 @@ const getPressureFactor = (pressure) => { return a * pressure ** 2 + b * pressure + c } -function faintPoint(x, y) { - return [x, y, 1, PREDICTED_POINT_COLOR] -} - -function attributedPoint(x, y, pressure = 0) { +function selectedRadiusPoint(x, y, color, pressure = 0) { return [ x, y, toolSelection.getStrokeRadius() * getPressureFactor(pressure), - toolSelection.getStrokeColour(), + color, ] } +function faintPredictionPoint(x, y, pressure = 0) { + return selectedRadiusPoint(x, y, PREDICTED_POINT_COLOR, pressure) +} + +function selectedColorAndRadiusPoint(x, y, pressure = 0) { + return selectedRadiusPoint(x, y, toolSelection.getStrokeColour(), pressure) +} + function eraseEverythingAtPosition(x, y, radius, room) { const mousePos = [x, y] room.getPaths().forEach((points, pathID) => { @@ -218,24 +222,28 @@ function clearRecognizedUpcoming() { canvas.renderPath(LAST_RECOGNIZED_PATH_ID, [], []) } -function drawRecognizedUpcoming(points) { +function drawRecognizedUpcoming(points, pressure) { drawIfRecognized( points, (recognizedPoints) => canvas.renderPath( LAST_RECOGNIZED_PATH_ID, - recognizedPoints.map((x) => faintPoint(...x)), + recognizedPoints.map((point) => + faintPredictionPoint(point[0], point[1], pressure), + ), [], ), clearRecognizedUpcoming, ) } -function drawRecognized(pathID, points) { +function drawRecognized(pathID, points, pressure) { drawIfRecognized(points, (newPoints) => room.replacePath( pathID, - newPoints.map((x) => attributedPoint(...x)), + newPoints.map((point) => + selectedColorAndRadiusPoint(point[0], point[1], pressure), + ), ), ) clearRecognizedUpcoming() @@ -403,11 +411,12 @@ canvas.input.addEventListener("strokestart", ({ detail: e }) => { }) canvas.input.addEventListener("strokeend", ({ detail: e }) => { - const pathID = pathIDsByPointerID.get(e.pointerId) + const { pressure, pointerId } = e + const pathID = pathIDsByPointerID.get(pointerId) if (toolSelection.isRecognitionModeSet()) { - drawRecognized(pathID, room.getPoints(pathID)) + drawRecognized(pathID, room.getPoints(pathID), pressure) } - pathIDsByPointerID.delete(e.pointerId) + pathIDsByPointerID.delete(pointerId) clearRecognizedUpcoming() }) @@ -419,10 +428,12 @@ canvas.input.addEventListener("strokemove", ({ detail: e }) => { const mousePos = [e.offsetX, e.offsetY] if (currentTool == toolSelection.Tools.PEN) { const pathID = pathIDsByPointerID.get(e.pointerId) - room.extendPath(pathID, attributedPoint(...mousePos, e.pressure)) + room.extendPath( + pathID, + selectedColorAndRadiusPoint(...mousePos, e.pressure), + ) if (toolSelection.isRecognitionModeSet()) { - console.log("SHULD DR") - drawRecognizedUpcoming(room.getPoints(pathID)) + drawRecognizedUpcoming(room.getPoints(pathID), e.pressure) } } else if (currentTool == toolSelection.Tools.ERASER) { eraseEverythingAtPosition( diff --git a/src/shapes.js b/src/shapes.js index e3fc050351f9c220bbb729404c113c7c81eb7a2b..213b02be1da496e96afbaed22131e2f802236130 100644 --- a/src/shapes.js +++ b/src/shapes.js @@ -90,7 +90,6 @@ export function computeMatrixCoefficients(points, boundingRect) { const xBounds = matrixBoundsArray(minX, maxX) const yBounds = matrixBoundsArray(minY, maxY) const clusters = computeClusters(points, xBounds, yBounds) - console.log(clusters) const coefficients = clusterCoefficients(clusters, points) return coefficients }