Turfjs / Turfjs/turf

turf.lineIntersect() doesn't work when line coordinate precision is greater than 6

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

Nobody has claimed this yet.

@turf/line-intersect
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

line1 and line2 intersect, they have same last coordinates in both geometry arrays, but lineIntersects returns 0 features. If you change first coordinate in line1, in a way that it has 5, 6 or 7 decimals, lineIntersects return one feature. Code is bellow:

let line1 = {
    "type": "Feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [
            [
                18.9717337097508,
                42.2588785942886
            ],
            [
                18.9721316,
                42.258861
            ]
        ]
    },
    "properties": null
};

let line2 = {
    "type": "Feature",
    "geometry": {
        "type": "LineString",
        "coordinates": [
            [
                18.9886841,
                42.2635654
            ],
            [
                18.9859838,
                42.262568
            ],
            [
                18.9847824,
                42.262127
            ],
            [
                18.9839994,
                42.26183
            ],
            [
                18.9830067,
                42.2614419
            ],
            [
                18.9810483,
                42.2609998
            ],
            [
                18.9792739,
                42.2605528
            ],
            [
                18.9774267,
                42.2601404
            ],
            [
                18.9758575,
                42.2597555
            ],
            [
                18.9737945,
                42.2592482
            ],
            [
                18.9721316,
                42.258861
            ]
        ]
    },
    "properties": null
};

alert(turf.lineIntersect(line1, line2).features.length);

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.lineIntersect() entry point and reproduce the supplied line1 and line2 example, then compare results while changing line1's first coordinate precision. Done means the intersecting lines consistently produce one feature, including with the original high-precision coordinates; the payload names no files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.