From a0f4ec7dd5cac57e62cbdfc2be46dcb9da14e30b Mon Sep 17 00:00:00 2001 From: daengdaenglee Date: Wed, 8 Jul 2020 10:52:42 +0900 Subject: [PATCH 1/2] =?UTF-8?q?$$getBoxPoints=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit transformed 좌표가 잘못 계산되는 문제 해결 transform list 의 transform 을 적용하는 순서 문제 먼저 merged matrix 를 생성하고 각 original point 에 1회 matrix transform 적용하는 것으로 수정 --- src/getBoxPoints/getBoxPoints.index.js | 24 +++++++++++------------- src/getBoxPoints/getBoxPoints.spec.js | 22 +++++++++++++++------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/getBoxPoints/getBoxPoints.index.js b/src/getBoxPoints/getBoxPoints.index.js index 907965a..dd7cbd1 100644 --- a/src/getBoxPoints/getBoxPoints.index.js +++ b/src/getBoxPoints/getBoxPoints.index.js @@ -19,24 +19,22 @@ const $$getTransformedBoxPoints = ({ top_right: original_top_right, bottom_right: original_bottom_right, bottom_left: original_bottom_left, -}) => ($el, $svg = $$getSVG()) => { +}) => ($el) => { const transform_list = $$getBaseTransformList($el); - const [top_left, top_right, bottom_left, bottom_right] = go( + const merged_matrix = go( + rangeL(transform_list.numberOfItems), + mapL((i) => transform_list.getItem(i)), + mapL(({ matrix: m }) => m), + reduce((m1, m2) => m1.multiply(m2)) + ); + const [top_left, top_right, bottom_left, bottom_right] = mapL( + (p) => (merged_matrix ? p.matrixTransform(merged_matrix) : p), [ original_top_left, original_top_right, original_bottom_left, original_bottom_right, - ], - mapL((p) => $$createSVGPoint(p)($svg)), - mapL((p) => - go( - rangeL(transform_list.numberOfItems), - mapL((i) => transform_list.getItem(i)), - mapL(({ matrix: m }) => m), - (iter) => reduce((p, m) => p.matrixTransform(m), p, iter) - ) - ) + ] ); return { @@ -75,7 +73,7 @@ const $$getBoundingBoxPoints = ({ export const $$getBoxPoints = ($el, $svg = $$getSVG()) => { const original = $$getOriginalBoxPoints($el, $svg); - const transformed = $$getTransformedBoxPoints(original)($el, $svg); + const transformed = $$getTransformedBoxPoints(original)($el); const bounding = $$getBoundingBoxPoints(transformed)($el, $svg); return { original, transformed, bounding }; diff --git a/src/getBoxPoints/getBoxPoints.spec.js b/src/getBoxPoints/getBoxPoints.spec.js index 7b8a467..5535673 100644 --- a/src/getBoxPoints/getBoxPoints.spec.js +++ b/src/getBoxPoints/getBoxPoints.spec.js @@ -1,9 +1,10 @@ import { expect } from "chai"; -import { map, reduce } from "fxjs2"; +import { defaultTo, go, mapL, rangeL, reduce } from "fxjs2"; import { makeMockRect } from "../../test/utils/makeMockRect.js"; import { makeRandomInt } from "../../test/utils/makeRandomInt.js"; import { makeRandomNumber } from "../../test/utils/makeRandomNumber.js"; import { makeRandomTransformAttributeValue } from "../../test/utils/makeRandomTransformAttributeValue.js"; +import { $$createSVGMatrix } from "../createSVGMatrix/createSVGMatrix.index.js"; import { $$getBaseTransformList } from "../getBaseTransformList/getBaseTransformList.index.js"; import { $$getBoxPoints } from "./getBoxPoints.index.js"; @@ -78,17 +79,24 @@ export default ({ describe, it }) => [ bottom_left: { x: x4_1, y: y4_1 }, }, } = $$getBoxPoints($el); + const merged_matrix = go( + rangeL(transform_list.numberOfItems), + mapL((i) => transform_list.getItem(i)), + mapL(({ matrix: m }) => m), + reduce((m1, m2) => m1.multiply(m2)), + defaultTo($$createSVGMatrix()()) + ); const [ { x: x1_2, y: y1_2 }, { x: x2_2, y: y2_2 }, { x: x3_2, y: y3_2 }, { x: x4_2, y: y4_2 }, - ] = reduce( - (points, { matrix }) => - map((point) => point.matrixTransform(matrix), points), - [top_left, top_right, bottom_right, bottom_left], - transform_list - ); + ] = mapL((point) => point.matrixTransform(merged_matrix), [ + top_left, + top_right, + bottom_right, + bottom_left, + ]); expect(x1_2).equal(x1_1); expect(y1_2).equal(y1_1); From f730c1e2e6f91c32dd4634194218f8af82979d3c Mon Sep 17 00:00:00 2001 From: daengdaenglee Date: Wed, 8 Jul 2020 10:53:30 +0900 Subject: [PATCH 2/2] Bump Version 0.4.1 -> 0.4.2 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 64582cf..749bfaf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "fxsvg", - "version": "0.4.1", + "version": "0.4.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ccb2287..6f9eac5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fxsvg", - "version": "0.4.1", + "version": "0.4.2", "description": "Functional SVG Handling Library", "type": "module", "main": "./src/index.js",