Repository: ManevilleF/hexx (rust)

Issue:
Hex::line_to always returns the origin when start==end
Specialcasing this in my code fixed the bug I was seeing, so it's just a simple bad computation :)

Pull request description:
Fixed empty line to
> Closes #43 

Fixes empty `line_to` implementation. With this fix the returned line will always contain at least both `start` and `end` coordinates.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad164d4..984f6a3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,10 @@
 # CHANGELOG
 
+## Unreleased
+
+* Fixed `conversion` module was private (#42)
+* Fixed `Hex::line_to` returning `(0, 0)` when both ends are identical (#43)
+
 ## 0.4.1
 
 ### Fix
diff --git a/src/hex/mod.rs b/src/hex/mod.rs
index d424059..983d684 100644
--- a/src/hex/mod.rs
+++ b/src/hex/mod.rs
@@ -720,8 +720,9 @@ impl Hex {
     /// ````
     pub fn line_to(self, other: Self) -> impl Iterator<Item = Self> {
         let distance = self.distance_to(other);
+        let dist = distance.max(1) as f32;
         let [a, b]: [Vec2; 2] = [self.as_vec2(), other.as_vec2()];
-        (0..=distance).map(move |step| a.lerp(b, step as f32 / distance as f32).into())
+        (0..=distance).map(move |step| a.lerp(b, step as f32 / dist).into())
     }
 
     /// Performs a linear interpolation between `self` and `rhs` based on the value `s`.


Test patch:
diff --git a/src/hex/tests.rs b/src/hex/tests.rs
index 365d591..dfce358 100644
--- a/src/hex/tests.rs
+++ b/src/hex/tests.rs
@@ -337,6 +337,13 @@ fn line_to() {
     );
 }
 
+#[test]
+fn empty_line_to() {
+    let start = Hex::new(3, -7);
+    let line: Vec<_> = start.line_to(start).collect();
+    assert_eq!(line, vec![start]);
+}
+
 #[test]
 fn directions_to() {
     let a = Hex::new(0, 0);