<commit_before>(ns infinitelives.utils.geom2-test
  (:require [cljs.test :refer-macros [deftest is]]
            [infinitelives.utils.geom2 :as geom2]
            [infinitelives.utils.vec2 :as vec2]))

(def on-root-2 (/ 1 (Math/sqrt 2)))
(def pi-on-2 (/ Math/PI 2))

(deftest angle
  (is (= pi-on-2
         (geom2/angle
          (vec2/vec2 100 100)
          (vec2/vec2 100 50)
          (vec2/vec2 400 50))))
  (is (> 1e-7 (geom2/angle
              (vec2/vec2 -10 10)
              (vec2/vec2 0 0)
              (vec2/vec2 -10 10))))
  (is (= Math/PI
         (geom2/angle
          (vec2/vec2 -10 0)
          (vec2/vec2 0 0)
          (vec2/vec2 10 0)))))

(deftest polygon-triplets
  (let [a (vec2/vec2 0 0)
        b (vec2/vec2 0 1)
        c (vec2/vec2 1 1)
        d (vec2/vec2 1 0)
        poly [a b c d]]
    (is (= (geom2/polygon-triplets poly)
           [[d a b] [a b c] [b c d] [c d a]]))))


(deftest polygon-angles
  (let [a (vec2/vec2 0 0)
        b (vec2/vec2 0 4)
        c (vec2/vec2 3 3)
        d (vec2/vec2 4 1)
        e (vec2/vec2 3 0)
        poly [a b c d e]]
    (println
     (sort (map vector
                              (map #(apply geom2/angle %) (geom2/polygon-triplets poly))
                              (range))))))
<commit_msg>polygon angles needs more thought to prevent returning outside angle in concave poly<commit_after>(ns infinitelives.utils.geom2-test
  (:require [cljs.test :refer-macros [deftest is]]
            [infinitelives.utils.geom2 :as geom2]
            [infinitelives.utils.vec2 :as vec2]))

(def on-root-2 (/ 1 (Math/sqrt 2)))
(def pi-on-2 (/ Math/PI 2))

(deftest angle
  (is (= pi-on-2
         (geom2/angle
          (vec2/vec2 100 100)
          (vec2/vec2 100 50)
          (vec2/vec2 400 50))))
  (is (> 1e-7 (geom2/angle
              (vec2/vec2 -10 10)
              (vec2/vec2 0 0)
              (vec2/vec2 -10 10))))
  (is (= Math/PI
         (geom2/angle
          (vec2/vec2 -10 0)
          (vec2/vec2 0 0)
          (vec2/vec2 10 0)))))

(deftest polygon-triplets
  (let [a (vec2/vec2 0 0)
        b (vec2/vec2 0 1)
        c (vec2/vec2 1 1)
        d (vec2/vec2 1 0)
        poly [a b c d]]
    (is (= (geom2/polygon-triplets poly)
           [[d a b] [a b c] [b c d] [c d a]]))))

(comment
  (deftest polygon-angles
    (let [a (vec2/vec2 0 0)
          b (vec2/vec2 0 4)
          c (vec2/vec2 3 3)
          d (vec2/vec2 4 1)
          e (vec2/vec2 3 0)
          poly [a b c d e]]
      (println
       (sort (map vector
                  (map #(apply geom2/angle %) (geom2/polygon-triplets poly))
                  (range)))))))

{'fraction_non_alphanumeric': 0.14548238897396631, 'fraction_numerical': 0.08192955589586524, 'mean_word_length': 1.5246376811594202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2753113', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1021, 'n_words': 289}