paleolimbot commented on code in PR #45459:
URL: https://github.com/apache/arrow/pull/45459#discussion_r2059536427


##########
cpp/src/parquet/geospatial/util_internal_test.cc:
##########
@@ -0,0 +1,517 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <cmath>
+#include <cstring>
+
+#include "parquet/geospatial/util_internal.h"
+#include "parquet/test_util.h"
+
+namespace parquet::geospatial {
+
+TEST(TestGeometryUtil, TestBoundingBox) {
+  BoundingBox box;
+  EXPECT_EQ(box, BoundingBox({kInf, kInf, kInf, kInf}, {-kInf, -kInf, -kInf, 
-kInf}));
+  EXPECT_EQ(box.ToString(),
+            "BoundingBox\n  x: [inf, -inf]\n  y: [inf, -inf]\n  z: [inf, 
-inf]\n  m: "
+            "[inf, -inf]\n");
+
+  BoundingBox box_xyzm({-1, -2, -3, -4}, {1, 2, 3, 4});
+  BoundingBox box_xy({-10, -20, kInf, kInf}, {10, 20, -kInf, -kInf});
+  BoundingBox box_xyz({kInf, kInf, -30, kInf}, {-kInf, -kInf, 30, -kInf});
+  BoundingBox box_xym({kInf, kInf, kInf, -40}, {-kInf, -kInf, -kInf, 40});
+
+  box_xyzm.Merge(box_xy);
+  EXPECT_EQ(box_xyzm, BoundingBox({-10, -20, -3, -4}, {10, 20, 3, 4}));
+  EXPECT_EQ(box_xyzm.ToString(),
+            "BoundingBox\n  x: [-10, 10]\n  y: [-20, 20]\n  z: [-3, 3]\n  m: "
+            "[-4, 4]\n");

Review Comment:
   Good call! I added a dedicated test for the equality method.



##########
cpp/src/parquet/geospatial/util_internal_test.cc:
##########
@@ -0,0 +1,517 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <cmath>
+#include <cstring>
+
+#include "parquet/geospatial/util_internal.h"
+#include "parquet/test_util.h"
+
+namespace parquet::geospatial {
+
+TEST(TestGeometryUtil, TestBoundingBox) {
+  BoundingBox box;
+  EXPECT_EQ(box, BoundingBox({kInf, kInf, kInf, kInf}, {-kInf, -kInf, -kInf, 
-kInf}));
+  EXPECT_EQ(box.ToString(),
+            "BoundingBox\n  x: [inf, -inf]\n  y: [inf, -inf]\n  z: [inf, 
-inf]\n  m: "
+            "[inf, -inf]\n");
+
+  BoundingBox box_xyzm({-1, -2, -3, -4}, {1, 2, 3, 4});
+  BoundingBox box_xy({-10, -20, kInf, kInf}, {10, 20, -kInf, -kInf});
+  BoundingBox box_xyz({kInf, kInf, -30, kInf}, {-kInf, -kInf, 30, -kInf});
+  BoundingBox box_xym({kInf, kInf, kInf, -40}, {-kInf, -kInf, -kInf, 40});
+
+  box_xyzm.Merge(box_xy);
+  EXPECT_EQ(box_xyzm, BoundingBox({-10, -20, -3, -4}, {10, 20, 3, 4}));
+  EXPECT_EQ(box_xyzm.ToString(),
+            "BoundingBox\n  x: [-10, 10]\n  y: [-20, 20]\n  z: [-3, 3]\n  m: "
+            "[-4, 4]\n");
+
+  box_xyzm.Merge(box_xyz);
+  EXPECT_EQ(box_xyzm, BoundingBox({-10, -20, -30, -4}, {10, 20, 30, 4}));
+
+  box_xyzm.Merge(box_xym);
+  EXPECT_EQ(box_xyzm, BoundingBox({-10, -20, -30, -40}, {10, 20, 30, 40}));
+
+  double nan_dbl = std::numeric_limits<double>::quiet_NaN();
+  BoundingBox box_nan({nan_dbl, nan_dbl, nan_dbl, nan_dbl},
+                      {nan_dbl, nan_dbl, nan_dbl, nan_dbl});
+  box_xyzm.Merge(box_nan);
+  for (int i = 0; i < 4; i++) {
+    EXPECT_TRUE(std::isnan(box_xyzm.min[i]));
+    EXPECT_TRUE(std::isnan(box_xyzm.max[i]));
+  }
+
+  box_xyzm.Reset();
+  EXPECT_EQ(box_xyzm, BoundingBox());
+}
+
+struct WKBTestCase {
+  WKBTestCase() = default;
+  WKBTestCase(GeometryType geometry_type, Dimensions dimensions,
+              const std::vector<uint8_t>& wkb, const std::vector<double>& 
box_values = {})
+      : geometry_type(geometry_type), dimensions(dimensions), wkb(wkb) {
+    std::array<double, 4> mins = {kInf, kInf, kInf, kInf};
+    std::array<double, 4> maxes{-kInf, -kInf, -kInf, -kInf};
+
+    if (dimensions == Dimensions::kXYM) {
+      mins = {box_values[0], box_values[1], kInf, box_values[2]};
+      maxes = {box_values[3], box_values[4], -kInf, box_values[5]};
+    } else {
+      size_t coord_size = box_values.size() / 2;
+      for (uint32_t i = 0; i < coord_size; i++) {
+        mins[i] = box_values[i];
+        maxes[i] = box_values[coord_size + i];
+      }
+    }
+
+    box = BoundingBox(mins, maxes);
+  }
+  WKBTestCase(const WKBTestCase& other) = default;
+
+  GeometryType geometry_type;
+  Dimensions dimensions;
+  std::vector<uint8_t> wkb;
+  BoundingBox box;
+};
+
+std::ostream& operator<<(std::ostream& os, const WKBTestCase& obj) {
+  uint32_t iso_wkb_geometry_type =
+      static_cast<int>(obj.dimensions) * 1000 + 
static_cast<int>(obj.geometry_type);
+  os << "WKBTestCase<" << iso_wkb_geometry_type << ">";
+  return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const BoundingBox& obj) {

Review Comment:
   Moved!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to