diff --git a/src/thi/ng/geom/triangle.cljc b/src/thi/ng/geom/triangle.cljc index 5a0aff1..52de266 100644 --- a/src/thi/ng/geom/triangle.cljc +++ b/src/thi/ng/geom/triangle.cljc @@ -159,7 +159,17 @@ [o (g/dist o b)])))) (defn circumcircle - ([t] (circumcircle (get t :a) (get t :b) (get t :c))) + ([t] + (cond (instance? Triangle2 t) + (let [{[a b c] :points} t] + (circumcircle a b c)) + (map? t) + (let [{:keys [a b c]} t] + (circumcircle a b c)) + (sequential? t) + (let [[a b c] t] + (circumcircle a b c)) + :else (err/illegal-arg! t))) ([a b c] (let [[o r] (circumcircle-raw a b c)] (Circle2. o r)))) diff --git a/test/thi/ng/geom/test/types/triangle.cljc b/test/thi/ng/geom/test/types/triangle.cljc new file mode 100644 index 0000000..ebcda7e --- /dev/null +++ b/test/thi/ng/geom/test/types/triangle.cljc @@ -0,0 +1,23 @@ +(ns thi.ng.geom.test.types.triangle + #?(:cljs + (:require-macros + [cemerick.cljs.test :refer (is deftest)])) + (:require + [thi.ng.geom.types] + [thi.ng.geom.circle :as c] + [thi.ng.geom.triangle :as t] + [thi.ng.geom.vector :as v] + #?(:clj + [clojure.test :refer [is deftest]] + :cljs + [cemerick.cljs.test]))) + +(deftest test-circumcircle + (let [a (v/vec2 0 0) + b (v/vec2 4 0) + c (v/vec2 0 2) + expected (c/circle (v/vec2 2.0 0.0) 2.0)] + (is (= expected (t/circumcircle a b c))) + (is (= expected (t/circumcircle (t/triangle2 a b c)))) + (is (= expected (t/circumcircle {:a a :b b :c c}))) + (is (= expected (t/circumcircle [a b c])))))