From fd15e4195209103dd1121d8960b344d029e7c691 Mon Sep 17 00:00:00 2001 From: Simon Brooke Date: Sat, 13 Apr 2024 15:35:50 +0100 Subject: [PATCH] Builds and runs; output is crazily wrong... --- src/cc/journeyman/walkmap/ocean.clj | 14 +++++++++++--- src/cc/journeyman/walkmap/polygon.clj | 1 + src/cc/journeyman/walkmap/stl.clj | 6 +++--- src/cc/journeyman/walkmap/test_all.clj | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/cc/journeyman/walkmap/test_all.clj diff --git a/src/cc/journeyman/walkmap/ocean.clj b/src/cc/journeyman/walkmap/ocean.clj index 70b4633..55b88e1 100644 --- a/src/cc/journeyman/walkmap/ocean.clj +++ b/src/cc/journeyman/walkmap/ocean.clj @@ -1,6 +1,8 @@ (ns cc.journeyman.walkmap.ocean "Deal with (specifically, at this stage, cull) ocean areas" - (:require [cc.journeyman.walkmap.utils :refer [=ish]])) + (:require [cc.journeyman.walkmap.polygon :refer [triangle?]] + [cc.journeyman.walkmap.stl :refer [stl?]] + [cc.journeyman.walkmap.utils :refer [=ish]])) (def ^:dynamic *sea-level* "The sea level on heightmaps we're currently handling. If characters are to @@ -21,5 +23,11 @@ (defn cull-ocean-facets "Ye cannae walk on water. Remove all facets from this `stl` structure which are at sea level." - [stl] - (assoc stl :facets (remove ocean? (:facets stl)))) + [stl-or-seq] + (cond + (and (seq? stl-or-seq) + (every? triangle? stl-or-seq)) (remove ocean? stl-or-seq) + (stl? stl-or-seq)(assoc stl-or-seq :facets + (cull-ocean-facets (:facets stl-or-seq))) + :else (throw (IllegalArgumentException. + "Expected STL structure, or sequence of triangles.")))) diff --git a/src/cc/journeyman/walkmap/polygon.clj b/src/cc/journeyman/walkmap/polygon.clj index c3fa094..d425038 100644 --- a/src/cc/journeyman/walkmap/polygon.clj +++ b/src/cc/journeyman/walkmap/polygon.clj @@ -43,6 +43,7 @@ [o] (and (coll? o) + (#{:polygon :triangle} (kind-type o)) (= (count (:vertices o)) 3))) (defmacro check-triangle diff --git a/src/cc/journeyman/walkmap/stl.clj b/src/cc/journeyman/walkmap/stl.clj index e951418..893aaf4 100644 --- a/src/cc/journeyman/walkmap/stl.clj +++ b/src/cc/journeyman/walkmap/stl.clj @@ -207,8 +207,8 @@ ([stl solidname] (str "solid " - solidname - (s/trim (:header stl)) + (or solidname + (when (:header stl)(s/trim (:header stl)))) "\n" (s/join (map @@ -227,7 +227,7 @@ filename stl (subs b 0 (or (s/index-of b ".") (count b)))))) ([filename stl solidname] - (debug "Solid name is " solidname) + (debug (format "Writing STL to '%s'; solid name is %s" filename solidname)) (spit filename (stl->ascii stl solidname)))) diff --git a/src/cc/journeyman/walkmap/test_all.clj b/src/cc/journeyman/walkmap/test_all.clj new file mode 100644 index 0000000..afd1955 --- /dev/null +++ b/src/cc/journeyman/walkmap/test_all.clj @@ -0,0 +1,19 @@ +(ns cc.journeyman.walkmap.test-all + (:require [cc.journeyman.walkmap.mw-stl :refer [mw->stl]] + [cc.journeyman.walkmap.stl :refer [write-ascii-stl]] + [mw-engine.world :refer [world?]])) + +(defn run-test + ([^String name] + (run-test (str name ".edn") (str name ".stl") name)) + ([^String mw-name ^String stl-name ^String title] + (let [mw (read-string (slurp mw-name))] + (if (world? mw) + (write-ascii-stl + stl-name + (mw->stl mw) + title) + (throw (IllegalArgumentException. + (format + "Content of file '%s' was not recognised as a valid world" + mw-name))))))) \ No newline at end of file