rust/landgen/src/wavefront_collapse/generator.rs
changeset 16064 07cb6dbc8444
parent 16062 288df7b85efc
child 16073 5d302b12d837
--- a/rust/landgen/src/wavefront_collapse/generator.rs	Mon Jan 27 13:08:58 2025 +0100
+++ b/rust/landgen/src/wavefront_collapse/generator.rs	Mon Jan 27 14:06:10 2025 +0100
@@ -364,3 +364,29 @@
         }
     }
 }
+
+impl<T: AsRef<str>> From<T> for EdgeDescription {
+    fn from(val: T) -> Self {
+        use std::cmp::Ordering;
+
+        let reversed = val.as_ref().chars().rev().collect::<String>();
+
+        match val.as_ref().cmp(&reversed) {
+            Ordering::Less => EdgeDescription {
+                name: val.as_ref().to_owned(),
+                symmetrical: Some(false),
+                reversed: Some(false),
+            },
+            Ordering::Equal => EdgeDescription {
+                name: reversed,
+                symmetrical: Some(true),
+                reversed: Some(false),
+            },
+            Ordering::Greater => EdgeDescription {
+                name: reversed,
+                symmetrical: Some(false),
+                reversed: Some(true),
+            },
+        }
+    }
+}