A lens bulges, and its edge has no seam

The lens was a flat zoom: everything under it the same amount bigger, so
its edge cut the picture and it read as a magnified cut-out rather than as
glass. It now magnifies most in its middle and eases back to as it is at
its rim, where what is near the edge is squeezed round the curve, as
Photoshop's Spherize does. The rim is how far the shape reaches from its
own middle, so the bulge ends at the edge of the glass drawn at any size,
with nothing to set. Below 0 it pinches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Olive Vaughn 2026-11-24 08:22:16 -05:00
parent 4cee461ecd
commit d06fa52c8a
3 changed files with 54 additions and 9 deletions

View file

@ -6,7 +6,8 @@
[arthur.domain.paint :as paint]
[arthur.domain.palette :as pal]
[arthur.domain.pick :as pick]
[arthur.domain.raster :as raster]))
[arthur.domain.raster :as raster]
[arthur.domain.warp :as warp]))
(defn- sq [x0 y0 x1 y1] [x0 y0 x1 y0 x1 y1 x0 y1])
@ -53,6 +54,25 @@
(is (= [:lens] (pick/hit (:ops d) [12 12] [:lens]))
"unless the glass is what is selected, which is how it is dragged")))
(deftest a-lens-bulges-and-has-no-seam
;; A round glass of radius 10 about (50, 50): magnified in the middle, as it
;; is at its rim and outside it, and squeezed in between.
(let [ring (into [] (mapcat #(let [t (* % (/ js/Math.PI 16))]
[(* 10 (js/Math.cos t)) (* 10 (js/Math.sin t))]))
(range 32))
op (fn [a] {:kind :poly :pts (js/Float64Array. (clj->js (map-indexed #(+ %2 50) ring)))
:n 32 :warp :lens :amount a
:m (js/Float64Array. #js [1 0 0 1 50 50])})
shows (fn [a x] (aget ((warp/field (op a)) (js/Float64Array. 2) x 50) 0))
near? (fn [a b] (< (js/Math.abs (- a b)) 1e-9))]
(is (< (js/Math.abs (- 50.5 (shows 1 51))) 0.01) "twice the size at the middle: one pixel out shows half of one")
(is (near? 60 (shows 1 60)) "as it is at the rim, so the edge meets what is outside it")
(is (near? 63 (shows 1 63)) "and outside it")
(is (< (- (shows 1 54) (shows 1 53)) 1) "magnified across its middle two thirds")
(is (> (- (shows 1 59.5) (shows 1 58.5)) 1) "and squeezed round the curve at it")
(is (> (shows -0.5 51) 51) "below 0 it pinches")
(is (near? 55 (shows 0 55)) "and at 0 it is not there")))
(deftest a-warp-at-amount-zero-is-not-there
;; Amount 0 is untouched for every kind, which is what lets a tween from 0
;; bring any of them in from nothing.
@ -94,7 +114,8 @@
frame (fn [f] (let [ops ((clip/resolver doc :main nil (pal/compile doc) nil) f)]
(raster/draw-ops! (raster/clear! (raster/make 320 200) 0) ops)))
wide (fn [f] (count (filter #(= 4 (aget (:buf (frame f)) (+ % (* 21 320)))) (range 10 30))))]
(is (= [2 4 6] (mapv wide [0 1 2])) "1×, 2×, 3× through the tween")))
(is (= [2 4 5] (mapv wide [0 1 2]))
"wider through the tween: 2× and 3× in the middle, easing off toward the rim")))
(deftest a-lens-in-a-symbol-magnifies-what-is-outside-the-symbol
;; The point of a lens is to go BETWEEN things, so a lens a symbol holds sees