Skip to content

Commit

Permalink
[types] bugfix closest-point impls for Bezier2/3, Quad3, Rect2 &
Browse files Browse the repository at this point in the history
Triangle3, update lob-geom-proxi template
  • Loading branch information
postspectacular committed Mar 22, 2015
1 parent 50ce3d1 commit b1721a9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 22 deletions.
14 changes: 4 additions & 10 deletions geom-types/src/bezier.org
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,8 @@ required control points. This only works for non-closed curves, though.
#+END_SRC

*** PProximity
#+BEGIN_SRC clojure :noweb-ref impl2
g/PProximity
(closest-point
[_ p]
(gu/closest-point-on-segments p (g/edges _)))
#+BEGIN_SRC clojure :noweb-ref impl2 :noweb yes
<<lob-geom-proxi>>
#+END_SRC

*** PSample
Expand Down Expand Up @@ -249,11 +246,8 @@ required control points. This only works for non-closed curves, though.
#+END_SRC

*** PProximity
#+BEGIN_SRC clojure :noweb-ref impl3
g/PProximity
(closest-point
[_ p]
(gu/closest-point-on-segments p (g/edges _)))
#+BEGIN_SRC clojure :noweb-ref impl3 :noweb yes
<<lob-geom-proxi>>
#+END_SRC

