Skip to content

Commit 55dc530

Browse files
committed
fix: correct pinchZoom distance calculation and Y-axis offset
- Fixed Math.sqrt() using comma instead of addition for Pythagorean distance - Fixed Yf calculation using globalScope.ox instead of globalScope.oy These were pre-existing bugs that broke pinch-zoom functionality.
1 parent 4140ebe commit 55dc530

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/simulator/src/listeners.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ export function pinchZoom(e, globalScope) {
129129
updatePositionSet(true)
130130
updateCanvasSet(true)
131131
// Calculating distance between touch to see if its pinchIN or pinchOut
132-
distance = Math.sqrt(
133-
(e.touches[1].clientX - e.touches[0].clientX) ** 2,
134-
(e.touches[1].clientY - e.touches[0].clientY) ** 2
135-
)
132+
const dx = e.touches[1].clientX - e.touches[0].clientX
133+
const dy = e.touches[1].clientY - e.touches[0].clientY
134+
distance = Math.sqrt(dx * dx + dy * dy)
136135
if (distance >= currDistance) {
137136
pinchZ += 0.02
138137
currDistance = distance
@@ -155,7 +154,7 @@ export function pinchZoom(e, globalScope) {
155154
const RawX = (centreX - rect.left) * DPR
156155
const RawY = (centreY - rect.top) * DPR
157156
const Xf = Math.round((RawX - globalScope.ox) / globalScope.scale / unit)
158-
const Yf = Math.round((RawY - globalScope.ox) / globalScope.scale / unit)
157+
const Yf = Math.round((RawY - globalScope.oy) / globalScope.scale / unit)
159158
const currCentreX = Math.round(Xf / unit) * unit
160159
const currCentreY = Math.round(Yf / unit) * unit
161160
globalScope.ox = Math.round(currCentreX * (globalScope.scale - oldScale))

0 commit comments

Comments
 (0)