0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-27 15:11:26 -05:00

Move fressian and transit impl for geom objects to respective nss

This commit is contained in:
Andrey Antukh 2023-06-20 12:54:18 +02:00
parent f7801f9450
commit 3f14308908
5 changed files with 63 additions and 68 deletions

View file

@ -7,12 +7,8 @@
(ns app.common.fressian
(:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[clojure.data.fressian :as fres])
(:import
app.common.geom.matrix.Matrix
app.common.geom.point.Point
clojure.lang.Ratio
java.io.ByteArrayInputStream
java.io.ByteArrayOutputStream
@ -297,39 +293,3 @@
[data]
(with-open [^ByteArrayInputStream input (ByteArrayInputStream. ^bytes data)]
(-> 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})

View file

@ -8,6 +8,7 @@
(:require
#?(:cljs [cljs.pprint :as pp]
:clj [clojure.pprint :as pp])
#?(:clj [app.common.fressian :as fres])
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.point :as gpt]
@ -16,7 +17,12 @@
[app.common.schema.generators :as sg]
[app.common.schema.openapi :as-alias oapi]
[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)
@ -376,3 +382,36 @@
(mth/almost-zero? b)
(mth/almost-zero? c)
(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)}))})

View file

@ -11,6 +11,7 @@
:clj [clojure.pprint :as pp])
#?(:cljs [cljs.core :as c]
:clj [clojure.core :as c])
#?(:clj [app.common.fressian :as fres])
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.exceptions :as ex]
@ -19,8 +20,12 @@
[app.common.schema.generators :as sg]
[app.common.schema.openapi :as-alias oapi]
[app.common.spec :as us]
[app.common.transit :as t]
[clojure.spec.alpha :as s]
[cuerdas.core :as str]))
[cuerdas.core :as str])
#?(:clj
(:import
java.util.List)))
;; --- Point Impl
@ -466,3 +471,19 @@
(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})

View file

@ -51,11 +51,7 @@
(if ^boolean (d/num? x) (+ dx x) x)
(if ^boolean (d/num? y) (+ dy y) y)
w
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)))
h))
selrect))
(defn- move-points

View file

@ -7,8 +7,6 @@
(ns app.common.transit
(:require
[app.common.data :as d]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.uri :as uri]
[cognitect.transit :as t]
[lambdaisland.uri :as luri]
@ -18,8 +16,6 @@
#?(:cljs ["luxon" :as lxn]))
#?(:clj
(:import
app.common.geom.matrix.Matrix
app.common.geom.point.Point
java.io.ByteArrayInputStream
java.io.ByteArrayOutputStream
java.io.File
@ -122,23 +118,6 @@
{:id "u"
: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"
:class #?(:clj LinkedSet :cljs lks/LinkedSet)
:wfn vec