*** PSample
Expand Down
41 changes: 39 additions & 2 deletions geom-types/src/quad.org
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- [[#todo-pintersect][TODO PIntersect]]
- [[#pmeshconvert][PMeshConvert]]
- [[#todo-ppointmap][TODO PPointMap]]
- [[#todo-pproximity][TODO PProximity]]
- [[#pproximity][PProximity]]
- [[#todo-psample][TODO PSample]]
- [[#psubdivide][PSubdivide]]
- [[#ptessellate][PTessellate]]
Expand All @@ -32,6 +32,7 @@
* thi.ng.geom.quad

** Constructor

#+BEGIN_SRC clojure :noweb-ref ctors
(defn quad3
([] (quad3 1.0))
Expand All @@ -41,6 +42,7 @@
:default (err/illegal-arg! w)))
([a b c d] (thi.ng.geom.types.Quad3. [(vec3 a) (vec3 b) (vec3 c) (vec3 d)])))
#+END_SRC

** TODO Type specific functions

#+BEGIN_SRC clojure :noweb-ref helpers
Expand Down Expand Up @@ -77,46 +79,62 @@ quad.
#+END_SRC

** Protocol implementations

#+BEGIN_SRC clojure :noweb-ref impl
(extend-type thi.ng.geom.types.Quad3
#+END_SRC

*** PArea

#+BEGIN_SRC clojure :noweb-ref impl
g/PArea
(area
[{[a b c d] :points}]
(+ (gu/tri-area3 a b c) (gu/tri-area3 a c d)))
#+END_SRC

*** TODO PBoundary

#+BEGIN_SRC clojure :noweb-ref impl
g/PBoundary
(contains-point?
[_ p] )
#+END_SRC

*** PBounds :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-bounds(fn="tu/bounding-box", depth="yes")>>
#+END_SRC

*** PBoundingSphere :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-bsphere>>
#+END_SRC

*** PCenter :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-center(type="thi.ng.geom.types.Quad3",vtype="vec3")>>
(centroid [_] (gu/centroid (:points _)))
#+END_SRC

*** PCircumference :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-circum>>
#+END_SRC

*** TODO PClassify

#+BEGIN_SRC clojure :noweb-ref impl
g/PClassify
(classify-point
[_ p]
(transduce (map #(g/classify-point (thi.ng.geom.types.Line3. %) p)) min (g/edges _)))
#+END_SRC

*** TODO PExtrude

Extruding a quad along an axis vector results in a 3D quad mesh.
Expand Down Expand Up @@ -167,11 +185,15 @@ than 1.0.
(extrude-shell
[_ opts] nil)
#+END_SRC

*** PFlip :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-flip(type="thi.ng.geom.types.Quad3")>>
#+END_SRC

*** PGraph

#+BEGIN_SRC clojure :noweb-ref impl
g/PVertexAccess
(vertices
Expand All @@ -185,13 +207,17 @@ than 1.0.
(vertex-valence
[_ v] (if ((set (:points _)) v) 2 0))
#+END_SRC

*** PInset

#+BEGIN_SRC clojure :noweb-ref impl
g/PInset
(inset
[_ inset] (thi.ng.geom.types.Quad3. (inset-quad (:points _) inset)))
#+END_SRC

*** TODO PIntersect

#+BEGIN_SRC clojure :noweb-ref impl
g/PIntersect
(intersect-line
Expand All @@ -201,6 +227,7 @@ than 1.0.
(intersect-shape
[_ s])
#+END_SRC

*** PMeshConvert

A quad's mesh representation is simply a quad mesh with a single face.
Expand All @@ -211,6 +238,7 @@ A quad's mesh representation is simply a quad mesh with a single face.
([_] (g/as-mesh _ {}))
([_ opts] (g/add-face (or (:mesh opts) (bm/basic-mesh)) (:points _))))
#+END_SRC

*** TODO PPointMap

=map-point= currently broken, based on:
Expand All @@ -236,16 +264,21 @@ https://www.garagegames.com/community/forums/viewthread/76960/1#comment-543505
(unmap-point
[_ p] (gu/map-bilinear (:points _) p))
#+END_SRC
*** TODO PProximity

*** PProximity

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-proxi>>
#+END_SRC

*** TODO PSample

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-sample(n="4")>>
(random-point-inside
[_] (gu/map-bilinear (:points _) (vec2 (m/random) (m/random))))
#+END_SRC

*** PSubdivide

A quad can be subdivided into smaller ones, i.e. to create a list
Expand Down Expand Up @@ -276,6 +309,7 @@ default for missing args.
(thi.ng.geom.types.Quad3.
[(map-p [u1 v1]) (map-p [u2 v1]) (map-p [u2 v2]) (map-p [u1 v2])])))))
#+END_SRC

*** PTessellate

A quad can be tessellated into a number of triangles. When called
Expand All @@ -299,6 +333,7 @@ function returns a lazyseq of triangles of the subdivided quad.
#+END_SRC

*** PTransform :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-rotate(type="thi.ng.geom.types.Quad3")>>
<<lob-geom-rotate3d(type="thi.ng.geom.types.Quad3")>>
Expand All @@ -308,11 +343,13 @@ function returns a lazyseq of triangles of the subdivided quad.
#+END_SRC

*** PVolume :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-zerovol>>
#+END_SRC

*** End of implementations :noexport:

#+BEGIN_SRC clojure :noweb-ref impl
)
#+END_SRC
Expand Down
33 changes: 27 additions & 6 deletions geom-types/src/rect.org
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* thi.ng.geom.rect

** Constructor

#+BEGIN_SRC clojure :noweb-ref ctors
(defn rect
([] (thi.ng.geom.types.Rect2. (vec2) (vec2 1.0)))
Expand All @@ -49,16 +50,18 @@
(thi.ng.geom.types.Rect2. (vec2 x) (vec2 y w))))
([x y w h] (thi.ng.geom.types.Rect2. (vec2 x y) (vec2 w h))))
#+END_SRC

** Type specific functions

#+BEGIN_SRC clojure :noweb-ref helpers
(defn union
[{p :p [w h] :size} {q :p [qw qh] :size}]
(let [[x1 y1 :as p*] (g/min p q)
(let [[x1 y1 :as p'] (g/min p q)
x2 (max (+ (p 0) w) (+ (q 0) qw))
y2 (max (+ (p 1) h) (+ (q 1) qh))
w (- x2 x1)
h (- y2 y1)]
(thi.ng.geom.types.Rect2. p* (vec2 w h))))
(thi.ng.geom.types.Rect2. p' (vec2 w h))))

(defn left [r] ((:p r) 0))
(defn right [r] (+ ((:p r) 0) ((:size r) 0)))
Expand All @@ -75,12 +78,14 @@
#+END_SRC

*** PArea

#+BEGIN_SRC clojure :noweb-ref impl
g/PArea
(area [_] (reduce * (:size _)))
#+END_SRC

*** PBoundary

#+BEGIN_SRC clojure :noweb-ref impl
g/PBoundary
(contains-point?
Expand All @@ -89,6 +94,7 @@
#+END_SRC

*** PBounds

#+BEGIN_SRC clojure :noweb-ref impl
g/PBounds
(bounds[_] _)
Expand All @@ -98,6 +104,7 @@
#+END_SRC

*** PBoundingCircle

#+BEGIN_SRC clojure :noweb-ref impl
g/PBoundingCircle
(bounding-circle
Expand All @@ -107,6 +114,7 @@
#+END_SRC

*** PCenter

#+BEGIN_SRC clojure :noweb-ref impl
g/PCenter
(center
Expand All @@ -119,12 +127,14 @@
#+END_SRC

*** PCircumference

#+BEGIN_SRC clojure :noweb-ref impl
g/PCircumference
(circumference [_] (* 2.0 (reduce + (:size _))))
#+END_SRC

*** PClassify

#+BEGIN_SRC clojure :noweb-ref impl
g/PClassify
(classify-point
Expand Down Expand Up @@ -163,6 +173,7 @@ than 1.0.
#+END_SRC

*** PGraph

#+BEGIN_SRC clojure :noweb-ref impl
g/PVertexAccess
(vertices
Expand All @@ -185,6 +196,7 @@ than 1.0.
#+END_SRC

*** PIntersect

#+BEGIN_SRC clojure :noweb-ref impl
g/PIntersect
(intersect-line
Expand All @@ -208,6 +220,7 @@ than 1.0.
#+END_SRC

*** PMeshConvert :verify:

#+BEGIN_SRC clojure :noweb-ref impl
g/PMeshConvert
(as-mesh
Expand Down Expand Up @@ -239,21 +252,23 @@ than 1.0.
(unmap-point
[_ q] (g/madd q (:size _) (:p _)))
#+END_SRC

*** PPolygonConvert

#+BEGIN_SRC clojure :noweb-ref impl
g/PPolygonConvert
(as-polygon
[_] (thi.ng.geom.types.Polygon2. (g/vertices _)))
#+END_SRC

*** PProximity
#+BEGIN_SRC clojure :noweb-ref impl
g/PProximity
(closest-point
[_ p] (gu/closest-point-on-segments p (g/edges _)))

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-proxi>>
#+END_SRC

*** PSample

#+BEGIN_SRC clojure :noweb-ref impl
g/PSample
(point-at
Expand Down Expand Up @@ -359,6 +374,7 @@ of triangles of the subdivided rects.
(map #(thi.ng.geom.types.Triangle2. %)))))))
#+END_SRC
*** TODO PTransform

#+BEGIN_SRC clojure :noweb-ref impl
g/PRotate
(rotate
Expand Down Expand Up @@ -386,16 +402,21 @@ of triangles of the subdivided rects.
(transform
[_ m] (g/transform (g/as-polygon _) m))
#+END_SRC

*** PVolume :usetemplate:

#+BEGIN_SRC clojure :noweb-ref impl :noweb yes
<<lob-geom-zerovol>>
#+END_SRC

*** End of implementations :noexport:

#+BEGIN_SRC clojure :noweb-ref impl
)
#+END_SRC

** Namespace declaration

#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/rect.cljx :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.rect
(:require
Expand Down
5 changes: 2 additions & 3 deletions geom-types/src/triangle.org
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,8 @@ currently not possible to turn triangles into meshes.
([_ opts] (g/add-face (or (:mesh opts) (bm/basic-mesh)) (:points _))))
#+END_SRC
**** TODO PProximity
#+BEGIN_SRC clojure :noweb-ref impl3
g/PProximity
(closest-point [_ p] nil) ; TODO
#+BEGIN_SRC clojure :noweb-ref impl3 :noweb yes
<<lob-geom-proxi>>
#+END_SRC
**** PSample :verify:usetemplate:
#+BEGIN_SRC clojure :noweb-ref impl3 :noweb yes
Expand Down
Loading

0 comments on commit b1721a9

Please sign in to comment.