-
Notifications
You must be signed in to change notification settings - Fork 952
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/ellipse - Create an Ellipse submodule based on Circle #1087
Conversation
Nice! Thanks for the contributions! Going to have a look at this more closely later on. I'll help out to make the TravisCI tests pass. |
Thanks. My goal, if it's not obvious, is to add Standard Deviational Ellipse functionality to turf. The potential for geostatistical packages in interactive maps (in leaflet, say)… 💥 |
When creating an Ellipse, would it also be possible points (Coordinates) to define |
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.
👍 Looks good, I've left a few comments, I can help with any final touches.
packages/turf-ellipse/index.js
Outdated
* //addToMap | ||
* const addToMap = [turf.point(center), ellipse] | ||
*/ | ||
module.exports = function (center, xRadius, yRadius, options) { |
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.
We are using ES Modules now + this type of module should also be using export default
.
function ellipse(center, xRadius, yRadius, options) {
...
}
export default ellipse
packages/turf-ellipse/index.js
Outdated
|
||
/** | ||
* Takes a {@link Point} and calculates the ellipse polygon given two axes in degrees and steps for precision. | ||
* |
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.
Most modules will contain a @name
JSDocs tag.
/**
* @name ellipse
*/
packages/turf-ellipse/index.js
Outdated
@@ -0,0 +1,68 @@ | |||
const polygon = require('@turf/helpers').polygon; | |||
const lengthToDegrees = require('@turf/helpers').lengthToDegrees; | |||
const getCoord = require('@turf/invariant').getCoord; |
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.
Since Turf now uses ES Modules, you should be using the import
syntax.
import { polygon, lengthToDegrees } from '@turf/helpers';
import { getCoord } from '@turf/invariant';
packages/turf-ellipse/index.d.ts
Outdated
/** | ||
* http://turfjs.org/docs/#ellipse | ||
*/ | ||
declare function ellipse(feature1: Feature, feature2: Feature): boolean; |
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.
... 🤔 I know Typescript is new for a lot of folks, but you could simply copy the Typescript definition from @turf/circle
which will be very similar to the new ellipse module.
https://github.com/Turfjs/turf/blob/master/packages/turf-circle/index.d.ts
packages/turf-ellipse/index.js
Outdated
if (!center) throw new Error('center is required'); | ||
if (!xRadius) throw new Error('xRadius is required'); | ||
if (!yRadius) throw new Error('yRadius is required'); | ||
if (typeof options !== 'object') throw new Error('options must be an object'); |
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.
There's a helper function isObject
in @turf/helpers
instead of using typeof
.
packages/turf-ellipse/index.js
Outdated
if (typeof options !== 'object') throw new Error('options must be an object'); | ||
if (typeof steps !== 'number') throw new Error('steps must be a number'); | ||
|
||
const centerCoords = getCoord(center); |
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.
At the moment TurfJS is only using ES5 code, ES6 is not being compiled to ES5 for the final build (at the moment).
- Replace
const
withvar
packages/turf-ellipse/index.js
Outdated
xRadius = lengthToDegrees(xRadius, units); | ||
yRadius = lengthToDegrees(yRadius, units); | ||
|
||
let 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.
Same as above, replace let
with var
packages/turf-ellipse/package.json
Outdated
@@ -0,0 +1,43 @@ | |||
{ | |||
"name": "@turf/ellipse", | |||
"version": "5.0.4", |
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.
Could you change the version to 5.0.0
for the first publish, Lerna will decide the patch version.
packages/turf-ellipse/package.json
Outdated
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" |
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.
Missing main.js
that will be the CommonJS distributed file from Rollup
packages/turf-ellipse/package.json
Outdated
"index.d.ts" | ||
], | ||
"scripts": { | ||
"test": "node test.js", |
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.
Use the same scripts as all the other modules.
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
},
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'll also need to install @std/esm
with the following config:
"@std/esm": {
"esm": "js",
"cjs": true
}
I'm looking at the ellipse code base, why don't we simply add |
👍 Super! 🚀 Lets definitely get this done, I think expanding the |
@DenisCarriere Thanks for making these changes. A few notes: Abstractly:
Concretely:
Switching to |
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.
Looks great. Thanks! 👍 I left a comment addressing come of your questions.
@muziejus @DenisCarriere nice addition here. 👍 Are the radii required by the module actually the semi-minor and the semi-major axes of the ellipse? If so I'd describe that way in the docs. May I suggest to include also an optional I don't think having this as a separate module would be a terrible idea, it would make it "easier to find" or like more explicit that Turf has that functionality. Just a thought. |
@stebogit You're right; they are the semi-minor and semi-major axes. My terminology is bad. But we can't use terms like "major" and "minor" because they actually relate to the x and y--it's very easy to send, say, Maybe |
@stebogit As for tilting, I considered that, since rotation is a vital aspect of the standard deviational ellipse, but given there's already a diff utility, I don't think adding another parameter is necessary. If I were to add a |
@muziejus looking at the picture in my understanding we are passing
We could easily use
What do you mean? |
@stebogit You're right. I meant "separate utility" in that the user could always use |
✅ 👍 for adding ✅ 👍 using ✅ 👍 Creating it's own module ❌ 👎 add a translate or scale option (doesn't seem necessary given there's already 3 parameters that will allow to control that) It is best to create it's own dedicated module |
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.
Approved once the module supports at least the following 3 params & 2 options:
Params
- center
- major
- minor
Options
- tilt
- units
🤔 Seems like the build is failing because of a linting issue.
|
Cannot find module Missing dependency 😄 The joys... Thank you TravisCI for being there for us.
|
👍 Awesome stuff @muziejus! |
Comments:
index.d.ts
file because I don't know what it does.Please fill in this template.
npm test
at the sub modules where changes have occurred.npm run lint
to ensure code style at the turf module level.Submitting a new TurfJS Module.
./scripts/generate-readmes
to createREADME.md
.package.json
using "Full Name <@github Username>".