<commit_before>(ns org.playasophy.wonderdome.geometry.cartesian
  "Functions for working in the cartesian coordinate system. A point is a
  3-element vector of [x y z]. Coordinates are assumed to be in meters.")


(defn scale
  "Scales a coordinate vector by a constant factor."
  [p s]
  (vec (map (partial * s) p)))


(defn magnitude
  "Determines the magnitude of the vector from the origin to the given point."
  [p]
  (Math/sqrt (apply + (map #(* % %) p))))


(defn distance
  "Determines the distance between two points."
  [a b]
  (magnitude (map - a b)))


(defn midpoint
  "Returns a new point that is a fraction of the distance towards point b
  from point a."
  [p a b]
  (->>
    (map - b a)
    (map (partial * p))
    (map + a)))


(defn ->sphere
  "Converts a cartesian coordinate to a spherical coordinate vector."
  [[x y z :as p]]
  (let [r (magnitude p)]
    [r
     (Math/acos (/ z r))
     (Math/atan (/ y x))]))


(defn project-to
  "Projects a point to the same vector on the surface of a sphere with the
  given radius."
  [r p]
  (let [scale (/ r (magnitude p))]
    (vec (map (partial * scale) p))))


(defn rotate-x
  "Rotates a point around the X axis by theta radians."
  [theta [x y z]]
  (let [cos-t (Math/cos theta)
        sin-t (Math/sin theta)]
    [x
     (- (* y cos-t) (* z sin-t))
     (+ (* y sin-t) (* z cos-t))]))


(defn dedupe-edges
  "Deduplicates a set of edges by unifying point values which lie within a certain
  distance epsilon of each other."
  [epsilon edges]
  (let [some-point (fn [points p]
                     (or (first (filter #(< (distance p %) epsilon)
                                        points))
                         p))]
    (loop [points #{}
           edges edges
           result #{}]
      (let [[a b] (first edges)
            a' (some-point points a)
            b' (some-point points b)
            points' (conj points a' b')
            result' (conj result (vec (sort [a' b'])))]
        (if (next edges)
          (recur points' (next edges) result')
          result')))))


(defn sort-edges
  "Returns a sequence of edges, sorted by z, y, then x coordinates."
  [edges]
  (let [edge-key (fn [[a b]] (vec (map sort (reverse (map vector a b)))))]
    (reverse (sort-by edge-key edges))))<commit_msg>Fix sorting bug in cartesian/sort-edges.<commit_after>(ns org.playasophy.wonderdome.geometry.cartesian
  "Functions for working in the cartesian coordinate system. A point is a
  3-element vector of [x y z]. Coordinates are assumed to be in meters.")


(defn scale
  "Scales a coordinate vector by a constant factor."
  [p s]
  (vec (map (partial * s) p)))


(defn magnitude
  "Determines the magnitude of the vector from the origin to the given point."
  [p]
  (Math/sqrt (apply + (map #(* % %) p))))


(defn distance
  "Determines the distance between two points."
  [a b]
  (magnitude (map - a b)))


(defn midpoint
  "Returns a new point that is a fraction of the distance towards point b
  from point a."
  [p a b]
  (->>
    (map - b a)
    (map (partial * p))
    (map + a)))


(defn ->sphere
  "Converts a cartesian coordinate to a spherical coordinate vector."
  [[x y z :as p]]
  (let [r (magnitude p)]
    [r
     (Math/acos (/ z r))
     (Math/atan (/ y x))]))


(defn project-to
  "Projects a point to the same vector on the surface of a sphere with the
  given radius."
  [r p]
  (let [scale (/ r (magnitude p))]
    (vec (map (partial * scale) p))))


(defn rotate-x
  "Rotates a point around the X axis by theta radians."
  [theta [x y z]]
  (let [cos-t (Math/cos theta)
        sin-t (Math/sin theta)]
    [x
     (- (* y cos-t) (* z sin-t))
     (+ (* y sin-t) (* z cos-t))]))


(defn dedupe-edges
  "Deduplicates a set of edges by unifying point values which lie within a certain
  distance epsilon of each other."
  [epsilon edges]
  (let [some-point (fn [points p]
                     (or (first (filter #(< (distance p %) epsilon)
                                        points))
                         p))]
    (loop [points #{}
           edges edges
           result #{}]
      (let [[a b] (first edges)
            a' (some-point points a)
            b' (some-point points b)
            points' (conj points a' b')
            result' (conj result (vec (sort [a' b'])))]
        (if (next edges)
          (recur points' (next edges) result')
          result')))))


(defn sort-edges
  "Returns a sequence of edges, sorted by z, y, then x coordinates."
  [edges]
  (let [edge-key (fn [[a b]] (vec (map (comp vec sort) (reverse (map vector a b)))))]
    (reverse (sort-by edge-key edges))))
{'fraction_non_alphanumeric': 0.13482414242292662, 'fraction_numerical': 0.0004342162396873643, 'mean_word_length': 2.239803094233474, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6642164', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1487, 'n_words': 615}