Coordinate flip in Picking.js causes out-of-bounds access when y=0
- Dominant language
- JavaScript
- Stars
- 15.7k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
### What happened?
Hello ,
In the `pickPositionWorldCoordinates` function at line 632:
https://github.com/CesiumGS/cesium/blob/7355e1eba2f0732a694c3e5f03960caa982ff7e1/packages/engine/Source/Scene/Picking.js#L632
There is a Y-coordinate flip:
` drawingBufferPosition.y = scene.drawingBufferHeight - drawingBufferPosition.y;`
However, this creates an off-by-one error. When drawingBufferPosition.y = 0, the result becomes scene.drawingBufferHeight, which is out of bounds since valid pixel coordinates should range from [0, scene.drawingBufferHeight - 1].
For example, with a drawing buffer height of 270:
Input: y = 0 → Output: y = 270 (invalid - should be 269)
Input: y = 269 → Output: y = 1 (valid)
Should this be corrected to:
` drawingBufferPosition.y = scene.drawingBufferHeight - drawingBufferPosition.y - 1 `
This would ensure the coordinate stays within valid bounds [0, height-1] after the flip.
Is this intentional behavior, or should it be fixed?
Contributor guide
Research direction
Start in packages/engine/Source/Scene/Picking.js at line 632, within pickPositionWorldCoordinates. Check the coordinate flip with y=0 and y=269 against the stated drawing-buffer bounds. Done means the flip no longer produces an out-of-bounds y value while preserving valid coordinate behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100