Rename zoom anchor variables for clarity

Signed-off-by: Robin Townsend <robin@robin.town>
This commit is contained in:
Robin Townsend 2021-07-22 09:48:56 -04:00
parent 875b46bacb
commit 9e0720a6c4

View file

@ -160,11 +160,11 @@ export default class ImageView extends React.Component<IProps, IState> {
}); });
}; };
private zoomDelta(delta: number, zoomX?: number, zoomY?: number) { private zoomDelta(delta: number, anchorX?: number, anchorY?: number) {
this.zoom(this.state.zoom + delta, zoomX, zoomY); this.zoom(this.state.zoom + delta, anchorX, anchorY);
} }
private zoom(zoomLevel: number, zoomX?: number, zoomY?: number) { private zoom(zoomLevel: number, anchorX?: number, anchorY?: number) {
const oldZoom = this.state.zoom; const oldZoom = this.state.zoom;
const newZoom = Math.min(zoomLevel, this.state.maxZoom); const newZoom = Math.min(zoomLevel, this.state.maxZoom);
@ -175,7 +175,7 @@ export default class ImageView extends React.Component<IProps, IState> {
translationX: 0, translationX: 0,
translationY: 0, translationY: 0,
}); });
} else if (typeof zoomX !== "number" && typeof zoomY !== "number") { } else if (typeof anchorX !== "number" && typeof anchorY !== "number") {
// Zoom relative to the center of the view // Zoom relative to the center of the view
this.setState({ this.setState({
zoom: newZoom, zoom: newZoom,
@ -190,20 +190,20 @@ export default class ImageView extends React.Component<IProps, IState> {
let offsetY; let offsetY;
switch (((this.state.rotation % 360) + 360) % 360) { switch (((this.state.rotation % 360) + 360) % 360) {
case 0: case 0:
offsetX = this.image.current.clientWidth / 2 - zoomX; offsetX = this.image.current.clientWidth / 2 - anchorX;
offsetY = this.image.current.clientHeight / 2 - zoomY; offsetY = this.image.current.clientHeight / 2 - anchorY;
break; break;
case 90: case 90:
offsetX = zoomY - this.image.current.clientHeight / 2; offsetX = anchorY - this.image.current.clientHeight / 2;
offsetY = this.image.current.clientWidth / 2 - zoomX; offsetY = this.image.current.clientWidth / 2 - anchorX;
break; break;
case 180: case 180:
offsetX = zoomX - this.image.current.clientWidth / 2; offsetX = anchorX - this.image.current.clientWidth / 2;
offsetY = zoomY - this.image.current.clientHeight / 2; offsetY = anchorY - this.image.current.clientHeight / 2;
break; break;
case 270: case 270:
offsetX = this.image.current.clientHeight / 2 - zoomY; offsetX = this.image.current.clientHeight / 2 - anchorY;
offsetY = zoomX - this.image.current.clientWidth / 2; offsetY = anchorX - this.image.current.clientWidth / 2;
} }
// Apply the zoom and offset // Apply the zoom and offset