From c967b507a67b8468854eec9c5b973ce309cebd98 Mon Sep 17 00:00:00 2001
From: Garth Minette <revarbat@gmail.com>
Date: Mon, 5 Jul 2021 20:46:43 -0700
Subject: [PATCH] Bugfix for line_of()

---
 distributors.scad            |  2 +-
 tests/test_distributors.scad | 19 +++++++++++++++++++
 tests/test_shapes2d.scad     |  6 ++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 tests/test_distributors.scad

diff --git a/distributors.scad b/distributors.scad
index db34690..387b88b 100644
--- a/distributors.scad
+++ b/distributors.scad
@@ -130,7 +130,7 @@ function line_of(spacing, n, l, p1, p2) =
     assert(is_undef(p2) || is_vector(p2))
     let(
         ll = !is_undef(l)? scalar_vec3(l, 0) :
-            (!is_undef(spacing) && !is_undef(n))? (n * scalar_vec3(spacing, 0)) :
+            (!is_undef(spacing) && !is_undef(n))? ((n-1) * scalar_vec3(spacing, 0)) :
             (!is_undef(p1) && !is_undef(p2))? point3d(p2-p1) :
             undef,
         cnt = !is_undef(n)? n :
diff --git a/tests/test_distributors.scad b/tests/test_distributors.scad
new file mode 100644
index 0000000..5704c96
--- /dev/null
+++ b/tests/test_distributors.scad
@@ -0,0 +1,19 @@
+include <../std.scad>
+
+
+module test_line_of() {
+    assert_equal(line_of(l=100,n=5), [[-50,0,0],[-25,0,0],[0,0,0],[25,0,0],[50,0,0]]);
+    assert_equal(line_of(20,n=5), [[-40,0,0],[-20,0,0],[0,0,0],[20,0,0],[40,0,0]]);
+    assert_equal(line_of(spacing=20,n=5), [[-40,0,0],[-20,0,0],[0,0,0],[20,0,0],[40,0,0]]);
+    assert_equal(line_of(spacing=[0,20],n=5), [[0,-40,0],[0,-20,0],[0,0,0],[0,20,0],[0,40,0]]);
+
+    assert_equal(line_of(p1=[0,0],l=100,n=5), [[0,0,0],[25,0,0],[50,0,0],[75,0,0],[100,0,0]]);
+    assert_equal(line_of(p1=[0,0],20,n=5), [[0,0,0],[20,0,0],[40,0,0],[60,0,0],[80,0,0]]);
+    assert_equal(line_of(p1=[0,0],spacing=20,n=5), [[0,0,0],[20,0,0],[40,0,0],[60,0,0],[80,0,0]]);
+    assert_equal(line_of(p1=[0,0],spacing=[0,20],n=5), [[0,0,0],[0,20,0],[0,40,0],[0,60,0],[0,80,0]]);
+}
+test_line_of();
+
+
+
+// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
diff --git a/tests/test_shapes2d.scad b/tests/test_shapes2d.scad
index aa5c4f6..4c69e25 100644
--- a/tests/test_shapes2d.scad
+++ b/tests/test_shapes2d.scad
@@ -242,5 +242,11 @@ module test_mask2d_ogee() {
 test_mask2d_ogee();
 
 
+module test_dashed_stroke() {
+    segs = dashed_stroke([[0,0],[10,0]], dashpat=[3,2], closed=false);
+    assert_equal(segs,[[[0,0],[3,0]], [[5,0],[8,0]]]);
+}
+test_dashed_stroke();
+
 
 // vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap