diff --git a/src/engine/SpatialJoinAlgorithms.cpp b/src/engine/SpatialJoinAlgorithms.cpp index 445883ed2b..5576aa13cb 100644 --- a/src/engine/SpatialJoinAlgorithms.cpp +++ b/src/engine/SpatialJoinAlgorithms.cpp @@ -301,7 +301,7 @@ std::vector SpatialJoinAlgorithms::computeBoundingBox( // safety buffer for numerical inaccuracies double maxDistInMetersBuffer = maxDist.value() + additionalDist; - if (maxDist.value() < 10) { + if (maxDistInMetersBuffer < 10) { maxDistInMetersBuffer = 10; } else if (static_cast(maxDist.value()) < static_cast(std::numeric_limits::max()) / diff --git a/src/engine/SpatialJoinAlgorithms.h b/src/engine/SpatialJoinAlgorithms.h index e5b60582c6..8efd250ad6 100644 --- a/src/engine/SpatialJoinAlgorithms.h +++ b/src/engine/SpatialJoinAlgorithms.h @@ -20,8 +20,6 @@ namespace bgi = boost::geometry::index; using Point = bg::model::point; using Box = bg::model::box; -// using Value = std::pair; // TODO: remove this line, it's -// legacy, when areas were not yet possible using Value = std::pair; using Polygon = boost::geometry::model::polygon< boost::geometry::model::d2::point_xy>; @@ -102,7 +100,7 @@ class SpatialJoinAlgorithms { // map and in the internal representation it looks like two/more boxes). The // additionalDist gets added on the max distance to compensate for areas being // bigger than points. AdditionalDist must be the max distance from the - // midpoint of the bounding box of the area to any point inside the method. + // midpoint of the bounding box of the area to any point inside the area. // The function getMaxDistFromMidpointToAnyPointInsideTheBox() can be used to // calculate it. std::vector computeBoundingBox( diff --git a/test/engine/SpatialJoinAlgorithmsTest.cpp b/test/engine/SpatialJoinAlgorithmsTest.cpp index 133a001fe2..7c6b861244 100644 --- a/test/engine/SpatialJoinAlgorithmsTest.cpp +++ b/test/engine/SpatialJoinAlgorithmsTest.cpp @@ -31,7 +31,8 @@ using SJ = std::variant; namespace computeResultTest { // Represents from left to right: the algorithm, addLeftChildFirst, -// bigChildLeft, a spatial join task and if areas or points should be used +// bigChildLeft, a spatial join task and if areas (=true) or points (=false) +// should be used using SpatialJoinTestParam = std::tuple; @@ -277,7 +278,7 @@ class SpatialJoinParamTest void testWrongPointInInput(SJ task, bool addLeftChildFirst, Rows expectedOutput, Row columnNames) { - auto kg = createSmallDatasetWithPoints(); + auto kg = createSmallDataset(); // make first point wrong: auto pos = kg.find("POINT("); kg = kg.insert(pos + 7, "wrongStuff"); @@ -339,11 +340,13 @@ class SpatialJoinParamTest : "\"Statue of liberty\""; std::string name5 = (std::get<4>(GetParam())) ? "\"eiffel tower Area\"" : "\"eiffel tower\""; + std::string node1 = (std::get<4>(GetParam())) ? "" : ""; std::string node2 = (std::get<4>(GetParam())) ? "" : ""; std::string node3 = (std::get<4>(GetParam())) ? "" : ""; std::string node4 = (std::get<4>(GetParam())) ? "" : ""; std::string node5 = (std::get<4>(GetParam())) ? "" : ""; + std::string geometry1 = (std::get<4>(GetParam())) ? "" : ""; std::string geometry2 = @@ -354,6 +357,7 @@ class SpatialJoinParamTest (std::get<4>(GetParam())) ? "" : ""; std::string geometry5 = (std::get<4>(GetParam())) ? "" : ""; + std::string wktString1 = (std::get<4>(GetParam())) ? SpatialJoinTestHelpers::areaUniFreiburg : "POINT(7.835050 48.012670)"; @@ -402,18 +406,8 @@ class SpatialJoinParamTest Row expectedDistSelf{"0"}; // helper functions - // auto P = [](double x, double y) { return GeoPoint(y, x); }; // TODO: - // delete this line GeoPoint P(double x, double y) { return GeoPoint(y, x); } - /* TODO: delete this lambda - auto expectedDist = [](const GeoPoint& p1, const GeoPoint& p2) { - auto p1_ = S2Point{S2LatLng::FromDegrees(p1.getLat(), p1.getLng())}; - auto p2_ = S2Point{S2LatLng::FromDegrees(p2.getLat(), p2.getLng())}; - - return std::to_string(S2Earth::ToKm(S1Angle(p1_, p2_))); - };*/ - std::string expectedDist(const GeoPoint& p1, const GeoPoint& p2) { auto p1_ = S2Point{S2LatLng::FromDegrees(p1.getLat(), p1.getLng())}; auto p2_ = S2Point{S2LatLng::FromDegrees(p2.getLat(), p2.getLng())}; diff --git a/test/engine/SpatialJoinTest.cpp b/test/engine/SpatialJoinTest.cpp index ed49d54e86..020c952670 100644 --- a/test/engine/SpatialJoinTest.cpp +++ b/test/engine/SpatialJoinTest.cpp @@ -607,7 +607,7 @@ INSTANTIATE_TEST_SUITE_P(SpatialJoin, SpatialJoinKnownEmptyTest, namespace resultSortedOn { TEST(SpatialJoin, resultSortedOn) { - std::string kg = createSmallDatasetWithPoints(); + std::string kg = createSmallDataset(); ad_utility::MemorySize blocksizePermutations = 16_MB; auto qec = getQec(kg, true, true, false, blocksizePermutations, false); @@ -727,7 +727,7 @@ class SpatialJoinMultiplicityAndSizeEstimateTest }; const double doubleBound = 0.00001; - std::string kg = createSmallDatasetWithPoints(); + std::string kg = createSmallDataset(); // add multiplicities to test knowledge graph kg += " \"testing multiplicity\" ."; @@ -859,7 +859,7 @@ class SpatialJoinMultiplicityAndSizeEstimateTest // ================================ here the children are only index // scans, as they are perfectly predictable in relation to size and // multiplicity estimates - std::string kg = createSmallDatasetWithPoints(); + std::string kg = createSmallDataset(); // add multiplicities to test knowledge graph kg += " \"POINT(7.12345 48.12345)\"."; diff --git a/test/engine/SpatialJoinTestHelpers.h b/test/engine/SpatialJoinTestHelpers.h index 98a2f1f759..0f21cfed37 100644 --- a/test/engine/SpatialJoinTestHelpers.h +++ b/test/engine/SpatialJoinTestHelpers.h @@ -250,17 +250,17 @@ inline std::vector createRowVectorFromColumnVector( return result; } -// create a small test dataset, which focuses on points as geometry objects. -// Note, that some of these objects have a polygon representation, but for -// testing purposes, they get represented as a point here. I took those +// create a small test dataset, which focuses on points or polygons as geometry +// objects. Note, that some of these objects have a polygon representation, but +// when choosing points, they get represented a single point. I took those // points, such that it is obvious, which pair of objects should be included, // when the maximum distance is x meters. Please note, that these datapoints -// are not copied from a real input file. Copying the query will therefore -// likely not result in the same results as here (also the names, coordinates, -// etc. might be different in the real datasets). The updated method also -// supports polygons as areas, which can be added to the knowledge graph using -// a boolean flag -inline std::string createSmallDatasetWithPoints(bool usePolygons = false) { +// are only partially copied from a real input file. Copying the query will +// therefore likely not result in the same results as here (the names, +// coordinates, etc. might be different in the real datasets). If usePolygons is +// set to false, all objects are represented by a point, otherwise all objects +// are represented by their area. +inline std::string createSmallDataset(bool usePolygons = false) { auto addPoint = [](std::string& kg, std::string number, std::string name, std::string point) { kg += absl::StrCat(" ", name, " . turtleInput = std::nullopt, bool loadAllPermutations = true, bool usePatterns = true,