Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature generics #76

Open
dellisd opened this issue Mar 10, 2021 · 1 comment
Open

Feature generics #76

dellisd opened this issue Mar 10, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@dellisd
Copy link
Owner

dellisd commented Mar 10, 2021

The class definition for features could be modified to include a generic type parameter to specify what type of geometry a feature holds. e.g.

class Feature<out T : Geometry?>(
    val geometry: T
// Rest of Feature class definition...

val p: Feature<Point> = Feature(Point(...))
p.geometry // is Point

This would facilitate passing Features in to turf functions as noted in #71.

Pros

  • Feature geometry can be made type-safe, reducing the number of runtime type checks on a feature's geometry in some cases
  • The Turf port can take advantage of this allowing for only certain types of features to be passed into some functions

Cons

  • Collections of features often hold many different types of geometry so any type-safety gains from this feature would be lost, and either star-projection or filling the generic type with Geometry or Geometry? repeatedly would be required.
  • Some Turf function signatures will conflict for specialized feature overloads. e.g. length(feature: Feature<?>, ...)

Open Questions

  • Should FeatureCollections have a generic type applied to them too?
FeatureCollection<LineString> // denotes a collection of LineString features
  • Should the properties of the feature class also be made a generic type to allow for type-safe feature properties?
@dellisd dellisd added the enhancement New feature or request label Mar 10, 2021
@dellisd dellisd self-assigned this Mar 10, 2021
@dellisd dellisd pinned this issue Mar 10, 2021
@dellisd dellisd mentioned this issue Mar 10, 2021
@elcolto
Copy link
Contributor

elcolto commented May 5, 2024

Regarding the cons, is it despite to use a generic type parameter? Then I'd like to open a PR for it. I think a FeatureCollection shouldn't have a generic type parameter. Cause the features could be polymorph so in many cases it would be FeatureCollection<Geometry>, which may be some overhead to define it every time. Even on updating/edit a collection this type parameter may have to be updated, this is unhandy on consumer side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants