diff --git a/test/data/.gitkeep b/test/data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/test/data/Cinzel-VariableFont_wght.ttf b/test/data/Cinzel-VariableFont_wght.ttf new file mode 100644 index 0000000..38ae229 Binary files /dev/null and b/test/data/Cinzel-VariableFont_wght.ttf differ diff --git a/test/data/pipes.glb b/test/data/pipes.glb new file mode 100644 index 0000000..193988c Binary files /dev/null and b/test/data/pipes.glb differ diff --git a/test/main/plexus/core_test.clj b/test/main/plexus/core_test.clj index 986d5d9..4996a89 100644 --- a/test/main/plexus/core_test.clj +++ b/test/main/plexus/core_test.clj @@ -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)] + (t/is (about= x y)))))) (def pi Math/PI) (def pi|2 (/ pi 2)) @@ -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 @@ -60,3 +73,52 @@ 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 191659.8125, :volume 143258.34375} + (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 50) + (for [i (range 4)] + (p/branch + :from :body + (case i + 0 [(p/left :angle pi|2) + (p/right :angle pi|2)] + 1 [(p/right :angle pi|2) + (p/left :angle pi|2)] + 2 [(p/up :angle pi|2) + (p/down :angle pi|2)] + 3 [(p/down :angle pi|2) + (p/up :angle pi|2)]))))))