{"action":"created","comment":{"url":"https://api.github.com/repos/neo4j/neo4j/pulls/comments/41035630","id":41035630,"diff_hunk":"@@ -0,0 +1,100 @@\n+/*\n+ * Copyright (c) 2002-2015 \"Neo Technology,\"\n+ * Network Engine for Objects in Lund AB [http://neotechnology.com]\n+ *\n+ * This file is part of Neo4j.\n+ *\n+ * Neo4j is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation, either version 3 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ */\n+package org.neo4j.cypher.internal.compiler.v3_0.commands.expressions\n+\n+import org.neo4j.cypher.internal.compiler.v3_0.ExecutionContext\n+import org.neo4j.cypher.internal.compiler.v3_0.pipes.QueryState\n+import org.neo4j.cypher.internal.compiler.v3_0.symbols.SymbolTable\n+import org.neo4j.cypher.internal.frontend.v3_0.symbols._\n+import Math._\n+\n+case class DistanceFunction(p1: Expression, p2: Expression) extends Expression {\n+\n+  def apply(ctx: ExecutionContext)(implicit state: QueryState): Any = {\n+    val geometry1 = convertToGeometry(p1, ctx);\n+    val geometry2 = convertToGeometry(p2, ctx);\n+    // TODO: Support better calculations, like https://en.wikipedia.org/wiki/Vincenty%27s_formulae\n+    // TODO: Support more coordinate systems\n+    HaversinCalculator.distance(geometry1, geometry2).getOrElse(\n+      CartesianCalculator.distance(geometry1, geometry2).getOrElse(\n+        throw new IllegalArgumentException(s\"Invalid points passed to distance($p1, $p2)\")\n+      )\n+    )\n+  }\n+\n+  def convertToGeometry(p: Expression, ctx: ExecutionContext)\n+                       (implicit state: QueryState): Geometry = p match {","path":"community/cypher/cypher-compiler-3.0/src/main/scala/org/neo4j/cypher/internal/compiler/v3_0/commands/expressions/DistanceFunction.scala","position":43,"original_position":43,"commit_id":"c15003324ba030e211fa6781d3d1f98b93ea3584","original_commit_id":"c15003324ba030e211fa6781d3d1f98b93ea3584","user":{"login":"cleishm","id":79651,"avatar_url":"https://avatars.githubusercontent.com/u/79651?v=3","gravatar_id":"","url":"https://api.github.com/users/cleishm","html_url":"https://github.com/cleishm","followers_url":"https://api.github.com/users/cleishm/followers","following_url":"https://api.github.com/users/cleishm/following{/other_user}","gists_url":"https://api.github.com/users/cleishm/gists{/gist_id}","starred_url":"https://api.github.com/users/cleishm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cleishm/subscriptions","organizations_url":"https://api.github.com/users/cleishm/orgs","repos_url":"https://api.github.com/users/cleishm/repos","events_url":"https://api.github.com/users/cleishm/events{/privacy}","received_events_url":"https://api.github.com/users/cleishm/received_events","type":"User","site_admin":false},"body":"I don't think you should be trying to match the type of `Expression` here. That makes this code need to enumerate all the possible Expression types that could yield a valid value. I think the better idiom is to apply it with the context first, then match on the result. E.g.:\r\n\r\n```\r\np(ctx) match {\r\n  case p: Point => ...\r\n  case _ => error\r\n}\r\n```","created_at":"2015-10-02T15:44:26Z","updated_at":"2015-10-02T15:44:26Z","html_url":"https://github.com/neo4j/neo4j/pull/5520#discussion_r41035630","pull_request_url":"https://api.github.com/repos/neo4j/neo4j/pulls/5520","_links":{"self":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/comments/41035630"},"html":{"href":"https://github.com/neo4j/neo4j/pull/5520#discussion_r41035630"},"pull_request":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/5520"}}},"pull_request":{"url":"https://api.github.com/repos/neo4j/neo4j/pulls/5520","id":46644312,"html_url":"https://github.com/neo4j/neo4j/pull/5520","diff_url":"https://github.com/neo4j/neo4j/pull/5520.diff","patch_url":"https://github.com/neo4j/neo4j/pull/5520.patch","issue_url":"https://api.github.com/repos/neo4j/neo4j/issues/5520","number":5520,"state":"open","locked":false,"title":"3.0 spatial point and distance","user":{"login":"craigtaverner","id":114451,"avatar_url":"https://avatars.githubusercontent.com/u/114451?v=3","gravatar_id":"","url":"https://api.github.com/users/craigtaverner","html_url":"https://github.com/craigtaverner","followers_url":"https://api.github.com/users/craigtaverner/followers","following_url":"https://api.github.com/users/craigtaverner/following{/other_user}","gists_url":"https://api.github.com/users/craigtaverner/gists{/gist_id}","starred_url":"https://api.github.com/users/craigtaverner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigtaverner/subscriptions","organizations_url":"https://api.github.com/users/craigtaverner/orgs","repos_url":"https://api.github.com/users/craigtaverner/repos","events_url":"https://api.github.com/users/craigtaverner/events{/privacy}","received_events_url":"https://api.github.com/users/craigtaverner/received_events","type":"User","site_admin":false},"body":"Rebased from origin 2.3 PR, and refactored to take into account code comments.","created_at":"2015-10-02T14:55:32Z","updated_at":"2015-10-02T15:44:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f720dc2cd4af3d232304716e6769926c61d6f655","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/neo4j/neo4j/pulls/5520/commits","review_comments_url":"https://api.github.com/repos/neo4j/neo4j/pulls/5520/comments","review_comment_url":"https://api.github.com/repos/neo4j/neo4j/pulls/comments{/number}","comments_url":"https://api.github.com/repos/neo4j/neo4j/issues/5520/comments","statuses_url":"https://api.github.com/repos/neo4j/neo4j/statuses/c15003324ba030e211fa6781d3d1f98b93ea3584","head":{"label":"craigtaverner:3.0-spatial-point-and-distance","ref":"3.0-spatial-point-and-distance","sha":"c15003324ba030e211fa6781d3d1f98b93ea3584","user":{"login":"craigtaverner","id":114451,"avatar_url":"https://avatars.githubusercontent.com/u/114451?v=3","gravatar_id":"","url":"https://api.github.com/users/craigtaverner","html_url":"https://github.com/craigtaverner","followers_url":"https://api.github.com/users/craigtaverner/followers","following_url":"https://api.github.com/users/craigtaverner/following{/other_user}","gists_url":"https://api.github.com/users/craigtaverner/gists{/gist_id}","starred_url":"https://api.github.com/users/craigtaverner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigtaverner/subscriptions","organizations_url":"https://api.github.com/users/craigtaverner/orgs","repos_url":"https://api.github.com/users/craigtaverner/repos","events_url":"https://api.github.com/users/craigtaverner/events{/privacy}","received_events_url":"https://api.github.com/users/craigtaverner/received_events","type":"User","site_admin":false},"repo":{"id":17599080,"name":"neo4j","full_name":"craigtaverner/neo4j","owner":{"login":"craigtaverner","id":114451,"avatar_url":"https://avatars.githubusercontent.com/u/114451?v=3","gravatar_id":"","url":"https://api.github.com/users/craigtaverner","html_url":"https://github.com/craigtaverner","followers_url":"https://api.github.com/users/craigtaverner/followers","following_url":"https://api.github.com/users/craigtaverner/following{/other_user}","gists_url":"https://api.github.com/users/craigtaverner/gists{/gist_id}","starred_url":"https://api.github.com/users/craigtaverner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigtaverner/subscriptions","organizations_url":"https://api.github.com/users/craigtaverner/orgs","repos_url":"https://api.github.com/users/craigtaverner/repos","events_url":"https://api.github.com/users/craigtaverner/events{/privacy}","received_events_url":"https://api.github.com/users/craigtaverner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/craigtaverner/neo4j","description":"The World's Leading Graph Database","fork":true,"url":"https://api.github.com/repos/craigtaverner/neo4j","forks_url":"https://api.github.com/repos/craigtaverner/neo4j/forks","keys_url":"https://api.github.com/repos/craigtaverner/neo4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/craigtaverner/neo4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/craigtaverner/neo4j/teams","hooks_url":"https://api.github.com/repos/craigtaverner/neo4j/hooks","issue_events_url":"https://api.github.com/repos/craigtaverner/neo4j/issues/events{/number}","events_url":"https://api.github.com/repos/craigtaverner/neo4j/events","assignees_url":"https://api.github.com/repos/craigtaverner/neo4j/assignees{/user}","branches_url":"https://api.github.com/repos/craigtaverner/neo4j/branches{/branch}","tags_url":"https://api.github.com/repos/craigtaverner/neo4j/tags","blobs_url":"https://api.github.com/repos/craigtaverner/neo4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/craigtaverner/neo4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/craigtaverner/neo4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/craigtaverner/neo4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/craigtaverner/neo4j/statuses/{sha}","languages_url":"https://api.github.com/repos/craigtaverner/neo4j/languages","stargazers_url":"https://api.github.com/repos/craigtaverner/neo4j/stargazers","contributors_url":"https://api.github.com/repos/craigtaverner/neo4j/contributors","subscribers_url":"https://api.github.com/repos/craigtaverner/neo4j/subscribers","subscription_url":"https://api.github.com/repos/craigtaverner/neo4j/subscription","commits_url":"https://api.github.com/repos/craigtaverner/neo4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/craigtaverner/neo4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/craigtaverner/neo4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/craigtaverner/neo4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/craigtaverner/neo4j/contents/{+path}","compare_url":"https://api.github.com/repos/craigtaverner/neo4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/craigtaverner/neo4j/merges","archive_url":"https://api.github.com/repos/craigtaverner/neo4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/craigtaverner/neo4j/downloads","issues_url":"https://api.github.com/repos/craigtaverner/neo4j/issues{/number}","pulls_url":"https://api.github.com/repos/craigtaverner/neo4j/pulls{/number}","milestones_url":"https://api.github.com/repos/craigtaverner/neo4j/milestones{/number}","notifications_url":"https://api.github.com/repos/craigtaverner/neo4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/craigtaverner/neo4j/labels{/name}","releases_url":"https://api.github.com/repos/craigtaverner/neo4j/releases{/id}","created_at":"2014-03-10T16:12:05Z","updated_at":"2015-03-14T12:35:18Z","pushed_at":"2015-10-02T14:53:51Z","git_url":"git://github.com/craigtaverner/neo4j.git","ssh_url":"git@github.com:craigtaverner/neo4j.git","clone_url":"https://github.com/craigtaverner/neo4j.git","svn_url":"https://github.com/craigtaverner/neo4j","homepage":"http://neo4j.org","size":212044,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"neo4j:3.0","ref":"3.0","sha":"606a129d8e815e230ab47493b5ffe430b7bf7433","user":{"login":"neo4j","id":201120,"avatar_url":"https://avatars.githubusercontent.com/u/201120?v=3","gravatar_id":"","url":"https://api.github.com/users/neo4j","html_url":"https://github.com/neo4j","followers_url":"https://api.github.com/users/neo4j/followers","following_url":"https://api.github.com/users/neo4j/following{/other_user}","gists_url":"https://api.github.com/users/neo4j/gists{/gist_id}","starred_url":"https://api.github.com/users/neo4j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neo4j/subscriptions","organizations_url":"https://api.github.com/users/neo4j/orgs","repos_url":"https://api.github.com/users/neo4j/repos","events_url":"https://api.github.com/users/neo4j/events{/privacy}","received_events_url":"https://api.github.com/users/neo4j/received_events","type":"Organization","site_admin":false},"repo":{"id":6650539,"name":"neo4j","full_name":"neo4j/neo4j","owner":{"login":"neo4j","id":201120,"avatar_url":"https://avatars.githubusercontent.com/u/201120?v=3","gravatar_id":"","url":"https://api.github.com/users/neo4j","html_url":"https://github.com/neo4j","followers_url":"https://api.github.com/users/neo4j/followers","following_url":"https://api.github.com/users/neo4j/following{/other_user}","gists_url":"https://api.github.com/users/neo4j/gists{/gist_id}","starred_url":"https://api.github.com/users/neo4j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neo4j/subscriptions","organizations_url":"https://api.github.com/users/neo4j/orgs","repos_url":"https://api.github.com/users/neo4j/repos","events_url":"https://api.github.com/users/neo4j/events{/privacy}","received_events_url":"https://api.github.com/users/neo4j/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/neo4j/neo4j","description":"Graphs for Everyone","fork":false,"url":"https://api.github.com/repos/neo4j/neo4j","forks_url":"https://api.github.com/repos/neo4j/neo4j/forks","keys_url":"https://api.github.com/repos/neo4j/neo4j/keys{/key_id}","collaborators_url":"https://api.github.com/repos/neo4j/neo4j/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/neo4j/neo4j/teams","hooks_url":"https://api.github.com/repos/neo4j/neo4j/hooks","issue_events_url":"https://api.github.com/repos/neo4j/neo4j/issues/events{/number}","events_url":"https://api.github.com/repos/neo4j/neo4j/events","assignees_url":"https://api.github.com/repos/neo4j/neo4j/assignees{/user}","branches_url":"https://api.github.com/repos/neo4j/neo4j/branches{/branch}","tags_url":"https://api.github.com/repos/neo4j/neo4j/tags","blobs_url":"https://api.github.com/repos/neo4j/neo4j/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/neo4j/neo4j/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/neo4j/neo4j/git/refs{/sha}","trees_url":"https://api.github.com/repos/neo4j/neo4j/git/trees{/sha}","statuses_url":"https://api.github.com/repos/neo4j/neo4j/statuses/{sha}","languages_url":"https://api.github.com/repos/neo4j/neo4j/languages","stargazers_url":"https://api.github.com/repos/neo4j/neo4j/stargazers","contributors_url":"https://api.github.com/repos/neo4j/neo4j/contributors","subscribers_url":"https://api.github.com/repos/neo4j/neo4j/subscribers","subscription_url":"https://api.github.com/repos/neo4j/neo4j/subscription","commits_url":"https://api.github.com/repos/neo4j/neo4j/commits{/sha}","git_commits_url":"https://api.github.com/repos/neo4j/neo4j/git/commits{/sha}","comments_url":"https://api.github.com/repos/neo4j/neo4j/comments{/number}","issue_comment_url":"https://api.github.com/repos/neo4j/neo4j/issues/comments{/number}","contents_url":"https://api.github.com/repos/neo4j/neo4j/contents/{+path}","compare_url":"https://api.github.com/repos/neo4j/neo4j/compare/{base}...{head}","merges_url":"https://api.github.com/repos/neo4j/neo4j/merges","archive_url":"https://api.github.com/repos/neo4j/neo4j/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/neo4j/neo4j/downloads","issues_url":"https://api.github.com/repos/neo4j/neo4j/issues{/number}","pulls_url":"https://api.github.com/repos/neo4j/neo4j/pulls{/number}","milestones_url":"https://api.github.com/repos/neo4j/neo4j/milestones{/number}","notifications_url":"https://api.github.com/repos/neo4j/neo4j/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/neo4j/neo4j/labels{/name}","releases_url":"https://api.github.com/repos/neo4j/neo4j/releases{/id}","created_at":"2012-11-12T08:46:15Z","updated_at":"2015-10-02T07:07:36Z","pushed_at":"2015-10-02T15:22:24Z","git_url":"git://github.com/neo4j/neo4j.git","ssh_url":"git@github.com:neo4j/neo4j.git","clone_url":"https://github.com/neo4j/neo4j.git","svn_url":"https://github.com/neo4j/neo4j","homepage":"http://neo4j.com","size":522318,"stargazers_count":1986,"watchers_count":1986,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":758,"mirror_url":null,"open_issues_count":485,"forks":758,"open_issues":485,"watchers":1986,"default_branch":"2.3"}},"_links":{"self":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/5520"},"html":{"href":"https://github.com/neo4j/neo4j/pull/5520"},"issue":{"href":"https://api.github.com/repos/neo4j/neo4j/issues/5520"},"comments":{"href":"https://api.github.com/repos/neo4j/neo4j/issues/5520/comments"},"review_comments":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/5520/comments"},"review_comment":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/neo4j/neo4j/pulls/5520/commits"},"statuses":{"href":"https://api.github.com/repos/neo4j/neo4j/statuses/c15003324ba030e211fa6781d3d1f98b93ea3584"}}}}