Skip to content

Commit

Permalink
Removed scala geometry type.
Browse files Browse the repository at this point in the history
  • Loading branch information
sherfert authored and MishaDemianenko committed Nov 27, 2017
1 parent a0c7a7d commit d83dfbd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 176 deletions.
Expand Up @@ -28,26 +28,22 @@
import java.util.Iterator;
import java.util.List;

import org.neo4j.cypher.internal.runtime.CRS;
import org.neo4j.cypher.internal.runtime.CartesianPoint;
import org.neo4j.cypher.internal.runtime.GeographicPoint;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Path;
import org.neo4j.graphdb.PropertyContainer;
import org.neo4j.graphdb.Relationship;
import org.neo4j.helpers.collection.ReverseArrayIterator;
import org.neo4j.kernel.impl.core.NodeManager;
import org.neo4j.values.AnyValueWriter;
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.TextArray;
import org.neo4j.values.storable.TextValue;
import org.neo4j.values.storable.CoordinateReferenceSystem;
import org.neo4j.values.storable.Values;
import org.neo4j.values.virtual.EdgeValue;
import org.neo4j.values.virtual.MapValue;
import org.neo4j.values.virtual.NodeValue;

import static org.neo4j.helpers.collection.Iterators.iteratorsEqual;
import static org.neo4j.values.storable.CoordinateReferenceSystem.Cartesian;
import static org.neo4j.values.storable.CoordinateReferenceSystem.WGS84;

