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

Bezier spline #73

Merged
merged 6 commits into from
Jan 8, 2019
Merged

Bezier spline #73

merged 6 commits into from
Jan 8, 2019

Conversation

RomainQuidet
Copy link
Contributor

Add bezier spline support by porting original code

@RomainQuidet RomainQuidet mentioned this pull request Dec 10, 2018
Copy link
Contributor

@frederoni frederoni left a comment

Choose a reason for hiding this comment

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

Thanks for porting this feature.

It looks a little bit cramped. Would you mind adding whitespace around / operators and mitigate excessive use of self?

Also add the corresponding turfjs feature to the table in the README.md.

/**
Returns a new LineString based on bezier transformation of the input line
*/
public static func bezier(_ line: LineString, resolution: Int = 10000, sharpness: Double = 0.85) -> LineString? {
Copy link
Contributor

@frederoni frederoni Dec 18, 2018

Choose a reason for hiding this comment

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

This static function would probably be a better fit as a method LineString.bezier(resolution:sharpness) in LineString.swift or as an extension on LineString in Spline.swift.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done as LineString extension in Spline.swift

#endif


/**
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Add documentation or remove the block if SplinePoint is only for internal use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course, done.

@1ec5 1ec5 added improvement Improvement for an existing feature. JS parity Java parity and removed Java parity labels Dec 18, 2018
@RomainQuidet
Copy link
Contributor Author

@frederoni I updated the code according to your reviews. Thanks.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution! Bézier splines will be pretty useful in combination with the map SDK.

I didn’t spot any actual porting problems, though it does look like Turf.js might have an off-by-one error. Most of the comments below are suggestions on how to make the code more functional. I think the functional alternatives make the code easier to understand. (There may be a memory tradeoff in the case of zip(_:_:), but the other suggestions should be memory-neutral at worst.)

Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
t = 0
}
if t > duration {
t = duration - 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it just me, or is there an off-by-one error in the original JavaScript version? If t is equal to duration, then leave it alone, but if it’s greater than duration, cap it at duration−1. 🤔

Without further investigation, I’m not sure we should deviate from Turf.js, given our experience with another seemingly accidental off-by-one error that turned out to be significant: #27.

Copy link
Contributor

@1ec5 1ec5 Jan 8, 2019

Choose a reason for hiding this comment

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

Filed upstream for further investigation: Turfjs/turf#1567.

Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
Sources/Turf/Spline.swift Outdated Show resolved Hide resolved
@RomainQuidet
Copy link
Contributor Author

RomainQuidet commented Jan 3, 2019

I merged master into this pull request to keep all things sync as I started with version 2.1 and I saw merge conflicts with v3

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Wonderful, thanks!

@1ec5 1ec5 merged commit 1114acd into mapbox:master Jan 8, 2019
@Woildan Woildan deleted the bezierSpline branch November 10, 2021 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement for an existing feature. JS parity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants