Skip to content

Commit

Permalink
Bugfix: isPointWithinRadius false even if true
Browse files Browse the repository at this point in the history
Because this function calls getDistance() without an accuracy value, it rounds up to the nearest meter.
  • Loading branch information
patrickpoon-ucberkeley committed Oct 10, 2020
1 parent e88635b commit 249d047
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/isPointWithinRadius.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@ describe('isPointWithinRadius', () => {
)
).toBe(false);
});

it('should return true if a given point is within a certain radius with high accuracy', () => {
expect(
isPointWithinRadius(
{ latitude: 42.53098, longitude: -71.28029 },
{ latitude: 42.53101, longitude: -71.2803986 },
10
)
).toBe(true);
});
});
3 changes: 2 additions & 1 deletion src/isPointWithinRadius.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const isPointWithinRadius = (
center: GeolibInputCoordinates,
radius: number
) => {
return getDistance(point, center) < radius;
const accuracy = 0.01;
return getDistance(point, center, accuracy) < radius;
};

export default isPointWithinRadius;

0 comments on commit 249d047

Please sign in to comment.