mirror of
https://github.com/penpot/penpot.git
synced 2025-08-06 12:58:28 +02:00
✨ Move fressian and transit impl for geom objects to respective nss
This commit is contained in:
parent
f7801f9450
commit
3f14308908
5 changed files with 63 additions and 68 deletions
|
@ -7,12 +7,8 @@
|
||||||
(ns app.common.fressian
|
(ns app.common.fressian
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.matrix :as gmt]
|
|
||||||
[app.common.geom.point :as gpt]
|
|
||||||
[clojure.data.fressian :as fres])
|
[clojure.data.fressian :as fres])
|
||||||
(:import
|
(:import
|
||||||
app.common.geom.matrix.Matrix
|
|
||||||
app.common.geom.point.Point
|
|
||||||
clojure.lang.Ratio
|
clojure.lang.Ratio
|
||||||
java.io.ByteArrayInputStream
|
java.io.ByteArrayInputStream
|
||||||
java.io.ByteArrayOutputStream
|
java.io.ByteArrayOutputStream
|
||||||
|
@ -297,39 +293,3 @@
|
||||||
[data]
|
[data]
|
||||||
(with-open [^ByteArrayInputStream input (ByteArrayInputStream. ^bytes data)]
|
(with-open [^ByteArrayInputStream input (ByteArrayInputStream. ^bytes data)]
|
||||||
(-> input reader read!)))
|
(-> input reader read!)))
|
||||||
|
|
||||||
;; --- ADDITIONAL
|
|
||||||
|
|
||||||
(add-handlers!
|
|
||||||
{:name "penpot/point"
|
|
||||||
:class app.common.geom.point.Point
|
|
||||||
:wfn (fn [n w ^Point o]
|
|
||||||
(write-tag! w n 1)
|
|
||||||
(write-list! w (List/of (.-x o) (.-y o))))
|
|
||||||
:rfn (fn [^Reader rdr]
|
|
||||||
(let [^List x (read-object! rdr)]
|
|
||||||
(Point. (.get x 0) (.get x 1))))}
|
|
||||||
|
|
||||||
{:name "penpot/matrix"
|
|
||||||
:class app.common.geom.matrix.Matrix
|
|
||||||
:wfn (fn [^String n ^Writer w o]
|
|
||||||
(write-tag! w n 1)
|
|
||||||
(write-list! w (List/of (.-a ^Matrix o)
|
|
||||||
(.-b ^Matrix o)
|
|
||||||
(.-c ^Matrix o)
|
|
||||||
(.-d ^Matrix o)
|
|
||||||
(.-e ^Matrix o)
|
|
||||||
(.-f ^Matrix o))))
|
|
||||||
:rfn (fn [^Reader rdr]
|
|
||||||
(let [^List x (read-object! rdr)]
|
|
||||||
(Matrix. (.get x 0) (.get x 1) (.get x 2) (.get x 3) (.get x 4) (.get x 5))))})
|
|
||||||
|
|
||||||
|
|
||||||
;; Backward compatibility for 1.19 with v1.20;
|
|
||||||
|
|
||||||
(add-handlers!
|
|
||||||
{:name "penpot/geom/rect"
|
|
||||||
:rfn read-map-like}
|
|
||||||
{:name "penpot/shape"
|
|
||||||
:rfn read-map-like})
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
#?(:cljs [cljs.pprint :as pp]
|
#?(:cljs [cljs.pprint :as pp]
|
||||||
:clj [clojure.pprint :as pp])
|
:clj [clojure.pprint :as pp])
|
||||||
|
#?(:clj [app.common.fressian :as fres])
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
|
@ -16,7 +17,12 @@
|
||||||
[app.common.schema.generators :as sg]
|
[app.common.schema.generators :as sg]
|
||||||
[app.common.schema.openapi :as-alias oapi]
|
[app.common.schema.openapi :as-alias oapi]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[clojure.spec.alpha :as s]))
|
[app.common.transit :as t]
|
||||||
|
[clojure.spec.alpha :as s])
|
||||||
|
#?(:clj
|
||||||
|
(:import
|
||||||
|
java.util.List)))
|
||||||
|
|
||||||
|
|
||||||
(def precision 6)
|
(def precision 6)
|
||||||
|
|
||||||
|
@ -376,3 +382,36 @@
|
||||||
(mth/almost-zero? b)
|
(mth/almost-zero? b)
|
||||||
(mth/almost-zero? c)
|
(mth/almost-zero? c)
|
||||||
(mth/almost-zero? (- d 1))))
|
(mth/almost-zero? (- d 1))))
|
||||||
|
|
||||||
|
#?(:clj
|
||||||
|
(fres/add-handlers!
|
||||||
|
{:name "penpot/matrix"
|
||||||
|
:class Matrix
|
||||||
|
:wfn (fn [n w o]
|
||||||
|
(fres/write-tag! w n 1)
|
||||||
|
(fres/write-list! w (List/of (.-a ^Matrix o)
|
||||||
|
(.-b ^Matrix o)
|
||||||
|
(.-c ^Matrix o)
|
||||||
|
(.-d ^Matrix o)
|
||||||
|
(.-e ^Matrix o)
|
||||||
|
(.-f ^Matrix o))))
|
||||||
|
:rfn (fn [rdr]
|
||||||
|
(let [^List x (fres/read-object! rdr)]
|
||||||
|
(map->Matrix {:a (.get x 0)
|
||||||
|
:b (.get x 1)
|
||||||
|
:c (.get x 2)
|
||||||
|
:d (.get x 3)
|
||||||
|
:e (.get x 4)
|
||||||
|
:f (.get x 5)})))}))
|
||||||
|
|
||||||
|
(t/add-handlers!
|
||||||
|
{:id "matrix"
|
||||||
|
:class Matrix
|
||||||
|
:wfn #(into {} %)
|
||||||
|
:rfn (fn [m]
|
||||||
|
(map->Matrix {:a (get m :a)
|
||||||
|
:b (get m :b)
|
||||||
|
:c (get m :c)
|
||||||
|
:d (get m :d)
|
||||||
|
:e (get m :e)
|
||||||
|
:f (get m :f)}))})
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
:clj [clojure.pprint :as pp])
|
:clj [clojure.pprint :as pp])
|
||||||
#?(:cljs [cljs.core :as c]
|
#?(:cljs [cljs.core :as c]
|
||||||
:clj [clojure.core :as c])
|
:clj [clojure.core :as c])
|
||||||
|
#?(:clj [app.common.fressian :as fres])
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
@ -19,8 +20,12 @@
|
||||||
[app.common.schema.generators :as sg]
|
[app.common.schema.generators :as sg]
|
||||||
[app.common.schema.openapi :as-alias oapi]
|
[app.common.schema.openapi :as-alias oapi]
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
|
[app.common.transit :as t]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]))
|
[cuerdas.core :as str])
|
||||||
|
#?(:clj
|
||||||
|
(:import
|
||||||
|
java.util.List)))
|
||||||
|
|
||||||
;; --- Point Impl
|
;; --- Point Impl
|
||||||
|
|
||||||
|
@ -466,3 +471,19 @@
|
||||||
|
|
||||||
(defmethod pp/simple-dispatch Point [obj] (pr obj))
|
(defmethod pp/simple-dispatch Point [obj] (pr obj))
|
||||||
|
|
||||||
|
#?(:clj
|
||||||
|
(fres/add-handlers!
|
||||||
|
{:name "penpot/point"
|
||||||
|
:class Point
|
||||||
|
:wfn (fn [n w ^Point o]
|
||||||
|
(fres/write-tag! w n 1)
|
||||||
|
(fres/write-list! w (List/of (.-x o) (.-y o))))
|
||||||
|
:rfn (fn [rdr]
|
||||||
|
(let [^List x (fres/read-object! rdr)]
|
||||||
|
(pos->Point (.get x 0) (.get x 1))))}))
|
||||||
|
|
||||||
|
(t/add-handlers!
|
||||||
|
{:id "point"
|
||||||
|
:class Point
|
||||||
|
:wfn #(into {} %)
|
||||||
|
:rfn map->Point})
|
||||||
|
|
|
@ -51,11 +51,7 @@
|
||||||
(if ^boolean (d/num? x) (+ dx x) x)
|
(if ^boolean (d/num? x) (+ dx x) x)
|
||||||
(if ^boolean (d/num? y) (+ dy y) y)
|
(if ^boolean (d/num? y) (+ dy y) y)
|
||||||
w
|
w
|
||||||
h
|
h))
|
||||||
(if ^boolean (d/num? x1) (+ dx x1) x1)
|
|
||||||
(if ^boolean (d/num? y1) (+ dy y1) y1)
|
|
||||||
(if ^boolean (d/num? x2) (+ dx x2) x2)
|
|
||||||
(if ^boolean (d/num? y2) (+ dy y2) y2)))
|
|
||||||
selrect))
|
selrect))
|
||||||
|
|
||||||
(defn- move-points
|
(defn- move-points
|
||||||
|
|
|
@ -7,8 +7,6 @@
|
||||||
(ns app.common.transit
|
(ns app.common.transit
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.geom.matrix :as gmt]
|
|
||||||
[app.common.geom.point :as gpt]
|
|
||||||
[app.common.uri :as uri]
|
[app.common.uri :as uri]
|
||||||
[cognitect.transit :as t]
|
[cognitect.transit :as t]
|
||||||
[lambdaisland.uri :as luri]
|
[lambdaisland.uri :as luri]
|
||||||
|
@ -18,8 +16,6 @@
|
||||||
#?(:cljs ["luxon" :as lxn]))
|
#?(:cljs ["luxon" :as lxn]))
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(:import
|
(:import
|
||||||
app.common.geom.matrix.Matrix
|
|
||||||
app.common.geom.point.Point
|
|
||||||
java.io.ByteArrayInputStream
|
java.io.ByteArrayInputStream
|
||||||
java.io.ByteArrayOutputStream
|
java.io.ByteArrayOutputStream
|
||||||
java.io.File
|
java.io.File
|
||||||
|
@ -122,23 +118,6 @@
|
||||||
{:id "u"
|
{:id "u"
|
||||||
:rfn parse-uuid})
|
:rfn parse-uuid})
|
||||||
|
|
||||||
{:id "point"
|
|
||||||
:class #?(:clj Point :cljs gpt/Point)
|
|
||||||
:wfn #(into {} %)
|
|
||||||
:rfn gpt/map->Point}
|
|
||||||
|
|
||||||
{:id "matrix"
|
|
||||||
:class #?(:clj Matrix :cljs gmt/Matrix)
|
|
||||||
:wfn #(into {} %)
|
|
||||||
:rfn #?(:cljs gmt/map->Matrix
|
|
||||||
:clj (fn [{:keys [a b c d e f]}]
|
|
||||||
(gmt/matrix (double a)
|
|
||||||
(double b)
|
|
||||||
(double c)
|
|
||||||
(double d)
|
|
||||||
(double e)
|
|
||||||
(double f))))}
|
|
||||||
|
|
||||||
{:id "ordered-set"
|
{:id "ordered-set"
|
||||||
:class #?(:clj LinkedSet :cljs lks/LinkedSet)
|
:class #?(:clj LinkedSet :cljs lks/LinkedSet)
|
||||||
:wfn vec
|
:wfn vec
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue