chore: Minor refactoring for consistency (#2425)

This commit is contained in:
Lipis 2020-11-29 18:32:51 +02:00 committed by GitHub
parent 204c8370a0
commit b21fd49412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 76 additions and 82 deletions

View file

@ -36,8 +36,8 @@ export const getElementAtPosition = (
// We need to to hit testing from front (end of the array) to back (beginning of the array)
// because array is ordered from lower z-index to highest and we want element z-index
// with higher z-index
for (let i = elements.length - 1; i >= 0; --i) {
const element = elements[i];
for (let index = elements.length - 1; index >= 0; --index) {
const element = elements[index];
if (element.isDeleted) {
continue;
}
@ -68,13 +68,13 @@ export const getElementContainingPosition = (
) => {
let hitElement = null;
// We need to to hit testing from front (end of the array) to back (beginning of the array)
for (let i = elements.length - 1; i >= 0; --i) {
if (elements[i].isDeleted) {
for (let index = elements.length - 1; index >= 0; --index) {
if (elements[index].isDeleted) {
continue;
}
const [x1, y1, x2, y2] = getElementAbsoluteCoords(elements[i]);
const [x1, y1, x2, y2] = getElementAbsoluteCoords(elements[index]);
if (x1 < x && x < x2 && y1 < y && y < y2) {
hitElement = elements[i];
hitElement = elements[index];
break;
}
}

View file

@ -16,4 +16,4 @@ export {
hasText,
getElementsAtPosition,
} from "./comparisons";
export { normalizeZoomValue as getNormalizedZoom, getNewZoom } from "./zoom";
export { getNormalizedZoom, getNewZoom } from "./zoom";

View file

@ -20,7 +20,7 @@ export const getNewZoom = (
};
};
export const normalizeZoomValue = (zoom: number): NormalizedZoomValue => {
export const getNormalizedZoom = (zoom: number): NormalizedZoomValue => {
const normalizedZoom = parseFloat(zoom.toFixed(2));
const clampedZoom = Math.max(0.1, Math.min(normalizedZoom, 2));
return clampedZoom as NormalizedZoomValue;