0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 21:09:00 -05:00

Improved intersection edge cases

This commit is contained in:
alonso.torres 2021-09-28 11:30:06 +02:00
parent 75f8e473a5
commit 1bd3a792da
4 changed files with 24 additions and 21 deletions

View file

@ -63,10 +63,9 @@
cy (:y p) cy (:y p)
ay (:y to-p) ay (:y to-p)
by (:y from-p)] by (:y from-p)]
(cond (cond
(> (- cy ay) 0) 1 (and (> (- cy ay) 0) (not (s= cy ay))) 1
(< (- cy ay) 0) -1 (and (< (- cy ay) 0) (not (s= cy ay))) -1
(< (- cy by) 0) 1 (< (- cy by) 0) 1
(> (- cy by) 0) -1 (> (- cy by) 0) -1
:else 0))) :else 0)))
@ -558,8 +557,14 @@
(defn- get-line-tval (defn- get-line-tval
[[{x1 :x y1 :y} {x2 :x y2 :y}] {:keys [x y]}] [[{x1 :x y1 :y} {x2 :x y2 :y}] {:keys [x y]}]
(if (mth/almost-zero? (- x2 x1)) (cond
(and (s= x1 x2) (s= y1 y2))
##Inf
(s= x1 x2)
(/ (- y y1) (- y2 y1)) (/ (- y y1) (- y2 y1))
:else
(/ (- x x1) (- x2 x1)))) (/ (- x x1) (- x2 x1))))
(defn- curve-range->rect (defn- curve-range->rect
@ -578,15 +583,16 @@
{x2 :x y2 :y} to-p {x2 :x y2 :y} to-p
{px :x py :y} point {px :x py :y} point
m (/ (- y2 y1) (- x2 x1)) m (when-not (s= x1 x2) (/ (- y2 y1) (- x2 x1)))
vy (+ (* m px) (* (- m) x1) y1) vy (when (some? m) (+ (* m px) (* (- m) x1) y1))
t (get-line-tval line point)] t (get-line-tval line point)]
;; If x1 = x2 there is no slope, to see if the point is in the line ;; If x1 = x2 there is no slope, to see if the point is in the line
;; only needs to check the x is the same ;; only needs to check the x is the same
(and (or (and (s= x1 x2) (s= px x1)) (and (or (and (s= x1 x2) (s= px x1))
(s= py vy)) (and (some? vy) (s= py vy)))
;; This will check if is between both segments ;; This will check if is between both segments
(or (> t 0) (s= t 0)) (or (> t 0) (s= t 0))
(or (< t 1) (s= t 1))))) (or (< t 1) (s= t 1)))))

View file

@ -13,17 +13,14 @@
;; Auxiliary functions to help create a set of changes (undo + redo) ;; Auxiliary functions to help create a set of changes (undo + redo)
(defn empty-changes [origin page-id] (defn empty-changes [origin page-id]
(with-meta (let [changes {:redo-changes []
{:redo-changes [] :undo-changes []
:undo-changes [] :origin origin}]
:origin origin} (with-meta changes
{::page-id page-id})) {::page-id page-id})))
(defn with-objects [changes objects] (defn with-objects [changes objects]
(with-meta (vary-meta changes assoc ::objects objects))
changes
(-> (meta changes)
(assoc ::objects objects))))
(defn add-obj (defn add-obj
([changes obj index] ([changes obj index]

View file

@ -16,23 +16,23 @@
(def ^:const bezier-circle-c 0.551915024494) (def ^:const bezier-circle-c 0.551915024494)
(def ^:const dissoc-attrs (def dissoc-attrs
[:x :y :width :height [:x :y :width :height
:rx :ry :r1 :r2 :r3 :r4 :rx :ry :r1 :r2 :r3 :r4
:metadata :shapes]) :metadata :shapes])
(def ^:const allowed-transform-types (def allowed-transform-types
#{:rect #{:rect
:circle :circle
:image :image
:group :group
:bool}) :bool})
(def ^:const style-group-properties (def style-group-properties
[:shadow [:shadow
:blur]) :blur])
(def ^:const style-properties (def style-properties
(d/concat (d/concat
style-group-properties style-group-properties
[:fill-color [:fill-color

View file

@ -44,7 +44,7 @@
(assoc :type :path) (assoc :type :path)
(assoc :stroke-color "blue") (assoc :stroke-color "blue")
(assoc :stroke-opacity 1) (assoc :stroke-opacity 1)
(assoc :stroke-width 0.5) (assoc :stroke-width 1)
(assoc :stroke-style :solid) (assoc :stroke-style :solid)
(dissoc :fill-color :fill-opacity) (dissoc :fill-color :fill-opacity)
(assoc :content content-b)) (assoc :content content-b))