Commit unstaged changes
This commit is contained in:
parent
c340684b33
commit
15e5cfc8e3
6 changed files with 59 additions and 25 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
|
report.html
|
||||||
node_modules
|
node_modules
|
||||||
.shadow-cljs
|
.shadow-cljs
|
||||||
resources/public/js
|
resources/public/js
|
||||||
|
|
|
||||||
20
README.md
20
README.md
|
|
@ -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
|
||||||
|
|
|
||||||
16
deps.edn
16
deps.edn
|
|
@ -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]}
|
||||||
|
appliedscience/js-interop {:mvn/version "0.2.5"}
|
||||||
|
reagent/reagent {:mvn/version "1.1.0"}
|
||||||
|
fipp/fipp {:mvn/version "0.6.25"}}
|
||||||
|
|
||||||
:aliases
|
:aliases
|
||||||
;; clojurescript build tool and dependencies (see also shadow-cljs.edn)
|
;; clojurescript build tool (see also shadow-cljs.edn)
|
||||||
{:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.8.109"}
|
{:cljs {:extra-deps {thheller/shadow-cljs {:mvn/version "2.16.10"}}}}}
|
||||||
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"}}}}}
|
|
||||||
|
|
|
||||||
14
dev/user.clj
Normal file
14
dev/user.clj
Normal 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)))
|
||||||
|
|
@ -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]}}}}}
|
||||||
|
|
|
||||||
|
|
@ -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,25 +125,25 @@
|
||||||
:title (str "Remove " n " items")} "❌"]])]])])
|
:title (str "Remove " n " items")} "❌"]])]])])
|
||||||
|
|
||||||
(defn visualization [frame packed-rects]
|
(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)
|
[:h1 "Visualization"]
|
||||||
:height (geom/height frame)}]
|
[:svg.visualization {:viewBox "-0.5 -0.5 501 501" :xmlns "http://www.w3.org/2000/svg"}
|
||||||
(for [[idx rect] (map-indexed vector packed-rects)
|
[:rect {:width (geom/width frame)
|
||||||
:let [[x y] (:p rect)
|
:height (geom/height frame)}]
|
||||||
w (geom/width rect)
|
(for [[idx rect] (map-indexed vector packed-rects)
|
||||||
h (geom/height rect)]]
|
:let [[x y] (:p rect)
|
||||||
^{:key idx} [:<>
|
w (geom/width rect)
|
||||||
[:rect {:width w :height h :x x :y y}]
|
h (geom/height rect)]]
|
||||||
[:text {:x x :y y :dx 4 :dy 14} (str w "x" h)]])])
|
^{: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 []
|
(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…")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue