-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e34466
commit 0c721d5
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(ns plexus.core-test | ||
(:require | ||
[clj-manifold3d.core :as m] | ||
[clojure.test :as t] | ||
[plexus.core :as p])) | ||
|
||
(defn get-volume [extrusion] | ||
(-> extrusion | ||
(p/get-model (:main-model extrusion)) | ||
(m/get-properties) | ||
(:volume))) | ||
|
||
(def default-eps 0.002) | ||
|
||
(def pi Math/PI) | ||
(def pi|2 (/ pi 2)) | ||
(def pi|3 (/ pi 3)) | ||
(def pi|4 (/ pi 4)) | ||
(def pow #(Math/pow %1 %2)) | ||
|
||
(defn circle-area [r n] | ||
(let [s (* 2 r (Math/sin (/ (* 2 pi) (* 2 n))))] | ||
(/ (* n (pow s 2)) | ||
(* 4 (Math/tan (/ pi n)))))) | ||
|
||
(defn about= | ||
([x y] (about= x y default-eps)) | ||
([x y eps] (< (Math/abs (- x y)) eps))) | ||
|
||
(t/deftest test-extrudes | ||
(t/is (about= (get-volume | ||
(p/extrude | ||
(p/frame :name :body :cross-section (m/square 10 10 true)) | ||
(p/forward :length 10))) | ||
1000.0)) | ||
(let [r 10 | ||
cr 100 | ||
cs 200] | ||
(t/is (about= (get-volume | ||
(p/extrude | ||
(p/frame :name :body :cross-section (m/circle r cs)) | ||
(p/left :angle (* 2 pi) :curve-radius cr :cs cs))) | ||
(* 2 (pow pi 2) (pow r 2) cr) | ||
200)) | ||
(t/is (about= | ||
3180.828 | ||
(get-volume | ||
(p/extrude | ||
(p/result :name :tmp | ||
:expr (p/difference :body :mask)) | ||
(p/frame :name :body :cross-section (m/circle 4) | ||
:cs 30 | ||
:curve-radius 30) | ||
(p/frame :name :mask :cross-section (m/circle 3)) | ||
(for [i (range 4)] | ||
(p/branch | ||
:from :body | ||
(case i | ||
0 (p/left :angle pi|2) | ||
1 (p/right :angle pi|2) | ||
2 (p/up :angle pi|2) | ||
3 (p/down :angle pi|2)))))))))) |