Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure tessellation of polygon2 returns a collection of triangle2 #89

Open
wants to merge 1 commit into
base: feature/no-org
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/thi/ng/geom/polygon.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
[thi.ng.geom.triangle :as t]
[thi.ng.geom.basicmesh :as bm]
[thi.ng.geom.attribs :as attr]
#?(:clj [thi.ng.geom.types] :cljs [thi.ng.geom.types :refer [Circle2 Polygon2]])
#?(:clj [thi.ng.geom.types] :cljs [thi.ng.geom.types :refer [Circle2 Polygon2 Triangle2]])
[thi.ng.dstruct.core :as d]
[thi.ng.math.core :as m :refer [PI HALF_PI THREE_HALVES_PI *eps*]])
#?(:clj (:import [thi.ng.geom.types Circle2 Polygon2])))
#?(:clj (:import [thi.ng.geom.types Circle2 Polygon2 Triangle2])))

(defn polygon2
([points] (Polygon2. (mapv vec2 points)))
Expand Down Expand Up @@ -371,7 +371,7 @@

g/ITessellate
(tessellate
[_] (tessellate* _))
[_] (map #(Triangle2. %) (tessellate* _)))

g/IRotate
(rotate
Expand Down
10 changes: 7 additions & 3 deletions test/thi/ng/geom/test/types/polygon.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
[cemerick.cljs.test :refer (is deftest)]))
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.vector :refer [vec2]]
[thi.ng.geom.types]
#?(:clj [thi.ng.geom.types] :cljs [thi.ng.geom.types :refer [Triangle2]])
[thi.ng.geom.polygon :as p]
#?(:clj
[clojure.test :refer :all]
:cljs
[cemerick.cljs.test])))
[cemerick.cljs.test]))
#?(:clj (:import [thi.ng.geom.types Triangle2])))

(deftest test-flip
(let [poly (p/polygon2 [[0 0] [1 0] [1 1] [0 1]])
flipped-poly (g/flip poly)]
(is (= (-> poly g/as-mesh g/faces count)
(-> flipped-poly g/as-mesh g/faces count))
"flipped polygon tesselates to same number of faces")))

(deftest tessellation
(let [poly (p/polygon2 [[0 0] [1 0] [1 1] [0 1]])]
(is (every? #(instance? Triangle2 %) (g/tessellate poly)))))