paleolimbot commented on code in PR #45459:
URL: https://github.com/apache/arrow/pull/45459#discussion_r1975903356
##########
cpp/src/parquet/test_util.h:
##########
@@ -830,5 +833,124 @@ inline void GenerateData<FLBA>(int num_values, FLBA* out,
std::vector<uint8_t>*
random_fixed_byte_array(num_values, 0, heap->data(),
kGenerateDataFLBALength, out);
}
+// ----------------------------------------------------------------------
+// Test utility functions for geometry
+
+#if defined(ARROW_LITTLE_ENDIAN)
+static constexpr uint8_t kWkbNativeEndianness = 0x01;
+#else
+static constexpr uint8_t kWkbNativeEndianness = 0x00;
+#endif
+
+static uint32_t GeometryTypeToWKB(geometry::GeometryType geometry_type, bool
has_z,
+ bool has_m) {
+ auto wkb_geom_type = static_cast<uint32_t>(geometry_type);
+
+ if (has_z) {
+ wkb_geom_type += 1000;
+ }
+
+ if (has_m) {
+ wkb_geom_type += 2000;
+ }
+
+ return wkb_geom_type;
+}
+
+static inline std::string MakeWKBPoint(const double* xyzm, bool has_z, bool
has_m) {
+ // 1:endianness + 4:type + 8:x + 8:y
+ int num_bytes = 21 + (has_z ? 8 : 0) + (has_m ? 8 : 0);
+ std::string wkb(num_bytes, 0);
+ char* ptr = wkb.data();
+
+ ptr[0] = kWkbNativeEndianness;
+ uint32_t geom_type = GeometryTypeToWKB(geometry::GeometryType::POINT, has_z,
has_m);
+ std::memcpy(&ptr[1], &geom_type, 4);
+ std::memcpy(&ptr[5], &xyzm[0], 8);
+ std::memcpy(&ptr[13], &xyzm[1], 8);
+ ptr += 21;
+
+ if (has_z) {
+ std::memcpy(ptr, &xyzm[2], 8);
+ ptr += 8;
+ }
+ if (has_m) {
+ std::memcpy(ptr, &xyzm[3], 8);
+ }
+
+ return wkb;
+}
+
+static constexpr int kWkbPointSize = 21; // 1:endianness + 4:type + 8:x + 8:y
+
+inline void GenerateWKBPoint(uint8_t* ptr, double x, double y) {
+ double xyzm[] = {x, y, geometry::kInf, geometry::kInf};
+ std::string wkb = MakeWKBPoint(xyzm, false, false);
+ std::memcpy(ptr, wkb.data(), kWkbPointSize);
Review Comment:
I made this variable name more clear and added a comment (an XY point will
always be 21 bytes).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]