Skip to content

Commit

Permalink
Merge pull request #2 from SovereignShop/core-tests-2
Browse files Browse the repository at this point in the history
More Core Tests
  • Loading branch information
cartesian-theatrics authored Apr 5, 2024
2 parents 2838468 + e7390e7 commit 5ccb46e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
Empty file added test/data/.gitkeep
Empty file.
Binary file added test/data/Cinzel-VariableFont_wght.ttf
Binary file not shown.
Binary file added test/data/pipes.glb
Binary file not shown.
72 changes: 67 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)]
(t/is (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,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)]))))))

0 comments on commit 5ccb46e

Please sign in to comment.