Search in sources :

Example 1 with PointValue

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

the class GenericKeyStateTest method comparePointsMustOnlyReturnZeroForEqualPoints.

@Test
void comparePointsMustOnlyReturnZeroForEqualPoints() {
    PointValue firstPoint = random.randomValues().nextPointValue();
    PointValue equalPoint = Values.point(firstPoint);
    CoordinateReferenceSystem crs = firstPoint.getCoordinateReferenceSystem();
    SpaceFillingCurve curve = noSpecificIndexSettings.forCrs(crs);
    Long spaceFillingCurveValue = curve.derivedValueFor(firstPoint.coordinate());
    PointValue centerPoint = Values.pointValue(crs, curve.centerPointFor(spaceFillingCurveValue));
    GenericKey firstKey = newKeyState();
    firstKey.writeValue(firstPoint, NEUTRAL);
    GenericKey equalKey = newKeyState();
    equalKey.writeValue(equalPoint, NEUTRAL);
    GenericKey centerKey = newKeyState();
    centerKey.writeValue(centerPoint, NEUTRAL);
    GenericKey noCoordsKey = newKeyState();
    noCoordsKey.writeValue(equalPoint, NEUTRAL);
    GeometryType.setNoCoordinates(noCoordsKey);
    assertEquals(0, firstKey.compareValueTo(equalKey), "expected keys to be equal");
    assertEquals(firstPoint.compareTo(centerPoint) != 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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with PointValue

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

the class GenericAccessorPointsTest method shouldNotGetRoundingErrorsWithPointsJustWithinTheTileUpperBound.

/**
 * The test mustHandlePointArraysWithinSameTile was flaky on random numbers that placed points just
 * within the tile upper bound, and allocated points to adjacent tiles due to rounding errors.
 * This test uses a specific point that triggers that exact failure in a non-flaky way.
 */
@Test
void shouldNotGetRoundingErrorsWithPointsJustWithinTheTileUpperBound() {
    PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
    long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
    // [1.6763806343078613E-7, 8.381903171539307E-8]
    double[] centerPoint = curve.centerPointFor(derivedValueForCenterPoint);
    // 1.6763806343078613E-7
    double xWidthMultiplier = curve.getTileWidth(0, curve.getMaxLevel()) / 2;
    // 8.381903171539307E-8
    double yWidthMultiplier = curve.getTileWidth(1, curve.getMaxLevel()) / 2;
    double[] faultyCoords = { 1.874410632171803E-8, 1.6763806281859016E-7 };
    assertTrue(centerPoint[0] + xWidthMultiplier > faultyCoords[0], "inside upper x limit");
    assertTrue(centerPoint[0] - xWidthMultiplier < faultyCoords[0], "inside lower x limit");
    assertTrue(centerPoint[1] + yWidthMultiplier > faultyCoords[1], "inside upper y limit");
    assertTrue(centerPoint[1] - yWidthMultiplier < faultyCoords[1], "inside lower y limit");
    long derivedValueForFaultyCoords = curve.derivedValueFor(faultyCoords);
    assertEquals(derivedValueForCenterPoint, derivedValueForFaultyCoords, "expected same derived value");
}
Also used : PointValue(org.neo4j.values.storable.PointValue) Test(org.junit.jupiter.api.Test)

Example 3 with PointValue

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

the class GenericAccessorPointsTest method assertDerivedValue.

private static void assertDerivedValue(Long targetDerivedValue, PointValue... values) {
    for (PointValue value : values) {
        Long derivedValueForValue = curve.derivedValueFor(value.coordinate());
        assertEquals(targetDerivedValue, derivedValueForValue, "expected random value to belong to same tile as center point");
    }
}
Also used : PointValue(org.neo4j.values.storable.PointValue)

Example 4 with PointValue

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

the class GenericAccessorPointsTest method addPointsToLists.

private long addPointsToLists(List<Value> pointValues, List<IndexEntryUpdate<?>> updates, long nodeId, PointValue... values) {
    for (PointValue value : values) {
        pointValues.add(value);
        updates.add(IndexEntryUpdate.add(nodeId++, descriptor, value));
    }
    return nodeId;
}
Also used : PointValue(org.neo4j.values.storable.PointValue)

Example 5 with PointValue

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

the class SimpleIndexAccessorCompatibility method testIndexRangeSeekWithSpatial.

@Test
public void testIndexRangeSeekWithSpatial() throws Exception {
    Assume.assumeTrue(testSuite.supportsSpatial());
    PointValue p1 = Values.pointValue(CoordinateReferenceSystem.WGS84, -180, -1);
    PointValue p2 = Values.pointValue(CoordinateReferenceSystem.WGS84, -180, 1);
    PointValue p3 = Values.pointValue(CoordinateReferenceSystem.WGS84, 0, 0);
    updateAndCommit(asList(add(1L, descriptor.schema(), p1), add(2L, descriptor.schema(), p2), add(3L, descriptor.schema(), p3)));
    assertThat(query(range(1, p1, true, p2, true))).containsExactly(1L, 2L);
}
Also used : PointValue(org.neo4j.values.storable.PointValue) Test(org.junit.Test)

Aggregations

PointValue (org.neo4j.values.storable.PointValue)32 Test (org.junit.jupiter.api.Test)16 ArrayList (java.util.ArrayList)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 Value (org.neo4j.values.storable.Value)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)7 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)7 Transaction (org.neo4j.graphdb.Transaction)6 Pair (org.neo4j.internal.helpers.collection.Pair)6 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)6 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)5 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)5 Values.stringValue (org.neo4j.values.storable.Values.stringValue)5 Path (java.nio.file.Path)4 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)4 Node (org.neo4j.graphdb.Node)4 TextValue (org.neo4j.values.storable.TextValue)4 Values.pointValue (org.neo4j.values.storable.Values.pointValue)4 SpaceFillingCurve (org.neo4j.gis.spatial.index.curves.SpaceFillingCurve)3 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)3