Commit unstaged changes

This commit is contained in:
heyarne 2022-02-19 19:23:12 +01:00
commit 15e5cfc8e3
6 changed files with 59 additions and 25 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
report.html
node_modules node_modules
.shadow-cljs .shadow-cljs
resources/public/js resources/public/js

View file

@ -1,9 +1,27 @@
# Rect-Packing # 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`: This project is built using `shadow-cljs`:
``` bash ``` bash
npx shadow-cljs watch :app 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

View file

@ -1,14 +1,12 @@
{:paths ["src" "resources"] {:paths ["src" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.10.0"} :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 :exclusions [org.jogamp.jogl/jogl-all
org.jogamp.gluegen/gluegen-rt]}} org.jogamp.gluegen/gluegen-rt]}
: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"} appliedscience/js-interop {:mvn/version "0.2.5"}
reagent/reagent {:mvn/version "1.1.0"} reagent/reagent {:mvn/version "1.1.0"}
fipp/fipp {:mvn/version "0.6.25"} fipp/fipp {:mvn/version "0.6.25"}}
#_#_ refactor-nrepl/refactor-nrepl {:mvn/version "3.1.0"}
#_#_ cider/cider-nrepl {:mvn/version "0.27.2"}}}}} :aliases
;; clojurescript build tool (see also shadow-cljs.edn)
{:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.16.10"}}}}}

14
dev/user.clj Normal file
View file

@ -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)))

View file

@ -7,4 +7,4 @@
{:app {:target :browser {:app {:target :browser
:output-dir "resources/public/js" :output-dir "resources/public/js"
:asset-path "/js" :asset-path "/js"
:modules {:main {:entries [heyarne.rect-packing.core]}}}} } :modules {:main {:entries [heyarne.rect-packing.core]}}}}}

View file

@ -100,8 +100,11 @@
(defn remove-rects-of-size! [size] (defn remove-rects-of-size! [size]
(swap! state update :rects dissoc size)) (swap! state update :rects dissoc size))
(defn inventory [rects] (defn inventory [frame rects]
[:<> [:<>
[:h2 "Frames"]
[:pre (prn-str frame)]
[:h2 "Rectangles"]
[order] [order]
(when (seq rects) (when (seq rects)
[:<> [:<>
@ -122,6 +125,8 @@
:title (str "Remove " n " items")} "❌"]])]])]) :title (str "Remove " n " items")} "❌"]])]])])
(defn visualization [frame packed-rects] (defn visualization [frame packed-rects]
[:<>
[:h1 "Visualization"]
[:svg.visualization {:viewBox "-0.5 -0.5 501 501" :xmlns "http://www.w3.org/2000/svg"} [:svg.visualization {:viewBox "-0.5 -0.5 501 501" :xmlns "http://www.w3.org/2000/svg"}
[:rect {:width (geom/width frame) [:rect {:width (geom/width frame)
:height (geom/height frame)}] :height (geom/height frame)}]
@ -131,16 +136,14 @@
h (geom/height rect)]] h (geom/height rect)]]
^{:key idx} [:<> ^{:key idx} [:<>
[:rect {:width w :height h :x x :y y}] [:rect {:width w :height h :x x :y y}]
[:text {:x x :y y :dx 4 :dy 14} (str w "x" h)]])]) [:text {:x x :y y :dx 4 :dy 14} (str w "x" h)]])]])
(defn main [] (defn main []
(let [{:keys [frame rects]} @state (let [{:keys [frame rects]} @state
packed @packed-rects] packed @packed-rects]
[:main [:main
[:h1 "Visualization"]
[visualization frame packed] [visualization frame packed]
[:h2 "Rectangles"] [inventory frame rects]]))
[inventory rects]]))
(defn ^:dev/after-load init [] (defn ^:dev/after-load init []
(println "Initializing…") (println "Initializing…")