Closed maxerbubba closed 1 week ago
Hi @maxerbubba this is a misconception with the Line object. the x,y properties are just for initialization. After that is only the left/top that count.
We know this is unoptimal and we plan to remove Line in favor of polyLine with only a single segment.
Thanks. I was able to use Rect as a workaround but computing the angles myself was tricky
Sent from an iPhone
On Sun, Jun 23, 2024 at 1:07 AM Andrea Bogazzi @.***> wrote:
We know this is unoptimal and we plan to remove Line in favor of polyLine with only a single segment.
— Reply to this email directly, view it on GitHub https://github.com/fabricjs/fabric.js/issues/9934#issuecomment-2184832161, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB7KYTXMZT3IFLUH3Z5UNSLZIZ63BAVCNFSM6AAAAABJWK5VCGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBUHAZTEMJWGE . You are receiving this because you were mentioned.Message ID: @.***>
Is not hard to get updated points in realtime from the line object.
How does one get the updated points from a line in realtime?
Consider updating function documentation. Thanks!
get the poins relative from the center of the line.
const p1 = new Point(x1, y1);
const p2 = new Point(x2, y2);
const center = p1.lerp(p2);
const p1Relative = p1.subtract(center);
const p2Relative = p2.subtract(center);
use the moving or object:moving event and use the myLine.calcTransformMatrix()
function in the event to get the updated matrix. and transform the points
line.on('moving', () => {
const m = myLine.calcTransformMatrix();
const updatedP1 = p1Relative.transform(m);
const updatedP2 = p2relative.transform(m);
});
CheckList
Version
5.3.0
In What environments are you experiencing the problem?
Chrome
Node Version (if applicable)
None
Link To Reproduction
https://jsfiddle.net/pLco1yr2/2/
Steps To Reproduce
Expected Behavior
x1, y1, x2, y2 see new values in event handler.
Actual Behavior
x1, y1, x2, y2 do not update.
Note that top and left update correctly.
Error Message & Stack Trace
No response