From c0ba81d3788fe08d3754d744514efe401aa9a635 Mon Sep 17 00:00:00 2001
From: Jake Read <jake.read@cba.mit.edu>
Date: Sun, 27 Oct 2019 18:49:45 -0400
Subject: [PATCH] pathes to pathes

---
 hunks/adhoc/npath_to_path.js            | 35 +++++++++
 save/contexts/cuttlefish/test-np2p.json | 96 +++++++++++++++++++++++++
 2 files changed, 131 insertions(+)
 create mode 100644 save/contexts/cuttlefish/test-np2p.json

diff --git a/hunks/adhoc/npath_to_path.js b/hunks/adhoc/npath_to_path.js
index 8774940..e88a82d 100644
--- a/hunks/adhoc/npath_to_path.js
+++ b/hunks/adhoc/npath_to_path.js
@@ -17,4 +17,39 @@ export default function NPZ2PZ(){
   let outPath = this.output('reference', 'path')
   let inPath = this.input('reference', 'path')
   let zUp = this.state('number', 'clearance', 10)
+  let zDown = this.state('number', 'depth', -5)
+
+  let unfp = []
+  let unfpUpdated = false
+
+  let unfPath = (fp) => {
+    // RIP oldboy
+    unfp.length = 0
+    // new friend
+    let zu = zUp.value
+    let zd = zDown.value
+    // flatten, adding z-moves
+    for(let leg of fp){
+      // start each leg up top, above the first point,
+      unfp.push([leg[0][0], leg[0][1], zu])
+      for(let point of leg){
+        unfp.push([point[0], point[1], zd])
+      }
+      // and the lift, to tail
+      let last = leg[leg.length - 1]
+      unfp.push([last[0], last[1], zu])
+    }
+    // we doooone
+    unfpUpdated = true
+  }
+
+  this.loop = () => {
+    if(inPath.io()){
+      unfPath(inPath.get())
+    }
+    if(unfpUpdated && !outPath.io()){
+      outPath.put(unfp)
+      unfpUpdated = false
+    }
+  }
 }
diff --git a/save/contexts/cuttlefish/test-np2p.json b/save/contexts/cuttlefish/test-np2p.json
new file mode 100644
index 0000000..2cbe0cd
--- /dev/null
+++ b/save/contexts/cuttlefish/test-np2p.json
@@ -0,0 +1,96 @@
+{
+  "interpreterName": "cuttlefish",
+  "interpreterVersion": "v0.1",
+  "hunks": [
+    {
+      "type": "manager",
+      "name": "nrol",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "1",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "view",
+      "name": "tlview",
+      "inputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "msgs",
+          "type": "byteArray",
+          "connections": [
+            {
+              "inHunkIndex": "0",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ]
+    },
+    {
+      "type": "data/open_json",
+      "name": "data/open_json_2",
+      "outputs": [
+        {
+          "name": "data",
+          "type": "reference",
+          "connections": [
+            {
+              "inHunkIndex": "3",
+              "inHunkInput": "0"
+            }
+          ]
+        }
+      ],
+      "states": [
+        {
+          "name": "release",
+          "type": "boolean",
+          "value": "false"
+        }
+      ]
+    },
+    {
+      "type": "adhoc/npath_to_path",
+      "name": "adhoc/npath_to_path_3",
+      "inputs": [
+        {
+          "name": "path",
+          "type": "reference"
+        }
+      ],
+      "outputs": [
+        {
+          "name": "path",
+          "type": "reference"
+        }
+      ],
+      "states": [
+        {
+          "name": "clearance",
+          "type": "number",
+          "value": "10"
+        }
+      ]
+    }
+  ]
+}
\ No newline at end of file
-- 
GitLab