+Coords::Coords(s4u::Host* host, const char* coordStr)
+{
+ if (!Coords::EXTENSION_ID.valid()) {
+ Coords::EXTENSION_ID = s4u::Host::extension_create<Coords>();
+ }
+
+ unsigned int cursor;
+ char* str;
+
+ xbt_dynar_t ctn_str = xbt_str_split_str(coordStr, " ");
+ xbt_assert(xbt_dynar_length(ctn_str) == 3, "Coordinates of %s must have 3 dimensions", host->name().c_str());
+
+ this->coords = xbt_dynar_new(sizeof(double), nullptr);
+ xbt_dynar_foreach (ctn_str, cursor, str) {
+ double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
+ xbt_dynar_push(this->coords, &val);
+ }
+ xbt_dynar_free(&ctn_str);
+ xbt_dynar_shrink(this->coords, 0);
+ host->extension_set<Coords>(this);
+}
+Coords::~Coords()
+{
+ xbt_dynar_free(&coords);
+}
+}; // namespace vivaldi
+
+static inline double euclidean_dist_comp(int index, xbt_dynar_t src, xbt_dynar_t dst)
+{
+ double src_coord = xbt_dynar_get_as(src, index, double);
+ double dst_coord = xbt_dynar_get_as(dst, index, double);
+
+ return (src_coord - dst_coord) * (src_coord - dst_coord);