gabzim / circle-to-polygon

Receives a Coordinate, a Radius and a Number of edges and aproximates a circle by creating a polygon that fills its area
ISC License
113 stars 29 forks source link

Coordinates with 3 elements cause error. #10

Closed mdurling closed 4 years ago

mdurling commented 4 years ago

In version 2.0.0, the validateCenter function fails when passing a 3rd element (altitude/elevation) as the center point:

if (!Array.isArray(center) || center.length !== 2) {
  throw new Error("ERROR! Center has to be an array of length two");
}

From RFC 7946

A position is an array of numbers. There MUST be two or more elements. The first two elements are longitude and latitude, or easting and northing, precisely in that order and using decimal numbers. Altitude or elevation MAY be included as an optional third element.

From @types/geojson

/**
 * A Position is an array of coordinates.
 * https://tools.ietf.org/html/rfc7946#section-3.1.1
 * Array should contain between two and three elements.
 * The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values),
 * but the current specification only allows X, Y, and (optionally) Z to be defined.
 */
export type Position = number[]; // [number, number] | [number, number, number];

The center validation check should be something similar to this:

if (!Array.isArray(center) || ![2,3].includes(center.length)) {
  throw new Error("ERROR! Center has to be an array of length two or three");
}
johachi commented 4 years ago

You are correct. Sorry if this has caused you any problem. I will fix this asap (= hopefully within a few hours when I'm at my computer again).