Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cartesian-theatrics committed Apr 5, 2024
1 parent 2838468 commit 989e7a6
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions test/main/plexus/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,30 @@
[clojure.test :as t]
[plexus.core :as p]))

(def default-eps 0.002)

(defn get-volume [extrusion]
(-> extrusion
(p/get-model (:main-model extrusion))
(m/get-properties)
(:volume)))

(def default-eps 0.002)
(defn get-props [extrusion]
(-> extrusion
(p/get-model (:main-model extrusion))
(m/get-properties)
(update :volume double)
(update :surface-area double)))

(defn about=
([x y] (about= x y default-eps))
([x y eps] (< (Math/abs (- x y)) eps)))

(defn test-props [props extrusion]
(let [e-props (get-props extrusion)]
(doseq [[k x] e-props]
(let [y (get props k)]
(about= x y)))))

(def pi Math/PI)
(def pi|2 (/ pi 2))
Expand All @@ -23,10 +40,6 @@
(/ (* 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
Expand Down Expand Up @@ -60,3 +73,48 @@
1 (p/right :angle pi|2)
2 (p/up :angle pi|2)
3 (p/down :angle pi|2))))))))))

(t/deftest test-export
(let [extrusion (p/extrude
(p/frame :cross-section (m/circle 6) :name :body)
(p/forward :length 10))
vol (get-volume extrusion)]
(p/export extrusion "test/data/pipes.glb" (m/material :color [0 0.7 0.7 1.0] :metalness 0.2))
(t/is (= vol (:volume (m/get-properties (m/manifold (m/import-mesh "test/data/pipes.glb"))))))))

(t/deftest test-hull
(let [m (p/extrude
(p/result :name :pipes
:expr (p/difference :body :mask))

(p/frame :cross-section (m/circle 6) :name :body)
(p/frame :cross-section (m/circle 4) :name :mask)
(p/set :curve-radius 20)
(p/hull
(p/hull
(p/forward :length 20)
(p/set :cross-section (m/square 20 20 true) :to [:body])
(p/set :cross-section (m/square 16 16 true) :to [:mask])
(p/forward :length 20))
(p/set :cross-section (m/circle 6) :to [:body])
(p/set :cross-section (m/circle 4) :to [:mask])
(p/forward :length 20))) ]
(test-props {:surface-area 7264.4707, :volume 7129.058} m)))

(t/deftest test-orientation
(test-props
{:surface-area 182291.09375, :volume 138770.296875}
(p/extrude
(p/frame :name :body
:cross-section (-> (m/text "test/data/Cinzel-VariableFont_wght.ttf" "abc" 10 5 :non-zero)
(m/scale-to-height 20)
(m/center))
:curve-radius 100)
(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)))))))

0 comments on commit 989e7a6

Please sign in to comment.