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

Initial commit of booleanPointOnLine #858

Merged
merged 7 commits into from
Jul 24, 2017
Merged

Conversation

rowanwins
Copy link
Member

@rowanwins rowanwins commented Jul 22, 2017

Please fill in this template.

  • 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.

  • Overview description of proposed module.

  • Include JSDocs with a basic example.

  • Execute ./scripts/generate-readmes to create README.md.

  • Add yourself to contributors in package.json using "Full Name <@github Username>".

booleanPointOnLine

Returns true if a point is on a line. Accepts a optional parameter to ignore the start and end vertices of the linestring.

This is a snippet that we've used across a number of the boolean modules now so figured it was worth separating out.

Ref. #809

@stebogit
Copy link
Collaborator

@rowanwins @DenisCarriere
looking at this new module (:+1: btw), may I suggest (for the following major release) to rename @turf/point-on-line to something like @turf/nearest-point-on-line?
Otherwise it's a little confusing and the user has to go to the docs or the code to understand the difference.
We might even "group" the nearest modules, allowing an easy addition of other modules alike, renaming also @turf/nearest to @turf/nearest-point

@DenisCarriere
Copy link
Member

@turf/point-on-line to something like @turf/nearest-point-on-line?
Otherwise it's a little confusing and the user has to go to the docs or the code to understand the difference.
We might even "group" the nearest modules, allowing an easy addition of other modules alike, renaming also @turf/nearest to @turf/nearest-point

👍 I like this change for a next major release, it is a big confusing when they aren't grouped and the name is too generalized.

module.exports = function (point, linestring, ignoreEndVertices) {
var pointCoords = getCoords(point);
var lineCoords = getCoords(linestring);
for (var i = 0; i < lineCoords.length - 1; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

👍 Code looks good.

We really need a segmentEach module (also mentioned here #856 (comment))

Copy link
Member Author

Choose a reason for hiding this comment

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

The only thing I find tricky about the invariant type modules is a lack of flow control, but in a lot of cases they are super-handy!

Copy link
Member

Choose a reason for hiding this comment

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

What do you mean by lack of flow control?

* @param {Geometry|Feature<Point>} point GeoJSON Feature or Geometry
* @param {Geometry|Feature<LineString>} linestring GeoJSON Feature or Geometry
* @param {Boolean} [ignoreEndVertices=false] whether to ignore the start and end vertices.
* @returns {Boolean} true/false
Copy link
Member

@DenisCarriere DenisCarriere Jul 22, 2017

Choose a reason for hiding this comment

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

I remember having this conversation with @tmcw about Boolean vs. boolean.

From what I can read on JSDocs, it's saying to use boolean
http://usejsdoc.org/tags-type.html

Also DocumentationJS linting flags Boolean as a warning (which we will be adding soon)

This change applies to many modules, so don't need to fix this right now.

type Feature = GeoJSON.Feature<any> | GeoJSON.GeometryObject;

/**
* http://turfjs.org/docs/#booleanPointOnLine
Copy link
Member

Choose a reason for hiding this comment

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

All lowercase for the URL.

Example http://turfjs.org/docs/#centerOfMass (doesn't work)

* PointOnLineStart: 0.021ms
* PointOnLineEnd x 13,957,263 ops/sec ±0.53% (91 runs sampled)
* PointOnLineMidpoint x 17,388,052 ops/sec ±0.46% (94 runs sampled)
* PointOnLineStart x 17,036,405 ops/sec ±1.34% (91 runs sampled)
Copy link
Member

Choose a reason for hiding this comment

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

🏎 💨 Zoom Zoom!

Copy link
Member

@DenisCarriere DenisCarriere left a comment

Choose a reason for hiding this comment

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

Overall looks good, just a few little comments, and making the TravisCI tests pass.


/**
* http://turfjs.org/docs/#booleanpointonline
*/
declare function booleanPointOnLine(feature1: Point, feature2: Line, ignoreEndVertices: boolean): boolean;
declare function booleanPointOnLine(point: Point, linestring: Line, ignoreEndVertices?: boolean): boolean;
Copy link
Member

Choose a reason for hiding this comment

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

@rowanwins Another thing with these definitions, I try to use the same parameter names as the index.js

And ignoreEndVertices is optional, you can add ? to define optional params.

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