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

New module @turf/sector #653

Merged
merged 16 commits into from
Apr 12, 2017
Merged

New module @turf/sector #653

merged 16 commits into from
Apr 12, 2017

Conversation

stebogit
Copy link
Collaborator

@stebogit stebogit commented Apr 9, 2017

@DenisCarriere I implemented the turf-sector module (related to #155 and #649).
However I did not create the README file cause I thought it was created automatically from the documentation in the index.js, but it didn't. Should I create it manually?
Not sure if the index.d.ts and bench.js are correct, as I'm not familiar with them.

Is that ok if I created the branch in this repo or should I work on my forked one?

@Adraesh
Copy link

Adraesh commented Apr 9, 2017

Thank for the fast implementation.

Is it already ready in the turf.min.js ?

Thanks.

@stebogit
Copy link
Collaborator Author

stebogit commented Apr 9, 2017

@Adraesh I just happened to be implementing it at the right moment apparently 😄
It is not yet an official module, just created the PR. But you might want to try it as npm module and see if you find any issue with it.
BTW I don't really know how the process works to have it in the min version.

@DenisCarriere
Copy link
Member

DenisCarriere commented Apr 9, 2017

However I did not create the README file cause I thought it was created automatically from the documentation in the index.js, but it didn't. Should I create it manually?

It is created by the index.js, however when creating a new modules you would need to initially run /scripts/generate-readme.

Not sure if the index.d.ts and bench.js are correct, as I'm not familiar with them.

  • I can help review the Typescript definition.
  • Benchmark is useful to determine the efficiency of the module, you can almost copy-paste any recent module for the benchmark template (ex: turf-bbox-clip

Is that ok if I created the branch in this repo or should I work on my forked one?

Perfectly fine what you did, for every new PR generate a new forked branches from Turf's master branch.

BTW I don't really know how the process works to have it in the min version.

The minified build happens when a new release is published using npm build.

CC: @stebogit

@DenisCarriere
Copy link
Member

@stebogit Look over your source code! 👍 I'm going to send over a few commits to add dynamic testing from GeoJSON point features in test/in & test/out.

@stebogit
Copy link
Collaborator Author

stebogit commented Apr 9, 2017

@DenisCarriere so this is the way to go for any (new) module now, right?

dynamic testing from GeoJSON point features in test/in & test/out.

I started this module by cloning the circle module which doesn't have that, so I though the test/in - test/out thing was only used for more complex modules

@DenisCarriere
Copy link
Member

@stebogit ideally every module should have dynamic testing and you shouldn't have to touch the source code of the test.js, simply add geojson features to the test/in is the easiest way that others can contribute to improve the test cases. Also it's impossible to visually see the results when they are not being generated in test/out.

Just added dynamic tests via 57b0717.

Noticed an issue with:

  • bearing1= -50
  • bearing2= -15

image

And an error with:

  • bearing1= -15
  • bearing2= -50
Error: Each LinearRing of a Polygon must have 4 or more Positions.
    at module.exports.polygon (/Users/mac/Github/turf-sector/packages/turf-sector/node_m
odules/@turf/helpers/index.js:84:19)

@DenisCarriere
Copy link
Member

DenisCarriere commented Apr 9, 2017

This might be handy to have 65c3c36

  • extract required params from GeoJSON properties (only applied to required params and must be undefined) (Edit: not a common behavior in TurfJS, i'll remove in next commit)
  • more verbose validation (to know exactly which param required)

@stebogit
Copy link
Collaborator Author

stebogit commented Apr 9, 2017

@DenisCarriere I don't understand exactly how to run ./scripts/generate-readmes, would you mind adding some more details about this on CONTRIBUTING.md, I think it might be beneficial for other less expert developers, like me, as well.

@DenisCarriere
Copy link
Member

@stebogit Are you running on MacOS or Linux? You can simply just execute it via the terminal/command line.

$ ./scripts/generate-readmes

In windows you might need to add node in front of the script

$ node ./scripts/generate/readmes

@DenisCarriere DenisCarriere changed the title added turf-sector module New module @turf/sector Apr 9, 2017
@DenisCarriere DenisCarriere changed the title New module @turf/sector New module @turf/sector Apr 9, 2017
@DenisCarriere
Copy link
Member

@stebogit You might be interested to know that there's already a getCoords() function in @turf/invariant, it's an easy way to get coords from Geometry or Feature or an Array.

https://github.com/Turfjs/turf/blob/master/packages/turf-invariant/index.js#L22-L50

This `sector-error.geojson` seems to be having some issues, it should be the inverse.
- bearing1 = -15 (345)
- bearing2 = -50 (310)
CC: @stebogit
@DenisCarriere
Copy link
Member

DenisCarriere commented Apr 9, 2017

Added test case sector-error.geojson seems to be having some issues, it should be the inverse.

  • bearing1 = -15 (345)
  • bearing2 = -50 (310)

I'm sure this would be resolved if we have a 100% tested @turf/line-arc module based on your getArcLine function.

@stebogit 👍 We are almost there!!

@DenisCarriere DenisCarriere modified the milestones: 4.2.0, 4.1.0 Apr 10, 2017
* sector3 x 38,093 ops/sec ±2.97% (77 runs sampled)
* sector4 x 210,468 ops/sec ±2.58% (78 runs sampled)
* sector5 x 26,438 ops/sec ±9.98% (70 runs sampled)
* sector6 x 29,032 ops/sec ±2.36% (70 runs sampled)
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@DenisCarriere I thought to run bench.js and it turned out it worked 😆 (I guess)
I don't understand though if the result is good, I mean how do I evaluate these numbers, what do they mean?

Copy link
Member

@DenisCarriere DenisCarriere Apr 10, 2017

Choose a reason for hiding this comment

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

Well the results will vary based on each machine, however it's a good performance gauge when you are trying to tweak a specific function.

Let's say you want to know if map() is faster than featureEach(), you can run the benchmark and then change the function and run the benchmark again to see which one has better performance.

Also when refactoring existing code, you might want to know if your "new" code is actually improving the performance or decreasing it. My @turf/buffer attempt is a good example of refactoring gone bad 🤦‍♂️ #656 (fail me)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so higher ops/sec means better performance, right?
then you might want to re-run bench.js here, as I'm sure my old macbook air here at home is slower than your machine...

Copy link
Member

Choose a reason for hiding this comment

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

Yes higher ops/sec is better.

The Benchmark results are approximate, it gives you a good idea where the module stands.

@stebogit
Copy link
Collaborator Author

@DenisCarriere since we have now more than one module having angles/bearing as input, I think the convertAngleTo360 function (used in both turf-sector and turf-line-arc) could be moved into turf-helpers, what do you think?
Maybe you can find a better name.

@DenisCarriere
Copy link
Member

@stebogit 👍 for convertAngleTo360 that would fit the theme of @turf/helpers, there's already a few degrees methods https://github.com/Turfjs/turf/blob/master/packages/turf-helpers/index.js#L277-L320.

I'm sure there's a few other TurfJS modules that have this type of function internally built in, you could poke around and see if you could include it in other modules.

@stebogit
Copy link
Collaborator Author

stebogit commented Apr 10, 2017

@DenisCarriere may/should I add this task as a new issue and assign it to myself then?
Are you ok with the name of the function? I'm not 100% satisfied, but I can't find really a better one...

@DenisCarriere
Copy link
Member

@stebogit Yep, make a new issue or open up a new PR and briefly explain it.

Usually I let a PR sit for a few days and review it again with a fresh mindset, you might find a better name for convertAngleTo360 in a couple days.

@stebogit
Copy link
Collaborator Author

@DenisCarriere what about bearingToAngle?
After some research I find out that the 'bearing' is the angle between (generally) the north and a generic line/direction (that's why bearing is -180 and +180 degrees!), while an angle is generally express between 0 and 360 degrees (here again we might choose north as reference).
This is probably obvious to most people, but I would add some details in the turf-bearing description just to be more clear.

@DenisCarriere
Copy link
Member

@stebogit 👍 I like it a lot! A lot better than the previous method name.

I think you've got a winner there!

@stebogit
Copy link
Collaborator Author

@DenisCarriere I believe this module might be ready for merging, after your blessing 😃

@DenisCarriere
Copy link
Member

@stebogit ✋ High Five! Looks great!

@DenisCarriere DenisCarriere merged commit 6dd8e9f into master Apr 12, 2017
@DenisCarriere
Copy link
Member

GeoJSON Pac-Man! 🚀

https://github.com/Turfjs/turf/blob/master/packages/turf-sector/test/out/pacman.geojson
image

@stebogit
Copy link
Collaborator Author

stebogit commented Apr 12, 2017

@DenisCarriere Great, thanks! 🎉
How come that the branch turf-sector is still unmerged? Did you just copied the module over to master? Just curious
screen shot 2017-04-11 at 10 18 03 pm

@DenisCarriere
Copy link
Member

DenisCarriere commented Apr 12, 2017

Strange, might be an issue on the GitHub Network graph. I simply merged it via this PR, nothing special (maybe check again tomorrow, might be a delay).

Regardless, it's always best to delete the branch after it's been merged (if no more work is going to happen on that branch).

@DenisCarriere DenisCarriere deleted the turf-sector branch April 12, 2017 05:31
@DenisCarriere DenisCarriere restored the turf-sector branch April 12, 2017 05:32
@DenisCarriere DenisCarriere deleted the turf-sector branch April 12, 2017 05:32
@DenisCarriere
Copy link
Member

@stebogit Reference the network graph. Maybe it's because when I merge I always select the Squash and merge vs. using Create a merge commit (I personally like having a single commit for each individual PRs vs. having 10 new commits for one fix/new module).

@DenisCarriere
Copy link
Member

Yep that was it, I just did a merge using Create a merge commit with bearingToAngle and the network graph merged.

image

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

Successfully merging this pull request may close these issues.

3 participants