Closed johachi closed 4 years ago
I'm closing this PR since it's quite big and contain some things that is not connected to the issue. I will instead break the PR into several smaller PR's that are much more easy to check. Easier to check several small PR's with small changed than one big PR.
This PR extends
circleToPolygon
so the function accepts center coordinate either as anarray
or as anobject
. Behavior is unchanged when the center coordinate is anarray
.Key-pair priorization
Passing the
lat
andlon
values in an object causes the complication that the object can contain more than two keys, and some of the keys might seem to be duplicates (eg:{ lat, latitude, longitude }
, where lat does not mean "latitude").This problem can be solved in several ways. I chose to solve it by looking for complete key-pairs. The first found complete key-par is being used (no matter if the keys has the correct values or not). Key pairs are being looked for in the following order:
{ lat: latValue, lon: lonValue }
{ lat: latValue, lng: lonValue }
{ latitude: latValue, longitude: lonValue }
In other words;
{ lat: 0, latitude: 1, lng: 3, lon: 4, longitude: 5 }
will be interpreted as[4, 0]
{ lat: 6, latitude: 7, lng: 8, longitude: 9 }
will be interpreted as[8, 6]
{ lat: 10, latitude: 11, longitude 12 }
will be interpreted as[12, 11]
{ lat: "there", latitude: 1, lng: 3, lon: "hello", longitude: 5 }
will be interpreted as["hello", "there"]
Error handling
No valid key pairs
circleToPolygon
will throw an error if no complete key pairs are found (when center argument is an object).In other words, the following key pairs will throw an error:
{ lat, longitude}
{ lng, latitude }
{ log, latitude }
No valid values
An error will be thrown if the first found complete key pair does not have the correct type or values. For example:
{ lat: "General" lon: "Kenobi", latitude: 120.827492, longitude: 40.729362 }
will throw an error sincelat/lon
is used instead oflatitude/longitude
Other
I have chose to accept objects such as
{ lat, latitude, longitude }
since maybe it makes sense for someone to have the keylat
in the center object for use somewhere else, idk...I'm wondering if it makes more sense to prioritize the keys pair
latitude/longitude
the highest, instead of lowest...Also, should I have it look for the first valid key-pair instead of the first complete key pair?
I'm open to changing this behavior is requested.
This closes #12 .