Search in sources :

Example 6 with SpaceFillingCurve

use of org.neo4j.gis.spatial.index.curves.SpaceFillingCurve in project neo4j by neo4j.

the class GenericKeyStateTest method comparePointArraysMustOnlyReturnZeroForEqualArrays.

@Test
void comparePointArraysMustOnlyReturnZeroForEqualArrays() {
    PointArray firstArray = random.randomValues().nextPointArray();
    PointValue[] sourcePointValues = firstArray.asObjectCopy();
    PointArray equalArray = Values.pointArray(sourcePointValues);
    PointValue[] centerPointValues = new PointValue[sourcePointValues.length];
    for (int i = 0; i < sourcePointValues.length; i++) {
        PointValue sourcePointValue = sourcePointValues[i];
        CoordinateReferenceSystem crs = sourcePointValue.getCoordinateReferenceSystem();
        SpaceFillingCurve curve = noSpecificIndexSettings.forCrs(crs);
        Long spaceFillingCurveValue = curve.derivedValueFor(sourcePointValue.coordinate());
        centerPointValues[i] = Values.pointValue(crs, curve.centerPointFor(spaceFillingCurveValue));
    }
    PointArray centerArray = Values.pointArray(centerPointValues);
    GenericKey firstKey = newKeyState();
    firstKey.writeValue(firstArray, NEUTRAL);
    GenericKey equalKey = newKeyState();
    equalKey.writeValue(equalArray, NEUTRAL);
    GenericKey centerKey = newKeyState();
    centerKey.writeValue(centerArray, NEUTRAL);
    GenericKey noCoordsKey = newKeyState();
    noCoordsKey.writeValue(equalArray, NEUTRAL);
    GeometryType.setNoCoordinates(noCoordsKey);
    assertEquals(0, firstKey.compareValueTo(equalKey), "expected keys to be equal");
    assertEquals(firstArray.compareToSequence(centerArray, AnyValues.COMPARATOR) != 0, firstKey.compareValueTo(centerKey) != 0, "expected keys to be equal if and only if source points are equal");
    assertEquals(0, firstKey.compareValueTo(noCoordsKey), "expected keys to be equal");
}
Also used : PointValue(org.neo4j.values.storable.PointValue) SpaceFillingCurve(org.neo4j.gis.spatial.index.curves.SpaceFillingCurve) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) PointArray(org.neo4j.values.storable.PointArray) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)6 PointValue (org.neo4j.values.storable.PointValue)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)3 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 Config (org.neo4j.configuration.Config)1 Pair (org.neo4j.internal.helpers.collection.Pair)1 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)1 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)1 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)1 BridgingIndexProgressor (org.neo4j.kernel.api.index.BridgingIndexProgressor)1 ConfiguredSpaceFillingCurveSettingsCache (org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache)1 IndexSpecificSpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettings)1 SpaceFillingCurveSettings (org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings)1 PointArray (org.neo4j.values.storable.PointArray)1