Skip to content

Commit

Permalink
[types] update intersections for Rect2 & Triangle2
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 16, 2015
1 parent 6a9cdbc commit 66e6be1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
22 changes: 15 additions & 7 deletions geom-types/src/rect.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- [[#pclassify][PClassify]]
- [[#pextrude][PExtrude]]
- [[#pgraph][PGraph]]
- [[#todo-pintersect][TODO PIntersect]]
- [[#pintersect][PIntersect]]
- [[#pmeshconvert][PMeshConvert]]
- [[#ppointmap][PPointMap]]
- [[#ppolygonconvert][PPolygonConvert]]
Expand Down Expand Up @@ -182,19 +182,27 @@ than 1.0.
[_ v] (if ((set (g/vertices _)) (vec2 v)) 2 0))
#+END_SRC

*** TODO PIntersect
*** PIntersect
#+BEGIN_SRC clojure :noweb-ref impl
g/PIntersect
(intersect-line
[_ l])
[_ {[p q] :points}]
(if (and (g/contains-point? _ p) (g/contains-point? _ q))
{:type :coincident}
(isec/intersect-line2-edges? p q (g/edges _))))
(intersect-ray
[_ r])
([_ ray]
(let [[p dir] (if (map? ray) [(:p ray) (:dir ray)] ray)]
(isec/intersect-ray2-edges? p dir (g/edges _))))
([_ p dir]
(isec/intersect-ray2-edges? p dir (g/edges _))))
(intersect-shape
[_ s]
(cond
(instance? thi.ng.geom.types.Rect2 s) (isec/intersect-rect-rect? _ s)
(instance? thi.ng.geom.types.Circle2 s) (isec/intersect-aabb-sphere? _ s)
:default (err/type-error! "Rect2" s)))
(instance? thi.ng.geom.types.Line2 s) (g/intersect-line _ s)
(instance? thi.ng.geom.types.Rect2 s) (isec/intersect-rect-rect? _ s)
(instance? thi.ng.geom.types.Circle2 s) (isec/intersect-aabb-sphere? _ s)
:default (err/unsupported! (str "can't intersect w/ " s))))
#+END_SRC

*** PMeshConvert :verify:
Expand Down
18 changes: 18 additions & 0 deletions geom-types/src/triangle.org
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [[#pextrude][PExtrude]]
- [[#pflip][PFlip]]
- [[#pgraph][PGraph]]
- [[#pintersect][PIntersect]]
- [[#pmeshconvert][PMeshConvert]]
- [[#ppolygonconvert][PPolygonConvert]]
- [[#pproximity][PProximity]]
Expand Down Expand Up @@ -315,6 +316,23 @@
#+BEGIN_SRC clojure :noweb-ref impl2 :noweb yes
<<tpl-graph>>
#+END_SRC
**** PIntersect
- Note taken on [2015-03-15 Sun 01:47] \\
update ray definition or protocol?
#+BEGIN_SRC clojure :noweb-ref impl2
g/PIntersect
(intersect-line
[_ {[p q] :points}]
(if (and (g/contains-point? _ p) (g/contains-point? _ q))
{:type :coincident}
(isec/intersect-line2-edges? p q (g/edges _))))
(intersect-ray
([_ ray]
(let [[p dir] (if (map? ray) [(:p ray) (:dir ray)] ray)]
(isec/intersect-ray2-edges? p dir (g/edges _))))
([_ p dir]
(isec/intersect-ray2-edges? p dir (g/edges _))))
#+END_SRC
**** PMeshConvert :fix:
#+BEGIN_SRC clojure :noweb-ref impl2
g/PMeshConvert
Expand Down

0 comments on commit 66e6be1

Please sign in to comment.