-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.clj
45 lines (41 loc) · 1.54 KB
/
util.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;; Slightly more advanced utilities.
(ns scad-tarmi.util
(:require [scad-clj.model :as model]
[scad-tarmi.maybe :as maybe]))
;;;;;;;;;;;;;;;;;;;;;;;;;
;; INTERFACE FUNCTIONS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
(defn loft
"Link passed shapes by a series of convex hulls. By default, link by pairs.
While this function shares its etymological root with lofting as the term is
used in WYSIWYG 3D modeling software, it does not generate any new primitives
or intermediate planar sections to fill out a shape along a given path. The
path must be created first and all objects placed along it before they are
passed to this function. The function merely wraps each pair/trio etc. of the
sequence in hulls."
([block]
(loft 2 1 block))
([chunk-size block]
(loft chunk-size 1 block))
([chunk-size step block]
{:pre [(integer? chunk-size)
(not (zero? chunk-size))
(integer? step)
(not (zero? step))]}
(let [block (remove nil? block)
n (count block)]
(cond
;; If no shapes are passed return nil.
(zero? n) nil
;; If one shape is passed, return it.
(= 1 n) (first block)
;; Hull other short input (partitioning would return an empty list).
(> chunk-size n) (apply model/hull block)
:else
(apply maybe/union
(map (partial apply model/hull)
(partition chunk-size step block)))))))
(defn radiate
"Link a series of shapes through a single, central shape."
[hub spokes]
(loft 2 2 (list* hub (interpose hub spokes))))