geojson icon indicating copy to clipboard operation
geojson copied to clipboard

[Spike] Allow Position to be (f64, f64) or Vec<f64>

Open frewsxcv opened this issue 5 years ago • 4 comments

frewsxcv avatar Jul 17 '20 03:07 frewsxcv

Potentially 25% faster

Screen Shot 2020-07-16 at 11 18 02 PM

frewsxcv avatar Jul 18 '20 23:07 frewsxcv

Just peeping on your WIP. 👀

Is there any reason to continue supporting vec other than avoiding breaking the old API? For new code, the coord based approach seems strictly better, right?

I was musing if there'd be some way to deprecate the vec based API so people know they're getting the slow impl.

And then also maybe that'd give us a way forward to removing vec based approach one day and remove the generics if it were deprecated for a "long enough" time.

michaelkirk avatar Dec 12 '20 01:12 michaelkirk

Is there any reason to continue supporting vec other than avoiding breaking the old API? For new code, the coord based approach seems strictly better, right?

I was musing if there'd be some way to deprecate the vec based API so people know they're getting the slow impl.

And then also maybe that'd give us a way forward to removing vec based approach one day and remove the generics if it were deprecated for a "long enough" time.

Here's what the spec says:

   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.

   Implementations SHOULD NOT extend positions beyond three elements
   because the semantics of extra elements are unspecified and
   ambiguous.  Historically, some implementations have used a fourth
   element to carry a linear referencing measure (sometimes denoted as
   "M") or a numerical timestamp, but in most situations a parser will
   not be able to properly interpret these values.  The interpretation
   and meaning of additional elements is beyond the scope of this
   specification, and additional elements MAY be ignored by parsers.

Considering the SHOULD NOT usage (as opposed to MUST NOT), I'm thinking we should keep the Vec<f64> option around. I agree though, it's probably overkill for most usages of GeoJSON. I'm guessing most just need two or three item coordinates. Here are the implementations I'm thinking:

  • impl Position for (f64, f64)
  • impl Position for (f64, f64, f64)
  • impl Position for Vec<f64>

Are there others we should consider? (f64, f64, Option<f64>)?

So regarding this PR, my thinking is that it should make all of our types generic over Position, and have everything default to Vec<f64> (e.g. pub enum GeoJson<Pos: Position = Vec<f64>>) to minimize changes for dependent crates. And in the future, after some dust has settled and we feel good about this design, we can change the default from Vec<f64> to something else like (f64, f64).

What do you think?

frewsxcv avatar Dec 12 '20 02:12 frewsxcv

And in the future, after some dust has settled and we feel good about this design, we can change the default from Vec<f64> to something else like (f64, f64).

On second thought, maybe (f64, f64, Option<f64>) would be the safest option will still retaining some performance benefits.

frewsxcv avatar Dec 12 '20 02:12 frewsxcv