Skip to content
Snippets Groups Projects
Commit 289ac9dd authored by Yuriy Maksymets's avatar Yuriy Maksymets
Browse files

Recognition refactoing

parent 47ad7d8e
No related branches found
No related tags found
No related merge requests found
...@@ -145,7 +145,9 @@ const onRoomConnect = (room_) => { ...@@ -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) { function attributedPoint(x, y, pressure = 0) {
return [ return [
...@@ -156,24 +158,28 @@ function attributedPoint(x, y, pressure = 0) { ...@@ -156,24 +158,28 @@ function attributedPoint(x, y, pressure = 0) {
] ]
} }
const INF_LINE_OFFSET = 2000
function getRecognizedShapePoints(points) { function getRecognizedShapePoints(points) {
const recognizedShape = recognizeFromPoints(points) const recognizedShape = recognizeFromPoints(points)
if (recognizedShape.shape === Shapes.line) { if (!recognizedShape.shape) return undefined
console.log(recognizedShape) switch (recognizedShape.shape) {
const [x, y] = points[0] case Shapes.line: {
const a = (recognizedShape.angle * Math.PI) / 180 const [x, y] = points[0]
const p1 = [x - 2000 * Math.cos(a), y + 2000 * Math.sin(a)] const a = (recognizedShape.angle * Math.PI) / 180
const p2 = [x + 2000 * Math.cos(a), y - 2000 * Math.sin(a)] const dx = INF_LINE_OFFSET * Math.cos(a)
return [p1, p2] const dy = INF_LINE_OFFSET * Math.sin(a)
} else if (recognizedShape.shape === Shapes.rectangle) { const p1 = [x - dx, y + dy]
console.log(recognizedShape) const p2 = [x + dx, y - dy]
return recognizedShape.boundingPoints return [p1, p2]
}
case Shapes.rectangle: {
return recognizedShape.boundingPoints
}
} }
return undefined return undefined
} }
const LAST_RECOGNIZED_PATH_ID = "LSP"
function drawIfRecognized(points, callback, notRecCallback) { function drawIfRecognized(points, callback, notRecCallback) {
const recognizedPoints = getRecognizedShapePoints(points) const recognizedPoints = getRecognizedShapePoints(points)
if (recognizedPoints) { if (recognizedPoints) {
...@@ -183,6 +189,8 @@ function drawIfRecognized(points, callback, notRecCallback) { ...@@ -183,6 +189,8 @@ function drawIfRecognized(points, callback, notRecCallback) {
} }
} }
const LAST_RECOGNIZED_PATH_ID = "LSP"
function clearRecognizedUpcoming() { function clearRecognizedUpcoming() {
canvas.renderPath(LAST_RECOGNIZED_PATH_ID, []) canvas.renderPath(LAST_RECOGNIZED_PATH_ID, [])
} }
...@@ -193,7 +201,7 @@ function drawRecognizedUpcoming(points) { ...@@ -193,7 +201,7 @@ function drawRecognizedUpcoming(points) {
(recognizedPoints) => (recognizedPoints) =>
canvas.renderPath( canvas.renderPath(
LAST_RECOGNIZED_PATH_ID, LAST_RECOGNIZED_PATH_ID,
recognizedPoints.map((x) => mp(...x)), recognizedPoints.map((x) => faintPoint(...x)),
), ),
clearRecognizedUpcoming, clearRecognizedUpcoming,
) )
......
...@@ -54,7 +54,7 @@ class Room extends EventTarget { ...@@ -54,7 +54,7 @@ class Room extends EventTarget {
[flattenErasureIntervals({ [pointID]: newIntervals })], [flattenErasureIntervals({ [pointID]: newIntervals })],
)[0] )[0]
const postJSON = JSON.stringify(combinedIntervals) const postJSON = JSON.stringify(combinedIntervals)
console.log(postJSON)
if (prevJSON == postJSON) { if (prevJSON == postJSON) {
return return
} }
...@@ -63,6 +63,7 @@ class Room extends EventTarget { ...@@ -63,6 +63,7 @@ class Room extends EventTarget {
}) })
} }
// TODO: Refactor duplication
replacePath(pathID, newPoints) { replacePath(pathID, newPoints) {
const self = this const self = this
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment