diff --git a/.gitignore b/.gitignore index e027dd6..1fe51d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +report.html node_modules .shadow-cljs resources/public/js diff --git a/README.md b/README.md index 44fd419..596b0a6 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,27 @@ # Rect-Packing +This folder contains a small project that aims to help in finding a good way to position individual cuttings on a frame. It is currently a work in progress. + +## Dev environment + This project is built using `shadow-cljs`: ``` bash npx shadow-cljs watch :app ``` -Use `cider-connect-cljs` to connect to the REPL in emacs after opening http://localhost:8080 in your browser. :) +Use `cider-connect-cljs` to connect to the REPL in emacs after opening http://localhost:8080 in your browser. Alternatively you can just call `cider-jack-in-cljs` and select the app build. :) + +### Production Build + +``` bash +npx shadow-cljs release :app +``` + +A [build report](https://shadow-cljs.github.io/docs/UsersGuide.html#build-report) will automatically be created and written to `resources/public/js/report.html`. + +## Tentative Roadmap + +- [ ] Warn when rects don't fit the given frame(s) +- [ ] Show coverage quote +- [ ] Allow multiple frames diff --git a/deps.edn b/deps.edn index 8cd8c94..3a34322 100644 --- a/deps.edn +++ b/deps.edn @@ -1,14 +1,12 @@ {:paths ["src" "resources"] :deps {org.clojure/clojure {:mvn/version "1.10.0"} - thi.ng/geom {:mvn/version "1.0.0-RC3" + thi.ng/geom {:mvn/version "1.0.0-RC4" :exclusions [org.jogamp.jogl/jogl-all - org.jogamp.gluegen/gluegen-rt]}} + org.jogamp.gluegen/gluegen-rt]} + appliedscience/js-interop {:mvn/version "0.2.5"} + reagent/reagent {:mvn/version "1.1.0"} + fipp/fipp {:mvn/version "0.6.25"}} :aliases - ;; clojurescript build tool and dependencies (see also shadow-cljs.edn) - {:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.8.109"} - appliedscience/js-interop {:mvn/version "0.2.5"} - reagent/reagent {:mvn/version "1.1.0"} - fipp/fipp {:mvn/version "0.6.25"} - #_#_ refactor-nrepl/refactor-nrepl {:mvn/version "3.1.0"} - #_#_ cider/cider-nrepl {:mvn/version "0.27.2"}}}}} + ;; clojurescript build tool (see also shadow-cljs.edn) + {:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.16.10"}}}}} diff --git a/dev/user.clj b/dev/user.clj new file mode 100644 index 0000000..4ce40df --- /dev/null +++ b/dev/user.clj @@ -0,0 +1,14 @@ +(ns user + (:require [shadow.cljs.devtools.api :as shadow] + [shadow.cljs.devtools.server :as server])) + +;; copied from https://docs.cider.mx/cider/cljs/shadow-cljs.html + +(defn cljs-repl + "Connects to a given build-id. Defaults to `:app`." + ([] + (cljs-repl :app)) + ([build-id] + (server/start!) + (shadow/watch build-id) + (shadow/nrepl-select build-id))) diff --git a/shadow-cljs.edn b/shadow-cljs.edn index a1b44c4..d783aef 100644 --- a/shadow-cljs.edn +++ b/shadow-cljs.edn @@ -7,4 +7,4 @@ {:app {:target :browser :output-dir "resources/public/js" :asset-path "/js" - :modules {:main {:entries [heyarne.rect-packing.core]}}}} } + :modules {:main {:entries [heyarne.rect-packing.core]}}}}} diff --git a/src/heyarne/rect_packing/core.cljs b/src/heyarne/rect_packing/core.cljs index ab98b42..4cb7a55 100644 --- a/src/heyarne/rect_packing/core.cljs +++ b/src/heyarne/rect_packing/core.cljs @@ -100,8 +100,11 @@ (defn remove-rects-of-size! [size] (swap! state update :rects dissoc size)) -(defn inventory [rects] +(defn inventory [frame rects] [:<> + [:h2 "Frames"] + [:pre (prn-str frame)] + [:h2 "Rectangles"] [order] (when (seq rects) [:<> @@ -122,25 +125,25 @@ :title (str "Remove " n " items")} "❌"]])]])]) (defn visualization [frame packed-rects] - [:svg.visualization {:viewBox "-0.5 -0.5 501 501" :xmlns "http://www.w3.org/2000/svg"} - [:rect {:width (geom/width frame) - :height (geom/height frame)}] - (for [[idx rect] (map-indexed vector packed-rects) - :let [[x y] (:p rect) - w (geom/width rect) - h (geom/height rect)]] - ^{:key idx} [:<> - [:rect {:width w :height h :x x :y y}] - [:text {:x x :y y :dx 4 :dy 14} (str w "x" h)]])]) + [:<> + [:h1 "Visualization"] + [:svg.visualization {:viewBox "-0.5 -0.5 501 501" :xmlns "http://www.w3.org/2000/svg"} + [:rect {:width (geom/width frame) + :height (geom/height frame)}] + (for [[idx rect] (map-indexed vector packed-rects) + :let [[x y] (:p rect) + w (geom/width rect) + h (geom/height rect)]] + ^{:key idx} [:<> + [:rect {:width w :height h :x x :y y}] + [:text {:x x :y y :dx 4 :dy 14} (str w "x" h)]])]]) (defn main [] (let [{:keys [frame rects]} @state packed @packed-rects] [:main - [:h1 "Visualization"] [visualization frame packed] - [:h2 "Rectangles"] - [inventory rects]])) + [inventory frame rects]])) (defn ^:dev/after-load init [] (println "Initializing…")