{"action":"created","comment":{"url":"https://api.github.com/repos/uber/deck.gl/pulls/comments/119531334","pull_request_review_id":41418443,"id":119531334,"diff_hunk":"@@ -212,6 +263,93 @@ function pickFromBuffer(gl, {\n   const width = Math.min(pickingFBO.width, deviceX + deviceRadius) - x + 1;\n   const height = Math.min(pickingFBO.height, deviceY + deviceRadius) - y + 1;\n \n+  const pickedColors = getPickedColors(gl, {layers, pickingFBO, deviceRect: {x, y, width, height}});\n+\n+  // Traverse all pixels in picking results and find the one closest to the supplied\n+  // [deviceX, deviceY]\n+  let minSquareDistanceToCenter = deviceRadius * deviceRadius;\n+  let closestResultToCenter = null;\n+  let i = 0;\n+\n+  for (let row = 0; row < height; row++) {\n+    for (let col = 0; col < width; col++) {\n+      // Decode picked layer from color\n+      const pickedLayerIndex = pickedColors[i + 3] - 1;\n+\n+      if (pickedLayerIndex >= 0) {\n+        const dx = col + x - deviceX;\n+        const dy = row + y - deviceY;\n+        const d2 = dx * dx + dy * dy;\n+\n+        if (d2 <= minSquareDistanceToCenter) {\n+          minSquareDistanceToCenter = d2;\n+\n+          // Decode picked object index from color\n+          const pickedColor = pickedColors.slice(i, i + 4);\n+          const pickedLayer = layers[pickedLayerIndex];\n+          const pickedObjectIndex = pickedLayer.decodePickingColor(pickedColor);\n+          closestResultToCenter = {pickedColor, pickedLayer, pickedObjectIndex};\n+        }\n+      }\n+      i += 4;\n+    }\n+  }\n+\n+  return closestResultToCenter || {\n+    pickedColor: EMPTY_PIXEL,\n+    pickedLayer: null,\n+    pickedObjectIndex: -1\n+  };\n+}\n+\n+/**\n+ * Query within a specified rectangle\n+ * Returns array of unique objects in shape `{x, y, pickedColor, pickedLayer, pickedObjectIndex}`\n+ */\n+function queryFromBuffer(gl, {\n+  layers,\n+  pickingFBO,\n+  deviceRect: {x, y, width, height}\n+}) {\n+  const pickedColors = getPickedColors(gl, {layers, pickingFBO, deviceRect: {x, y, width, height}});\n+  const uniqueColors = new Map();\n+\n+  // Traverse all pixels in picking results and get unique colors\n+  let i = 0;\n+\n+  for (let row = 0; row < height; row++) {\n+    for (let col = 0; col < width; col++) {\n+      // Decode picked layer from color\n+      const pickedLayerIndex = pickedColors[i + 3] - 1;\n+\n+      if (pickedLayerIndex >= 0) {\n+        const pickedColor = pickedColors.slice(i, i + 4);\n+        const colorKey = pickedColor.join(',');\n+        if (!uniqueColors.has(colorKey)) {\n+          const pickedLayer = layers[pickedLayerIndex];\n+          uniqueColors.set(colorKey, {\n+            x: col + x,\n+            y: row + y,\n+            pickedColor,\n+            pickedLayer,\n+            pickedObjectIndex: pickedLayer.decodePickingColor(pickedColor)\n+          });\n+        }\n+      }\n+      i += 4;\n+    }\n+  }\n+\n+  return Array.from(uniqueColors.values());\n+}\n+/* eslint-enable max-depth, max-statements */\n+\n+// Returns an Uint8ClampedArray of picked pixels\n+function getPickedColors(gl, {\n+  layers,\n+  pickingFBO,\n+  deviceRect: {x, y, width, height}\n+}) {\n   // TODO - just return glContextWithState once luma updates","path":"src/lib/draw-and-pick.js","position":149,"original_position":149,"commit_id":"429008258b9c5b2be2c21fa9a998fae0b467cffe","original_commit_id":"429008258b9c5b2be2c21fa9a998fae0b467cffe","user":{"login":"ericsoco","id":1127259,"avatar_url":"https://avatars2.githubusercontent.com/u/1127259?v=3","gravatar_id":"","url":"https://api.github.com/users/ericsoco","html_url":"https://github.com/ericsoco","followers_url":"https://api.github.com/users/ericsoco/followers","following_url":"https://api.github.com/users/ericsoco/following{/other_user}","gists_url":"https://api.github.com/users/ericsoco/gists{/gist_id}","starred_url":"https://api.github.com/users/ericsoco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericsoco/subscriptions","organizations_url":"https://api.github.com/users/ericsoco/orgs","repos_url":"https://api.github.com/users/ericsoco/repos","events_url":"https://api.github.com/users/ericsoco/events{/privacy}","received_events_url":"https://api.github.com/users/ericsoco/received_events","type":"User","site_admin":false},"body":"I've worked around this TODO before as well -- @ibgreen , any context here? How low does this fruit hang?","created_at":"2017-06-01T05:39:48Z","updated_at":"2017-06-01T05:39:48Z","html_url":"https://github.com/uber/deck.gl/pull/673#discussion_r119531334","pull_request_url":"https://api.github.com/repos/uber/deck.gl/pulls/673","_links":{"self":{"href":"https://api.github.com/repos/uber/deck.gl/pulls/comments/119531334"},"html":{"href":"https://github.com/uber/deck.gl/pull/673#discussion_r119531334"},"pull_request":{"href":"https://api.github.com/repos/uber/deck.gl/pulls/673"}}},"pull_request":{"url":"https://api.github.com/repos/uber/deck.gl/pulls/673","id":123408732,"html_url":"https://github.com/uber/deck.gl/pull/673","diff_url":"https://github.com/uber/deck.gl/pull/673.diff","patch_url":"https://github.com/uber/deck.gl/pull/673.patch","issue_url":"https://api.github.com/repos/uber/deck.gl/issues/673","number":673,"state":"open","locked":false,"title":"Add queryObjects api to DeckGL component","user":{"login":"Pessimistress","id":2059298,"avatar_url":"https://avatars1.githubusercontent.com/u/2059298?v=3","gravatar_id":"","url":"https://api.github.com/users/Pessimistress","html_url":"https://github.com/Pessimistress","followers_url":"https://api.github.com/users/Pessimistress/followers","following_url":"https://api.github.com/users/Pessimistress/following{/other_user}","gists_url":"https://api.github.com/users/Pessimistress/gists{/gist_id}","starred_url":"https://api.github.com/users/Pessimistress/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pessimistress/subscriptions","organizations_url":"https://api.github.com/users/Pessimistress/orgs","repos_url":"https://api.github.com/users/Pessimistress/repos","events_url":"https://api.github.com/users/Pessimistress/events{/privacy}","received_events_url":"https://api.github.com/users/Pessimistress/received_events","type":"User","site_admin":false},"body":"Given a bounding box and a list of layer ids (optional), returns an array of unique picking info objects.\r\n\r\nAs discussed before, the limitation of this API is that it doesn't return occluded objects.","created_at":"2017-06-01T02:48:11Z","updated_at":"2017-06-01T05:39:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"38f07a86e90dd4afd100facf050c4015e4b874fb","assignee":null,"assignees":[],"requested_reviewers":[{"login":"gnavvy","id":144743,"avatar_url":"https://avatars0.githubusercontent.com/u/144743?v=3","gravatar_id":"","url":"https://api.github.com/users/gnavvy","html_url":"https://github.com/gnavvy","followers_url":"https://api.github.com/users/gnavvy/followers","following_url":"https://api.github.com/users/gnavvy/following{/other_user}","gists_url":"https://api.github.com/users/gnavvy/gists{/gist_id}","starred_url":"https://api.github.com/users/gnavvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnavvy/subscriptions","organizations_url":"https://api.github.com/users/gnavvy/orgs","repos_url":"https://api.github.com/users/gnavvy/repos","events_url":"https://api.github.com/users/gnavvy/events{/privacy}","received_events_url":"https://api.github.com/users/gnavvy/received_events","type":"User","site_admin":false},{"login":"shaojingli","id":21322704,"avatar_url":"https://avatars2.githubusercontent.com/u/21322704?v=3","gravatar_id":"","url":"https://api.github.com/users/shaojingli","html_url":"https://github.com/shaojingli","followers_url":"https://api.github.com/users/shaojingli/followers","following_url":"https://api.github.com/users/shaojingli/following{/other_user}","gists_url":"https://api.github.com/users/shaojingli/gists{/gist_id}","starred_url":"https://api.github.com/users/shaojingli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shaojingli/subscriptions","organizations_url":"https://api.github.com/users/shaojingli/orgs","repos_url":"https://api.github.com/users/shaojingli/repos","events_url":"https://api.github.com/users/shaojingli/events{/privacy}","received_events_url":"https://api.github.com/users/shaojingli/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/uber/deck.gl/pulls/673/commits","review_comments_url":"https://api.github.com/repos/uber/deck.gl/pulls/673/comments","review_comment_url":"https://api.github.com/repos/uber/deck.gl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/deck.gl/issues/673/comments","statuses_url":"https://api.github.com/repos/uber/deck.gl/statuses/429008258b9c5b2be2c21fa9a998fae0b467cffe","head":{"label":"uber:query-objects","ref":"query-objects","sha":"429008258b9c5b2be2c21fa9a998fae0b467cffe","user":{"login":"uber","id":538264,"avatar_url":"https://avatars0.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":48030204,"name":"deck.gl","full_name":"uber/deck.gl","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars0.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/deck.gl","description":"WebGL based visualization layers","fork":false,"url":"https://api.github.com/repos/uber/deck.gl","forks_url":"https://api.github.com/repos/uber/deck.gl/forks","keys_url":"https://api.github.com/repos/uber/deck.gl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/deck.gl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/deck.gl/teams","hooks_url":"https://api.github.com/repos/uber/deck.gl/hooks","issue_events_url":"https://api.github.com/repos/uber/deck.gl/issues/events{/number}","events_url":"https://api.github.com/repos/uber/deck.gl/events","assignees_url":"https://api.github.com/repos/uber/deck.gl/assignees{/user}","branches_url":"https://api.github.com/repos/uber/deck.gl/branches{/branch}","tags_url":"https://api.github.com/repos/uber/deck.gl/tags","blobs_url":"https://api.github.com/repos/uber/deck.gl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/deck.gl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/deck.gl/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/deck.gl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/deck.gl/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/deck.gl/languages","stargazers_url":"https://api.github.com/repos/uber/deck.gl/stargazers","contributors_url":"https://api.github.com/repos/uber/deck.gl/contributors","subscribers_url":"https://api.github.com/repos/uber/deck.gl/subscribers","subscription_url":"https://api.github.com/repos/uber/deck.gl/subscription","commits_url":"https://api.github.com/repos/uber/deck.gl/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/deck.gl/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/deck.gl/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/deck.gl/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/deck.gl/contents/{+path}","compare_url":"https://api.github.com/repos/uber/deck.gl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/deck.gl/merges","archive_url":"https://api.github.com/repos/uber/deck.gl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/deck.gl/downloads","issues_url":"https://api.github.com/repos/uber/deck.gl/issues{/number}","pulls_url":"https://api.github.com/repos/uber/deck.gl/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/deck.gl/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/deck.gl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/deck.gl/labels{/name}","releases_url":"https://api.github.com/repos/uber/deck.gl/releases{/id}","deployments_url":"https://api.github.com/repos/uber/deck.gl/deployments","created_at":"2015-12-15T08:38:29Z","updated_at":"2017-06-01T05:11:12Z","pushed_at":"2017-06-01T02:48:12Z","git_url":"git://github.com/uber/deck.gl.git","ssh_url":"git@github.com:uber/deck.gl.git","clone_url":"https://github.com/uber/deck.gl.git","svn_url":"https://github.com/uber/deck.gl","homepage":"http://uber.github.io/deck.gl","size":97760,"stargazers_count":3030,"watchers_count":3030,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":312,"mirror_url":null,"open_issues_count":44,"forks":312,"open_issues":44,"watchers":3030,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"e41ef18386fa86e2cf50e17b1a2da8c3bd8fa301","user":{"login":"uber","id":538264,"avatar_url":"https://avatars0.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":48030204,"name":"deck.gl","full_name":"uber/deck.gl","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars0.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/deck.gl","description":"WebGL based visualization layers","fork":false,"url":"https://api.github.com/repos/uber/deck.gl","forks_url":"https://api.github.com/repos/uber/deck.gl/forks","keys_url":"https://api.github.com/repos/uber/deck.gl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/deck.gl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/deck.gl/teams","hooks_url":"https://api.github.com/repos/uber/deck.gl/hooks","issue_events_url":"https://api.github.com/repos/uber/deck.gl/issues/events{/number}","events_url":"https://api.github.com/repos/uber/deck.gl/events","assignees_url":"https://api.github.com/repos/uber/deck.gl/assignees{/user}","branches_url":"https://api.github.com/repos/uber/deck.gl/branches{/branch}","tags_url":"https://api.github.com/repos/uber/deck.gl/tags","blobs_url":"https://api.github.com/repos/uber/deck.gl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/deck.gl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/deck.gl/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/deck.gl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/deck.gl/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/deck.gl/languages","stargazers_url":"https://api.github.com/repos/uber/deck.gl/stargazers","contributors_url":"https://api.github.com/repos/uber/deck.gl/contributors","subscribers_url":"https://api.github.com/repos/uber/deck.gl/subscribers","subscription_url":"https://api.github.com/repos/uber/deck.gl/subscription","commits_url":"https://api.github.com/repos/uber/deck.gl/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/deck.gl/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/deck.gl/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/deck.gl/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/deck.gl/contents/{+path}","compare_url":"https://api.github.com/repos/uber/deck.gl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/deck.gl/merges","archive_url":"https://api.github.com/repos/uber/deck.gl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/deck.gl/downloads","issues_url":"https://api.github.com/repos/uber/deck.gl/issues{/number}","pulls_url":"https://api.github.com/repos/uber/deck.gl/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/deck.gl/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/deck.gl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/deck.gl/labels{/name}","releases_url":"https://api.github.com/repos/uber/deck.gl/releases{/id}","deployments_url":"https://api.github.com/repos/uber/deck.gl/deployments","created_at":"2015-12-15T08:38:29Z","updated_at":"2017-06-01T05:11:12Z","pushed_at":"2017-06-01T02:48:12Z","git_url":"git://github.com/uber/deck.gl.git","ssh_url":"git@github.com:uber/deck.gl.git","clone_url":"https://github.com/uber/deck.gl.git","svn_url":"https://github.com/uber/deck.gl","homepage":"http://uber.github.io/deck.gl","size":97760,"stargazers_count":3030,"watchers_count":3030,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":312,"mirror_url":null,"open_issues_count":44,"forks":312,"open_issues":44,"watchers":3030,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/deck.gl/pulls/673"},"html":{"href":"https://github.com/uber/deck.gl/pull/673"},"issue":{"href":"https://api.github.com/repos/uber/deck.gl/issues/673"},"comments":{"href":"https://api.github.com/repos/uber/deck.gl/issues/673/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/deck.gl/pulls/673/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/deck.gl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/deck.gl/pulls/673/commits"},"statuses":{"href":"https://api.github.com/repos/uber/deck.gl/statuses/429008258b9c5b2be2c21fa9a998fae0b467cffe"}}}}
{"actor":{"display_login":"ericsoco"}}