.. _program_listing_file_dx2_utils.cxx: Program Listing for File utils.cxx ================================== |exhale_lsh| :ref:`Return to documentation for file ` (``dx2/utils.cxx``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #include "dx2/utils.hpp" #include #include #include #include #include using Eigen::Vector3d; double angle_between_vectors_degrees(Vector3d v1, Vector3d v2) { double l1 = v1.norm(); double l2 = v2.norm(); double dot = v1.dot(v2); double normdot = dot / (l1 * l2); if (std::abs(normdot - 1.0) < 1E-6) { return 0.0; } if (std::abs(normdot + 1.0) < 1E-6) { return 180.0; } double angle = std::acos(normdot) * 180.0 / M_PI; return angle; } std::string ersatz_uuid4() { // Generate 16 random bytes std::array bytes; std::random_device rd; std::uniform_int_distribution dist(0, 255); for (auto &b : bytes) { b = static_cast(dist(rd)); } // Convert bytes to a single 128-bit hex string (little endian) std::ostringstream oss; for (auto it = bytes.rbegin(); it != bytes.rend(); ++it) { oss << std::hex << std::setw(2) << std::setfill('0') << static_cast(*it); } std::string hex = oss.str(); // Format as UUID: 8-4-4-4-12 std::ostringstream uuid; uuid << hex.substr(0, 8) << "-" << hex.substr(8, 4) << "-" << hex.substr(12, 4) << "-" << hex.substr(16, 4) << "-" << hex.substr(20, 12); return uuid.str(); }