<commit_before>#+SETUPFILE: ../../src/setup.org

* thi.ng.geom.plane

** Constructor
#+BEGIN_SRC clojure :noweb-ref ctors
  (defn plane
    [n w] (thi.ng.geom.types.Plane. (g/normalize (vec3 n)) w))

  (defn plane-with-p
    [p n]
    (let [n (g/normalize (vec3 n))]
      (thi.ng.geom.types.Plane. n (g/dot n p))))

  (defn plane-from-points
    ([[a b c]] (plane-from-points a b c))
    ([a b c]
       (let [n (gu/ortho-normal a b c)]
         (thi.ng.geom.types.Plane. n (g/dot n a)))))
#+END_SRC
** Helper functions
#+BEGIN_SRC clojure :noweb-ref helpers
  (defn intersect-plane
    [an aw bn bw]
    (when-not (or (m/delta= aw bw *eps*) (m/delta= an bn *eps*))
      (let [od (g/dot an bn)
            det (/ (mm/madd od od -1))
            u (* (mm/madd bw od (- aw)) det)
            v (* (mm/madd aw od (- bw)) det)]
        {:p (g/madd an u (g/* bn v)) :dir (g/normalize (g/cross an bn))})))
#+END_SRC
** TODO Protocol implementation
#+BEGIN_SRC clojure :noweb-ref impl
  (extend-type thi.ng.geom.types.Plane
#+END_SRC
*** PClassify
#+BEGIN_SRC clojure :noweb-ref impl
  g/PClassify
  (classify-point
    [_ p]
    (-> (:n _) (g/dot p) (- (:w _)) (m/signum *eps*)))
#+END_SRC
*** PDistance
#+BEGIN_SRC clojure :noweb-ref impl
  g/PDistance
  (dist
   [_ p] (->> p (g/dot (:n _)) (+ (- (:w _)))))
  (dist-squared
   [_ p] (let [d (g/dist _ p)] (* d d)))<commit_msg>add PCenter impl for Plane type<commit_after>#+SETUPFILE: ../../src/setup.org

* thi.ng.geom.plane

** Constructor
#+BEGIN_SRC clojure :noweb-ref ctors
  (defn plane
    [n w] (thi.ng.geom.types.Plane. (g/normalize (vec3 n)) w))

  (defn plane-with-p
    [p n]
    (let [n (g/normalize (vec3 n))]
      (thi.ng.geom.types.Plane. n (g/dot n p))))

  (defn plane-from-points
    ([[a b c]] (plane-from-points a b c))
    ([a b c]
       (let [n (gu/ortho-normal a b c)]
         (thi.ng.geom.types.Plane. n (g/dot n a)))))
#+END_SRC
** Helper functions
#+BEGIN_SRC clojure :noweb-ref helpers
  (defn intersect-plane
    [an aw bn bw]
    (when-not (or (m/delta= aw bw *eps*) (m/delta= an bn *eps*))
      (let [od (g/dot an bn)
            det (/ (mm/madd od od -1))
            u (* (mm/madd bw od (- aw)) det)
            v (* (mm/madd aw od (- bw)) det)]
        {:p (g/madd an u (g/* bn v)) :dir (g/normalize (g/cross an bn))})))
#+END_SRC
** TODO Protocol implementation
#+BEGIN_SRC clojure :noweb-ref impl
  (extend-type thi.ng.geom.types.Plane
#+END_SRC
*** PCenter
#+BEGIN_SRC clojure :noweb-ref impl
  g/PCenter
  (center
    ([_] (thi.ng.geom.types.Plane. (:n _) 0))
    ([_ o] (plane-with-p o (:n _))))
  (centroid
    ([_] (g/* (:n _) (:w _))))
#+END_SRC
*** PClassify
#+BEGIN_SRC clojure :noweb-ref impl
  g/PClassify
  (classify-point
    [_ p]
    (-> (:n _) (g/dot p) (- (:w _)) (m/signum *eps*)))
#+END_SRC
*** PDistance
#+BEGIN_SRC clojure :noweb-ref impl
  g/PDistance
  (dist
   [_ p] (->> p (g/dot (:n _)) (+ (- (:w _)))))
  (dist-squared
   [_ p] (let [d (g/dist _ p)] (* d d)))
{'fraction_non_alphanumeric': 0.20558546433378197, 'fraction_numerical': 0.0023553162853297443, 'mean_word_length': 2.4935370152761456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2725595', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1296, 'n_words': 337}