 (ns labs-4-cource.aproximation
   (:require [clojure.core.matrix :as m]
-            [labs-4-cource.first-order-lines :refer [floor line-points]]))
+            [labs-4-cource.first-order-lines
+             :refer
+             [->BrezenhameLine floor line-points]]))
+
+(defn get-form-points [matrix [p1 p2 p3 p4]]
+    (m/emap
+     floor
+     (m/mmul
+      (m/matrix
+       (map (fn [t] [(* t t t) (* t t) t 1]) (range 0 1 0.05)))
+      matrix
+      (m/matrix (list p1
+                      p2
+                      p3
+                      p4)))))
+
+(defn linearise [points]
+    (mapcat line-points
+            (map (fn [[p1 p2]] (->BrezenhameLine p1 p2))
+                 (partition 2 1 points))))
 
 (defn ->Ermit [p1 p2 p3 p4]
   (let [[x1 y1] p1

    [1  0  0  0]]))

(defmethod line-points :ermit [{:keys [p1 p4 v1 v4]}]
  (m/emap
   floor
   (m/mmul
    (m/matrix
     (map (fn [t] [(* t t t) (* t t) t 1]) (range 0 1 0.01)))
    ermit-matrix
    (m/matrix (list p1
                    p4
                    v1
                    v4)))))
(line-points (->Ermit [30 30] [240 300] [130 20] [200 400]))

(defn ->Bezie [p1 p2 p3 p4]

   (/ 1 6)))

(defn b-spline-segment [[p1 p2 p3 p4]]
  (get-form-points b-spline-matrix [p1 p2 p3 p4]))

(defmethod line-points :spline [{points :points}]
  (linearise (mapcat b-spline-segment (partition 4 1 points))))

(comment
  (line-points {:type :spline :points [[0 0] [0 0] [100 100] [200 200] [100 100][100 100]]})
  (doall
   (partition 2 1 (b-spline-segment [[0 0] [100 100] [200 200] [100 100]]))))
