correction things

This commit is contained in:
Olive Vaughn 2026-10-04 02:47:29 -04:00
parent 064a3d7c19
commit eca1a96b82
7 changed files with 329 additions and 14 deletions

View file

@ -474,3 +474,37 @@
(is (= 2 (ch/value-shape (ch/keyed {0 [1 2], 4 [3 4]} :linear))))
(is (= :opaque (ch/value-shape (ch/keyed {0 :a} :hold))))
(is (nil? (ch/value-shape (ch/keyed {} :hold))) "nothing to read it off"))
(deftest repair-borrows-current-base-and-keeps-target-corrections
(let [c (assoc (ch/keyed {0 10, 2 20, 4 40} :hold)
:repairs [{:id :repair :from 2 :through 3 :donor 0}]
:over [(ch/layer :nudge [2 4] :offset (ch/framed 5))])
cursor (ch/cursor c nil)]
(is (= [10 15 15 40 15]
(mapv #(ch/value-at c % nil) [0 2 3 4 2])))
(is (= [10 15 15 40 15]
(mapv #(ch/sample! cursor %) [0 2 3 4 2])))
(is (= 35 (ch/value-at (assoc c :keys {0 30, 2 20, 4 40}) 2 nil)))))
(deftest repair-fills-absent-base-without-recursing
(let [c (assoc (ch/keyed {0 10, 2 ch/absent, 4 40} :hold)
:repairs [{:from 2 :through 3 :donor 0}
{:from 0 :through 0 :donor 4}])]
(is (= 10 (ch/value-at c 2 nil)))
(is (= 40 (ch/value-at c 0 nil)))
(is (= 10 (ch/sample! (ch/cursor c nil) 3)))))
(deftest lid-adjustment-is-procedural-and-does-not-mutate-dense-geometry
(let [points [0 0, 2 2, 4 0, 2 -2]
c (assoc (ch/framed points)
:over [(ch/layer :lids [2 5] :eye-opening
(ch/keyed {2 1, 4 0} :linear))])
cur (ch/cursor c nil)]
(is (empty? (ch/problems c)))
(is (= points (ch/value-at c 1 nil)))
(is (= [0 0, 2 1, 4 0, 2 -1] (ch/value-at c 3 nil)))
(is (= [0 0, 2 0, 4 0, 2 0] (ch/sample! cur 4)))
(is (= [0 0, 2 1, 4 0, 2 -1] (ch/sample! cur 3)))
(is (= points (:value c)))
(is (= [0 0, 1 1, 2 0, 3 -1, 4 0]
(ch/value-at (assoc c :value [0 0, 1 2, 2 0, 3 -2, 4 0]) 3 nil)))))

View file

@ -4,6 +4,7 @@
[arthur.demo.stage :as stage]
[arthur.domain.bring :as bring]
[arthur.domain.channel :as ch]
[arthur.domain.correction :as correction]
[arthur.domain.clip :as clip]
[arthur.domain.params :as params]
[arthur.domain.project :as project]
@ -381,3 +382,61 @@
(is (empty? (ch/conflicts (channel fine :mouth path))))
(is (empty? (clip/conflicts (:clip fine))))
(is (empty? (clip/problems (:clip fine)))))))
(deftest borrowed-pose-survives-parameter-regeneration
(let [result (correction/borrow-pose (:clip @initial) :face-1
{:id :repair :from 10 :through 15 :donor 5 :head? true}
(:store @initial))
repaired (assoc @initial :clip (:clip result))
changed (regenerate/change repaired
{:scope :subject :id :face-1 :knob :anchor-avg :value 3})
c (channel changed :head [:xform :pos])
base (dissoc c :repairs :over)]
(is (nil? (:refused result)))
(is (= 1 (count (:repairs c))))
(is (= (vec (ch/value-at base 5 (:store changed)))
(vec (ch/value-at c 12 (:store changed)))))
(is (empty? (:repairs (channel
(assoc changed :clip (-> (correction/remove-repair (:clip changed) :face-1 :repair) :clip))
:head [:xform :pos]))))))
(deftest borrow-allows-a-donor-with-no-teeth-contour
(let [doc (assoc-in (:clip @initial)
[:symbols :face-1 :nodes :teeth]
{:id :teeth :kind :poly :z "a9"
:channels {[:geom :pts] (ch/keyed {} :hold)}})
doc (assoc-in doc [:features :test-teeth]
{:id :test-teeth :subject :face-1 :symbol :face-1
:area :teeth :nodes [:teeth] :params {}})
result (correction/borrow-pose doc :face-1
{:id :repair :from 10 :through 15 :donor 5}
(:store @initial))]
(is (nil? (:refused result)))
(is (= 1 (count (get-in (:clip result)
[:symbols :face-1 :nodes :teeth :channels [:geom :pts] :repairs]))))))
(deftest eye-keys-tween-over-borrowed-pose-and-survive-regeneration
(let [repair (correction/borrow-pose (:clip @initial) :face-1
{:id :repair :from 10 :through 20 :donor 5}
(:store @initial))
key1 (correction/eye-key (:clip repair) :face-1 :repair :l 10
{:opening 1 :gaze-x 0 :gaze-y 0})
key2 (correction/eye-key (:clip key1) :face-1 :repair :l 20
{:opening 0 :gaze-x 0.02 :gaze-y -0.01})
entry (assoc @initial :clip (:clip key2))
changed (regenerate/change entry
{:scope :subject :id :face-1 :knob :contour-avg :value 3})
lids (channel changed :eye-l [:geom :pts])
iris (channel changed :iris-l [:xform :pos])
removed (:clip (correction/remove-repair (:clip changed) :face-1 :repair))]
(is (nil? (:refused key1)))
(is (nil? (:refused key2)))
(is (= 1 (count (:over lids))))
(is (= 0.5 (ch/value-at (:values (first (:over lids))) 15 nil)))
(is (= [0.01 -0.005] (ch/value-at (:values (first (:over iris))) 15 nil)))
(is (= (vec (ch/value-at lids 15 (:store changed)))
(vec (ch/sample! (ch/cursor lids (:store changed)) 15))))
(is (empty? (get-in removed [:symbols :face-1 :nodes :eye-l :channels [:geom :pts] :over])))
(is (:refused (correction/eye-key (:clip repair) :face-1 :repair :l 9
{:opening 1 :gaze-x 0 :gaze-y 0})))))