Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-14553: Ignore small distance differences when sorting pick results.
Browse files Browse the repository at this point in the history
Intersection distances returned for 2D features on the sample plane may
differ by small values (~1e-6 in world distance). Ignore those small
difference and take into account only render order in those cases.

Signed-off-by: Andres Mandado <[email protected]>
  • Loading branch information
atomicsulfate committed Apr 27, 2021
1 parent cb96eaf commit 943588e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion @here/harp-mapview/lib/PickListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { PickResult } from "./PickHandler";

// Default sorting by distance first and then by reversed render order.
function defaultSort(lhs: PickResult, rhs: PickResult) {
// HARP-14553: Set a distance tolerance to ignore small distance differences between 2D objects
// that are supposed to lie on the same plane.
const eps = 1e-4;
const distanceDiff = lhs.distance - rhs.distance;
const haveRenderOrder = lhs.renderOrder !== undefined && rhs.renderOrder !== undefined;
if (distanceDiff !== 0 || !haveRenderOrder) {
if (Math.abs(distanceDiff) > eps || !haveRenderOrder) {
return distanceDiff;
}

Expand Down
26 changes: 26 additions & 0 deletions @here/harp-mapview/test/PickListenerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ describe("PickListener", function () {
expect(listener.results).to.have.ordered.members(expectedResults);
});

it("ignores small distance differences for sorting", function () {
const listener = new PickListener();
const eps = 1e-6;
const expectedResults: PickResult[] = [
{
type: PickObjectType.Point,
point,
distance: eps,
renderOrder: 2,
dataSourceName
},
{
type: PickObjectType.Point,
point,
distance: 0,
renderOrder: 1,
dataSourceName
}
];
listener.addResult(expectedResults[1]);
listener.addResult(expectedResults[0]);
listener.finish();

expect(listener.results).to.have.ordered.members(expectedResults);
});

it("keeps only the closest maximum result count if specified", function () {
const maxResultCount = 1;
const listener = new PickListener({ maxResultCount });
Expand Down

0 comments on commit 943588e

Please sign in to comment.