1
0
Fork 0

chore(core): Make generatePartTransform a named export

This commit is contained in:
Joost De Cock 2022-07-02 20:05:31 +02:00
parent 20440b9830
commit 7a33cf1783
3 changed files with 30 additions and 25 deletions

View file

@ -18,9 +18,13 @@ export {
Snippet, Snippet,
utils, utils,
} }
// This is a helper for configuration files // This is a helper for configuration files
export const pctBasedOn = utils.pctBasedOn export const pctBasedOn = utils.pctBasedOn
// This is a helper for manual layouts
export const generatePartTransform = utils.generatePartTransform
/* /*
* Default exports will be removed in FreeSewing v3 * Default exports will be removed in FreeSewing v3
*/ */

View file

@ -350,33 +350,9 @@ Part.prototype.shorthand = function () {
return shorthand return shorthand
} }
/** generate the transform attributes needed for the given part */
export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
const center = {
x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2,
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
}
const transforms = [`translate(${x},${y})`]
if (flipX) transforms.push(
'scale(-1, 1)',
)
if (flipY) transforms.push(
'scale(1, -1)',
)
if (rotate) transforms.push(
`rotate(${rotate})`
)
return {
transform: transforms.join(' '),
'transform-origin': `${center.x} ${center.y}`
}
}
Part.prototype.generateTransform = function(transforms) { Part.prototype.generateTransform = function(transforms) {
const {move, rotate, flipX, flipY} = transforms; const {move, rotate, flipX, flipY} = transforms;
const generated = generatePartTransform(move.x, move.y, rotate, flipX, flipY, this); const generated = utils.generatePartTransform(move.x, move.y, rotate, flipX, flipY, this);
for (var t in generated) { for (var t in generated) {
this.attr(t, generated[t], true); this.attr(t, generated[t], true);

View file

@ -359,3 +359,28 @@ export function pctBasedOn(measurement) {
fromAbs: (val, { measurements }) => Math.round((10 * val) / measurements[measurement]) / 10, fromAbs: (val, { measurements }) => Math.round((10 * val) / measurements[measurement]) / 10,
} }
} }
/** Generates the transform attributes needed for a given part */
export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
const center = {
x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2,
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
}
const transforms = [`translate(${x},${y})`]
if (flipX) transforms.push(
'scale(-1, 1)',
)
if (flipY) transforms.push(
'scale(1, -1)',
)
if (rotate) transforms.push(
`rotate(${rotate})`
)
return {
transform: transforms.join(' '),
'transform-origin': `${center.x} ${center.y}`
}
}