<commit_before>* thi.ng.geom.bezier
** Namespace declaration
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
  (ns thi.ng.geom.bezier
    (:require
     [thi.ng.data.core :as d]
     [thi.ng.math.core :as m]
     [thi.ng.geom.core :as g]))
#+END_SRC
** The Bernstein polynomial
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
(defn bernstein
  [t]
  (let [it (- 1.0 t) it2 (* it it) t2 (* t t)]
    [(* it it2) (* 3 (* t it2)) (* 3 (* it t2)) (* t t2)]))
#+END_SRC
** Interpolation & curve samplings
     Applied to calculate a single point on a bezier patch, sample a patch
     at a fixed resolution and sample a continous curve from a seq of
     control points... =interpolate*= and =as-linestrip*= are
     implemented as HOF to support both 2D/3D cases. Further below
     we'll provide pre-configured implementations for each.
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
  (defn interpolate
    [[a b c d] t]
    (let [[ta tb tc td] (bernstein t)]
      (-> a
          (g/scale ta)
          (g/add (g/scale b tb))
          (g/add (g/scale c tc))
          (g/add (g/scale d td)))))

  (defn sample-segment
    [seg res]
    (for [t (range 0.0 1.0 (/ 1.0 res))]
      (interpolate seg t)))

  (defn as-linestrip
    [res include-last? points]
    (let [ls (->> points
                  (d/successive-nth 4)
                  (take-nth 3)
                  (mapcat #(sample-segment % res)))]
      (if include-last?
        (concat ls [(last points)])
        ls)))
#+END_SRC
** Automatic curve generation
     The following two functions allow us to compute a bezier curve
     which passes through all given points and automatically computes
     the required control points.
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
  (defn find-cpoints*
    [ctor]
    (fn [tight points]<commit_msg>bezier: refactoring interpolate to use new vector madd fns<commit_after>* thi.ng.geom.bezier
** Namespace declaration
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
  (ns thi.ng.geom.bezier
    (:require
     [thi.ng.data.core :as d]
     [thi.ng.math.core :as m]
     [thi.ng.geom.core :as g]))
#+END_SRC
** The Bernstein polynomial
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
(defn bernstein
  [t]
  (let [it (- 1.0 t) it2 (* it it) t2 (* t t)]
    [(* it it2) (* 3 (* t it2)) (* 3 (* it t2)) (* t t2)]))
#+END_SRC
** Interpolation & curve samplings
     Applied to calculate a single point on a bezier patch, sample a patch
     at a fixed resolution and sample a continous curve from a seq of
     control points... =interpolate*= and =as-linestrip*= are
     implemented as HOF to support both 2D/3D cases. Further below
     we'll provide pre-configured implementations for each.
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
  (defn interpolate
    [[a b c d] t]
    (let [[ta tb tc td] (bernstein t)]
      (->> (g/scale a ta)
           (g/madd b tb)
           (g/madd c tc)
           (g/madd d td))))

  (defn sample-segment
    [seg res]
    (for [t (range 0.0 1.0 (/ 1.0 res))]
      (interpolate seg t)))

  (defn as-linestrip
    [res include-last? points]
    (let [ls (->> points
                  (d/successive-nth 4)
                  (take-nth 3)
                  (mapcat #(sample-segment % res)))]
      (if include-last?
        (concat ls [(last points)])
        ls)))
#+END_SRC
** Automatic curve generation
     The following two functions allow us to compute a bezier curve
     which passes through all given points and automatically computes
     the required control points.
#+BEGIN_SRC clojure :tangle babel/src-cljx/thi/ng/geom/bezier.cljx
  (defn find-cpoints*
    [ctor]
    (fn [tight points]
{'fraction_non_alphanumeric': 0.13010068892421833, 'fraction_numerical': 0.010598834128245893, 'mean_word_length': 2.4953703703703702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '6460397', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1359, 'n_words': 424}