mirror of https://github.com/penpot/penpot.git
🐛 Fix typos in common
This commit is contained in:
parent
cd2d3d5fa3
commit
39246f2beb
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
;; Extract some attributes of a list of shapes.
|
;; Extract some attributes of a list of shapes.
|
||||||
;; For each attribute, if the value is the same in all shapes,
|
;; For each attribute, if the value is the same in all shapes,
|
||||||
;; wll take this value. If there is any shape that is different,
|
;; will take this value. If there is any shape that is different,
|
||||||
;; the value of the attribute will be the keyword :multiple.
|
;; the value of the attribute will be the keyword :multiple.
|
||||||
;;
|
;;
|
||||||
;; If some shape has the value nil in any attribute, it's
|
;; If some shape has the value nil in any attribute, it's
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@
|
||||||
"Maps a function to each pair of values that can be combined inside the
|
"Maps a function to each pair of values that can be combined inside the
|
||||||
function without repetition.
|
function without repetition.
|
||||||
|
|
||||||
Optional parmeters:
|
Optional parameters:
|
||||||
`pred?` A predicate that if not satisfied won't process the pair
|
`pred?` A predicate that if not satisfied won't process the pair
|
||||||
`target?` A collection that will be used as seed to be stored
|
`target?` A collection that will be used as seed to be stored
|
||||||
|
|
||||||
|
|
@ -433,8 +433,8 @@
|
||||||
(str maybe-keyword)))))
|
(str maybe-keyword)))))
|
||||||
|
|
||||||
(defn with-next
|
(defn with-next
|
||||||
"Given a collectin will return a new collection where each element
|
"Given a collection will return a new collection where each element
|
||||||
is paried with the next item in the collection
|
is paired with the next item in the collection
|
||||||
(with-next (range 5)) => [[0 1] [1 2] [2 3] [3 4] [4 nil]"
|
(with-next (range 5)) => [[0 1] [1 2] [2 3] [3 4] [4 nil]"
|
||||||
[coll]
|
[coll]
|
||||||
(map vector
|
(map vector
|
||||||
|
|
@ -442,8 +442,8 @@
|
||||||
(concat [] (rest coll) [nil])))
|
(concat [] (rest coll) [nil])))
|
||||||
|
|
||||||
(defn with-prev
|
(defn with-prev
|
||||||
"Given a collectin will return a new collection where each element
|
"Given a collection will return a new collection where each element
|
||||||
is paried with the previous item in the collection
|
is paired with the previous item in the collection
|
||||||
(with-prev (range 5)) => [[0 nil] [1 0] [2 1] [3 2] [4 3]"
|
(with-prev (range 5)) => [[0 nil] [1 0] [2 1] [3 2] [4 3]"
|
||||||
[coll]
|
[coll]
|
||||||
(map vector
|
(map vector
|
||||||
|
|
@ -469,7 +469,7 @@
|
||||||
(keyword (str prefix kw))))
|
(keyword (str prefix kw))))
|
||||||
|
|
||||||
(defn tap
|
(defn tap
|
||||||
"Simpilar to the tap in rxjs but for plain collections"
|
"Similar to the tap in rxjs but for plain collections"
|
||||||
[f coll]
|
[f coll]
|
||||||
(f coll)
|
(f coll)
|
||||||
coll)
|
coll)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
(s/def ::type keyword?)
|
(s/def ::type keyword?)
|
||||||
(s/def ::code keyword?)
|
(s/def ::code keyword?)
|
||||||
(s/def ::mesage string?)
|
(s/def ::message string?)
|
||||||
(s/def ::hint string?)
|
(s/def ::hint string?)
|
||||||
(s/def ::cause #?(:clj #(instance? Throwable %)
|
(s/def ::cause #?(:clj #(instance? Throwable %)
|
||||||
:cljs #(instance? js/Error %)))
|
:cljs #(instance? js/Error %)))
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
(s/keys :req-un [::type]
|
(s/keys :req-un [::type]
|
||||||
:opt-un [::code
|
:opt-un [::code
|
||||||
::hint
|
::hint
|
||||||
::mesage
|
::message
|
||||||
::cause]))
|
::cause]))
|
||||||
|
|
||||||
(defn error
|
(defn error
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@
|
||||||
"Distribute equally the space between shapes in the given axis. If
|
"Distribute equally the space between shapes in the given axis. If
|
||||||
there is no space enough, it does nothing. It takes into account
|
there is no space enough, it does nothing. It takes into account
|
||||||
the form of the shape and the rotation, what is distributed is
|
the form of the shape and the rotation, what is distributed is
|
||||||
the wrapping recangles of the shapes. If any shape is a group,
|
the wrapping rectangles of the shapes. If any shape is a group,
|
||||||
move also all of its recursive children."
|
move also all of its recursive children."
|
||||||
[shapes axis objects]
|
[shapes axis objects]
|
||||||
(let [coord (if (= axis :horizontal) :x :y)
|
(let [coord (if (= axis :horizontal) :x :y)
|
||||||
|
|
@ -116,7 +116,7 @@
|
||||||
(mapcat #(recursive-move %1 {coord %2 other-coord 0} objects)
|
(mapcat #(recursive-move %1 {coord %2 other-coord 0} objects)
|
||||||
sorted-shapes deltas)))))
|
sorted-shapes deltas)))))
|
||||||
|
|
||||||
;; Adjusto to viewport
|
;; Adjust to viewport
|
||||||
|
|
||||||
(defn adjust-to-viewport
|
(defn adjust-to-viewport
|
||||||
([viewport srect] (adjust-to-viewport viewport srect nil))
|
([viewport srect] (adjust-to-viewport viewport srect nil))
|
||||||
|
|
|
||||||
|
|
@ -187,14 +187,14 @@
|
||||||
(defn round
|
(defn round
|
||||||
"Change the precision of the point coordinates."
|
"Change the precision of the point coordinates."
|
||||||
([point] (round point 0))
|
([point] (round point 0))
|
||||||
([{:keys [x y] :as p} decimanls]
|
([{:keys [x y] :as p} decimals]
|
||||||
(assert (point? p))
|
(assert (point? p))
|
||||||
(assert (number? decimanls))
|
(assert (number? decimals))
|
||||||
(Point. (mth/precision x decimanls)
|
(Point. (mth/precision x decimals)
|
||||||
(mth/precision y decimanls))))
|
(mth/precision y decimals))))
|
||||||
|
|
||||||
(defn transform
|
(defn transform
|
||||||
"Transform a point applying a matrix transfomation."
|
"Transform a point applying a matrix transformation."
|
||||||
[{:keys [x y] :as p} {:keys [a b c d e f]}]
|
[{:keys [x y] :as p} {:keys [a b c d e f]}]
|
||||||
(assert (point? p))
|
(assert (point? p))
|
||||||
(Point. (+ (* x a) (* y c) e)
|
(Point. (+ (* x a) (* y c) e)
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@
|
||||||
(not= wn 0))))
|
(not= wn 0))))
|
||||||
|
|
||||||
;; A intersects with B
|
;; A intersects with B
|
||||||
;; Three posible cases:
|
;; Three possible cases:
|
||||||
;; 1) A is inside of B
|
;; 1) A is inside of B
|
||||||
;; 2) B is inside of A
|
;; 2) B is inside of A
|
||||||
;; 3) A intersects B
|
;; 3) A intersects B
|
||||||
|
|
@ -207,11 +207,11 @@
|
||||||
(<= v 1)))
|
(<= v 1)))
|
||||||
|
|
||||||
(defn intersects-line-ellipse?
|
(defn intersects-line-ellipse?
|
||||||
"Checks wether a single line intersects with the given ellipse"
|
"Checks whether a single line intersects with the given ellipse"
|
||||||
[[{x1 :x y1 :y} {x2 :x y2 :y}] {:keys [cx cy rx ry]}]
|
[[{x1 :x y1 :y} {x2 :x y2 :y}] {:keys [cx cy rx ry]}]
|
||||||
|
|
||||||
;; Given the ellipse inequality after inserting the line parametric equations
|
;; Given the ellipse inequality after inserting the line parametric equations
|
||||||
;; we resolve t and gives us a cuadratic formula
|
;; we resolve t and gives us a quadratic formula
|
||||||
;; The result of this quadratic will give us a value of T that needs to be
|
;; The result of this quadratic will give us a value of T that needs to be
|
||||||
;; between 0-1 to be in the segment
|
;; between 0-1 to be in the segment
|
||||||
|
|
||||||
|
|
@ -284,7 +284,7 @@
|
||||||
(intersects-lines-ellipse? rect-lines ellipse-data))))
|
(intersects-lines-ellipse? rect-lines ellipse-data))))
|
||||||
|
|
||||||
(defn overlaps?
|
(defn overlaps?
|
||||||
"General case to check for overlaping between shapes and a rectangle"
|
"General case to check for overlapping between shapes and a rectangle"
|
||||||
[shape rect]
|
[shape rect]
|
||||||
(let [stroke-width (/ (or (:stroke-width shape) 0) 2)
|
(let [stroke-width (/ (or (:stroke-width shape) 0) 2)
|
||||||
rect (-> rect
|
rect (-> rect
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
(mth/almost-zero? (- a b)))
|
(mth/almost-zero? (- a b)))
|
||||||
|
|
||||||
(defn calculate-opposite-handler
|
(defn calculate-opposite-handler
|
||||||
"Given a point and its handler, gives the symetric handler"
|
"Given a point and its handler, gives the symmetric handler"
|
||||||
[point handler]
|
[point handler]
|
||||||
(let [handler-vector (gpt/to-vec point handler)]
|
(let [handler-vector (gpt/to-vec point handler)]
|
||||||
(gpt/add point (gpt/negate handler-vector))))
|
(gpt/add point (gpt/negate handler-vector))))
|
||||||
|
|
@ -179,7 +179,7 @@
|
||||||
(and (mth/almost-zero? d) (mth/almost-zero? a))
|
(and (mth/almost-zero? d) (mth/almost-zero? a))
|
||||||
[(/ (- c) b)]
|
[(/ (- c) b)]
|
||||||
|
|
||||||
;; Cuadratic
|
;; Quadratic
|
||||||
(mth/almost-zero? d)
|
(mth/almost-zero? d)
|
||||||
[(/ (+ (- b) sqrt-b2-4ac)
|
[(/ (+ (- b) sqrt-b2-4ac)
|
||||||
(* 2 a))
|
(* 2 a))
|
||||||
|
|
@ -681,7 +681,7 @@
|
||||||
(defn ray-line-intersect
|
(defn ray-line-intersect
|
||||||
[point [a b :as line]]
|
[point [a b :as line]]
|
||||||
|
|
||||||
;; If the ray is paralell to the line there will be no crossings
|
;; If the ray is parallel to the line there will be no crossings
|
||||||
(let [ray-line [point (gpt/point (inc (:x point)) (:y point))]
|
(let [ray-line [point (gpt/point (inc (:x point)) (:y point))]
|
||||||
;; Rays fail when fall just in a vertex so we move a bit upward
|
;; Rays fail when fall just in a vertex so we move a bit upward
|
||||||
;; because only want to use this for insideness
|
;; because only want to use this for insideness
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
(mapv #(gpt/add % move-vec))))
|
(mapv #(gpt/add % move-vec))))
|
||||||
|
|
||||||
(defn move
|
(defn move
|
||||||
"Move the shape relativelly to its current
|
"Move the shape relatively to its current
|
||||||
position applying the provided delta."
|
position applying the provided delta."
|
||||||
[shape {dx :x dy :y}]
|
[shape {dx :x dy :y}]
|
||||||
(let [dx (d/check-num dx)
|
(let [dx (d/check-num dx)
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
:else scale))
|
:else scale))
|
||||||
|
|
||||||
(defn- calculate-skew-angle
|
(defn- calculate-skew-angle
|
||||||
"Calculates the skew angle of the paralelogram given by the points"
|
"Calculates the skew angle of the parallelogram given by the points"
|
||||||
[[p1 _ p3 p4]]
|
[[p1 _ p3 p4]]
|
||||||
(let [v1 (gpt/to-vec p3 p4)
|
(let [v1 (gpt/to-vec p3 p4)
|
||||||
v2 (gpt/to-vec p4 p1)]
|
v2 (gpt/to-vec p4 p1)]
|
||||||
|
|
@ -83,13 +83,13 @@
|
||||||
(- 90 (gpt/angle-with-other v1 v2)))))
|
(- 90 (gpt/angle-with-other v1 v2)))))
|
||||||
|
|
||||||
(defn- calculate-height
|
(defn- calculate-height
|
||||||
"Calculates the height of a paralelogram given by the points"
|
"Calculates the height of a parallelogram given by the points"
|
||||||
[[p1 _ _ p4]]
|
[[p1 _ _ p4]]
|
||||||
(-> (gpt/to-vec p4 p1)
|
(-> (gpt/to-vec p4 p1)
|
||||||
(gpt/length)))
|
(gpt/length)))
|
||||||
|
|
||||||
(defn- calculate-width
|
(defn- calculate-width
|
||||||
"Calculates the width of a paralelogram given by the points"
|
"Calculates the width of a parallelogram given by the points"
|
||||||
[[p1 p2 _ _]]
|
[[p1 p2 _ _]]
|
||||||
(-> (gpt/to-vec p1 p2)
|
(-> (gpt/to-vec p1 p2)
|
||||||
(gpt/length)))
|
(gpt/length)))
|
||||||
|
|
@ -299,7 +299,7 @@
|
||||||
(gpr/rect->points)
|
(gpr/rect->points)
|
||||||
(gco/transform-points shape-center (:transform group (gmt/matrix))))
|
(gco/transform-points shape-center (:transform group (gmt/matrix))))
|
||||||
|
|
||||||
;; Calculte the new selrect
|
;; Calculate the new selrect
|
||||||
new-selrect (gpr/points->selrect base-points)]
|
new-selrect (gpr/points->selrect base-points)]
|
||||||
|
|
||||||
;; Updates the shape and the applytransform-rect will update the other properties
|
;; Updates the shape and the applytransform-rect will update the other properties
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@
|
||||||
(reduce update-parent-id $ shapes)
|
(reduce update-parent-id $ shapes)
|
||||||
|
|
||||||
;; Analyze the old parents and clear the old links
|
;; Analyze the old parents and clear the old links
|
||||||
;; only if the new parrent is different form old
|
;; only if the new parent is different form old
|
||||||
;; parent.
|
;; parent.
|
||||||
(reduce (partial remove-from-old-parent cpindex) $ shapes)
|
(reduce (partial remove-from-old-parent cpindex) $ shapes)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@
|
||||||
|
|
||||||
(defn fix-move-to
|
(defn fix-move-to
|
||||||
[content]
|
[content]
|
||||||
;; Remove the field `:prev` and makes the necesaries `move-to`
|
;; Remove the field `:prev` and makes the necessaries `move-to`
|
||||||
;; then clean the subpaths
|
;; then clean the subpaths
|
||||||
|
|
||||||
(loop [current (first content)
|
(loop [current (first content)
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@
|
||||||
[])))))
|
[])))))
|
||||||
|
|
||||||
(defn opposite-index
|
(defn opposite-index
|
||||||
"Calculate sthe opposite index given a prefix and an index"
|
"Calculates the opposite index given a prefix and an index"
|
||||||
[content index prefix]
|
[content index prefix]
|
||||||
|
|
||||||
(let [point (if (= prefix :c2)
|
(let [point (if (= prefix :c2)
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@
|
||||||
(pt= (:from subpath) (:to subpath)))
|
(pt= (:from subpath) (:to subpath)))
|
||||||
|
|
||||||
(defn close-subpaths
|
(defn close-subpaths
|
||||||
"Searches a path for posible supaths that can create closed loops and merge them"
|
"Searches a path for possible supaths that can create closed loops and merge them"
|
||||||
[content]
|
[content]
|
||||||
(let [subpaths (get-subpaths content)
|
(let [subpaths (get-subpaths content)
|
||||||
closed-subpaths
|
closed-subpaths
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
;; NOTE: don't remove this, causes exception on advanced build
|
;; NOTE: don't remove this, causes exception on advanced build
|
||||||
;; because of some strange interaction with cljs.spec.alpha and
|
;; because of some strange interaction with cljs.spec.alpha and
|
||||||
;; modules spliting.
|
;; modules splitting.
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@
|
||||||
:x :y :width :height :x1 :y1 :x2 :y2))
|
:x :y :width :height :x1 :y1 :x2 :y2))
|
||||||
:rect :path))
|
:rect :path))
|
||||||
|
|
||||||
(t/testing "Transform shape with invalid selrect fails gracefuly"
|
(t/testing "Transform shape with invalid selrect fails gracefully"
|
||||||
(t/are [type selrect]
|
(t/are [type selrect]
|
||||||
(let [modifiers {:displacement (gmt/matrix)}
|
(let [modifiers {:displacement (gmt/matrix)}
|
||||||
shape-before (-> (create-test-shape type {:modifiers modifiers})
|
shape-before (-> (create-test-shape type {:modifiers modifiers})
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
:components {}
|
:components {}
|
||||||
:version 7}
|
:version 7}
|
||||||
|
|
||||||
expct (-> data
|
expect (-> data
|
||||||
(update-in [:pages-index page-id :objects] dissoc
|
(update-in [:pages-index page-id :objects] dissoc
|
||||||
(uuid/custom 1 2)
|
(uuid/custom 1 2)
|
||||||
(uuid/custom 1 3)
|
(uuid/custom 1 3)
|
||||||
|
|
@ -84,8 +84,8 @@
|
||||||
res (cpm/migrate-data data)]
|
res (cpm/migrate-data data)]
|
||||||
|
|
||||||
;; (pprint res)
|
;; (pprint res)
|
||||||
;; (pprint expct)
|
;; (pprint expect)
|
||||||
|
|
||||||
(t/is (= (dissoc expct :version)
|
(t/is (= (dissoc expect :version)
|
||||||
(dissoc res :version)))
|
(dissoc res :version)))
|
||||||
))
|
))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue