Skip to content

getAreaOfPolygon returns a number when I pass an unclosed area #302

@kasir-barati

Description

@kasir-barati

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:
image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions