Skip to content

Commit

Permalink
v0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
daengdaengLee committed Jul 8, 2020
2 parents 69a0103 + f730c1e commit ec8a853
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 11 additions & 13 deletions src/getBoxPoints/getBoxPoints.index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 };
Expand Down
22 changes: 15 additions & 7 deletions src/getBoxPoints/getBoxPoints.spec.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ec8a853

Please sign in to comment.