Skip to content

@turf/lineSlice expected precision #2947

@mn-prp

Description

@mn-prp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions