From 912be764003238207fb7528504c4d943478873bb Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 25 Nov 2020 09:57:52 +0100 Subject: [PATCH] :bug: Fixed problem with divide by zero --- common/app/common/geom/point.cljc | 23 ++++++++++--------- common/app/common/geom/shapes/transforms.cljc | 2 +- common/app/common/pages_migrations.cljc | 17 +++----------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/common/app/common/geom/point.cljc b/common/app/common/geom/point.cljc index 0d13aa542..1f97b3174 100644 --- a/common/app/common/geom/point.cljc +++ b/common/app/common/geom/point.cljc @@ -148,17 +148,18 @@ (assert (point? p)) (assert (point? other)) - (if (or (= 0 (length p)) - (= 0 (length other))) - 0 - (let [a (/ (+ (* x ox) - (* y oy)) - (* (length p) - (length other))) - a (mth/acos (if (< a -1) -1 (if (> a 1) 1 a))) - d (-> (mth/degrees a) - (mth/precision 6))] - (if (mth/nan? d) 0 d)))) + (let [length-p (length p) + length-other (length other)] + (if (or (mth/almost-zero? length-p) + (mth/almost-zero? length-other)) + 0 + (let [a (/ (+ (* x ox) + (* y oy)) + (* length-p length-other)) + a (mth/acos (if (< a -1) -1 (if (> a 1) 1 a))) + d (-> (mth/degrees a) + (mth/precision 6))] + (if (mth/nan? d) 0 d))))) (defn update-angle diff --git a/common/app/common/geom/shapes/transforms.cljc b/common/app/common/geom/shapes/transforms.cljc index ec5e51f4a..deebb5966 100644 --- a/common/app/common/geom/shapes/transforms.cljc +++ b/common/app/common/geom/shapes/transforms.cljc @@ -167,7 +167,7 @@ h1 (calculate-height points-temp) h2 (calculate-height (transform-points points-rec center stretch-matrix)) - h3 (/ h1 h2) + h3 (if-not (mth/almost-zero? h2) (/ h1 h2) 1) h3 (if (mth/nan? h3) 1 h3) stretch-matrix (gmt/multiply stretch-matrix (gmt/scale-matrix (gpt/point 1 h3))) diff --git a/common/app/common/pages_migrations.cljc b/common/app/common/pages_migrations.cljc index e36ca0f5b..257d135b5 100644 --- a/common/app/common/pages_migrations.cljc +++ b/common/app/common/pages_migrations.cljc @@ -110,17 +110,6 @@ (update data :pages-index #(d/mapm update-page %)))) -(defmethod migrate 4 - [data] - (letfn [(update-object [id object] - (cond-> object - (= (:id object) uuid/zero) - (assoc :points [] - :selrect {:x 0 :y 0 - :width 1 :height 1 - :x1 0 :y1 0 - :x2 1 :y2 1}))) - - (update-page [id page] - (update page :objects #(d/mapm update-object %)))] - (update data :pages-index #(d/mapm update-page %)))) +;; We did rollback version 4 migration. +;; Keep this in order to remember the next version to be 5 +(defmethod migrate 4 [data] data)