Previously when creating a Fabric.Path in 1.x, the properties minX and minY were returned.
In 2.4.1 these values are not returned. There appears to me no mention of this removal in the migration docs. Whilst minX and minY are equivalent to left and top at the time of path initialisation, it appears as though the values cannot simply be swapped out. For example, the following function (the need for this function is explained here FabricJS - When moving a path the 'path' object doesn't update) now does not work (and swapping minX to left and minY to top works when drawing the initial path but when updating it causes the path to 'snap' back to the original position).
transformedPoint = (target) => {
const points = [];
const path = target.path;
points.push(new fabric.Point(path[0][1], path[0][2]));
points.push(new fabric.Point(path[1][3], path[1][4]));
points.push(new fabric.Point(path[1][1], path[1][2]));
const matrix = target.calcTransformMatrix();
return points
.map(p => new fabric.Point(
p.x - target.minX - (target.width / 2) - (target.strokeWidth / 2),
p.y - target.minY - (target.height / 2) - (target.strokeWidth / 2)),
)
.map(p => fabric.util.transformPoint(p, matrix));
}
I have looked at the 1.7.19 source code to see how these values used to be calculated but I don't see how I can make use of _parseDimensions() in the code above as it is a private method?
from Replicating minX and minY returned by a Path class in Fabric 1.x in 2.x
No comments:
Post a Comment