mirror of
https://github.com/Doodle3D/Doodle3D-Core.git
synced 2025-04-20 17:56:24 +02:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import update from 'react-addons-update';
|
|
import { Matrix } from 'cal';
|
|
import constrainMatrix from './constrainMatrix.js';
|
|
import { calculateGestureMatrix } from '../../utils/matrixUtils.js';
|
|
import * as actions from '../../actions/index.js';
|
|
import createDebug from 'debug';
|
|
const debug = createDebug('d3d:reducer:d2:pinchZoom');
|
|
|
|
export default function pinchZoomReducer(state, action) {
|
|
if (action.log !== false) debug(action.type);
|
|
|
|
switch (action.type) {
|
|
case actions.CLEAR:
|
|
return update(state, {
|
|
d2: { canvasMatrix: { $set: new Matrix() } }
|
|
});
|
|
|
|
case actions.D2_MULTITOUCH:
|
|
return multitouch(state, action);
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
function multitouch(state, { positions, previousPositions, screenMatrixContainer }) {
|
|
const gestureMatrix = calculateGestureMatrix(positions, previousPositions, screenMatrixContainer, {
|
|
rotate: false, scale: true, pan: true
|
|
});
|
|
|
|
const { canvasMatrix } = state.d2;
|
|
const matrix = canvasMatrix.multiplyMatrix(gestureMatrix);
|
|
|
|
constrainMatrix(matrix);
|
|
|
|
return update(state, {
|
|
d2: {
|
|
canvasMatrix: { $set: matrix }
|
|
}
|
|
});
|
|
}
|