Skip to content

Floating point precision issues when searching for exact points #33

Open
@Smilliam

Description

@Smilliam

Hi there, so I've run into an issue with floating point precision when searching for exact points in an rtree. For a demonstration of this bug, grab my test case located on my fork here and run it a few times on the current build. You'll get some output similar to this:

$ node searchexact.test.js
TAP version 13
# RTree Searching for exact point
not ok 1 1k In-Bounds Searches
  ---
    operator: equal
    expected: 1000
    actual:   997
    at: Test.<anonymous> (/home/centos/proj/rtree/RTree/test/searchexact.test.js:23:5)
  ...

1..1
# tests 1
# pass  0
# fail  1

$ node searchexact.test.js
TAP version 13
# RTree Searching for exact point
not ok 1 1k In-Bounds Searches
  ---
    operator: equal
    expected: 1000
    actual:   997
    at: Test.<anonymous> (/home/centos/proj/rtree/RTree/test/searchexact.test.js:23:5)
  ...

1..1
# tests 1
# pass  0
# fail  1

$ node searchexact.test.js
TAP version 13
# RTree Searching for exact point
not ok 1 1k In-Bounds Searches
  ---
    operator: equal
    expected: 1000
    actual:   998
    at: Test.<anonymous> (/home/centos/proj/rtree/RTree/test/searchexact.test.js:23:5)
  ...

1..1
# tests 1
# pass  0
# fail  1

I've created a patch and submitted a PR (#34) for review. My solution was to introduce an epsilon and to check bounds relative to this epsilon.

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