                                 above-y0-end-e)
 
                      (set/union below-y1-start-e
-                                below-y1-end-e))
-        det (fn [[ax ay] [bx by] [x y]]
-              (math/sign (- (* (- bx ax)
-                               (- y ay))
-                            (* (- by ay)
-                               (- x ax)))))]
+                                below-y1-end-e))]
     (set (filter (fn [eid]
                    ;; TODO: optimize by looking up start-x, end-x, etc. from the index ranges
                    ;;       we've already created

                                              {:start-x (get-in state [:drawing :layers 0 :layer/start-x])
                                               :end-x snap-x
                                               :start-y (get-in state [:drawing :layers 0 :layer/start-y])
                                               :end-y snap-y}))]
    (-> state
        (update-in [:drawing :layers 0] #(-> %
                                             (assoc :points points
                                                    :force-even? force-even?
                                                    :layer/current-x snap-x
                                                    :layer/current-y snap-y)
                                             (cond-> (and (= tool :text)
                                                          (get-in state [:mouse-down]))
                                               ((fn [s]
                                                  (let [zoom (get-in state [:camera :zf])]
                                                    (-> s
                                                      (update-in [:layer/start-x] + (* (/ 1 zoom)
                                                                                       (:x delta)))
                                                      (update-in [:layer/start-y] + (* (/ 1 zoom)
                                                                                       (:y delta))))))))))
        (update-in [:drawing :layers 0]
                   (fn [layer]
                     (merge
                      layer
                      (when (= :pen tool)
                        {:layer/path (svg/points->path points)})
                      (when (or (= :circle tool)
                                ;; TODO: hack to preserve border-radius for re-editing circles
                                (layers/circle? layer))
                        {:layer/rx (js/Math.abs (- (:layer/start-x layer)
                                                   (:layer/current-x layer)))
                         :layer/ry (js/Math.abs (- (:layer/start-y layer)
                                                   (:layer/current-y layer)))})
                      (when (seq bounding-eids)
                        {:layer/child bounding-eids}))))
        (assoc-in [:editing-eids :editing-eids] #{(get-in state [:drawing :layers 0 :db/id])})
        (cond-> group?
          (assoc-in [:selected-eids :selected-eids] (set bounding-eids))))))

(defn move-points [points move-x move-y]
  (map (fn [{:keys [rx ry]}]

    (assoc-in [:drawing :layers 0 :layer/text] value)
    (assoc-in [:drawing :layers 0 :bbox] bbox)))

(defn det [[ax ay] [bx by] [x y]]
  (math/sign (- (* (- bx ax)
                   (- y ay))
                (* (- by ay)
                   (- x ax)))))

(defn eids-in-bounding-box [db {:keys [start-x end-x start-y end-y] :as box}]
  (let [x0 (min start-x end-x)
        x1 (max start-x end-x)
