-
Notifications
You must be signed in to change notification settings - Fork 1
/
flex.clj
29 lines (22 loc) · 808 Bytes
/
flex.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
;;; Functions that inspect their arguments and apply either OpenSCAD
;;; functions or their mathematical equivalents from the reckon module.
(ns scad-tarmi.flex
(:require [clojure.spec.alpha :as spec]
[scad-tarmi.core :as core]
[scad-tarmi.maybe :as maybe]
[scad-tarmi.reckon :as reckon]))
;;;;;;;;;;;;;;
;; INTERNAL ;;
;;;;;;;;;;;;;;
(defn- flex-fn
"Produce a function that applies one of two subject functions."
[reckon-fn else-fn]
(fn [parameters item]
(if (spec/valid? ::core/point-2-3d item)
(reckon-fn parameters item)
(else-fn parameters item))))
;;;;;;;;;;;;;;;;;;;;;;;;;
;; INTERFACE FUNCTIONS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;
(def translate (flex-fn reckon/translate maybe/translate))
(def rotate (flex-fn reckon/rotate maybe/rotate))