-
Notifications
You must be signed in to change notification settings - Fork 963
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/polygon-tangents
#708
Conversation
var suite = new Benchmark.Suite('turf-point-on-surface'); | ||
suite | ||
.add('turf-point-on-surface',function () { | ||
centroid(fc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rowanwins Might want to change this 🤦♂️ to @turf/tangents
@@ -0,0 +1,12 @@ | |||
/// <reference types="geojson" /> | |||
|
|||
type Point = GeoJSON.Feature<GeoJSON.Point>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started including Geometry Object as a valid input.
type Point = GeoJSON.Feature<GeoJSON.Point> | GeoJSON.Point;
type Polygon = GeoJSON.Feature<GeoJSON.Polygon> | GeoJSON.Polygon;
* @name polygonTangents | ||
* @param {Feature<Point>} point to calculate the tangent points from | ||
* @param {Feature<Polygon>} polygon to get tangents from | ||
* @returns {FeatureCollection|Feature<Point>} Feature Collection containing the two tangent points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should only return FeatureCollection<Point>
var rtan = 0; | ||
var ltan = 0; | ||
|
||
coordEach(polygon, function (currentCoords, currentIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to look into using coordReduce
, seems like this is the type of operation you are doing with eprev
& enext
.
|
||
coordEach(polygon, function (currentCoords, currentIndex) { | ||
if (currentIndex === 0) { | ||
eprev = isLeft(polygon.geometry.coordinates[0][0], polygon.geometry.coordinates[0][1], point.geometry.coordinates); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to consider using a shorter variable to declare your coordinates instead of always having to use polygon.geometry.coordinates
(hard to read).
var polyCoords = getCoords(polygon);
var ptCoords = getCoords(point);
Also this normalizes retrieving coordinates from either Feature or Geometry Object.
return turfFc([turfPoint(polygon.geometry.coordinates[0][rtan]), turfPoint(polygon.geometry.coordinates[0][ltan])]); | ||
}; | ||
|
||
function isAbove(Point1, Point2, Point3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally capitalized Javascript variables are used for Class
objects.
Point1
should be lowercased, we can look into including this as a warning in the ESLinter.
"tangent", | ||
"polygon" | ||
], | ||
"author": "Turf Authors", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add yourself in contributors
"contributors": [
"Rowan Winsemius <@rowanwins>"
]
- Added types test `tsc test/types.ts` to execute (if nothing happens, then it passes) - Added MultiPolygon to Types & JSDocs - Updated bench name :)
CC: @rowanwins This one is for you :)
Supporting Geometry ObjectsYou might find Error
Feature{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [132, -26]
}
} Geometry{
"type": "Point",
"coordinates": [132, -26]
} Using
|
- Dropped unused slice() methods - Prevent input mutation tests
@rowanwins 👍 Looks good to publish now. If you have anymore improvements just send over a new PR or simply push directly to master if they are minor changes (if |
@turf/polygon-tangents
New Module
@turf/polygon-tangents
Initial commit of a new
@turf/polygonTangents
module as per #648The only downside at the moment is that it doesnt handle a multipolygon input as
@turf/meta.coordsEach
function is a bit limited.coordsEach
will loop through a multipoly but there isn't doesnt provide much useful information in the currentIndex as to what depth you're at etc so I just need to do some refactoring.If there is anything else you notice let me know, otherwise I'll get the multipoly thing sorted and recommit.
Cheers
Rowan