-
Notifications
You must be signed in to change notification settings - Fork 946
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
🛠 Extend Circle Options #2516
base: master
Are you sure you want to change the base?
🛠 Extend Circle Options #2516
Conversation
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.
Thank you for this contribution @AminoffZ. I'd like to request a few changes:
- You seem to have included a number of file permission changes as part of this PR. Can you please remove these?
- You offered to added a couple more tests for this functionality, those would be welcome.
- Check the CI test result for any issues.
- You can run prettier manually using a command like
npx prettier --write .
. Or possibly install prettier to be run automatically by your editor of choice.
See the rest of my comments in the code.
packages/turf-circle/index.ts
Outdated
|
||
if (!Array.isArray(center) && center.type === "Feature") { | ||
properties = properties || center.properties; | ||
bboxValue = center.bbox; |
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.
Do you think it makes sense to pass on the bbox
of the center point to polygon()
? I would suspect that the bbox of the point will almost never be representative of the bbox of the resulting circle. I think it would be better to leave it undefined if the caller doesn't provide their own options.bbox. And the user can generate their own using bbox()
packages/turf-circle/index.ts
Outdated
|
||
// main | ||
let properties: P | undefined = options.properties; |
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.
Not essential but consider letting the types flow through without manual duplication like
let properties: Pick<typeof options, 'properties'> = options.properties;
packages/turf-circle/index.ts
Outdated
* @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature | ||
* @param {string|number} [options.id] Identifier associated with the Feature |
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.
Can these please clarify these relate to the result Feature, for example "Identifier to assign to the resulting circle feature", "Bounding Box Array [west, south, east, north] to assign to the resulting circle Feature"
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.
Can the center
param typedoc also please clarify that if it is a Feature, then its properties/id will be assigned to the resulting circle feature, and whether they will have precedence over options
passed.
packages/turf-circle/index.ts
Outdated
let _options: { bbox?: BBox; id?: Id } | undefined; | ||
if (bboxValue || idValue) { | ||
_options = { | ||
...(bboxValue ? { bbox: bboxValue } : {}), | ||
...(idValue ? { id: idValue } : {}), | ||
}; | ||
} |
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.
This feels a bit overcomplicated. Can it be removed altogether and you can construct the options object in the call to polygon()
? For example:
return polygon([coordinates], properties, {bbox: bboxValue, id: idValue);
Thank you for your review and suggestion @twelch! I'm going to have a pretty busy coming few days but will get back to this when I have the time 🙂, ETA ~2 weeks. |
ok lol, i have some git setting or something that keeps messing up the file permissions (i'm on wsl2 ubuntu)... will look into it later. i added some of your suggestions, haven't gotten around to the tests yet. i think that will take quite a while to research. on another note: finally #2248 which probably was due to a different issue at time of posting, is now relevant again.
on results in
|
id and bbox options for @turf/circle
Functions like polygon, which circle depends on, has options to directly assign id or bbox. This change makes it possible to set these using additional parameters.
Changes
options
parameter in the circle function to allow setting bbox and id directly.properties: any
toproperties: P | undefined
const stepAngle = -360 / steps;
outside of the loop.Test and Bench
Test
Didn't have time to write more tests for this case, can do if the idea is approved 👍.
Bench
Before:
After:
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.