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

Provide proper coord index #2344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Provide proper coord index #2344

wants to merge 1 commit into from

Conversation

rowanwins
Copy link
Member

I had this case recently where I needed the proper coordinate index for polygons with holes. Currently the callback advertises

turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {

But coordIndex just continually increments up as you work through nested rings so you can't find the coordinate properly using indexing.

So there are two options

  • Add another argument to the callback at the end, which doesn't require a breaking change (that's the approach taken here)
    • if we go down that route I'll probably rename coordIndex to make it more explicit
  • Introduce a breaking change so that coordIndex returns the proper index

In preparing this PR I noticed some comments in the test.js like

// Coord Index => [0, 1, 2, 3, 4] (Major Release Change v6.x)

and
// Coord Index => [0, 1, 2, 3, 4] (Major Release Change v6.x)

So someone intended to go for the breaking change at some stage...

I don't have a strong preference either way.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Have read How To Contribute.
  • Run npm test at the sub modules where changes have occurred.
  • Run npm run lint to ensure code style at the turf module level.

Copy link
Collaborator

@twelch twelch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like your approach taken. coordIndex as-is seems like it has value so it makes sense to me to just leave it and add a new parameter at the end.

The name coordIndex also seems okay, I don't feel strongly a name change is needed. Perhaps a clarification in the docs what it is if missing?

Consider ringIndex instead of indexOnRing for consistency with the other names.

@rowanwins
Copy link
Member Author

Re naming I was thinking coordIndex perhaps could become index, or absoluteIndex?

Consider ringIndex instead of indexOnRing for consistency with the other names.

I think ringIndex could be confusing because it could be interpreted as which ring (eg an outer ring or a hole)... maybe if we do change the name of the 2 argument this could be named coordIndex?

Copy link
Collaborator

@JamesLMilner JamesLMilner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the approach here is good - would be good to update the docs to document indexInRing. I think the naming conventions used make sense and we probably don't need to change coordIndex (happy for others to disagree).

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

Successfully merging this pull request may close these issues.

3 participants