{"action":"created","comment":{"url":"https://api.github.com/repos/google/blockly/pulls/comments/54495887","id":54495887,"diff_hunk":"@@ -579,104 +557,11 @@ Blockly.Connection.prototype.tighten_ = function() {\n  *     another connection or null, and 'radius' which is the distance.\n  */\n Blockly.Connection.prototype.closest = function(maxLimit, dx, dy) {\n-  if (this.targetConnection) {\n-    // Don't offer to connect to a connection that's already connected.\n-    return {connection: null, radius: maxLimit};\n-  }\n-  // Determine the opposite type of connection.\n-  var db = this.dbOpposite_;\n-\n-  // Since this connection is probably being dragged, add the delta.\n-  var currentX = this.x_ + dx;\n-  var currentY = this.y_ + dy;\n-\n-  // Binary search to find the closest y location.\n-  var pointerMin = 0;\n-  var pointerMax = db.length - 2;\n-  var pointerMid = pointerMax;\n-  while (pointerMin < pointerMid) {\n-    if (db[pointerMid].y_ < currentY) {\n-      pointerMin = pointerMid;\n-    } else {\n-      pointerMax = pointerMid;\n-    }\n-    pointerMid = Math.floor((pointerMin + pointerMax) / 2);\n-  }\n-\n-  // Walk forward and back on the y axis looking for the closest x,y point.\n-  pointerMin = pointerMid;\n-  pointerMax = pointerMid;\n-  var closestConnection = null;\n-  var sourceBlock = this.sourceBlock_;\n-  var thisConnection = this;\n-  if (db.length) {\n-    while (pointerMin >= 0 && checkConnection_(pointerMin)) {\n-      pointerMin--;\n-    }\n-    do {\n-      pointerMax++;\n-    } while (pointerMax < db.length && checkConnection_(pointerMax));\n-  }\n-\n-  /**\n-   * Computes if the current connection is within the allowed radius of another\n-   * connection.\n-   * This function is a closure and has access to outside variables.\n-   * @param {number} yIndex The other connection's index in the database.\n-   * @return {boolean} True if the search needs to continue: either the current\n-   *     connection's vertical distance from the other connection is less than\n-   *     the allowed radius, or if the connection is not compatible.\n-   * @private\n-   */\n-  function checkConnection_(yIndex) {\n-    var connection = db[yIndex];\n-    if (connection.type == Blockly.OUTPUT_VALUE ||\n-        connection.type == Blockly.PREVIOUS_STATEMENT) {\n-      // Don't offer to connect an already connected left (male) value plug to\n-      // an available right (female) value plug.  Don't offer to connect the\n-      // bottom of a statement block to one that's already connected.\n-      if (connection.targetConnection) {\n-        return true;\n-      }\n-    }\n-    // Offering to connect the top of a statement block to an already connected\n-    // connection is ok, we'll just insert it into the stack.\n-\n-    // Offering to connect the left (male) of a value block to an already\n-    // connected value pair is ok, we'll splice it in.\n-    // However, don't offer to splice into an unmovable block.\n-    if (connection.type == Blockly.INPUT_VALUE &&\n-        connection.targetConnection &&\n-        !connection.targetBlock().isMovable() &&\n-        !connection.targetBlock().isShadow()) {\n-      return true;\n-    }\n-\n-    // Do type checking.\n-    if (!thisConnection.checkType_(connection)) {\n-      return true;\n-    }\n-\n-    // Don't let blocks try to connect to themselves or ones they nest.\n-    var targetSourceBlock = connection.sourceBlock_;\n-    do {\n-      if (sourceBlock == targetSourceBlock) {\n-        return true;\n-      }\n-      targetSourceBlock = targetSourceBlock.getParent();\n-    } while (targetSourceBlock);\n-\n-    // Only connections within the maxLimit radius.\n-    var dx = currentX - connection.x_;\n-    var dy = currentY - connection.y_;\n-    var r = Math.sqrt(dx * dx + dy * dy);\n-    if (r <= maxLimit) {\n-      closestConnection = connection;\n-      maxLimit = r;\n-    }\n-    return Math.abs(dy) < maxLimit;\n+  var closestConnection = this.dbOpposite_.searchForClosest(this, maxLimit, dx, dy);\n+  if (closestConnection) {\n+    return {connection: closestConnection, radius: this.distanceFrom(closestConnection)};","path":"core/connection.js","position":null,"original_position":176,"commit_id":"76719867348c2689689339d6b265f45c670ef9f8","original_commit_id":"c177fa527684797feb8593337d07a22f6c66c428","user":{"login":"rachel-fenichel","id":13686399,"avatar_url":"https://avatars.githubusercontent.com/u/13686399?v=3","gravatar_id":"","url":"https://api.github.com/users/rachel-fenichel","html_url":"https://github.com/rachel-fenichel","followers_url":"https://api.github.com/users/rachel-fenichel/followers","following_url":"https://api.github.com/users/rachel-fenichel/following{/other_user}","gists_url":"https://api.github.com/users/rachel-fenichel/gists{/gist_id}","starred_url":"https://api.github.com/users/rachel-fenichel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rachel-fenichel/subscriptions","organizations_url":"https://api.github.com/users/rachel-fenichel/orgs","repos_url":"https://api.github.com/users/rachel-fenichel/repos","events_url":"https://api.github.com/users/rachel-fenichel/events{/privacy}","received_events_url":"https://api.github.com/users/rachel-fenichel/received_events","type":"User","site_admin":false},"body":"Cleaned up throughout.","created_at":"2016-02-29T23:07:36Z","updated_at":"2016-02-29T23:07:36Z","html_url":"https://github.com/google/blockly/pull/266#discussion_r54495887","pull_request_url":"https://api.github.com/repos/google/blockly/pulls/266","_links":{"self":{"href":"https://api.github.com/repos/google/blockly/pulls/comments/54495887"},"html":{"href":"https://github.com/google/blockly/pull/266#discussion_r54495887"},"pull_request":{"href":"https://api.github.com/repos/google/blockly/pulls/266"}}},"pull_request":{"url":"https://api.github.com/repos/google/blockly/pulls/266","id":60926256,"html_url":"https://github.com/google/blockly/pull/266","diff_url":"https://github.com/google/blockly/pull/266.diff","patch_url":"https://github.com/google/blockly/pull/266.patch","issue_url":"https://api.github.com/repos/google/blockly/issues/266","number":266,"state":"open","locked":false,"title":"Connection db testing","user":{"login":"rachel-fenichel","id":13686399,"avatar_url":"https://avatars.githubusercontent.com/u/13686399?v=3","gravatar_id":"","url":"https://api.github.com/users/rachel-fenichel","html_url":"https://github.com/rachel-fenichel","followers_url":"https://api.github.com/users/rachel-fenichel/followers","following_url":"https://api.github.com/users/rachel-fenichel/following{/other_user}","gists_url":"https://api.github.com/users/rachel-fenichel/gists{/gist_id}","starred_url":"https://api.github.com/users/rachel-fenichel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rachel-fenichel/subscriptions","organizations_url":"https://api.github.com/users/rachel-fenichel/orgs","repos_url":"https://api.github.com/users/rachel-fenichel/repos","events_url":"https://api.github.com/users/rachel-fenichel/events{/privacy}","received_events_url":"https://api.github.com/users/rachel-fenichel/received_events","type":"User","site_admin":false},"body":"Adding tests for the connection db and separating out connection and connectionDB behaviours.","created_at":"2016-02-27T00:38:07Z","updated_at":"2016-02-29T23:07:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"73300dad221bdccb5135df5dd1e007c19febfc5e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/blockly/pulls/266/commits","review_comments_url":"https://api.github.com/repos/google/blockly/pulls/266/comments","review_comment_url":"https://api.github.com/repos/google/blockly/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/blockly/issues/266/comments","statuses_url":"https://api.github.com/repos/google/blockly/statuses/76719867348c2689689339d6b265f45c670ef9f8","head":{"label":"rachel-fenichel:feature/connection_db_testing","ref":"feature/connection_db_testing","sha":"76719867348c2689689339d6b265f45c670ef9f8","user":{"login":"rachel-fenichel","id":13686399,"avatar_url":"https://avatars.githubusercontent.com/u/13686399?v=3","gravatar_id":"","url":"https://api.github.com/users/rachel-fenichel","html_url":"https://github.com/rachel-fenichel","followers_url":"https://api.github.com/users/rachel-fenichel/followers","following_url":"https://api.github.com/users/rachel-fenichel/following{/other_user}","gists_url":"https://api.github.com/users/rachel-fenichel/gists{/gist_id}","starred_url":"https://api.github.com/users/rachel-fenichel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rachel-fenichel/subscriptions","organizations_url":"https://api.github.com/users/rachel-fenichel/orgs","repos_url":"https://api.github.com/users/rachel-fenichel/repos","events_url":"https://api.github.com/users/rachel-fenichel/events{/privacy}","received_events_url":"https://api.github.com/users/rachel-fenichel/received_events","type":"User","site_admin":false},"repo":{"id":49751865,"name":"blockly","full_name":"rachel-fenichel/blockly","owner":{"login":"rachel-fenichel","id":13686399,"avatar_url":"https://avatars.githubusercontent.com/u/13686399?v=3","gravatar_id":"","url":"https://api.github.com/users/rachel-fenichel","html_url":"https://github.com/rachel-fenichel","followers_url":"https://api.github.com/users/rachel-fenichel/followers","following_url":"https://api.github.com/users/rachel-fenichel/following{/other_user}","gists_url":"https://api.github.com/users/rachel-fenichel/gists{/gist_id}","starred_url":"https://api.github.com/users/rachel-fenichel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rachel-fenichel/subscriptions","organizations_url":"https://api.github.com/users/rachel-fenichel/orgs","repos_url":"https://api.github.com/users/rachel-fenichel/repos","events_url":"https://api.github.com/users/rachel-fenichel/events{/privacy}","received_events_url":"https://api.github.com/users/rachel-fenichel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rachel-fenichel/blockly","description":"The web-based visual programming editor.","fork":true,"url":"https://api.github.com/repos/rachel-fenichel/blockly","forks_url":"https://api.github.com/repos/rachel-fenichel/blockly/forks","keys_url":"https://api.github.com/repos/rachel-fenichel/blockly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rachel-fenichel/blockly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rachel-fenichel/blockly/teams","hooks_url":"https://api.github.com/repos/rachel-fenichel/blockly/hooks","issue_events_url":"https://api.github.com/repos/rachel-fenichel/blockly/issues/events{/number}","events_url":"https://api.github.com/repos/rachel-fenichel/blockly/events","assignees_url":"https://api.github.com/repos/rachel-fenichel/blockly/assignees{/user}","branches_url":"https://api.github.com/repos/rachel-fenichel/blockly/branches{/branch}","tags_url":"https://api.github.com/repos/rachel-fenichel/blockly/tags","blobs_url":"https://api.github.com/repos/rachel-fenichel/blockly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rachel-fenichel/blockly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rachel-fenichel/blockly/git/refs{/sha}","trees_url":"https://api.github.com/repos/rachel-fenichel/blockly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rachel-fenichel/blockly/statuses/{sha}","languages_url":"https://api.github.com/repos/rachel-fenichel/blockly/languages","stargazers_url":"https://api.github.com/repos/rachel-fenichel/blockly/stargazers","contributors_url":"https://api.github.com/repos/rachel-fenichel/blockly/contributors","subscribers_url":"https://api.github.com/repos/rachel-fenichel/blockly/subscribers","subscription_url":"https://api.github.com/repos/rachel-fenichel/blockly/subscription","commits_url":"https://api.github.com/repos/rachel-fenichel/blockly/commits{/sha}","git_commits_url":"https://api.github.com/repos/rachel-fenichel/blockly/git/commits{/sha}","comments_url":"https://api.github.com/repos/rachel-fenichel/blockly/comments{/number}","issue_comment_url":"https://api.github.com/repos/rachel-fenichel/blockly/issues/comments{/number}","contents_url":"https://api.github.com/repos/rachel-fenichel/blockly/contents/{+path}","compare_url":"https://api.github.com/repos/rachel-fenichel/blockly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rachel-fenichel/blockly/merges","archive_url":"https://api.github.com/repos/rachel-fenichel/blockly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rachel-fenichel/blockly/downloads","issues_url":"https://api.github.com/repos/rachel-fenichel/blockly/issues{/number}","pulls_url":"https://api.github.com/repos/rachel-fenichel/blockly/pulls{/number}","milestones_url":"https://api.github.com/repos/rachel-fenichel/blockly/milestones{/number}","notifications_url":"https://api.github.com/repos/rachel-fenichel/blockly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rachel-fenichel/blockly/labels{/name}","releases_url":"https://api.github.com/repos/rachel-fenichel/blockly/releases{/id}","deployments_url":"https://api.github.com/repos/rachel-fenichel/blockly/deployments","created_at":"2016-01-16T00:12:26Z","updated_at":"2016-01-16T00:13:34Z","pushed_at":"2016-02-29T23:06:06Z","git_url":"git://github.com/rachel-fenichel/blockly.git","ssh_url":"git@github.com:rachel-fenichel/blockly.git","clone_url":"https://github.com/rachel-fenichel/blockly.git","svn_url":"https://github.com/rachel-fenichel/blockly","homepage":"https://developers.google.com/blockly/","size":51444,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"google:develop","ref":"develop","sha":"b567d6b0d7bea7e7be18e1bc12cf8e0d1d2bf314","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":13872231,"name":"blockly","full_name":"google/blockly","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/blockly","description":"The web-based visual programming editor.","fork":false,"url":"https://api.github.com/repos/google/blockly","forks_url":"https://api.github.com/repos/google/blockly/forks","keys_url":"https://api.github.com/repos/google/blockly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/blockly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/blockly/teams","hooks_url":"https://api.github.com/repos/google/blockly/hooks","issue_events_url":"https://api.github.com/repos/google/blockly/issues/events{/number}","events_url":"https://api.github.com/repos/google/blockly/events","assignees_url":"https://api.github.com/repos/google/blockly/assignees{/user}","branches_url":"https://api.github.com/repos/google/blockly/branches{/branch}","tags_url":"https://api.github.com/repos/google/blockly/tags","blobs_url":"https://api.github.com/repos/google/blockly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/blockly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/blockly/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/blockly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/blockly/statuses/{sha}","languages_url":"https://api.github.com/repos/google/blockly/languages","stargazers_url":"https://api.github.com/repos/google/blockly/stargazers","contributors_url":"https://api.github.com/repos/google/blockly/contributors","subscribers_url":"https://api.github.com/repos/google/blockly/subscribers","subscription_url":"https://api.github.com/repos/google/blockly/subscription","commits_url":"https://api.github.com/repos/google/blockly/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/blockly/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/blockly/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/blockly/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/blockly/contents/{+path}","compare_url":"https://api.github.com/repos/google/blockly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/blockly/merges","archive_url":"https://api.github.com/repos/google/blockly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/blockly/downloads","issues_url":"https://api.github.com/repos/google/blockly/issues{/number}","pulls_url":"https://api.github.com/repos/google/blockly/pulls{/number}","milestones_url":"https://api.github.com/repos/google/blockly/milestones{/number}","notifications_url":"https://api.github.com/repos/google/blockly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/blockly/labels{/name}","releases_url":"https://api.github.com/repos/google/blockly/releases{/id}","deployments_url":"https://api.github.com/repos/google/blockly/deployments","created_at":"2013-10-25T21:13:33Z","updated_at":"2016-02-29T17:58:37Z","pushed_at":"2016-02-29T23:06:07Z","git_url":"git://github.com/google/blockly.git","ssh_url":"git@github.com:google/blockly.git","clone_url":"https://github.com/google/blockly.git","svn_url":"https://github.com/google/blockly","homepage":"https://developers.google.com/blockly/","size":96328,"stargazers_count":2000,"watchers_count":2000,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":637,"mirror_url":null,"open_issues_count":68,"forks":637,"open_issues":68,"watchers":2000,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/blockly/pulls/266"},"html":{"href":"https://github.com/google/blockly/pull/266"},"issue":{"href":"https://api.github.com/repos/google/blockly/issues/266"},"comments":{"href":"https://api.github.com/repos/google/blockly/issues/266/comments"},"review_comments":{"href":"https://api.github.com/repos/google/blockly/pulls/266/comments"},"review_comment":{"href":"https://api.github.com/repos/google/blockly/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/blockly/pulls/266/commits"},"statuses":{"href":"https://api.github.com/repos/google/blockly/statuses/76719867348c2689689339d6b265f45c670ef9f8"}}}}