0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-25 07:58:49 -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)
ay (:y to-p)
by (:y from-p)]
(cond
(> (- cy ay) 0) 1
(< (- cy ay) 0) -1
(and (> (- cy ay) 0) (not (s= cy ay))) 1
(and (< (- cy ay) 0) (not (s= cy ay))) -1
(< (- cy by) 0) 1
(> (- cy by) 0) -1
:else 0)))
@ -558,8 +557,14 @@
(defn- get-line-tval
[[{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))
:else
(/ (- x x1) (- x2 x1))))
(defn- curve-range->rect
@ -578,15 +583,16 @@
{x2 :x y2 :y} to-p
{px :x py :y} point
m (/ (- y2 y1) (- x2 x1))
vy (+ (* m px) (* (- m) x1) y1)
m (when-not (s= x1 x2) (/ (- y2 y1) (- x2 x1)))
vy (when (some? m) (+ (* m px) (* (- m) x1) y1))
t (get-line-tval line point)]
;; 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
(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
(or (> t 0) (s= t 0))
(or (< t 1) (s= t 1)))))

View file

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

View file

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

View file

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