iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.06k stars 290 forks source link

[PROPOSAL] Error as value instead of throwing during picking #2305

Open HoloTheDrunk opened 3 months ago

HoloTheDrunk commented 3 months ago

Your Environment

Context

Datasets should ideally be clean of artifacts, but that's rarely the case so failing an entire picking call for a single artifact encounter is ineffective. This happens for example when picking certain NaN-ed out points in point cloud datasets while using proj4.

Expected Behavior

The picking routine should catch the errors and return them as values along with the valid results.

Actual Behavior

The picking routine pickPointsAt in src/Core/Picking.js does not catch errors and instead passes them along, leading to a discard of possibly valid and unrelated results when Coordinates::spatialEuclideanDistanceTo throws an error.

Possible Cause/Fix/Solution

Catching thrown errors per-point and transforming them into error values to push into the result array. This should not incur additional runtime costs at least on the V8 engine.

HoloTheDrunk commented 3 months ago

It just hit me that this would be even better handled by making the function a generator and keeping the current throw mechanism.