Turfjs / turf

A modular geospatial engine written in JavaScript and TypeScript

Home Page:https://turfjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

turf-line-arc not providing requested number of steps

smallsaucepan opened this issue · comments

While looking at #2446 (already fixed I think) noted that the number of coordinates in the test case didn't match the number of segments expected (15).

The code in lineArc to add the next segment angle seems odd (L69):

alfa = arcStartDegree + (i * 360) / steps;

This seems to be adding a portion of a full circle each iteration, rather than a portion of the arc between start and end bearing. I suspect this causes the logic to take larger leaps between each iteration and produce fewer segments than expected.

Will investigate further, though please someone pipe up if I've misunderstood what the steps option is supposed to convey.

Please provide the following when reporting an issue:

  • The version of Turf you are using, and any other relevant versions. - 7.0.0-alpha.2
  • GeoJSON data as a gist file or geojson.io (filename extension must be .geojson).
  • Snippet of source code or for complex examples use jsfiddle.

Current result from passing the following:

const options = { steps: 10, units: "kilometers" };

const center = point([115.959444, -31.945]);
const startAngle = 223;
const endAngle = 277;
const radius = 130;
const arc = lineArc(center, radius, startAngle, endAngle, options);

Note the uneven segments, and only two of them when 10 steps were requested.

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            115.01093453374415,
            -32.796517853741484
          ],
          [
            114.60375948351884,
            -32.16087936772768
          ],
          [
            114.5941289639308,
            -31.795215147513787
          ]
        ]
      }
    }
  ]
}