Skip to content

Commit

Permalink
do not record additional point on beginStroke and endStroke
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubfiala committed Jan 18, 2024
1 parent a225d22 commit db7242e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
1 change: 0 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ atrament.addEventListener('strokeend', () => log('event: strokeend'));

atrament.addEventListener('strokerecorded', ({ stroke }) => {
log(`event: strokerecorded - ${stroke.points.length} points`);

setRecorded(stroke);

atrament.recordStrokes = false;
Expand Down
6 changes: 3 additions & 3 deletions demo/recording.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const setRecorded = (stroke) => Object.assign(recordedStroke, stroke);

export const playRecorded = async (atrament) => {
// offset the drawing to avoid drawing at the exact same place
const offsetX = Math.floor(Math.random() * 100) - 50;
const offsetY = Math.floor(Math.random() * 100) - 50;
const offsetX = 0;// Math.floor(Math.random() * 100) - 50;
const offsetY = 0;// Math.floor(Math.random() * 100) - 50;

// set drawing options
/* eslint-disable no-param-reassign */
Expand All @@ -35,7 +35,7 @@ export const playRecorded = async (atrament) => {
atrament.beginStroke(prevPoint.x, prevPoint.y);

// eslint-disable-next-line no-restricted-syntax
for (const point of recordedStroke.points.slice(1)) {
for (const point of recordedStroke.points) {
// waiting for time from reference
// eslint-disable-next-line no-await-in-loop
await waitUntil(reference, point.time);
Expand Down
11 changes: 0 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ export default class Atrament extends AtramentEventTarget {

if (this.recordStrokes) {
this.strokeTimestamp = performance.now();
this.#strokeMemory.push({
point: new Point(x, y),
time: performance.now() - this.strokeTimestamp,
});
}

this.dispatchEvent('strokestart', { x, y });
Expand All @@ -97,13 +93,6 @@ export default class Atrament extends AtramentEventTarget {
*/
endStroke(x, y) {
this.#context.closePath();

if (this.recordStrokes) {
this.#strokeMemory.push({
point: new Point(x, y),
time: performance.now() - this.strokeTimestamp,
});
}
this.dispatchEvent('strokeend', { x, y });

if (this.recordStrokes) {
Expand Down

0 comments on commit db7242e

Please sign in to comment.