Skip to content

Commit

Permalink
chore: remove lodash.isEqual in favor of simple isSameCoordinate cust…
Browse files Browse the repository at this point in the history
…om function on helper file
  • Loading branch information
dornelasnelson committed Jan 2, 2024
1 parent d68fd97 commit 2486bea
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = {
'!**/*.d.ts'
],
roots: ['<rootDir>/src'],
collectCoverageFrom: [
'src/modules/**/*.{ts,tsx}',
'!**/node_modules/**'
],
// collectCoverageFrom: [
// 'src/modules/**/*.{ts,tsx}',
// '!**/node_modules/**'
// ],
};
16 changes: 0 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@mapbox/geojsonhint": "^3.1.0",
"leaflet-path-drag": "^1.8.0-beta.3",
"lodash.flatten": "^4.4.0",
"lodash.isequal": "^4.5.0",
"react-undo-redo": "^3.0.0"
},
"devDependencies": {
Expand All @@ -68,7 +67,6 @@
"@types/jest": "^29.4.0",
"@types/leaflet": "^1.9.1",
"@types/lodash.flatten": "^4.4.7",
"@types/lodash.isequal": "^4.5.6",
"@types/node": "^18.14.2",
"@types/react": "^18.0.28",
"@types/react-leaflet": "^3.0.0",
Expand Down
13 changes: 8 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LatLng, LatLngBounds, LatLngTuple } from 'leaflet';
import isEqual from 'lodash.isequal';

import { Coordinate } from './types';

Expand Down Expand Up @@ -30,7 +29,7 @@ export const subtractCoordinates = (coordA: Coordinate, coordB: Coordinate): Coo
});

export const isPolygonClosed = (coordinates: Coordinate[]): boolean =>
coordinates && coordinates.length > 2 && isEqual(coordinates[0], coordinates[coordinates.length - 1]);
coordinates && coordinates.length > 2 && isSameCoordinate(coordinates[0], coordinates[coordinates.length - 1]);

export const isClosingPointsSelected = (coordinates: Coordinate[], selection: Set<number>): boolean =>
isPolygonClosed(coordinates) && (selection.has(coordinates.length - 1) || selection.has(0));
Expand Down Expand Up @@ -74,14 +73,18 @@ export const movePolygonCoordinates = (
});
};

const isSameCoordinate = (firstCoordinate: Coordinate, secondCoordinate: Coordinate) =>
firstCoordinate.latitude === secondCoordinate.latitude &&
firstCoordinate.longitude === secondCoordinate.longitude;

export const removeSelectedPoints = (polygonCoordinates: Coordinate[], selectedPoints: Set<number>) => {
const newPolygonCoordinates = polygonCoordinates.filter((polygonCoordinate, index) => !selectedPoints.has(index));
const isOldPathClosed =
polygonCoordinates.length > 1 &&
isEqual(polygonCoordinates[0], polygonCoordinates[polygonCoordinates.length - 1]);
isSameCoordinate(polygonCoordinates[0], polygonCoordinates[polygonCoordinates.length - 1]);
const isNewPathClosed =
newPolygonCoordinates.length > 1 &&
isEqual(newPolygonCoordinates[0], newPolygonCoordinates[newPolygonCoordinates.length - 1]);
isSameCoordinate(newPolygonCoordinates[0], newPolygonCoordinates[newPolygonCoordinates.length - 1]);

// Open closed path if it has 3 points or less
if (newPolygonCoordinates.length < 4 && isNewPathClosed) {
Expand Down Expand Up @@ -114,7 +117,7 @@ export const getCenterCoordinate = (coordA: Coordinate, coordB: Coordinate): Coo
// Returns the center coordinates of the polygon edges
export const getPolygonEdges = (polygon: Coordinate[]) =>
polygon.reduce<Coordinate[]>((edges, coordinate, index) => {
if (index === 0 || isEqual(polygon[index], polygon[index - 1])) {
if (index === 0 || isSameCoordinate(polygon[index], polygon[index - 1])) {
return edges;
}
edges.push(getCenterCoordinate(polygon[index], polygon[index - 1]));
Expand Down

0 comments on commit 2486bea

Please sign in to comment.