Search in sources :

Example 1 with PointArray

use of org.neo4j.values.storable.PointArray 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)

Example 2 with PointArray

use of org.neo4j.values.storable.PointArray in project neo4j by neo4j.

the class GenericAccessorPointsTest method mustHandlePointArraysWithinSameTile.

/**
 * This test verify that we correctly handle unique point arrays where every point in every array belong to the same tile on the space filling curve.
 * We verify this by asserting that we always get exactly one hit on an exact match and that the value is what we expect.
 */
@Test
void mustHandlePointArraysWithinSameTile() throws IndexEntryConflictException, IndexNotApplicableKernelException {
    // given
    // Many random points that all are close enough to each other to belong to the same tile on the space filling curve.
    int nbrOfValues = 10000;
    PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
    Long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
    double[] centerPoint = curve.centerPointFor(derivedValueForCenterPoint);
    double xWidthMultiplier = curve.getTileWidth(0, curve.getMaxLevel()) / 2;
    double yWidthMultiplier = curve.getTileWidth(1, curve.getMaxLevel()) / 2;
    List<Value> pointArrays = new ArrayList<>();
    List<IndexEntryUpdate<?>> updates = new ArrayList<>();
    for (int i = 0; i < nbrOfValues; i++) {
        int arrayLength = random.nextInt(5) + 1;
        PointValue[] pointValues = new PointValue[arrayLength];
        for (int j = 0; j < arrayLength; j++) {
            double x = (random.nextDouble() * 2 - 1) * xWidthMultiplier;
            double y = (random.nextDouble() * 2 - 1) * yWidthMultiplier;
            PointValue value = Values.pointValue(WGS84, centerPoint[0] + x, centerPoint[1] + y);
            assertDerivedValue(derivedValueForCenterPoint, value);
            pointValues[j] = value;
        }
        PointArray array = Values.pointArray(pointValues);
        pointArrays.add(array);
        updates.add(IndexEntryUpdate.add(i, descriptor, array));
    }
    processAll(updates);
    // then
    exactMatchOnAllValues(pointArrays);
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) PointValue(org.neo4j.values.storable.PointValue) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) PointArray(org.neo4j.values.storable.PointArray) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 PointArray (org.neo4j.values.storable.PointArray)2 PointValue (org.neo4j.values.storable.PointValue)2 ArrayList (java.util.ArrayList)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)1 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)1 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)1 Value (org.neo4j.values.storable.Value)1