Is there an easy way to calculate the coordinates of elements in a group ? #10299
-
The document says that v6 reconstructs groups. After dragging and zooming a group, belows is fabric@4.5.0's code, Would you like to ask if the position information of the rectangle can be calculated from the rectangle element itself? Or zoom the group configuration center or something? Can calculations be made easier? const rects = g.getObjects()
const newPoints: { data: Block; point4: number[] }[] = []
const matrix = g.calcTransformMatrix()
rects.forEach(rect => {
rect.setCoords()
// https://github.com/fabricjs/fabric.js/issues/4206#issuecomment-429710311
const point: { x: number; y: number } = fabric.util.transformPoint({ y: rect.top, x: rect.left }, matrix)
newPoints.push({
data: rect.data,
point4: [point.x, point.y, (rect.width || 0) * (g.scaleX || 1), (rect.height || 0) * (g.scaleY || 1)],
})
})
return newPoints
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This has been already asked in various form in many issues. |
Beta Was this translation helpful? Give feedback.
This has been already asked in various form in many issues.
Take the rect aCoords and transorm each of the point for the rect transformMatrix. ( that includes the group one )