geolib
geolib copied to clipboard
getAreaOfPolygon returns a number when I pass an unclosed area
Hi dear reader, When I execute this code IDK why but for some reason for the second one also returns a number though it is not even a closed area. So my question is that if this is an expected behaviour and OK. BTW based on my understanding it should not work like that, I mean it is not even a closed are to begin with:
const geolib = require("geolib");
// 1
console.log(
geolib.getAreaOfPolygon([
[7.453635617650258, 51.49320556213869],
[7.454583481047989, 51.49328893754685],
[7.454778172179346, 51.49240881084831],
[7.453832678225655, 51.49231619246726],
[7.453635617650258, 51.49320556213869],
])
);
// 2
console.log(
geolib.getAreaOfPolygon([
{
latitude: -72.2781577,
longitude: 42.9288483,
},
{
latitude: -72.2864358,
longitude: 42.928252,
},
{
latitude: -72.2877233,
longitude: 42.9247012,
},
{
latitude: -72.2817152,
longitude: 42.9237898,
},
])
);
Here is what I meant by not closed area, as you can see in the uploaded image the starting point - the first point on the right top corner - is not even close to the ending point -- the last point in the bottom right corner:
Here is my work env conf:
geolib: 3.3.4
node: 20.3.1
npm: 9.6.7
OS: Darwin Kernel Version 22.5.0 arm64
Can you please let me know if this is a bug or not dear @manuelbieh? IMO it is but still it is a good idea to be sure 😅
OK, I am coming from the future. In this part of code we are closing it https://github.com/manuelbieh/geolib/blob/26ec179e861750623d496a962465e5c399664efd/src/getAreaOfPolygon.ts#L16-L36
Though IMO this is not OK, and also the documentation lacks clarity about these kind of underlying implementations.
I hope someone will just address this GitHub issue