Turfjs / Turfjs/turf

BooleanContains should return false when the Outer contains all the verticies of the Inner, but their borders intersect.

Open
#1,467 18 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

Given two polygons, Outer and Inner, we are checking that booleanContains(outer, inner) should return the correct result.

Consider the case where Outer contains all of the verticies of Inner, but their boundaries intersect. booleanContains incorrectly returns false in such a scenario.

Here is a picture of an example case:
image

As well as a unit test showing the failing case.

import booleanContains from "@turf/boolean-contains"

describe('booleanContains', () => {

  it('Contains should be false when borders intersect but all verticies are contained', () => {

    // Outer: A 2 x 2 square with the top-right quadrant removed.
    const outer = {
      type: "Polygon",
      coordinates: [[
        [0, 0],
        [0, 2],
        [1, 2],
        [1, 1],
        [2, 1],
        [2, 0],
        [0, 0]
      ]]
    };

    // Inner: A triangle with all 3 verticies inside outer, but one segment intersecting the border of outer
    const inner = {
      type: "Polygon",
      coordinates: [[
        [.1, .1],
        [.1, 1.9],
        [1.9, .1],
        [.1, .1]
      ]]
    }

    expect(booleanContains(outer, inner)).toBe(false) // Returns true
  })
});

Result:

  ● booleanContains › Contains should be false when borders intersect but all verticies are contained

    expect(received).toBe(expected) // Object.is equality

    Expected: false
    Received: true

      89 |     }
      90 | 
    > 91 |     expect(booleanContains(outer, inner)).toBe(false)
         |                                           ^
      92 |   })
      93 | });
      94 | 

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 booleanContains entry point and reproduce the supplied polygon case as a unit test. Compare the returned result with the expected false value, then run the booleanContains test suite and confirm the regression case passes.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.