Turfjs / Turfjs/turf

@turf/lineSlice expected precision

Open
#2,947 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

What is the expected precision of utilities like @turf/lineSlice. I certainly expect some floating point issues, but I noticed one relatively glaring

{
  "startPt": {
    "type": "Point",
    "coordinates": [
      1,
      2
    ]
  },
  "endPt": {
    "type": "Point",
    "coordinates": [
      4,
      2
    ]
  },
  "line": {
    "type": "LineString",
    "coordinates": [
      [
        -1,
        2
      ],
      [
        5,
        2
      ]
    ]
  },
  "result": {
    "type": "Feature",
    "properties": {},
    "geometry": {
      "type": "LineString",
      "coordinates": [
        [
          0.9999985123144755,
          2.0024376784603275
        ],
        [
          4.000001859181029,
          2.0015234321498467
        ]
      ]
    }
  }
}

The distance between [1,2] and [0.9999985123144755, 2.0024376784603275] is 0.17 miles, which is significant and much larger than I would have expected for a floating point precision drift in a single calculation.

This may be expected behavior, but if it is, I'd request that the library includes some documentation of the expected tolerances.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the @turf/lineSlice utility and reproduce the supplied start point, end point, and line coordinates. Investigate whether the 0.17-mile discrepancy is expected algorithmic behavior or an error; done means the behavior is corrected or its expected precision and tolerances are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.