dartclub / turf_dart

A turf.js-like geospatial analysis library working with GeoJSON, written in pure Dart.
https://pub.dev/packages/turf
MIT License
67 stars 30 forks source link

Feature reducers #49

Closed baparham closed 2 years ago

baparham commented 2 years ago



lukas-h commented 2 years ago

48 is merged, so nothing stands in the way of implementing the functions! 😄

CC @armantorkzaban

armantorkzaban commented 2 years ago

I am currently working on this one.

lukas-h commented 2 years ago

@armantorkzaban

We have to make a technical decision about the types of the reducer functions. I thought of two ways to handle it.

  1. dynamic types: The previousValue will be initialized if initialValue==null with currentProperties, currentGeometry, a.s.o., like in the original JS version and also like in Arman’s and Brad’s initial versions. We will drop the generic types to not limit it to geodata-related data types.

  2. generic types: Very clean, but we break a little bit with Turf.js-compatibility: We don’t have the if-clause to initialize previousValue if initialValue==null. I’ve implemented that in the latest commit to this branch.

You can see in the diff of the latest commit clearly the two concepts 1 & 2

Let’s decide together!

lukas-h commented 2 years ago

We now decided for a different approach, where we don't lose any type information and are entirely compatible with TurfJS! But in this version, we added another type check to the functions:

      if (previousValue == null && featureIndex == 0 && currentGeometry is T) {
        previousValue = currentGeometry?.clone() as T;
      } else {
lukas-h commented 2 years ago

@armantorkzaban For the unit tests, please look at geomReduce, Brad did a great job there. I added some lines to test the behavior with dynamic types.

TurfJS may also have some good inspiration for the tests..