/**
* Used for turning parameters into appropriate types in the compiled runtime
Expand Down Expand Up @@ -346,18 +342,7 @@ public void writeByteArray( byte[] value ) throws RuntimeException
@Override
public void writePoint( CoordinateReferenceSystem crs, double[] coordinate ) throws RuntimeException
{
if ( crs.equals( WGS84 ) )
{
writeValue( new GeographicPoint( coordinate[0], coordinate[1], new CRS( crs.name, crs.code, crs.href ) ) );
}
else if ( crs.equals( Cartesian ) )
{
writeValue( new CartesianPoint( coordinate[0], coordinate[1], new CRS( crs.name, crs.code, crs.href ) ) );
}
else
{
throw new IllegalArgumentException( crs + " is not a supported coordinate reference system" );
}
writeValue( Values.pointValue( crs, coordinate ) );
}

private interface Writer
Expand Down
Expand Up @@ -21,12 +21,11 @@ package org.neo4j.cypher.internal.runtime.interpreted.commands.expressions

import java.lang.Math._

import org.neo4j.cypher.internal.runtime.CRS
import org.neo4j.cypher.internal.util.v3_4.CypherTypeException
import org.neo4j.cypher.internal.runtime.interpreted.pipes.QueryState
import org.neo4j.cypher.internal.runtime.interpreted.ExecutionContext
import org.neo4j.values.AnyValue
import org.neo4j.values.storable.{DoubleValue, PointValue, Values}
import org.neo4j.values.storable.{CoordinateReferenceSystem, DoubleValue, PointValue, Values}

case class DistanceFunction(p1: Expression, p2: Expression) extends Expression {

Expand Down Expand Up @@ -74,7 +73,8 @@ trait DistanceCalculator {

object CartesianCalculator extends DistanceCalculator {
override def isDefinedAt(p1: PointValue, p2: PointValue): Boolean =
p1.getCoordinateReferenceSystem.code == CRS.Cartesian.code && p2.getCoordinateReferenceSystem.code == CRS.Cartesian.code
p1.getCoordinateReferenceSystem.code == CoordinateReferenceSystem.Cartesian.code &&
p2.getCoordinateReferenceSystem.code == CoordinateReferenceSystem.Cartesian.code

override def calculateDistance(p1: PointValue, p2: PointValue): Double = {
val p1Coordinates = p1.coordinate()
Expand All @@ -90,7 +90,8 @@ object HaversinCalculator extends DistanceCalculator {
private val EARTH_RADIUS_METERS = 6378140.0

override def isDefinedAt(p1: PointValue, p2: PointValue): Boolean =
p1.getCoordinateReferenceSystem.code == CRS.WGS84.code && p2.getCoordinateReferenceSystem.code == CRS.WGS84.code
p1.getCoordinateReferenceSystem.code == CoordinateReferenceSystem.WGS84.code &&
p2.getCoordinateReferenceSystem.code == CoordinateReferenceSystem.WGS84.code

override def calculateDistance(p1: PointValue, p2: PointValue): Double = {
val c1Coord = p1.coordinate()
Expand Down

This file was deleted.

Expand Up @@ -41,18 +41,23 @@ public static CoordinateReferenceSystem get( CRS crs )
}
else
{
if ( CoordinateReferenceSystem.WGS84.href.equals( crs.getHref() ) )
{
return CoordinateReferenceSystem.WGS84;
}
else if ( CoordinateReferenceSystem.Cartesian.href.equals( crs.getHref() ) )
{
return CoordinateReferenceSystem.Cartesian;
}
else
{
throw new UnsupportedOperationException( "Unknown CRS: " + crs );
}
return get(crs.getHref());
}
}

public static CoordinateReferenceSystem get( String href )
{
if ( CoordinateReferenceSystem.WGS84.href.equals( href ) )
{
return CoordinateReferenceSystem.WGS84;
}
else if ( CoordinateReferenceSystem.Cartesian.href.equals( href ) )
{
return CoordinateReferenceSystem.Cartesian;
}
else
{
throw new UnsupportedOperationException( "Unknown CRS: " + href );
}
}

Expand Down
Expand Up @@ -27,7 +27,7 @@ import org.neo4j.cypher.internal.compiler.v3_4.planner.CantCompileQueryException
import org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService
import org.neo4j.cypher.internal.runtime.planDescription.InternalPlanDescription
import org.neo4j.cypher.internal.runtime.planDescription.InternalPlanDescription.Arguments.{Planner => IPDPlanner, Runtime => IPDRuntime, Version => IPDVersion}
import org.neo4j.cypher.internal.runtime.{CRS, CartesianPoint, GeographicPoint, InternalExecutionResult}
import org.neo4j.cypher.internal.runtime.InternalExecutionResult
import org.neo4j.cypher.internal.util.v3_4.Eagerly
import org.neo4j.cypher.internal.util.v3_4.test_helpers.CypherTestSupport
import org.neo4j.cypher.internal.v3_4.logical.plans.LogicalPlan
Expand All @@ -37,6 +37,7 @@ import org.neo4j.graphdb.factory.GraphDatabaseSettings
import org.neo4j.helpers.Exceptions
import org.neo4j.internal.cypher.acceptance.NewRuntimeMonitor.{NewPlanSeen, NewRuntimeMonitorCall, UnableToCompileQuery}
import org.neo4j.test.TestEnterpriseGraphDatabaseFactory
import org.neo4j.values.storable.{CoordinateReferenceSystem, Values}
import org.scalatest.Assertions
import org.scalatest.matchers.{MatchResult, Matcher}

Expand Down Expand Up @@ -73,8 +74,8 @@ trait CypherComparisonSupport extends CypherTestSupport {

def toComparableSeq(replaceNaNs: Boolean): Seq[Map[String, Any]] = {
def convert(v: Any): Any = v match {
case p: GeographicPointv3_1 => GeographicPoint(p.longitude, p.latitude, CRS(p.crs.name, p.crs.code, p.crs.url))
case p: CartesianPointv3_1 => CartesianPoint(p.x, p.y, CRS(p.crs.name, p.crs.code, p.crs.url))
case p: GeographicPointv3_1 => Values.pointValue(CoordinateReferenceSystem.get(p.crs.url), p.longitude, p.latitude)
case p: CartesianPointv3_1 => Values.pointValue(CoordinateReferenceSystem.get(p.crs.url), p.x, p.y)
case a: Array[_] => a.toList.map(convert)
case m: Map[_, _] =>
Eagerly.immutableMapValues(m, convert)
Expand Down

0 comments on commit d83dfbd

Please sign in to comment.