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

lineArc with leaflet - end angle problem? #2446

Closed
tj26x opened this issue Jun 27, 2023 · 7 comments
Closed

lineArc with leaflet - end angle problem? #2446

tj26x opened this issue Jun 27, 2023 · 7 comments
Assignees
Milestone

Comments

@tj26x
Copy link

tj26x commented Jun 27, 2023

Hello,
I am having trouble with turf lineArc returning the error: coordinates must be an array of two or more positions.
for the example below for RA if I change the endAngley to a value of 276 or 278 turf.lineArc works correctly but a value of 277 always gives an error. R8A also gives the same error.

        //RB works correctly
        var centery = turf.point([115.959444, -31.945]);
        var startAngley = 253; 
        var endAngley = 278;
        var radiusy =69.83195;
        var arc = turf.lineArc(centery, radiusy * 1.852, startAngley, endAngley, options);

        //RA gives error as below
        var centery = turf.point([115.959444, -31.945]);
        var startAngley = 253;
        var endAngley = 277; //change this to 276 or 278 and works fine?!?
        var radiusy =119.7195; //changing this value makes no difference.
        var arc = turf.lineArc(centery, radiusy * 1.852, startAngley, endAngley, options);

       //R8A not ok, give error below		
        var centerx = turf.point([115.959444, -31.945]);
	var startAnglex = 303;
	var endAnglex = 327;
	var radiusx = 60.0439;
	console.log("R168A test");
	var arc = turf.lineArc(centerx, radiusx * 1.852, startAnglex, endAnglex, options);
	console.log(arc);
> turf.min.js:1  Uncaught Error: coordinates must be an array of two or
> more positions
>     at h (turf.min.js:1:2371)
>     at Object.bi [as lineArc] (turf.min.js:43:85958)
>     at getOrderedPolyLines (?dataset=7a95f134-be37-49e6-9aca-0b0780f30258:223009:18)
>     at drawVolume (?dataset=7a95f134-be37-49e6-9aca-0b0780f30258:222669:22)
>     at HTMLDivElement.<anonymous> (?dataset=7a95f134-be37-49e6-9aca-0b0780f30258:222549:8)
>     at HTMLDivElement.dispatch (jquery.min.js:2:43331)
>     at y.handle (jquery.min.js:2:41315)
>     at Object.trigger (jquery.min.js:2:71937)
>     at E.fn.init.triggerHandler (jquery.min.js:2:72616)
>     at Object.checkboxChange (gijgo.min.js:1:121495)

here is a jsfiddle showing the problem.

https://jsfiddle.net/7g9smnkd/1/

I have thousands of these types of lineArc calculations but these 2 are the only ones that cause an error.
Any help would be greatly appreciated.
Thank you.

Using turfjs 7.0.0-alpha.0 (but experienced problem on previous release too)

@JamesLMilner
Copy link
Collaborator

Thanks for raising - I haven't got the time to fully debug this right now but looking at your reproduction case (thank you for including) it does seem odd and there is nothing immediately obvious wrong with your code or the data. I noticed if you change the steps option down to 14 it passes without an error.

I'll flag this as a bug and hopefully when I or someone gets more time we can investigate.

@smallsaucepan
Copy link
Member

smallsaucepan commented Oct 26, 2023

Oh, this is a good one! 🤯

Basically, if 360 / number of steps in options equals end angle - start angle, this function errors out. So when you changed the angle by a single degree in either direction it was enough to upset that relationship and let the code work.

A fix shouldn't be too difficult. Stay tuned.

@smallsaucepan smallsaucepan self-assigned this Oct 26, 2023
@smallsaucepan
Copy link
Member

Looking into this a bit more @tj26x it has already been fixed and was included in 7.0.0-alpha.0 and later. Would you mind confirming that you're using that version? Just noted that the Turf version in your jsfiddle is still 6.5.0.

smallsaucepan added a commit to smallsaucepan/turf that referenced this issue Oct 27, 2023
…ct number of steps. Also a bit related to Turfjs#2446, which should have been fixed a while ago by a previous fix to the previous version of this code (see Turfjs#2142). Including a unit test to make sure we don't go backwards with this approach.
@tj26x
Copy link
Author

tj26x commented Oct 29, 2023

So it looks like I am using 6.5.0 but everywhere i go to download the minified (turf.min.js) release 7.0.x points me to this: https://npmcdn.com/@turf/turf@6.5.0/turf.min.js

putting 7.0.0 in the address does not work?

Where can I download an actual 7.0.x release?

Thank you.

@smallsaucepan
Copy link
Member

7.0.0 isn't officially released yet so please try https://npmcdn.com/@turf/turf@7.0.0-alpha.2/turf.min.js

That's the latest alpha release.

@tj26x
Copy link
Author

tj26x commented Nov 2, 2023

Release 7.0.0 fix my problem. Is it to be officially released soon?

Thank you very much.

smallsaucepan added a commit that referenced this issue Nov 2, 2023
…rated arc (#2525)

* Fixes #2524 where lineArc isn't dividing the arc into the correct number of steps. Also a bit related to #2446, which should have been fixed a while ago by a previous fix to the previous version of this code (see #2142). Including a unit test to make sure we don't go backwards with this approach.

* Flow on changes to turf-sector and turf-angle unit test outputs as a result of fix to turf-line-arc. All changes checked visually using geojson.io, noting start and end coords are identical and it's only the intermediate ones changing due to the curve being smoother by default.

* Update changelog.

* Clarifying what the "steps" param means in the documentation. Haven't rebuilt the readme as generate-readmes needs some work. Will make that a seperate PR though.
@smallsaucepan smallsaucepan added this to the 7.0.0 milestone Nov 2, 2023
@smallsaucepan
Copy link
Member

Thanks for confirming @tj26x. Will close this issue. Sorry, I'm not aware of any planned release date for v7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants