I need to recreate an inverted version of an original 2d model side by side.
I can achieve this with scaleX(-1) but the text is upside down.
When I scaleX(-1) again on the inverted model, the coordinates of the text are distorted, how can I solve this problem?
the one on the left is the original model and the one on the right is the reversed model. I made the backgrounds yellow to make it clearer that it has shifted.
to give an example from part of the code
function mmToPx(mm) {
return mm * dimensions.currentScale;
}
// Bobin
const coil = new Konva.Rect({
x : centerX - (mmToPx(dimensions.R1 - dimensions.r2) - mmToPx(1)) / 2,
y : centerY - (mmToPx(dimensions.Ls) - mmToPx(1)) / 2,
width : mmToPx(dimensions.R1 - dimensions.r2) - mmToPx(1),
height : mmToPx(dimensions.Ls - dimensions.ts) - mmToPx(1),
fill: '#ff7f27',
stroke: 'black',
strokeWidth: 5,
});
const lines = [
...,
{
isText : true,
width : coil.width(),
text: 'N,I',
textX: coil.x(),
textY: (coil.y() + (coil.height() / 2)) - (dimensions.currentScale / 2),
textColor : 'black',
},
...,
];
lines.forEach(line => {
...,
if(line.isText){
var text = new Konva.Text({
x: line.textX,
y: line.textY,
text: line.text,
fill: line.textColor,
fontFamily: 'Calibri',
fontSize: 14,
align : 'center',
width : line.width,
});
const textBackground = new Konva.Rect({
x: line.textX,
y: line.textY,
width: line.width,
height: 20,
fill: 'yellow',
cornerRadius: 4,
});
originalGroup.add(textBackground);
originalGroup.add(text);
}
});
and here is the scaleX() method
const mirrored = originalGroup.clone();
mirrored.x(centerX * 2.35)
mirrored.scaleX(-1);
mirrored.find('Text').forEach((textNode) => {
textNode.scaleX(-1);
});
[![enter image description here][1]][1]